Chromium Code Reviews| Index: chrome/browser/autocomplete/extension_app_provider.cc |
| =================================================================== |
| --- chrome/browser/autocomplete/extension_app_provider.cc (revision 0) |
| +++ chrome/browser/autocomplete/extension_app_provider.cc (revision 0) |
| @@ -0,0 +1,163 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/autocomplete/extension_app_provider.h" |
| + |
| +#include <algorithm> |
| + |
| +#include "base/string16.h" |
| +#include "base/utf_string_conversions.h" |
| +#include "chrome/browser/autocomplete/autocomplete_match.h" |
| +#include "chrome/browser/extensions/extension_service.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "content/common/notification_service.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| + |
| +ExtensionAppProvider::ExtensionAppProvider(ACProviderListener* listener, |
| + Profile* profile) |
| + : AutocompleteProvider(listener, profile, "ExtensionApps") { |
| + RefreshAppList(); |
| + RegisterForNotifications(); |
|
mrossetti
2011/03/31 16:44:17
I don't know — I'm just askin': Is it possible for
Finnur
2011/04/01 15:49:36
I don't think so, but I also think that reversing
|
| +} |
| + |
| +ExtensionAppProvider::ExtensionAppProvider(ACProviderListener* listener, |
|
Peter Kasting
2011/03/31 21:33:59
Will you really be using this? A TemplateURLModel
Finnur
2011/04/01 15:49:36
Done.
|
| + TemplateURLModel* model) |
| + : AutocompleteProvider(listener, NULL, "ExtensionApps") { |
| + RefreshAppList(); |
| + RegisterForNotifications(); |
| +} |
| + |
| +void ExtensionAppProvider::Start(const AutocompleteInput& input, |
| + bool minimal_changes) { |
| + matches_.clear(); |
| + |
| + if (!input.text().empty()) { |
|
Peter Kasting
2011/03/31 21:33:59
Your changes to autocomplete.h claimed you only ac
Finnur
2011/04/01 15:49:36
Done.
|
| + std::string input_utf8 = WideToUTF8(input.text()); |
| + for (std::vector<ExtensionApp>::const_iterator app = |
| + extension_apps_.begin(); |
| + app != extension_apps_.end(); ++app) { |
| + // See if the input matches this extension application. |
| + const std::string& name = (*app).first; |
|
mrossetti
2011/03/31 16:44:17
Nit: "(*app)." ==> "app->", here and the next line
Finnur
2011/04/01 15:49:36
Doh! Done.
On 2011/03/31 16:44:17, mrossetti wrot
|
| + const std::string& url = (*app).second; |
| + std::string::const_iterator name_iter = |
| + std::search(name.begin(), |
| + name.end(), |
| + input_utf8.begin(), |
| + input_utf8.end(), |
| + base::CaseInsensitiveCompare<char>()); |
| + std::string::const_iterator url_iter = |
| + std::search(url.begin(), |
| + url.end(), |
| + input_utf8.begin(), |
| + input_utf8.end(), |
| + base::CaseInsensitiveCompare<char>()); |
| + |
| + bool matches_name = name_iter != name.end(); |
| + bool matches_url = url_iter != url.end(); |
|
mrossetti
2011/03/31 16:44:17
Nit: No need for this 'matches_url' temporary. Jus
Finnur
2011/04/01 15:49:36
I think it improves readability. |matches_name| is
|
| + if (matches_name || matches_url) { |
| + bool complete_match = input.text().length() == name.length(); |
| + // We have a match, might be a partial match. |
| + // TODO(finnur): Figure out what type to return here, might want to have |
| + // the extension icon/a generic icon show up in the Omnibox. |
| + AutocompleteMatch match(this, 0, false, AutocompleteMatch::HISTORY_URL); |
|
mrossetti
2011/03/31 16:44:17
Yeah, I'd think we'd want an app type icon at a mi
Finnur
2011/04/01 15:49:36
Yeah, I'm on the this-is-an-app visual clue side.
|
| + match.fill_into_edit = input.text(); |
|
Peter Kasting
2011/03/31 21:33:59
No, you want the string that someone should see wh
Finnur
2011/04/01 15:49:36
Good point.
On 2011/03/31 21:33:59, Peter Kasting
|
| + match.destination_url = GURL(url); |
| + match.inline_autocomplete_offset = string16::npos; |
| + /* Will add this to the generated_resources.grd (currently has a bunch |
| + of other changes in my tree from another CL): |
| + <!-- Extension App Provider strings --> |
| + <message name="IDS_EXTENSION_APP_LAUNCH_PREFIX" |
| + desc="App launcher prefix for the Omnibox."> |
| + Launch |
|
Peter Kasting
2011/03/31 21:33:59
You need to use "Launch $1", not just give a prefi
Finnur
2011/04/01 15:49:36
I opted to remove this string. It wasn't part of t
|
| + </message> |
| + */ |
| + string16 prefix = ASCIIToWide("Launch "); |
| + match.contents = prefix + UTF8ToWide(name); |
| + match.contents_class.push_back( |
| + ACMatchClassification(0, ACMatchClassification::DIM)); |
| + if (name_iter != name.end()) { |
| + size_t pos = name_iter - name.begin(); |
| + match.contents_class.push_back( |
| + ACMatchClassification(prefix.length() + pos, |
| + ACMatchClassification::MATCH)); |
| + if (pos + input.text().length() < name.length()) |
| + match.contents_class.push_back( |
| + ACMatchClassification(prefix.length() + pos + |
| + input.text().length(), |
| + ACMatchClassification::DIM)); |
| + } |
| + |
| + match.description = UTF8ToWide(url); |
| + match.description_class.push_back( |
| + ACMatchClassification(0, ACMatchClassification::DIM)); |
| + if (url_iter != url.end()) { |
| + size_t pos = url_iter - url.begin(); |
| + match.description_class.push_back( |
| + ACMatchClassification(pos, ACMatchClassification::MATCH)); |
| + if (pos + input.text().length() < url.length()) |
| + match.description_class.push_back( |
| + ACMatchClassification(pos + input.text().length(), |
| + ACMatchClassification::DIM)); |
| + } |
| + |
| + match.relevance = CalculateRelevance(input.type(), |
| + complete_match, |
| + matches_name); |
| + matches_.push_back(match); |
| + } |
| + } |
| + } |
| + |
| + done_ = true; |
|
Peter Kasting
2011/03/31 21:33:59
Nit: You don't need this.
Finnur
2011/04/01 15:49:36
Done.
|
| +} |
| + |
| +void ExtensionAppProvider::Stop() { |
|
Peter Kasting
2011/03/31 21:33:59
Nit: You don't need to override this.
Finnur
2011/04/01 15:49:36
Done.
|
| + done_ = true; |
| +} |
| + |
| +ExtensionAppProvider::~ExtensionAppProvider() { |
| +} |
| + |
| +void ExtensionAppProvider::RefreshAppList() { |
| + ExtensionService* extensions_service = profile_->GetExtensionService(); |
|
Peter Kasting
2011/03/31 21:33:59
Nit: Roll this into the next statement.
Finnur
2011/04/01 15:49:36
Done.
|
| + const ExtensionList* extensions = extensions_service->extensions(); |
| + |
| + extension_apps_.clear(); |
|
Peter Kasting
2011/03/31 21:33:59
Nit: No blank lines above/below this.
Finnur
2011/04/01 15:49:36
Done.
|
| + |
| + for (ExtensionList::const_iterator app = extensions->begin(); |
| + app != extensions->end(); ++app) { |
| + if (!(*app)->is_app() || (*app)->launch_web_url().empty()) |
|
Peter Kasting
2011/03/31 21:33:59
Nit: Reverse the conditional and do the push_back(
Finnur
2011/04/01 15:49:36
Done.
|
| + continue; |
| + |
| + extension_apps_.push_back(std::make_pair((*app)->name(), |
| + (*app)->launch_web_url())); |
|
Peter Kasting
2011/03/31 21:33:59
What if this is a relative URL?
Finnur
2011/04/01 15:49:36
That is never supposed to happen and we'd have pro
Peter Kasting
2011/04/01 16:32:10
Huh. Maybe I misread the comments on its declarat
Finnur
2011/04/01 18:10:40
Um... Sure. I can do that in a followup changelist
|
| + } |
| +} |
| + |
| +void ExtensionAppProvider::RegisterForNotifications() { |
| + registrar_.Add(this, NotificationType::EXTENSION_LOADED, |
| + NotificationService::AllSources()); |
| + registrar_.Add(this, NotificationType::EXTENSION_UNINSTALLED, |
| + NotificationService::AllSources()); |
| +} |
| + |
| + |
| +// static |
| +int ExtensionAppProvider::CalculateRelevance(AutocompleteInput::Type type, |
|
mrossetti
2011/03/31 16:44:17
Driveby: I'd probably put CalculateRelevance at th
Finnur
2011/04/01 15:49:36
Done.
|
| + bool complete, |
| + bool matches_name) { |
| + // TODO(finnur): Need to figure out what to return here. |
|
Peter Kasting
2011/03/31 21:33:59
You definitely shouldn't return the exact value an
|
| + return 1200; |
|
mrossetti
2011/03/31 16:44:17
Driveby: Yeah, a value based at least on 1) how fa
Finnur
2011/04/01 15:49:36
I opted for a simple sliding scale of 850 to 1450
Peter Kasting
2011/04/01 16:32:10
Be careful. 1450 is above history exact match/inl
Finnur
2011/04/01 18:10:40
My thinking was that the likelyhood of you install
Finnur
2011/04/01 20:29:10
Yes? No? We are nearing the deadline for M12 featu
|
| +} |
|
Finnur
2011/03/31 22:25:20
Thank you both for your comments...
It is late, a
|
| + |
| +void ExtensionAppProvider::Observe(NotificationType type, |
| + const NotificationSource& source, |
| + const NotificationDetails& details) { |
| + switch (type.value) { |
| + case NotificationType::EXTENSION_LOADED: |
| + case NotificationType::EXTENSION_UNINSTALLED: |
| + RefreshAppList(); |
| + break; |
| + } |
| +} |
| Property changes on: chrome\browser\autocomplete\extension_app_provider.cc |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |