OLD | NEW |
---|---|
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 |
35 const char kStringsJsPath[] = "strings.js"; | |
36 const char kCrashesJsPath[] = "crashes.js"; | |
37 | |
34 /////////////////////////////////////////////////////////////////////////////// | 38 /////////////////////////////////////////////////////////////////////////////// |
35 // | 39 // |
36 // CrashesUIHTMLSource | 40 // CrashesUIHTMLSource |
37 // | 41 // |
38 /////////////////////////////////////////////////////////////////////////////// | 42 /////////////////////////////////////////////////////////////////////////////// |
39 | 43 |
40 class CrashesUIHTMLSource : public ChromeURLDataManager::DataSource { | 44 class CrashesUIHTMLSource : public ChromeWebUIDataSource { |
41 public: | 45 public: |
42 CrashesUIHTMLSource() | 46 CrashesUIHTMLSource(); |
43 : DataSource(chrome::kChromeUICrashesHost, MessageLoop::current()) {} | |
44 | |
45 // Called when the network layer has requested a resource underneath | |
46 // the path we registered. | |
47 virtual void StartDataRequest(const std::string& path, | 47 virtual void StartDataRequest(const std::string& path, |
48 bool is_incognito, | 48 bool is_incognito, |
49 int request_id); | 49 int request_id); |
50 virtual std::string GetMimeType(const std::string&) const { | 50 virtual std::string GetMimeType(const std::string& path) const; |
51 return "text/html"; | |
52 } | |
53 | 51 |
54 private: | 52 private: |
55 ~CrashesUIHTMLSource() {} | 53 ~CrashesUIHTMLSource() {} |
56 | |
57 DISALLOW_COPY_AND_ASSIGN(CrashesUIHTMLSource); | 54 DISALLOW_COPY_AND_ASSIGN(CrashesUIHTMLSource); |
58 }; | 55 }; |
59 | 56 |
57 | |
58 CrashesUIHTMLSource::CrashesUIHTMLSource() | |
59 : ChromeWebUIDataSource(chrome::kChromeUICrashesHost) { | |
60 AddLocalizedString("crashesTitle",IDS_CRASHES_TITLE); | |
61 AddLocalizedString("crashCountFormat", | |
62 IDS_CRASHES_CRASH_COUNT_BANNER_FORMAT); | |
63 AddLocalizedString("crashHeaderFormat", IDS_CRASHES_CRASH_HEADER_FORMAT); | |
64 AddLocalizedString("crashTimeFormat", IDS_CRASHES_CRASH_TIME_FORMAT); | |
65 AddLocalizedString("bugLinkText", IDS_CRASHES_BUG_LINK_LABEL); | |
66 AddLocalizedString("noCrashesMessage", IDS_CRASHES_NO_CRASHES_MESSAGE); | |
67 AddLocalizedString("disabledHeader", IDS_CRASHES_DISABLED_HEADER); | |
68 AddLocalizedString("disabledMessage", IDS_CRASHES_DISABLED_MESSAGE); | |
69 } | |
70 | |
60 void CrashesUIHTMLSource::StartDataRequest(const std::string& path, | 71 void CrashesUIHTMLSource::StartDataRequest(const std::string& path, |
Evan Stade
2011/06/30 23:25:23
didn't you change this interface recently
| |
61 bool is_incognito, | 72 bool is_incognito, |
62 int request_id) { | 73 int request_id) { |
63 DictionaryValue localized_strings; | 74 if (path == kStringsJsPath) { |
64 localized_strings.SetString("crashesTitle", | 75 SendLocalizedStringsAsJSON(request_id); |
65 l10n_util::GetStringUTF16(IDS_CRASHES_TITLE)); | 76 } else { |
66 localized_strings.SetString("crashCountFormat", | 77 int idr = (path == kCrashesJsPath) ? IDR_CRASHES_JS : IDR_CRASHES_HTML; |
Evan Stade
2011/06/30 23:25:23
no ()
| |
67 l10n_util::GetStringUTF16(IDS_CRASHES_CRASH_COUNT_BANNER_FORMAT)); | 78 SendFromResourceBundle(request_id, idr); |
68 localized_strings.SetString("crashHeaderFormat", | 79 } |
69 l10n_util::GetStringUTF16(IDS_CRASHES_CRASH_HEADER_FORMAT)); | 80 } |
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 |
81 ChromeURLDataManager::DataSource::SetFontAndTextDirection(&localized_strings); | 82 std::string CrashesUIHTMLSource::GetMimeType(const std::string& path) const { |
83 if (path == kCrashesJsPath || path == kStringsJsPath) | |
84 return "application/javascript"; | |
82 | 85 |
83 static const base::StringPiece crashes_html( | 86 return "text/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 } | 87 } |
95 | 88 |
96 //////////////////////////////////////////////////////////////////////////////// | 89 //////////////////////////////////////////////////////////////////////////////// |
97 // | 90 // |
98 // CrashesDOMHandler | 91 // CrashesDOMHandler |
99 // | 92 // |
100 //////////////////////////////////////////////////////////////////////////////// | 93 //////////////////////////////////////////////////////////////////////////////// |
101 | 94 |
102 // The handler for Javascript messages for the chrome://crashes/ page. | 95 // The handler for Javascript messages for the chrome://crashes/ page. |
103 class CrashesDOMHandler : public WebUIMessageHandler, | 96 class CrashesDOMHandler : public WebUIMessageHandler, |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 bool CrashesUI::CrashReportingEnabled() { | 206 bool CrashesUI::CrashReportingEnabled() { |
214 #if defined(GOOGLE_CHROME_BUILD) && !defined(OS_CHROMEOS) | 207 #if defined(GOOGLE_CHROME_BUILD) && !defined(OS_CHROMEOS) |
215 PrefService* prefs = g_browser_process->local_state(); | 208 PrefService* prefs = g_browser_process->local_state(); |
216 return prefs->GetBoolean(prefs::kMetricsReportingEnabled); | 209 return prefs->GetBoolean(prefs::kMetricsReportingEnabled); |
217 #elif defined(GOOGLE_CHROME_BUILD) && defined(OS_CHROMEOS) | 210 #elif defined(GOOGLE_CHROME_BUILD) && defined(OS_CHROMEOS) |
218 return chromeos::MetricsCrosSettingsProvider::GetMetricsStatus(); | 211 return chromeos::MetricsCrosSettingsProvider::GetMetricsStatus(); |
219 #else | 212 #else |
220 return false; | 213 return false; |
221 #endif | 214 #endif |
222 } | 215 } |
OLD | NEW |