| Index: chrome/browser/cocoa/preferences_window_controller.mm
|
| ===================================================================
|
| --- chrome/browser/cocoa/preferences_window_controller.mm (revision 22290)
|
| +++ chrome/browser/cocoa/preferences_window_controller.mm (working copy)
|
| @@ -14,6 +14,7 @@
|
| #import "chrome/browser/cocoa/clear_browsing_data_controller.h"
|
| #import "chrome/browser/cocoa/custom_home_pages_model.h"
|
| #import "chrome/browser/cocoa/search_engine_list_model.h"
|
| +#include "chrome/browser/extensions/extensions_service.h"
|
| #include "chrome/browser/metrics/metrics_service.h"
|
| #include "chrome/browser/metrics/user_metrics.h"
|
| #include "chrome/browser/net/dns_global.h"
|
| @@ -628,12 +629,80 @@
|
| [controller runModalDialog];
|
| }
|
|
|
| -// Called to reset the theming info back to the defaults.
|
| -- (IBAction)resetTheme:(id)sender {
|
| - [self recordUserAction:L"Options_ThemesReset"];
|
| - profile_->ClearTheme();
|
| +- (NSArray*)availableThemes {
|
| + const ExtensionList* extensions =
|
| + profile_->GetExtensionsService()->extensions();
|
| +
|
| + NSMutableArray* themes = [NSMutableArray array];
|
| +
|
| + for (size_t i = 0; i < extensions->size(); ++i) {
|
| + Extension* extension = extensions->at(i);
|
| + if (!extension->IsTheme())
|
| + continue;
|
| +
|
| + NSDictionary* theme =
|
| + [NSDictionary dictionaryWithObjectsAndKeys:
|
| + [NSString stringWithUTF8String:extension->name().c_str()], @"name",
|
| + [NSString stringWithUTF8String:extension->id().c_str()], @"id",
|
| + nil];
|
| + [themes addObject:theme];
|
| + }
|
| +
|
| + NSSortDescriptor* sortDescriptor =
|
| + [[[NSSortDescriptor alloc] initWithKey:@"name"
|
| + ascending:YES] autorelease];
|
| +
|
| + [themes sortUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];
|
| +
|
| + NSMutableArray* themeNames = [NSMutableArray array];
|
| + NSMutableArray* themeIds = [NSMutableArray array];
|
| +
|
| + for (NSDictionary* themeDict in themes) {
|
| + [themeNames addObject:[themeDict objectForKey:@"name"]];
|
| + [themeIds addObject:[themeDict objectForKey:@"id"]];
|
| + }
|
| +
|
| + themeMenuOffset_ = 0;
|
| + if ([themeNames count] > 0) {
|
| + [themeNames insertObject:@"-" atIndex:0];
|
| + ++themeMenuOffset_;
|
| + }
|
| + NSString* defaultLabel =
|
| + [NSString stringWithUTF8String:
|
| + l10n_util::GetStringUTF8(IDS_THEMES_DEFAULT_THEME_LABEL).c_str()];
|
| + [themeNames insertObject:defaultLabel atIndex:0];
|
| + ++themeMenuOffset_;
|
| +
|
| + themeIds_.reset([themeIds retain]);
|
| + return themeNames;
|
| }
|
|
|
| +- (int)currentTheme {
|
| + const Extension* theme = profile_->GetTheme();
|
| +
|
| + if (theme) {
|
| + NSString* themeId = [NSString stringWithUTF8String:theme->id().c_str()];
|
| + return [themeIds_.get() indexOfObject:themeId] + themeMenuOffset_;
|
| + }
|
| +
|
| + return 0;
|
| +}
|
| +
|
| +- (void)setCurrentTheme:(int)newTheme {
|
| + newTheme -= themeMenuOffset_;
|
| +
|
| + if (newTheme < 0) {
|
| + [self recordUserAction:L"Options_ThemesReset"];
|
| + profile_->ClearTheme();
|
| + } else {
|
| + NSString* themeId = [themeIds_.get() objectAtIndex:newTheme];
|
| + Extension* extension =
|
| + profile_->GetExtensionsService()->
|
| + GetExtensionById([themeId UTF8String]);
|
| + profile_->SetTheme(extension);
|
| + }
|
| +}
|
| +
|
| - (IBAction)themesGallery:(id)sender {
|
| [self recordUserAction:L"Options_ThemesGallery"];
|
| Browser* browser =
|
|
|