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/flags_ui.h" | 5 #include "chrome/browser/ui/webui/flags_ui.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "base/values.h" | 11 #include "base/values.h" |
12 #include "chrome/browser/about_flags.h" | 12 #include "chrome/browser/about_flags.h" |
13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
14 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/ui/browser_list.h" | 16 #include "chrome/browser/ui/browser_list.h" |
17 #include "chrome/browser/ui/webui/chrome_url_data_manager.h" | 17 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
18 #include "chrome/common/jstemplate_builder.h" | 18 #include "chrome/common/jstemplate_builder.h" |
19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
20 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
21 #include "content/browser/browser_thread.h" | 21 #include "content/browser/browser_thread.h" |
22 #include "content/browser/tab_contents/tab_contents.h" | 22 #include "content/browser/tab_contents/tab_contents.h" |
23 #include "grit/browser_resources.h" | 23 #include "grit/browser_resources.h" |
24 #include "grit/chromium_strings.h" | 24 #include "grit/chromium_strings.h" |
25 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
26 #include "grit/theme_resources.h" | 26 #include "grit/theme_resources.h" |
27 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
28 #include "ui/base/resource/resource_bundle.h" | 28 #include "ui/base/resource/resource_bundle.h" |
29 | 29 |
30 #if defined(OS_CHROMEOS) | 30 #if defined(OS_CHROMEOS) |
31 #include "chrome/browser/chromeos/user_cros_settings_provider.h" | 31 #include "chrome/browser/chromeos/user_cros_settings_provider.h" |
32 #include "chrome/browser/chromeos/login/user_manager.h" | 32 #include "chrome/browser/chromeos/login/user_manager.h" |
33 #endif | 33 #endif |
34 | 34 |
35 namespace { | 35 static const char kFlagsJs[] = "flags.js"; |
| 36 static const char kStringsJs[] = "strings.js"; |
36 | 37 |
37 /////////////////////////////////////////////////////////////////////////////// | 38 /////////////////////////////////////////////////////////////////////////////// |
38 // | 39 // |
39 // FlagsUIHTMLSource | 40 // FlagsUIHTMLSource |
40 // | 41 // |
41 /////////////////////////////////////////////////////////////////////////////// | 42 /////////////////////////////////////////////////////////////////////////////// |
42 | 43 |
43 class FlagsUIHTMLSource : public ChromeURLDataManager::DataSource { | 44 class FlagsUIHTMLSource : public ChromeWebUIDataSource { |
44 public: | 45 public: |
45 FlagsUIHTMLSource() | 46 FlagsUIHTMLSource(); |
46 : DataSource(chrome::kChromeUIFlagsHost, MessageLoop::current()) {} | |
47 | 47 |
48 // Called when the network layer has requested a resource underneath | 48 // Called when the network layer has requested a resource underneath |
49 // the path we registered. | 49 // the path we registered. |
50 virtual void StartDataRequest(const std::string& path, | 50 virtual void StartDataRequest(const std::string& path, |
51 bool is_incognito, | 51 bool is_incognito, |
52 int request_id); | 52 int request_id); |
53 virtual std::string GetMimeType(const std::string&) const { | 53 virtual std::string GetMimeType(const std::string&) const; |
54 return "text/html"; | |
55 } | |
56 | 54 |
57 private: | 55 private: |
58 ~FlagsUIHTMLSource() {} | 56 ~FlagsUIHTMLSource() {} |
59 | |
60 DISALLOW_COPY_AND_ASSIGN(FlagsUIHTMLSource); | 57 DISALLOW_COPY_AND_ASSIGN(FlagsUIHTMLSource); |
61 }; | 58 }; |
62 | 59 |
| 60 FlagsUIHTMLSource::FlagsUIHTMLSource() |
| 61 : ChromeWebUIDataSource(chrome::kChromeUIFlagsHost) { |
| 62 AddLocalizedString("flagsLongTitle", IDS_FLAGS_LONG_TITLE); |
| 63 AddLocalizedString("flagsTableTitle", IDS_FLAGS_TABLE_TITLE); |
| 64 AddLocalizedString("flagsNoExperimentsAvailable", |
| 65 IDS_FLAGS_NO_EXPERIMENTS_AVAILABLE); |
| 66 AddLocalizedString("flagsWarningHeader", IDS_FLAGS_WARNING_HEADER); |
| 67 AddLocalizedString("flagsBlurb", IDS_FLAGS_WARNING_TEXT); |
| 68 #if defined(OS_CHROMEOS) |
| 69 int ids = IDS_PRODUCT_OS_NAME; |
| 70 #else |
| 71 int ids = IDS_PRODUCT_NAME; |
| 72 #endif |
| 73 AddString("flagsRestartNotice", |
| 74 l10n_util::GetStringFUTF16(IDS_FLAGS_RELAUNCH_NOTICE, |
| 75 l10n_util::GetStringUTF16(ids))); |
| 76 AddLocalizedString("flagsRestartButton", IDS_FLAGS_RELAUNCH_BUTTON); |
| 77 AddLocalizedString("disable", IDS_FLAGS_DISABLE); |
| 78 AddLocalizedString("enable", IDS_FLAGS_ENABLE); |
| 79 #if defined(OS_CHROMEOS) |
| 80 // Set the strings to show which user can actually change the flags |
| 81 AddLocalizedString("ownerOnly", IDS_OPTIONS_ACCOUNTS_OWNER_ONLY); |
| 82 AddString("ownerUserId", |
| 83 UTF8ToUTF16(chromeos::UserCrosSettingsProvider::cached_owner())); |
| 84 #endif |
| 85 } |
| 86 |
63 void FlagsUIHTMLSource::StartDataRequest(const std::string& path, | 87 void FlagsUIHTMLSource::StartDataRequest(const std::string& path, |
64 bool is_incognito, | 88 bool is_incognito, |
65 int request_id) { | 89 int request_id) { |
66 // Strings used in the JsTemplate file. | 90 if (path == kStringsJs) { |
67 DictionaryValue localized_strings; | 91 SendLocalizedStringsAsJSON(request_id); |
68 localized_strings.SetString("flagsLongTitle", | 92 } else { |
69 l10n_util::GetStringUTF16(IDS_FLAGS_LONG_TITLE)); | 93 int idr; |
70 localized_strings.SetString("flagsTableTitle", | 94 if (path == kFlagsJs) |
71 l10n_util::GetStringUTF16(IDS_FLAGS_TABLE_TITLE)); | 95 idr = IDR_FLAGS_JS; |
72 localized_strings.SetString("flagsNoExperimentsAvailable", | 96 #if defined (OS_CHROMEOS) |
73 l10n_util::GetStringUTF16(IDS_FLAGS_NO_EXPERIMENTS_AVAILABLE)); | 97 else if (!chromeos::UserManager::Get()->current_user_is_owner()) |
74 localized_strings.SetString("flagsWarningHeader", l10n_util::GetStringUTF16( | 98 idr = IDR_FLAGS_HTML_WARNING; |
75 IDS_FLAGS_WARNING_HEADER)); | |
76 localized_strings.SetString("flagsBlurb", l10n_util::GetStringUTF16( | |
77 IDS_FLAGS_WARNING_TEXT)); | |
78 localized_strings.SetString("flagsRestartNotice", l10n_util::GetStringFUTF16( | |
79 IDS_FLAGS_RELAUNCH_NOTICE, | |
80 l10n_util::GetStringUTF16( | |
81 #if defined(OS_CHROMEOS) | |
82 IDS_PRODUCT_OS_NAME | |
83 #else | |
84 IDS_PRODUCT_NAME | |
85 #endif | 99 #endif |
86 ))); | 100 else |
87 localized_strings.SetString("flagsRestartButton", | 101 idr = IDR_FLAGS_HTML; |
88 l10n_util::GetStringUTF16(IDS_FLAGS_RELAUNCH_BUTTON)); | |
89 localized_strings.SetString("disable", | |
90 l10n_util::GetStringUTF16(IDS_FLAGS_DISABLE)); | |
91 localized_strings.SetString("enable", | |
92 l10n_util::GetStringUTF16(IDS_FLAGS_ENABLE)); | |
93 | 102 |
94 base::StringPiece html = | 103 SendFromResourceBundle(request_id, idr); |
95 ResourceBundle::GetSharedInstance().GetRawDataResource(IDR_FLAGS_HTML); | 104 } |
96 #if defined (OS_CHROMEOS) | 105 } |
97 if (!chromeos::UserManager::Get()->current_user_is_owner()) { | |
98 html = ResourceBundle::GetSharedInstance().GetRawDataResource( | |
99 IDR_FLAGS_HTML_WARNING); | |
100 | 106 |
101 // Set the strings to show which user can actually change the flags | 107 std::string FlagsUIHTMLSource::GetMimeType(const std::string& path) const { |
102 localized_strings.SetString("ownerOnly", l10n_util::GetStringUTF16( | 108 if (path == kStringsJs || path == kFlagsJs) |
103 IDS_OPTIONS_ACCOUNTS_OWNER_ONLY)); | 109 return "application/javascript"; |
104 localized_strings.SetString("ownerUserId", UTF8ToUTF16( | |
105 chromeos::UserCrosSettingsProvider::cached_owner())); | |
106 } | |
107 #endif | |
108 static const base::StringPiece flags_html(html); | |
109 ChromeURLDataManager::DataSource::SetFontAndTextDirection(&localized_strings); | |
110 | 110 |
111 std::string full_html(flags_html.data(), flags_html.size()); | 111 return "text/html"; |
112 jstemplate_builder::AppendJsonHtml(&localized_strings, &full_html); | 112 } |
113 jstemplate_builder::AppendI18nTemplateSourceHtml(&full_html); | |
114 jstemplate_builder::AppendI18nTemplateProcessHtml(&full_html); | |
115 jstemplate_builder::AppendJsTemplateSourceHtml(&full_html); | |
116 | 113 |
117 scoped_refptr<RefCountedBytes> html_bytes(new RefCountedBytes); | 114 namespace { |
118 html_bytes->data.resize(full_html.size()); | |
119 std::copy(full_html.begin(), full_html.end(), html_bytes->data.begin()); | |
120 | |
121 SendResponse(request_id, html_bytes); | |
122 } | |
123 | 115 |
124 //////////////////////////////////////////////////////////////////////////////// | 116 //////////////////////////////////////////////////////////////////////////////// |
125 // | 117 // |
126 // FlagsDOMHandler | 118 // FlagsDOMHandler |
127 // | 119 // |
128 //////////////////////////////////////////////////////////////////////////////// | 120 //////////////////////////////////////////////////////////////////////////////// |
129 | 121 |
130 // The handler for Javascript messages for the about:flags page. | 122 // The handler for Javascript messages for the about:flags page. |
131 class FlagsDOMHandler : public WebUIMessageHandler { | 123 class FlagsDOMHandler : public WebUIMessageHandler { |
132 public: | 124 public: |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 // static | 212 // static |
221 RefCountedMemory* FlagsUI::GetFaviconResourceBytes() { | 213 RefCountedMemory* FlagsUI::GetFaviconResourceBytes() { |
222 return ResourceBundle::GetSharedInstance(). | 214 return ResourceBundle::GetSharedInstance(). |
223 LoadDataResourceBytes(IDR_FLAGS); | 215 LoadDataResourceBytes(IDR_FLAGS); |
224 } | 216 } |
225 | 217 |
226 // static | 218 // static |
227 void FlagsUI::RegisterPrefs(PrefService* prefs) { | 219 void FlagsUI::RegisterPrefs(PrefService* prefs) { |
228 prefs->RegisterListPref(prefs::kEnabledLabsExperiments); | 220 prefs->RegisterListPref(prefs::kEnabledLabsExperiments); |
229 } | 221 } |
OLD | NEW |