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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/webui/net_internals_ui.cc
===================================================================
--- chrome/browser/ui/webui/net_internals_ui.cc (revision 93894)
+++ chrome/browser/ui/webui/net_internals_ui.cc (working copy)
@@ -32,6 +32,7 @@
#include "chrome/browser/prerender/prerender_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/webui/chrome_url_data_manager.h"
+#include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
#include "chrome/common/chrome_notification_types.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_version_info.h"
@@ -129,22 +130,18 @@
return dict;
}
-class NetInternalsHTMLSource : public ChromeURLDataManager::DataSource {
- public:
- NetInternalsHTMLSource();
+ChromeWebUIDataSource* CreateNetInternalsHTMLSource() {
+ ChromeWebUIDataSource* source =
+ new ChromeWebUIDataSource(chrome::kChromeUINetInternalsHost);
- // Called when the network layer has requested a resource underneath
- // the path we registered.
- virtual void StartDataRequest(const std::string& path,
- bool is_incognito,
- int request_id);
- virtual std::string GetMimeType(const std::string&) const;
+ source->set_default_resource(IDR_NET_INTERNALS_INDEX_HTML);
+ source->add_resource_path("help.html", IDR_NET_INTERNALS_HELP_HTML);
+ source->add_resource_path("help.js", IDR_NET_INTERNALS_HELP_JS);
+ source->add_resource_path("index.js", IDR_NET_INTERNALS_INDEX_JS);
+ source->set_json_path("strings.js");
+ return source;
+}
- private:
- ~NetInternalsHTMLSource() {}
- DISALLOW_COPY_AND_ASSIGN(NetInternalsHTMLSource);
-};
-
// This class receives javascript messages from the renderer.
// Note that the WebUI infrastructure runs on the UI thread, therefore all of
// this class's methods are expected to run on the UI thread.
@@ -450,54 +447,6 @@
////////////////////////////////////////////////////////////////////////////////
//
-// NetInternalsHTMLSource
-//
-////////////////////////////////////////////////////////////////////////////////
-
-NetInternalsHTMLSource::NetInternalsHTMLSource()
- : DataSource(chrome::kChromeUINetInternalsHost, MessageLoop::current()) {
-}
-
-void NetInternalsHTMLSource::StartDataRequest(const std::string& path,
- bool is_incognito,
- int request_id) {
- DictionaryValue localized_strings;
- SetFontAndTextDirection(&localized_strings);
-
- // The provided "path" may contain a fragment, or query section. We only
- // care about the path itself, and will disregard anything else.
- std::string filename =
- GURL(std::string("chrome://net/") + path).path().substr(1);
-
- // The source for the net internals page is flattened during compilation, so
- // the only resource that should legitimately be requested is the main file.
- // Note that users can type anything into the address bar, though, so we must
- // handle arbitrary input.
- if (filename.empty() || filename == "index.html") {
- base::StringPiece html(
- ResourceBundle::GetSharedInstance().GetRawDataResource(
- IDR_NET_INTERNALS_INDEX_HTML));
- std::string full_html(html.data(), html.size());
- jstemplate_builder::AppendJsonHtml(&localized_strings, &full_html);
- jstemplate_builder::AppendI18nTemplateSourceHtml(&full_html);
- jstemplate_builder::AppendI18nTemplateProcessHtml(&full_html);
- jstemplate_builder::AppendJsTemplateSourceHtml(&full_html);
-
- SendResponse(request_id, base::RefCountedString::TakeString(&full_html));
- return;
- }
-
- std::string data_string("<p style='color:red'>Failed to read resource" +
- EscapeForHTML(filename) + "</p>");
- SendResponse(request_id, base::RefCountedString::TakeString(&data_string));
-}
-
-std::string NetInternalsHTMLSource::GetMimeType(const std::string&) const {
- return "text/html";
-}
-
-////////////////////////////////////////////////////////////////////////////////
-//
// NetInternalsMessageHandler
//
////////////////////////////////////////////////////////////////////////////////
@@ -1609,8 +1558,7 @@
NetInternalsUI::NetInternalsUI(TabContents* contents) : ChromeWebUI(contents) {
AddMessageHandler((new NetInternalsMessageHandler())->Attach(this));
- NetInternalsHTMLSource* html_source = new NetInternalsHTMLSource();
-
// Set up the chrome://net-internals/ source.
- GetProfile()->GetChromeURLDataManager()->AddDataSource(html_source);
+ GetProfile()->GetChromeURLDataManager()->AddDataSource(
+ CreateNetInternalsHTMLSource());
}
« 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