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
|
|
|
|
2020-07-01 02:57:00 +02:00
|
|
|
#include "libcef/browser/iothread_state.h"
|
2015-11-26 03:53:12 +01:00
|
|
|
#include "libcef/browser/net/internal_scheme_handler.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();
|
2023-01-02 23:59:03 +01:00
|
|
|
if (path.length() > 0) {
|
2012-10-08 19:47:37 +02:00
|
|
|
path = path.substr(1);
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2012-05-18 17:04:56 +02:00
|
|
|
|
2020-02-10 18:10:17 +01:00
|
|
|
action->bytes =
|
|
|
|
content::DevToolsFrontendHost::GetFrontendResourceBytes(path);
|
|
|
|
return !!action->bytes;
|
2012-05-18 17:04:56 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2020-07-01 02:57:00 +02:00
|
|
|
void RegisterChromeDevToolsHandler(CefIOThreadState* iothread_state) {
|
|
|
|
iothread_state->RegisterSchemeHandlerFactory(
|
2019-04-30 22:45:13 +02:00
|
|
|
content::kChromeDevToolsScheme, kChromeDevToolsHost,
|
|
|
|
CreateInternalHandlerFactory(base::WrapUnique(new Delegate())));
|
|
|
|
}
|
|
|
|
|
2012-10-08 19:47:37 +02:00
|
|
|
} // namespace scheme
|