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

Side by Side Diff: chrome/browser/ui/webui/settings/search_engines_handler.cc

Issue 2529543002: MD Settings: indicate extension controlled search engines (Closed)
Patch Set: self-review Created 4 years, 1 month 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/webui/settings/search_engines_handler.h" 5 #include "chrome/browser/ui/webui/settings/search_engines_handler.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/extensions/extension_util.h" 12 #include "chrome/browser/extensions/extension_util.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" 14 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h"
15 #include "chrome/browser/ui/search_engines/template_url_table_model.h" 15 #include "chrome/browser/ui/search_engines/template_url_table_model.h"
16 #include "chrome/common/url_constants.h" 16 #include "chrome/common/url_constants.h"
17 #include "chrome/grit/generated_resources.h" 17 #include "chrome/grit/generated_resources.h"
18 #include "components/search_engines/template_url.h" 18 #include "components/search_engines/template_url.h"
19 #include "components/search_engines/template_url_service.h" 19 #include "components/search_engines/template_url_service.h"
20 #include "content/public/browser/user_metrics.h" 20 #include "content/public/browser/user_metrics.h"
21 #include "content/public/browser/web_ui.h" 21 #include "content/public/browser/web_ui.h"
22 #include "extensions/browser/extension_registry.h" 22 #include "extensions/browser/extension_registry.h"
23 #include "extensions/browser/extension_system.h"
24 #include "extensions/browser/management_policy.h"
23 #include "extensions/common/extension.h" 25 #include "extensions/common/extension.h"
24 26
25 namespace { 27 namespace {
26 // The following strings need to match with the IDs of the paper-input elements 28 // The following strings need to match with the IDs of the paper-input elements
27 // at settings/search_engines_page/add_search_engine_dialog.html. 29 // at settings/search_engines_page/add_search_engine_dialog.html.
28 const char kSearchEngineField[] = "searchEngine"; 30 const char kSearchEngineField[] = "searchEngine";
29 const char kKeywordField[] = "keyword"; 31 const char kKeywordField[] = "keyword";
30 const char kQueryUrlField[] = "queryUrl"; 32 const char kQueryUrlField[] = "queryUrl";
31 33
32 // Dummy number used for indicating that a new search engine is added. 34 // Dummy number used for indicating that a new search engine is added.
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 // in @typedef for SearchEngine. Please update it whenever you add or remove 159 // in @typedef for SearchEngine. Please update it whenever you add or remove
158 // any keys here. 160 // any keys here.
159 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); 161 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
160 dict->SetString("name", template_url->short_name()); 162 dict->SetString("name", template_url->short_name());
161 dict->SetString("displayName", 163 dict->SetString("displayName",
162 table_model->GetText( 164 table_model->GetText(
163 index, IDS_SEARCH_ENGINES_EDITOR_DESCRIPTION_COLUMN)); 165 index, IDS_SEARCH_ENGINES_EDITOR_DESCRIPTION_COLUMN));
164 dict->SetString( 166 dict->SetString(
165 "keyword", 167 "keyword",
166 table_model->GetText(index, IDS_SEARCH_ENGINES_EDITOR_KEYWORD_COLUMN)); 168 table_model->GetText(index, IDS_SEARCH_ENGINES_EDITOR_KEYWORD_COLUMN));
167 dict->SetString("url", 169 Profile* profile = Profile::FromWebUI(web_ui());
168 template_url->url_ref().DisplayURL( 170 dict->SetString("url", template_url->url_ref().DisplayURL(
169 UIThreadSearchTermsData(Profile::FromWebUI(web_ui())))); 171 UIThreadSearchTermsData(profile)));
170 dict->SetBoolean("urlLocked", template_url->prepopulate_id() > 0); 172 dict->SetBoolean("urlLocked", template_url->prepopulate_id() > 0);
171 GURL icon_url = template_url->favicon_url(); 173 GURL icon_url = template_url->favicon_url();
172 if (icon_url.is_valid()) 174 if (icon_url.is_valid())
173 dict->SetString("iconURL", icon_url.spec()); 175 dict->SetString("iconURL", icon_url.spec());
174 dict->SetInteger("modelIndex", index); 176 dict->SetInteger("modelIndex", index);
175 177
176 dict->SetBoolean("canBeRemoved", list_controller_.CanRemove(template_url)); 178 dict->SetBoolean("canBeRemoved", list_controller_.CanRemove(template_url));
177 dict->SetBoolean("canBeDefault", 179 dict->SetBoolean("canBeDefault",
178 list_controller_.CanMakeDefault(template_url)); 180 list_controller_.CanMakeDefault(template_url));
179 dict->SetBoolean("default", is_default); 181 dict->SetBoolean("default", is_default);
180 dict->SetBoolean("canBeEdited", list_controller_.CanEdit(template_url)); 182 dict->SetBoolean("canBeEdited", list_controller_.CanEdit(template_url));
181 TemplateURL::Type type = template_url->type(); 183 TemplateURL::Type type = template_url->type();
182 dict->SetBoolean("isOmniboxExtension", 184 dict->SetBoolean("isOmniboxExtension",
183 type == TemplateURL::OMNIBOX_API_EXTENSION); 185 type == TemplateURL::OMNIBOX_API_EXTENSION);
184 if (type == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION || 186 if (type == TemplateURL::NORMAL_CONTROLLED_BY_EXTENSION ||
185 type == TemplateURL::OMNIBOX_API_EXTENSION) { 187 type == TemplateURL::OMNIBOX_API_EXTENSION) {
186 const extensions::Extension* extension = 188 const extensions::Extension* extension =
187 extensions::ExtensionRegistry::Get(Profile::FromWebUI(web_ui())) 189 extensions::ExtensionRegistry::Get(profile)->GetExtensionById(
188 ->GetExtensionById(template_url->GetExtensionId(), 190 template_url->GetExtensionId(),
189 extensions::ExtensionRegistry::EVERYTHING); 191 extensions::ExtensionRegistry::EVERYTHING);
190 if (extension) { 192 if (extension) {
191 dict->Set("extension", 193 std::unique_ptr<base::DictionaryValue> ext_info =
192 extensions::util::GetExtensionInfo(extension).release()); 194 extensions::util::GetExtensionInfo(extension);
195 ext_info->SetBoolean("canBeDisabled",
196 !extensions::ExtensionSystem::Get(profile)
197 ->management_policy()
198 ->MustRemainEnabled(extension, nullptr));
199 dict->Set("extension", ext_info.release());
193 } 200 }
194 } 201 }
195 return dict; 202 return dict;
196 } 203 }
197 204
198 void SearchEnginesHandler::HandleGetSearchEnginesList( 205 void SearchEnginesHandler::HandleGetSearchEnginesList(
199 const base::ListValue* args) { 206 const base::ListValue* args) {
200 CHECK_EQ(1U, args->GetSize()); 207 CHECK_EQ(1U, args->GetSize());
201 const base::Value* callback_id; 208 const base::Value* callback_id;
202 CHECK(args->Get(0, &callback_id)); 209 CHECK(args->Get(0, &callback_id));
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 // user calls the right JS functions directly from the web inspector. 332 // user calls the right JS functions directly from the web inspector.
326 if (CheckFieldValidity(kSearchEngineField, search_engine) && 333 if (CheckFieldValidity(kSearchEngineField, search_engine) &&
327 CheckFieldValidity(kKeywordField, keyword) && 334 CheckFieldValidity(kKeywordField, keyword) &&
328 CheckFieldValidity(kQueryUrlField, query_url)) { 335 CheckFieldValidity(kQueryUrlField, query_url)) {
329 edit_controller_->AcceptAddOrEdit(base::UTF8ToUTF16(search_engine), 336 edit_controller_->AcceptAddOrEdit(base::UTF8ToUTF16(search_engine),
330 base::UTF8ToUTF16(keyword), query_url); 337 base::UTF8ToUTF16(keyword), query_url);
331 } 338 }
332 } 339 }
333 340
334 } // namespace settings 341 } // namespace settings
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698