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"
|
2016-07-14 03:35:07 +02:00
|
|
|
#include "blink/grit/devtools_resources_map.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
|
|
|
|
|
|
|
for (size_t i = 0; i < kDevtoolsResourcesSize; ++i) {
|
2015-08-26 00:33:31 +02:00
|
|
|
if (base::EqualsCaseInsensitiveASCII(kDevtoolsResources[i].name,
|
|
|
|
path.c_str())) {
|
2012-10-08 19:47:37 +02:00
|
|
|
action->resource_id = kDevtoolsResources[i].value;
|
|
|
|
return true;
|
2012-05-18 17:04:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-08 19:47:37 +02:00
|
|
|
return false;
|
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(
|
2014-02-19 17:27:54 +01:00
|
|
|
content::kChromeDevToolsScheme,
|
2012-10-08 19:47:37 +02:00
|
|
|
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
|