summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/ui')
-rw-r--r--chrome/browser/ui/search_engines/keyword_editor_controller.cc7
-rw-r--r--chrome/browser/ui/search_engines/template_url_table_model.cc50
-rw-r--r--chrome/browser/ui/search_engines/template_url_table_model.h8
-rw-r--r--chrome/browser/ui/webui/options/search_engine_manager_handler.cc57
-rw-r--r--chrome/browser/ui/webui/options/search_engine_manager_handler.h3
5 files changed, 67 insertions, 58 deletions
diff --git a/chrome/browser/ui/search_engines/keyword_editor_controller.cc b/chrome/browser/ui/search_engines/keyword_editor_controller.cc
index 132ce86..a44ab2d 100644
--- a/chrome/browser/ui/search_engines/keyword_editor_controller.cc
+++ b/chrome/browser/ui/search_engines/keyword_editor_controller.cc
@@ -39,12 +39,7 @@ int KeywordEditorController::AddTemplateURL(const string16& title,
content::RecordAction(UserMetricsAction("KeywordEditor_AddKeyword"));
- // There's a bug (1090726) in TableView with groups enabled such that newly
- // added items in groups ALWAYS appear at the end, regardless of the index
- // passed in. Worse yet, the selected rows get messed up when this happens
- // causing other problems. As a work around we always add the item to the end
- // of the list.
- const int new_index = table_model_->RowCount();
+ const int new_index = table_model_->last_other_engine_index();
table_model_->Add(new_index, title, keyword, url);
return new_index;
diff --git a/chrome/browser/ui/search_engines/template_url_table_model.cc b/chrome/browser/ui/search_engines/template_url_table_model.cc
index 4e610da..a0319bd 100644
--- a/chrome/browser/ui/search_engines/template_url_table_model.cc
+++ b/chrome/browser/ui/search_engines/template_url_table_model.cc
@@ -28,6 +28,7 @@
// Group IDs used by TemplateURLTableModel.
static const int kMainGroupID = 0;
static const int kOtherGroupID = 1;
+static const int kExtensionGroupID = 2;
// ModelEntry ----------------------------------------------------
@@ -143,6 +144,7 @@ void TemplateURLTableModel::Reload() {
TemplateURLService::TemplateURLVector urls =
template_url_service_->GetTemplateURLs();
+ std::vector<ModelEntry*> default_entries, other_entries, extension_entries;
// Keywords that can be made the default first.
for (TemplateURLService::TemplateURLVector::iterator i = urls.begin();
i != urls.end(); ++i) {
@@ -150,22 +152,28 @@ void TemplateURLTableModel::Reload() {
// NOTE: we don't use ShowInDefaultList here to avoid items bouncing around
// the lists while editing.
if (template_url->show_in_default_list())
- entries_.push_back(new ModelEntry(this, template_url));
+ default_entries.push_back(new ModelEntry(this, template_url));
+ else if (template_url->IsExtensionKeyword())
+ extension_entries.push_back(new ModelEntry(this, template_url));
+ else
+ other_entries.push_back(new ModelEntry(this, template_url));
}
- last_search_engine_index_ = static_cast<int>(entries_.size());
+ last_search_engine_index_ = static_cast<int>(default_entries.size());
+ last_other_engine_index_ = last_search_engine_index_ +
+ static_cast<int>(other_entries.size());
- // Then the rest.
- for (TemplateURLService::TemplateURLVector::iterator i = urls.begin();
- i != urls.end(); ++i) {
- TemplateURL* template_url = *i;
- // NOTE: we don't use ShowInDefaultList here to avoid things bouncing
- // the lists while editing.
- if (!template_url->show_in_default_list() &&
- !template_url->IsExtensionKeyword()) {
- entries_.push_back(new ModelEntry(this, template_url));
- }
- }
+ entries_.insert(entries_.end(),
+ default_entries.begin(),
+ default_entries.end());
+
+ entries_.insert(entries_.end(),
+ other_entries.begin(),
+ other_entries.end());
+
+ entries_.insert(entries_.end(),
+ extension_entries.begin(),
+ extension_entries.end());
if (observer_)
observer_->OnModelChanged();
@@ -222,12 +230,20 @@ TemplateURLTableModel::Groups TemplateURLTableModel::GetGroups() {
other_group.id = kOtherGroupID;
groups.push_back(other_group);
+ Group extension_group;
+ extension_group.title =
+ l10n_util::GetStringUTF16(IDS_SEARCH_ENGINES_EDITOR_EXTENSIONS_SEPARATOR);
+ extension_group.id = kExtensionGroupID;
+ groups.push_back(extension_group);
+
return groups;
}
int TemplateURLTableModel::GetGroupID(int row) {
DCHECK(row >= 0 && row < RowCount());
- return row < last_search_engine_index_ ? kMainGroupID : kOtherGroupID;
+ if (row < last_search_engine_index_)
+ return kMainGroupID;
+ return row < last_other_engine_index_ ? kOtherGroupID : kExtensionGroupID;
}
void TemplateURLTableModel::Remove(int index) {
@@ -239,7 +255,9 @@ void TemplateURLTableModel::Remove(int index) {
scoped_ptr<ModelEntry> entry(entries_[index]);
entries_.erase(entries_.begin() + index);
if (index < last_search_engine_index_)
- last_search_engine_index_--;
+ --last_search_engine_index_;
+ if (index < last_other_engine_index_)
+ --last_other_engine_index_;
if (observer_)
observer_->OnItemsRemoved(index, 1);
@@ -265,6 +283,8 @@ void TemplateURLTableModel::Add(int index,
ModelEntry* entry = new ModelEntry(this, turl);
template_url_service_->AddObserver(this);
entries_.insert(entries_.begin() + index, entry);
+ if (index <= last_other_engine_index_)
+ ++last_other_engine_index_;
if (observer_)
observer_->OnItemsAdded(index, 1);
}
diff --git a/chrome/browser/ui/search_engines/template_url_table_model.h b/chrome/browser/ui/search_engines/template_url_table_model.h
index cedd552..6ee70b9 100644
--- a/chrome/browser/ui/search_engines/template_url_table_model.h
+++ b/chrome/browser/ui/search_engines/template_url_table_model.h
@@ -97,6 +97,10 @@ class TemplateURLTableModel : public ui::TableModel,
// Returns the index of the last entry shown in the search engines group.
int last_search_engine_index() const { return last_search_engine_index_; }
+ // Returns the index of the last entry shown in the other search engines
+ // group.
+ int last_other_engine_index() const { return last_other_engine_index_; }
+
private:
friend class ModelEntry;
@@ -118,6 +122,10 @@ class TemplateURLTableModel : public ui::TableModel,
// group boundaries.
int last_search_engine_index_;
+ // Index of the last other engine in entries_. This is used to determine the
+ // group boundaries.
+ int last_other_engine_index_;
+
DISALLOW_COPY_AND_ASSIGN(TemplateURLTableModel);
};
diff --git a/chrome/browser/ui/webui/options/search_engine_manager_handler.cc b/chrome/browser/ui/webui/options/search_engine_manager_handler.cc
index cae706e..10bb6a4 100644
--- a/chrome/browser/ui/webui/options/search_engine_manager_handler.cc
+++ b/chrome/browser/ui/webui/options/search_engine_manager_handler.cc
@@ -126,29 +126,28 @@ void SearchEngineManagerHandler::OnModelChanged() {
int last_default_engine_index =
list_controller_->table_model()->last_search_engine_index();
for (int i = 0; i < last_default_engine_index; ++i) {
- defaults_list.Append(CreateDictionaryForEngine(i, i == default_index));
+ // Third argument is false, as the engine is not from an extension.
+ defaults_list.Append(CreateDictionaryForEngine(
+ i, i == default_index, false));
}
// Build the second list (other search templates).
ListValue others_list;
+ int last_other_engine_index =
+ list_controller_->table_model()->last_other_engine_index();
if (last_default_engine_index < 0)
last_default_engine_index = 0;
- int engine_count = list_controller_->table_model()->RowCount();
- for (int i = last_default_engine_index; i < engine_count; ++i) {
- others_list.Append(CreateDictionaryForEngine(i, i == default_index));
+ for (int i = last_default_engine_index; i < last_other_engine_index; ++i) {
+ others_list.Append(CreateDictionaryForEngine(i, i == default_index, false));
}
// Build the extension keywords list.
ListValue keyword_list;
- ExtensionService* extension_service =
- Profile::FromWebUI(web_ui())->GetExtensionService();
- if (extension_service) {
- const ExtensionSet* extensions = extension_service->extensions();
- for (ExtensionSet::const_iterator it = extensions->begin();
- it != extensions->end(); ++it) {
- if (extensions::OmniboxInfo::GetKeyword(*it).size() > 0)
- keyword_list.Append(CreateDictionaryForExtension(*(*it)));
- }
+ if (last_other_engine_index < 0)
+ last_other_engine_index = 0;
+ int engine_count = list_controller_->table_model()->RowCount();
+ for (int i = last_other_engine_index; i < engine_count; ++i) {
+ keyword_list.Append(CreateDictionaryForEngine(i, i == default_index, true));
}
web_ui()->CallJavascriptFunction("SearchEngineManager.updateSearchEngineList",
@@ -167,22 +166,8 @@ void SearchEngineManagerHandler::OnItemsRemoved(int start, int length) {
OnModelChanged();
}
-base::DictionaryValue* SearchEngineManagerHandler::CreateDictionaryForExtension(
- const extensions::Extension& extension) {
- base::DictionaryValue* dict = new base::DictionaryValue();
- dict->SetString("name", extension.name());
- dict->SetString("displayName", extension.name());
- dict->SetString("keyword",
- extensions::OmniboxInfo::GetKeyword(&extension));
- GURL icon = extensions::IconsInfo::GetIconURL(
- &extension, 16, ExtensionIconSet::MATCH_BIGGER);
- dict->SetString("iconURL", icon.spec());
- dict->SetString("url", string16());
- return dict;
-}
-
base::DictionaryValue* SearchEngineManagerHandler::CreateDictionaryForEngine(
- int index, bool is_default) {
+ int index, bool is_default, bool is_extension) {
TemplateURLTableModel* table_model = list_controller_->table_model();
const TemplateURL* template_url = list_controller_->GetTemplateURL(index);
@@ -199,14 +184,13 @@ base::DictionaryValue* SearchEngineManagerHandler::CreateDictionaryForEngine(
dict->SetString("iconURL", icon_url.spec());
dict->SetString("modelIndex", base::IntToString(index));
- if (list_controller_->CanRemove(template_url))
- dict->SetString("canBeRemoved", "1");
- if (list_controller_->CanMakeDefault(template_url))
- dict->SetString("canBeDefault", "1");
- if (is_default)
- dict->SetString("default", "1");
- if (list_controller_->CanEdit(template_url))
- dict->SetString("canBeEdited", "1");
+ dict->SetBoolean("canBeRemoved",
+ list_controller_->CanRemove(template_url) && !is_extension);
+ dict->SetBoolean("canBeDefault",
+ list_controller_->CanMakeDefault(template_url) && !is_extension);
+ dict->SetBoolean("default", is_default);
+ dict->SetBoolean("canBeEdited", list_controller_->CanEdit(template_url));
+ dict->SetBoolean("isExtension", is_extension);
return dict;
}
@@ -310,6 +294,7 @@ void SearchEngineManagerHandler::EditCompleted(const ListValue* args) {
NOTREACHED();
return;
}
+
// Recheck validity. It's possible to get here with invalid input if e.g. the
// user calls the right JS functions directly from the web inspector.
if (edit_controller_->IsTitleValid(name) &&
diff --git a/chrome/browser/ui/webui/options/search_engine_manager_handler.h b/chrome/browser/ui/webui/options/search_engine_manager_handler.h
index e28d6a5..337a7da 100644
--- a/chrome/browser/ui/webui/options/search_engine_manager_handler.h
+++ b/chrome/browser/ui/webui/options/search_engine_manager_handler.h
@@ -72,7 +72,8 @@ class SearchEngineManagerHandler : public OptionsPageUIHandler,
void EditCompleted(const base::ListValue* args);
// Returns a dictionary to pass to WebUI representing the given search engine.
- base::DictionaryValue* CreateDictionaryForEngine(int index, bool is_default);
+ base::DictionaryValue* CreateDictionaryForEngine(
+ int index, bool is_default, bool is_extension);
// Returns a dictionary to pass to WebUI representing the extension.
base::DictionaryValue* CreateDictionaryForExtension(