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

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

Issue 7574021: Remove frontend code that allows for dynamic profile setting, and read the profile off the browse... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 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 (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/autocomplete/autocomplete_popup_model.h" 5 #include "chrome/browser/autocomplete/autocomplete_popup_model.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "unicode/ubidi.h" 9 #include "unicode/ubidi.h"
10 10
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/autocomplete/autocomplete_edit.h" 13 #include "chrome/browser/autocomplete/autocomplete_edit.h"
14 #include "chrome/browser/autocomplete/autocomplete_match.h" 14 #include "chrome/browser/autocomplete/autocomplete_match.h"
15 #include "chrome/browser/autocomplete/autocomplete_popup_view.h" 15 #include "chrome/browser/autocomplete/autocomplete_popup_view.h"
16 #include "chrome/browser/extensions/extension_service.h" 16 #include "chrome/browser/extensions/extension_service.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/search_engines/template_url.h" 18 #include "chrome/browser/search_engines/template_url.h"
19 #include "chrome/browser/search_engines/template_url_service.h" 19 #include "chrome/browser/search_engines/template_url_service.h"
20 #include "chrome/browser/search_engines/template_url_service_factory.h" 20 #include "chrome/browser/search_engines/template_url_service_factory.h"
21 #include "ui/gfx/rect.h" 21 #include "ui/gfx/rect.h"
22 22
23 /////////////////////////////////////////////////////////////////////////////// 23 ///////////////////////////////////////////////////////////////////////////////
24 // AutocompletePopupModel 24 // AutocompletePopupModel
25 25
26 AutocompletePopupModel::AutocompletePopupModel( 26 AutocompletePopupModel::AutocompletePopupModel(
27 AutocompletePopupView* popup_view, 27 AutocompletePopupView* popup_view,
28 AutocompleteEditModel* edit_model, 28 AutocompleteEditModel* edit_model)
29 Profile* profile)
30 : view_(popup_view), 29 : view_(popup_view),
31 edit_model_(edit_model), 30 edit_model_(edit_model),
32 profile_(profile),
33 hovered_line_(kNoMatch), 31 hovered_line_(kNoMatch),
34 selected_line_(kNoMatch) { 32 selected_line_(kNoMatch) {
35 edit_model->set_popup_model(this); 33 edit_model->set_popup_model(this);
36 } 34 }
37 35
38 AutocompletePopupModel::~AutocompletePopupModel() { 36 AutocompletePopupModel::~AutocompletePopupModel() {
39 } 37 }
40 38
41 bool AutocompletePopupModel::IsOpen() const { 39 bool AutocompletePopupModel::IsOpen() const {
42 return view_->IsOpen(); 40 return view_->IsOpen();
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 view_->OnDragCanceled(); 127 view_->OnDragCanceled();
130 } 128 }
131 129
132 bool AutocompletePopupModel::GetKeywordForMatch(const AutocompleteMatch& match, 130 bool AutocompletePopupModel::GetKeywordForMatch(const AutocompleteMatch& match,
133 string16* keyword) const { 131 string16* keyword) const {
134 // Assume we have no keyword until we find otherwise. 132 // Assume we have no keyword until we find otherwise.
135 keyword->clear(); 133 keyword->clear();
136 134
137 if (match.template_url) { 135 if (match.template_url) {
138 TemplateURLService* url_service = 136 TemplateURLService* url_service =
139 TemplateURLServiceFactory::GetForProfile(profile_); 137 TemplateURLServiceFactory::GetForProfile(edit_model_->profile());
140 if (!url_service) 138 if (!url_service)
141 return false; 139 return false;
142 140
143 // Only show the keyword for the default provider if the user typed in 141 // Only show the keyword for the default provider if the user typed in
144 // the keyword and it isn't SEARCH_WHAT_YOU_TYPED. 142 // the keyword and it isn't SEARCH_WHAT_YOU_TYPED.
145 const TemplateURL* default_url = url_service->GetDefaultSearchProvider(); 143 const TemplateURL* default_url = url_service->GetDefaultSearchProvider();
146 if (default_url && (default_url->id() == match.template_url->id())) { 144 if (default_url && (default_url->id() == match.template_url->id())) {
147 if (StartsWith(autocomplete_controller()->input().text(), 145 if (StartsWith(autocomplete_controller()->input().text(),
148 default_url->keyword(), false) && 146 default_url->keyword(), false) &&
149 (match.type != AutocompleteMatch::SEARCH_WHAT_YOU_TYPED)) { 147 (match.type != AutocompleteMatch::SEARCH_WHAT_YOU_TYPED)) {
(...skipping 14 matching lines...) Expand all
164 bool AutocompletePopupModel::GetKeywordForText(const string16& text, 162 bool AutocompletePopupModel::GetKeywordForText(const string16& text,
165 string16* keyword) const { 163 string16* keyword) const {
166 // Creates keyword_hint first in case |keyword| is a pointer to |text|. 164 // Creates keyword_hint first in case |keyword| is a pointer to |text|.
167 const string16 keyword_hint(TemplateURLService::CleanUserInputKeyword(text)); 165 const string16 keyword_hint(TemplateURLService::CleanUserInputKeyword(text));
168 166
169 // Assume we have no keyword until we find otherwise. 167 // Assume we have no keyword until we find otherwise.
170 keyword->clear(); 168 keyword->clear();
171 169
172 if (keyword_hint.empty()) 170 if (keyword_hint.empty())
173 return false; 171 return false;
172 Profile* profile = edit_model_->profile();
174 TemplateURLService* url_service = 173 TemplateURLService* url_service =
175 TemplateURLServiceFactory::GetForProfile(profile_); 174 TemplateURLServiceFactory::GetForProfile(profile);
176 if (!url_service) 175 if (!url_service)
177 return false; 176 return false;
178 url_service->Load(); 177 url_service->Load();
179 178
180 // Don't provide a hint if this keyword doesn't support replacement. 179 // Don't provide a hint if this keyword doesn't support replacement.
181 const TemplateURL* const template_url = 180 const TemplateURL* const template_url =
182 url_service->GetTemplateURLForKeyword(keyword_hint); 181 url_service->GetTemplateURLForKeyword(keyword_hint);
183 if (!TemplateURL::SupportsReplacement(template_url)) 182 if (!TemplateURL::SupportsReplacement(template_url))
184 return false; 183 return false;
185 184
186 // Don't provide a hint for inactive/disabled extension keywords. 185 // Don't provide a hint for inactive/disabled extension keywords.
187 if (template_url->IsExtensionKeyword()) { 186 if (template_url->IsExtensionKeyword()) {
188 const Extension* extension = profile_->GetExtensionService()-> 187 const Extension* extension = profile->GetExtensionService()->
189 GetExtensionById(template_url->GetExtensionId(), false); 188 GetExtensionById(template_url->GetExtensionId(), false);
190 if (!extension || 189 if (!extension || (profile->IsOffTheRecord() &&
191 (profile_->IsOffTheRecord() && 190 !profile->GetExtensionService()->IsIncognitoEnabled(extension->id())))
192 !profile_->GetExtensionService()->
193 IsIncognitoEnabled(extension->id())))
194 return false; 191 return false;
195 } 192 }
196 193
197 keyword->assign(keyword_hint); 194 keyword->assign(keyword_hint);
198 return true; 195 return true;
199 } 196 }
200 197
201 void AutocompletePopupModel::Move(int count) { 198 void AutocompletePopupModel::Move(int count) {
202 const AutocompleteResult& result = this->result(); 199 const AutocompleteResult& result = this->result();
203 if (result.empty()) 200 if (result.empty())
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 SetSelectedLine(selected_line, false, true); 240 SetSelectedLine(selected_line, false, true);
244 } 241 }
245 } 242 }
246 } 243 }
247 244
248 const SkBitmap* AutocompletePopupModel::GetIconIfExtensionMatch( 245 const SkBitmap* AutocompletePopupModel::GetIconIfExtensionMatch(
249 const AutocompleteMatch& match) const { 246 const AutocompleteMatch& match) const {
250 if (!match.template_url || !match.template_url->IsExtensionKeyword()) 247 if (!match.template_url || !match.template_url->IsExtensionKeyword())
251 return NULL; 248 return NULL;
252 249
253 return &profile_->GetExtensionService()->GetOmniboxPopupIcon( 250 return &edit_model_->profile()->GetExtensionService()->GetOmniboxPopupIcon(
254 match.template_url->GetExtensionId()); 251 match.template_url->GetExtensionId());
255 } 252 }
256 253
257 void AutocompletePopupModel::OnResultChanged() { 254 void AutocompletePopupModel::OnResultChanged() {
258 const AutocompleteResult& result = this->result(); 255 const AutocompleteResult& result = this->result();
259 selected_line_ = result.default_match() == result.end() ? 256 selected_line_ = result.default_match() == result.end() ?
260 kNoMatch : static_cast<size_t>(result.default_match() - result.begin()); 257 kNoMatch : static_cast<size_t>(result.default_match() - result.begin());
261 // There had better not be a nonempty result set with no default match. 258 // There had better not be a nonempty result set with no default match.
262 CHECK((selected_line_ != kNoMatch) || result.empty()); 259 CHECK((selected_line_ != kNoMatch) || result.empty());
263 manually_selected_match_.Clear(); 260 manually_selected_match_.Clear();
264 // If we're going to trim the window size to no longer include the hovered 261 // If we're going to trim the window size to no longer include the hovered
265 // line, turn hover off. Practically, this shouldn't happen, but it 262 // line, turn hover off. Practically, this shouldn't happen, but it
266 // doesn't hurt to be defensive. 263 // doesn't hurt to be defensive.
267 if ((hovered_line_ != kNoMatch) && (result.size() <= hovered_line_)) 264 if ((hovered_line_ != kNoMatch) && (result.size() <= hovered_line_))
268 SetHoveredLine(kNoMatch); 265 SetHoveredLine(kNoMatch);
269 266
270 view_->UpdatePopupAppearance(); 267 view_->UpdatePopupAppearance();
271 } 268 }
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_popup_model.h ('k') | chrome/browser/ui/cocoa/omnibox/omnibox_popup_view_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698