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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 105 |
106 //////////////////////////////////////////////////////////////////////////////// | 106 //////////////////////////////////////////////////////////////////////////////// |
107 // | 107 // |
108 // FlagsDOMHandler | 108 // FlagsDOMHandler |
109 // | 109 // |
110 //////////////////////////////////////////////////////////////////////////////// | 110 //////////////////////////////////////////////////////////////////////////////// |
111 | 111 |
112 // The handler for Javascript messages for the about:flags page. | 112 // The handler for Javascript messages for the about:flags page. |
113 class FlagsDOMHandler : public WebUIMessageHandler { | 113 class FlagsDOMHandler : public WebUIMessageHandler { |
114 public: | 114 public: |
115 FlagsDOMHandler() : access_(about_flags::kGeneralAccessFlagsOnly), | 115 FlagsDOMHandler() : access_(flags_ui::kGeneralAccessFlagsOnly), |
116 experimental_features_requested_(false) { | 116 experimental_features_requested_(false) { |
117 } | 117 } |
118 ~FlagsDOMHandler() override {} | 118 ~FlagsDOMHandler() override {} |
119 | 119 |
120 // Initializes the DOM handler with the provided flags storage and flags | 120 // Initializes the DOM handler with the provided flags storage and flags |
121 // access. If there were flags experiments requested from javascript before | 121 // access. If there were flags experiments requested from javascript before |
122 // this was called, it calls |HandleRequestExperimentalFeatures| again. | 122 // this was called, it calls |HandleRequestExperimentalFeatures| again. |
123 void Init(flags_ui::FlagsStorage* flags_storage, | 123 void Init(flags_ui::FlagsStorage* flags_storage, |
124 about_flags::FlagAccess access); | 124 flags_ui::FlagAccess access); |
125 | 125 |
126 // WebUIMessageHandler implementation. | 126 // WebUIMessageHandler implementation. |
127 void RegisterMessages() override; | 127 void RegisterMessages() override; |
128 | 128 |
129 // Callback for the "requestExperimentFeatures" message. | 129 // Callback for the "requestExperimentFeatures" message. |
130 void HandleRequestExperimentalFeatures(const base::ListValue* args); | 130 void HandleRequestExperimentalFeatures(const base::ListValue* args); |
131 | 131 |
132 // Callback for the "enableExperimentalFeature" message. | 132 // Callback for the "enableExperimentalFeature" message. |
133 void HandleEnableExperimentalFeatureMessage(const base::ListValue* args); | 133 void HandleEnableExperimentalFeatureMessage(const base::ListValue* args); |
134 | 134 |
135 // Callback for the "restartBrowser" message. Restores all tabs on restart. | 135 // Callback for the "restartBrowser" message. Restores all tabs on restart. |
136 void HandleRestartBrowser(const base::ListValue* args); | 136 void HandleRestartBrowser(const base::ListValue* args); |
137 | 137 |
138 // Callback for the "resetAllFlags" message. | 138 // Callback for the "resetAllFlags" message. |
139 void HandleResetAllFlags(const base::ListValue* args); | 139 void HandleResetAllFlags(const base::ListValue* args); |
140 | 140 |
141 private: | 141 private: |
142 scoped_ptr<flags_ui::FlagsStorage> flags_storage_; | 142 scoped_ptr<flags_ui::FlagsStorage> flags_storage_; |
143 about_flags::FlagAccess access_; | 143 flags_ui::FlagAccess access_; |
144 bool experimental_features_requested_; | 144 bool experimental_features_requested_; |
145 | 145 |
146 DISALLOW_COPY_AND_ASSIGN(FlagsDOMHandler); | 146 DISALLOW_COPY_AND_ASSIGN(FlagsDOMHandler); |
147 }; | 147 }; |
148 | 148 |
149 void FlagsDOMHandler::RegisterMessages() { | 149 void FlagsDOMHandler::RegisterMessages() { |
150 web_ui()->RegisterMessageCallback( | 150 web_ui()->RegisterMessageCallback( |
151 flags_ui::kRequestExperimentalFeatures, | 151 flags_ui::kRequestExperimentalFeatures, |
152 base::Bind(&FlagsDOMHandler::HandleRequestExperimentalFeatures, | 152 base::Bind(&FlagsDOMHandler::HandleRequestExperimentalFeatures, |
153 base::Unretained(this))); | 153 base::Unretained(this))); |
154 web_ui()->RegisterMessageCallback( | 154 web_ui()->RegisterMessageCallback( |
155 flags_ui::kEnableExperimentalFeature, | 155 flags_ui::kEnableExperimentalFeature, |
156 base::Bind(&FlagsDOMHandler::HandleEnableExperimentalFeatureMessage, | 156 base::Bind(&FlagsDOMHandler::HandleEnableExperimentalFeatureMessage, |
157 base::Unretained(this))); | 157 base::Unretained(this))); |
158 web_ui()->RegisterMessageCallback( | 158 web_ui()->RegisterMessageCallback( |
159 flags_ui::kRestartBrowser, | 159 flags_ui::kRestartBrowser, |
160 base::Bind(&FlagsDOMHandler::HandleRestartBrowser, | 160 base::Bind(&FlagsDOMHandler::HandleRestartBrowser, |
161 base::Unretained(this))); | 161 base::Unretained(this))); |
162 web_ui()->RegisterMessageCallback( | 162 web_ui()->RegisterMessageCallback( |
163 flags_ui::kResetAllFlags, | 163 flags_ui::kResetAllFlags, |
164 base::Bind(&FlagsDOMHandler::HandleResetAllFlags, | 164 base::Bind(&FlagsDOMHandler::HandleResetAllFlags, |
165 base::Unretained(this))); | 165 base::Unretained(this))); |
166 } | 166 } |
167 | 167 |
168 void FlagsDOMHandler::Init(flags_ui::FlagsStorage* flags_storage, | 168 void FlagsDOMHandler::Init(flags_ui::FlagsStorage* flags_storage, |
169 about_flags::FlagAccess access) { | 169 flags_ui::FlagAccess access) { |
170 flags_storage_.reset(flags_storage); | 170 flags_storage_.reset(flags_storage); |
171 access_ = access; | 171 access_ = access; |
172 | 172 |
173 if (experimental_features_requested_) | 173 if (experimental_features_requested_) |
174 HandleRequestExperimentalFeatures(NULL); | 174 HandleRequestExperimentalFeatures(NULL); |
175 } | 175 } |
176 | 176 |
177 void FlagsDOMHandler::HandleRequestExperimentalFeatures( | 177 void FlagsDOMHandler::HandleRequestExperimentalFeatures( |
178 const base::ListValue* args) { | 178 const base::ListValue* args) { |
179 experimental_features_requested_ = true; | 179 experimental_features_requested_ = true; |
180 // Bail out if the handler hasn't been initialized yet. The request will be | 180 // Bail out if the handler hasn't been initialized yet. The request will be |
181 // handled after the initialization. | 181 // handled after the initialization. |
182 if (!flags_storage_) | 182 if (!flags_storage_) |
183 return; | 183 return; |
184 | 184 |
185 base::DictionaryValue results; | 185 base::DictionaryValue results; |
186 | 186 |
187 scoped_ptr<base::ListValue> supported_features(new base::ListValue); | 187 scoped_ptr<base::ListValue> supported_features(new base::ListValue); |
188 scoped_ptr<base::ListValue> unsupported_features(new base::ListValue); | 188 scoped_ptr<base::ListValue> unsupported_features(new base::ListValue); |
189 about_flags::GetFlagFeatureEntries(flags_storage_.get(), | 189 about_flags::GetFlagFeatureEntries(flags_storage_.get(), |
190 access_, | 190 access_, |
191 supported_features.get(), | 191 supported_features.get(), |
192 unsupported_features.get()); | 192 unsupported_features.get()); |
193 results.Set(flags_ui::kSupportedFeatures, supported_features.release()); | 193 results.Set(flags_ui::kSupportedFeatures, supported_features.release()); |
194 results.Set(flags_ui::kUnsupportedFeatures, unsupported_features.release()); | 194 results.Set(flags_ui::kUnsupportedFeatures, unsupported_features.release()); |
195 results.SetBoolean(flags_ui::kNeedsRestart, | 195 results.SetBoolean(flags_ui::kNeedsRestart, |
196 about_flags::IsRestartNeededToCommitChanges()); | 196 about_flags::IsRestartNeededToCommitChanges()); |
197 results.SetBoolean(flags_ui::kShowOwnerWarning, | 197 results.SetBoolean(flags_ui::kShowOwnerWarning, |
198 access_ == about_flags::kGeneralAccessFlagsOnly); | 198 access_ == flags_ui::kGeneralAccessFlagsOnly); |
199 | 199 |
200 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) | 200 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
201 version_info::Channel channel = chrome::GetChannel(); | 201 version_info::Channel channel = chrome::GetChannel(); |
202 results.SetBoolean(flags_ui::kShowBetaChannelPromotion, | 202 results.SetBoolean(flags_ui::kShowBetaChannelPromotion, |
203 channel == version_info::Channel::STABLE); | 203 channel == version_info::Channel::STABLE); |
204 results.SetBoolean(flags_ui::kShowDevChannelPromotion, | 204 results.SetBoolean(flags_ui::kShowDevChannelPromotion, |
205 channel == version_info::Channel::BETA); | 205 channel == version_info::Channel::BETA); |
206 #else | 206 #else |
207 results.SetBoolean(flags_ui::kShowBetaChannelPromotion, false); | 207 results.SetBoolean(flags_ui::kShowBetaChannelPromotion, false); |
208 results.SetBoolean(flags_ui::kShowDevChannelPromotion, false); | 208 results.SetBoolean(flags_ui::kShowDevChannelPromotion, false); |
(...skipping 20 matching lines...) Expand all Loading... |
229 } | 229 } |
230 | 230 |
231 void FlagsDOMHandler::HandleRestartBrowser(const base::ListValue* args) { | 231 void FlagsDOMHandler::HandleRestartBrowser(const base::ListValue* args) { |
232 DCHECK(flags_storage_); | 232 DCHECK(flags_storage_); |
233 #if defined(OS_CHROMEOS) | 233 #if defined(OS_CHROMEOS) |
234 // On ChromeOS be less intrusive and restart inside the user session after | 234 // On ChromeOS be less intrusive and restart inside the user session after |
235 // we apply the newly selected flags. | 235 // we apply the newly selected flags. |
236 base::CommandLine user_flags(base::CommandLine::NO_PROGRAM); | 236 base::CommandLine user_flags(base::CommandLine::NO_PROGRAM); |
237 about_flags::ConvertFlagsToSwitches(flags_storage_.get(), | 237 about_flags::ConvertFlagsToSwitches(flags_storage_.get(), |
238 &user_flags, | 238 &user_flags, |
239 about_flags::kAddSentinels); | 239 flags_ui::kAddSentinels); |
240 base::CommandLine::StringVector flags; | 240 base::CommandLine::StringVector flags; |
241 // argv[0] is the program name |base::CommandLine::NO_PROGRAM|. | 241 // argv[0] is the program name |base::CommandLine::NO_PROGRAM|. |
242 flags.assign(user_flags.argv().begin() + 1, user_flags.argv().end()); | 242 flags.assign(user_flags.argv().begin() + 1, user_flags.argv().end()); |
243 VLOG(1) << "Restarting to apply per-session flags..."; | 243 VLOG(1) << "Restarting to apply per-session flags..."; |
244 chromeos::DBusThreadManager::Get() | 244 chromeos::DBusThreadManager::Get() |
245 ->GetSessionManagerClient() | 245 ->GetSessionManagerClient() |
246 ->SetFlagsForUser( | 246 ->SetFlagsForUser( |
247 user_manager::UserManager::Get()->GetActiveUser()->email(), flags); | 247 user_manager::UserManager::Get()->GetActiveUser()->email(), flags); |
248 #endif | 248 #endif |
249 chrome::AttemptRestart(); | 249 chrome::AttemptRestart(); |
(...skipping 21 matching lines...) Expand all Loading... |
271 // On Chrome OS the owner can set system wide flags and other users can only | 271 // On Chrome OS the owner can set system wide flags and other users can only |
272 // set flags for their own session. | 272 // set flags for their own session. |
273 // Note that |dom_handler| is owned by the web ui that owns |flags_ui|, so | 273 // Note that |dom_handler| is owned by the web ui that owns |flags_ui|, so |
274 // it is still alive if |flags_ui| is. | 274 // it is still alive if |flags_ui| is. |
275 if (current_user_is_owner) { | 275 if (current_user_is_owner) { |
276 chromeos::OwnerSettingsServiceChromeOS* service = | 276 chromeos::OwnerSettingsServiceChromeOS* service = |
277 chromeos::OwnerSettingsServiceChromeOSFactory::GetForBrowserContext( | 277 chromeos::OwnerSettingsServiceChromeOSFactory::GetForBrowserContext( |
278 profile); | 278 profile); |
279 dom_handler->Init(new chromeos::about_flags::OwnerFlagsStorage( | 279 dom_handler->Init(new chromeos::about_flags::OwnerFlagsStorage( |
280 profile->GetPrefs(), service), | 280 profile->GetPrefs(), service), |
281 about_flags::kOwnerAccessToFlags); | 281 flags_ui::kOwnerAccessToFlags); |
282 } else { | 282 } else { |
283 dom_handler->Init( | 283 dom_handler->Init( |
284 new flags_ui::PrefServiceFlagsStorage(profile->GetPrefs()), | 284 new flags_ui::PrefServiceFlagsStorage(profile->GetPrefs()), |
285 about_flags::kGeneralAccessFlagsOnly); | 285 flags_ui::kGeneralAccessFlagsOnly); |
286 } | 286 } |
287 } | 287 } |
288 #endif | 288 #endif |
289 | 289 |
290 } // namespace | 290 } // namespace |
291 | 291 |
292 /////////////////////////////////////////////////////////////////////////////// | 292 /////////////////////////////////////////////////////////////////////////////// |
293 // | 293 // |
294 // FlagsUI | 294 // FlagsUI |
295 // | 295 // |
(...skipping 16 matching lines...) Expand all Loading... |
312 profile); | 312 profile); |
313 service->IsOwnerAsync(base::Bind( | 313 service->IsOwnerAsync(base::Bind( |
314 &FinishInitialization, weak_factory_.GetWeakPtr(), profile, handler)); | 314 &FinishInitialization, weak_factory_.GetWeakPtr(), profile, handler)); |
315 } else { | 315 } else { |
316 FinishInitialization(weak_factory_.GetWeakPtr(), profile, handler, | 316 FinishInitialization(weak_factory_.GetWeakPtr(), profile, handler, |
317 false /* current_user_is_owner */); | 317 false /* current_user_is_owner */); |
318 } | 318 } |
319 #else | 319 #else |
320 handler->Init( | 320 handler->Init( |
321 new flags_ui::PrefServiceFlagsStorage(g_browser_process->local_state()), | 321 new flags_ui::PrefServiceFlagsStorage(g_browser_process->local_state()), |
322 about_flags::kOwnerAccessToFlags); | 322 flags_ui::kOwnerAccessToFlags); |
323 #endif | 323 #endif |
324 | 324 |
325 // Set up the about:flags source. | 325 // Set up the about:flags source. |
326 content::WebUIDataSource::Add(profile, CreateFlagsUIHTMLSource()); | 326 content::WebUIDataSource::Add(profile, CreateFlagsUIHTMLSource()); |
327 } | 327 } |
328 | 328 |
329 FlagsUI::~FlagsUI() { | 329 FlagsUI::~FlagsUI() { |
330 } | 330 } |
331 | 331 |
332 // static | 332 // static |
333 base::RefCountedMemory* FlagsUI::GetFaviconResourceBytes( | 333 base::RefCountedMemory* FlagsUI::GetFaviconResourceBytes( |
334 ui::ScaleFactor scale_factor) { | 334 ui::ScaleFactor scale_factor) { |
335 return ResourceBundle::GetSharedInstance(). | 335 return ResourceBundle::GetSharedInstance(). |
336 LoadDataResourceBytesForScale(IDR_FLAGS_FAVICON, scale_factor); | 336 LoadDataResourceBytesForScale(IDR_FLAGS_FAVICON, scale_factor); |
337 } | 337 } |
338 | 338 |
339 // static | 339 // static |
340 void FlagsUI::RegisterPrefs(PrefRegistrySimple* registry) { | 340 void FlagsUI::RegisterPrefs(PrefRegistrySimple* registry) { |
341 registry->RegisterListPref(flags_ui::prefs::kEnabledLabsExperiments); | 341 registry->RegisterListPref(flags_ui::prefs::kEnabledLabsExperiments); |
342 } | 342 } |
343 | 343 |
344 #if defined(OS_CHROMEOS) | 344 #if defined(OS_CHROMEOS) |
345 // static | 345 // static |
346 void FlagsUI::RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { | 346 void FlagsUI::RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { |
347 registry->RegisterListPref(flags_ui::prefs::kEnabledLabsExperiments); | 347 registry->RegisterListPref(flags_ui::prefs::kEnabledLabsExperiments); |
348 } | 348 } |
349 | 349 |
350 #endif | 350 #endif |
OLD | NEW |