| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/autocomplete/extension_app_provider.h" | 5 #include "chrome/browser/autocomplete/extension_app_provider.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 | 9 |
| 10 #include "base/string16.h" | 10 #include "base/string16.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/extensions/extension_system_factory.h" | 13 #include "chrome/browser/extensions/extension_system_factory.h" |
| 14 #include "chrome/browser/history/history.h" | 14 #include "chrome/browser/history/history.h" |
| 15 #include "chrome/browser/history/history_service_factory.h" | 15 #include "chrome/browser/history/history_service_factory.h" |
| 16 #include "chrome/browser/history/url_database.h" | 16 #include "chrome/browser/history/url_database.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/extensions/application_launch.h" | 18 #include "chrome/browser/ui/extensions/application_launch.h" |
| 19 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" | 19 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h" |
| 20 #include "chrome/common/chrome_notification_types.h" | 20 #include "chrome/common/chrome_notification_types.h" |
| 21 #include "chrome/common/extensions/extension.h" | 21 #include "chrome/common/extensions/extension.h" |
| 22 #include "content/public/browser/notification_source.h" | 22 #include "content/public/browser/notification_source.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 24 | 24 |
| 25 ExtensionAppProvider::ExtensionAppProvider( | 25 ExtensionAppProvider::ExtensionAppProvider( |
| 26 AutocompleteProviderListener* listener, | 26 AutocompleteProviderListener* listener, |
| 27 Profile* profile) | 27 Profile* profile) |
| 28 : AutocompleteProvider(listener, profile, "ExtensionApps") { | 28 : AutocompleteProvider(listener, profile, |
| 29 AutocompleteProvider::TYPE_EXTENSION_APP) { |
| 29 // Notifications of extensions loading and unloading always come from the | 30 // Notifications of extensions loading and unloading always come from the |
| 30 // non-incognito profile, but we need to see them regardless, as the incognito | 31 // non-incognito profile, but we need to see them regardless, as the incognito |
| 31 // windows can be affected. | 32 // windows can be affected. |
| 32 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, | 33 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, |
| 33 content::Source<Profile>(profile_->GetOriginalProfile())); | 34 content::Source<Profile>(profile_->GetOriginalProfile())); |
| 34 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, | 35 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, |
| 35 content::Source<Profile>(profile_->GetOriginalProfile())); | 36 content::Source<Profile>(profile_->GetOriginalProfile())); |
| 36 RefreshAppList(); | 37 RefreshAppList(); |
| 37 } | 38 } |
| 38 | 39 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 extension_apps_.push_back(extension_app); | 71 extension_apps_.push_back(extension_app); |
| 71 } | 72 } |
| 72 | 73 |
| 73 AutocompleteMatch ExtensionAppProvider::CreateAutocompleteMatch( | 74 AutocompleteMatch ExtensionAppProvider::CreateAutocompleteMatch( |
| 74 const AutocompleteInput& input, | 75 const AutocompleteInput& input, |
| 75 const ExtensionApp& app, | 76 const ExtensionApp& app, |
| 76 size_t name_match_index, | 77 size_t name_match_index, |
| 77 size_t url_match_index) { | 78 size_t url_match_index) { |
| 78 // TODO(finnur): Figure out what type to return here, might want to have | 79 // TODO(finnur): Figure out what type to return here, might want to have |
| 79 // the extension icon/a generic icon show up in the Omnibox. | 80 // the extension icon/a generic icon show up in the Omnibox. |
| 80 AutocompleteMatch match(this, 0, false, | 81 AutocompleteMatch match(this, 0, false, AutocompleteMatch::EXTENSION_APP); |
| 81 AutocompleteMatch::EXTENSION_APP); | |
| 82 match.fill_into_edit = | 82 match.fill_into_edit = |
| 83 app.should_match_against_launch_url ? app.launch_url : input.text(); | 83 app.should_match_against_launch_url ? app.launch_url : input.text(); |
| 84 match.destination_url = GURL(app.launch_url); | 84 match.destination_url = GURL(app.launch_url); |
| 85 match.inline_autocomplete_offset = string16::npos; | 85 match.inline_autocomplete_offset = string16::npos; |
| 86 match.contents = AutocompleteMatch::SanitizeString(app.name); | 86 match.contents = AutocompleteMatch::SanitizeString(app.name); |
| 87 AutocompleteMatch::ClassifyLocationInString(name_match_index, | 87 AutocompleteMatch::ClassifyLocationInString(name_match_index, |
| 88 input.text().length(), app.name.length(), ACMatchClassification::NONE, | 88 input.text().length(), app.name.length(), ACMatchClassification::NONE, |
| 89 &match.contents_class); | 89 &match.contents_class); |
| 90 if (app.should_match_against_launch_url) { | 90 if (app.should_match_against_launch_url) { |
| 91 match.description = app.launch_url; | 91 match.description = app.launch_url; |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 history::URLRow info; | 217 history::URLRow info; |
| 218 url_db->GetRowForURL(url, &info); | 218 url_db->GetRowForURL(url, &info); |
| 219 type_count_boost = | 219 type_count_boost = |
| 220 400 * (1.0 - (std::pow(static_cast<double>(2), -info.typed_count()))); | 220 400 * (1.0 - (std::pow(static_cast<double>(2), -info.typed_count()))); |
| 221 } | 221 } |
| 222 int relevance = 575 + static_cast<int>(type_count_boost) + | 222 int relevance = 575 + static_cast<int>(type_count_boost) + |
| 223 static_cast<int>(fraction_boost); | 223 static_cast<int>(fraction_boost); |
| 224 DCHECK_LE(relevance, kMaxRelevance); | 224 DCHECK_LE(relevance, kMaxRelevance); |
| 225 return relevance; | 225 return relevance; |
| 226 } | 226 } |
| OLD | NEW |