OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/webui/options2/browser_options_handler2.h" | 5 #include "chrome/browser/ui/webui/options2/browser_options_handler2.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 DictionaryValue* localized_strings) { | 110 DictionaryValue* localized_strings) { |
111 DCHECK(localized_strings); | 111 DCHECK(localized_strings); |
112 | 112 |
113 static OptionsStringResource resources[] = { | 113 static OptionsStringResource resources[] = { |
114 { "advancedOptionsButtonTitle", IDS_OPTIONS_ADVANCED_BUTTON_TITLE }, | 114 { "advancedOptionsButtonTitle", IDS_OPTIONS_ADVANCED_BUTTON_TITLE }, |
115 { "autologinEnabled", IDS_OPTIONS_PASSWORDS_AUTOLOGIN }, | 115 { "autologinEnabled", IDS_OPTIONS_PASSWORDS_AUTOLOGIN }, |
116 { "browsingData", IDS_OPTIONS_BROWSING_DATA_GROUP_NAME }, // needed? | 116 { "browsingData", IDS_OPTIONS_BROWSING_DATA_GROUP_NAME }, // needed? |
117 { "changeHomePage", IDS_OPTIONS_CHANGE_HOME_PAGE }, | 117 { "changeHomePage", IDS_OPTIONS_CHANGE_HOME_PAGE }, |
118 { "customizeSync", IDS_OPTIONS2_CUSTOMIZE_SYNC_BUTTON_LABEL }, | 118 { "customizeSync", IDS_OPTIONS2_CUSTOMIZE_SYNC_BUTTON_LABEL }, |
119 { "defaultSearchManageEngines", IDS_OPTIONS_DEFAULTSEARCH_MANAGE_ENGINES }, | 119 { "defaultSearchManageEngines", IDS_OPTIONS_DEFAULTSEARCH_MANAGE_ENGINES }, |
| 120 { "homePage", IDS_OPTIONS2_HOMEPAGE }, |
| 121 { "homePageChoose", IDS_OPTIONS2_HOMEPAGE_CHOOSE }, |
| 122 { "homePageDialogLabel", IDS_OPTIONS2_HOMEPAGE_DIALOG_LABEL }, |
120 { "homePageTitle", IDS_OPTIONS2_HOMEPAGE_TITLE }, | 123 { "homePageTitle", IDS_OPTIONS2_HOMEPAGE_TITLE }, |
121 { "homepageUseNewTab", IDS_OPTIONS_HOMEPAGE_USE_NEWTAB }, | 124 { "homePageNone", IDS_OPTIONS2_HOMEPAGE_NONE }, |
122 { "homepageUseURL", IDS_OPTIONS_HOMEPAGE_USE_URL }, | 125 { "homePageNtp", IDS_OPTIONS2_HOMEPAGE_NTP }, |
| 126 { "homePageUseNewTab", IDS_OPTIONS_HOMEPAGE_USE_NEWTAB }, |
| 127 { "homePageUseURL", IDS_OPTIONS_HOMEPAGE_USE_URL }, |
123 { "instantConfirmMessage", IDS_INSTANT_OPT_IN_MESSAGE }, | 128 { "instantConfirmMessage", IDS_INSTANT_OPT_IN_MESSAGE }, |
124 { "instantConfirmTitle", IDS_INSTANT_OPT_IN_TITLE }, | 129 { "instantConfirmTitle", IDS_INSTANT_OPT_IN_TITLE }, |
125 { "importData", IDS_OPTIONS_IMPORT_DATA_BUTTON }, | 130 { "importData", IDS_OPTIONS_IMPORT_DATA_BUTTON }, |
126 { "manageDataDescription", IDS_OPTIONS_MANAGE_DATA_DESCRIPTION }, | 131 { "manageDataDescription", IDS_OPTIONS_MANAGE_DATA_DESCRIPTION }, |
127 { "profilesCreate", IDS_PROFILES_CREATE_BUTTON_LABEL }, | 132 { "profilesCreate", IDS_PROFILES_CREATE_BUTTON_LABEL }, |
128 { "profilesDelete", IDS_PROFILES_DELETE_BUTTON_LABEL }, | 133 { "profilesDelete", IDS_PROFILES_DELETE_BUTTON_LABEL }, |
129 { "profilesDeleteSingle", IDS_PROFILES_DELETE_SINGLE_BUTTON_LABEL }, | 134 { "profilesDeleteSingle", IDS_PROFILES_DELETE_SINGLE_BUTTON_LABEL }, |
130 { "profilesListItemCurrent", IDS_PROFILES_LIST_ITEM_CURRENT }, | 135 { "profilesListItemCurrent", IDS_PROFILES_LIST_ITEM_CURRENT }, |
131 { "profilesManage", IDS_PROFILES_MANAGE_BUTTON_LABEL }, | 136 { "profilesManage", IDS_PROFILES_MANAGE_BUTTON_LABEL }, |
132 { "sectionTitleAdvanced", IDS_OPTIONS_ADVANCED_TAB_LABEL }, | 137 { "sectionTitleAdvanced", IDS_OPTIONS_ADVANCED_TAB_LABEL }, |
133 { "sectionTitleAppearance", IDS_APPEARANCE_GROUP_NAME }, | 138 { "sectionTitleAppearance", IDS_APPEARANCE_GROUP_NAME }, |
134 { "sectionTitleDefaultBrowser", IDS_OPTIONS_DEFAULTBROWSER_GROUP_NAME }, | 139 { "sectionTitleDefaultBrowser", IDS_OPTIONS_DEFAULTBROWSER_GROUP_NAME }, |
135 { "sectionTitleUsers", IDS_PROFILES_OPTIONS_GROUP_NAME }, | 140 { "sectionTitleUsers", IDS_PROFILES_OPTIONS_GROUP_NAME }, |
136 { "sectionTitleSearch", IDS_OPTIONS_DEFAULTSEARCH_GROUP_NAME }, | 141 { "sectionTitleSearch", IDS_OPTIONS_DEFAULTSEARCH_GROUP_NAME }, |
137 { "sectionTitleStartup", IDS_OPTIONS_STARTUP_GROUP_NAME }, | 142 { "sectionTitleStartup", IDS_OPTIONS_STARTUP_GROUP_NAME }, |
138 { "sectionTitleSync", IDS_SYNC_OPTIONS_GROUP_NAME }, | 143 { "sectionTitleSync", IDS_SYNC_OPTIONS_GROUP_NAME }, |
139 { "startupSetPages", IDS_OPTIONS2_STARTUP_SET_PAGES }, | 144 { "startupSetPages", IDS_OPTIONS2_STARTUP_SET_PAGES }, |
140 { "startupShowDefaultAndNewTab", | 145 { "startupShowDefaultAndNewTab", |
141 IDS_OPTIONS_STARTUP_SHOW_DEFAULT_AND_NEWTAB}, | 146 IDS_OPTIONS2_STARTUP_SHOW_DEFAULT_AND_NEWTAB}, |
142 { "startupShowLastSession", IDS_OPTIONS_STARTUP_SHOW_LAST_SESSION }, | 147 { "startupShowLastSession", IDS_OPTIONS_STARTUP_SHOW_LAST_SESSION }, |
143 { "startupShowPages", IDS_OPTIONS2_STARTUP_SHOW_PAGES }, | 148 { "startupShowPages", IDS_OPTIONS2_STARTUP_SHOW_PAGES }, |
144 { "themesGallery", IDS_THEMES_GALLERY_BUTTON }, | 149 { "themesGallery", IDS_THEMES_GALLERY_BUTTON }, |
145 { "themesGalleryURL", IDS_THEMES_GALLERY_URL }, | 150 { "themesGalleryURL", IDS_THEMES_GALLERY_URL }, |
146 { "toolbarGroupName", IDS_OPTIONS2_TOOLBAR_GROUP_NAME }, | 151 { "toolbarGroupName", IDS_OPTIONS2_TOOLBAR_GROUP_NAME }, |
147 { "toolbarShowBookmarksBar", IDS_OPTIONS_TOOLBAR_SHOW_BOOKMARKS_BAR }, | 152 { "toolbarShowBookmarksBar", IDS_OPTIONS_TOOLBAR_SHOW_BOOKMARKS_BAR }, |
148 { "toolbarShowHomeButton", IDS_OPTIONS_TOOLBAR_SHOW_HOME_BUTTON }, | 153 { "toolbarShowHomeButton", IDS_OPTIONS_TOOLBAR_SHOW_HOME_BUTTON }, |
149 #if defined(TOOLKIT_GTK) | 154 #if defined(TOOLKIT_GTK) |
150 { "showWindowDecorations", IDS_SHOW_WINDOW_DECORATIONS }, | 155 { "showWindowDecorations", IDS_SHOW_WINDOW_DECORATIONS }, |
151 { "themesGTKButton", IDS_THEMES_GTK_BUTTON }, | 156 { "themesGTKButton", IDS_THEMES_GTK_BUTTON }, |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 // Create our favicon data source. | 384 // Create our favicon data source. |
380 profile->GetChromeURLDataManager()->AddDataSource( | 385 profile->GetChromeURLDataManager()->AddDataSource( |
381 new FaviconSource(profile, FaviconSource::FAVICON)); | 386 new FaviconSource(profile, FaviconSource::FAVICON)); |
382 | 387 |
383 homepage_.Init(prefs::kHomePage, profile->GetPrefs(), NULL); | 388 homepage_.Init(prefs::kHomePage, profile->GetPrefs(), NULL); |
384 default_browser_policy_.Init(prefs::kDefaultBrowserSettingEnabled, | 389 default_browser_policy_.Init(prefs::kDefaultBrowserSettingEnabled, |
385 g_browser_process->local_state(), | 390 g_browser_process->local_state(), |
386 this); | 391 this); |
387 UpdateDefaultBrowserState(); | 392 UpdateDefaultBrowserState(); |
388 | 393 |
389 pref_change_registrar_.Init(profile->GetPrefs()); | |
390 pref_change_registrar_.Add(prefs::kHomePageIsNewTabPage, this); | |
391 pref_change_registrar_.Add(prefs::kHomePage, this); | |
392 | |
393 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, | 394 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, |
394 content::NotificationService::AllSources()); | 395 content::NotificationService::AllSources()); |
395 #if defined(OS_CHROMEOS) | 396 #if defined(OS_CHROMEOS) |
396 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, | 397 registrar_.Add(this, chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED, |
397 content::NotificationService::AllSources()); | 398 content::NotificationService::AllSources()); |
398 #endif | 399 #endif |
399 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 400 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
400 content::Source<ThemeService>( | 401 content::Source<ThemeService>( |
401 ThemeServiceFactory::GetForProfile(profile))); | 402 ThemeServiceFactory::GetForProfile(profile))); |
402 | 403 |
403 UpdateSearchEngines(); | 404 UpdateSearchEngines(); |
404 UpdateHomePageLabel(); | |
405 ObserveThemeChanged(); | 405 ObserveThemeChanged(); |
406 | 406 |
407 autocomplete_controller_.reset(new AutocompleteController(profile, this)); | 407 autocomplete_controller_.reset(new AutocompleteController(profile, this)); |
408 | 408 |
409 #if defined(OS_WIN) | 409 #if defined(OS_WIN) |
410 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 410 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
411 base::Bind(&BrowserOptionsHandler::CheckAutoLaunch, | 411 base::Bind(&BrowserOptionsHandler::CheckAutoLaunch, |
412 weak_ptr_factory_for_ui_.GetWeakPtr(), | 412 weak_ptr_factory_for_ui_.GetWeakPtr(), |
413 weak_ptr_factory_for_file_.GetWeakPtr())); | 413 weak_ptr_factory_for_file_.GetWeakPtr())); |
414 weak_ptr_factory_for_ui_.DetachFromThread(); | 414 weak_ptr_factory_for_ui_.DetachFromThread(); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 void BrowserOptionsHandler::UpdateSearchEngines() { | 586 void BrowserOptionsHandler::UpdateSearchEngines() { |
587 template_url_service_ = | 587 template_url_service_ = |
588 TemplateURLServiceFactory::GetForProfile(Profile::FromWebUI(web_ui())); | 588 TemplateURLServiceFactory::GetForProfile(Profile::FromWebUI(web_ui())); |
589 if (template_url_service_) { | 589 if (template_url_service_) { |
590 template_url_service_->Load(); | 590 template_url_service_->Load(); |
591 template_url_service_->AddObserver(this); | 591 template_url_service_->AddObserver(this); |
592 OnTemplateURLServiceChanged(); | 592 OnTemplateURLServiceChanged(); |
593 } | 593 } |
594 } | 594 } |
595 | 595 |
596 void BrowserOptionsHandler::UpdateHomePageLabel() const { | |
597 Profile* profile = Profile::FromWebUI(web_ui()); | |
598 PrefService* prefs = profile->GetPrefs(); | |
599 scoped_ptr<Value> label; | |
600 string16 str; | |
601 | |
602 if (prefs->GetBoolean(prefs::kHomePageIsNewTabPage)) { | |
603 str = l10n_util::GetStringUTF16(IDS_OPTIONS_SHOW_HOME_BUTTON_FOR_NTP); | |
604 } else { | |
605 str = l10n_util::GetStringFUTF16( | |
606 IDS_OPTIONS_SHOW_HOME_BUTTON_FOR_URL, | |
607 UTF8ToUTF16(prefs->GetString(prefs::kHomePage))); | |
608 } | |
609 | |
610 label.reset(Value::CreateStringValue(str)); | |
611 web_ui()->CallJavascriptFunction("BrowserOptions.updateHomePageLabel", | |
612 *label); | |
613 } | |
614 | |
615 void BrowserOptionsHandler::Observe( | 596 void BrowserOptionsHandler::Observe( |
616 int type, | 597 int type, |
617 const content::NotificationSource& source, | 598 const content::NotificationSource& source, |
618 const content::NotificationDetails& details) { | 599 const content::NotificationDetails& details) { |
619 if (type == chrome::NOTIFICATION_BROWSER_THEME_CHANGED) { | 600 if (type == chrome::NOTIFICATION_BROWSER_THEME_CHANGED) { |
620 ObserveThemeChanged(); | 601 ObserveThemeChanged(); |
621 #if defined(OS_CHROMEOS) | 602 #if defined(OS_CHROMEOS) |
622 } else if (type == chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED) { | 603 } else if (type == chrome::NOTIFICATION_LOGIN_USER_IMAGE_CHANGED) { |
623 UpdateAccountPicture(); | 604 UpdateAccountPicture(); |
624 #endif | 605 #endif |
625 } else if (type == chrome::NOTIFICATION_PREF_CHANGED) { | 606 } else if (type == chrome::NOTIFICATION_PREF_CHANGED) { |
626 std::string* pref = content::Details<std::string>(details).ptr(); | 607 std::string* pref = content::Details<std::string>(details).ptr(); |
627 if (*pref == prefs::kDefaultBrowserSettingEnabled) { | 608 if (*pref == prefs::kDefaultBrowserSettingEnabled) { |
628 UpdateDefaultBrowserState(); | 609 UpdateDefaultBrowserState(); |
629 } else if (*pref == prefs::kHomePageIsNewTabPage || | |
630 *pref == prefs::kHomePage) { | |
631 UpdateHomePageLabel(); | |
632 } else { | 610 } else { |
633 NOTREACHED(); | 611 NOTREACHED(); |
634 } | 612 } |
635 } else if (multiprofile_ && | 613 } else if (multiprofile_ && |
636 type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED) { | 614 type == chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED) { |
637 SendProfilesInfo(); | 615 SendProfilesInfo(); |
638 } else { | 616 } else { |
639 NOTREACHED(); | 617 NOTREACHED(); |
640 } | 618 } |
641 } | 619 } |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 } | 776 } |
799 | 777 |
800 void BrowserOptionsHandler::IncreaseScreenBrightnessCallback( | 778 void BrowserOptionsHandler::IncreaseScreenBrightnessCallback( |
801 const ListValue* args) { | 779 const ListValue* args) { |
802 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | 780 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
803 IncreaseScreenBrightness(); | 781 IncreaseScreenBrightness(); |
804 } | 782 } |
805 #endif | 783 #endif |
806 | 784 |
807 } // namespace options2 | 785 } // namespace options2 |
OLD | NEW |