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 #import "chrome/browser/cocoa/preferences_window_controller.h" | 5 #import "chrome/browser/cocoa/preferences_window_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "app/l10n_util_mac.h" | 10 #include "app/l10n_util_mac.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 static const double kBannerGradientColorBottom[3] = | 68 static const double kBannerGradientColorBottom[3] = |
69 {250.0 / 255.0, 230.0 / 255.0, 145.0 / 255.0}; | 69 {250.0 / 255.0, 230.0 / 255.0, 145.0 / 255.0}; |
70 static const double kBannerStrokeColor = 135.0 / 255.0; | 70 static const double kBannerStrokeColor = 135.0 / 255.0; |
71 | 71 |
72 // Preferences relevant to the general page potentially constrained by policy. | 72 // Preferences relevant to the general page potentially constrained by policy. |
73 static const wchar_t* kGeneralPolicyConstrainedPrefs[] = { | 73 static const wchar_t* kGeneralPolicyConstrainedPrefs[] = { |
74 prefs::kHomePage, | 74 prefs::kHomePage, |
75 prefs::kHomePageIsNewTabPage | 75 prefs::kHomePageIsNewTabPage |
76 }; | 76 }; |
77 | 77 |
| 78 // Content page preferences that are potentially constrained by policy. |
| 79 static const wchar_t* kContentPolicyConstrainedPrefs[] = { |
| 80 prefs::kSyncManaged |
| 81 }; |
| 82 |
78 std::string GetNewTabUIURLString() { | 83 std::string GetNewTabUIURLString() { |
79 return URLFixerUpper::FixupURL(chrome::kChromeUINewTabURL, | 84 return URLFixerUpper::FixupURL(chrome::kChromeUINewTabURL, |
80 std::string()).possibly_invalid_spec(); | 85 std::string()).possibly_invalid_spec(); |
81 } | 86 } |
82 | 87 |
83 // Helper that sizes two buttons to fit in a row keeping their spacing, returns | 88 // Helper that sizes two buttons to fit in a row keeping their spacing, returns |
84 // the total horizontal size change. | 89 // the total horizontal size change. |
85 CGFloat SizeToFitButtonPair(NSButton* leftButton, NSButton* rightButton) { | 90 CGFloat SizeToFitButtonPair(NSButton* leftButton, NSButton* rightButton) { |
86 CGFloat widthShift = 0.0; | 91 CGFloat widthShift = 0.0; |
87 | 92 |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 static ManagedPrefsBannerState* CreateForPage( | 409 static ManagedPrefsBannerState* CreateForPage( |
405 PreferencesWindowController* controller, | 410 PreferencesWindowController* controller, |
406 OptionsPage page, | 411 OptionsPage page, |
407 PrefService* prefs) { | 412 PrefService* prefs) { |
408 switch (page) { | 413 switch (page) { |
409 case OPTIONS_PAGE_GENERAL: | 414 case OPTIONS_PAGE_GENERAL: |
410 return new ManagedPrefsBannerState(controller, page, prefs, | 415 return new ManagedPrefsBannerState(controller, page, prefs, |
411 kGeneralPolicyConstrainedPrefs, | 416 kGeneralPolicyConstrainedPrefs, |
412 arraysize(kGeneralPolicyConstrainedPrefs)); | 417 arraysize(kGeneralPolicyConstrainedPrefs)); |
413 case OPTIONS_PAGE_CONTENT: | 418 case OPTIONS_PAGE_CONTENT: |
| 419 return new ManagedPrefsBannerState(controller, page, prefs, |
| 420 kContentPolicyConstrainedPrefs, |
| 421 arraysize(kContentPolicyConstrainedPrefs)); |
414 break; | 422 break; |
415 case OPTIONS_PAGE_ADVANCED: | 423 case OPTIONS_PAGE_ADVANCED: |
416 break; | 424 break; |
417 case OPTIONS_PAGE_DEFAULT: | 425 case OPTIONS_PAGE_DEFAULT: |
418 case OPTIONS_PAGE_COUNT: | 426 case OPTIONS_PAGE_COUNT: |
419 LOG(DFATAL) << "Invalid page value " << page; | 427 LOG(DFATAL) << "Invalid page value " << page; |
420 break; | 428 break; |
421 } | 429 } |
422 return new ManagedPrefsBannerState(controller, page, prefs, NULL, 0); | 430 return new ManagedPrefsBannerState(controller, page, prefs, NULL, 0); |
423 } | 431 } |
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1227 browser = Browser::Create(profile_); | 1235 browser = Browser::Create(profile_); |
1228 browser->OpenThemeGalleryTabAndActivate(); | 1236 browser->OpenThemeGalleryTabAndActivate(); |
1229 } | 1237 } |
1230 | 1238 |
1231 // Called when the "stop syncing" confirmation dialog started by | 1239 // Called when the "stop syncing" confirmation dialog started by |
1232 // doSyncAction is finished. Stop syncing only If the user clicked | 1240 // doSyncAction is finished. Stop syncing only If the user clicked |
1233 // OK. | 1241 // OK. |
1234 - (void)stopSyncAlertDidEnd:(NSAlert*)alert | 1242 - (void)stopSyncAlertDidEnd:(NSAlert*)alert |
1235 returnCode:(int)returnCode | 1243 returnCode:(int)returnCode |
1236 contextInfo:(void*)contextInfo { | 1244 contextInfo:(void*)contextInfo { |
1237 DCHECK(syncService_); | 1245 DCHECK(syncService_ && !syncService_->IsManaged()); |
1238 if (returnCode == NSAlertFirstButtonReturn) { | 1246 if (returnCode == NSAlertFirstButtonReturn) { |
1239 syncService_->DisableForUser(); | 1247 syncService_->DisableForUser(); |
1240 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS); | 1248 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS); |
1241 } | 1249 } |
1242 } | 1250 } |
1243 | 1251 |
1244 // Called when the user clicks the multi-purpose sync button in the | 1252 // Called when the user clicks the multi-purpose sync button in the |
1245 // "Personal Stuff" pane. | 1253 // "Personal Stuff" pane. |
1246 - (IBAction)doSyncAction:(id)sender { | 1254 - (IBAction)doSyncAction:(id)sender { |
1247 DCHECK(syncService_); | 1255 DCHECK(syncService_ && !syncService_->IsManaged()); |
1248 if (syncService_->HasSyncSetupCompleted()) { | 1256 if (syncService_->HasSyncSetupCompleted()) { |
1249 // If sync setup has completed that means the sync button was a | 1257 // If sync setup has completed that means the sync button was a |
1250 // "stop syncing" button. Bring up a confirmation dialog before | 1258 // "stop syncing" button. Bring up a confirmation dialog before |
1251 // actually stopping syncing (see stopSyncAlertDidEnd). | 1259 // actually stopping syncing (see stopSyncAlertDidEnd). |
1252 scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]); | 1260 scoped_nsobject<NSAlert> alert([[NSAlert alloc] init]); |
1253 [alert addButtonWithTitle:l10n_util::GetNSStringWithFixup( | 1261 [alert addButtonWithTitle:l10n_util::GetNSStringWithFixup( |
1254 IDS_SYNC_STOP_SYNCING_CONFIRM_BUTTON_LABEL)]; | 1262 IDS_SYNC_STOP_SYNCING_CONFIRM_BUTTON_LABEL)]; |
1255 [alert addButtonWithTitle:l10n_util::GetNSStringWithFixup( | 1263 [alert addButtonWithTitle:l10n_util::GetNSStringWithFixup( |
1256 IDS_CANCEL)]; | 1264 IDS_CANCEL)]; |
1257 [alert setMessageText:l10n_util::GetNSStringWithFixup( | 1265 [alert setMessageText:l10n_util::GetNSStringWithFixup( |
(...skipping 17 matching lines...) Expand all Loading... |
1275 } | 1283 } |
1276 | 1284 |
1277 // Called when the user clicks the "Customize Sync" button in the | 1285 // Called when the user clicks the "Customize Sync" button in the |
1278 // "Personal Stuff" pane. Spawns a dialog-modal sheet that cleans | 1286 // "Personal Stuff" pane. Spawns a dialog-modal sheet that cleans |
1279 // itself up on close. | 1287 // itself up on close. |
1280 - (IBAction)doSyncCustomize:(id)sender { | 1288 - (IBAction)doSyncCustomize:(id)sender { |
1281 syncService_->ShowChooseDataTypes(); | 1289 syncService_->ShowChooseDataTypes(); |
1282 } | 1290 } |
1283 | 1291 |
1284 - (IBAction)doSyncReauthentication:(id)sender { | 1292 - (IBAction)doSyncReauthentication:(id)sender { |
1285 DCHECK(syncService_); | 1293 DCHECK(syncService_ && !syncService_->IsManaged()); |
1286 syncService_->ShowLoginDialog(); | 1294 syncService_->ShowLoginDialog(); |
1287 } | 1295 } |
1288 | 1296 |
1289 - (void)setPasswordManagerEnabledIndex:(NSInteger)value { | 1297 - (void)setPasswordManagerEnabledIndex:(NSInteger)value { |
1290 if (value == kEnabledIndex) | 1298 if (value == kEnabledIndex) |
1291 [self recordUserAction:UserMetricsAction( | 1299 [self recordUserAction:UserMetricsAction( |
1292 "Options_PasswordManager_Enable")]; | 1300 "Options_PasswordManager_Enable")]; |
1293 else | 1301 else |
1294 [self recordUserAction:UserMetricsAction( | 1302 [self recordUserAction:UserMetricsAction( |
1295 "Options_PasswordManager_Disable")]; | 1303 "Options_PasswordManager_Disable")]; |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1703 // | 1711 // |
1704 // TODO(akalin): Decomp this out since a lot of it is copied from the | 1712 // TODO(akalin): Decomp this out since a lot of it is copied from the |
1705 // Windows version. | 1713 // Windows version. |
1706 // TODO(akalin): Change the background of the status label/link on error. | 1714 // TODO(akalin): Change the background of the status label/link on error. |
1707 - (void)syncStateChanged { | 1715 - (void)syncStateChanged { |
1708 DCHECK(syncService_); | 1716 DCHECK(syncService_); |
1709 | 1717 |
1710 string16 statusLabel, linkLabel; | 1718 string16 statusLabel, linkLabel; |
1711 sync_ui_util::MessageType status = | 1719 sync_ui_util::MessageType status = |
1712 sync_ui_util::GetStatusLabels(syncService_, &statusLabel, &linkLabel); | 1720 sync_ui_util::GetStatusLabels(syncService_, &statusLabel, &linkLabel); |
| 1721 bool managed = syncService_->IsManaged(); |
1713 | 1722 |
1714 [syncButton_ setEnabled:!syncService_->WizardIsVisible()]; | 1723 [syncButton_ setEnabled:!syncService_->WizardIsVisible()]; |
1715 NSString* buttonLabel; | 1724 NSString* buttonLabel; |
1716 if (syncService_->HasSyncSetupCompleted() | 1725 if (syncService_->HasSyncSetupCompleted() |
1717 && status != sync_ui_util::SYNC_ERROR) { | 1726 && status != sync_ui_util::SYNC_ERROR) { |
1718 buttonLabel = l10n_util::GetNSStringWithFixup( | 1727 buttonLabel = l10n_util::GetNSStringWithFixup( |
1719 IDS_SYNC_STOP_SYNCING_BUTTON_LABEL); | 1728 IDS_SYNC_STOP_SYNCING_BUTTON_LABEL); |
1720 [syncCustomizeButton_ setHidden:false]; | 1729 [syncCustomizeButton_ setHidden:false]; |
1721 } else if (syncService_->SetupInProgress()) { | 1730 } else if (syncService_->SetupInProgress()) { |
1722 buttonLabel = l10n_util::GetNSStringWithFixup( | 1731 buttonLabel = l10n_util::GetNSStringWithFixup( |
1723 IDS_SYNC_NTP_SETUP_IN_PROGRESS); | 1732 IDS_SYNC_NTP_SETUP_IN_PROGRESS); |
1724 [syncCustomizeButton_ setHidden:true]; | 1733 [syncCustomizeButton_ setHidden:true]; |
1725 } else { | 1734 } else { |
1726 buttonLabel = l10n_util::GetNSStringWithFixup( | 1735 buttonLabel = l10n_util::GetNSStringWithFixup( |
1727 IDS_SYNC_START_SYNC_BUTTON_LABEL); | 1736 IDS_SYNC_START_SYNC_BUTTON_LABEL); |
1728 [syncCustomizeButton_ setHidden:true]; | 1737 [syncCustomizeButton_ setHidden:true]; |
1729 } | 1738 } |
| 1739 [syncCustomizeButton_ setEnabled:!managed]; |
1730 [syncButton_ setTitle:buttonLabel]; | 1740 [syncButton_ setTitle:buttonLabel]; |
| 1741 [syncButton_ setEnabled:!managed]; |
1731 | 1742 |
1732 [syncStatus_ setStringValue:base::SysUTF16ToNSString(statusLabel)]; | 1743 [syncStatus_ setStringValue:base::SysUTF16ToNSString(statusLabel)]; |
1733 [syncLink_ setHidden:linkLabel.empty()]; | 1744 [syncLink_ setHidden:linkLabel.empty()]; |
1734 [syncLink_ setTitle:base::SysUTF16ToNSString(linkLabel)]; | 1745 [syncLink_ setTitle:base::SysUTF16ToNSString(linkLabel)]; |
| 1746 [syncLink_ setEnabled:!managed]; |
1735 | 1747 |
1736 NSButtonCell* syncLinkCell = static_cast<NSButtonCell*>([syncLink_ cell]); | 1748 NSButtonCell* syncLinkCell = static_cast<NSButtonCell*>([syncLink_ cell]); |
1737 if (!syncStatusNoErrorBackgroundColor_) { | 1749 if (!syncStatusNoErrorBackgroundColor_) { |
1738 DCHECK(!syncLinkNoErrorBackgroundColor_); | 1750 DCHECK(!syncLinkNoErrorBackgroundColor_); |
1739 // We assume that the sync controls start off in a non-error | 1751 // We assume that the sync controls start off in a non-error |
1740 // state. | 1752 // state. |
1741 syncStatusNoErrorBackgroundColor_.reset( | 1753 syncStatusNoErrorBackgroundColor_.reset( |
1742 [[syncStatus_ backgroundColor] retain]); | 1754 [[syncStatus_ backgroundColor] retain]); |
1743 syncLinkNoErrorBackgroundColor_.reset( | 1755 syncLinkNoErrorBackgroundColor_.reset( |
1744 [[syncLinkCell backgroundColor] retain]); | 1756 [[syncLinkCell backgroundColor] retain]); |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2019 case OPTIONS_PAGE_ADVANCED: | 2031 case OPTIONS_PAGE_ADVANCED: |
2020 return underTheHoodView_; | 2032 return underTheHoodView_; |
2021 case OPTIONS_PAGE_DEFAULT: | 2033 case OPTIONS_PAGE_DEFAULT: |
2022 case OPTIONS_PAGE_COUNT: | 2034 case OPTIONS_PAGE_COUNT: |
2023 LOG(DFATAL) << "Invalid page value " << page; | 2035 LOG(DFATAL) << "Invalid page value " << page; |
2024 } | 2036 } |
2025 return basicsView_; | 2037 return basicsView_; |
2026 } | 2038 } |
2027 | 2039 |
2028 @end | 2040 @end |
OLD | NEW |