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/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/memory/singleton.h" | 9 #include "base/memory/singleton.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "chrome/browser/prefs/session_startup_pref.h" | 22 #include "chrome/browser/prefs/session_startup_pref.h" |
23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
24 #include "chrome/browser/search_engines/template_url.h" | 24 #include "chrome/browser/search_engines/template_url.h" |
25 #include "chrome/browser/search_engines/template_url_service.h" | 25 #include "chrome/browser/search_engines/template_url_service.h" |
26 #include "chrome/browser/search_engines/template_url_service_factory.h" | 26 #include "chrome/browser/search_engines/template_url_service_factory.h" |
27 #include "chrome/browser/ui/webui/favicon_source.h" | 27 #include "chrome/browser/ui/webui/favicon_source.h" |
28 #include "chrome/common/chrome_notification_types.h" | 28 #include "chrome/common/chrome_notification_types.h" |
29 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
30 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
31 #include "content/browser/browser_thread.h" | 31 #include "content/browser/browser_thread.h" |
| 32 #include "content/browser/tab_contents/tab_contents.h" |
32 #include "content/browser/user_metrics.h" | 33 #include "content/browser/user_metrics.h" |
33 #include "content/common/notification_details.h" | 34 #include "content/common/notification_details.h" |
34 #include "content/common/notification_service.h" | 35 #include "content/common/notification_service.h" |
35 #include "content/common/notification_source.h" | 36 #include "content/common/notification_source.h" |
36 #include "grit/chromium_strings.h" | 37 #include "grit/chromium_strings.h" |
37 #include "grit/generated_resources.h" | 38 #include "grit/generated_resources.h" |
38 #include "ui/base/l10n/l10n_util.h" | 39 #include "ui/base/l10n/l10n_util.h" |
39 | 40 |
40 BrowserOptionsHandler::BrowserOptionsHandler() | 41 BrowserOptionsHandler::BrowserOptionsHandler() |
41 : template_url_service_(NULL), startup_custom_pages_table_model_(NULL) { | 42 : template_url_service_(NULL), startup_custom_pages_table_model_(NULL) { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 NewCallback(this, &BrowserOptionsHandler::EnableInstant)); | 133 NewCallback(this, &BrowserOptionsHandler::EnableInstant)); |
133 web_ui_->RegisterMessageCallback( | 134 web_ui_->RegisterMessageCallback( |
134 "disableInstant", | 135 "disableInstant", |
135 NewCallback(this, &BrowserOptionsHandler::DisableInstant)); | 136 NewCallback(this, &BrowserOptionsHandler::DisableInstant)); |
136 web_ui_->RegisterMessageCallback( | 137 web_ui_->RegisterMessageCallback( |
137 "getInstantFieldTrialStatus", | 138 "getInstantFieldTrialStatus", |
138 NewCallback(this, &BrowserOptionsHandler::GetInstantFieldTrialStatus)); | 139 NewCallback(this, &BrowserOptionsHandler::GetInstantFieldTrialStatus)); |
139 } | 140 } |
140 | 141 |
141 void BrowserOptionsHandler::Initialize() { | 142 void BrowserOptionsHandler::Initialize() { |
142 Profile* profile = web_ui_->GetProfile(); | 143 Profile* profile = |
| 144 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
143 | 145 |
144 // Create our favicon data source. | 146 // Create our favicon data source. |
145 profile->GetChromeURLDataManager()->AddDataSource( | 147 profile->GetChromeURLDataManager()->AddDataSource( |
146 new FaviconSource(profile, FaviconSource::FAVICON)); | 148 new FaviconSource(profile, FaviconSource::FAVICON)); |
147 | 149 |
148 homepage_.Init(prefs::kHomePage, profile->GetPrefs(), NULL); | 150 homepage_.Init(prefs::kHomePage, profile->GetPrefs(), NULL); |
149 default_browser_policy_.Init(prefs::kDefaultBrowserSettingEnabled, | 151 default_browser_policy_.Init(prefs::kDefaultBrowserSettingEnabled, |
150 g_browser_process->local_state(), | 152 g_browser_process->local_state(), |
151 this); | 153 this); |
152 UpdateDefaultBrowserState(); | 154 UpdateDefaultBrowserState(); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 #if defined(OS_MACOSX) | 217 #if defined(OS_MACOSX) |
216 if (ShellIntegration::SetAsDefaultBrowser()) | 218 if (ShellIntegration::SetAsDefaultBrowser()) |
217 UpdateDefaultBrowserState(); | 219 UpdateDefaultBrowserState(); |
218 #else | 220 #else |
219 default_browser_worker_->StartSetAsDefault(); | 221 default_browser_worker_->StartSetAsDefault(); |
220 // Callback takes care of updating UI. | 222 // Callback takes care of updating UI. |
221 #endif | 223 #endif |
222 | 224 |
223 // If the user attempted to make Chrome the default browser, then he/she | 225 // If the user attempted to make Chrome the default browser, then he/she |
224 // arguably wants to be notified when that changes. | 226 // arguably wants to be notified when that changes. |
225 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); | 227 Profile* profile = |
| 228 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
| 229 PrefService* prefs = profile->GetPrefs(); |
226 prefs->SetBoolean(prefs::kCheckDefaultBrowser, true); | 230 prefs->SetBoolean(prefs::kCheckDefaultBrowser, true); |
227 } | 231 } |
228 | 232 |
229 int BrowserOptionsHandler::StatusStringIdForState( | 233 int BrowserOptionsHandler::StatusStringIdForState( |
230 ShellIntegration::DefaultWebClientState state) { | 234 ShellIntegration::DefaultWebClientState state) { |
231 if (state == ShellIntegration::IS_DEFAULT_WEB_CLIENT) | 235 if (state == ShellIntegration::IS_DEFAULT_WEB_CLIENT) |
232 return IDS_OPTIONS_DEFAULTBROWSER_DEFAULT; | 236 return IDS_OPTIONS_DEFAULTBROWSER_DEFAULT; |
233 if (state == ShellIntegration::NOT_DEFAULT_WEB_CLIENT) | 237 if (state == ShellIntegration::NOT_DEFAULT_WEB_CLIENT) |
234 return IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT; | 238 return IDS_OPTIONS_DEFAULTBROWSER_NOTDEFAULT; |
235 return IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN; | 239 return IDS_OPTIONS_DEFAULTBROWSER_UNKNOWN; |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 std::vector<const TemplateURL*> model_urls = | 313 std::vector<const TemplateURL*> model_urls = |
310 template_url_service_->GetTemplateURLs(); | 314 template_url_service_->GetTemplateURLs(); |
311 if (selected_index >= 0 && | 315 if (selected_index >= 0 && |
312 selected_index < static_cast<int>(model_urls.size())) | 316 selected_index < static_cast<int>(model_urls.size())) |
313 template_url_service_->SetDefaultSearchProvider(model_urls[selected_index]); | 317 template_url_service_->SetDefaultSearchProvider(model_urls[selected_index]); |
314 | 318 |
315 UserMetrics::RecordAction(UserMetricsAction("Options_SearchEngineChanged")); | 319 UserMetrics::RecordAction(UserMetricsAction("Options_SearchEngineChanged")); |
316 } | 320 } |
317 | 321 |
318 void BrowserOptionsHandler::UpdateSearchEngines() { | 322 void BrowserOptionsHandler::UpdateSearchEngines() { |
319 template_url_service_ = TemplateURLServiceFactory::GetForProfile( | 323 Profile* profile = |
320 web_ui_->GetProfile()); | 324 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
| 325 template_url_service_ = TemplateURLServiceFactory::GetForProfile(profile); |
321 if (template_url_service_) { | 326 if (template_url_service_) { |
322 template_url_service_->Load(); | 327 template_url_service_->Load(); |
323 template_url_service_->AddObserver(this); | 328 template_url_service_->AddObserver(this); |
324 OnTemplateURLServiceChanged(); | 329 OnTemplateURLServiceChanged(); |
325 } | 330 } |
326 } | 331 } |
327 | 332 |
328 void BrowserOptionsHandler::UpdateRestoreOnStartup() { | 333 void BrowserOptionsHandler::UpdateRestoreOnStartup() { |
329 Profile* profile = web_ui_->GetProfile(); | 334 Profile* profile = |
| 335 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
330 const SessionStartupPref startup_pref = | 336 const SessionStartupPref startup_pref = |
331 SessionStartupPref::GetStartupPref(profile->GetPrefs()); | 337 SessionStartupPref::GetStartupPref(profile->GetPrefs()); |
332 FundamentalValue restore_on_startup(startup_pref.type); | 338 FundamentalValue restore_on_startup(startup_pref.type); |
333 web_ui_->CallJavascriptFunction("BrowserOptions.updateRestoreOnStartup", | 339 web_ui_->CallJavascriptFunction("BrowserOptions.updateRestoreOnStartup", |
334 restore_on_startup); | 340 restore_on_startup); |
335 } | 341 } |
336 | 342 |
337 void BrowserOptionsHandler::UpdateStartupPages() { | 343 void BrowserOptionsHandler::UpdateStartupPages() { |
338 Profile* profile = web_ui_->GetProfile(); | 344 Profile* profile = |
| 345 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
339 const SessionStartupPref startup_pref = | 346 const SessionStartupPref startup_pref = |
340 SessionStartupPref::GetStartupPref(profile->GetPrefs()); | 347 SessionStartupPref::GetStartupPref(profile->GetPrefs()); |
341 startup_custom_pages_table_model_->SetURLs(startup_pref.urls); | 348 startup_custom_pages_table_model_->SetURLs(startup_pref.urls); |
342 } | 349 } |
343 | 350 |
344 void BrowserOptionsHandler::OnModelChanged() { | 351 void BrowserOptionsHandler::OnModelChanged() { |
345 ListValue startup_pages; | 352 ListValue startup_pages; |
346 int page_count = startup_custom_pages_table_model_->RowCount(); | 353 int page_count = startup_custom_pages_table_model_->RowCount(); |
347 std::vector<GURL> urls = startup_custom_pages_table_model_->GetURLs(); | 354 std::vector<GURL> urls = startup_custom_pages_table_model_->GetURLs(); |
348 for (int i = 0; i < page_count; ++i) { | 355 for (int i = 0; i < page_count; ++i) { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 const ListValue* args) { | 401 const ListValue* args) { |
395 startup_custom_pages_table_model_->SetToCurrentlyOpenPages(); | 402 startup_custom_pages_table_model_->SetToCurrentlyOpenPages(); |
396 SaveStartupPagesPref(); | 403 SaveStartupPagesPref(); |
397 } | 404 } |
398 | 405 |
399 void BrowserOptionsHandler::SetRestoreOnStartup(const ListValue* args) { | 406 void BrowserOptionsHandler::SetRestoreOnStartup(const ListValue* args) { |
400 std::string pref_string; | 407 std::string pref_string; |
401 CHECK_EQ(args->GetSize(), 1UL); | 408 CHECK_EQ(args->GetSize(), 1UL); |
402 CHECK(args->GetString(0, &pref_string)); | 409 CHECK(args->GetString(0, &pref_string)); |
403 | 410 |
404 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); | 411 Profile* profile = |
| 412 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
| 413 PrefService* prefs = profile->GetPrefs(); |
405 | 414 |
406 SessionStartupPref pref = SessionStartupPref::GetStartupPref(prefs); | 415 SessionStartupPref pref = SessionStartupPref::GetStartupPref(prefs); |
407 if (pref_string == "0") { | 416 if (pref_string == "0") { |
408 pref.type = SessionStartupPref::DEFAULT; | 417 pref.type = SessionStartupPref::DEFAULT; |
409 } else if (pref_string == "1") { | 418 } else if (pref_string == "1") { |
410 pref.type = SessionStartupPref::LAST; | 419 pref.type = SessionStartupPref::LAST; |
411 } else if (pref_string == "2") { | 420 } else if (pref_string == "2") { |
412 pref.type = SessionStartupPref::URLS; | 421 pref.type = SessionStartupPref::URLS; |
413 } else { | 422 } else { |
414 NOTREACHED(); | 423 NOTREACHED(); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 CHECK(selected->GetString(i, &value)); | 493 CHECK(selected->GetString(i, &value)); |
485 base::StringToInt(value, &index); | 494 base::StringToInt(value, &index); |
486 index_list.push_back(index); | 495 index_list.push_back(index); |
487 } | 496 } |
488 | 497 |
489 startup_custom_pages_table_model_->MoveURLs(to_index, index_list); | 498 startup_custom_pages_table_model_->MoveURLs(to_index, index_list); |
490 SaveStartupPagesPref(); | 499 SaveStartupPagesPref(); |
491 } | 500 } |
492 | 501 |
493 void BrowserOptionsHandler::SaveStartupPagesPref() { | 502 void BrowserOptionsHandler::SaveStartupPagesPref() { |
494 PrefService* prefs = web_ui_->GetProfile()->GetPrefs(); | 503 Profile* profile = |
| 504 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
| 505 PrefService* prefs = profile->GetPrefs(); |
495 | 506 |
496 SessionStartupPref pref = SessionStartupPref::GetStartupPref(prefs); | 507 SessionStartupPref pref = SessionStartupPref::GetStartupPref(prefs); |
497 pref.urls = startup_custom_pages_table_model_->GetURLs(); | 508 pref.urls = startup_custom_pages_table_model_->GetURLs(); |
498 | 509 |
499 SessionStartupPref::SetStartupPref(prefs, pref); | 510 SessionStartupPref::SetStartupPref(prefs, pref); |
500 } | 511 } |
501 | 512 |
502 void BrowserOptionsHandler::RequestAutocompleteSuggestions( | 513 void BrowserOptionsHandler::RequestAutocompleteSuggestions( |
503 const ListValue* args) { | 514 const ListValue* args) { |
504 string16 input; | 515 string16 input; |
505 CHECK_EQ(args->GetSize(), 1U); | 516 CHECK_EQ(args->GetSize(), 1U); |
506 CHECK(args->GetString(0, &input)); | 517 CHECK(args->GetString(0, &input)); |
507 | 518 |
508 autocomplete_controller_->Start(input, string16(), true, false, false, | 519 autocomplete_controller_->Start(input, string16(), true, false, false, |
509 AutocompleteInput::ALL_MATCHES); | 520 AutocompleteInput::ALL_MATCHES); |
510 } | 521 } |
511 | 522 |
512 void BrowserOptionsHandler::ToggleShowBookmarksBar(const ListValue* args) { | 523 void BrowserOptionsHandler::ToggleShowBookmarksBar(const ListValue* args) { |
513 Source<Profile> source(web_ui_->GetProfile()); | 524 Profile* profile = |
| 525 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
| 526 Source<Profile> source(profile); |
514 NotificationService::current()->Notify( | 527 NotificationService::current()->Notify( |
515 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, | 528 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, |
516 source, | 529 source, |
517 NotificationService::NoDetails()); | 530 NotificationService::NoDetails()); |
518 } | 531 } |
519 | 532 |
520 void BrowserOptionsHandler::EnableInstant(const ListValue* args) { | 533 void BrowserOptionsHandler::EnableInstant(const ListValue* args) { |
521 InstantController::Enable(web_ui_->GetProfile()); | 534 Profile* profile = |
| 535 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
| 536 InstantController::Enable(profile); |
522 } | 537 } |
523 | 538 |
524 void BrowserOptionsHandler::DisableInstant(const ListValue* args) { | 539 void BrowserOptionsHandler::DisableInstant(const ListValue* args) { |
525 InstantController::Disable(web_ui_->GetProfile()); | 540 Profile* profile = |
| 541 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
| 542 InstantController::Disable(profile); |
526 } | 543 } |
527 | 544 |
528 void BrowserOptionsHandler::GetInstantFieldTrialStatus(const ListValue* args) { | 545 void BrowserOptionsHandler::GetInstantFieldTrialStatus(const ListValue* args) { |
| 546 Profile* profile = |
| 547 Profile::FromBrowserContext(web_ui_->tab_contents()->browser_context()); |
529 FundamentalValue enabled( | 548 FundamentalValue enabled( |
530 InstantFieldTrial::IsExperimentGroup(web_ui_->GetProfile())); | 549 InstantFieldTrial::IsExperimentGroup(profile)); |
531 web_ui_->CallJavascriptFunction("BrowserOptions.setInstantFieldTrialStatus", | 550 web_ui_->CallJavascriptFunction("BrowserOptions.setInstantFieldTrialStatus", |
532 enabled); | 551 enabled); |
533 } | 552 } |
534 | 553 |
535 void BrowserOptionsHandler::OnResultChanged(bool default_match_changed) { | 554 void BrowserOptionsHandler::OnResultChanged(bool default_match_changed) { |
536 const AutocompleteResult& result = autocomplete_controller_->result(); | 555 const AutocompleteResult& result = autocomplete_controller_->result(); |
537 ListValue suggestions; | 556 ListValue suggestions; |
538 for (size_t i = 0; i < result.size(); ++i) { | 557 for (size_t i = 0; i < result.size(); ++i) { |
539 const AutocompleteMatch& match = result.match_at(i); | 558 const AutocompleteMatch& match = result.match_at(i); |
540 AutocompleteMatch::Type type = match.type; | 559 AutocompleteMatch::Type type = match.type; |
541 if (type != AutocompleteMatch::HISTORY_URL && | 560 if (type != AutocompleteMatch::HISTORY_URL && |
542 type != AutocompleteMatch::HISTORY_TITLE && | 561 type != AutocompleteMatch::HISTORY_TITLE && |
543 type != AutocompleteMatch::HISTORY_BODY && | 562 type != AutocompleteMatch::HISTORY_BODY && |
544 type != AutocompleteMatch::HISTORY_KEYWORD && | 563 type != AutocompleteMatch::HISTORY_KEYWORD && |
545 type != AutocompleteMatch::NAVSUGGEST) | 564 type != AutocompleteMatch::NAVSUGGEST) |
546 continue; | 565 continue; |
547 DictionaryValue* entry = new DictionaryValue(); | 566 DictionaryValue* entry = new DictionaryValue(); |
548 entry->SetString("title", match.description); | 567 entry->SetString("title", match.description); |
549 entry->SetString("displayURL", match.contents); | 568 entry->SetString("displayURL", match.contents); |
550 entry->SetString("url", match.destination_url.spec()); | 569 entry->SetString("url", match.destination_url.spec()); |
551 suggestions.Append(entry); | 570 suggestions.Append(entry); |
552 } | 571 } |
553 | 572 |
554 web_ui_->CallJavascriptFunction( | 573 web_ui_->CallJavascriptFunction( |
555 "BrowserOptions.updateAutocompleteSuggestions", suggestions); | 574 "BrowserOptions.updateAutocompleteSuggestions", suggestions); |
556 } | 575 } |
OLD | NEW |