| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/devtools_ui.h" | 5 #include "chrome/browser/ui/webui/devtools_ui.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "chrome/browser/net/chrome_url_request_context.h" | 12 #include "chrome/browser/net/chrome_url_request_context.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | |
| 15 #include "chrome/common/url_constants.h" | 14 #include "chrome/common/url_constants.h" |
| 16 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/devtools_client_host.h" | 16 #include "content/public/browser/devtools_client_host.h" |
| 18 #include "content/public/browser/devtools_http_handler.h" | 17 #include "content/public/browser/devtools_http_handler.h" |
| 19 #include "content/public/browser/render_view_host.h" | 18 #include "content/public/browser/render_view_host.h" |
| 20 #include "content/public/browser/url_data_source_delegate.h" | 19 #include "content/public/browser/url_data_source.h" |
| 21 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 22 #include "content/public/browser/web_ui.h" | 21 #include "content/public/browser/web_ui.h" |
| 23 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
| 24 | 23 |
| 25 using content::BrowserThread; | 24 using content::BrowserThread; |
| 26 using content::WebContents; | 25 using content::WebContents; |
| 27 | 26 |
| 28 namespace { | 27 namespace { |
| 29 | 28 |
| 30 std::string PathWithoutParams(const std::string& path) { | 29 std::string PathWithoutParams(const std::string& path) { |
| 31 return GURL(std::string("chrome-devtools://devtools/") + path) | 30 return GURL(std::string("chrome-devtools://devtools/") + path) |
| 32 .path().substr(1); | 31 .path().substr(1); |
| 33 } | 32 } |
| 34 | 33 |
| 35 } // namespace | 34 } // namespace |
| 36 | 35 |
| 37 class DevToolsDataSource : public content::URLDataSourceDelegate { | 36 class DevToolsDataSource : public content::URLDataSource { |
| 38 public: | 37 public: |
| 39 DevToolsDataSource(); | 38 DevToolsDataSource(); |
| 40 | 39 |
| 41 // content::URLDataSourceDelegate implementation. | 40 // content::URLDataSource implementation. |
| 42 virtual std::string GetSource() OVERRIDE; | 41 virtual std::string GetSource() OVERRIDE; |
| 43 virtual void StartDataRequest(const std::string& path, | 42 virtual void StartDataRequest( |
| 44 bool is_incognito, | 43 const std::string& path, |
| 45 int request_id) OVERRIDE; | 44 bool is_incognito, |
| 45 const content::URLDataSource::GotDataCallback& callback) OVERRIDE; |
| 46 virtual std::string GetMimeType(const std::string& path) const OVERRIDE; | 46 virtual std::string GetMimeType(const std::string& path) const OVERRIDE; |
| 47 | 47 |
| 48 private: | 48 private: |
| 49 ~DevToolsDataSource() {} | 49 ~DevToolsDataSource() {} |
| 50 DISALLOW_COPY_AND_ASSIGN(DevToolsDataSource); | 50 DISALLOW_COPY_AND_ASSIGN(DevToolsDataSource); |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 | 53 |
| 54 DevToolsDataSource::DevToolsDataSource() { | 54 DevToolsDataSource::DevToolsDataSource() { |
| 55 } | 55 } |
| 56 | 56 |
| 57 std::string DevToolsDataSource::GetSource() { | 57 std::string DevToolsDataSource::GetSource() { |
| 58 return chrome::kChromeUIDevToolsHost; | 58 return chrome::kChromeUIDevToolsHost; |
| 59 } | 59 } |
| 60 | 60 |
| 61 void DevToolsDataSource::StartDataRequest(const std::string& path, | 61 void DevToolsDataSource::StartDataRequest( |
| 62 bool is_incognito, | 62 const std::string& path, |
| 63 int request_id) { | 63 bool is_incognito, |
| 64 const content::URLDataSource::GotDataCallback& callback) { |
| 64 std::string filename = PathWithoutParams(path); | 65 std::string filename = PathWithoutParams(path); |
| 65 | 66 |
| 66 | |
| 67 int resource_id = | 67 int resource_id = |
| 68 content::DevToolsHttpHandler::GetFrontendResourceId(filename); | 68 content::DevToolsHttpHandler::GetFrontendResourceId(filename); |
| 69 | 69 |
| 70 DLOG_IF(WARNING, -1 == resource_id) << "Unable to find dev tool resource: " | 70 DLOG_IF(WARNING, -1 == resource_id) << "Unable to find dev tool resource: " |
| 71 << filename << ". If you compiled with debug_devtools=1, try running" | 71 << filename << ". If you compiled with debug_devtools=1, try running" |
| 72 " with --debug-devtools."; | 72 " with --debug-devtools."; |
| 73 const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 73 const ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 74 scoped_refptr<base::RefCountedStaticMemory> bytes(rb.LoadDataResourceBytes( | 74 scoped_refptr<base::RefCountedStaticMemory> bytes(rb.LoadDataResourceBytes( |
| 75 resource_id)); | 75 resource_id)); |
| 76 url_data_source()->SendResponse(request_id, bytes); | 76 callback.Run(bytes); |
| 77 } | 77 } |
| 78 | 78 |
| 79 std::string DevToolsDataSource::GetMimeType(const std::string& path) const { | 79 std::string DevToolsDataSource::GetMimeType(const std::string& path) const { |
| 80 std::string filename = PathWithoutParams(path); | 80 std::string filename = PathWithoutParams(path); |
| 81 if (EndsWith(filename, ".html", false)) { | 81 if (EndsWith(filename, ".html", false)) { |
| 82 return "text/html"; | 82 return "text/html"; |
| 83 } else if (EndsWith(filename, ".css", false)) { | 83 } else if (EndsWith(filename, ".css", false)) { |
| 84 return "text/css"; | 84 return "text/css"; |
| 85 } else if (EndsWith(filename, ".js", false)) { | 85 } else if (EndsWith(filename, ".js", false)) { |
| 86 return "application/javascript"; | 86 return "application/javascript"; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 105 | 105 |
| 106 DevToolsUI::DevToolsUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 106 DevToolsUI::DevToolsUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
| 107 ChromeURLDataManager::AddDataSource( | 107 ChromeURLDataManager::AddDataSource( |
| 108 Profile::FromWebUI(web_ui), new DevToolsDataSource); | 108 Profile::FromWebUI(web_ui), new DevToolsDataSource); |
| 109 } | 109 } |
| 110 | 110 |
| 111 void DevToolsUI::RenderViewCreated( | 111 void DevToolsUI::RenderViewCreated( |
| 112 content::RenderViewHost* render_view_host) { | 112 content::RenderViewHost* render_view_host) { |
| 113 content::DevToolsClientHost::SetupDevToolsFrontendClient(render_view_host); | 113 content::DevToolsClientHost::SetupDevToolsFrontendClient(render_view_host); |
| 114 } | 114 } |
| OLD | NEW |