| 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 "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/mac_util.h" | 8 #include "base/mac_util.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
| 11 #include "chrome/browser/browser.h" | 11 #include "chrome/browser/browser.h" |
| 12 #include "chrome/browser/browser_list.h" | 12 #include "chrome/browser/browser_list.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #import "chrome/browser/cocoa/clear_browsing_data_controller.h" | 14 #import "chrome/browser/cocoa/clear_browsing_data_controller.h" |
| 15 #import "chrome/browser/cocoa/custom_home_pages_model.h" | 15 #import "chrome/browser/cocoa/custom_home_pages_model.h" |
| 16 #import "chrome/browser/cocoa/search_engine_list_model.h" | 16 #import "chrome/browser/cocoa/search_engine_list_model.h" |
| 17 #include "chrome/browser/extensions/extensions_service.h" |
| 17 #include "chrome/browser/metrics/metrics_service.h" | 18 #include "chrome/browser/metrics/metrics_service.h" |
| 18 #include "chrome/browser/metrics/user_metrics.h" | 19 #include "chrome/browser/metrics/user_metrics.h" |
| 19 #include "chrome/browser/net/dns_global.h" | 20 #include "chrome/browser/net/dns_global.h" |
| 20 #include "chrome/browser/net/url_fixer_upper.h" | 21 #include "chrome/browser/net/url_fixer_upper.h" |
| 21 #include "chrome/browser/profile.h" | 22 #include "chrome/browser/profile.h" |
| 22 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 23 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 23 #include "chrome/browser/session_startup_pref.h" | 24 #include "chrome/browser/session_startup_pref.h" |
| 24 #include "chrome/browser/shell_integration.h" | 25 #include "chrome/browser/shell_integration.h" |
| 25 #include "chrome/browser/tab_contents/tab_contents.h" | 26 #include "chrome/browser/tab_contents/tab_contents.h" |
| 26 #include "chrome/common/notification_details.h" | 27 #include "chrome/common/notification_details.h" |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 | 622 |
| 622 // Called to clear user's browsing data. This puts up an application-modal | 623 // Called to clear user's browsing data. This puts up an application-modal |
| 623 // dialog to guide the user through clearing the data. | 624 // dialog to guide the user through clearing the data. |
| 624 - (IBAction)clearData:(id)sender { | 625 - (IBAction)clearData:(id)sender { |
| 625 scoped_nsobject<ClearBrowsingDataController> controller( | 626 scoped_nsobject<ClearBrowsingDataController> controller( |
| 626 [[ClearBrowsingDataController alloc] | 627 [[ClearBrowsingDataController alloc] |
| 627 initWithProfile:profile_]); | 628 initWithProfile:profile_]); |
| 628 [controller runModalDialog]; | 629 [controller runModalDialog]; |
| 629 } | 630 } |
| 630 | 631 |
| 631 // Called to reset the theming info back to the defaults. | 632 - (NSArray*)availableThemes { |
| 632 - (IBAction)resetTheme:(id)sender { | 633 const ExtensionList* extensions = |
| 633 [self recordUserAction:L"Options_ThemesReset"]; | 634 profile_->GetExtensionsService()->extensions(); |
| 634 profile_->ClearTheme(); | 635 |
| 636 NSMutableArray* themes = [NSMutableArray array]; |
| 637 |
| 638 for (size_t i = 0; i < extensions->size(); ++i) { |
| 639 Extension* extension = extensions->at(i); |
| 640 if (!extension->IsTheme()) |
| 641 continue; |
| 642 |
| 643 NSDictionary* theme = |
| 644 [NSDictionary dictionaryWithObjectsAndKeys: |
| 645 [NSString stringWithUTF8String:extension->name().c_str()], @"name", |
| 646 [NSString stringWithUTF8String:extension->id().c_str()], @"id", |
| 647 nil]; |
| 648 [themes addObject:theme]; |
| 649 } |
| 650 |
| 651 NSSortDescriptor* sortDescriptor = |
| 652 [[[NSSortDescriptor alloc] initWithKey:@"name" |
| 653 ascending:YES] autorelease]; |
| 654 |
| 655 [themes sortUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]]; |
| 656 |
| 657 NSMutableArray* themeNames = [NSMutableArray array]; |
| 658 NSMutableArray* themeIds = [NSMutableArray array]; |
| 659 |
| 660 for (NSDictionary* themeDict in themes) { |
| 661 [themeNames addObject:[themeDict objectForKey:@"name"]]; |
| 662 [themeIds addObject:[themeDict objectForKey:@"id"]]; |
| 663 } |
| 664 |
| 665 themeMenuOffset_ = 0; |
| 666 if ([themeNames count] > 0) { |
| 667 [themeNames insertObject:@"-" atIndex:0]; |
| 668 ++themeMenuOffset_; |
| 669 } |
| 670 NSString* defaultLabel = |
| 671 [NSString stringWithUTF8String: |
| 672 l10n_util::GetStringUTF8(IDS_THEMES_DEFAULT_THEME_LABEL).c_str()]; |
| 673 [themeNames insertObject:defaultLabel atIndex:0]; |
| 674 ++themeMenuOffset_; |
| 675 |
| 676 themeIds_.reset([themeIds retain]); |
| 677 return themeNames; |
| 678 } |
| 679 |
| 680 - (int)currentTheme { |
| 681 const Extension* theme = profile_->GetTheme(); |
| 682 |
| 683 if (theme) { |
| 684 NSString* themeId = [NSString stringWithUTF8String:theme->id().c_str()]; |
| 685 return [themeIds_.get() indexOfObject:themeId] + themeMenuOffset_; |
| 686 } |
| 687 |
| 688 return 0; |
| 689 } |
| 690 |
| 691 - (void)setCurrentTheme:(int)newTheme { |
| 692 newTheme -= themeMenuOffset_; |
| 693 |
| 694 if (newTheme < 0) { |
| 695 [self recordUserAction:L"Options_ThemesReset"]; |
| 696 profile_->ClearTheme(); |
| 697 } else { |
| 698 NSString* themeId = [themeIds_.get() objectAtIndex:newTheme]; |
| 699 Extension* extension = |
| 700 profile_->GetExtensionsService()-> |
| 701 GetExtensionById([themeId UTF8String]); |
| 702 profile_->SetTheme(extension); |
| 703 } |
| 635 } | 704 } |
| 636 | 705 |
| 637 - (IBAction)themesGallery:(id)sender { | 706 - (IBAction)themesGallery:(id)sender { |
| 638 [self recordUserAction:L"Options_ThemesGallery"]; | 707 [self recordUserAction:L"Options_ThemesGallery"]; |
| 639 Browser* browser = | 708 Browser* browser = |
| 640 BrowserList::FindBrowserWithType(profile_, Browser::TYPE_NORMAL); | 709 BrowserList::FindBrowserWithType(profile_, Browser::TYPE_NORMAL); |
| 641 | 710 |
| 642 if (!browser || !browser->GetSelectedTabContents()) { | 711 if (!browser || !browser->GetSelectedTabContents()) { |
| 643 browser = Browser::Create(profile_); | 712 browser = Browser::Create(profile_); |
| 644 browser->OpenURL( | 713 browser->OpenURL( |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 854 | 923 |
| 855 // Called when the window is being closed. Send out a notification that the | 924 // Called when the window is being closed. Send out a notification that the |
| 856 // user is done editing preferences. | 925 // user is done editing preferences. |
| 857 - (void)windowWillClose:(NSNotification *)notification { | 926 - (void)windowWillClose:(NSNotification *)notification { |
| 858 [[NSNotificationCenter defaultCenter] | 927 [[NSNotificationCenter defaultCenter] |
| 859 postNotificationName:kUserDoneEditingPrefsNotification | 928 postNotificationName:kUserDoneEditingPrefsNotification |
| 860 object:self]; | 929 object:self]; |
| 861 } | 930 } |
| 862 | 931 |
| 863 @end | 932 @end |
| OLD | NEW |