Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: chrome/browser/ui/webui/net_internals_ui.cc

Issue 7455005: Apply content-security-policy to chrome://net-internals. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/net_internals_ui.h" 5 #include "chrome/browser/ui/webui/net_internals_ui.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <list> 8 #include <list>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 14 matching lines...) Expand all
25 #include "chrome/browser/browser_process.h" 25 #include "chrome/browser/browser_process.h"
26 #include "chrome/browser/io_thread.h" 26 #include "chrome/browser/io_thread.h"
27 #include "chrome/browser/net/chrome_net_log.h" 27 #include "chrome/browser/net/chrome_net_log.h"
28 #include "chrome/browser/net/connection_tester.h" 28 #include "chrome/browser/net/connection_tester.h"
29 #include "chrome/browser/net/passive_log_collector.h" 29 #include "chrome/browser/net/passive_log_collector.h"
30 #include "chrome/browser/net/url_fixer_upper.h" 30 #include "chrome/browser/net/url_fixer_upper.h"
31 #include "chrome/browser/prefs/pref_member.h" 31 #include "chrome/browser/prefs/pref_member.h"
32 #include "chrome/browser/prerender/prerender_manager.h" 32 #include "chrome/browser/prerender/prerender_manager.h"
33 #include "chrome/browser/profiles/profile.h" 33 #include "chrome/browser/profiles/profile.h"
34 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 34 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
35 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
35 #include "chrome/common/chrome_notification_types.h" 36 #include "chrome/common/chrome_notification_types.h"
36 #include "chrome/common/chrome_paths.h" 37 #include "chrome/common/chrome_paths.h"
37 #include "chrome/common/chrome_version_info.h" 38 #include "chrome/common/chrome_version_info.h"
38 #include "chrome/common/jstemplate_builder.h" 39 #include "chrome/common/jstemplate_builder.h"
39 #include "chrome/common/pref_names.h" 40 #include "chrome/common/pref_names.h"
40 #include "chrome/common/url_constants.h" 41 #include "chrome/common/url_constants.h"
41 #include "content/browser/browser_thread.h" 42 #include "content/browser/browser_thread.h"
42 #include "content/common/notification_details.h" 43 #include "content/common/notification_details.h"
43 #include "grit/generated_resources.h" 44 #include "grit/generated_resources.h"
44 #include "grit/net_internals_resources.h" 45 #include "grit/net_internals_resources.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 123
123 dict->SetString("proxy_settings_experiment", 124 dict->SetString("proxy_settings_experiment",
124 ConnectionTester::ProxySettingsExperimentDescription( 125 ConnectionTester::ProxySettingsExperimentDescription(
125 experiment.proxy_settings_experiment)); 126 experiment.proxy_settings_experiment));
126 dict->SetString("host_resolver_experiment", 127 dict->SetString("host_resolver_experiment",
127 ConnectionTester::HostResolverExperimentDescription( 128 ConnectionTester::HostResolverExperimentDescription(
128 experiment.host_resolver_experiment)); 129 experiment.host_resolver_experiment));
129 return dict; 130 return dict;
130 } 131 }
131 132
132 class NetInternalsHTMLSource : public ChromeURLDataManager::DataSource { 133 ChromeWebUIDataSource* CreateNetInternalsHTMLSource() {
133 public: 134 ChromeWebUIDataSource* source =
134 NetInternalsHTMLSource(); 135 new ChromeWebUIDataSource(chrome::kChromeUINetInternalsHost);
135 136
136 // Called when the network layer has requested a resource underneath 137 source->set_default_resource(IDR_NET_INTERNALS_INDEX_HTML);
137 // the path we registered. 138 source->add_resource_path("help.html", IDR_NET_INTERNALS_HELP_HTML);
138 virtual void StartDataRequest(const std::string& path, 139 source->add_resource_path("help.js", IDR_NET_INTERNALS_HELP_JS);
139 bool is_incognito, 140 source->add_resource_path("index.js", IDR_NET_INTERNALS_INDEX_JS);
140 int request_id); 141 source->set_json_path("strings.js");
141 virtual std::string GetMimeType(const std::string&) const; 142 return source;
142 143 }
143 private:
144 ~NetInternalsHTMLSource() {}
145 DISALLOW_COPY_AND_ASSIGN(NetInternalsHTMLSource);
146 };
147 144
148 // This class receives javascript messages from the renderer. 145 // This class receives javascript messages from the renderer.
149 // Note that the WebUI infrastructure runs on the UI thread, therefore all of 146 // Note that the WebUI infrastructure runs on the UI thread, therefore all of
150 // this class's methods are expected to run on the UI thread. 147 // this class's methods are expected to run on the UI thread.
151 // 148 //
152 // Since the network code we want to run lives on the IO thread, we proxy 149 // Since the network code we want to run lives on the IO thread, we proxy
153 // almost everything over to NetInternalsMessageHandler::IOThreadImpl, which 150 // almost everything over to NetInternalsMessageHandler::IOThreadImpl, which
154 // runs on the IO thread. 151 // runs on the IO thread.
155 // 152 //
156 // TODO(eroman): Can we start on the IO thread to begin with? 153 // TODO(eroman): Can we start on the IO thread to begin with?
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 } 440 }
444 } 441 }
445 442
446 private: 443 private:
447 scoped_refptr<IOThreadImpl> instance_; 444 scoped_refptr<IOThreadImpl> instance_;
448 IOThreadImpl::MessageHandler method_; 445 IOThreadImpl::MessageHandler method_;
449 }; 446 };
450 447
451 //////////////////////////////////////////////////////////////////////////////// 448 ////////////////////////////////////////////////////////////////////////////////
452 // 449 //
453 // NetInternalsHTMLSource
454 //
455 ////////////////////////////////////////////////////////////////////////////////
456
457 NetInternalsHTMLSource::NetInternalsHTMLSource()
458 : DataSource(chrome::kChromeUINetInternalsHost, MessageLoop::current()) {
459 }
460
461 void NetInternalsHTMLSource::StartDataRequest(const std::string& path,
462 bool is_incognito,
463 int request_id) {
464 DictionaryValue localized_strings;
465 SetFontAndTextDirection(&localized_strings);
466
467 // The provided "path" may contain a fragment, or query section. We only
468 // care about the path itself, and will disregard anything else.
469 std::string filename =
470 GURL(std::string("chrome://net/") + path).path().substr(1);
471
472 // The source for the net internals page is flattened during compilation, so
473 // the only resource that should legitimately be requested is the main file.
474 // Note that users can type anything into the address bar, though, so we must
475 // handle arbitrary input.
476 if (filename.empty() || filename == "index.html") {
477 base::StringPiece html(
478 ResourceBundle::GetSharedInstance().GetRawDataResource(
479 IDR_NET_INTERNALS_INDEX_HTML));
480 std::string full_html(html.data(), html.size());
481 jstemplate_builder::AppendJsonHtml(&localized_strings, &full_html);
482 jstemplate_builder::AppendI18nTemplateSourceHtml(&full_html);
483 jstemplate_builder::AppendI18nTemplateProcessHtml(&full_html);
484 jstemplate_builder::AppendJsTemplateSourceHtml(&full_html);
485
486 SendResponse(request_id, base::RefCountedString::TakeString(&full_html));
487 return;
488 }
489
490 std::string data_string("<p style='color:red'>Failed to read resource" +
491 EscapeForHTML(filename) + "</p>");
492 SendResponse(request_id, base::RefCountedString::TakeString(&data_string));
493 }
494
495 std::string NetInternalsHTMLSource::GetMimeType(const std::string&) const {
496 return "text/html";
497 }
498
499 ////////////////////////////////////////////////////////////////////////////////
500 //
501 // NetInternalsMessageHandler 450 // NetInternalsMessageHandler
502 // 451 //
503 //////////////////////////////////////////////////////////////////////////////// 452 ////////////////////////////////////////////////////////////////////////////////
504 453
505 NetInternalsMessageHandler::NetInternalsMessageHandler() {} 454 NetInternalsMessageHandler::NetInternalsMessageHandler() {}
506 455
507 NetInternalsMessageHandler::~NetInternalsMessageHandler() { 456 NetInternalsMessageHandler::~NetInternalsMessageHandler() {
508 if (proxy_) { 457 if (proxy_) {
509 proxy_.get()->OnWebUIDeleted(); 458 proxy_.get()->OnWebUIDeleted();
510 // Notify the handler on the IO thread that the renderer is gone. 459 // Notify the handler on the IO thread that the renderer is gone.
(...skipping 1091 matching lines...) Expand 10 before | Expand all | Expand 10 after
1602 // Pass it as a string, since it may be too large to fit in an integer. 1551 // Pass it as a string, since it may be too large to fit in an integer.
1603 constants_dict->SetString("timeTickOffset", 1552 constants_dict->SetString("timeTickOffset",
1604 base::Int64ToString(tick_to_unix_time_ms)); 1553 base::Int64ToString(tick_to_unix_time_ms));
1605 } 1554 }
1606 return constants_dict; 1555 return constants_dict;
1607 } 1556 }
1608 1557
1609 NetInternalsUI::NetInternalsUI(TabContents* contents) : ChromeWebUI(contents) { 1558 NetInternalsUI::NetInternalsUI(TabContents* contents) : ChromeWebUI(contents) {
1610 AddMessageHandler((new NetInternalsMessageHandler())->Attach(this)); 1559 AddMessageHandler((new NetInternalsMessageHandler())->Attach(this));
1611 1560
1612 NetInternalsHTMLSource* html_source = new NetInternalsHTMLSource();
1613
1614 // Set up the chrome://net-internals/ source. 1561 // Set up the chrome://net-internals/ source.
1615 GetProfile()->GetChromeURLDataManager()->AddDataSource(html_source); 1562 GetProfile()->GetChromeURLDataManager()->AddDataSource(
1563 CreateNetInternalsHTMLSource());
1616 } 1564 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/net_internals_resources.grd ('k') | chrome/test/functional/special_tabs.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698