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

Side by Side Diff: chrome/browser/ui/webui/options/personal_options_handler.cc

Issue 7322014: Autofill button should get enabled and disabled according to the policy value. (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
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/options/personal_options_handler.h" 5 #include "chrome/browser/ui/webui/options/personal_options_handler.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/stl_util-inl.h" 13 #include "base/stl_util-inl.h"
14 #include "base/stringprintf.h" 14 #include "base/stringprintf.h"
15 #include "base/time.h" 15 #include "base/time.h"
16 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "build/build_config.h" 18 #include "build/build_config.h"
19 #include "chrome/browser/prefs/pref_service.h"
19 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/profiles/profile_manager.h" 21 #include "chrome/browser/profiles/profile_manager.h"
21 #include "chrome/browser/sync/profile_sync_service.h" 22 #include "chrome/browser/sync/profile_sync_service.h"
22 #include "chrome/browser/sync/sync_setup_flow.h" 23 #include "chrome/browser/sync/sync_setup_flow.h"
23 #include "chrome/browser/sync/sync_ui_util.h" 24 #include "chrome/browser/sync/sync_ui_util.h"
24 #include "chrome/browser/themes/theme_service.h" 25 #include "chrome/browser/themes/theme_service.h"
25 #include "chrome/browser/themes/theme_service_factory.h" 26 #include "chrome/browser/themes/theme_service_factory.h"
26 #include "chrome/browser/ui/webui/options/options_managed_banner_handler.h" 27 #include "chrome/browser/ui/webui/options/options_managed_banner_handler.h"
27 #include "chrome/common/chrome_paths.h" 28 #include "chrome/common/chrome_paths.h"
28 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
29 #include "chrome/common/net/gaia/google_service_auth_error.h" 30 #include "chrome/common/net/gaia/google_service_auth_error.h"
31 #include "chrome/common/pref_names.h"
30 #include "chrome/common/url_constants.h" 32 #include "chrome/common/url_constants.h"
31 #include "content/browser/user_metrics.h" 33 #include "content/browser/user_metrics.h"
32 #include "content/common/notification_service.h" 34 #include "content/common/notification_service.h"
33 #include "grit/chromium_strings.h" 35 #include "grit/chromium_strings.h"
34 #include "grit/generated_resources.h" 36 #include "grit/generated_resources.h"
35 #include "grit/locale_settings.h" 37 #include "grit/locale_settings.h"
36 #include "grit/theme_resources.h" 38 #include "grit/theme_resources.h"
37 #include "ui/base/l10n/l10n_util.h" 39 #include "ui/base/l10n/l10n_util.h"
38 40
39 #if defined(OS_CHROMEOS) 41 #if defined(OS_CHROMEOS)
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 void PersonalOptionsHandler::Observe(NotificationType type, 210 void PersonalOptionsHandler::Observe(NotificationType type,
209 const NotificationSource& source, 211 const NotificationSource& source,
210 const NotificationDetails& details) { 212 const NotificationDetails& details) {
211 if (type == NotificationType::BROWSER_THEME_CHANGED) { 213 if (type == NotificationType::BROWSER_THEME_CHANGED) {
212 ObserveThemeChanged(); 214 ObserveThemeChanged();
213 #if defined(OS_CHROMEOS) 215 #if defined(OS_CHROMEOS)
214 } else if (type == NotificationType::LOGIN_USER_IMAGE_CHANGED) { 216 } else if (type == NotificationType::LOGIN_USER_IMAGE_CHANGED) {
215 LoadAccountPicture(NULL); 217 LoadAccountPicture(NULL);
216 #endif 218 #endif
217 } else { 219 } else {
220 if (type == NotificationType::PREF_CHANGED) {
221 std::string* pref_name = Details<std::string>(details).ptr();
222 if (*pref_name == prefs::kAutofillEnabled)
223 UpdateAutofillUI();
224 }
218 OptionsPageUIHandler::Observe(type, source, details); 225 OptionsPageUIHandler::Observe(type, source, details);
219 } 226 }
220 } 227 }
221 228
222 void PersonalOptionsHandler::OnStateChanged() { 229 void PersonalOptionsHandler::OnStateChanged() {
223 string16 status_label; 230 string16 status_label;
224 string16 link_label; 231 string16 link_label;
225 ProfileSyncService* service = web_ui_->GetProfile()->GetProfileSyncService(); 232 ProfileSyncService* service = web_ui_->GetProfile()->GetProfileSyncService();
226 DCHECK(service); 233 DCHECK(service);
227 bool managed = service->IsManaged(); 234 bool managed = service->IsManaged();
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 banner_handler_.reset( 360 banner_handler_.reset(
354 OptionsManagedBannerHandler::Create(web_ui_, 361 OptionsManagedBannerHandler::Create(web_ui_,
355 ASCIIToUTF16("PersonalOptions"), 362 ASCIIToUTF16("PersonalOptions"),
356 OPTIONS_PAGE_CONTENT)); 363 OPTIONS_PAGE_CONTENT));
357 364
358 // Listen for theme installation. 365 // Listen for theme installation.
359 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, 366 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
360 NotificationService::AllSources()); 367 NotificationService::AllSources());
361 ObserveThemeChanged(); 368 ObserveThemeChanged();
362 369
370 // Listen for autofill status changes.
371 autofill_enabled_.Init(prefs::kAutofillEnabled,
372 web_ui_->GetProfile()->GetPrefs(), this);
373 UpdateAutofillUI();
374
363 ProfileSyncService* sync_service = 375 ProfileSyncService* sync_service =
364 web_ui_->GetProfile()->GetProfileSyncService(); 376 web_ui_->GetProfile()->GetProfileSyncService();
365 if (sync_service) { 377 if (sync_service) {
366 sync_service->AddObserver(this); 378 sync_service->AddObserver(this);
367 OnStateChanged(); 379 OnStateChanged();
368 380
369 DictionaryValue args; 381 DictionaryValue args;
370 SyncSetupFlow::GetArgsForConfigure(sync_service, &args); 382 SyncSetupFlow::GetArgsForConfigure(sync_service, &args);
371 383
372 web_ui_->CallJavascriptFunction("PersonalOptions.setRegisteredDataTypes", 384 web_ui_->CallJavascriptFunction("PersonalOptions.setRegisteredDataTypes",
373 args); 385 args);
374 } else { 386 } else {
375 web_ui_->CallJavascriptFunction("options.PersonalOptions.hideSyncSection"); 387 web_ui_->CallJavascriptFunction("options.PersonalOptions.hideSyncSection");
376 } 388 }
377 } 389 }
378 390
379 void PersonalOptionsHandler::ThemesReset(const ListValue* args) { 391 void PersonalOptionsHandler::ThemesReset(const ListValue* args) {
380 UserMetricsRecordAction(UserMetricsAction("Options_ThemesReset")); 392 UserMetricsRecordAction(UserMetricsAction("Options_ThemesReset"));
381 ThemeServiceFactory::GetForProfile(web_ui_->GetProfile())->UseDefaultTheme(); 393 ThemeServiceFactory::GetForProfile(web_ui_->GetProfile())->UseDefaultTheme();
382 } 394 }
383 395
384 #if defined(TOOLKIT_GTK) 396 #if defined(TOOLKIT_GTK)
385 void PersonalOptionsHandler::ThemesSetGTK(const ListValue* args) { 397 void PersonalOptionsHandler::ThemesSetGTK(const ListValue* args) {
386 UserMetricsRecordAction(UserMetricsAction("Options_GtkThemeSet")); 398 UserMetricsRecordAction(UserMetricsAction("Options_GtkThemeSet"));
387 ThemeServiceFactory::GetForProfile(web_ui_->GetProfile())->SetNativeTheme(); 399 ThemeServiceFactory::GetForProfile(web_ui_->GetProfile())->SetNativeTheme();
388 } 400 }
389 #endif 401 #endif
390 402
403 void PersonalOptionsHandler::UpdateAutofillUI() {
404 // Update AutoFill button state.
405 bool autofill_disabled = autofill_enabled_.IsManaged() && !*autofill_enabled_;
406 scoped_ptr<Value> autofill_enabled_state(
407 Value::CreateBooleanValue(!autofill_disabled));
408 web_ui_->CallJavascriptFunction("PersonalOptions.setAutoFillButtonEnabled",
409 *autofill_enabled_state);
410 }
411
391 #if defined(OS_CHROMEOS) 412 #if defined(OS_CHROMEOS)
392 void PersonalOptionsHandler::LoadAccountPicture(const ListValue* args) { 413 void PersonalOptionsHandler::LoadAccountPicture(const ListValue* args) {
393 const chromeos::UserManager::User& user = 414 const chromeos::UserManager::User& user =
394 chromeos::UserManager::Get()->logged_in_user(); 415 chromeos::UserManager::Get()->logged_in_user();
395 std::string email = user.email(); 416 std::string email = user.email();
396 if (!email.empty()) { 417 if (!email.empty()) {
397 // int64 is either long or long long, but we need a certain format 418 // int64 is either long or long long, but we need a certain format
398 // specifier. 419 // specifier.
399 long long timestamp = base::TimeTicks::Now().ToInternalValue(); 420 long long timestamp = base::TimeTicks::Now().ToInternalValue();
400 StringValue image_url( 421 StringValue image_url(
401 StringPrintf("%s%s?id=%lld", 422 StringPrintf("%s%s?id=%lld",
402 chrome::kChromeUIUserImageURL, 423 chrome::kChromeUIUserImageURL,
403 email.c_str(), 424 email.c_str(),
404 timestamp)); 425 timestamp));
405 web_ui_->CallJavascriptFunction("PersonalOptions.setAccountPicture", 426 web_ui_->CallJavascriptFunction("PersonalOptions.setAccountPicture",
406 image_url); 427 image_url);
407 428
408 StringValue email_value(email); 429 StringValue email_value(email);
409 web_ui_->CallJavascriptFunction("AccountsOptions.updateAccountPicture", 430 web_ui_->CallJavascriptFunction("AccountsOptions.updateAccountPicture",
410 email_value, image_url); 431 email_value, image_url);
411 } 432 }
412 } 433 }
413 #endif 434 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698