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

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

Issue 7277010: Apply CSP to about:conflicts page. (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/conflicts_ui.h" 5 #include "chrome/browser/ui/webui/conflicts_ui.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/string_number_conversions.h" 11 #include "base/string_number_conversions.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/enumerate_modules_model_win.h" 14 #include "chrome/browser/enumerate_modules_model_win.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 16 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
17 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
17 #include "chrome/common/chrome_notification_types.h" 18 #include "chrome/common/chrome_notification_types.h"
18 #include "chrome/common/jstemplate_builder.h" 19 #include "chrome/common/jstemplate_builder.h"
19 #include "chrome/common/url_constants.h" 20 #include "chrome/common/url_constants.h"
20 #include "content/browser/tab_contents/tab_contents.h" 21 #include "content/browser/tab_contents/tab_contents.h"
21 #include "content/browser/user_metrics.h" 22 #include "content/browser/user_metrics.h"
22 #include "content/common/notification_observer.h" 23 #include "content/common/notification_observer.h"
23 #include "content/common/notification_registrar.h" 24 #include "content/common/notification_registrar.h"
24 #include "content/common/notification_service.h" 25 #include "content/common/notification_service.h"
25 #include "grit/browser_resources.h" 26 #include "grit/browser_resources.h"
26 #include "grit/chromium_strings.h" 27 #include "grit/chromium_strings.h"
27 #include "grit/generated_resources.h" 28 #include "grit/generated_resources.h"
28 #include "grit/theme_resources.h" 29 #include "grit/theme_resources.h"
29 #include "grit/theme_resources_standard.h" 30 #include "grit/theme_resources_standard.h"
30 #include "ui/base/l10n/l10n_util.h" 31 #include "ui/base/l10n/l10n_util.h"
31 #include "ui/base/resource/resource_bundle.h" 32 #include "ui/base/resource/resource_bundle.h"
32 33
33 namespace { 34 namespace {
34 35
35 //////////////////////////////////////////////////////////////////////////////// 36 ChromeWebUIDataSource* CreateConflictsUIHTMLSource() {
36 // 37 ChromeWebUIDataSource* source =
37 // ConflictsUIHTMLSource 38 new ChromeWebUIDataSource(chrome::kChromeUIConflictsHost);
38 //
39 ////////////////////////////////////////////////////////////////////////////////
40 39
41 class ConflictsUIHTMLSource : public ChromeURLDataManager::DataSource { 40 source->AddLocalizedString("loadingMessage", IDS_CONFLICTS_LOADING_MESSAGE);
42 public: 41 source->AddLocalizedString("modulesLongTitle",
43 ConflictsUIHTMLSource() 42 IDS_CONFLICTS_CHECK_PAGE_TITLE_LONG);
44 : DataSource(chrome::kChromeUIConflictsHost, MessageLoop::current()) {} 43 source->AddLocalizedString("modulesBlurb", IDS_CONFLICTS_EXPLANATION_TEXT);
45 44 source->AddLocalizedString("moduleSuspectedBad",
46 // Called when the network layer has requested a resource underneath 45 IDS_CONFLICTS_CHECK_WARNING_SUSPECTED);
47 // the path we registered. 46 source->AddLocalizedString("moduleConfirmedBad",
48 virtual void StartDataRequest(const std::string& path, 47 IDS_CONFLICTS_CHECK_WARNING_CONFIRMED);
49 bool is_incognito, 48 source->AddLocalizedString("helpCenterLink", IDS_CONFLICTS_HELP_CENTER_LINK);
50 int request_id); 49 source->AddLocalizedString("investigatingText",
51 50 IDS_CONFLICTS_CHECK_INVESTIGATING);
52 virtual std::string GetMimeType(const std::string&) const { 51 source->AddLocalizedString("modulesNoneLoaded",
53 return "text/html"; 52 IDS_CONFLICTS_NO_MODULES_LOADED);
54 } 53 source->AddLocalizedString("headerSoftware", IDS_CONFLICTS_HEADER_SOFTWARE);
55 54 source->AddLocalizedString("headerSignedBy", IDS_CONFLICTS_HEADER_SIGNED_BY);
56 private: 55 source->AddLocalizedString("headerLocation", IDS_CONFLICTS_HEADER_LOCATION);
57 DISALLOW_COPY_AND_ASSIGN(ConflictsUIHTMLSource); 56 source->AddLocalizedString("headerVersion", IDS_CONFLICTS_HEADER_VERSION);
58 }; 57 source->AddLocalizedString("headerHelpTip", IDS_CONFLICTS_HEADER_HELP_TIP);
59 58 source->set_json_path("strings.js");
60 void ConflictsUIHTMLSource::StartDataRequest(const std::string& path, 59 source->add_resource_path("conflicts.js", IDR_ABOUT_CONFLICTS_JS);
61 bool is_incognito, 60 source->set_default_resource(IDR_ABOUT_CONFLICTS_HTML);
62 int request_id) { 61 return source;
63 // Strings used in the JsTemplate file.
64 DictionaryValue localized_strings;
65 localized_strings.SetString("loadingMessage",
66 l10n_util::GetStringUTF16(IDS_CONFLICTS_LOADING_MESSAGE));
67 localized_strings.SetString("modulesLongTitle",
68 l10n_util::GetStringUTF16(IDS_CONFLICTS_CHECK_PAGE_TITLE_LONG));
69 localized_strings.SetString("modulesBlurb",
70 l10n_util::GetStringUTF16(IDS_CONFLICTS_EXPLANATION_TEXT));
71 localized_strings.SetString("moduleSuspectedBad",
72 l10n_util::GetStringUTF16(IDS_CONFLICTS_CHECK_WARNING_SUSPECTED));
73 localized_strings.SetString("moduleConfirmedBad",
74 l10n_util::GetStringUTF16(IDS_CONFLICTS_CHECK_WARNING_CONFIRMED));
75 localized_strings.SetString("helpCenterLink",
76 l10n_util::GetStringUTF16(IDS_CONFLICTS_HELP_CENTER_LINK));
77 localized_strings.SetString("investigatingText",
78 l10n_util::GetStringUTF16(IDS_CONFLICTS_CHECK_INVESTIGATING));
79 localized_strings.SetString("modulesNoneLoaded",
80 l10n_util::GetStringUTF16(IDS_CONFLICTS_NO_MODULES_LOADED));
81 localized_strings.SetString("headerSoftware",
82 l10n_util::GetStringUTF16(IDS_CONFLICTS_HEADER_SOFTWARE));
83 localized_strings.SetString("headerSignedBy",
84 l10n_util::GetStringUTF16(IDS_CONFLICTS_HEADER_SIGNED_BY));
85 localized_strings.SetString("headerLocation",
86 l10n_util::GetStringUTF16(IDS_CONFLICTS_HEADER_LOCATION));
87 localized_strings.SetString("headerVersion",
88 l10n_util::GetStringUTF16(IDS_CONFLICTS_HEADER_VERSION));
89 localized_strings.SetString("headerHelpTip",
90 l10n_util::GetStringUTF16(IDS_CONFLICTS_HEADER_HELP_TIP));
91
92 ChromeURLDataManager::DataSource::SetFontAndTextDirection(&localized_strings);
93
94 static const base::StringPiece flags_html(
95 ResourceBundle::GetSharedInstance().GetRawDataResource(
96 IDR_ABOUT_CONFLICTS_HTML));
97 std::string full_html(flags_html.data(), flags_html.size());
98 jstemplate_builder::AppendJsonHtml(&localized_strings, &full_html);
99 jstemplate_builder::AppendI18nTemplateSourceHtml(&full_html);
100 jstemplate_builder::AppendI18nTemplateProcessHtml(&full_html);
101 jstemplate_builder::AppendJsTemplateSourceHtml(&full_html);
102
103 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes);
104 html_bytes->data.resize(full_html.size());
105 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin());
106
107 SendResponse(request_id, html_bytes);
108 } 62 }
109 63
110 //////////////////////////////////////////////////////////////////////////////// 64 ////////////////////////////////////////////////////////////////////////////////
111 // 65 //
112 // ConflictsDOMHandler 66 // ConflictsDOMHandler
113 // 67 //
114 //////////////////////////////////////////////////////////////////////////////// 68 ////////////////////////////////////////////////////////////////////////////////
115 69
116 // The handler for JavaScript messages for the about:flags page. 70 // The handler for JavaScript messages for the about:flags page.
117 class ConflictsDOMHandler : public WebUIMessageHandler, 71 class ConflictsDOMHandler : public WebUIMessageHandler,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 146
193 } // namespace 147 } // namespace
194 148
195 /////////////////////////////////////////////////////////////////////////////// 149 ///////////////////////////////////////////////////////////////////////////////
196 // 150 //
197 // ConflictsUI 151 // ConflictsUI
198 // 152 //
199 /////////////////////////////////////////////////////////////////////////////// 153 ///////////////////////////////////////////////////////////////////////////////
200 154
201 ConflictsUI::ConflictsUI(TabContents* contents) : ChromeWebUI(contents) { 155 ConflictsUI::ConflictsUI(TabContents* contents) : ChromeWebUI(contents) {
202 UserMetrics::RecordAction( 156 UserMetrics::RecordAction(UserMetricsAction("ViewAboutConflicts"));
203 UserMetricsAction("ViewAboutConflicts"));
204
205 AddMessageHandler((new ConflictsDOMHandler())->Attach(this)); 157 AddMessageHandler((new ConflictsDOMHandler())->Attach(this));
206 158
207 ConflictsUIHTMLSource* html_source = new ConflictsUIHTMLSource();
208
209 // Set up the about:conflicts source. 159 // Set up the about:conflicts source.
210 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source); 160 contents->profile()->GetChromeURLDataManager()->AddDataSource(
161 CreateConflictsUIHTMLSource());
211 } 162 }
212 163
213 // static 164 // static
214 RefCountedMemory* ConflictsUI::GetFaviconResourceBytes() { 165 RefCountedMemory* ConflictsUI::GetFaviconResourceBytes() {
215 return ResourceBundle::GetSharedInstance(). 166 return ResourceBundle::GetSharedInstance().
216 LoadDataResourceBytes(IDR_CONFLICT_FAVICON); 167 LoadDataResourceBytes(IDR_CONFLICT_FAVICON);
217 } 168 }
218 169
219 #endif 170 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698