Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(176)

Side by Side Diff: chrome/browser/autocomplete/extension_app_provider.cc

Issue 6758031: Implement a simple Extension App Omnibox provider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/autocomplete/extension_app_provider.h"
6
7 #include <algorithm>
8
9 #include "base/string16.h"
10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/autocomplete/autocomplete_match.h"
12 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/profiles/profile.h"
14 #include "content/common/notification_service.h"
15 #include "ui/base/l10n/l10n_util.h"
16
17 ExtensionAppProvider::ExtensionAppProvider(ACProviderListener* listener,
18 Profile* profile)
19 : AutocompleteProvider(listener, profile, "ExtensionApps") {
20 RefreshAppList();
21 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
22 }
23
24 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.
25 TemplateURLModel* model)
26 : AutocompleteProvider(listener, NULL, "ExtensionApps") {
27 RefreshAppList();
28 RegisterForNotifications();
29 }
30
31 void ExtensionAppProvider::Start(const AutocompleteInput& input,
32 bool minimal_changes) {
33 matches_.clear();
34
35 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.
36 std::string input_utf8 = WideToUTF8(input.text());
37 for (std::vector<ExtensionApp>::const_iterator app =
38 extension_apps_.begin();
39 app != extension_apps_.end(); ++app) {
40 // See if the input matches this extension application.
41 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
42 const std::string& url = (*app).second;
43 std::string::const_iterator name_iter =
44 std::search(name.begin(),
45 name.end(),
46 input_utf8.begin(),
47 input_utf8.end(),
48 base::CaseInsensitiveCompare<char>());
49 std::string::const_iterator url_iter =
50 std::search(url.begin(),
51 url.end(),
52 input_utf8.begin(),
53 input_utf8.end(),
54 base::CaseInsensitiveCompare<char>());
55
56 bool matches_name = name_iter != name.end();
57 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
58 if (matches_name || matches_url) {
59 bool complete_match = input.text().length() == name.length();
60 // We have a match, might be a partial match.
61 // TODO(finnur): Figure out what type to return here, might want to have
62 // the extension icon/a generic icon show up in the Omnibox.
63 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.
64 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
65 match.destination_url = GURL(url);
66 match.inline_autocomplete_offset = string16::npos;
67 /* Will add this to the generated_resources.grd (currently has a bunch
68 of other changes in my tree from another CL):
69 <!-- Extension App Provider strings -->
70 <message name="IDS_EXTENSION_APP_LAUNCH_PREFIX"
71 desc="App launcher prefix for the Omnibox.">
72 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
73 </message>
74 */
75 string16 prefix = ASCIIToWide("Launch ");
76 match.contents = prefix + UTF8ToWide(name);
77 match.contents_class.push_back(
78 ACMatchClassification(0, ACMatchClassification::DIM));
79 if (name_iter != name.end()) {
80 size_t pos = name_iter - name.begin();
81 match.contents_class.push_back(
82 ACMatchClassification(prefix.length() + pos,
83 ACMatchClassification::MATCH));
84 if (pos + input.text().length() < name.length())
85 match.contents_class.push_back(
86 ACMatchClassification(prefix.length() + pos +
87 input.text().length(),
88 ACMatchClassification::DIM));
89 }
90
91 match.description = UTF8ToWide(url);
92 match.description_class.push_back(
93 ACMatchClassification(0, ACMatchClassification::DIM));
94 if (url_iter != url.end()) {
95 size_t pos = url_iter - url.begin();
96 match.description_class.push_back(
97 ACMatchClassification(pos, ACMatchClassification::MATCH));
98 if (pos + input.text().length() < url.length())
99 match.description_class.push_back(
100 ACMatchClassification(pos + input.text().length(),
101 ACMatchClassification::DIM));
102 }
103
104 match.relevance = CalculateRelevance(input.type(),
105 complete_match,
106 matches_name);
107 matches_.push_back(match);
108 }
109 }
110 }
111
112 done_ = true;
Peter Kasting 2011/03/31 21:33:59 Nit: You don't need this.
Finnur 2011/04/01 15:49:36 Done.
113 }
114
115 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.
116 done_ = true;
117 }
118
119 ExtensionAppProvider::~ExtensionAppProvider() {
120 }
121
122 void ExtensionAppProvider::RefreshAppList() {
123 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.
124 const ExtensionList* extensions = extensions_service->extensions();
125
126 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.
127
128 for (ExtensionList::const_iterator app = extensions->begin();
129 app != extensions->end(); ++app) {
130 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.
131 continue;
132
133 extension_apps_.push_back(std::make_pair((*app)->name(),
134 (*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
135 }
136 }
137
138 void ExtensionAppProvider::RegisterForNotifications() {
139 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
140 NotificationService::AllSources());
141 registrar_.Add(this, NotificationType::EXTENSION_UNINSTALLED,
142 NotificationService::AllSources());
143 }
144
145
146 // static
147 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.
148 bool complete,
149 bool matches_name) {
150 // 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
151 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
152 }
Finnur 2011/03/31 22:25:20 Thank you both for your comments... It is late, a
153
154 void ExtensionAppProvider::Observe(NotificationType type,
155 const NotificationSource& source,
156 const NotificationDetails& details) {
157 switch (type.value) {
158 case NotificationType::EXTENSION_LOADED:
159 case NotificationType::EXTENSION_UNINSTALLED:
160 RefreshAppList();
161 break;
162 }
163 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698