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

Side by Side Diff: chrome/browser/gtk/options/content_page_gtk.cc

Issue 2905003: Implement support for disabling sync through configuration management. (Closed)
Patch Set: Fix PrefsControllerTest on MAC. Created 10 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/gtk/options/content_page_gtk.h" 5 #include "chrome/browser/gtk/options/content_page_gtk.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "app/gtk_util.h" 9 #include "app/gtk_util.h"
10 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
(...skipping 24 matching lines...) Expand all
35 35
36 #if defined(OS_CHROMEOS) 36 #if defined(OS_CHROMEOS)
37 #include "chrome/browser/chromeos/options/options_window_view.h" 37 #include "chrome/browser/chromeos/options/options_window_view.h"
38 #endif // defined(OS_CHROMEOS) 38 #endif // defined(OS_CHROMEOS)
39 39
40 namespace { 40 namespace {
41 41
42 // Background color for the status label when it's showing an error. 42 // Background color for the status label when it's showing an error.
43 static const GdkColor kSyncLabelErrorBgColor = GDK_COLOR_RGB(0xff, 0x9a, 0x9a); 43 static const GdkColor kSyncLabelErrorBgColor = GDK_COLOR_RGB(0xff, 0x9a, 0x9a);
44 44
45 // Set of preferences which might be unavailable for editing when managed.
46 const wchar_t* kContentManagablePrefs[] = {
47 prefs::kSyncManaged
48 };
49
45 // Helper for WrapLabelAtAllocationHack. 50 // Helper for WrapLabelAtAllocationHack.
46 void OnLabelAllocate(GtkWidget* label, GtkAllocation* allocation) { 51 void OnLabelAllocate(GtkWidget* label, GtkAllocation* allocation) {
47 gtk_widget_set_size_request(label, allocation->width, -1); 52 gtk_widget_set_size_request(label, allocation->width, -1);
48 53
49 // Disconnect ourselves. Repeatedly resizing based on allocation causes 54 // Disconnect ourselves. Repeatedly resizing based on allocation causes
50 // the dialog to become unshrinkable. 55 // the dialog to become unshrinkable.
51 g_signal_handlers_disconnect_by_func( 56 g_signal_handlers_disconnect_by_func(
52 label, reinterpret_cast<gpointer>(OnLabelAllocate), NULL); 57 label, reinterpret_cast<gpointer>(OnLabelAllocate), NULL);
53 } 58 }
54 59
(...skipping 17 matching lines...) Expand all
72 : OptionsPageBase(profile), 77 : OptionsPageBase(profile),
73 sync_status_label_background_(NULL), 78 sync_status_label_background_(NULL),
74 sync_status_label_(NULL), 79 sync_status_label_(NULL),
75 #if !defined(OS_CHROMEOS) 80 #if !defined(OS_CHROMEOS)
76 sync_action_link_background_(NULL), 81 sync_action_link_background_(NULL),
77 sync_action_link_(NULL), 82 sync_action_link_(NULL),
78 sync_start_stop_button_(NULL), 83 sync_start_stop_button_(NULL),
79 #endif 84 #endif
80 sync_customize_button_(NULL), 85 sync_customize_button_(NULL),
81 initializing_(true), 86 initializing_(true),
82 sync_service_(NULL) { 87 sync_service_(NULL),
88 managed_prefs_banner_(profile->GetPrefs(), kContentManagablePrefs,
89 arraysize(kContentManagablePrefs)) {
83 if (profile->GetProfileSyncService()) { 90 if (profile->GetProfileSyncService()) {
84 sync_service_ = profile->GetProfileSyncService(); 91 sync_service_ = profile->GetProfileSyncService();
85 sync_service_->AddObserver(this); 92 sync_service_->AddObserver(this);
86 } 93 }
87 94
88 // Prepare the group options layout. 95 // Prepare the group options layout.
89 scoped_ptr<OptionsLayoutBuilderGtk> 96 scoped_ptr<OptionsLayoutBuilderGtk>
90 options_builder(OptionsLayoutBuilderGtk::CreateOptionallyCompactLayout()); 97 options_builder(OptionsLayoutBuilderGtk::CreateOptionallyCompactLayout());
98 options_builder->AddWidget(managed_prefs_banner_.banner_widget(), false);
91 if (sync_service_) { 99 if (sync_service_) {
92 options_builder->AddOptionGroup( 100 options_builder->AddOptionGroup(
93 l10n_util::GetStringUTF8(IDS_SYNC_OPTIONS_GROUP_NAME), 101 l10n_util::GetStringUTF8(IDS_SYNC_OPTIONS_GROUP_NAME),
94 InitSyncGroup(), false); 102 InitSyncGroup(), false);
95 UpdateSyncControls(); 103 UpdateSyncControls();
96 } 104 }
97 105
98 options_builder->AddOptionGroup( 106 options_builder->AddOptionGroup(
99 l10n_util::GetStringUTF8(IDS_OPTIONS_PASSWORDS_GROUP_NAME), 107 l10n_util::GetStringUTF8(IDS_OPTIONS_PASSWORDS_GROUP_NAME),
100 InitPasswordSavingGroup(), false); 108 InitPasswordSavingGroup(), false);
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 403
396 return vbox; 404 return vbox;
397 } 405 }
398 406
399 void ContentPageGtk::UpdateSyncControls() { 407 void ContentPageGtk::UpdateSyncControls() {
400 DCHECK(sync_service_); 408 DCHECK(sync_service_);
401 string16 status_label; 409 string16 status_label;
402 string16 link_label; 410 string16 link_label;
403 std::string customize_button_label; 411 std::string customize_button_label;
404 std::string button_label; 412 std::string button_label;
413 bool managed = sync_service_->IsManaged();
405 bool sync_setup_completed = sync_service_->HasSyncSetupCompleted(); 414 bool sync_setup_completed = sync_service_->HasSyncSetupCompleted();
406 bool status_has_error = sync_ui_util::GetStatusLabels(sync_service_, 415 bool status_has_error = sync_ui_util::GetStatusLabels(sync_service_,
407 &status_label, &link_label) == sync_ui_util::SYNC_ERROR; 416 &status_label, &link_label) == sync_ui_util::SYNC_ERROR;
408 customize_button_label = 417 customize_button_label =
409 l10n_util::GetStringUTF8(IDS_SYNC_CUSTOMIZE_BUTTON_LABEL); 418 l10n_util::GetStringUTF8(IDS_SYNC_CUSTOMIZE_BUTTON_LABEL);
410 if (sync_setup_completed) { 419 if (sync_setup_completed) {
411 button_label = l10n_util::GetStringUTF8(IDS_SYNC_STOP_SYNCING_BUTTON_LABEL); 420 button_label = l10n_util::GetStringUTF8(IDS_SYNC_STOP_SYNCING_BUTTON_LABEL);
412 } else if (sync_service_->SetupInProgress()) { 421 } else if (sync_service_->SetupInProgress()) {
413 button_label = l10n_util::GetStringUTF8(IDS_SYNC_NTP_SETUP_IN_PROGRESS); 422 button_label = l10n_util::GetStringUTF8(IDS_SYNC_NTP_SETUP_IN_PROGRESS);
414 } else { 423 } else {
415 button_label = l10n_util::GetStringUTF8(IDS_SYNC_START_SYNC_BUTTON_LABEL); 424 button_label = l10n_util::GetStringUTF8(IDS_SYNC_START_SYNC_BUTTON_LABEL);
416 } 425 }
417 426
418 gtk_label_set_label(GTK_LABEL(sync_status_label_), 427 gtk_label_set_label(GTK_LABEL(sync_status_label_),
419 UTF16ToUTF8(status_label).c_str()); 428 UTF16ToUTF8(status_label).c_str());
420 #if !defined(OS_CHROMEOS) 429 #if !defined(OS_CHROMEOS)
421 gtk_widget_set_sensitive(sync_start_stop_button_, 430 gtk_widget_set_sensitive(sync_start_stop_button_,
422 !sync_service_->WizardIsVisible()); 431 !sync_service_->WizardIsVisible() && !managed);
423 gtk_button_set_label(GTK_BUTTON(sync_start_stop_button_), 432 gtk_button_set_label(GTK_BUTTON(sync_start_stop_button_),
424 button_label.c_str()); 433 button_label.c_str());
425 #endif 434 #endif
426 435
427 gtk_widget_set_child_visible(sync_customize_button_, 436 gtk_widget_set_child_visible(sync_customize_button_,
428 sync_setup_completed && !status_has_error); 437 sync_setup_completed && !status_has_error);
429 gtk_button_set_label(GTK_BUTTON(sync_customize_button_), 438 gtk_button_set_label(GTK_BUTTON(sync_customize_button_),
430 customize_button_label.c_str()); 439 customize_button_label.c_str());
440 gtk_widget_set_sensitive(sync_customize_button_, !managed);
431 #if !defined(OS_CHROMEOS) 441 #if !defined(OS_CHROMEOS)
432 gtk_chrome_link_button_set_label(GTK_CHROME_LINK_BUTTON(sync_action_link_), 442 gtk_chrome_link_button_set_label(GTK_CHROME_LINK_BUTTON(sync_action_link_),
433 UTF16ToUTF8(link_label).c_str()); 443 UTF16ToUTF8(link_label).c_str());
434 if (link_label.empty()) { 444 if (link_label.empty()) {
435 gtk_widget_set_no_show_all(sync_action_link_background_, TRUE); 445 gtk_widget_set_no_show_all(sync_action_link_background_, TRUE);
436 gtk_widget_hide(sync_action_link_background_); 446 gtk_widget_hide(sync_action_link_background_);
437 } else { 447 } else {
438 gtk_widget_set_no_show_all(sync_action_link_background_, FALSE); 448 gtk_widget_set_no_show_all(sync_action_link_background_, FALSE);
439 gtk_widget_show(sync_action_link_background_); 449 gtk_widget_show(sync_action_link_background_);
440 } 450 }
451 gtk_widget_set_sensitive(sync_action_link_, !managed);
441 #endif 452 #endif
442 if (status_has_error) { 453 if (status_has_error) {
443 gtk_widget_modify_bg(sync_status_label_background_, GTK_STATE_NORMAL, 454 gtk_widget_modify_bg(sync_status_label_background_, GTK_STATE_NORMAL,
444 &kSyncLabelErrorBgColor); 455 &kSyncLabelErrorBgColor);
445 #if !defined(OS_CHROMEOS) 456 #if !defined(OS_CHROMEOS)
446 gtk_widget_modify_bg(sync_action_link_background_, GTK_STATE_NORMAL, 457 gtk_widget_modify_bg(sync_action_link_background_, GTK_STATE_NORMAL,
447 &kSyncLabelErrorBgColor); 458 &kSyncLabelErrorBgColor);
448 #endif 459 #endif
449 } else { 460 } else {
450 gtk_widget_modify_bg(sync_status_label_background_, GTK_STATE_NORMAL, NULL); 461 gtk_widget_modify_bg(sync_status_label_background_, GTK_STATE_NORMAL, NULL);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 gtk_widget_set_sensitive(autofill_button_, TRUE); 568 gtk_widget_set_sensitive(autofill_button_, TRUE);
558 } else { 569 } else {
559 UserMetricsRecordAction(UserMetricsAction("Options_FormAutofill_Disable"), 570 UserMetricsRecordAction(UserMetricsAction("Options_FormAutofill_Disable"),
560 profile()->GetPrefs()); 571 profile()->GetPrefs());
561 gtk_widget_set_sensitive(autofill_button_, FALSE); 572 gtk_widget_set_sensitive(autofill_button_, FALSE);
562 } 573 }
563 enable_form_autofill_.SetValue(enabled); 574 enable_form_autofill_.SetValue(enabled);
564 } 575 }
565 576
566 void ContentPageGtk::OnSyncStartStopButtonClicked(GtkWidget* widget) { 577 void ContentPageGtk::OnSyncStartStopButtonClicked(GtkWidget* widget) {
567 DCHECK(sync_service_); 578 DCHECK(sync_service_ && !sync_service_->IsManaged());
568 579
569 if (sync_service_->HasSyncSetupCompleted()) { 580 if (sync_service_->HasSyncSetupCompleted()) {
570 GtkWidget* dialog = gtk_message_dialog_new( 581 GtkWidget* dialog = gtk_message_dialog_new(
571 GTK_WINDOW(gtk_widget_get_toplevel(widget)), 582 GTK_WINDOW(gtk_widget_get_toplevel(widget)),
572 static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL), 583 static_cast<GtkDialogFlags>(GTK_DIALOG_MODAL),
573 GTK_MESSAGE_WARNING, 584 GTK_MESSAGE_WARNING,
574 GTK_BUTTONS_NONE, 585 GTK_BUTTONS_NONE,
575 "%s", 586 "%s",
576 l10n_util::GetStringFUTF8( 587 l10n_util::GetStringFUTF8(
577 IDS_SYNC_STOP_SYNCING_EXPLANATION_LABEL, 588 IDS_SYNC_STOP_SYNCING_EXPLANATION_LABEL,
(...skipping 17 matching lines...) Expand all
595 gtk_util::ShowDialog(dialog); 606 gtk_util::ShowDialog(dialog);
596 return; 607 return;
597 } else { 608 } else {
598 sync_service_->EnableForUser(); 609 sync_service_->EnableForUser();
599 ProfileSyncService::SyncEvent(ProfileSyncService::START_FROM_OPTIONS); 610 ProfileSyncService::SyncEvent(ProfileSyncService::START_FROM_OPTIONS);
600 } 611 }
601 } 612 }
602 613
603 void ContentPageGtk::OnSyncCustomizeButtonClicked(GtkWidget* widget) { 614 void ContentPageGtk::OnSyncCustomizeButtonClicked(GtkWidget* widget) {
604 // sync_customize_button_ should be invisible if sync is not yet set up. 615 // sync_customize_button_ should be invisible if sync is not yet set up.
605 DCHECK(sync_service_->HasSyncSetupCompleted()); 616 DCHECK(sync_service_ && !sync_service_->IsManaged() &&
617 sync_service_->HasSyncSetupCompleted());
606 sync_service_->ShowChooseDataTypes(); 618 sync_service_->ShowChooseDataTypes();
607 } 619 }
608 620
609 void ContentPageGtk::OnSyncActionLinkClicked(GtkWidget* widget) { 621 void ContentPageGtk::OnSyncActionLinkClicked(GtkWidget* widget) {
610 DCHECK(sync_service_); 622 DCHECK(sync_service_ && !sync_service_->IsManaged());
611 sync_service_->ShowLoginDialog(); 623 sync_service_->ShowLoginDialog();
612 } 624 }
613 625
614 void ContentPageGtk::OnStopSyncDialogResponse(GtkWidget* widget, int response) { 626 void ContentPageGtk::OnStopSyncDialogResponse(GtkWidget* widget, int response) {
615 if (response == GTK_RESPONSE_ACCEPT) { 627 if (response == GTK_RESPONSE_ACCEPT) {
616 sync_service_->DisableForUser(); 628 sync_service_->DisableForUser();
617 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS); 629 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS);
618 } 630 }
619 gtk_widget_destroy(widget); 631 gtk_widget_destroy(widget);
620 } 632 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/options/content_page_gtk.h ('k') | chrome/browser/managed_prefs_banner_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698