OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "chrome/browser/net/chrome_url_request_context.h" | 8 #include "chrome/browser/net/chrome_url_request_context.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h" | 10 #include "chrome/browser/ui/webui/chrome_url_data_manager_backend.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 }; | 40 }; |
41 | 41 |
42 | 42 |
43 DevToolsDataSource::DevToolsDataSource() | 43 DevToolsDataSource::DevToolsDataSource() |
44 : DataSource(chrome::kChromeUIDevToolsHost, NULL) { | 44 : DataSource(chrome::kChromeUIDevToolsHost, NULL) { |
45 } | 45 } |
46 | 46 |
47 void DevToolsDataSource::StartDataRequest(const std::string& path, | 47 void DevToolsDataSource::StartDataRequest(const std::string& path, |
48 bool is_incognito, | 48 bool is_incognito, |
49 int request_id) { | 49 int request_id) { |
| 50 if (path.empty()) { |
| 51 SendResponse(request_id, NULL); |
| 52 return; |
| 53 } |
| 54 |
50 std::string filename = PathWithoutParams(path); | 55 std::string filename = PathWithoutParams(path); |
51 | 56 |
52 int resource_id = -1; | 57 int resource_id = -1; |
53 for (size_t i = 0; i < kDevtoolsResourcesSize; ++i) { | 58 for (size_t i = 0; i < kDevtoolsResourcesSize; ++i) { |
54 if (filename == kDevtoolsResources[i].name) { | 59 if (filename == kDevtoolsResources[i].name) { |
55 resource_id = kDevtoolsResources[i].value; | 60 resource_id = kDevtoolsResources[i].value; |
56 break; | 61 break; |
57 } | 62 } |
58 } | 63 } |
59 | 64 |
(...skipping 12 matching lines...) Expand all Loading... |
72 return "text/html"; | 77 return "text/html"; |
73 } else if (EndsWith(filename, ".css", false)) { | 78 } else if (EndsWith(filename, ".css", false)) { |
74 return "text/css"; | 79 return "text/css"; |
75 } else if (EndsWith(filename, ".js", false)) { | 80 } else if (EndsWith(filename, ".js", false)) { |
76 return "application/javascript"; | 81 return "application/javascript"; |
77 } else if (EndsWith(filename, ".png", false)) { | 82 } else if (EndsWith(filename, ".png", false)) { |
78 return "image/png"; | 83 return "image/png"; |
79 } else if (EndsWith(filename, ".gif", false)) { | 84 } else if (EndsWith(filename, ".gif", false)) { |
80 return "image/gif"; | 85 return "image/gif"; |
81 } | 86 } |
82 NOTREACHED(); | |
83 return "text/plain"; | 87 return "text/plain"; |
84 } | 88 } |
85 | 89 |
86 // static | 90 // static |
87 void DevToolsUI::RegisterDevToolsDataSource() { | 91 void DevToolsUI::RegisterDevToolsDataSource() { |
88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
89 static bool registered = false; | 93 static bool registered = false; |
90 if (!registered) { | 94 if (!registered) { |
91 DevToolsDataSource* data_source = new DevToolsDataSource(); | 95 DevToolsDataSource* data_source = new DevToolsDataSource(); |
92 ChromeURLRequestContext* context = static_cast<ChromeURLRequestContext*>( | 96 ChromeURLRequestContext* context = static_cast<ChromeURLRequestContext*>( |
93 Profile::GetDefaultRequestContext()->GetURLRequestContext()); | 97 Profile::GetDefaultRequestContext()->GetURLRequestContext()); |
94 context->chrome_url_data_manager_backend()->AddDataSource(data_source); | 98 context->chrome_url_data_manager_backend()->AddDataSource(data_source); |
95 registered = true; | 99 registered = true; |
96 } | 100 } |
97 } | 101 } |
98 | 102 |
99 DevToolsUI::DevToolsUI(TabContents* contents) : WebUI(contents) { | 103 DevToolsUI::DevToolsUI(TabContents* contents) : WebUI(contents) { |
100 DevToolsDataSource* data_source = new DevToolsDataSource(); | 104 DevToolsDataSource* data_source = new DevToolsDataSource(); |
101 contents->profile()->GetChromeURLDataManager()->AddDataSource(data_source); | 105 contents->profile()->GetChromeURLDataManager()->AddDataSource(data_source); |
102 } | 106 } |
103 | 107 |
104 void DevToolsUI::RenderViewCreated(RenderViewHost* render_view_host) { | 108 void DevToolsUI::RenderViewCreated(RenderViewHost* render_view_host) { |
105 render_view_host->Send(new DevToolsMsg_SetupDevToolsClient( | 109 render_view_host->Send(new DevToolsMsg_SetupDevToolsClient( |
106 render_view_host->routing_id())); | 110 render_view_host->routing_id())); |
107 } | 111 } |
OLD | NEW |