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 | |
40 BrowserOptionsHandler::BrowserOptionsHandler() | 46 BrowserOptionsHandler::BrowserOptionsHandler() |
41 : template_url_service_(NULL), startup_custom_pages_table_model_(NULL) { | 47 : template_url_service_(NULL), startup_custom_pages_table_model_(NULL) { |
42 #if !defined(OS_MACOSX) | 48 #if !defined(OS_MACOSX) |
43 default_browser_worker_ = new ShellIntegration::DefaultBrowserWorker(this); | 49 default_browser_worker_ = new ShellIntegration::DefaultBrowserWorker(this); |
44 #endif | 50 #endif |
45 } | 51 } |
46 | 52 |
47 BrowserOptionsHandler::~BrowserOptionsHandler() { | 53 BrowserOptionsHandler::~BrowserOptionsHandler() { |
48 if (default_browser_worker_.get()) | 54 if (default_browser_worker_.get()) |
49 default_browser_worker_->ObserverDestroyed(); | 55 default_browser_worker_->ObserverDestroyed(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 IDS_OPTIONS_GENERAL_TAB_LABEL); | 89 IDS_OPTIONS_GENERAL_TAB_LABEL); |
84 | 90 |
85 localized_strings->SetString("instantLearnMoreLink", | 91 localized_strings->SetString("instantLearnMoreLink", |
86 ASCIIToUTF16(browser::InstantLearnMoreURL().spec())); | 92 ASCIIToUTF16(browser::InstantLearnMoreURL().spec())); |
87 localized_strings->SetString("defaultBrowserUnknown", | 93 localized_strings->SetString("defaultBrowserUnknown", |
88 l10n_util::GetStringFUTF16(IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN, | 94 l10n_util::GetStringFUTF16(IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN, |
89 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); | 95 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); |
90 localized_strings->SetString("defaultBrowserUseAsDefault", | 96 localized_strings->SetString("defaultBrowserUseAsDefault", |
91 l10n_util::GetStringFUTF16(IDS_OPTIONS_DEFAULTBROWSER_USEASDEFAULT, | 97 l10n_util::GetStringFUTF16(IDS_OPTIONS_DEFAULTBROWSER_USEASDEFAULT, |
92 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); | 98 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); |
99 localized_strings->SetString("autoLaunchText", | |
100 l10n_util::GetStringFUTF16(IDS_AUTOLAUNCH_TEXT, | |
101 l10n_util::GetStringUTF16(IDS_PRODUCT_NAME))); | |
93 } | 102 } |
94 | 103 |
95 void BrowserOptionsHandler::RegisterMessages() { | 104 void BrowserOptionsHandler::RegisterMessages() { |
96 web_ui_->RegisterMessageCallback("becomeDefaultBrowser", | 105 web_ui_->RegisterMessageCallback("becomeDefaultBrowser", |
97 base::Bind(&BrowserOptionsHandler::BecomeDefaultBrowser, | 106 base::Bind(&BrowserOptionsHandler::BecomeDefaultBrowser, |
98 base::Unretained(this))); | 107 base::Unretained(this))); |
99 web_ui_->RegisterMessageCallback("setDefaultSearchEngine", | 108 web_ui_->RegisterMessageCallback("setDefaultSearchEngine", |
100 base::Bind(&BrowserOptionsHandler::SetDefaultSearchEngine, | 109 base::Bind(&BrowserOptionsHandler::SetDefaultSearchEngine, |
101 base::Unretained(this))); | 110 base::Unretained(this))); |
102 web_ui_->RegisterMessageCallback("removeStartupPages", | 111 web_ui_->RegisterMessageCallback("removeStartupPages", |
(...skipping 16 matching lines...) Expand all Loading... | |
119 base::Unretained(this))); | 128 base::Unretained(this))); |
120 web_ui_->RegisterMessageCallback("enableInstant", | 129 web_ui_->RegisterMessageCallback("enableInstant", |
121 base::Bind(&BrowserOptionsHandler::EnableInstant, | 130 base::Bind(&BrowserOptionsHandler::EnableInstant, |
122 base::Unretained(this))); | 131 base::Unretained(this))); |
123 web_ui_->RegisterMessageCallback("disableInstant", | 132 web_ui_->RegisterMessageCallback("disableInstant", |
124 base::Bind(&BrowserOptionsHandler::DisableInstant, | 133 base::Bind(&BrowserOptionsHandler::DisableInstant, |
125 base::Unretained(this))); | 134 base::Unretained(this))); |
126 web_ui_->RegisterMessageCallback("getInstantFieldTrialStatus", | 135 web_ui_->RegisterMessageCallback("getInstantFieldTrialStatus", |
127 base::Bind(&BrowserOptionsHandler::GetInstantFieldTrialStatus, | 136 base::Bind(&BrowserOptionsHandler::GetInstantFieldTrialStatus, |
128 base::Unretained(this))); | 137 base::Unretained(this))); |
138 if (auto_launch_trial::IsInAutoLaunchGroup()) { | |
139 web_ui_->RegisterMessageCallback("toggleAutoLaunch", | |
140 base::Bind(&BrowserOptionsHandler::ToggleAutoLaunch, | |
141 base::Unretained(this))); | |
142 } | |
129 } | 143 } |
130 | 144 |
131 void BrowserOptionsHandler::Initialize() { | 145 void BrowserOptionsHandler::Initialize() { |
132 Profile* profile = Profile::FromWebUI(web_ui_); | 146 Profile* profile = Profile::FromWebUI(web_ui_); |
133 | 147 |
134 // Create our favicon data source. | 148 // Create our favicon data source. |
135 profile->GetChromeURLDataManager()->AddDataSource( | 149 profile->GetChromeURLDataManager()->AddDataSource( |
136 new FaviconSource(profile, FaviconSource::FAVICON)); | 150 new FaviconSource(profile, FaviconSource::FAVICON)); |
137 | 151 |
138 homepage_.Init(prefs::kHomePage, profile->GetPrefs(), NULL); | 152 homepage_.Init(prefs::kHomePage, profile->GetPrefs(), NULL); |
139 default_browser_policy_.Init(prefs::kDefaultBrowserSettingEnabled, | 153 default_browser_policy_.Init(prefs::kDefaultBrowserSettingEnabled, |
140 g_browser_process->local_state(), | 154 g_browser_process->local_state(), |
141 this); | 155 this); |
142 UpdateDefaultBrowserState(); | 156 UpdateDefaultBrowserState(); |
143 | 157 |
144 startup_custom_pages_table_model_.reset( | 158 startup_custom_pages_table_model_.reset( |
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 if (auto_launch_trial::IsInAutoLaunchGroup()) { | |
172 base::FundamentalValue enabled(auto_launch_util::WillLaunchAtLogin()); | |
173 web_ui_->CallJavascriptFunction("BrowserOptions.updateAutoLaunchState", | |
174 enabled); | |
175 } | |
176 #endif | |
155 } | 177 } |
156 | 178 |
157 void BrowserOptionsHandler::UpdateDefaultBrowserState() { | 179 void BrowserOptionsHandler::UpdateDefaultBrowserState() { |
158 // Check for side-by-side first. | 180 // Check for side-by-side first. |
159 if (!ShellIntegration::CanSetAsDefaultBrowser()) { | 181 if (!ShellIntegration::CanSetAsDefaultBrowser()) { |
160 SetDefaultBrowserUIString(IDS_OPTIONS_DEFAULTBROWSER_SXS); | 182 SetDefaultBrowserUIString(IDS_OPTIONS_DEFAULTBROWSER_SXS); |
161 return; | 183 return; |
162 } | 184 } |
163 | 185 |
164 #if defined(OS_MACOSX) | 186 #if defined(OS_MACOSX) |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
454 } | 476 } |
455 | 477 |
456 void BrowserOptionsHandler::EnableInstant(const ListValue* args) { | 478 void BrowserOptionsHandler::EnableInstant(const ListValue* args) { |
457 InstantController::Enable(Profile::FromWebUI(web_ui_)); | 479 InstantController::Enable(Profile::FromWebUI(web_ui_)); |
458 } | 480 } |
459 | 481 |
460 void BrowserOptionsHandler::DisableInstant(const ListValue* args) { | 482 void BrowserOptionsHandler::DisableInstant(const ListValue* args) { |
461 InstantController::Disable(Profile::FromWebUI(web_ui_)); | 483 InstantController::Disable(Profile::FromWebUI(web_ui_)); |
462 } | 484 } |
463 | 485 |
486 void BrowserOptionsHandler::ToggleAutoLaunch(const ListValue* args) { | |
487 #if defined(OS_WIN) | |
488 if (!auto_launch_trial::IsInAutoLaunchGroup()) | |
489 return; | |
490 | |
491 bool enable; | |
492 CHECK_EQ(args->GetSize(), 1U); | |
493 CHECK(args->GetBoolean(0, &enable)); | |
494 | |
495 // Make sure we keep track of how many disable and how many enable. | |
grt (UTC plus 2)
2011/12/01 04:45:02
this is almost duplicate code. could it be shared
| |
496 auto_launch_trial::UpdateToggleAutoLaunchMetric(enable); | |
497 | |
498 FilePath chrome_exe; | |
grt (UTC plus 2)
2011/12/01 04:45:02
chrome_exe -> chrome_dir, or somesuch
| |
499 if (!PathService::Get(base::DIR_EXE, &chrome_exe)) | |
stuartmorgan
2011/12/01 10:11:44
Seems a bit odd to me that this code lives here an
| |
500 NOTREACHED(); | |
501 | |
502 auto_launch_util::SetWillLaunchAtLogin(enable, chrome_exe); | |
grt (UTC plus 2)
2011/12/01 04:45:02
this will touch the registry. is IO allowed from
| |
503 #endif // OS_WIN | |
504 } | |
505 | |
464 void BrowserOptionsHandler::GetInstantFieldTrialStatus(const ListValue* args) { | 506 void BrowserOptionsHandler::GetInstantFieldTrialStatus(const ListValue* args) { |
465 Profile* profile = Profile::FromWebUI(web_ui_); | 507 Profile* profile = Profile::FromWebUI(web_ui_); |
466 base::FundamentalValue enabled( | 508 base::FundamentalValue enabled( |
467 InstantFieldTrial::IsInstantExperiment(profile) && | 509 InstantFieldTrial::IsInstantExperiment(profile) && |
468 !InstantFieldTrial::IsHiddenExperiment(profile)); | 510 !InstantFieldTrial::IsHiddenExperiment(profile)); |
469 web_ui_->CallJavascriptFunction("BrowserOptions.setInstantFieldTrialStatus", | 511 web_ui_->CallJavascriptFunction("BrowserOptions.setInstantFieldTrialStatus", |
470 enabled); | 512 enabled); |
471 } | 513 } |
472 | 514 |
473 void BrowserOptionsHandler::OnResultChanged(bool default_match_changed) { | 515 void BrowserOptionsHandler::OnResultChanged(bool default_match_changed) { |
(...skipping 11 matching lines...) Expand all Loading... | |
485 DictionaryValue* entry = new DictionaryValue(); | 527 DictionaryValue* entry = new DictionaryValue(); |
486 entry->SetString("title", match.description); | 528 entry->SetString("title", match.description); |
487 entry->SetString("displayURL", match.contents); | 529 entry->SetString("displayURL", match.contents); |
488 entry->SetString("url", match.destination_url.spec()); | 530 entry->SetString("url", match.destination_url.spec()); |
489 suggestions.Append(entry); | 531 suggestions.Append(entry); |
490 } | 532 } |
491 | 533 |
492 web_ui_->CallJavascriptFunction( | 534 web_ui_->CallJavascriptFunction( |
493 "BrowserOptions.updateAutocompleteSuggestions", suggestions); | 535 "BrowserOptions.updateAutocompleteSuggestions", suggestions); |
494 } | 536 } |
OLD | NEW |