| 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/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" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/browser/instant/instant_controller.h" | 21 #include "chrome/browser/instant/instant_controller.h" |
| 22 #include "chrome/browser/instant/instant_field_trial.h" | 22 #include "chrome/browser/instant/instant_field_trial.h" |
| 23 #include "chrome/browser/net/url_fixer_upper.h" | 23 #include "chrome/browser/net/url_fixer_upper.h" |
| 24 #include "chrome/browser/prefs/pref_service.h" | 24 #include "chrome/browser/prefs/pref_service.h" |
| 25 #include "chrome/browser/prefs/session_startup_pref.h" | 25 #include "chrome/browser/prefs/session_startup_pref.h" |
| 26 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
| 27 #include "chrome/browser/search_engines/template_url.h" | 27 #include "chrome/browser/search_engines/template_url.h" |
| 28 #include "chrome/browser/search_engines/template_url_service.h" | 28 #include "chrome/browser/search_engines/template_url_service.h" |
| 29 #include "chrome/browser/search_engines/template_url_service_factory.h" | 29 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 30 #include "chrome/browser/ui/webui/favicon_source.h" | 30 #include "chrome/browser/ui/webui/favicon_source.h" |
| 31 #include "chrome/common/chrome_constants.h" |
| 31 #include "chrome/common/chrome_notification_types.h" | 32 #include "chrome/common/chrome_notification_types.h" |
| 32 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
| 33 #include "chrome/common/url_constants.h" | 34 #include "chrome/common/url_constants.h" |
| 34 #include "content/public/browser/browser_thread.h" | 35 #include "content/public/browser/browser_thread.h" |
| 35 #include "content/public/browser/notification_details.h" | 36 #include "content/public/browser/notification_details.h" |
| 36 #include "content/public/browser/notification_source.h" | 37 #include "content/public/browser/notification_source.h" |
| 37 #include "content/public/browser/user_metrics.h" | 38 #include "content/public/browser/user_metrics.h" |
| 38 #include "content/public/browser/web_ui.h" | 39 #include "content/public/browser/web_ui.h" |
| 39 #include "grit/chromium_strings.h" | 40 #include "grit/chromium_strings.h" |
| 40 #include "grit/generated_resources.h" | 41 #include "grit/generated_resources.h" |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 pref_change_registrar_.Add(prefs::kURLsToRestoreOnStartup, this); | 167 pref_change_registrar_.Add(prefs::kURLsToRestoreOnStartup, this); |
| 167 | 168 |
| 168 UpdateSearchEngines(); | 169 UpdateSearchEngines(); |
| 169 | 170 |
| 170 autocomplete_controller_.reset(new AutocompleteController(profile, this)); | 171 autocomplete_controller_.reset(new AutocompleteController(profile, this)); |
| 171 | 172 |
| 172 #if defined(OS_WIN) | 173 #if defined(OS_WIN) |
| 173 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 174 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
| 174 base::Bind(&BrowserOptionsHandler::CheckAutoLaunch, | 175 base::Bind(&BrowserOptionsHandler::CheckAutoLaunch, |
| 175 weak_ptr_factory_for_ui_.GetWeakPtr(), | 176 weak_ptr_factory_for_ui_.GetWeakPtr(), |
| 176 weak_ptr_factory_for_file_.GetWeakPtr())); | 177 weak_ptr_factory_for_file_.GetWeakPtr(), |
| 178 profile->GetPath())); |
| 177 weak_ptr_factory_for_ui_.DetachFromThread(); | 179 weak_ptr_factory_for_ui_.DetachFromThread(); |
| 178 #endif | 180 #endif |
| 179 } | 181 } |
| 180 | 182 |
| 181 void BrowserOptionsHandler::CheckAutoLaunch( | 183 void BrowserOptionsHandler::CheckAutoLaunch( |
| 182 base::WeakPtr<BrowserOptionsHandler> weak_this) { | 184 base::WeakPtr<BrowserOptionsHandler> weak_this, |
| 185 const FilePath& profile_path) { |
| 183 #if defined(OS_WIN) | 186 #if defined(OS_WIN) |
| 184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
| 185 | 188 |
| 189 // We don't support this for secondary profiles yet. |
| 190 if (profile_path.BaseName().value() != ASCIIToUTF16(chrome::kInitialProfile)) |
| 191 return; |
| 192 |
| 186 // Pass in weak pointer to this to avoid race if BrowserOptionsHandler is | 193 // Pass in weak pointer to this to avoid race if BrowserOptionsHandler is |
| 187 // deleted. | 194 // deleted. |
| 188 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 195 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 189 base::Bind(&BrowserOptionsHandler::CheckAutoLaunchCallback, | 196 base::Bind(&BrowserOptionsHandler::CheckAutoLaunchCallback, |
| 190 weak_this, | 197 weak_this, |
| 191 auto_launch_trial::IsInAutoLaunchGroup(), | 198 auto_launch_trial::IsInAutoLaunchGroup(), |
| 192 auto_launch_util::WillLaunchAtLogin(FilePath()))); | 199 auto_launch_util::WillLaunchAtLogin(FilePath(), |
| 200 profile_path))); |
| 193 #endif | 201 #endif |
| 194 } | 202 } |
| 195 | 203 |
| 196 void BrowserOptionsHandler::CheckAutoLaunchCallback( | 204 void BrowserOptionsHandler::CheckAutoLaunchCallback( |
| 197 bool is_in_auto_launch_group, | 205 bool is_in_auto_launch_group, |
| 198 bool will_launch_at_login) { | 206 bool will_launch_at_login) { |
| 199 #if defined(OS_WIN) | 207 #if defined(OS_WIN) |
| 200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 201 | 209 |
| 202 if (is_in_auto_launch_group) { | 210 if (is_in_auto_launch_group) { |
| 203 web_ui()->RegisterMessageCallback("toggleAutoLaunch", | 211 web_ui()->RegisterMessageCallback("toggleAutoLaunch", |
| 204 base::Bind(&BrowserOptionsHandler::ToggleAutoLaunch, | 212 base::Bind(&BrowserOptionsHandler::ToggleAutoLaunch, |
| 205 base::Unretained(this))); | 213 base::Unretained(this))); |
| 206 | 214 |
| 207 base::FundamentalValue enabled(will_launch_at_login); | 215 base::FundamentalValue enabled(will_launch_at_login); |
| 208 web_ui()->CallJavascriptFunction("BrowserOptions.updateAutoLaunchState", | 216 web_ui()->CallJavascriptFunction("BrowserOptions.updateAutoLaunchState", |
| 209 enabled); | 217 enabled); |
| 210 } | 218 } |
| 211 #endif | 219 #endif |
| 212 } | 220 } |
| 213 | 221 |
| 214 void BrowserOptionsHandler::UpdateDefaultBrowserState() { | 222 void BrowserOptionsHandler::UpdateDefaultBrowserState() { |
| 215 // Check for side-by-side first. | 223 // Check for side-by-side first. |
| 216 if (!ShellIntegration::CanSetAsDefaultBrowser()) { | 224 if (!ShellIntegration::CanSetAsDefaultBrowser()) { |
| 217 SetDefaultBrowserUIString(IDS_OPTIONS_DEFAULTBROWSER_SXS); | 225 SetDefaultBrowserUIString(IDS_OPTIONS_DEFAULTBROWSER_SXS); |
| 218 return; | 226 return; |
| 219 } | 227 } |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 #if defined(OS_WIN) | 531 #if defined(OS_WIN) |
| 524 if (!auto_launch_trial::IsInAutoLaunchGroup()) | 532 if (!auto_launch_trial::IsInAutoLaunchGroup()) |
| 525 return; | 533 return; |
| 526 | 534 |
| 527 bool enable; | 535 bool enable; |
| 528 CHECK_EQ(args->GetSize(), 1U); | 536 CHECK_EQ(args->GetSize(), 1U); |
| 529 CHECK(args->GetBoolean(0, &enable)); | 537 CHECK(args->GetBoolean(0, &enable)); |
| 530 | 538 |
| 531 // Make sure we keep track of how many disable and how many enable. | 539 // Make sure we keep track of how many disable and how many enable. |
| 532 auto_launch_trial::UpdateToggleAutoLaunchMetric(enable); | 540 auto_launch_trial::UpdateToggleAutoLaunchMetric(enable); |
| 541 Profile* profile = Profile::FromWebUI(web_ui()); |
| 533 content::BrowserThread::PostTask( | 542 content::BrowserThread::PostTask( |
| 534 content::BrowserThread::FILE, FROM_HERE, | 543 content::BrowserThread::FILE, FROM_HERE, |
| 535 base::Bind(&auto_launch_util::SetWillLaunchAtLogin, enable, FilePath())); | 544 base::Bind(&auto_launch_util::SetWillLaunchAtLogin, enable, |
| 545 FilePath(), profile->GetPath())); |
| 536 #endif // OS_WIN | 546 #endif // OS_WIN |
| 537 } | 547 } |
| 538 | 548 |
| 539 void BrowserOptionsHandler::GetInstantFieldTrialStatus(const ListValue* args) { | 549 void BrowserOptionsHandler::GetInstantFieldTrialStatus(const ListValue* args) { |
| 540 Profile* profile = Profile::FromWebUI(web_ui()); | 550 Profile* profile = Profile::FromWebUI(web_ui()); |
| 541 base::FundamentalValue enabled( | 551 base::FundamentalValue enabled( |
| 542 InstantFieldTrial::IsInstantExperiment(profile) && | 552 InstantFieldTrial::IsInstantExperiment(profile) && |
| 543 !InstantFieldTrial::IsHiddenExperiment(profile)); | 553 !InstantFieldTrial::IsHiddenExperiment(profile)); |
| 544 web_ui()->CallJavascriptFunction("BrowserOptions.setInstantFieldTrialStatus", | 554 web_ui()->CallJavascriptFunction("BrowserOptions.setInstantFieldTrialStatus", |
| 545 enabled); | 555 enabled); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 560 DictionaryValue* entry = new DictionaryValue(); | 570 DictionaryValue* entry = new DictionaryValue(); |
| 561 entry->SetString("title", match.description); | 571 entry->SetString("title", match.description); |
| 562 entry->SetString("displayURL", match.contents); | 572 entry->SetString("displayURL", match.contents); |
| 563 entry->SetString("url", match.destination_url.spec()); | 573 entry->SetString("url", match.destination_url.spec()); |
| 564 suggestions.Append(entry); | 574 suggestions.Append(entry); |
| 565 } | 575 } |
| 566 | 576 |
| 567 web_ui()->CallJavascriptFunction( | 577 web_ui()->CallJavascriptFunction( |
| 568 "BrowserOptions.updateAutocompleteSuggestions", suggestions); | 578 "BrowserOptions.updateAutocompleteSuggestions", suggestions); |
| 569 } | 579 } |
| OLD | NEW |