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" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
12 #include "base/values.h" | 12 #include "base/values.h" |
13 #include "chrome/browser/autocomplete/autocomplete.h" | 13 #include "chrome/browser/autocomplete/autocomplete.h" |
14 #include "chrome/browser/autocomplete/autocomplete_match.h" | 14 #include "chrome/browser/autocomplete/autocomplete_match.h" |
15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
16 #include "chrome/browser/custom_home_pages_table_model.h" | 16 #include "chrome/browser/custom_home_pages_table_model.h" |
17 #include "chrome/browser/instant/instant_confirm_dialog.h" | 17 #include "chrome/browser/instant/instant_confirm_dialog.h" |
| 18 #include "chrome/browser/instant/instant_controller.h" |
| 19 #include "chrome/browser/instant/instant_field_trial.h" |
18 #include "chrome/browser/net/url_fixer_upper.h" | 20 #include "chrome/browser/net/url_fixer_upper.h" |
19 #include "chrome/browser/prefs/pref_service.h" | 21 #include "chrome/browser/prefs/pref_service.h" |
20 #include "chrome/browser/prefs/session_startup_pref.h" | 22 #include "chrome/browser/prefs/session_startup_pref.h" |
21 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/browser/search_engines/template_url.h" | 24 #include "chrome/browser/search_engines/template_url.h" |
23 #include "chrome/browser/search_engines/template_url_service.h" | 25 #include "chrome/browser/search_engines/template_url_service.h" |
24 #include "chrome/browser/search_engines/template_url_service_factory.h" | 26 #include "chrome/browser/search_engines/template_url_service_factory.h" |
25 #include "chrome/browser/ui/webui/favicon_source.h" | 27 #include "chrome/browser/ui/webui/favicon_source.h" |
26 #include "chrome/common/chrome_notification_types.h" | 28 #include "chrome/common/chrome_notification_types.h" |
27 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 web_ui_->RegisterMessageCallback( | 117 web_ui_->RegisterMessageCallback( |
116 "dragDropStartupPage", | 118 "dragDropStartupPage", |
117 NewCallback(this, &BrowserOptionsHandler::DragDropStartupPage)); | 119 NewCallback(this, &BrowserOptionsHandler::DragDropStartupPage)); |
118 web_ui_->RegisterMessageCallback( | 120 web_ui_->RegisterMessageCallback( |
119 "requestAutocompleteSuggestions", | 121 "requestAutocompleteSuggestions", |
120 NewCallback(this, | 122 NewCallback(this, |
121 &BrowserOptionsHandler::RequestAutocompleteSuggestions)); | 123 &BrowserOptionsHandler::RequestAutocompleteSuggestions)); |
122 web_ui_->RegisterMessageCallback( | 124 web_ui_->RegisterMessageCallback( |
123 "toggleShowBookmarksBar", | 125 "toggleShowBookmarksBar", |
124 NewCallback(this, &BrowserOptionsHandler::ToggleShowBookmarksBar)); | 126 NewCallback(this, &BrowserOptionsHandler::ToggleShowBookmarksBar)); |
| 127 web_ui_->RegisterMessageCallback( |
| 128 "enableInstant", |
| 129 NewCallback(this, &BrowserOptionsHandler::EnableInstant)); |
| 130 web_ui_->RegisterMessageCallback( |
| 131 "disableInstant", |
| 132 NewCallback(this, &BrowserOptionsHandler::DisableInstant)); |
| 133 web_ui_->RegisterMessageCallback( |
| 134 "isInstantFieldTrialExperimentGroup", |
| 135 NewCallback(this, |
| 136 &BrowserOptionsHandler::IsInstantFieldTrialExperimentGroup)); |
125 } | 137 } |
126 | 138 |
127 void BrowserOptionsHandler::Initialize() { | 139 void BrowserOptionsHandler::Initialize() { |
128 Profile* profile = web_ui_->GetProfile(); | 140 Profile* profile = web_ui_->GetProfile(); |
129 | 141 |
130 // Create our favicon data source. | 142 // Create our favicon data source. |
131 profile->GetChromeURLDataManager()->AddDataSource( | 143 profile->GetChromeURLDataManager()->AddDataSource( |
132 new FaviconSource(profile, FaviconSource::FAVICON)); | 144 new FaviconSource(profile, FaviconSource::FAVICON)); |
133 | 145 |
134 homepage_.Init(prefs::kHomePage, profile->GetPrefs(), NULL); | 146 homepage_.Init(prefs::kHomePage, profile->GetPrefs(), NULL); |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 } | 474 } |
463 | 475 |
464 void BrowserOptionsHandler::ToggleShowBookmarksBar(const ListValue* args) { | 476 void BrowserOptionsHandler::ToggleShowBookmarksBar(const ListValue* args) { |
465 Source<Profile> source(web_ui_->GetProfile()); | 477 Source<Profile> source(web_ui_->GetProfile()); |
466 NotificationService::current()->Notify( | 478 NotificationService::current()->Notify( |
467 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, | 479 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, |
468 source, | 480 source, |
469 NotificationService::NoDetails()); | 481 NotificationService::NoDetails()); |
470 } | 482 } |
471 | 483 |
| 484 void BrowserOptionsHandler::EnableInstant(const ListValue* args) { |
| 485 InstantController::Enable(web_ui_->GetProfile()); |
| 486 } |
| 487 |
| 488 void BrowserOptionsHandler::DisableInstant(const ListValue* args) { |
| 489 InstantController::Disable(web_ui_->GetProfile()); |
| 490 } |
| 491 |
| 492 void BrowserOptionsHandler::IsInstantFieldTrialExperimentGroup( |
| 493 const ListValue* args) { |
| 494 if (InstantFieldTrial::IsExperimentGroup(web_ui_->GetProfile())) { |
| 495 web_ui_->CallJavascriptFunction( |
| 496 "BrowserOptions.setInstantFieldTrialExperimentGroup"); |
| 497 } |
| 498 } |
| 499 |
472 void BrowserOptionsHandler::OnResultChanged(bool default_match_changed) { | 500 void BrowserOptionsHandler::OnResultChanged(bool default_match_changed) { |
473 const AutocompleteResult& result = autocomplete_controller_->result(); | 501 const AutocompleteResult& result = autocomplete_controller_->result(); |
474 ListValue suggestions; | 502 ListValue suggestions; |
475 for (size_t i = 0; i < result.size(); ++i) { | 503 for (size_t i = 0; i < result.size(); ++i) { |
476 const AutocompleteMatch& match = result.match_at(i); | 504 const AutocompleteMatch& match = result.match_at(i); |
477 AutocompleteMatch::Type type = match.type; | 505 AutocompleteMatch::Type type = match.type; |
478 if (type != AutocompleteMatch::HISTORY_URL && | 506 if (type != AutocompleteMatch::HISTORY_URL && |
479 type != AutocompleteMatch::HISTORY_TITLE && | 507 type != AutocompleteMatch::HISTORY_TITLE && |
480 type != AutocompleteMatch::HISTORY_BODY && | 508 type != AutocompleteMatch::HISTORY_BODY && |
481 type != AutocompleteMatch::HISTORY_KEYWORD && | 509 type != AutocompleteMatch::HISTORY_KEYWORD && |
482 type != AutocompleteMatch::NAVSUGGEST) | 510 type != AutocompleteMatch::NAVSUGGEST) |
483 continue; | 511 continue; |
484 DictionaryValue* entry = new DictionaryValue(); | 512 DictionaryValue* entry = new DictionaryValue(); |
485 entry->SetString("title", match.description); | 513 entry->SetString("title", match.description); |
486 entry->SetString("displayURL", match.contents); | 514 entry->SetString("displayURL", match.contents); |
487 entry->SetString("url", match.destination_url.spec()); | 515 entry->SetString("url", match.destination_url.spec()); |
488 suggestions.Append(entry); | 516 suggestions.Append(entry); |
489 } | 517 } |
490 | 518 |
491 web_ui_->CallJavascriptFunction( | 519 web_ui_->CallJavascriptFunction( |
492 "BrowserOptions.updateAutocompleteSuggestions", suggestions); | 520 "BrowserOptions.updateAutocompleteSuggestions", suggestions); |
493 } | 521 } |
OLD | NEW |