| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/search_engines/template_url_model.h" | 5 #include "chrome/browser/search_engines/template_url_model.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/stl_util-inl.h" | 8 #include "base/stl_util-inl.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/extensions/extensions_service.h" | 10 #include "chrome/browser/extensions/extensions_service.h" |
| (...skipping 1050 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1061 // TODO(mpcomplete): disable the keyword when the extension is disabled. | 1061 // TODO(mpcomplete): disable the keyword when the extension is disabled. |
| 1062 if (extension->omnibox_keyword().empty()) | 1062 if (extension->omnibox_keyword().empty()) |
| 1063 return; | 1063 return; |
| 1064 | 1064 |
| 1065 Load(); | 1065 Load(); |
| 1066 if (!loaded_) { | 1066 if (!loaded_) { |
| 1067 pending_extension_ids_.push_back(extension->id()); | 1067 pending_extension_ids_.push_back(extension->id()); |
| 1068 return; | 1068 return; |
| 1069 } | 1069 } |
| 1070 | 1070 |
| 1071 if (GetTemplateURLForExtension(extension)) | 1071 const TemplateURL* existing_url = GetTemplateURLForExtension(extension); |
| 1072 return; // Already have this one registered (might be an upgrade). | |
| 1073 | |
| 1074 std::wstring keyword = UTF8ToWide(extension->omnibox_keyword()); | 1072 std::wstring keyword = UTF8ToWide(extension->omnibox_keyword()); |
| 1075 | 1073 |
| 1076 TemplateURL* template_url = new TemplateURL; | 1074 TemplateURL* template_url = new TemplateURL; |
| 1077 template_url->set_short_name(UTF8ToWide(extension->name())); | 1075 template_url->set_short_name(UTF8ToWide(extension->name())); |
| 1078 template_url->set_keyword(keyword); | 1076 template_url->set_keyword(keyword); |
| 1079 // This URL is not actually used for navigation. It holds the extension's | 1077 // This URL is not actually used for navigation. It holds the extension's |
| 1080 // ID, as well as forcing the TemplateURL to be treated as a search keyword. | 1078 // ID, as well as forcing the TemplateURL to be treated as a search keyword. |
| 1081 template_url->SetURL( | 1079 template_url->SetURL( |
| 1082 std::string(chrome::kExtensionScheme) + "://" + | 1080 std::string(chrome::kExtensionScheme) + "://" + |
| 1083 extension->id() + "/?q={searchTerms}", 0, 0); | 1081 extension->id() + "/?q={searchTerms}", 0, 0); |
| 1084 template_url->set_safe_for_autoreplace(false); | 1082 template_url->set_safe_for_autoreplace(false); |
| 1085 | 1083 |
| 1086 Add(template_url); | 1084 if (existing_url) { |
| 1085 // TODO(mpcomplete): only replace if the user hasn't changed the keyword. |
| 1086 // (We don't have UI for that yet). |
| 1087 Replace(existing_url, template_url); |
| 1088 } else { |
| 1089 Add(template_url); |
| 1090 } |
| 1087 } | 1091 } |
| 1088 | 1092 |
| 1089 void TemplateURLModel::UnregisterExtensionKeyword(Extension* extension) { | 1093 void TemplateURLModel::UnregisterExtensionKeyword(Extension* extension) { |
| 1090 const TemplateURL* url = GetTemplateURLForExtension(extension); | 1094 const TemplateURL* url = GetTemplateURLForExtension(extension); |
| 1091 if (url) | 1095 if (url) |
| 1092 Remove(url); | 1096 Remove(url); |
| 1093 } | 1097 } |
| 1094 | 1098 |
| 1095 const TemplateURL* TemplateURLModel::GetTemplateURLForExtension( | 1099 const TemplateURL* TemplateURLModel::GetTemplateURLForExtension( |
| 1096 Extension* extension) const { | 1100 Extension* extension) const { |
| 1097 for (TemplateURLVector::const_iterator i = template_urls_.begin(); | 1101 for (TemplateURLVector::const_iterator i = template_urls_.begin(); |
| 1098 i != template_urls_.end(); ++i) { | 1102 i != template_urls_.end(); ++i) { |
| 1099 if ((*i)->IsExtensionKeyword() && (*i)->url()->GetHost() == extension->id()) | 1103 if ((*i)->IsExtensionKeyword() && (*i)->url()->GetHost() == extension->id()) |
| 1100 return *i; | 1104 return *i; |
| 1101 } | 1105 } |
| 1102 | 1106 |
| 1103 return NULL; | 1107 return NULL; |
| 1104 } | 1108 } |
| OLD | NEW |