2012-10-08 17:47:37 +00:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that can
|
|
|
|
// be found in the LICENSE file.
|
2012-05-18 15:04:56 +00:00
|
|
|
|
2015-11-25 21:53:12 -05:00
|
|
|
#include "libcef/browser/net/devtools_scheme_handler.h"
|
2013-03-12 20:23:24 +00:00
|
|
|
|
2012-05-18 15:04:56 +00:00
|
|
|
#include <string>
|
2013-03-12 20:23:24 +00:00
|
|
|
|
2015-11-25 21:53:12 -05:00
|
|
|
#include "libcef/browser/net/internal_scheme_handler.h"
|
|
|
|
#include "libcef/browser/net/url_request_manager.h"
|
2013-03-12 20:23:24 +00:00
|
|
|
|
2016-04-27 16:38:52 -04:00
|
|
|
#include "base/memory/ptr_util.h"
|
2013-06-22 02:06:32 +00:00
|
|
|
#include "base/strings/string_util.h"
|
2017-07-06 16:39:37 -04:00
|
|
|
#include "content/public/browser/devtools_frontend_host.h"
|
2013-03-12 20:23:24 +00:00
|
|
|
#include "content/public/common/url_constants.h"
|
2012-10-08 17:47:37 +00:00
|
|
|
|
|
|
|
namespace scheme {
|
2012-05-18 15:04:56 +00:00
|
|
|
|
|
|
|
const char kChromeDevToolsHost[] = "devtools";
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2012-10-08 17:47:37 +00:00
|
|
|
class Delegate : public InternalHandlerDelegate {
|
2012-05-18 15:04:56 +00:00
|
|
|
public:
|
2012-10-08 17:47:37 +00:00
|
|
|
Delegate() {}
|
2012-05-18 15:04:56 +00:00
|
|
|
|
2015-03-02 20:25:14 +00:00
|
|
|
bool OnRequest(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefRequest> request,
|
2014-11-12 19:25:15 +00:00
|
|
|
Action* action) override {
|
2012-10-08 17:47:37 +00:00
|
|
|
GURL url = GURL(request->GetURL().ToString());
|
|
|
|
std::string path = url.path();
|
|
|
|
if (path.length() > 0)
|
|
|
|
path = path.substr(1);
|
2012-05-18 15:04:56 +00:00
|
|
|
|
2017-07-06 16:39:37 -04:00
|
|
|
action->string_piece =
|
|
|
|
content::DevToolsFrontendHost::GetFrontendResource(path);
|
|
|
|
return !action->string_piece.empty();
|
2012-05-18 15:04:56 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2015-03-02 20:25:14 +00:00
|
|
|
void RegisterChromeDevToolsHandler(CefURLRequestManager* request_manager) {
|
|
|
|
request_manager->AddFactory(
|
2017-05-17 11:29:28 +02:00
|
|
|
content::kChromeDevToolsScheme, kChromeDevToolsHost,
|
2016-04-27 16:38:52 -04:00
|
|
|
CreateInternalHandlerFactory(base::WrapUnique(new Delegate())));
|
2012-05-18 15:04:56 +00:00
|
|
|
}
|
2012-10-08 17:47:37 +00:00
|
|
|
|
|
|
|
} // namespace scheme
|