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

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

Issue 7276009: Add content-security-policy directive to chrome://crashes 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
« no previous file with comments | « chrome/browser/resources/crashes.html ('k') | chrome/test/functional/special_tabs.py » ('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/crashes_ui.h" 5 #include "chrome/browser/ui/webui/crashes_ui.h"
6 6
7 #include "base/i18n/time_formatting.h" 7 #include "base/i18n/time_formatting.h"
8 #include "base/memory/ref_counted_memory.h" 8 #include "base/memory/ref_counted_memory.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/crash_upload_list.h" 12 #include "chrome/browser/crash_upload_list.h"
13 #include "chrome/browser/prefs/pref_service.h" 13 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" 15 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
16 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h"
16 #include "chrome/common/chrome_version_info.h" 17 #include "chrome/common/chrome_version_info.h"
17 #include "chrome/common/jstemplate_builder.h" 18 #include "chrome/common/jstemplate_builder.h"
18 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.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 "grit/browser_resources.h" 22 #include "grit/browser_resources.h"
22 #include "grit/chromium_strings.h" 23 #include "grit/chromium_strings.h"
23 #include "grit/generated_resources.h" 24 #include "grit/generated_resources.h"
24 #include "grit/theme_resources.h" 25 #include "grit/theme_resources.h"
25 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
26 #include "ui/base/resource/resource_bundle.h" 27 #include "ui/base/resource/resource_bundle.h"
27 28
28 #if defined(OS_CHROMEOS) 29 #if defined(OS_CHROMEOS)
29 #include "chrome/browser/chromeos/metrics_cros_settings_provider.h" 30 #include "chrome/browser/chromeos/metrics_cros_settings_provider.h"
30 #endif 31 #endif
31 32
32 namespace { 33 namespace {
33 34
34 /////////////////////////////////////////////////////////////////////////////// 35 ChromeWebUIDataSource* CreateCrashesUIHTMLSource() {
35 // 36 ChromeWebUIDataSource* source =
36 // CrashesUIHTMLSource 37 new ChromeWebUIDataSource(chrome::kChromeUICrashesHost);
37 //
38 ///////////////////////////////////////////////////////////////////////////////
39 38
40 class CrashesUIHTMLSource : public ChromeURLDataManager::DataSource { 39 source->AddLocalizedString("crashesTitle",IDS_CRASHES_TITLE);
41 public: 40 source->AddLocalizedString("crashCountFormat",
42 CrashesUIHTMLSource() 41 IDS_CRASHES_CRASH_COUNT_BANNER_FORMAT);
43 : DataSource(chrome::kChromeUICrashesHost, MessageLoop::current()) {} 42 source->AddLocalizedString("crashHeaderFormat",
44 43 IDS_CRASHES_CRASH_HEADER_FORMAT);
45 // Called when the network layer has requested a resource underneath 44 source->AddLocalizedString("crashTimeFormat", IDS_CRASHES_CRASH_TIME_FORMAT);
46 // the path we registered. 45 source->AddLocalizedString("bugLinkText", IDS_CRASHES_BUG_LINK_LABEL);
47 virtual void StartDataRequest(const std::string& path, 46 source->AddLocalizedString("noCrashesMessage",
48 bool is_incognito, 47 IDS_CRASHES_NO_CRASHES_MESSAGE);
49 int request_id); 48 source->AddLocalizedString("disabledHeader", IDS_CRASHES_DISABLED_HEADER);
50 virtual std::string GetMimeType(const std::string&) const { 49 source->AddLocalizedString("disabledMessage", IDS_CRASHES_DISABLED_MESSAGE);
51 return "text/html"; 50 source->set_json_path("strings.js");
52 } 51 source->add_resource_path("crashes.js", IDR_CRASHES_JS);
53 52 source->set_default_resource(IDR_CRASHES_HTML);
54 private: 53 return source;
55 ~CrashesUIHTMLSource() {}
56
57 DISALLOW_COPY_AND_ASSIGN(CrashesUIHTMLSource);
58 };
59
60 void CrashesUIHTMLSource::StartDataRequest(const std::string& path,
61 bool is_incognito,
62 int request_id) {
63 DictionaryValue localized_strings;
64 localized_strings.SetString("crashesTitle",
65 l10n_util::GetStringUTF16(IDS_CRASHES_TITLE));
66 localized_strings.SetString("crashCountFormat",
67 l10n_util::GetStringUTF16(IDS_CRASHES_CRASH_COUNT_BANNER_FORMAT));
68 localized_strings.SetString("crashHeaderFormat",
69 l10n_util::GetStringUTF16(IDS_CRASHES_CRASH_HEADER_FORMAT));
70 localized_strings.SetString("crashTimeFormat",
71 l10n_util::GetStringUTF16(IDS_CRASHES_CRASH_TIME_FORMAT));
72 localized_strings.SetString("bugLinkText",
73 l10n_util::GetStringUTF16(IDS_CRASHES_BUG_LINK_LABEL));
74 localized_strings.SetString("noCrashesMessage",
75 l10n_util::GetStringUTF16(IDS_CRASHES_NO_CRASHES_MESSAGE));
76 localized_strings.SetString("disabledHeader",
77 l10n_util::GetStringUTF16(IDS_CRASHES_DISABLED_HEADER));
78 localized_strings.SetString("disabledMessage",
79 l10n_util::GetStringUTF16(IDS_CRASHES_DISABLED_MESSAGE));
80
81 ChromeURLDataManager::DataSource::SetFontAndTextDirection(&localized_strings);
82
83 static const base::StringPiece crashes_html(
84 ResourceBundle::GetSharedInstance().GetRawDataResource(IDR_CRASHES_HTML));
85 std::string full_html =
86 jstemplate_builder::GetI18nTemplateHtml(crashes_html, &localized_strings);
87 jstemplate_builder::AppendJsTemplateSourceHtml(&full_html);
88
89 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes);
90 html_bytes->data.resize(full_html.size());
91 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin());
92
93 SendResponse(request_id, html_bytes);
94 } 54 }
95 55
96 //////////////////////////////////////////////////////////////////////////////// 56 ////////////////////////////////////////////////////////////////////////////////
97 // 57 //
98 // CrashesDOMHandler 58 // CrashesDOMHandler
99 // 59 //
100 //////////////////////////////////////////////////////////////////////////////// 60 ////////////////////////////////////////////////////////////////////////////////
101 61
102 // The handler for Javascript messages for the chrome://crashes/ page. 62 // The handler for Javascript messages for the chrome://crashes/ page.
103 class CrashesDOMHandler : public WebUIMessageHandler, 63 class CrashesDOMHandler : public WebUIMessageHandler,
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 150
191 /////////////////////////////////////////////////////////////////////////////// 151 ///////////////////////////////////////////////////////////////////////////////
192 // 152 //
193 // CrashesUI 153 // CrashesUI
194 // 154 //
195 /////////////////////////////////////////////////////////////////////////////// 155 ///////////////////////////////////////////////////////////////////////////////
196 156
197 CrashesUI::CrashesUI(TabContents* contents) : ChromeWebUI(contents) { 157 CrashesUI::CrashesUI(TabContents* contents) : ChromeWebUI(contents) {
198 AddMessageHandler((new CrashesDOMHandler())->Attach(this)); 158 AddMessageHandler((new CrashesDOMHandler())->Attach(this));
199 159
200 CrashesUIHTMLSource* html_source = new CrashesUIHTMLSource();
201
202 // Set up the chrome://crashes/ source. 160 // Set up the chrome://crashes/ source.
203 contents->profile()->GetChromeURLDataManager()->AddDataSource(html_source); 161 contents->profile()->GetChromeURLDataManager()->AddDataSource(
162 CreateCrashesUIHTMLSource());
204 } 163 }
205 164
206 // static 165 // static
207 RefCountedMemory* CrashesUI::GetFaviconResourceBytes() { 166 RefCountedMemory* CrashesUI::GetFaviconResourceBytes() {
208 return ResourceBundle::GetSharedInstance(). 167 return ResourceBundle::GetSharedInstance().
209 LoadDataResourceBytes(IDR_SAD_FAVICON); 168 LoadDataResourceBytes(IDR_SAD_FAVICON);
210 } 169 }
211 170
212 // static 171 // static
213 bool CrashesUI::CrashReportingEnabled() { 172 bool CrashesUI::CrashReportingEnabled() {
214 #if defined(GOOGLE_CHROME_BUILD) && !defined(OS_CHROMEOS) 173 #if defined(GOOGLE_CHROME_BUILD) && !defined(OS_CHROMEOS)
215 PrefService* prefs = g_browser_process->local_state(); 174 PrefService* prefs = g_browser_process->local_state();
216 return prefs->GetBoolean(prefs::kMetricsReportingEnabled); 175 return prefs->GetBoolean(prefs::kMetricsReportingEnabled);
217 #elif defined(GOOGLE_CHROME_BUILD) && defined(OS_CHROMEOS) 176 #elif defined(GOOGLE_CHROME_BUILD) && defined(OS_CHROMEOS)
218 return chromeos::MetricsCrosSettingsProvider::GetMetricsStatus(); 177 return chromeos::MetricsCrosSettingsProvider::GetMetricsStatus();
219 #else 178 #else
220 return false; 179 return false;
221 #endif 180 #endif
222 } 181 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/crashes.html ('k') | chrome/test/functional/special_tabs.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698