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_file_(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_file_.GetWeakPtr())); |
| 175 weak_ptr_factory_for_ui_.DetachFromThread(); |
| 176 #endif |
| 177 } |
| 178 |
| 179 void BrowserOptionsHandler::CheckAutoLaunch( |
| 180 base::WeakPtr<BrowserOptionsHandler> weak_this) { |
| 181 #if defined(OS_WIN) |
| 182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 183 |
| 184 // Pass in weak pointer to this to avoid race if BrowserOptionsHandler is |
| 185 // deleted. |
| 186 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 187 base::Bind(&BrowserOptionsHandler::CheckAutoLaunchCallback, |
| 188 weak_this, |
| 189 auto_launch_trial::IsInAutoLaunchGroup(), |
| 190 auto_launch_util::WillLaunchAtLogin(FilePath()))); |
| 191 #endif |
| 192 } |
| 193 |
| 194 void BrowserOptionsHandler::CheckAutoLaunchCallback( |
| 195 bool is_in_auto_launch_group, |
| 196 bool will_launch_at_login) { |
| 197 #if defined(OS_WIN) |
| 198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 199 |
| 200 if (is_in_auto_launch_group) { |
| 201 web_ui_->RegisterMessageCallback("toggleAutoLaunch", |
| 202 base::Bind(&BrowserOptionsHandler::ToggleAutoLaunch, |
| 203 base::Unretained(this))); |
| 204 |
| 205 base::FundamentalValue enabled(will_launch_at_login); |
| 206 web_ui_->CallJavascriptFunction("BrowserOptions.updateAutoLaunchState", |
| 207 enabled); |
| 208 } |
| 209 #endif |
155 } | 210 } |
156 | 211 |
157 void BrowserOptionsHandler::UpdateDefaultBrowserState() { | 212 void BrowserOptionsHandler::UpdateDefaultBrowserState() { |
158 // Check for side-by-side first. | 213 // Check for side-by-side first. |
159 if (!ShellIntegration::CanSetAsDefaultBrowser()) { | 214 if (!ShellIntegration::CanSetAsDefaultBrowser()) { |
160 SetDefaultBrowserUIString(IDS_OPTIONS_DEFAULTBROWSER_SXS); | 215 SetDefaultBrowserUIString(IDS_OPTIONS_DEFAULTBROWSER_SXS); |
161 return; | 216 return; |
162 } | 217 } |
163 | 218 |
164 #if defined(OS_MACOSX) | 219 #if defined(OS_MACOSX) |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 } | 509 } |
455 | 510 |
456 void BrowserOptionsHandler::EnableInstant(const ListValue* args) { | 511 void BrowserOptionsHandler::EnableInstant(const ListValue* args) { |
457 InstantController::Enable(Profile::FromWebUI(web_ui_)); | 512 InstantController::Enable(Profile::FromWebUI(web_ui_)); |
458 } | 513 } |
459 | 514 |
460 void BrowserOptionsHandler::DisableInstant(const ListValue* args) { | 515 void BrowserOptionsHandler::DisableInstant(const ListValue* args) { |
461 InstantController::Disable(Profile::FromWebUI(web_ui_)); | 516 InstantController::Disable(Profile::FromWebUI(web_ui_)); |
462 } | 517 } |
463 | 518 |
| 519 void BrowserOptionsHandler::ToggleAutoLaunch(const ListValue* args) { |
| 520 #if defined(OS_WIN) |
| 521 if (!auto_launch_trial::IsInAutoLaunchGroup()) |
| 522 return; |
| 523 |
| 524 bool enable; |
| 525 CHECK_EQ(args->GetSize(), 1U); |
| 526 CHECK(args->GetBoolean(0, &enable)); |
| 527 |
| 528 // Make sure we keep track of how many disable and how many enable. |
| 529 auto_launch_trial::UpdateToggleAutoLaunchMetric(enable); |
| 530 content::BrowserThread::PostTask( |
| 531 content::BrowserThread::FILE, FROM_HERE, |
| 532 base::Bind(&auto_launch_util::SetWillLaunchAtLogin, enable, FilePath())); |
| 533 #endif // OS_WIN |
| 534 } |
| 535 |
464 void BrowserOptionsHandler::GetInstantFieldTrialStatus(const ListValue* args) { | 536 void BrowserOptionsHandler::GetInstantFieldTrialStatus(const ListValue* args) { |
465 Profile* profile = Profile::FromWebUI(web_ui_); | 537 Profile* profile = Profile::FromWebUI(web_ui_); |
466 base::FundamentalValue enabled( | 538 base::FundamentalValue enabled( |
467 InstantFieldTrial::IsInstantExperiment(profile) && | 539 InstantFieldTrial::IsInstantExperiment(profile) && |
468 !InstantFieldTrial::IsHiddenExperiment(profile)); | 540 !InstantFieldTrial::IsHiddenExperiment(profile)); |
469 web_ui_->CallJavascriptFunction("BrowserOptions.setInstantFieldTrialStatus", | 541 web_ui_->CallJavascriptFunction("BrowserOptions.setInstantFieldTrialStatus", |
470 enabled); | 542 enabled); |
471 } | 543 } |
472 | 544 |
473 void BrowserOptionsHandler::OnResultChanged(bool default_match_changed) { | 545 void BrowserOptionsHandler::OnResultChanged(bool default_match_changed) { |
(...skipping 11 matching lines...) Expand all Loading... |
485 DictionaryValue* entry = new DictionaryValue(); | 557 DictionaryValue* entry = new DictionaryValue(); |
486 entry->SetString("title", match.description); | 558 entry->SetString("title", match.description); |
487 entry->SetString("displayURL", match.contents); | 559 entry->SetString("displayURL", match.contents); |
488 entry->SetString("url", match.destination_url.spec()); | 560 entry->SetString("url", match.destination_url.spec()); |
489 suggestions.Append(entry); | 561 suggestions.Append(entry); |
490 } | 562 } |
491 | 563 |
492 web_ui_->CallJavascriptFunction( | 564 web_ui_->CallJavascriptFunction( |
493 "BrowserOptions.updateAutocompleteSuggestions", suggestions); | 565 "BrowserOptions.updateAutocompleteSuggestions", suggestions); |
494 } | 566 } |
OLD | NEW |