Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/options/browser_options_handler.h" | 5 #include "chrome/browser/ui/webui/options/browser_options_handler.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/memory/singleton.h" | 10 #include "base/memory/singleton.h" |
| 11 #include "base/path_service.h" | |
| 11 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 12 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 13 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/auto_launch_trial.h" | |
| 14 #include "chrome/browser/autocomplete/autocomplete.h" | 16 #include "chrome/browser/autocomplete/autocomplete.h" |
| 15 #include "chrome/browser/autocomplete/autocomplete_match.h" | 17 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 16 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
| 17 #include "chrome/browser/custom_home_pages_table_model.h" | 19 #include "chrome/browser/custom_home_pages_table_model.h" |
| 18 #include "chrome/browser/instant/instant_confirm_dialog.h" | 20 #include "chrome/browser/instant/instant_confirm_dialog.h" |
| 19 #include "chrome/browser/instant/instant_controller.h" | 21 #include "chrome/browser/instant/instant_controller.h" |
| 20 #include "chrome/browser/instant/instant_field_trial.h" | 22 #include "chrome/browser/instant/instant_field_trial.h" |
| 21 #include "chrome/browser/net/url_fixer_upper.h" | 23 #include "chrome/browser/net/url_fixer_upper.h" |
| 22 #include "chrome/browser/prefs/pref_service.h" | 24 #include "chrome/browser/prefs/pref_service.h" |
| 23 #include "chrome/browser/prefs/session_startup_pref.h" | 25 #include "chrome/browser/prefs/session_startup_pref.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/search_engines/template_url.h" | 27 #include "chrome/browser/search_engines/template_url.h" |
| 26 #include "chrome/browser/search_engines/template_url_service.h" | 28 #include "chrome/browser/search_engines/template_url_service.h" |
| 27 #include "chrome/browser/search_engines/template_url_service_factory.h" | 29 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 28 #include "chrome/browser/ui/webui/favicon_source.h" | 30 #include "chrome/browser/ui/webui/favicon_source.h" |
| 29 #include "chrome/common/chrome_notification_types.h" | 31 #include "chrome/common/chrome_notification_types.h" |
| 30 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
| 31 #include "chrome/common/url_constants.h" | 33 #include "chrome/common/url_constants.h" |
| 32 #include "content/browser/user_metrics.h" | 34 #include "content/browser/user_metrics.h" |
| 33 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
| 34 #include "content/public/browser/notification_details.h" | 36 #include "content/public/browser/notification_details.h" |
| 35 #include "content/public/browser/notification_source.h" | 37 #include "content/public/browser/notification_source.h" |
| 36 #include "grit/chromium_strings.h" | 38 #include "grit/chromium_strings.h" |
| 37 #include "grit/generated_resources.h" | 39 #include "grit/generated_resources.h" |
| 38 #include "ui/base/l10n/l10n_util.h" | 40 #include "ui/base/l10n/l10n_util.h" |
| 39 | 41 |
| 42 #if defined(OS_WIN) | |
| 43 #include "chrome/installer/util/auto_launch_util.h" | |
| 44 #endif | |
| 45 | |
| 46 using content::BrowserThread; | |
| 47 | |
| 40 BrowserOptionsHandler::BrowserOptionsHandler() | 48 BrowserOptionsHandler::BrowserOptionsHandler() |
| 41 : template_url_service_(NULL), startup_custom_pages_table_model_(NULL) { | 49 : template_url_service_(NULL), |
| 50 startup_custom_pages_table_model_(NULL), | |
| 51 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_for_io_(this)), | |
| 52 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_for_ui_(this)) { | |
| 42 #if !defined(OS_MACOSX) | 53 #if !defined(OS_MACOSX) |
| 43 default_browser_worker_ = new ShellIntegration::DefaultBrowserWorker(this); | 54 default_browser_worker_ = new ShellIntegration::DefaultBrowserWorker(this); |
| 44 #endif | 55 #endif |
| 45 } | 56 } |
| 46 | 57 |
| 47 BrowserOptionsHandler::~BrowserOptionsHandler() { | 58 BrowserOptionsHandler::~BrowserOptionsHandler() { |
| 48 if (default_browser_worker_.get()) | 59 if (default_browser_worker_.get()) |
| 49 default_browser_worker_->ObserverDestroyed(); | 60 default_browser_worker_->ObserverDestroyed(); |
| 50 if (template_url_service_) | 61 if (template_url_service_) |
| 51 template_url_service_->RemoveObserver(this); | 62 template_url_service_->RemoveObserver(this); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 IDS_OPTIONS_GENERAL_TAB_LABEL); | 94 IDS_OPTIONS_GENERAL_TAB_LABEL); |
| 84 | 95 |
| 85 localized_strings->SetString("instantLearnMoreLink", | 96 localized_strings->SetString("instantLearnMoreLink", |
| 86 ASCIIToUTF16(browser::InstantLearnMoreURL().spec())); | 97 ASCIIToUTF16(browser::InstantLearnMoreURL().spec())); |
| 87 localized_strings->SetString("defaultBrowserUnknown", | 98 localized_strings->SetString("defaultBrowserUnknown", |
| 88 l10n_util::GetStringFUTF16(IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN, | 99 l10n_util::GetStringFUTF16(IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN, |
| 89 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); | 100 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); |
| 90 localized_strings->SetString("defaultBrowserUseAsDefault", | 101 localized_strings->SetString("defaultBrowserUseAsDefault", |
| 91 l10n_util::GetStringFUTF16(IDS_OPTIONS_DEFAULTBROWSER_USEASDEFAULT, | 102 l10n_util::GetStringFUTF16(IDS_OPTIONS_DEFAULTBROWSER_USEASDEFAULT, |
| 92 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); | 103 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); |
| 104 localized_strings->SetString("autoLaunchText", | |
| 105 l10n_util::GetStringFUTF16(IDS_AUTOLAUNCH_TEXT, | |
| 106 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); | |
| 93 } | 107 } |
| 94 | 108 |
| 95 void BrowserOptionsHandler::RegisterMessages() { | 109 void BrowserOptionsHandler::RegisterMessages() { |
| 96 web_ui_->RegisterMessageCallback("becomeDefaultBrowser", | 110 web_ui_->RegisterMessageCallback("becomeDefaultBrowser", |
| 97 base::Bind(&BrowserOptionsHandler::BecomeDefaultBrowser, | 111 base::Bind(&BrowserOptionsHandler::BecomeDefaultBrowser, |
| 98 base::Unretained(this))); | 112 base::Unretained(this))); |
| 99 web_ui_->RegisterMessageCallback("setDefaultSearchEngine", | 113 web_ui_->RegisterMessageCallback("setDefaultSearchEngine", |
| 100 base::Bind(&BrowserOptionsHandler::SetDefaultSearchEngine, | 114 base::Bind(&BrowserOptionsHandler::SetDefaultSearchEngine, |
| 101 base::Unretained(this))); | 115 base::Unretained(this))); |
| 102 web_ui_->RegisterMessageCallback("removeStartupPages", | 116 web_ui_->RegisterMessageCallback("removeStartupPages", |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 new CustomHomePagesTableModel(profile)); | 159 new CustomHomePagesTableModel(profile)); |
| 146 startup_custom_pages_table_model_->SetObserver(this); | 160 startup_custom_pages_table_model_->SetObserver(this); |
| 147 UpdateStartupPages(); | 161 UpdateStartupPages(); |
| 148 | 162 |
| 149 pref_change_registrar_.Init(profile->GetPrefs()); | 163 pref_change_registrar_.Init(profile->GetPrefs()); |
| 150 pref_change_registrar_.Add(prefs::kURLsToRestoreOnStartup, this); | 164 pref_change_registrar_.Add(prefs::kURLsToRestoreOnStartup, this); |
| 151 | 165 |
| 152 UpdateSearchEngines(); | 166 UpdateSearchEngines(); |
| 153 | 167 |
| 154 autocomplete_controller_.reset(new AutocompleteController(profile, this)); | 168 autocomplete_controller_.reset(new AutocompleteController(profile, this)); |
| 169 | |
| 170 #if defined(OS_WIN) | |
| 171 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | |
| 172 base::Bind(&BrowserOptionsHandler::CheckAutoLaunch, | |
| 173 weak_ptr_factory_for_ui_.GetWeakPtr(), | |
| 174 weak_ptr_factory_for_io_.GetWeakPtr())); | |
| 175 weak_ptr_factory_for_ui_.DetachFromThread(); | |
|
grt (UTC plus 2)
2011/12/13 17:08:55
i'm not familiar enough with WeakPtr machinery to
| |
| 176 #endif | |
| 177 } | |
| 178 | |
| 179 void BrowserOptionsHandler::CheckAutoLaunch( | |
| 180 base::WeakPtr<BrowserOptionsHandler> weak_this) { | |
| 181 // Pass in weak pointer to this to avoid race if BrowserOptionsHandler is | |
|
grt (UTC plus 2)
2011/12/13 17:08:55
should the contents of this and CheckAutoLaunchCal
| |
| 182 // deleted. | |
| 183 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | |
| 184 base::Bind(&BrowserOptionsHandler::CheckAutoLaunchCallback, | |
| 185 weak_this, | |
| 186 auto_launch_trial::IsInAutoLaunchGroup(), | |
| 187 auto_launch_util::WillLaunchAtLogin(FilePath()))); | |
| 188 } | |
| 189 | |
| 190 void BrowserOptionsHandler::CheckAutoLaunchCallback( | |
| 191 bool is_in_auto_launch_group, bool will_launch_at_login) { | |
|
grt (UTC plus 2)
2011/12/13 17:08:55
newline after comma
| |
| 192 if (is_in_auto_launch_group) { | |
| 193 web_ui_->RegisterMessageCallback("toggleAutoLaunch", | |
| 194 base::Bind(&BrowserOptionsHandler::ToggleAutoLaunch, | |
| 195 base::Unretained(this))); | |
| 196 | |
| 197 base::FundamentalValue enabled(will_launch_at_login); | |
| 198 web_ui_->CallJavascriptFunction("BrowserOptions.updateAutoLaunchState", | |
| 199 enabled); | |
| 200 } | |
| 155 } | 201 } |
| 156 | 202 |
| 157 void BrowserOptionsHandler::UpdateDefaultBrowserState() { | 203 void BrowserOptionsHandler::UpdateDefaultBrowserState() { |
| 158 // Check for side-by-side first. | 204 // Check for side-by-side first. |
| 159 if (!ShellIntegration::CanSetAsDefaultBrowser()) { | 205 if (!ShellIntegration::CanSetAsDefaultBrowser()) { |
| 160 SetDefaultBrowserUIString(IDS_OPTIONS_DEFAULTBROWSER_SXS); | 206 SetDefaultBrowserUIString(IDS_OPTIONS_DEFAULTBROWSER_SXS); |
| 161 return; | 207 return; |
| 162 } | 208 } |
| 163 | 209 |
| 164 #if defined(OS_MACOSX) | 210 #if defined(OS_MACOSX) |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 454 } | 500 } |
| 455 | 501 |
| 456 void BrowserOptionsHandler::EnableInstant(const ListValue* args) { | 502 void BrowserOptionsHandler::EnableInstant(const ListValue* args) { |
| 457 InstantController::Enable(Profile::FromWebUI(web_ui_)); | 503 InstantController::Enable(Profile::FromWebUI(web_ui_)); |
| 458 } | 504 } |
| 459 | 505 |
| 460 void BrowserOptionsHandler::DisableInstant(const ListValue* args) { | 506 void BrowserOptionsHandler::DisableInstant(const ListValue* args) { |
| 461 InstantController::Disable(Profile::FromWebUI(web_ui_)); | 507 InstantController::Disable(Profile::FromWebUI(web_ui_)); |
| 462 } | 508 } |
| 463 | 509 |
| 510 void BrowserOptionsHandler::ToggleAutoLaunch(const ListValue* args) { | |
| 511 #if defined(OS_WIN) | |
| 512 if (!auto_launch_trial::IsInAutoLaunchGroup()) | |
| 513 return; | |
| 514 | |
| 515 bool enable; | |
| 516 CHECK_EQ(args->GetSize(), 1U); | |
| 517 CHECK(args->GetBoolean(0, &enable)); | |
| 518 | |
| 519 // Make sure we keep track of how many disable and how many enable. | |
| 520 auto_launch_trial::UpdateToggleAutoLaunchMetric(enable); | |
| 521 content::BrowserThread::PostTask( | |
| 522 content::BrowserThread::FILE, FROM_HERE, | |
| 523 base::Bind(&auto_launch_util::SetWillLaunchAtLogin, enable, FilePath())); | |
| 524 #endif // OS_WIN | |
| 525 } | |
| 526 | |
| 464 void BrowserOptionsHandler::GetInstantFieldTrialStatus(const ListValue* args) { | 527 void BrowserOptionsHandler::GetInstantFieldTrialStatus(const ListValue* args) { |
| 465 Profile* profile = Profile::FromWebUI(web_ui_); | 528 Profile* profile = Profile::FromWebUI(web_ui_); |
| 466 base::FundamentalValue enabled( | 529 base::FundamentalValue enabled( |
| 467 InstantFieldTrial::IsInstantExperiment(profile) && | 530 InstantFieldTrial::IsInstantExperiment(profile) && |
| 468 !InstantFieldTrial::IsHiddenExperiment(profile)); | 531 !InstantFieldTrial::IsHiddenExperiment(profile)); |
| 469 web_ui_->CallJavascriptFunction("BrowserOptions.setInstantFieldTrialStatus", | 532 web_ui_->CallJavascriptFunction("BrowserOptions.setInstantFieldTrialStatus", |
| 470 enabled); | 533 enabled); |
| 471 } | 534 } |
| 472 | 535 |
| 473 void BrowserOptionsHandler::OnResultChanged(bool default_match_changed) { | 536 void BrowserOptionsHandler::OnResultChanged(bool default_match_changed) { |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 485 DictionaryValue* entry = new DictionaryValue(); | 548 DictionaryValue* entry = new DictionaryValue(); |
| 486 entry->SetString("title", match.description); | 549 entry->SetString("title", match.description); |
| 487 entry->SetString("displayURL", match.contents); | 550 entry->SetString("displayURL", match.contents); |
| 488 entry->SetString("url", match.destination_url.spec()); | 551 entry->SetString("url", match.destination_url.spec()); |
| 489 suggestions.Append(entry); | 552 suggestions.Append(entry); |
| 490 } | 553 } |
| 491 | 554 |
| 492 web_ui_->CallJavascriptFunction( | 555 web_ui_->CallJavascriptFunction( |
| 493 "BrowserOptions.updateAutocompleteSuggestions", suggestions); | 556 "BrowserOptions.updateAutocompleteSuggestions", suggestions); |
| 494 } | 557 } |
| OLD | NEW |