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

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
« no previous file with comments | « chrome/browser/resources/shared_resources.grd ('k') | chrome/chrome.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 26 matching lines...) Expand all
37 #include "chrome/browser/ui/webui/theme_source.h" 37 #include "chrome/browser/ui/webui/theme_source.h"
38 #include "chrome/common/jstemplate_builder.h" 38 #include "chrome/common/jstemplate_builder.h"
39 #include "chrome/common/time_format.h" 39 #include "chrome/common/time_format.h"
40 #include "chrome/common/url_constants.h" 40 #include "chrome/common/url_constants.h"
41 #include "content/browser/browser_thread.h" 41 #include "content/browser/browser_thread.h"
42 #include "content/browser/renderer_host/render_view_host.h" 42 #include "content/browser/renderer_host/render_view_host.h"
43 #include "content/browser/tab_contents/tab_contents.h" 43 #include "content/browser/tab_contents/tab_contents.h"
44 #include "content/browser/tab_contents/tab_contents_delegate.h" 44 #include "content/browser/tab_contents/tab_contents_delegate.h"
45 #include "content/browser/user_metrics.h" 45 #include "content/browser/user_metrics.h"
46 #include "content/common/notification_type.h" 46 #include "content/common/notification_type.h"
47 #include "grit/browser_resources.h"
48 #include "grit/chromium_strings.h" 47 #include "grit/chromium_strings.h"
49 #include "grit/generated_resources.h" 48 #include "grit/generated_resources.h"
50 #include "grit/locale_settings.h" 49 #include "grit/locale_settings.h"
50 #include "grit/options_resources.h"
51 #include "grit/theme_resources.h" 51 #include "grit/theme_resources.h"
52 #include "net/base/escape.h" 52 #include "net/base/escape.h"
53 #include "ui/base/resource/resource_bundle.h" 53 #include "ui/base/resource/resource_bundle.h"
54 54
55 #if defined(OS_CHROMEOS) 55 #if defined(OS_CHROMEOS)
56 #include "chrome/browser/ui/webui/options/chromeos/accounts_options_handler.h" 56 #include "chrome/browser/ui/webui/options/chromeos/accounts_options_handler.h"
57 #include "chrome/browser/ui/webui/options/chromeos/change_picture_options_handle r.h" 57 #include "chrome/browser/ui/webui/options/chromeos/change_picture_options_handle r.h"
58 #include "chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler .h" 58 #include "chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler .h"
59 #include "chrome/browser/ui/webui/options/chromeos/cros_language_options_handler .h" 59 #include "chrome/browser/ui/webui/options/chromeos/cros_language_options_handler .h"
60 #include "chrome/browser/ui/webui/options/chromeos/internet_options_handler.h" 60 #include "chrome/browser/ui/webui/options/chromeos/internet_options_handler.h"
61 #include "chrome/browser/ui/webui/options/chromeos/language_chewing_handler.h" 61 #include "chrome/browser/ui/webui/options/chromeos/language_chewing_handler.h"
62 #include "chrome/browser/ui/webui/options/chromeos/language_customize_modifier_k eys_handler.h" 62 #include "chrome/browser/ui/webui/options/chromeos/language_customize_modifier_k eys_handler.h"
63 #include "chrome/browser/ui/webui/options/chromeos/language_hangul_handler.h" 63 #include "chrome/browser/ui/webui/options/chromeos/language_hangul_handler.h"
64 #include "chrome/browser/ui/webui/options/chromeos/language_mozc_handler.h" 64 #include "chrome/browser/ui/webui/options/chromeos/language_mozc_handler.h"
65 #include "chrome/browser/ui/webui/options/chromeos/language_pinyin_handler.h" 65 #include "chrome/browser/ui/webui/options/chromeos/language_pinyin_handler.h"
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 static const char kOptionsBundleJsFile[] = "options_bundle.js";
78
76 //////////////////////////////////////////////////////////////////////////////// 79 ////////////////////////////////////////////////////////////////////////////////
77 // 80 //
78 // OptionsUIHTMLSource 81 // OptionsUIHTMLSource
79 // 82 //
80 //////////////////////////////////////////////////////////////////////////////// 83 ////////////////////////////////////////////////////////////////////////////////
81 84
82 class OptionsUIHTMLSource : public ChromeURLDataManager::DataSource { 85 class OptionsUIHTMLSource : public ChromeURLDataManager::DataSource {
83 public: 86 public:
84 // The constructor takes over ownership of |localized_strings|. 87 // The constructor takes over ownership of |localized_strings|.
85 explicit OptionsUIHTMLSource(DictionaryValue* localized_strings); 88 explicit OptionsUIHTMLSource(DictionaryValue* localized_strings);
(...skipping 17 matching lines...) Expand all
103 : DataSource(chrome::kChromeUISettingsHost, MessageLoop::current()) { 106 : DataSource(chrome::kChromeUISettingsHost, MessageLoop::current()) {
104 DCHECK(localized_strings); 107 DCHECK(localized_strings);
105 localized_strings_.reset(localized_strings); 108 localized_strings_.reset(localized_strings);
106 } 109 }
107 110
108 OptionsUIHTMLSource::~OptionsUIHTMLSource() {} 111 OptionsUIHTMLSource::~OptionsUIHTMLSource() {}
109 112
110 void OptionsUIHTMLSource::StartDataRequest(const std::string& path, 113 void OptionsUIHTMLSource::StartDataRequest(const std::string& path,
111 bool is_incognito, 114 bool is_incognito,
112 int request_id) { 115 int request_id) {
116 scoped_refptr<RefCountedBytes> response_bytes(new RefCountedBytes);
113 SetFontAndTextDirection(localized_strings_.get()); 117 SetFontAndTextDirection(localized_strings_.get());
114 118
115 static const base::StringPiece options_html( 119 if (path == kLocalizedStringsFile) {
116 ResourceBundle::GetSharedInstance().GetRawDataResource( 120 // Return dynamically-generated strings from memory.
117 IDR_OPTIONS_HTML)); 121 std::string template_data;
118 const std::string full_html = jstemplate_builder::GetI18nTemplateHtml( 122 jstemplate_builder::AppendJsonJS(localized_strings_.get(), &template_data);
119 options_html, localized_strings_.get()); 123 response_bytes->data.resize(template_data.size());
124 std::copy(template_data.begin(),
125 template_data.end(),
126 response_bytes->data.begin());
127 } else if (path == kOptionsBundleJsFile) {
128 // Return (and cache) the options javascript code.
129 static const base::StringPiece options_javascript(
130 ResourceBundle::GetSharedInstance().GetRawDataResource(
131 IDR_OPTIONS_BUNDLE_JS));
132 response_bytes->data.resize(options_javascript.size());
133 std::copy(options_javascript.begin(),
134 options_javascript.end(),
135 response_bytes->data.begin());
136 } else {
137 // Return (and cache) the main options html page as the default.
138 static const base::StringPiece options_html(
139 ResourceBundle::GetSharedInstance().GetRawDataResource(
140 IDR_OPTIONS_HTML));
141 response_bytes->data.resize(options_html.size());
142 std::copy(options_html.begin(),
143 options_html.end(),
144 response_bytes->data.begin());
145 }
120 146
121 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); 147 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 } 148 }
127 149
128 std::string OptionsUIHTMLSource::GetMimeType(const std::string&) const { 150 std::string OptionsUIHTMLSource::GetMimeType(const std::string& path) const {
151 if (path == kLocalizedStringsFile || path == kOptionsBundleJsFile)
152 return "application/javascript";
153
129 return "text/html"; 154 return "text/html";
130 } 155 }
131 156
132 //////////////////////////////////////////////////////////////////////////////// 157 ////////////////////////////////////////////////////////////////////////////////
133 // 158 //
134 // OptionsPageUIHandler 159 // OptionsPageUIHandler
135 // 160 //
136 //////////////////////////////////////////////////////////////////////////////// 161 ////////////////////////////////////////////////////////////////////////////////
137 162
138 OptionsPageUIHandler::OptionsPageUIHandler() { 163 OptionsPageUIHandler::OptionsPageUIHandler() {
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 OptionsPageUIHandler* handler_raw) { 350 OptionsPageUIHandler* handler_raw) {
326 scoped_ptr<OptionsPageUIHandler> handler(handler_raw); 351 scoped_ptr<OptionsPageUIHandler> handler(handler_raw);
327 DCHECK(handler.get()); 352 DCHECK(handler.get());
328 // Add only if handler's service is enabled. 353 // Add only if handler's service is enabled.
329 if (handler->IsEnabled()) { 354 if (handler->IsEnabled()) {
330 handler->GetLocalizedValues(localized_strings); 355 handler->GetLocalizedValues(localized_strings);
331 // Add handler to the list and also pass the ownership. 356 // Add handler to the list and also pass the ownership.
332 AddMessageHandler(handler.release()->Attach(this)); 357 AddMessageHandler(handler.release()->Attach(this));
333 } 358 }
334 } 359 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/shared_resources.grd ('k') | chrome/chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698