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

Unified Diff: chrome/browser/extensions/api/developer_private/developer_private_api.cc

Issue 954943007: [Extensions] Make chrome://extensions use api functions for file access, reload (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/developer_private/developer_private_api.cc
diff --git a/chrome/browser/extensions/api/developer_private/developer_private_api.cc b/chrome/browser/extensions/api/developer_private/developer_private_api.cc
index d09f8a471de9a114bcbfd4cc9f56611dddc344bc..bf09f0bd94d2e8b022c93ac345d4305087e1705e 100644
--- a/chrome/browser/extensions/api/developer_private/developer_private_api.cc
+++ b/chrome/browser/extensions/api/developer_private/developer_private_api.cc
@@ -90,11 +90,15 @@ namespace developer_private = api::developer_private;
namespace {
const char kNoSuchExtensionError[] = "No such extension.";
+const char kCannotModifyPolicyExtensionError[] =
+ "Cannot modify the extension by policy.";
+const char kRequiresUserGestureError[] =
+ "This action requires a user gesture.";
const char kUnpackedAppsFolder[] = "apps_target";
-ExtensionService* GetExtensionService(Profile* profile) {
- return ExtensionSystem::Get(profile)->extension_service();
+ExtensionService* GetExtensionService(content::BrowserContext* context) {
+ return ExtensionSystem::Get(context)->extension_service();
}
ExtensionUpdater* GetExtensionUpdater(Profile* profile) {
@@ -671,33 +675,33 @@ bool DeveloperPrivateGetItemsInfoFunction::RunAsync() {
DeveloperPrivateGetItemsInfoFunction::~DeveloperPrivateGetItemsInfoFunction() {}
-bool DeveloperPrivateAllowFileAccessFunction::RunSync() {
+ExtensionFunction::ResponseAction
+DeveloperPrivateAllowFileAccessFunction::Run() {
scoped_ptr<AllowFileAccess::Params> params(
AllowFileAccess::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
- EXTENSION_FUNCTION_VALIDATE(user_gesture_);
-
- ExtensionSystem* system = ExtensionSystem::Get(GetProfile());
- ManagementPolicy* management_policy = system->management_policy();
const Extension* extension =
- ExtensionRegistry::Get(GetProfile())
+ ExtensionRegistry::Get(browser_context())
->GetExtensionById(params->item_id, ExtensionRegistry::EVERYTHING);
- bool result = true;
- if (!extension) {
- result = false;
- } else if (!management_policy->UserMayModifySettings(extension, NULL)) {
+ if (!extension)
+ return RespondNow(Error(kNoSuchExtensionError));
+
+ if (!user_gesture())
+ return RespondNow(Error(kRequiresUserGestureError));
+
+ ManagementPolicy* management_policy =
+ ExtensionSystem::Get(browser_context())->management_policy();
+ if (!management_policy->UserMayModifySettings(extension, nullptr)) {
LOG(ERROR) << "Attempt to change allow file access of an extension that "
<< "non-usermanagable was made. Extension id : "
<< extension->id();
- result = false;
- } else {
- util::SetAllowFileAccess(extension->id(), GetProfile(), params->allow);
- result = true;
+ return RespondNow(Error(kCannotModifyPolicyExtensionError));
}
- return result;
+ util::SetAllowFileAccess(extension->id(), browser_context(), params->allow);
+ return RespondNow(NoArguments());
}
DeveloperPrivateAllowFileAccessFunction::
@@ -716,6 +720,9 @@ DeveloperPrivateAllowIncognitoFunction::Run() {
if (!extension)
return RespondNow(Error(kNoSuchExtensionError));
+ if (!user_gesture())
not at google - send to devlin 2015/02/26 00:56:47 ... drive by I guess?
Devlin 2015/02/26 01:14:03 Yes. :)
+ return RespondNow(Error(kRequiresUserGestureError));
+
// Should this take into account policy settings?
util::SetIsIncognitoEnabled(
extension->id(), browser_context(), params->allow);
@@ -726,14 +733,31 @@ DeveloperPrivateAllowIncognitoFunction::Run() {
DeveloperPrivateAllowIncognitoFunction::
~DeveloperPrivateAllowIncognitoFunction() {}
-bool DeveloperPrivateReloadFunction::RunSync() {
+ExtensionFunction::ResponseAction DeveloperPrivateReloadFunction::Run() {
scoped_ptr<Reload::Params> params(Reload::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
- CHECK(!params->item_id.empty());
- ExtensionService* service = GetExtensionService(GetProfile());
- service->ReloadExtension(params->item_id);
- return true;
+ const Extension* extension =
+ ExtensionRegistry::Get(browser_context())
+ ->GetExtensionById(params->item_id, ExtensionRegistry::EVERYTHING);
not at google - send to devlin 2015/02/26 00:56:47 Can we pull this huge 3-line "get me installed ext
Devlin 2015/02/26 01:14:03 Was meaning to do that for awhile. Done.
+ if (!extension)
+ return RespondNow(Error(kNoSuchExtensionError));
+
+ // Default to failing "noisily".
not at google - send to devlin 2015/02/26 00:56:47 comment unnecssary
Devlin 2015/02/26 01:14:03 Done.
+ bool fail_quietly =
+ params->options.get() &&
+ params->options->fail_quietly.get() &&
+ *params->options->fail_quietly;
+
+ ExtensionService* service = GetExtensionService(browser_context());
+ if (fail_quietly)
+ service->ReloadExtensionWithQuietFailure(params->item_id);
+ else
+ service->ReloadExtension(params->item_id);
+
+ // TODO(devlin): We shouldn't return until the extension has finished trying
+ // to reload (and then we could also return the error).
+ return RespondNow(NoArguments());
}
bool DeveloperPrivateShowPermissionsDialogFunction::RunSync() {

Powered by Google App Engine
This is Rietveld 408576698