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

Side by Side Diff: chrome/browser/ui/webui/options/options_ui.cc

Issue 7003007: Apply content-security-policy to the HTML options page. This is a (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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/options/options_ui.h" 5 #include "chrome/browser/ui/webui/options/options_ui.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 #include "chrome/browser/ui/webui/options/chromeos/proxy_handler.h" 66 #include "chrome/browser/ui/webui/options/chromeos/proxy_handler.h"
67 #include "chrome/browser/ui/webui/options/chromeos/stats_options_handler.h" 67 #include "chrome/browser/ui/webui/options/chromeos/stats_options_handler.h"
68 #include "chrome/browser/ui/webui/options/chromeos/system_options_handler.h" 68 #include "chrome/browser/ui/webui/options/chromeos/system_options_handler.h"
69 #include "chrome/browser/ui/webui/options/chromeos/user_image_source.h" 69 #include "chrome/browser/ui/webui/options/chromeos/user_image_source.h"
70 #endif 70 #endif
71 71
72 #if defined(USE_NSS) 72 #if defined(USE_NSS)
73 #include "chrome/browser/ui/webui/options/certificate_manager_handler.h" 73 #include "chrome/browser/ui/webui/options/certificate_manager_handler.h"
74 #endif 74 #endif
75 75
76 static const char kLocalizedStringsFile[] = "strings.js";
77
76 //////////////////////////////////////////////////////////////////////////////// 78 ////////////////////////////////////////////////////////////////////////////////
77 // 79 //
78 // OptionsUIHTMLSource 80 // OptionsUIHTMLSource
79 // 81 //
80 //////////////////////////////////////////////////////////////////////////////// 82 ////////////////////////////////////////////////////////////////////////////////
81 83
82 class OptionsUIHTMLSource : public ChromeURLDataManager::DataSource { 84 class OptionsUIHTMLSource : public ChromeURLDataManager::DataSource {
83 public: 85 public:
84 // The constructor takes over ownership of |localized_strings|. 86 // The constructor takes over ownership of |localized_strings|.
85 explicit OptionsUIHTMLSource(DictionaryValue* localized_strings); 87 explicit OptionsUIHTMLSource(DictionaryValue* localized_strings);
(...skipping 17 matching lines...) Expand all
103 : DataSource(chrome::kChromeUISettingsHost, MessageLoop::current()) { 105 : DataSource(chrome::kChromeUISettingsHost, MessageLoop::current()) {
104 DCHECK(localized_strings); 106 DCHECK(localized_strings);
105 localized_strings_.reset(localized_strings); 107 localized_strings_.reset(localized_strings);
106 } 108 }
107 109
108 OptionsUIHTMLSource::~OptionsUIHTMLSource() {} 110 OptionsUIHTMLSource::~OptionsUIHTMLSource() {}
109 111
110 void OptionsUIHTMLSource::StartDataRequest(const std::string& path, 112 void OptionsUIHTMLSource::StartDataRequest(const std::string& path,
111 bool is_incognito, 113 bool is_incognito,
112 int request_id) { 114 int request_id) {
115 scoped_refptr<RefCountedBytes> response_bytes(new RefCountedBytes);
113 SetFontAndTextDirection(localized_strings_.get()); 116 SetFontAndTextDirection(localized_strings_.get());
114 117
115 static const base::StringPiece options_html( 118 if (path == kLocalizedStringsFile) {
116 ResourceBundle::GetSharedInstance().GetRawDataResource( 119 std::string template_data;
117 IDR_OPTIONS_HTML)); 120 jstemplate_builder::AppendJsonJS(localized_strings_.get(), &template_data);
118 const std::string full_html = jstemplate_builder::GetI18nTemplateHtml( 121 response_bytes->data.resize(template_data.size());
119 options_html, localized_strings_.get()); 122 std::copy(template_data.begin(),
123 template_data.end(),
124 response_bytes->data.begin());
125 } else {
126 static const base::StringPiece options_html(
127 ResourceBundle::GetSharedInstance().GetRawDataResource(
128 IDR_OPTIONS_HTML));
129 response_bytes->data.resize(options_html.size());
130 std::copy(options_html.begin(),
131 options_html.end(),
132 response_bytes->data.begin());
133 }
120 134
121 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); 135 SendResponse(request_id, response_bytes);
122 html_bytes->data.resize(full_html.size());
123 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin());
124
125 SendResponse(request_id, html_bytes);
126 } 136 }
127 137
128 std::string OptionsUIHTMLSource::GetMimeType(const std::string&) const { 138 std::string OptionsUIHTMLSource::GetMimeType(const std::string& path) const {
139 if (path == kLocalizedStringsFile)
140 return "application/javascript";
141
129 return "text/html"; 142 return "text/html";
130 } 143 }
131 144
132 //////////////////////////////////////////////////////////////////////////////// 145 ////////////////////////////////////////////////////////////////////////////////
133 // 146 //
134 // OptionsPageUIHandler 147 // OptionsPageUIHandler
135 // 148 //
136 //////////////////////////////////////////////////////////////////////////////// 149 ////////////////////////////////////////////////////////////////////////////////
137 150
138 OptionsPageUIHandler::OptionsPageUIHandler() { 151 OptionsPageUIHandler::OptionsPageUIHandler() {
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 OptionsPageUIHandler* handler_raw) { 338 OptionsPageUIHandler* handler_raw) {
326 scoped_ptr<OptionsPageUIHandler> handler(handler_raw); 339 scoped_ptr<OptionsPageUIHandler> handler(handler_raw);
327 DCHECK(handler.get()); 340 DCHECK(handler.get());
328 // Add only if handler's service is enabled. 341 // Add only if handler's service is enabled.
329 if (handler->IsEnabled()) { 342 if (handler->IsEnabled()) {
330 handler->GetLocalizedValues(localized_strings); 343 handler->GetLocalizedValues(localized_strings);
331 // Add handler to the list and also pass the ownership. 344 // Add handler to the list and also pass the ownership.
332 AddMessageHandler(handler.release()->Attach(this)); 345 AddMessageHandler(handler.release()->Attach(this));
333 } 346 }
334 } 347 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698