OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 source->SetUseJsonJSFormatV2(); | 47 source->SetUseJsonJSFormatV2(); |
48 source->AddLocalizedString("flagsLongTitle", IDS_FLAGS_LONG_TITLE); | 48 source->AddLocalizedString("flagsLongTitle", IDS_FLAGS_LONG_TITLE); |
49 source->AddLocalizedString("flagsTableTitle", IDS_FLAGS_TABLE_TITLE); | 49 source->AddLocalizedString("flagsTableTitle", IDS_FLAGS_TABLE_TITLE); |
50 source->AddLocalizedString("flagsNoExperimentsAvailable", | 50 source->AddLocalizedString("flagsNoExperimentsAvailable", |
51 IDS_FLAGS_NO_EXPERIMENTS_AVAILABLE); | 51 IDS_FLAGS_NO_EXPERIMENTS_AVAILABLE); |
52 source->AddLocalizedString("flagsWarningHeader", IDS_FLAGS_WARNING_HEADER); | 52 source->AddLocalizedString("flagsWarningHeader", IDS_FLAGS_WARNING_HEADER); |
53 source->AddLocalizedString("flagsBlurb", IDS_FLAGS_WARNING_TEXT); | 53 source->AddLocalizedString("flagsBlurb", IDS_FLAGS_WARNING_TEXT); |
54 source->AddLocalizedString("flagsNotSupported", IDS_FLAGS_NOT_AVAILABLE); | 54 source->AddLocalizedString("flagsNotSupported", IDS_FLAGS_NOT_AVAILABLE); |
55 source->AddLocalizedString("flagsRestartNotice", IDS_FLAGS_RELAUNCH_NOTICE); | 55 source->AddLocalizedString("flagsRestartNotice", IDS_FLAGS_RELAUNCH_NOTICE); |
56 source->AddLocalizedString("flagsRestartButton", IDS_FLAGS_RELAUNCH_BUTTON); | 56 source->AddLocalizedString("flagsRestartButton", IDS_FLAGS_RELAUNCH_BUTTON); |
| 57 source->AddLocalizedString("resetAllButton", IDS_FLAGS_RESET_ALL_BUTTON); |
57 source->AddLocalizedString("disable", IDS_FLAGS_DISABLE); | 58 source->AddLocalizedString("disable", IDS_FLAGS_DISABLE); |
58 source->AddLocalizedString("enable", IDS_FLAGS_ENABLE); | 59 source->AddLocalizedString("enable", IDS_FLAGS_ENABLE); |
59 #if defined(OS_CHROMEOS) | 60 #if defined(OS_CHROMEOS) |
60 // Set the strings to show which user can actually change the flags | 61 // Set the strings to show which user can actually change the flags |
61 source->AddLocalizedString("ownerOnly", IDS_OPTIONS_ACCOUNTS_OWNER_ONLY); | 62 source->AddLocalizedString("ownerOnly", IDS_OPTIONS_ACCOUNTS_OWNER_ONLY); |
62 std::string owner; | 63 std::string owner; |
63 chromeos::CrosSettings::Get()->GetString(chromeos::kDeviceOwner, &owner); | 64 chromeos::CrosSettings::Get()->GetString(chromeos::kDeviceOwner, &owner); |
64 source->AddString("ownerUserId", UTF8ToUTF16(owner)); | 65 source->AddString("ownerUserId", UTF8ToUTF16(owner)); |
65 #endif | 66 #endif |
66 | 67 |
(...skipping 27 matching lines...) Expand all Loading... |
94 | 95 |
95 // Callback for the "requestFlagsExperiments" message. | 96 // Callback for the "requestFlagsExperiments" message. |
96 void HandleRequestFlagsExperiments(const ListValue* args); | 97 void HandleRequestFlagsExperiments(const ListValue* args); |
97 | 98 |
98 // Callback for the "enableFlagsExperiment" message. | 99 // Callback for the "enableFlagsExperiment" message. |
99 void HandleEnableFlagsExperimentMessage(const ListValue* args); | 100 void HandleEnableFlagsExperimentMessage(const ListValue* args); |
100 | 101 |
101 // Callback for the "restartBrowser" message. Restores all tabs on restart. | 102 // Callback for the "restartBrowser" message. Restores all tabs on restart. |
102 void HandleRestartBrowser(const ListValue* args); | 103 void HandleRestartBrowser(const ListValue* args); |
103 | 104 |
| 105 // Callback for the "resetAllFlags" message. |
| 106 void HandleResetAllFlags(const ListValue* args); |
| 107 |
104 private: | 108 private: |
105 DISALLOW_COPY_AND_ASSIGN(FlagsDOMHandler); | 109 DISALLOW_COPY_AND_ASSIGN(FlagsDOMHandler); |
106 }; | 110 }; |
107 | 111 |
108 void FlagsDOMHandler::RegisterMessages() { | 112 void FlagsDOMHandler::RegisterMessages() { |
109 web_ui()->RegisterMessageCallback("requestFlagsExperiments", | 113 web_ui()->RegisterMessageCallback("requestFlagsExperiments", |
110 base::Bind(&FlagsDOMHandler::HandleRequestFlagsExperiments, | 114 base::Bind(&FlagsDOMHandler::HandleRequestFlagsExperiments, |
111 base::Unretained(this))); | 115 base::Unretained(this))); |
112 web_ui()->RegisterMessageCallback("enableFlagsExperiment", | 116 web_ui()->RegisterMessageCallback("enableFlagsExperiment", |
113 base::Bind(&FlagsDOMHandler::HandleEnableFlagsExperimentMessage, | 117 base::Bind(&FlagsDOMHandler::HandleEnableFlagsExperimentMessage, |
114 base::Unretained(this))); | 118 base::Unretained(this))); |
115 web_ui()->RegisterMessageCallback("restartBrowser", | 119 web_ui()->RegisterMessageCallback("restartBrowser", |
116 base::Bind(&FlagsDOMHandler::HandleRestartBrowser, | 120 base::Bind(&FlagsDOMHandler::HandleRestartBrowser, |
117 base::Unretained(this))); | 121 base::Unretained(this))); |
| 122 web_ui()->RegisterMessageCallback("resetAllFlags", |
| 123 base::Bind(&FlagsDOMHandler::HandleResetAllFlags, |
| 124 base::Unretained(this))); |
118 } | 125 } |
119 | 126 |
120 void FlagsDOMHandler::HandleRequestFlagsExperiments(const ListValue* args) { | 127 void FlagsDOMHandler::HandleRequestFlagsExperiments(const ListValue* args) { |
121 DictionaryValue results; | 128 DictionaryValue results; |
122 results.Set("flagsExperiments", | 129 results.Set("flagsExperiments", |
123 about_flags::GetFlagsExperimentsData( | 130 about_flags::GetFlagsExperimentsData( |
124 g_browser_process->local_state())); | 131 g_browser_process->local_state())); |
125 results.SetBoolean("needsRestart", | 132 results.SetBoolean("needsRestart", |
126 about_flags::IsRestartNeededToCommitChanges()); | 133 about_flags::IsRestartNeededToCommitChanges()); |
127 web_ui()->CallJavascriptFunction("returnFlagsExperiments", results); | 134 web_ui()->CallJavascriptFunction("returnFlagsExperiments", results); |
(...skipping 14 matching lines...) Expand all Loading... |
142 about_flags::SetExperimentEnabled( | 149 about_flags::SetExperimentEnabled( |
143 g_browser_process->local_state(), | 150 g_browser_process->local_state(), |
144 experiment_internal_name, | 151 experiment_internal_name, |
145 enable_str == "true"); | 152 enable_str == "true"); |
146 } | 153 } |
147 | 154 |
148 void FlagsDOMHandler::HandleRestartBrowser(const ListValue* args) { | 155 void FlagsDOMHandler::HandleRestartBrowser(const ListValue* args) { |
149 browser::AttemptRestart(); | 156 browser::AttemptRestart(); |
150 } | 157 } |
151 | 158 |
| 159 void FlagsDOMHandler::HandleResetAllFlags(const ListValue* args) { |
| 160 about_flags::ResetAllFlags(g_browser_process->local_state()); |
| 161 } |
| 162 |
152 } // namespace | 163 } // namespace |
153 | 164 |
154 /////////////////////////////////////////////////////////////////////////////// | 165 /////////////////////////////////////////////////////////////////////////////// |
155 // | 166 // |
156 // FlagsUI | 167 // FlagsUI |
157 // | 168 // |
158 /////////////////////////////////////////////////////////////////////////////// | 169 /////////////////////////////////////////////////////////////////////////////// |
159 | 170 |
160 FlagsUI::FlagsUI(content::WebUI* web_ui) : WebUIController(web_ui) { | 171 FlagsUI::FlagsUI(content::WebUI* web_ui) : WebUIController(web_ui) { |
161 web_ui->AddMessageHandler(new FlagsDOMHandler()); | 172 web_ui->AddMessageHandler(new FlagsDOMHandler()); |
162 | 173 |
163 // Set up the about:flags source. | 174 // Set up the about:flags source. |
164 Profile* profile = Profile::FromWebUI(web_ui); | 175 Profile* profile = Profile::FromWebUI(web_ui); |
165 content::WebUIDataSource::Add(profile, CreateFlagsUIHTMLSource()); | 176 content::WebUIDataSource::Add(profile, CreateFlagsUIHTMLSource()); |
166 } | 177 } |
167 | 178 |
168 // static | 179 // static |
169 base::RefCountedMemory* FlagsUI::GetFaviconResourceBytes( | 180 base::RefCountedMemory* FlagsUI::GetFaviconResourceBytes( |
170 ui::ScaleFactor scale_factor) { | 181 ui::ScaleFactor scale_factor) { |
171 return ResourceBundle::GetSharedInstance(). | 182 return ResourceBundle::GetSharedInstance(). |
172 LoadDataResourceBytesForScale(IDR_FLAGS_FAVICON, scale_factor); | 183 LoadDataResourceBytesForScale(IDR_FLAGS_FAVICON, scale_factor); |
173 } | 184 } |
174 | 185 |
175 // static | 186 // static |
176 void FlagsUI::RegisterPrefs(PrefRegistrySimple* registry) { | 187 void FlagsUI::RegisterPrefs(PrefRegistrySimple* registry) { |
177 registry->RegisterListPref(prefs::kEnabledLabsExperiments); | 188 registry->RegisterListPref(prefs::kEnabledLabsExperiments); |
178 } | 189 } |
OLD | NEW |