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

Side by Side Diff: chrome/browser/extensions/api/developer_private/developer_private_api.cc

Issue 1083573002: Revert https://codereview.chromium.org/1060993003 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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/extensions/api/developer_private/developer_private_api. h" 5 #include "chrome/browser/extensions/api/developer_private/developer_private_api. h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/files/file_util.h" 9 #include "base/files/file_util.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/metrics/histogram_macros.h"
12 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
14 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
15 #include "chrome/browser/devtools/devtools_window.h" 14 #include "chrome/browser/devtools/devtools_window.h"
16 #include "chrome/browser/extensions/api/developer_private/developer_private_mang le.h" 15 #include "chrome/browser/extensions/api/developer_private/developer_private_mang le.h"
17 #include "chrome/browser/extensions/api/developer_private/entry_picker.h" 16 #include "chrome/browser/extensions/api/developer_private/entry_picker.h"
18 #include "chrome/browser/extensions/api/developer_private/extension_info_generat or.h" 17 #include "chrome/browser/extensions/api/developer_private/extension_info_generat or.h"
19 #include "chrome/browser/extensions/api/developer_private/show_permissions_dialo g_helper.h" 18 #include "chrome/browser/extensions/api/developer_private/show_permissions_dialo g_helper.h"
20 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" 19 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
21 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" 20 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h"
22 #include "chrome/browser/extensions/devtools_util.h" 21 #include "chrome/browser/extensions/devtools_util.h"
23 #include "chrome/browser/extensions/extension_service.h" 22 #include "chrome/browser/extensions/extension_service.h"
24 #include "chrome/browser/extensions/extension_ui_util.h" 23 #include "chrome/browser/extensions/extension_ui_util.h"
25 #include "chrome/browser/extensions/extension_util.h" 24 #include "chrome/browser/extensions/extension_util.h"
26 #include "chrome/browser/extensions/install_verifier.h"
27 #include "chrome/browser/extensions/shared_module_service.h" 25 #include "chrome/browser/extensions/shared_module_service.h"
28 #include "chrome/browser/extensions/unpacked_installer.h" 26 #include "chrome/browser/extensions/unpacked_installer.h"
29 #include "chrome/browser/extensions/updater/extension_updater.h" 27 #include "chrome/browser/extensions/updater/extension_updater.h"
30 #include "chrome/browser/prefs/incognito_mode_prefs.h"
31 #include "chrome/browser/profiles/profile.h" 28 #include "chrome/browser/profiles/profile.h"
32 #include "chrome/browser/ui/apps/app_info_dialog.h"
33 #include "chrome/browser/ui/browser_finder.h" 29 #include "chrome/browser/ui/browser_finder.h"
34 #include "chrome/browser/ui/tabs/tab_strip_model.h" 30 #include "chrome/browser/ui/tabs/tab_strip_model.h"
35 #include "chrome/common/extensions/api/developer_private.h" 31 #include "chrome/common/extensions/api/developer_private.h"
36 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" 32 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
37 #include "chrome/common/pref_names.h"
38 #include "chrome/common/url_constants.h" 33 #include "chrome/common/url_constants.h"
39 #include "chrome/grit/generated_resources.h" 34 #include "chrome/grit/generated_resources.h"
40 #include "content/public/browser/browser_thread.h" 35 #include "content/public/browser/browser_thread.h"
41 #include "content/public/browser/notification_service.h" 36 #include "content/public/browser/notification_service.h"
42 #include "content/public/browser/render_process_host.h" 37 #include "content/public/browser/render_process_host.h"
43 #include "content/public/browser/render_view_host.h" 38 #include "content/public/browser/render_view_host.h"
44 #include "content/public/browser/site_instance.h" 39 #include "content/public/browser/site_instance.h"
45 #include "content/public/browser/storage_partition.h" 40 #include "content/public/browser/storage_partition.h"
46 #include "content/public/browser/web_contents.h" 41 #include "content/public/browser/web_contents.h"
47 #include "extensions/browser/app_window/app_window.h" 42 #include "extensions/browser/app_window/app_window.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 const char kCouldNotShowSelectFileDialogError[] = 81 const char kCouldNotShowSelectFileDialogError[] =
87 "Could not show a file chooser."; 82 "Could not show a file chooser.";
88 const char kFileSelectionCanceled[] = 83 const char kFileSelectionCanceled[] =
89 "File selection was canceled."; 84 "File selection was canceled.";
90 const char kNoSuchRendererError[] = "No such renderer."; 85 const char kNoSuchRendererError[] = "No such renderer.";
91 const char kInvalidPathError[] = "Invalid path."; 86 const char kInvalidPathError[] = "Invalid path.";
92 const char kManifestKeyIsRequiredError[] = 87 const char kManifestKeyIsRequiredError[] =
93 "The 'manifestKey' argument is required for manifest files."; 88 "The 'manifestKey' argument is required for manifest files.";
94 const char kCouldNotFindWebContentsError[] = 89 const char kCouldNotFindWebContentsError[] =
95 "Could not find a valid web contents."; 90 "Could not find a valid web contents.";
96 const char kCannotUpdateSupervisedProfileSettingsError[] =
97 "Cannot change settings for a supervised profile.";
98 91
99 const char kUnpackedAppsFolder[] = "apps_target"; 92 const char kUnpackedAppsFolder[] = "apps_target";
100 const char kManifestFile[] = "manifest.json"; 93 const char kManifestFile[] = "manifest.json";
101 94
102 ExtensionService* GetExtensionService(content::BrowserContext* context) { 95 ExtensionService* GetExtensionService(content::BrowserContext* context) {
103 return ExtensionSystem::Get(context)->extension_service(); 96 return ExtensionSystem::Get(context)->extension_service();
104 } 97 }
105 98
106 ExtensionUpdater* GetExtensionUpdater(Profile* profile) { 99 ExtensionUpdater* GetExtensionUpdater(Profile* profile) {
107 return GetExtensionService(profile)->updater(); 100 return GetExtensionService(profile)->updater();
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 LOG(ERROR) << "Attempt to change settings of an extension that is " 170 LOG(ERROR) << "Attempt to change settings of an extension that is "
178 << "non-usermanagable was made. Extension id : " 171 << "non-usermanagable was made. Extension id : "
179 << extension->id(); 172 << extension->id();
180 *error = kCannotModifyPolicyExtensionError; 173 *error = kCannotModifyPolicyExtensionError;
181 return false; 174 return false;
182 } 175 }
183 176
184 return true; 177 return true;
185 } 178 }
186 179
187 // Runs the install verifier for all extensions that are enabled, disabled, or
188 // terminated.
189 void PerformVerificationCheck(content::BrowserContext* context) {
190 scoped_ptr<ExtensionSet> extensions =
191 ExtensionRegistry::Get(context)->GenerateInstalledExtensionsSet(
192 ExtensionRegistry::ENABLED |
193 ExtensionRegistry::DISABLED |
194 ExtensionRegistry::TERMINATED);
195 ExtensionPrefs* prefs = ExtensionPrefs::Get(context);
196 bool should_do_verification_check = false;
197 for (const scoped_refptr<const Extension>& extension : *extensions) {
198 if (ui_util::ShouldDisplayInExtensionSettings(extension.get(), context) &&
199 ((prefs->GetDisableReasons(extension->id()) &
200 Extension::DISABLE_NOT_VERIFIED) != 0)) {
201 should_do_verification_check = true;
202 break;
203 }
204 }
205
206 UMA_HISTOGRAM_BOOLEAN("ExtensionSettings.ShouldDoVerificationCheck",
207 should_do_verification_check);
208 if (should_do_verification_check)
209 ExtensionSystem::Get(context)->install_verifier()->VerifyAllExtensions();
210 }
211
212 } // namespace 180 } // namespace
213 181
214 namespace ChoosePath = api::developer_private::ChoosePath; 182 namespace ChoosePath = api::developer_private::ChoosePath;
215 namespace GetItemsInfo = api::developer_private::GetItemsInfo; 183 namespace GetItemsInfo = api::developer_private::GetItemsInfo;
216 namespace PackDirectory = api::developer_private::PackDirectory; 184 namespace PackDirectory = api::developer_private::PackDirectory;
217 namespace Reload = api::developer_private::Reload; 185 namespace Reload = api::developer_private::Reload;
218 186
219 static base::LazyInstance<BrowserContextKeyedAPIFactory<DeveloperPrivateAPI> > 187 static base::LazyInstance<BrowserContextKeyedAPIFactory<DeveloperPrivateAPI> >
220 g_factory = LAZY_INSTANCE_INITIALIZER; 188 g_factory = LAZY_INSTANCE_INITIALIZER;
221 189
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 content::BrowserThread::PostTask( 449 content::BrowserThread::PostTask(
482 content::BrowserThread::UI, 450 content::BrowserThread::UI,
483 FROM_HERE, 451 FROM_HERE,
484 base::Bind(&DeveloperPrivateGetItemsInfoFunction::Finish, this)); 452 base::Bind(&DeveloperPrivateGetItemsInfoFunction::Finish, this));
485 } 453 }
486 454
487 void DeveloperPrivateGetItemsInfoFunction::Finish() { 455 void DeveloperPrivateGetItemsInfoFunction::Finish() {
488 Respond(ArgumentList(developer::GetItemsInfo::Results::Create(item_list_))); 456 Respond(ArgumentList(developer::GetItemsInfo::Results::Create(item_list_)));
489 } 457 }
490 458
491 DeveloperPrivateGetProfileConfigurationFunction::
492 ~DeveloperPrivateGetProfileConfigurationFunction() {
493 }
494
495 ExtensionFunction::ResponseAction
496 DeveloperPrivateGetProfileConfigurationFunction::Run() {
497 developer::ProfileInfo info;
498 info.is_supervised = GetProfile()->IsSupervised();
499 info.is_incognito_available =
500 IncognitoModePrefs::GetAvailability(GetProfile()->GetPrefs()) !=
501 IncognitoModePrefs::DISABLED;
502 info.in_developer_mode =
503 !info.is_supervised &&
504 GetProfile()->GetPrefs()->GetBoolean(prefs::kExtensionsUIDeveloperMode);
505 info.app_info_dialog_enabled = CanShowAppInfoDialog();
506 info.can_load_unpacked =
507 !ExtensionManagementFactory::GetForBrowserContext(browser_context())
508 ->BlacklistedByDefault();
509
510 // If this is called from the chrome://extensions page, we use this as a
511 // heuristic that it's a good time to verify installs. We do this on startup,
512 // but there's a chance that it failed erroneously, so it's good to double-
513 // check.
514 if (source_context_type() == Feature::WEBUI_CONTEXT)
515 PerformVerificationCheck(browser_context());
516
517 return RespondNow(OneArgument(info.ToValue()));
518 }
519
520 DeveloperPrivateUpdateProfileConfigurationFunction::
521 ~DeveloperPrivateUpdateProfileConfigurationFunction() {
522 }
523
524 ExtensionFunction::ResponseAction
525 DeveloperPrivateUpdateProfileConfigurationFunction::Run() {
526 scoped_ptr<developer::UpdateProfileConfiguration::Params> params(
527 developer::UpdateProfileConfiguration::Params::Create(*args_));
528 EXTENSION_FUNCTION_VALIDATE(params);
529
530 const developer::ProfileConfigurationUpdate& update = params->update;
531 PrefService* prefs = GetProfile()->GetPrefs();
532 if (update.in_developer_mode) {
533 if (GetProfile()->IsSupervised())
534 return RespondNow(Error(kCannotUpdateSupervisedProfileSettingsError));
535 prefs->SetBoolean(prefs::kExtensionsUIDeveloperMode,
536 *update.in_developer_mode);
537 }
538
539 return RespondNow(NoArguments());
540 }
541
542 DeveloperPrivateUpdateExtensionConfigurationFunction:: 459 DeveloperPrivateUpdateExtensionConfigurationFunction::
543 ~DeveloperPrivateUpdateExtensionConfigurationFunction() {} 460 ~DeveloperPrivateUpdateExtensionConfigurationFunction() {}
544 461
545 ExtensionFunction::ResponseAction 462 ExtensionFunction::ResponseAction
546 DeveloperPrivateUpdateExtensionConfigurationFunction::Run() { 463 DeveloperPrivateUpdateExtensionConfigurationFunction::Run() {
547 scoped_ptr<developer::UpdateExtensionConfiguration::Params> params( 464 scoped_ptr<developer::UpdateExtensionConfiguration::Params> params(
548 developer::UpdateExtensionConfiguration::Params::Create(*args_)); 465 developer::UpdateExtensionConfiguration::Params::Create(*args_));
549 EXTENSION_FUNCTION_VALIDATE(params); 466 EXTENSION_FUNCTION_VALIDATE(params);
550 467
551 const developer::ExtensionConfigurationUpdate& update = params->update; 468 const developer::ExtensionConfigurationUpdate& update = params->update;
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 const developer::OpenDevToolsProperties& properties = params->properties; 1102 const developer::OpenDevToolsProperties& properties = params->properties;
1186 1103
1187 if (properties.render_process_id == -1) { 1104 if (properties.render_process_id == -1) {
1188 // This is a lazy background page. 1105 // This is a lazy background page.
1189 const Extension* extension = properties.extension_id ? 1106 const Extension* extension = properties.extension_id ?
1190 ExtensionRegistry::Get(browser_context())->enabled_extensions().GetByID( 1107 ExtensionRegistry::Get(browser_context())->enabled_extensions().GetByID(
1191 *properties.extension_id) : nullptr; 1108 *properties.extension_id) : nullptr;
1192 if (!extension) 1109 if (!extension)
1193 return RespondNow(Error(kNoSuchExtensionError)); 1110 return RespondNow(Error(kNoSuchExtensionError));
1194 1111
1195 Profile* profile = GetProfile(); 1112 Profile* profile = Profile::FromBrowserContext(browser_context());
1196 if (properties.incognito && *properties.incognito) 1113 if (properties.incognito && *properties.incognito)
1197 profile = profile->GetOffTheRecordProfile(); 1114 profile = profile->GetOffTheRecordProfile();
1198 1115
1199 // Wakes up the background page and opens the inspect window. 1116 // Wakes up the background page and opens the inspect window.
1200 devtools_util::InspectBackgroundPage(extension, profile); 1117 devtools_util::InspectBackgroundPage(extension, profile);
1201 return RespondNow(NoArguments()); 1118 return RespondNow(NoArguments());
1202 } 1119 }
1203 1120
1204 content::RenderViewHost* rvh = 1121 content::RenderViewHost* rvh =
1205 content::RenderViewHost::FromID(properties.render_process_id, 1122 content::RenderViewHost::FromID(properties.render_process_id,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 ~DeveloperPrivateDeleteExtensionErrorsFunction() {} 1164 ~DeveloperPrivateDeleteExtensionErrorsFunction() {}
1248 1165
1249 ExtensionFunction::ResponseAction 1166 ExtensionFunction::ResponseAction
1250 DeveloperPrivateDeleteExtensionErrorsFunction::Run() { 1167 DeveloperPrivateDeleteExtensionErrorsFunction::Run() {
1251 scoped_ptr<developer::DeleteExtensionErrors::Params> params( 1168 scoped_ptr<developer::DeleteExtensionErrors::Params> params(
1252 developer::DeleteExtensionErrors::Params::Create(*args_)); 1169 developer::DeleteExtensionErrors::Params::Create(*args_));
1253 EXTENSION_FUNCTION_VALIDATE(params); 1170 EXTENSION_FUNCTION_VALIDATE(params);
1254 const developer::DeleteExtensionErrorsProperties& properties = 1171 const developer::DeleteExtensionErrorsProperties& properties =
1255 params->properties; 1172 params->properties;
1256 1173
1257 ErrorConsole* error_console = ErrorConsole::Get(GetProfile()); 1174 ErrorConsole* error_console =
1175 ErrorConsole::Get(Profile::FromBrowserContext(browser_context()));
1258 int type = -1; 1176 int type = -1;
1259 if (properties.type != developer::ERROR_TYPE_NONE) { 1177 if (properties.type != developer::ERROR_TYPE_NONE) {
1260 type = properties.type == developer::ERROR_TYPE_MANIFEST ? 1178 type = properties.type == developer::ERROR_TYPE_MANIFEST ?
1261 ExtensionError::MANIFEST_ERROR : ExtensionError::RUNTIME_ERROR; 1179 ExtensionError::MANIFEST_ERROR : ExtensionError::RUNTIME_ERROR;
1262 } 1180 }
1263 std::set<int> error_ids; 1181 std::set<int> error_ids;
1264 if (properties.error_ids) { 1182 if (properties.error_ids) {
1265 error_ids.insert(properties.error_ids->begin(), 1183 error_ids.insert(properties.error_ids->begin(),
1266 properties.error_ids->end()); 1184 properties.error_ids->end());
1267 } 1185 }
1268 error_console->RemoveErrors(ErrorMap::Filter( 1186 error_console->RemoveErrors(ErrorMap::Filter(
1269 properties.extension_id, type, error_ids, false)); 1187 properties.extension_id, type, error_ids, false));
1270 1188
1271 return RespondNow(NoArguments()); 1189 return RespondNow(NoArguments());
1272 } 1190 }
1273 1191
1274 } // namespace api 1192 } // namespace api
1275 1193
1276 } // namespace extensions 1194 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698