| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 9 #include "app/l10n_util_mac.h" |
| 9 #include "base/mac_util.h" | 10 #include "base/mac_util.h" |
| 11 #include "base/string16.h" |
| 10 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 11 #include "base/sys_string_conversions.h" | 13 #include "base/sys_string_conversions.h" |
| 12 #include "chrome/browser/browser.h" | 14 #include "chrome/browser/browser.h" |
| 13 #include "chrome/browser/browser_list.h" | 15 #include "chrome/browser/browser_list.h" |
| 14 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
| 15 #import "chrome/browser/cocoa/clear_browsing_data_controller.h" | 17 #import "chrome/browser/cocoa/clear_browsing_data_controller.h" |
| 16 #import "chrome/browser/cocoa/custom_home_pages_model.h" | 18 #import "chrome/browser/cocoa/custom_home_pages_model.h" |
| 17 #import "chrome/browser/cocoa/keyword_editor_cocoa_controller.h" | 19 #import "chrome/browser/cocoa/keyword_editor_cocoa_controller.h" |
| 18 #import "chrome/browser/cocoa/search_engine_list_model.h" | 20 #import "chrome/browser/cocoa/search_engine_list_model.h" |
| 19 #include "chrome/browser/extensions/extensions_service.h" | 21 #include "chrome/browser/extensions/extensions_service.h" |
| 20 #include "chrome/browser/metrics/metrics_service.h" | 22 #include "chrome/browser/metrics/metrics_service.h" |
| 21 #include "chrome/browser/metrics/user_metrics.h" | 23 #include "chrome/browser/metrics/user_metrics.h" |
| 22 #include "chrome/browser/net/dns_global.h" | 24 #include "chrome/browser/net/dns_global.h" |
| 23 #include "chrome/browser/net/url_fixer_upper.h" | 25 #include "chrome/browser/net/url_fixer_upper.h" |
| 24 #include "chrome/browser/options_window.h" | 26 #include "chrome/browser/options_window.h" |
| 25 #include "chrome/browser/profile.h" | 27 #include "chrome/browser/profile.h" |
| 26 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 28 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 27 #include "chrome/browser/session_startup_pref.h" | 29 #include "chrome/browser/session_startup_pref.h" |
| 28 #include "chrome/browser/shell_integration.h" | 30 #include "chrome/browser/shell_integration.h" |
| 31 #include "chrome/browser/sync/profile_sync_service.h" |
| 32 #include "chrome/browser/sync/sync_status_ui_helper.h" |
| 29 #include "chrome/browser/tab_contents/tab_contents.h" | 33 #include "chrome/browser/tab_contents/tab_contents.h" |
| 30 #include "chrome/common/notification_details.h" | 34 #include "chrome/common/notification_details.h" |
| 31 #include "chrome/common/notification_observer.h" | 35 #include "chrome/common/notification_observer.h" |
| 32 #include "chrome/common/notification_type.h" | 36 #include "chrome/common/notification_type.h" |
| 33 #include "chrome/common/pref_names.h" | 37 #include "chrome/common/pref_names.h" |
| 34 #include "chrome/common/pref_service.h" | 38 #include "chrome/common/pref_service.h" |
| 35 #include "chrome/common/url_constants.h" | 39 #include "chrome/common/url_constants.h" |
| 36 #include "chrome/installer/util/google_update_settings.h" | 40 #include "chrome/installer/util/google_update_settings.h" |
| 37 #include "grit/chromium_strings.h" | 41 #include "grit/chromium_strings.h" |
| 38 #include "grit/generated_resources.h" | 42 #include "grit/generated_resources.h" |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 CGFloat y1 = NSMinY([view1 frame]); | 246 CGFloat y1 = NSMinY([view1 frame]); |
| 243 CGFloat y2 = NSMinY([view2 frame]); | 247 CGFloat y2 = NSMinY([view2 frame]); |
| 244 if (y1 < y2) | 248 if (y1 < y2) |
| 245 return NSOrderedAscending; | 249 return NSOrderedAscending; |
| 246 else if (y1 > y2) | 250 else if (y1 > y2) |
| 247 return NSOrderedDescending; | 251 return NSOrderedDescending; |
| 248 else | 252 else |
| 249 return NSOrderedSame; | 253 return NSOrderedSame; |
| 250 } | 254 } |
| 251 | 255 |
| 252 #if !defined(GOOGLE_CHROME_BUILD) | |
| 253 // Helper to remove a view and move everything above it down to take over the | 256 // Helper to remove a view and move everything above it down to take over the |
| 254 // space. | 257 // space. |
| 255 void RemoveViewFromView(NSView* view, NSView* toRemove) { | 258 void RemoveViewFromView(NSView* view, NSView* toRemove) { |
| 256 // Sort bottom up so we can spin over what is above it. | 259 // Sort bottom up so we can spin over what is above it. |
| 257 NSArray* views = | 260 NSArray* views = |
| 258 [[view subviews] sortedArrayUsingFunction:CompareFrameY context:NULL]; | 261 [[view subviews] sortedArrayUsingFunction:CompareFrameY context:NULL]; |
| 259 | 262 |
| 260 // Find where |toRemove| was. | 263 // Find where |toRemove| was. |
| 261 NSUInteger index = [views indexOfObject:toRemove]; | 264 NSUInteger index = [views indexOfObject:toRemove]; |
| 262 DCHECK_NE(index, NSNotFound); | 265 DCHECK_NE(index, NSNotFound); |
| 263 NSUInteger count = [views count]; | 266 NSUInteger count = [views count]; |
| 264 if (index == (count - 1)) | 267 CGFloat shrinkHeight = 0; |
| 265 return; // It was the top item, nothing to do (shouldn't happen). | 268 if (index < (count - 1)) { |
| 269 // If we're not the topmost control, the amount to shift is the bottom of |
| 270 // |toRemove| to the bottom of the view above it. |
| 271 CGFloat shiftDown = |
| 272 NSMinY([[views objectAtIndex:index + 1] frame]) - |
| 273 NSMinY([toRemove frame]); |
| 266 | 274 |
| 267 // The amount to shift is the bottom of |toRemove| to the bottom of the view | 275 // Now cycle over the views above it moving them down. |
| 268 // above it. | 276 for (++index; index < count; ++index) { |
| 269 CGFloat shiftDown = | 277 NSView* view = [views objectAtIndex:index]; |
| 270 NSMinY([[views objectAtIndex:index + 1] frame]) - | 278 NSPoint origin = [view frame].origin; |
| 271 NSMinY([toRemove frame]); | 279 origin.y -= shiftDown; |
| 280 [view setFrameOrigin:origin]; |
| 281 } |
| 272 | 282 |
| 273 // Now cycle over the views above it moving them down. | 283 shrinkHeight = shiftDown; |
| 274 for (++index; index < count; ++index) { | 284 } else if (index > 0) { |
| 275 NSView* view = [views objectAtIndex:index]; | 285 // If we're the topmost control, there's nothing to shift but we want to |
| 276 NSPoint origin = [view frame].origin; | 286 // shrink until the top edge of the second-topmost control, unless it is |
| 277 origin.y -= shiftDown; | 287 // actually higher than the topmost control (since we're sorting by the |
| 278 [view setFrameOrigin:origin]; | 288 // bottom edge). |
| 289 shrinkHeight = std::max(0.f, |
| 290 NSMaxY([toRemove frame]) - |
| 291 NSMaxY([[views objectAtIndex:index - 1] frame])); |
| 279 } | 292 } |
| 293 // If we only have one control, don't do any resizing (for now). |
| 280 | 294 |
| 281 // Remove |toRemove|. | 295 // Remove |toRemove|. |
| 282 [toRemove removeFromSuperview]; | 296 [toRemove removeFromSuperview]; |
| 283 | 297 |
| 284 // Resize the view. | |
| 285 [GTMUILocalizerAndLayoutTweaker | 298 [GTMUILocalizerAndLayoutTweaker |
| 286 resizeViewWithoutAutoResizingSubViews:view | 299 resizeViewWithoutAutoResizingSubViews:view |
| 287 delta:NSMakeSize(0, -shiftDown)]; | 300 delta:NSMakeSize(0, -shrinkHeight)]; |
| 288 } | 301 } |
| 289 #endif // !defined(GOOGLE_CHROME_BUILD) | 302 |
| 303 // Simply removes all the views in |toRemove|. |
| 304 void RemoveGroupFromView(NSView* view, NSArray* toRemove) { |
| 305 for (NSView* viewToRemove in toRemove) { |
| 306 RemoveViewFromView(view, viewToRemove); |
| 307 } |
| 308 } |
| 290 | 309 |
| 291 // Helper to tweak the layout of the "Under the Hood" content by autosizing all | 310 // Helper to tweak the layout of the "Under the Hood" content by autosizing all |
| 292 // the views and moving things up vertically. Special case the two controls for | 311 // the views and moving things up vertically. Special case the two controls for |
| 293 // download location as they are horizontal, and should fill the row. | 312 // download location as they are horizontal, and should fill the row. |
| 294 CGFloat AutoSizeUnderTheHoodContent(NSView* view, | 313 CGFloat AutoSizeUnderTheHoodContent(NSView* view, |
| 295 NSPathControl* downloadLocationControl, | 314 NSPathControl* downloadLocationControl, |
| 296 NSButton* downloadLocationButton) { | 315 NSButton* downloadLocationButton) { |
| 297 CGFloat verticalShift = 0.0; | 316 CGFloat verticalShift = 0.0; |
| 298 | 317 |
| 299 // Loop bottom up through the views sizing and shifting. | 318 // Loop bottom up through the views sizing and shifting. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 325 } | 344 } |
| 326 | 345 |
| 327 } // namespace | 346 } // namespace |
| 328 | 347 |
| 329 //------------------------------------------------------------------------- | 348 //------------------------------------------------------------------------- |
| 330 | 349 |
| 331 @interface PreferencesWindowController(Private) | 350 @interface PreferencesWindowController(Private) |
| 332 // Callback when preferences are changed. |prefName| is the name of the | 351 // Callback when preferences are changed. |prefName| is the name of the |
| 333 // pref that has changed. | 352 // pref that has changed. |
| 334 - (void)prefChanged:(std::wstring*)prefName; | 353 - (void)prefChanged:(std::wstring*)prefName; |
| 354 // Callback when sync state has changed. syncService_ needs to be |
| 355 // queried to find out what happened. |
| 356 - (void)syncStateChanged; |
| 335 // Record the user performed a certain action and save the preferences. | 357 // Record the user performed a certain action and save the preferences. |
| 336 - (void)recordUserAction:(const wchar_t*)action; | 358 - (void)recordUserAction:(const wchar_t*)action; |
| 337 - (void)registerPrefObservers; | 359 - (void)registerPrefObservers; |
| 338 - (void)unregisterPrefObservers; | 360 - (void)unregisterPrefObservers; |
| 339 | 361 |
| 340 - (void)customHomePagesChanged; | 362 - (void)customHomePagesChanged; |
| 341 | 363 |
| 342 // KVC setter methods. | 364 // KVC setter methods. |
| 343 - (void)setNewTabPageIsHomePageIndex:(NSInteger)val; | 365 - (void)setNewTabPageIsHomePageIndex:(NSInteger)val; |
| 344 - (void)setHomepageURL:(NSString*)urlString; | 366 - (void)setHomepageURL:(NSString*)urlString; |
| 345 - (void)setRestoreOnStartupIndex:(NSInteger)type; | 367 - (void)setRestoreOnStartupIndex:(NSInteger)type; |
| 346 - (void)setShowHomeButton:(BOOL)value; | 368 - (void)setShowHomeButton:(BOOL)value; |
| 347 - (void)setShowPageOptionsButtons:(BOOL)value; | 369 - (void)setShowPageOptionsButtons:(BOOL)value; |
| 348 - (void)setPasswordManagerEnabledIndex:(NSInteger)value; | 370 - (void)setPasswordManagerEnabledIndex:(NSInteger)value; |
| 349 - (void)setFormAutofillEnabledIndex:(NSInteger)value; | 371 - (void)setFormAutofillEnabledIndex:(NSInteger)value; |
| 350 - (void)setIsUsingDefaultTheme:(BOOL)value; | 372 - (void)setIsUsingDefaultTheme:(BOOL)value; |
| 351 - (void)setShowAlternateErrorPages:(BOOL)value; | 373 - (void)setShowAlternateErrorPages:(BOOL)value; |
| 352 - (void)setUseSuggest:(BOOL)value; | 374 - (void)setUseSuggest:(BOOL)value; |
| 353 - (void)setDnsPrefetch:(BOOL)value; | 375 - (void)setDnsPrefetch:(BOOL)value; |
| 354 - (void)setSafeBrowsing:(BOOL)value; | 376 - (void)setSafeBrowsing:(BOOL)value; |
| 355 - (void)setMetricsRecording:(BOOL)value; | 377 - (void)setMetricsRecording:(BOOL)value; |
| 356 - (void)setCookieBehavior:(NSInteger)value; | 378 - (void)setCookieBehavior:(NSInteger)value; |
| 357 - (void)setAskForSaveLocation:(BOOL)value; | 379 - (void)setAskForSaveLocation:(BOOL)value; |
| 358 - (void)displayPreferenceViewForToolbarItem:(NSToolbarItem*)toolbarItem | 380 - (void)displayPreferenceViewForToolbarItem:(NSToolbarItem*)toolbarItem |
| 359 animate:(BOOL)animate; | 381 animate:(BOOL)animate; |
| 360 @end | 382 @end |
| 361 | 383 |
| 362 // A C++ class registered for changes in preferences. Bridges the | 384 // A C++ class registered for changes in preferences. Bridges the |
| 363 // notification back to the PWC. | 385 // notification back to the PWC. |
| 364 class PrefObserverBridge : public NotificationObserver { | 386 class PrefObserverBridge : public NotificationObserver, |
| 387 public ProfileSyncServiceObserver { |
| 365 public: | 388 public: |
| 366 PrefObserverBridge(PreferencesWindowController* controller) | 389 PrefObserverBridge(PreferencesWindowController* controller) |
| 367 : controller_(controller) { } | 390 : controller_(controller) {} |
| 391 |
| 392 virtual ~PrefObserverBridge() {} |
| 393 |
| 368 // Overridden from NotificationObserver: | 394 // Overridden from NotificationObserver: |
| 369 virtual void Observe(NotificationType type, | 395 virtual void Observe(NotificationType type, |
| 370 const NotificationSource& source, | 396 const NotificationSource& source, |
| 371 const NotificationDetails& details) { | 397 const NotificationDetails& details) { |
| 372 if (type == NotificationType::PREF_CHANGED) | 398 if (type == NotificationType::PREF_CHANGED) |
| 373 [controller_ prefChanged:Details<std::wstring>(details).ptr()]; | 399 [controller_ prefChanged:Details<std::wstring>(details).ptr()]; |
| 374 } | 400 } |
| 401 |
| 402 // Overridden from ProfileSyncServiceObserver. |
| 403 virtual void OnStateChanged() { |
| 404 [controller_ syncStateChanged]; |
| 405 } |
| 406 |
| 375 private: | 407 private: |
| 376 PreferencesWindowController* controller_; // weak, owns us | 408 PreferencesWindowController* controller_; // weak, owns us |
| 377 }; | 409 }; |
| 378 | 410 |
| 379 @implementation PreferencesWindowController | 411 @implementation PreferencesWindowController |
| 380 | 412 |
| 381 - (id)initWithProfile:(Profile*)profile { | 413 - (id)initWithProfile:(Profile*)profile { |
| 382 DCHECK(profile); | 414 DCHECK(profile); |
| 383 // Use initWithWindowNibPath:: instead of initWithWindowNibName: so we | 415 // Use initWithWindowNibPath:: instead of initWithWindowNibName: so we |
| 384 // can override it in a unit test. | 416 // can override it in a unit test. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 // Use one animation so we can stop it if the user clicks quickly, and | 459 // Use one animation so we can stop it if the user clicks quickly, and |
| 428 // start the new animation. | 460 // start the new animation. |
| 429 animation_.reset([[NSViewAnimation alloc] init]); | 461 animation_.reset([[NSViewAnimation alloc] init]); |
| 430 // Make this the delegate so it can remove the old view at the end of the | 462 // Make this the delegate so it can remove the old view at the end of the |
| 431 // animation (once it is faded out). | 463 // animation (once it is faded out). |
| 432 [animation_ setDelegate:self]; | 464 [animation_ setDelegate:self]; |
| 433 // The default duration is 0.5s, which actually feels slow in here, so speed | 465 // The default duration is 0.5s, which actually feels slow in here, so speed |
| 434 // it up a bit. | 466 // it up a bit. |
| 435 [animation_ gtm_setDuration:0.2]; | 467 [animation_ gtm_setDuration:0.2]; |
| 436 [animation_ setAnimationBlockingMode:NSAnimationNonblocking]; | 468 [animation_ setAnimationBlockingMode:NSAnimationNonblocking]; |
| 469 |
| 470 // TODO(akalin): handle incognito profiles? The windows version of this |
| 471 // (in chrome/browser/views/options/content_page_view.cc) just does what |
| 472 // we do below. |
| 473 syncService_ = profile_->GetProfileSyncService(); |
| 437 } | 474 } |
| 438 return self; | 475 return self; |
| 439 } | 476 } |
| 440 | 477 |
| 441 - (void)awakeFromNib { | 478 - (void)awakeFromNib { |
| 442 | 479 |
| 443 // Validate some assumptions in debug builds. | 480 // Validate some assumptions in debug builds. |
| 444 | 481 |
| 445 // "Basics", "Personal Stuff", and "Under the Hood" views should be the same | 482 // "Basics", "Personal Stuff", and "Under the Hood" views should be the same |
| 446 // width. They should be the same width so they are laid out to look as good | 483 // width. They should be the same width so they are laid out to look as good |
| (...skipping 10 matching lines...) Expand all Loading... |
| 457 << "The Under the Hood content should be narrower than the content " | 494 << "The Under the Hood content should be narrower than the content " |
| 458 "of the scroller it goes into"; | 495 "of the scroller it goes into"; |
| 459 | 496 |
| 460 #if !defined(GOOGLE_CHROME_BUILD) | 497 #if !defined(GOOGLE_CHROME_BUILD) |
| 461 // "Enable logging" (breakpad and stats) is only in Google Chrome builds, | 498 // "Enable logging" (breakpad and stats) is only in Google Chrome builds, |
| 462 // remove the checkbox and slide everything above it down. | 499 // remove the checkbox and slide everything above it down. |
| 463 RemoveViewFromView(underTheHoodContentView_, enableLoggingCheckbox_); | 500 RemoveViewFromView(underTheHoodContentView_, enableLoggingCheckbox_); |
| 464 #endif // !defined(GOOGLE_CHROME_BUILD) | 501 #endif // !defined(GOOGLE_CHROME_BUILD) |
| 465 | 502 |
| 466 // There are three problem children within the groups: | 503 // There are three problem children within the groups: |
| 467 // Bascis - Default Browser | 504 // Basics - Default Browser |
| 468 // Personal Stuff - Themes | 505 // Personal Stuff - Themes |
| 469 // Personal Stuff - Browser Data | 506 // Personal Stuff - Browser Data |
| 470 // These three have buttons that with some localizations are wider then the | 507 // These three have buttons that with some localizations are wider then the |
| 471 // view. So the three get manually laid out before doing the general work so | 508 // view. So the three get manually laid out before doing the general work so |
| 472 // the views/window can be made wide enough to fit them. The layout in the | 509 // the views/window can be made wide enough to fit them. The layout in the |
| 473 // general pass is a noop for these buttons (since they are already sized). | 510 // general pass is a noop for these buttons (since they are already sized). |
| 474 | 511 |
| 475 // Size the default browser button. | 512 // Size the default browser button. |
| 476 const NSUInteger kDefaultBrowserGroupCount = 3; | 513 const NSUInteger kDefaultBrowserGroupCount = 3; |
| 477 const NSUInteger kDefaultBrowserButtonIndex = 1; | 514 const NSUInteger kDefaultBrowserButtonIndex = 1; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 verticalShift); | 589 verticalShift); |
| 553 verticalShift += AutoSizeGroup(personalStuffGroupBrowserData_, | 590 verticalShift += AutoSizeGroup(personalStuffGroupBrowserData_, |
| 554 kAutoSizeGroupBehaviorVerticalToFit, | 591 kAutoSizeGroupBehaviorVerticalToFit, |
| 555 verticalShift); | 592 verticalShift); |
| 556 verticalShift += AutoSizeGroup(personalStuffGroupAutofill_, | 593 verticalShift += AutoSizeGroup(personalStuffGroupAutofill_, |
| 557 kAutoSizeGroupBehaviorVerticalToFit, | 594 kAutoSizeGroupBehaviorVerticalToFit, |
| 558 verticalShift); | 595 verticalShift); |
| 559 verticalShift += AutoSizeGroup(personalStuffGroupPasswords_, | 596 verticalShift += AutoSizeGroup(personalStuffGroupPasswords_, |
| 560 kAutoSizeGroupBehaviorVerticalToFit, | 597 kAutoSizeGroupBehaviorVerticalToFit, |
| 561 verticalShift); | 598 verticalShift); |
| 599 // We want to autosize the sync button but not the text field, so we use |
| 600 // VerticalFirstToFit. |
| 601 verticalShift += AutoSizeGroup(personalStuffGroupSync_, |
| 602 kAutoSizeGroupBehaviorVerticalFirstToFit, |
| 603 verticalShift); |
| 562 [GTMUILocalizerAndLayoutTweaker | 604 [GTMUILocalizerAndLayoutTweaker |
| 563 resizeViewWithoutAutoResizingSubViews:personalStuffView_ | 605 resizeViewWithoutAutoResizingSubViews:personalStuffView_ |
| 564 delta:NSMakeSize(0.0, verticalShift)]; | 606 delta:NSMakeSize(0.0, verticalShift)]; |
| 565 | 607 |
| 608 if (syncService_) { |
| 609 syncService_->AddObserver(observer_.get()); |
| 610 // Update the controls according to the initial state. |
| 611 [self syncStateChanged]; |
| 612 } else { |
| 613 // If sync is disabled we don't want to show the sync controls at all. |
| 614 RemoveGroupFromView(personalStuffView_, personalStuffGroupSync_); |
| 615 } |
| 616 |
| 566 // Make the window as wide as the views. | 617 // Make the window as wide as the views. |
| 567 NSWindow* prefsWindow = [self window]; | 618 NSWindow* prefsWindow = [self window]; |
| 568 NSRect frame = [prefsWindow frame]; | 619 NSRect frame = [prefsWindow frame]; |
| 569 frame.size.width = newWidth; | 620 frame.size.width = newWidth; |
| 570 [prefsWindow setFrame:frame display:NO]; | 621 [prefsWindow setFrame:frame display:NO]; |
| 571 | 622 |
| 572 // The Under the Hood prefs is a scroller, it shouldn't get any border, so it | 623 // The Under the Hood prefs is a scroller, it shouldn't get any border, so it |
| 573 // gets resized to the as wide as the window ended up. | 624 // gets resized to the as wide as the window ended up. |
| 574 NSSize underTheHoodSize = [underTheHoodView_ frame].size; | 625 NSSize underTheHoodSize = [underTheHoodView_ frame].size; |
| 575 underTheHoodSize.width = newWidth; | 626 underTheHoodSize.width = newWidth; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 606 pageIndex = 0; | 657 pageIndex = 0; |
| 607 NSToolbarItem* firstItem = [[toolbar_ items] objectAtIndex:pageIndex]; | 658 NSToolbarItem* firstItem = [[toolbar_ items] objectAtIndex:pageIndex]; |
| 608 [self displayPreferenceViewForToolbarItem:firstItem animate:NO]; | 659 [self displayPreferenceViewForToolbarItem:firstItem animate:NO]; |
| 609 [toolbar_ setSelectedItemIdentifier:[firstItem itemIdentifier]]; | 660 [toolbar_ setSelectedItemIdentifier:[firstItem itemIdentifier]]; |
| 610 | 661 |
| 611 // TODO(pinkerton): save/restore position based on prefs. | 662 // TODO(pinkerton): save/restore position based on prefs. |
| 612 [[self window] center]; | 663 [[self window] center]; |
| 613 } | 664 } |
| 614 | 665 |
| 615 - (void)dealloc { | 666 - (void)dealloc { |
| 667 if (syncService_) { |
| 668 syncService_->RemoveObserver(observer_.get()); |
| 669 } |
| 616 [customPagesSource_ removeObserver:self forKeyPath:@"customHomePages"]; | 670 [customPagesSource_ removeObserver:self forKeyPath:@"customHomePages"]; |
| 617 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 671 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 618 [self unregisterPrefObservers]; | 672 [self unregisterPrefObservers]; |
| 619 [super dealloc]; | 673 [super dealloc]; |
| 620 } | 674 } |
| 621 | 675 |
| 622 // Xcode 3.1.x version of Interface Builder doesn't do a lot for editing | 676 // Xcode 3.1.x version of Interface Builder doesn't do a lot for editing |
| 623 // toolbars in XIB. So the toolbar's delegate is set to the controller so it | 677 // toolbars in XIB. So the toolbar's delegate is set to the controller so it |
| 624 // can tell the toolbar what items are selectable. | 678 // can tell the toolbar what items are selectable. |
| 625 - (NSArray*)toolbarSelectableItemIdentifiers:(NSToolbar*)toolbar { | 679 - (NSArray*)toolbarSelectableItemIdentifiers:(NSToolbar*)toolbar { |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1126 browser->OpenURL( | 1180 browser->OpenURL( |
| 1127 GURL(l10n_util::GetStringUTF8(IDS_THEMES_GALLERY_URL)), | 1181 GURL(l10n_util::GetStringUTF8(IDS_THEMES_GALLERY_URL)), |
| 1128 GURL(), NEW_WINDOW, PageTransition::LINK); | 1182 GURL(), NEW_WINDOW, PageTransition::LINK); |
| 1129 } else { | 1183 } else { |
| 1130 browser->OpenURL( | 1184 browser->OpenURL( |
| 1131 GURL(l10n_util::GetStringUTF8(IDS_THEMES_GALLERY_URL)), | 1185 GURL(l10n_util::GetStringUTF8(IDS_THEMES_GALLERY_URL)), |
| 1132 GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK); | 1186 GURL(), NEW_FOREGROUND_TAB, PageTransition::LINK); |
| 1133 } | 1187 } |
| 1134 } | 1188 } |
| 1135 | 1189 |
| 1190 - (IBAction)doSyncAction:(id)sender { |
| 1191 DCHECK(syncService_); |
| 1192 if (syncService_->HasSyncSetupCompleted()) { |
| 1193 syncService_->DisableForUser(); |
| 1194 ProfileSyncService::SyncEvent(ProfileSyncService::STOP_FROM_OPTIONS); |
| 1195 // TODO(akalin): Pop up a confirmation dialog before disabling syncing. |
| 1196 } else { |
| 1197 syncService_->EnableForUser(); |
| 1198 ProfileSyncService::SyncEvent(ProfileSyncService::START_FROM_OPTIONS); |
| 1199 } |
| 1200 } |
| 1201 |
| 1136 - (void)setPasswordManagerEnabledIndex:(NSInteger)value { | 1202 - (void)setPasswordManagerEnabledIndex:(NSInteger)value { |
| 1137 if (value == kEnabledIndex) | 1203 if (value == kEnabledIndex) |
| 1138 [self recordUserAction:L"Options_PasswordManager_Enable"]; | 1204 [self recordUserAction:L"Options_PasswordManager_Enable"]; |
| 1139 else | 1205 else |
| 1140 [self recordUserAction:L"Options_PasswordManager_Disable"]; | 1206 [self recordUserAction:L"Options_PasswordManager_Disable"]; |
| 1141 askSavePasswords_.SetValue(value == kEnabledIndex ? true : false); | 1207 askSavePasswords_.SetValue(value == kEnabledIndex ? true : false); |
| 1142 } | 1208 } |
| 1143 | 1209 |
| 1144 - (NSInteger)passwordManagerEnabledIndex { | 1210 - (NSInteger)passwordManagerEnabledIndex { |
| 1145 return askSavePasswords_.GetValue() ? kEnabledIndex : kDisabledIndex; | 1211 return askSavePasswords_.GetValue() ? kEnabledIndex : kDisabledIndex; |
| (...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1519 // Callback when preferences are changed. |prefName| is the name of the | 1585 // Callback when preferences are changed. |prefName| is the name of the |
| 1520 // pref that has changed and should not be NULL. | 1586 // pref that has changed and should not be NULL. |
| 1521 - (void)prefChanged:(std::wstring*)prefName { | 1587 - (void)prefChanged:(std::wstring*)prefName { |
| 1522 DCHECK(prefName); | 1588 DCHECK(prefName); |
| 1523 if (!prefName) return; | 1589 if (!prefName) return; |
| 1524 [self basicsPrefChanged:prefName]; | 1590 [self basicsPrefChanged:prefName]; |
| 1525 [self userDataPrefChanged:prefName]; | 1591 [self userDataPrefChanged:prefName]; |
| 1526 [self underHoodPrefChanged:prefName]; | 1592 [self underHoodPrefChanged:prefName]; |
| 1527 } | 1593 } |
| 1528 | 1594 |
| 1595 // Callback when sync service state has changed. |
| 1596 // |
| 1597 // TODO(akalin): Decomp this out since a lot of it is copied from the |
| 1598 // Windows version. |
| 1599 // TODO(akalin): Actually have a control for the link. |
| 1600 // TODO(akalin): Change the background of the status label/link on error. |
| 1601 // TODO(akalin): Make sure selecting the "Sync my bookmarks..." menu item |
| 1602 // pops up this preference pane if syncing has already been set up. |
| 1603 - (void)syncStateChanged { |
| 1604 DCHECK(syncService_); |
| 1605 |
| 1606 [syncButton_ setEnabled:!syncService_->WizardIsVisible()]; |
| 1607 NSString* buttonLabel; |
| 1608 if (syncService_->HasSyncSetupCompleted()) { |
| 1609 buttonLabel = l10n_util::GetNSStringWithFixup( |
| 1610 IDS_SYNC_STOP_SYNCING_BUTTON_LABEL); |
| 1611 } else if (syncService_->SetupInProgress()) { |
| 1612 buttonLabel = l10n_util::GetNSStringWithFixup( |
| 1613 IDS_SYNC_NTP_SETUP_IN_PROGRESS); |
| 1614 } else { |
| 1615 buttonLabel = l10n_util::GetNSStringWithFixup( |
| 1616 IDS_SYNC_START_SYNC_BUTTON_LABEL); |
| 1617 } |
| 1618 [syncButton_ setTitle:buttonLabel]; |
| 1619 |
| 1620 string16 statusLabel, linkLabel; |
| 1621 SyncStatusUIHelper::GetLabels(syncService_, &statusLabel, &linkLabel); |
| 1622 [syncStatus_ setStringValue:base::SysUTF16ToNSString(statusLabel)]; |
| 1623 } |
| 1624 |
| 1529 // Show the preferences window. | 1625 // Show the preferences window. |
| 1530 - (IBAction)showPreferences:(id)sender { | 1626 - (IBAction)showPreferences:(id)sender { |
| 1531 [self showWindow:sender]; | 1627 [self showWindow:sender]; |
| 1532 } | 1628 } |
| 1533 | 1629 |
| 1534 // Called when the window is being closed. Send out a notification that the user | 1630 // Called when the window is being closed. Send out a notification that the user |
| 1535 // is done editing preferences. Make sure there are no pending field editors | 1631 // is done editing preferences. Make sure there are no pending field editors |
| 1536 // by clearing the first responder. | 1632 // by clearing the first responder. |
| 1537 - (void)windowWillClose:(NSNotification*)notification { | 1633 - (void)windowWillClose:(NSNotification*)notification { |
| 1538 // Setting the first responder to the window ends any in-progress field | 1634 // Setting the first responder to the window ends any in-progress field |
| 1539 // editor. This will update the model appropriately so there's nothing left | 1635 // editor. This will update the model appropriately so there's nothing left |
| 1540 // to do. | 1636 // to do. |
| 1541 if (![[self window] makeFirstResponder:[self window]]) { | 1637 if (![[self window] makeFirstResponder:[self window]]) { |
| 1542 // We've hit a recalcitrant field editor, force it to go away. | 1638 // We've hit a recalcitrant field editor, force it to go away. |
| 1543 [[self window] endEditingFor:nil]; | 1639 [[self window] endEditingFor:nil]; |
| 1544 } | 1640 } |
| 1545 | 1641 |
| 1546 [[NSNotificationCenter defaultCenter] | 1642 [[NSNotificationCenter defaultCenter] |
| 1547 postNotificationName:kUserDoneEditingPrefsNotification | 1643 postNotificationName:kUserDoneEditingPrefsNotification |
| 1548 object:self]; | 1644 object:self]; |
| 1549 } | 1645 } |
| 1550 | 1646 |
| 1551 - (void)controlTextDidEndEditing:(NSNotification*)notification { | 1647 - (void)controlTextDidEndEditing:(NSNotification*)notification { |
| 1552 [customPagesSource_ validateURLs]; | 1648 [customPagesSource_ validateURLs]; |
| 1553 } | 1649 } |
| 1554 | 1650 |
| 1555 @end | 1651 @end |
| OLD | NEW |