1 // Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights 2 // reserved. Use of this source code is governed by a BSD-style license that can 3 // be found in the LICENSE file. 4 5 #include "libcef/browser/net/devtools_scheme_handler.h" 6 7 #include <string> 8 9 #include "libcef/browser/iothread_state.h" 10 #include "libcef/browser/net/internal_scheme_handler.h" 11 12 #include "base/memory/ptr_util.h" 13 #include "base/strings/string_util.h" 14 #include "content/public/browser/devtools_frontend_host.h" 15 #include "content/public/common/url_constants.h" 16 17 namespace scheme { 18 19 const char kChromeDevToolsHost[] = "devtools"; 20 21 namespace { 22 23 class Delegate : public InternalHandlerDelegate { 24 public: Delegate()25 Delegate() {} 26 OnRequest(CefRefPtr<CefBrowser> browser,CefRefPtr<CefRequest> request,Action * action)27 bool OnRequest(CefRefPtr<CefBrowser> browser, 28 CefRefPtr<CefRequest> request, 29 Action* action) override { 30 GURL url = GURL(request->GetURL().ToString()); 31 std::string path = url.path(); 32 if (path.length() > 0) 33 path = path.substr(1); 34 35 action->bytes = 36 content::DevToolsFrontendHost::GetFrontendResourceBytes(path); 37 return !!action->bytes; 38 } 39 }; 40 41 } // namespace 42 RegisterChromeDevToolsHandler(CefIOThreadState * iothread_state)43void RegisterChromeDevToolsHandler(CefIOThreadState* iothread_state) { 44 iothread_state->RegisterSchemeHandlerFactory( 45 content::kChromeDevToolsScheme, kChromeDevToolsHost, 46 CreateInternalHandlerFactory(base::WrapUnique(new Delegate()))); 47 } 48 49 } // namespace scheme 50