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