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

Side by Side Diff: chrome/browser/ui/search_engines/template_url_table_model.cc

Issue 15805002: Modify extension omnibox keywords to be user-configurable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Devlin's requests Created 7 years, 7 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
OLDNEW
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/ui/search_engines/template_url_table_model.h" 5 #include "chrome/browser/ui/search_engines/template_url_table_model.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/i18n/rtl.h" 9 #include "base/i18n/rtl.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 10 matching lines...) Expand all
21 #include "third_party/skia/include/core/SkBitmap.h" 21 #include "third_party/skia/include/core/SkBitmap.h"
22 #include "ui/base/l10n/l10n_util.h" 22 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/base/models/table_model_observer.h" 23 #include "ui/base/models/table_model_observer.h"
24 #include "ui/base/resource/resource_bundle.h" 24 #include "ui/base/resource/resource_bundle.h"
25 #include "ui/gfx/favicon_size.h" 25 #include "ui/gfx/favicon_size.h"
26 #include "ui/gfx/image/image_skia.h" 26 #include "ui/gfx/image/image_skia.h"
27 27
28 // Group IDs used by TemplateURLTableModel. 28 // Group IDs used by TemplateURLTableModel.
29 static const int kMainGroupID = 0; 29 static const int kMainGroupID = 0;
30 static const int kOtherGroupID = 1; 30 static const int kOtherGroupID = 1;
31 static const int kExtensionGroupID = 2;
31 32
32 // ModelEntry ---------------------------------------------------- 33 // ModelEntry ----------------------------------------------------
33 34
34 // ModelEntry wraps a TemplateURL as returned from the TemplateURL. 35 // ModelEntry wraps a TemplateURL as returned from the TemplateURL.
35 // ModelEntry also tracks state information about the URL. 36 // ModelEntry also tracks state information about the URL.
36 37
37 // Icon used while loading, or if a specific favicon can't be found. 38 // Icon used while loading, or if a specific favicon can't be found.
38 static gfx::ImageSkia* default_icon = NULL; 39 static gfx::ImageSkia* default_icon = NULL;
39 40
40 class ModelEntry { 41 class ModelEntry {
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 entries_.clear(); 137 entries_.clear();
137 } 138 }
138 139
139 void TemplateURLTableModel::Reload() { 140 void TemplateURLTableModel::Reload() {
140 STLDeleteElements(&entries_); 141 STLDeleteElements(&entries_);
141 entries_.clear(); 142 entries_.clear();
142 143
143 TemplateURLService::TemplateURLVector urls = 144 TemplateURLService::TemplateURLVector urls =
144 template_url_service_->GetTemplateURLs(); 145 template_url_service_->GetTemplateURLs();
145 146
146 // Keywords that can be made the default first. 147 // Keywords that can be made the default first.
Peter Kasting 2013/05/30 21:22:50 Nit: Since you have the same block of code three t
Aaron Jacobs 2013/05/31 03:07:24 Done.
147 for (TemplateURLService::TemplateURLVector::iterator i = urls.begin(); 148 for (TemplateURLService::TemplateURLVector::iterator i = urls.begin();
148 i != urls.end(); ++i) { 149 i != urls.end(); ++i) {
149 TemplateURL* template_url = *i; 150 TemplateURL* template_url = *i;
150 // NOTE: we don't use ShowInDefaultList here to avoid items bouncing around 151 // NOTE: we don't use ShowInDefaultList here to avoid items bouncing around
151 // the lists while editing. 152 // the lists while editing.
152 if (template_url->show_in_default_list()) 153 if (template_url->show_in_default_list())
153 entries_.push_back(new ModelEntry(this, template_url)); 154 entries_.push_back(new ModelEntry(this, template_url));
154 } 155 }
155 156
156 last_search_engine_index_ = static_cast<int>(entries_.size()); 157 last_search_engine_index_ = static_cast<int>(entries_.size());
157 158
158 // Then the rest. 159 // Then the non extension keywords.
159 for (TemplateURLService::TemplateURLVector::iterator i = urls.begin(); 160 for (TemplateURLService::TemplateURLVector::iterator i = urls.begin();
160 i != urls.end(); ++i) { 161 i != urls.end(); ++i) {
161 TemplateURL* template_url = *i; 162 TemplateURL* template_url = *i;
162 // NOTE: we don't use ShowInDefaultList here to avoid things bouncing 163 // NOTE: we don't use ShowInDefaultList here to avoid things bouncing
163 // the lists while editing. 164 // the lists while editing.
164 if (!template_url->show_in_default_list() && 165 if (!template_url->show_in_default_list() &&
165 !template_url->IsExtensionKeyword()) { 166 !template_url->IsExtensionKeyword()) {
166 entries_.push_back(new ModelEntry(this, template_url)); 167 entries_.push_back(new ModelEntry(this, template_url));
167 } 168 }
168 } 169 }
169 170
171 last_other_engine_index_ = static_cast<int>(entries_.size());
172
173 // Finally, the extensions.
174 for (TemplateURLService::TemplateURLVector::iterator i = urls.begin();
175 i != urls.end(); ++i) {
176 TemplateURL* template_url = *i;
177 // NOTE: we don't use ShowInDefaultList here to avoid things bouncing
178 // the lists while editing.
179 if (!template_url->show_in_default_list() &&
180 template_url->IsExtensionKeyword()) {
181 entries_.push_back(new ModelEntry(this, template_url));
182 }
183 }
184
170 if (observer_) 185 if (observer_)
171 observer_->OnModelChanged(); 186 observer_->OnModelChanged();
172 } 187 }
173 188
174 int TemplateURLTableModel::RowCount() { 189 int TemplateURLTableModel::RowCount() {
175 return static_cast<int>(entries_.size()); 190 return static_cast<int>(entries_.size());
176 } 191 }
177 192
178 string16 TemplateURLTableModel::GetText(int row, int col_id) { 193 string16 TemplateURLTableModel::GetText(int row, int col_id) {
179 DCHECK(row >= 0 && row < RowCount()); 194 DCHECK(row >= 0 && row < RowCount());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_MAIN_SEPARATOR); 230 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_MAIN_SEPARATOR);
216 search_engine_group.id = kMainGroupID; 231 search_engine_group.id = kMainGroupID;
217 groups.push_back(search_engine_group); 232 groups.push_back(search_engine_group);
218 233
219 Group other_group; 234 Group other_group;
220 other_group.title = 235 other_group.title =
221 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_OTHER_SEPARATOR); 236 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_OTHER_SEPARATOR);
222 other_group.id = kOtherGroupID; 237 other_group.id = kOtherGroupID;
223 groups.push_back(other_group); 238 groups.push_back(other_group);
224 239
240 Group extension_group;
241 extension_group.title =
242 l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_EXTENSIONS_SEPARATOR);
243 extension_group.id = kExtensionGroupID;
244 groups.push_back(extension_group);
245
225 return groups; 246 return groups;
226 } 247 }
227 248
228 int TemplateURLTableModel::GetGroupID(int row) { 249 int TemplateURLTableModel::GetGroupID(int row) {
229 DCHECK(row >= 0 && row < RowCount()); 250 DCHECK(row >= 0 && row < RowCount());
230 return row < last_search_engine_index_ ? kMainGroupID : kOtherGroupID; 251 if (row < last_search_engine_index_)
252 return kMainGroupID;
253 if (row < last_other_engine_index_)
Peter Kasting 2013/05/30 21:22:50 Nit: You could use ?: on this last pair
Aaron Jacobs 2013/05/31 03:07:24 Done.
254 return kOtherGroupID;
255 return kExtensionGroupID;
231 } 256 }
232 257
233 void TemplateURLTableModel::Remove(int index) { 258 void TemplateURLTableModel::Remove(int index) {
234 // Remove the observer while we modify the model, that way we don't need to 259 // Remove the observer while we modify the model, that way we don't need to
235 // worry about the model calling us back when we mutate it. 260 // worry about the model calling us back when we mutate it.
236 template_url_service_->RemoveObserver(this); 261 template_url_service_->RemoveObserver(this);
237 TemplateURL* template_url = GetTemplateURL(index); 262 TemplateURL* template_url = GetTemplateURL(index);
238 263
239 scoped_ptr<ModelEntry> entry(entries_[index]); 264 scoped_ptr<ModelEntry> entry(entries_[index]);
240 entries_.erase(entries_.begin() + index); 265 entries_.erase(entries_.begin() + index);
241 if (index < last_search_engine_index_) 266 if (index < last_search_engine_index_)
242 last_search_engine_index_--; 267 --last_search_engine_index_;
268 if (index < last_other_engine_index_)
269 --last_other_engine_index_;
243 if (observer_) 270 if (observer_)
244 observer_->OnItemsRemoved(index, 1); 271 observer_->OnItemsRemoved(index, 1);
245 272
246 // Make sure to remove from the table model first, otherwise the 273 // Make sure to remove from the table model first, otherwise the
247 // TemplateURL would be freed. 274 // TemplateURL would be freed.
248 template_url_service_->Remove(template_url); 275 template_url_service_->Remove(template_url);
249 template_url_service_->AddObserver(this); 276 template_url_service_->AddObserver(this);
250 } 277 }
251 278
252 void TemplateURLTableModel::Add(int index, 279 void TemplateURLTableModel::Add(int index,
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 void TemplateURLTableModel::FaviconAvailable(ModelEntry* entry) { 393 void TemplateURLTableModel::FaviconAvailable(ModelEntry* entry) {
367 std::vector<ModelEntry*>::iterator i = 394 std::vector<ModelEntry*>::iterator i =
368 std::find(entries_.begin(), entries_.end(), entry); 395 std::find(entries_.begin(), entries_.end(), entry);
369 DCHECK(i != entries_.end()); 396 DCHECK(i != entries_.end());
370 NotifyChanged(static_cast<int>(i - entries_.begin())); 397 NotifyChanged(static_cast<int>(i - entries_.begin()));
371 } 398 }
372 399
373 void TemplateURLTableModel::OnTemplateURLServiceChanged() { 400 void TemplateURLTableModel::OnTemplateURLServiceChanged() {
374 Reload(); 401 Reload();
375 } 402 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698