| OLD | NEW |
| 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/views/options/content_page_view.h" | 5 #include "chrome/browser/views/options/content_page_view.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <shlobj.h> | 8 #include <shlobj.h> |
| 9 #include <vsstyle.h> | 9 #include <vsstyle.h> |
| 10 #include <vssym32.h> | 10 #include <vssym32.h> |
| 11 | 11 |
| 12 #include "app/l10n_util.h" | 12 #include "app/l10n_util.h" |
| 13 #include "app/resource_bundle.h" | 13 #include "app/resource_bundle.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "chrome/browser/autofill/autofill_dialog.h" | 16 #include "chrome/browser/autofill/autofill_dialog.h" |
| 17 #include "chrome/browser/autofill/personal_data_manager.h" | 17 #include "chrome/browser/autofill/personal_data_manager.h" |
| 18 #include "chrome/browser/browser.h" | 18 #include "chrome/browser/browser.h" |
| 19 #include "chrome/browser/browser_list.h" | 19 #include "chrome/browser/browser_list.h" |
| 20 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/browser_window.h" | 21 #include "chrome/browser/browser_window.h" |
| 22 #include "chrome/browser/importer/importer_data_types.h" | 22 #include "chrome/browser/importer/importer_data_types.h" |
| 23 #include "chrome/browser/profile.h" | 23 #include "chrome/browser/profile.h" |
| 24 #include "chrome/browser/sync/sync_ui_util.h" | 24 #include "chrome/browser/sync/sync_ui_util.h" |
| 25 #include "chrome/browser/sync/sync_setup_wizard.h" | 25 #include "chrome/browser/sync/sync_setup_wizard.h" |
| 26 #include "chrome/browser/views/importer_view.h" | 26 #include "chrome/browser/views/importer_view.h" |
| 27 #include "chrome/browser/views/options/managed_prefs_banner_view.h" |
| 27 #include "chrome/browser/views/options/options_group_view.h" | 28 #include "chrome/browser/views/options/options_group_view.h" |
| 28 #include "chrome/browser/views/options/passwords_exceptions_window_view.h" | 29 #include "chrome/browser/views/options/passwords_exceptions_window_view.h" |
| 29 #include "chrome/common/chrome_switches.h" | 30 #include "chrome/common/chrome_switches.h" |
| 30 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| 31 #include "gfx/canvas.h" | 32 #include "gfx/canvas.h" |
| 32 #include "gfx/native_theme_win.h" | 33 #include "gfx/native_theme_win.h" |
| 33 #include "grit/chromium_strings.h" | 34 #include "grit/chromium_strings.h" |
| 34 #include "grit/generated_resources.h" | 35 #include "grit/generated_resources.h" |
| 35 #include "grit/locale_settings.h" | 36 #include "grit/locale_settings.h" |
| 36 #include "views/controls/button/radio_button.h" | 37 #include "views/controls/button/radio_button.h" |
| 37 #include "views/grid_layout.h" | 38 #include "views/grid_layout.h" |
| 38 #include "views/standard_layout.h" | 39 #include "views/standard_layout.h" |
| 39 #include "views/widget/widget.h" | 40 #include "views/widget/widget.h" |
| 40 #include "views/window/window.h" | 41 #include "views/window/window.h" |
| 41 | 42 |
| 42 namespace { | 43 namespace { |
| 43 | 44 |
| 44 // All the options pages are in the same view hierarchy. This means we need to | 45 // All the options pages are in the same view hierarchy. This means we need to |
| 45 // make sure group identifiers don't collide across different pages. | 46 // make sure group identifiers don't collide across different pages. |
| 46 const int kPasswordSavingRadioGroup = 201; | 47 const int kPasswordSavingRadioGroup = 201; |
| 47 const int kFormAutofillRadioGroup = 202; | 48 const int kFormAutofillRadioGroup = 202; |
| 48 | 49 |
| 49 // Background color for the status label when it's showing an error. | 50 // Background color for the status label when it's showing an error. |
| 50 static const SkColor kSyncLabelErrorBgColor = SkColorSetRGB(0xff, 0x9a, 0x9a); | 51 static const SkColor kSyncLabelErrorBgColor = SkColorSetRGB(0xff, 0x9a, 0x9a); |
| 51 | 52 |
| 53 // All content related preferences that are potentially managed by policy. We'll |
| 54 // display the warning banner if one of these have the managed bit set. |
| 55 const wchar_t* kContentPolicyConstrainedPrefs[] = { |
| 56 prefs::kSyncManaged |
| 57 }; |
| 58 |
| 52 static views::Background* CreateErrorBackground() { | 59 static views::Background* CreateErrorBackground() { |
| 53 return views::Background::CreateSolidBackground(kSyncLabelErrorBgColor); | 60 return views::Background::CreateSolidBackground(kSyncLabelErrorBgColor); |
| 54 } | 61 } |
| 55 | 62 |
| 56 } // namespace | 63 } // namespace |
| 57 | 64 |
| 58 ContentPageView::ContentPageView(Profile* profile) | 65 ContentPageView::ContentPageView(Profile* profile) |
| 59 : show_passwords_button_(NULL), | 66 : show_passwords_button_(NULL), |
| 60 passwords_group_(NULL), | 67 passwords_group_(NULL), |
| 61 passwords_asktosave_radio_(NULL), | 68 passwords_asktosave_radio_(NULL), |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 } else if (sender == themes_reset_button_) { | 135 } else if (sender == themes_reset_button_) { |
| 129 UserMetricsRecordAction(UserMetricsAction("Options_ThemesReset"), | 136 UserMetricsRecordAction(UserMetricsAction("Options_ThemesReset"), |
| 130 profile()->GetPrefs()); | 137 profile()->GetPrefs()); |
| 131 profile()->ClearTheme(); | 138 profile()->ClearTheme(); |
| 132 } else if (sender == import_button_) { | 139 } else if (sender == import_button_) { |
| 133 views::Window::CreateChromeWindow( | 140 views::Window::CreateChromeWindow( |
| 134 GetWindow()->GetNativeWindow(), | 141 GetWindow()->GetNativeWindow(), |
| 135 gfx::Rect(), | 142 gfx::Rect(), |
| 136 new ImporterView(profile(), importer::ALL))->Show(); | 143 new ImporterView(profile(), importer::ALL))->Show(); |
| 137 } else if (sender == sync_start_stop_button_) { | 144 } else if (sender == sync_start_stop_button_) { |
| 138 DCHECK(sync_service_); | 145 DCHECK(sync_service_ && !sync_service_->IsManaged()); |
| 139 | 146 |
| 140 if (sync_service_->HasSyncSetupCompleted()) { | 147 if (sync_service_->HasSyncSetupCompleted()) { |
| 141 ConfirmMessageBoxDialog::RunWithCustomConfiguration( | 148 ConfirmMessageBoxDialog::RunWithCustomConfiguration( |
| 142 GetWindow()->GetNativeWindow(), | 149 GetWindow()->GetNativeWindow(), |
| 143 this, | 150 this, |
| 144 l10n_util::GetStringF(IDS_SYNC_STOP_SYNCING_EXPLANATION_LABEL, | 151 l10n_util::GetStringF(IDS_SYNC_STOP_SYNCING_EXPLANATION_LABEL, |
| 145 l10n_util::GetString(IDS_PRODUCT_NAME)), | 152 l10n_util::GetString(IDS_PRODUCT_NAME)), |
| 146 l10n_util::GetString(IDS_SYNC_STOP_SYNCING_DIALOG_TITLE), | 153 l10n_util::GetString(IDS_SYNC_STOP_SYNCING_DIALOG_TITLE), |
| 147 l10n_util::GetString(IDS_SYNC_STOP_SYNCING_CONFIRM_BUTTON_LABEL), | 154 l10n_util::GetString(IDS_SYNC_STOP_SYNCING_CONFIRM_BUTTON_LABEL), |
| 148 l10n_util::GetString(IDS_CANCEL), | 155 l10n_util::GetString(IDS_CANCEL), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 162 } | 169 } |
| 163 | 170 |
| 164 void ContentPageView::LinkActivated(views::Link* source, int event_flags) { | 171 void ContentPageView::LinkActivated(views::Link* source, int event_flags) { |
| 165 if (source == themes_gallery_link_) { | 172 if (source == themes_gallery_link_) { |
| 166 UserMetricsRecordAction(UserMetricsAction("Options_ThemesGallery"), | 173 UserMetricsRecordAction(UserMetricsAction("Options_ThemesGallery"), |
| 167 profile()->GetPrefs()); | 174 profile()->GetPrefs()); |
| 168 BrowserList::GetLastActive()->OpenThemeGalleryTabAndActivate(); | 175 BrowserList::GetLastActive()->OpenThemeGalleryTabAndActivate(); |
| 169 return; | 176 return; |
| 170 } | 177 } |
| 171 DCHECK_EQ(source, sync_action_link_); | 178 DCHECK_EQ(source, sync_action_link_); |
| 172 DCHECK(sync_service_); | 179 DCHECK(sync_service_ && !sync_service_->IsManaged()); |
| 173 sync_service_->ShowLoginDialog(); | 180 sync_service_->ShowLoginDialog(); |
| 174 } | 181 } |
| 175 | 182 |
| 176 //////////////////////////////////////////////////////////////////////////////// | 183 //////////////////////////////////////////////////////////////////////////////// |
| 177 // ContentPageView, OptionsPageView implementation: | 184 // ContentPageView, OptionsPageView implementation: |
| 178 | 185 |
| 179 void ContentPageView::InitControlLayout() { | 186 void ContentPageView::InitControlLayout() { |
| 180 using views::GridLayout; | 187 using views::GridLayout; |
| 181 using views::ColumnSet; | 188 using views::ColumnSet; |
| 182 | 189 |
| 183 GridLayout* layout = new GridLayout(this); | 190 GridLayout* layout = new GridLayout(this); |
| 184 layout->SetInsets(5, 5, 5, 5); | 191 layout->SetInsets(5, 5, 5, 5); |
| 185 SetLayoutManager(layout); | 192 SetLayoutManager(layout); |
| 186 | 193 |
| 187 const int single_column_view_set_id = 0; | 194 const int single_column_view_set_id = 0; |
| 188 ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id); | 195 ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id); |
| 189 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, | 196 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, |
| 190 GridLayout::USE_PREF, 0, 0); | 197 GridLayout::USE_PREF, 0, 0); |
| 191 | 198 |
| 199 layout->StartRow(0, single_column_view_set_id); |
| 200 layout->AddView( |
| 201 new ManagedPrefsBannerView(profile()->GetPrefs(), |
| 202 kContentPolicyConstrainedPrefs, |
| 203 arraysize(kContentPolicyConstrainedPrefs))); |
| 192 if (sync_service_) { | 204 if (sync_service_) { |
| 193 layout->StartRow(0, single_column_view_set_id); | 205 layout->StartRow(0, single_column_view_set_id); |
| 194 InitSyncGroup(); | 206 InitSyncGroup(); |
| 195 layout->AddView(sync_group_); | 207 layout->AddView(sync_group_); |
| 196 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 208 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
| 197 } | 209 } |
| 198 | 210 |
| 199 layout->StartRow(0, single_column_view_set_id); | 211 layout->StartRow(0, single_column_view_set_id); |
| 200 InitPasswordSavingGroup(); | 212 InitPasswordSavingGroup(); |
| 201 layout->AddView(passwords_group_); | 213 layout->AddView(passwords_group_); |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 sync_group_ = new OptionsGroupView(contents, | 474 sync_group_ = new OptionsGroupView(contents, |
| 463 l10n_util::GetString(IDS_SYNC_OPTIONS_GROUP_NAME), std::wstring(), true); | 475 l10n_util::GetString(IDS_SYNC_OPTIONS_GROUP_NAME), std::wstring(), true); |
| 464 } | 476 } |
| 465 | 477 |
| 466 void ContentPageView::UpdateSyncControls() { | 478 void ContentPageView::UpdateSyncControls() { |
| 467 DCHECK(sync_service_); | 479 DCHECK(sync_service_); |
| 468 std::wstring status_label; | 480 std::wstring status_label; |
| 469 std::wstring link_label; | 481 std::wstring link_label; |
| 470 std::wstring customize_button_label; | 482 std::wstring customize_button_label; |
| 471 std::wstring button_label; | 483 std::wstring button_label; |
| 484 bool managed = sync_service_->IsManaged(); |
| 472 bool sync_setup_completed = sync_service_->HasSyncSetupCompleted(); | 485 bool sync_setup_completed = sync_service_->HasSyncSetupCompleted(); |
| 473 bool status_has_error = sync_ui_util::GetStatusLabels(sync_service_, | 486 bool status_has_error = sync_ui_util::GetStatusLabels(sync_service_, |
| 474 &status_label, &link_label) == sync_ui_util::SYNC_ERROR; | 487 &status_label, &link_label) == sync_ui_util::SYNC_ERROR; |
| 475 customize_button_label = | 488 customize_button_label = |
| 476 l10n_util::GetString(IDS_SYNC_CUSTOMIZE_BUTTON_LABEL); | 489 l10n_util::GetString(IDS_SYNC_CUSTOMIZE_BUTTON_LABEL); |
| 477 if (sync_setup_completed) { | 490 if (sync_setup_completed) { |
| 478 button_label = l10n_util::GetString(IDS_SYNC_STOP_SYNCING_BUTTON_LABEL); | 491 button_label = l10n_util::GetString(IDS_SYNC_STOP_SYNCING_BUTTON_LABEL); |
| 479 } else if (sync_service_->SetupInProgress()) { | 492 } else if (sync_service_->SetupInProgress()) { |
| 480 button_label = l10n_util::GetString(IDS_SYNC_NTP_SETUP_IN_PROGRESS); | 493 button_label = l10n_util::GetString(IDS_SYNC_NTP_SETUP_IN_PROGRESS); |
| 481 } else { | 494 } else { |
| 482 button_label = l10n_util::GetString(IDS_SYNC_START_SYNC_BUTTON_LABEL); | 495 button_label = l10n_util::GetString(IDS_SYNC_START_SYNC_BUTTON_LABEL); |
| 483 } | 496 } |
| 484 | 497 |
| 485 sync_status_label_->SetText(status_label); | 498 sync_status_label_->SetText(status_label); |
| 486 sync_start_stop_button_->SetEnabled(!sync_service_->WizardIsVisible()); | 499 sync_start_stop_button_->SetEnabled( |
| 500 !sync_service_->WizardIsVisible() && !managed); |
| 487 sync_start_stop_button_->SetLabel(button_label); | 501 sync_start_stop_button_->SetLabel(button_label); |
| 488 sync_customize_button_->SetLabel(customize_button_label); | 502 sync_customize_button_->SetLabel(customize_button_label); |
| 489 sync_customize_button_->SetVisible(sync_setup_completed && !status_has_error); | 503 sync_customize_button_->SetVisible(sync_setup_completed && !status_has_error); |
| 504 sync_customize_button_->SetEnabled(!managed); |
| 490 sync_action_link_->SetText(link_label); | 505 sync_action_link_->SetText(link_label); |
| 491 sync_action_link_->SetVisible(!link_label.empty()); | 506 sync_action_link_->SetVisible(!link_label.empty()); |
| 507 sync_action_link_->SetEnabled(!managed); |
| 492 | 508 |
| 493 if (status_has_error) { | 509 if (status_has_error) { |
| 494 sync_status_label_->set_background(CreateErrorBackground()); | 510 sync_status_label_->set_background(CreateErrorBackground()); |
| 495 sync_action_link_->set_background(CreateErrorBackground()); | 511 sync_action_link_->set_background(CreateErrorBackground()); |
| 496 } else { | 512 } else { |
| 497 sync_status_label_->set_background(NULL); | 513 sync_status_label_->set_background(NULL); |
| 498 sync_action_link_->set_background(NULL); | 514 sync_action_link_->set_background(NULL); |
| 499 } | 515 } |
| 500 } | 516 } |
| OLD | NEW |