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" | 18 #include "chrome/browser/instant/instant_controller.h" |
| 19 #include "chrome/browser/instant/instant_field_trial.h" |
19 #include "chrome/browser/net/url_fixer_upper.h" | 20 #include "chrome/browser/net/url_fixer_upper.h" |
20 #include "chrome/browser/prefs/pref_service.h" | 21 #include "chrome/browser/prefs/pref_service.h" |
21 #include "chrome/browser/prefs/session_startup_pref.h" | 22 #include "chrome/browser/prefs/session_startup_pref.h" |
22 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/search_engines/template_url.h" | 24 #include "chrome/browser/search_engines/template_url.h" |
24 #include "chrome/browser/search_engines/template_url_service.h" | 25 #include "chrome/browser/search_engines/template_url_service.h" |
25 #include "chrome/browser/search_engines/template_url_service_factory.h" | 26 #include "chrome/browser/search_engines/template_url_service_factory.h" |
26 #include "chrome/browser/ui/webui/favicon_source.h" | 27 #include "chrome/browser/ui/webui/favicon_source.h" |
27 #include "chrome/common/chrome_notification_types.h" | 28 #include "chrome/common/chrome_notification_types.h" |
28 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 &BrowserOptionsHandler::RequestAutocompleteSuggestions)); | 123 &BrowserOptionsHandler::RequestAutocompleteSuggestions)); |
123 web_ui_->RegisterMessageCallback( | 124 web_ui_->RegisterMessageCallback( |
124 "toggleShowBookmarksBar", | 125 "toggleShowBookmarksBar", |
125 NewCallback(this, &BrowserOptionsHandler::ToggleShowBookmarksBar)); | 126 NewCallback(this, &BrowserOptionsHandler::ToggleShowBookmarksBar)); |
126 web_ui_->RegisterMessageCallback( | 127 web_ui_->RegisterMessageCallback( |
127 "enableInstant", | 128 "enableInstant", |
128 NewCallback(this, &BrowserOptionsHandler::EnableInstant)); | 129 NewCallback(this, &BrowserOptionsHandler::EnableInstant)); |
129 web_ui_->RegisterMessageCallback( | 130 web_ui_->RegisterMessageCallback( |
130 "disableInstant", | 131 "disableInstant", |
131 NewCallback(this, &BrowserOptionsHandler::DisableInstant)); | 132 NewCallback(this, &BrowserOptionsHandler::DisableInstant)); |
| 133 web_ui_->RegisterMessageCallback( |
| 134 "getInstantFieldTrialStatus", |
| 135 NewCallback(this, &BrowserOptionsHandler::GetInstantFieldTrialStatus)); |
132 } | 136 } |
133 | 137 |
134 void BrowserOptionsHandler::Initialize() { | 138 void BrowserOptionsHandler::Initialize() { |
135 Profile* profile = web_ui_->GetProfile(); | 139 Profile* profile = web_ui_->GetProfile(); |
136 | 140 |
137 // Create our favicon data source. | 141 // Create our favicon data source. |
138 profile->GetChromeURLDataManager()->AddDataSource( | 142 profile->GetChromeURLDataManager()->AddDataSource( |
139 new FaviconSource(profile, FaviconSource::FAVICON)); | 143 new FaviconSource(profile, FaviconSource::FAVICON)); |
140 | 144 |
141 homepage_.Init(prefs::kHomePage, profile->GetPrefs(), NULL); | 145 homepage_.Init(prefs::kHomePage, profile->GetPrefs(), NULL); |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 } | 481 } |
478 | 482 |
479 void BrowserOptionsHandler::EnableInstant(const ListValue* args) { | 483 void BrowserOptionsHandler::EnableInstant(const ListValue* args) { |
480 InstantController::Enable(web_ui_->GetProfile()); | 484 InstantController::Enable(web_ui_->GetProfile()); |
481 } | 485 } |
482 | 486 |
483 void BrowserOptionsHandler::DisableInstant(const ListValue* args) { | 487 void BrowserOptionsHandler::DisableInstant(const ListValue* args) { |
484 InstantController::Disable(web_ui_->GetProfile()); | 488 InstantController::Disable(web_ui_->GetProfile()); |
485 } | 489 } |
486 | 490 |
| 491 void BrowserOptionsHandler::GetInstantFieldTrialStatus(const ListValue* args) { |
| 492 FundamentalValue enabled( |
| 493 InstantFieldTrial::IsExperimentGroup(web_ui_->GetProfile())); |
| 494 web_ui_->CallJavascriptFunction("BrowserOptions.setInstantFieldTrialStatus", |
| 495 enabled); |
| 496 } |
| 497 |
487 void BrowserOptionsHandler::OnResultChanged(bool default_match_changed) { | 498 void BrowserOptionsHandler::OnResultChanged(bool default_match_changed) { |
488 const AutocompleteResult& result = autocomplete_controller_->result(); | 499 const AutocompleteResult& result = autocomplete_controller_->result(); |
489 ListValue suggestions; | 500 ListValue suggestions; |
490 for (size_t i = 0; i < result.size(); ++i) { | 501 for (size_t i = 0; i < result.size(); ++i) { |
491 const AutocompleteMatch& match = result.match_at(i); | 502 const AutocompleteMatch& match = result.match_at(i); |
492 AutocompleteMatch::Type type = match.type; | 503 AutocompleteMatch::Type type = match.type; |
493 if (type != AutocompleteMatch::HISTORY_URL && | 504 if (type != AutocompleteMatch::HISTORY_URL && |
494 type != AutocompleteMatch::HISTORY_TITLE && | 505 type != AutocompleteMatch::HISTORY_TITLE && |
495 type != AutocompleteMatch::HISTORY_BODY && | 506 type != AutocompleteMatch::HISTORY_BODY && |
496 type != AutocompleteMatch::HISTORY_KEYWORD && | 507 type != AutocompleteMatch::HISTORY_KEYWORD && |
497 type != AutocompleteMatch::NAVSUGGEST) | 508 type != AutocompleteMatch::NAVSUGGEST) |
498 continue; | 509 continue; |
499 DictionaryValue* entry = new DictionaryValue(); | 510 DictionaryValue* entry = new DictionaryValue(); |
500 entry->SetString("title", match.description); | 511 entry->SetString("title", match.description); |
501 entry->SetString("displayURL", match.contents); | 512 entry->SetString("displayURL", match.contents); |
502 entry->SetString("url", match.destination_url.spec()); | 513 entry->SetString("url", match.destination_url.spec()); |
503 suggestions.Append(entry); | 514 suggestions.Append(entry); |
504 } | 515 } |
505 | 516 |
506 web_ui_->CallJavascriptFunction( | 517 web_ui_->CallJavascriptFunction( |
507 "BrowserOptions.updateAutocompleteSuggestions", suggestions); | 518 "BrowserOptions.updateAutocompleteSuggestions", suggestions); |
508 } | 519 } |
OLD | NEW |