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/net/url_fixer_upper.h" | 18 #include "chrome/browser/net/url_fixer_upper.h" |
19 #include "chrome/browser/platform_util.h" | 19 #include "chrome/browser/platform_util.h" |
20 #include "chrome/browser/prefs/pref_service.h" | 20 #include "chrome/browser/prefs/pref_service.h" |
21 #include "chrome/browser/prefs/session_startup_pref.h" | 21 #include "chrome/browser/prefs/session_startup_pref.h" |
22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/search_engines/template_url.h" | 23 #include "chrome/browser/search_engines/template_url.h" |
24 #include "chrome/browser/search_engines/template_url_service.h" | 24 #include "chrome/browser/search_engines/template_url_service.h" |
25 #include "chrome/browser/search_engines/template_url_service_factory.h" | 25 #include "chrome/browser/search_engines/template_url_service_factory.h" |
26 #include "chrome/browser/ui/webui/favicon_source.h" | 26 #include "chrome/browser/ui/webui/favicon_source.h" |
27 #include "chrome/browser/ui/webui/options/options_managed_banner_handler.h" | 27 #include "chrome/browser/ui/webui/options/options_managed_banner_handler.h" |
| 28 #include "chrome/common/chrome_notification_types.h" |
28 #include "chrome/common/pref_names.h" | 29 #include "chrome/common/pref_names.h" |
29 #include "chrome/common/url_constants.h" | 30 #include "chrome/common/url_constants.h" |
30 #include "content/browser/browser_thread.h" | 31 #include "content/browser/browser_thread.h" |
31 #include "content/browser/user_metrics.h" | 32 #include "content/browser/user_metrics.h" |
32 #include "content/common/notification_service.h" | 33 #include "content/common/notification_service.h" |
33 #include "content/common/notification_source.h" | 34 #include "content/common/notification_source.h" |
34 #include "content/common/notification_type.h" | |
35 #include "grit/chromium_strings.h" | 35 #include "grit/chromium_strings.h" |
36 #include "grit/generated_resources.h" | 36 #include "grit/generated_resources.h" |
37 #include "ui/base/l10n/l10n_util.h" | 37 #include "ui/base/l10n/l10n_util.h" |
38 | 38 |
39 BrowserOptionsHandler::BrowserOptionsHandler() | 39 BrowserOptionsHandler::BrowserOptionsHandler() |
40 : template_url_service_(NULL), startup_custom_pages_table_model_(NULL) { | 40 : template_url_service_(NULL), startup_custom_pages_table_model_(NULL) { |
41 #if !defined(OS_MACOSX) | 41 #if !defined(OS_MACOSX) |
42 default_browser_worker_ = new ShellIntegration::DefaultBrowserWorker(this); | 42 default_browser_worker_ = new ShellIntegration::DefaultBrowserWorker(this); |
43 #endif | 43 #endif |
44 } | 44 } |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 } | 341 } |
342 | 342 |
343 void BrowserOptionsHandler::OnItemsAdded(int start, int length) { | 343 void BrowserOptionsHandler::OnItemsAdded(int start, int length) { |
344 OnModelChanged(); | 344 OnModelChanged(); |
345 } | 345 } |
346 | 346 |
347 void BrowserOptionsHandler::OnItemsRemoved(int start, int length) { | 347 void BrowserOptionsHandler::OnItemsRemoved(int start, int length) { |
348 OnModelChanged(); | 348 OnModelChanged(); |
349 } | 349 } |
350 | 350 |
351 void BrowserOptionsHandler::Observe(NotificationType type, | 351 void BrowserOptionsHandler::Observe(int type, |
352 const NotificationSource& source, | 352 const NotificationSource& source, |
353 const NotificationDetails& details) { | 353 const NotificationDetails& details) { |
354 UpdateDefaultBrowserState(); | 354 UpdateDefaultBrowserState(); |
355 } | 355 } |
356 | 356 |
357 void BrowserOptionsHandler::SetStartupPagesToCurrentPages( | 357 void BrowserOptionsHandler::SetStartupPagesToCurrentPages( |
358 const ListValue* args) { | 358 const ListValue* args) { |
359 startup_custom_pages_table_model_->SetToCurrentlyOpenPages(); | 359 startup_custom_pages_table_model_->SetToCurrentlyOpenPages(); |
360 SaveStartupPagesPref(); | 360 SaveStartupPagesPref(); |
361 } | 361 } |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 CHECK_EQ(args->GetSize(), 1U); | 447 CHECK_EQ(args->GetSize(), 1U); |
448 CHECK(args->GetString(0, &input)); | 448 CHECK(args->GetString(0, &input)); |
449 | 449 |
450 autocomplete_controller_->Start(input, string16(), true, false, false, | 450 autocomplete_controller_->Start(input, string16(), true, false, false, |
451 AutocompleteInput::ALL_MATCHES); | 451 AutocompleteInput::ALL_MATCHES); |
452 } | 452 } |
453 | 453 |
454 void BrowserOptionsHandler::ToggleShowBookmarksBar(const ListValue* args) { | 454 void BrowserOptionsHandler::ToggleShowBookmarksBar(const ListValue* args) { |
455 Source<Profile> source(web_ui_->GetProfile()); | 455 Source<Profile> source(web_ui_->GetProfile()); |
456 NotificationService::current()->Notify( | 456 NotificationService::current()->Notify( |
457 NotificationType::BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, | 457 chrome::NOTIFICATION_BOOKMARK_BAR_VISIBILITY_PREF_CHANGED, |
458 source, | 458 source, |
459 NotificationService::NoDetails()); | 459 NotificationService::NoDetails()); |
460 } | 460 } |
461 | 461 |
462 void BrowserOptionsHandler::OnResultChanged(bool default_match_changed) { | 462 void BrowserOptionsHandler::OnResultChanged(bool default_match_changed) { |
463 const AutocompleteResult& result = autocomplete_controller_->result(); | 463 const AutocompleteResult& result = autocomplete_controller_->result(); |
464 ListValue suggestions; | 464 ListValue suggestions; |
465 for (size_t i = 0; i < result.size(); ++i) { | 465 for (size_t i = 0; i < result.size(); ++i) { |
466 const AutocompleteMatch& match = result.match_at(i); | 466 const AutocompleteMatch& match = result.match_at(i); |
467 AutocompleteMatch::Type type = match.type; | 467 AutocompleteMatch::Type type = match.type; |
468 if (type != AutocompleteMatch::HISTORY_URL && | 468 if (type != AutocompleteMatch::HISTORY_URL && |
469 type != AutocompleteMatch::HISTORY_TITLE && | 469 type != AutocompleteMatch::HISTORY_TITLE && |
470 type != AutocompleteMatch::HISTORY_BODY && | 470 type != AutocompleteMatch::HISTORY_BODY && |
471 type != AutocompleteMatch::HISTORY_KEYWORD && | 471 type != AutocompleteMatch::HISTORY_KEYWORD && |
472 type != AutocompleteMatch::NAVSUGGEST) | 472 type != AutocompleteMatch::NAVSUGGEST) |
473 continue; | 473 continue; |
474 DictionaryValue* entry = new DictionaryValue(); | 474 DictionaryValue* entry = new DictionaryValue(); |
475 entry->SetString("title", match.description); | 475 entry->SetString("title", match.description); |
476 entry->SetString("displayURL", match.contents); | 476 entry->SetString("displayURL", match.contents); |
477 entry->SetString("url", match.destination_url.spec()); | 477 entry->SetString("url", match.destination_url.spec()); |
478 suggestions.Append(entry); | 478 suggestions.Append(entry); |
479 } | 479 } |
480 | 480 |
481 web_ui_->CallJavascriptFunction( | 481 web_ui_->CallJavascriptFunction( |
482 "BrowserOptions.updateAutocompleteSuggestions", suggestions); | 482 "BrowserOptions.updateAutocompleteSuggestions", suggestions); |
483 } | 483 } |
OLD | NEW |