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

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

Issue 425303002: Move extension notifications to extensions/browser/notification_types.h (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: (extension-notifications) rebase Created 6 years, 4 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/keyword_extensions_delegate_impl.h" 5 #include "chrome/browser/autocomplete/keyword_extensions_delegate_impl.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" 8 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h"
10 #include "chrome/browser/extensions/extension_service.h" 9 #include "chrome/browser/extensions/extension_service.h"
11 #include "chrome/browser/extensions/extension_util.h" 10 #include "chrome/browser/extensions/extension_util.h"
12 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
13 #include "content/public/browser/notification_details.h" 12 #include "content/public/browser/notification_details.h"
14 #include "content/public/browser/notification_source.h" 13 #include "content/public/browser/notification_source.h"
15 #include "extensions/browser/extension_system.h" 14 #include "extensions/browser/extension_system.h"
15 #include "extensions/browser/notification_types.h"
16 16
17 namespace omnibox_api = extensions::api::omnibox; 17 namespace omnibox_api = extensions::api::omnibox;
18 18
19 int KeywordExtensionsDelegateImpl::global_input_uid_ = 0; 19 int KeywordExtensionsDelegateImpl::global_input_uid_ = 0;
20 20
21 KeywordExtensionsDelegateImpl::KeywordExtensionsDelegateImpl( 21 KeywordExtensionsDelegateImpl::KeywordExtensionsDelegateImpl(
22 KeywordProvider* provider) 22 KeywordProvider* provider)
23 : KeywordExtensionsDelegate(provider), 23 : KeywordExtensionsDelegate(provider),
24 provider_(provider) { 24 provider_(provider) {
25 DCHECK(provider_); 25 DCHECK(provider_);
26 26
27 current_input_id_ = 0; 27 current_input_id_ = 0;
28 // Extension suggestions always come from the original profile, since that's 28 // Extension suggestions always come from the original profile, since that's
29 // where extensions run. We use the input ID to distinguish whether the 29 // where extensions run. We use the input ID to distinguish whether the
30 // suggestions are meant for us. 30 // suggestions are meant for us.
31 registrar_.Add(this,
32 extensions::NOTIFICATION_EXTENSION_OMNIBOX_SUGGESTIONS_READY,
33 content::Source<Profile>(profile()->GetOriginalProfile()));
31 registrar_.Add( 34 registrar_.Add(
32 this, chrome::NOTIFICATION_EXTENSION_OMNIBOX_SUGGESTIONS_READY, 35 this,
36 extensions::NOTIFICATION_EXTENSION_OMNIBOX_DEFAULT_SUGGESTION_CHANGED,
33 content::Source<Profile>(profile()->GetOriginalProfile())); 37 content::Source<Profile>(profile()->GetOriginalProfile()));
34 registrar_.Add( 38 registrar_.Add(this,
35 this, chrome::NOTIFICATION_EXTENSION_OMNIBOX_DEFAULT_SUGGESTION_CHANGED, 39 extensions::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED,
36 content::Source<Profile>(profile()->GetOriginalProfile())); 40 content::Source<Profile>(profile()));
37 registrar_.Add(
38 this, chrome::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED,
39 content::Source<Profile>(profile()));
40 } 41 }
41 42
42 KeywordExtensionsDelegateImpl::~KeywordExtensionsDelegateImpl() { 43 KeywordExtensionsDelegateImpl::~KeywordExtensionsDelegateImpl() {
43 } 44 }
44 45
45 void KeywordExtensionsDelegateImpl::IncrementInputId() { 46 void KeywordExtensionsDelegateImpl::IncrementInputId() {
46 current_input_id_ = ++global_input_uid_; 47 current_input_id_ = ++global_input_uid_;
47 } 48 }
48 49
49 bool KeywordExtensionsDelegateImpl::IsEnabledExtension( 50 bool KeywordExtensionsDelegateImpl::IsEnabledExtension(
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 } 117 }
117 118
118 void KeywordExtensionsDelegateImpl::Observe( 119 void KeywordExtensionsDelegateImpl::Observe(
119 int type, 120 int type,
120 const content::NotificationSource& source, 121 const content::NotificationSource& source,
121 const content::NotificationDetails& details) { 122 const content::NotificationDetails& details) {
122 TemplateURLService* model = provider_->GetTemplateURLService(); 123 TemplateURLService* model = provider_->GetTemplateURLService();
123 const AutocompleteInput& input = extension_suggest_last_input_; 124 const AutocompleteInput& input = extension_suggest_last_input_;
124 125
125 switch (type) { 126 switch (type) {
126 case chrome::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED: 127 case extensions::NOTIFICATION_EXTENSION_OMNIBOX_INPUT_ENTERED:
127 // Input has been accepted, so we're done with this input session. Ensure 128 // Input has been accepted, so we're done with this input session. Ensure
128 // we don't send the OnInputCancelled event, or handle any more stray 129 // we don't send the OnInputCancelled event, or handle any more stray
129 // suggestions_ready events. 130 // suggestions_ready events.
130 current_keyword_extension_id_.clear(); 131 current_keyword_extension_id_.clear();
131 current_input_id_ = 0; 132 current_input_id_ = 0;
132 return; 133 return;
133 134
134 case chrome::NOTIFICATION_EXTENSION_OMNIBOX_DEFAULT_SUGGESTION_CHANGED: { 135 case extensions::NOTIFICATION_EXTENSION_OMNIBOX_DEFAULT_SUGGESTION_CHANGED
136 : {
135 // It's possible to change the default suggestion while not in an editing 137 // It's possible to change the default suggestion while not in an editing
136 // session. 138 // session.
137 base::string16 keyword, remaining_input; 139 base::string16 keyword, remaining_input;
138 if (matches()->empty() || current_keyword_extension_id_.empty() || 140 if (matches()->empty() || current_keyword_extension_id_.empty() ||
139 !KeywordProvider::ExtractKeywordFromInput( 141 !KeywordProvider::ExtractKeywordFromInput(
140 input, &keyword, &remaining_input)) 142 input, &keyword, &remaining_input))
141 return; 143 return;
142 144
143 const TemplateURL* template_url( 145 const TemplateURL* template_url(
144 model->GetTemplateURLForKeyword(keyword)); 146 model->GetTemplateURLForKeyword(keyword));
145 extensions::ApplyDefaultSuggestionForExtensionKeyword( 147 extensions::ApplyDefaultSuggestionForExtensionKeyword(
146 profile(), template_url, remaining_input, &matches()->front()); 148 profile(), template_url, remaining_input, &matches()->front());
147 OnProviderUpdate(true); 149 OnProviderUpdate(true);
148 return; 150 return;
149 } 151 }
150 152
151 case chrome::NOTIFICATION_EXTENSION_OMNIBOX_SUGGESTIONS_READY: { 153 case extensions::NOTIFICATION_EXTENSION_OMNIBOX_SUGGESTIONS_READY: {
152 const omnibox_api::SendSuggestions::Params& suggestions = 154 const omnibox_api::SendSuggestions::Params& suggestions =
153 *content::Details< 155 *content::Details<
154 omnibox_api::SendSuggestions::Params>(details).ptr(); 156 omnibox_api::SendSuggestions::Params>(details).ptr();
155 if (suggestions.request_id != current_input_id_) 157 if (suggestions.request_id != current_input_id_)
156 return; // This is an old result. Just ignore. 158 return; // This is an old result. Just ignore.
157 159
158 base::string16 keyword, remaining_input; 160 base::string16 keyword, remaining_input;
159 bool result = KeywordProvider::ExtractKeywordFromInput( 161 bool result = KeywordProvider::ExtractKeywordFromInput(
160 input, &keyword, &remaining_input); 162 input, &keyword, &remaining_input);
161 DCHECK(result); 163 DCHECK(result);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 203
202 default: 204 default:
203 NOTREACHED(); 205 NOTREACHED();
204 return; 206 return;
205 } 207 }
206 } 208 }
207 209
208 void KeywordExtensionsDelegateImpl::OnProviderUpdate(bool updated_matches) { 210 void KeywordExtensionsDelegateImpl::OnProviderUpdate(bool updated_matches) {
209 provider_->listener_->OnProviderUpdate(updated_matches); 211 provider_->listener_->OnProviderUpdate(updated_matches);
210 } 212 }
OLDNEW
« no previous file with comments | « chrome/browser/apps/event_page_browsertest.cc ('k') | chrome/browser/autocomplete/shortcuts_backend.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698