2012-10-08 19:47:37 +02: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 17:04:56 +02:00
|
|
|
|
2015-11-26 03:53:12 +01:00
|
|
|
#include "libcef/browser/net/devtools_scheme_handler.h"
|
2013-03-12 21:23:24 +01:00
|
|
|
|
2012-05-18 17:04:56 +02:00
|
|
|
#include <string>
|
2013-03-12 21:23:24 +01:00
|
|
|
|
2015-11-26 03:53:12 +01:00
|
|
|
#include "libcef/browser/net/internal_scheme_handler.h"
|
|
|
|
#include "libcef/browser/net/url_request_manager.h"
|
2013-03-12 21:23:24 +01:00
|
|
|
|
2016-04-27 22:38:52 +02:00
|
|
|
#include "base/memory/ptr_util.h"
|
2013-06-22 04:06:32 +02:00
|
|
|
#include "base/strings/string_util.h"
|
2017-07-06 22:39:37 +02:00
|
|
|
#include "content/public/browser/devtools_frontend_host.h"
|
2013-03-12 21:23:24 +01:00
|
|
|
#include "content/public/common/url_constants.h"
|
2012-10-08 19:47:37 +02:00
|
|
|
|
|
|
|
namespace scheme {
|
2012-05-18 17:04:56 +02:00
|
|
|
|
|
|
|
const char kChromeDevToolsHost[] = "devtools";
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2012-10-08 19:47:37 +02:00
|
|
|
class Delegate : public InternalHandlerDelegate {
|
2012-05-18 17:04:56 +02:00
|
|
|
public:
|
2012-10-08 19:47:37 +02:00
|
|
|
Delegate() {}
|
2012-05-18 17:04:56 +02:00
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
bool OnRequest(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefRequest> request,
|
2014-11-12 20:25:15 +01:00
|
|
|
Action* action) override {
|
2012-10-08 19:47:37 +02:00
|
|
|
GURL url = GURL(request->GetURL().ToString());
|
|
|
|
std::string path = url.path();
|
|
|
|
if (path.length() > 0)
|
|
|
|
path = path.substr(1);
|
2012-05-18 17:04:56 +02:00
|
|
|
|
2017-07-06 22:39:37 +02:00
|
|
|
action->string_piece =
|
|
|
|
content::DevToolsFrontendHost::GetFrontendResource(path);
|
|
|
|
return !action->string_piece.empty();
|
2012-05-18 17:04:56 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2015-03-02 21:25:14 +01:00
|
|
|
void RegisterChromeDevToolsHandler(CefURLRequestManager* request_manager) {
|
|
|
|
request_manager->AddFactory(
|
2017-05-17 11:29:28 +02:00
|
|
|
content::kChromeDevToolsScheme, kChromeDevToolsHost,
|
2016-04-27 22:38:52 +02:00
|
|
|
CreateInternalHandlerFactory(base::WrapUnique(new Delegate())));
|
2012-05-18 17:04:56 +02:00
|
|
|
}
|
2012-10-08 19:47:37 +02:00
|
|
|
|
|
|
|
} // namespace scheme
|