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

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

Issue 997183005: [Extensions] Add a developerPrivate.updateExtensionConfiguration function (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "chrome/browser/devtools/devtools_window.h" 14 #include "chrome/browser/devtools/devtools_window.h"
15 #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"
16 #include "chrome/browser/extensions/api/developer_private/entry_picker.h" 16 #include "chrome/browser/extensions/api/developer_private/entry_picker.h"
17 #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"
18 #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"
19 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
19 #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"
20 #include "chrome/browser/extensions/devtools_util.h" 21 #include "chrome/browser/extensions/devtools_util.h"
21 #include "chrome/browser/extensions/extension_service.h" 22 #include "chrome/browser/extensions/extension_service.h"
22 #include "chrome/browser/extensions/extension_ui_util.h" 23 #include "chrome/browser/extensions/extension_ui_util.h"
23 #include "chrome/browser/extensions/extension_util.h" 24 #include "chrome/browser/extensions/extension_util.h"
24 #include "chrome/browser/extensions/shared_module_service.h" 25 #include "chrome/browser/extensions/shared_module_service.h"
25 #include "chrome/browser/extensions/unpacked_installer.h" 26 #include "chrome/browser/extensions/unpacked_installer.h"
26 #include "chrome/browser/extensions/updater/extension_updater.h" 27 #include "chrome/browser/extensions/updater/extension_updater.h"
27 #include "chrome/browser/profiles/profile.h" 28 #include "chrome/browser/profiles/profile.h"
28 #include "chrome/browser/ui/browser_finder.h" 29 #include "chrome/browser/ui/browser_finder.h"
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 developer_private::OnItemStateChanged::kEventName, args.Pass())); 159 developer_private::OnItemStateChanged::kEventName, args.Pass()));
159 EventRouter::Get(browser_context)->BroadcastEvent(event.Pass()); 160 EventRouter::Get(browser_context)->BroadcastEvent(event.Pass());
160 } 161 }
161 162
162 std::string ReadFileToString(const base::FilePath& path) { 163 std::string ReadFileToString(const base::FilePath& path) {
163 std::string data; 164 std::string data;
164 ignore_result(base::ReadFileToString(path, &data)); 165 ignore_result(base::ReadFileToString(path, &data));
165 return data; 166 return data;
166 } 167 }
167 168
169 bool UserCanModifyExtensionConfiguration(
170 const Extension* extension,
171 content::BrowserContext* browser_context,
172 std::string* error) {
173 // Currently, we only gate file access modification on account permissions.
174 if (util::IsExtensionSupervised(
175 extension, Profile::FromBrowserContext(browser_context))) {
176 *error = kSupervisedUserError;
177 return false;
178 }
179
180 ManagementPolicy* management_policy =
181 ExtensionSystem::Get(browser_context)->management_policy();
182 if (!management_policy->UserMayModifySettings(extension, nullptr)) {
183 LOG(ERROR) << "Attempt to change allow file access of an extension that "
184 << "non-usermanagable was made. Extension id : "
185 << extension->id();
186 *error = kCannotModifyPolicyExtensionError;
187 return false;
188 }
189
190 return true;
191 }
192
168 } // namespace 193 } // namespace
169 194
170 namespace AllowFileAccess = api::developer_private::AllowFileAccess;
171 namespace AllowIncognito = api::developer_private::AllowIncognito;
172 namespace ChoosePath = api::developer_private::ChoosePath; 195 namespace ChoosePath = api::developer_private::ChoosePath;
173 namespace GetItemsInfo = api::developer_private::GetItemsInfo; 196 namespace GetItemsInfo = api::developer_private::GetItemsInfo;
174 namespace Inspect = api::developer_private::Inspect; 197 namespace Inspect = api::developer_private::Inspect;
175 namespace PackDirectory = api::developer_private::PackDirectory; 198 namespace PackDirectory = api::developer_private::PackDirectory;
176 namespace Reload = api::developer_private::Reload; 199 namespace Reload = api::developer_private::Reload;
177 200
178 static base::LazyInstance<BrowserContextKeyedAPIFactory<DeveloperPrivateAPI> > 201 static base::LazyInstance<BrowserContextKeyedAPIFactory<DeveloperPrivateAPI> >
179 g_factory = LAZY_INSTANCE_INITIALIZER; 202 g_factory = LAZY_INSTANCE_INITIALIZER;
180 203
181 // static 204 // static
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 registry->enabled_extensions().GetByID(params->id); 422 registry->enabled_extensions().GetByID(params->id);
400 if (!extension && 423 if (!extension &&
401 (extension = registry->disabled_extensions().GetByID(params->id)) != 424 (extension = registry->disabled_extensions().GetByID(params->id)) !=
402 nullptr) { 425 nullptr) {
403 state = developer::EXTENSION_STATE_DISABLED; 426 state = developer::EXTENSION_STATE_DISABLED;
404 } else if (!extension && 427 } else if (!extension &&
405 (extension = 428 (extension =
406 registry->terminated_extensions().GetByID(params->id)) != 429 registry->terminated_extensions().GetByID(params->id)) !=
407 nullptr) { 430 nullptr) {
408 state = developer::EXTENSION_STATE_TERMINATED; 431 state = developer::EXTENSION_STATE_TERMINATED;
409 } else { 432 }
433
434 if (!extension)
410 return RespondNow(Error(kNoSuchExtensionError)); 435 return RespondNow(Error(kNoSuchExtensionError));
411 }
412 436
413 return RespondNow(OneArgument(ExtensionInfoGenerator(browser_context()). 437 return RespondNow(OneArgument(ExtensionInfoGenerator(browser_context()).
414 CreateExtensionInfo(*extension, state)->ToValue().release())); 438 CreateExtensionInfo(*extension, state)->ToValue().release()));
415 } 439 }
416 440
417 DeveloperPrivateGetItemsInfoFunction::DeveloperPrivateGetItemsInfoFunction() {} 441 DeveloperPrivateGetItemsInfoFunction::DeveloperPrivateGetItemsInfoFunction() {}
418 DeveloperPrivateGetItemsInfoFunction::~DeveloperPrivateGetItemsInfoFunction() {} 442 DeveloperPrivateGetItemsInfoFunction::~DeveloperPrivateGetItemsInfoFunction() {}
419 443
420 ExtensionFunction::ResponseAction DeveloperPrivateGetItemsInfoFunction::Run() { 444 ExtensionFunction::ResponseAction DeveloperPrivateGetItemsInfoFunction::Run() {
421 scoped_ptr<developer::GetItemsInfo::Params> params( 445 scoped_ptr<developer::GetItemsInfo::Params> params(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 content::BrowserThread::PostTask( 498 content::BrowserThread::PostTask(
475 content::BrowserThread::UI, 499 content::BrowserThread::UI,
476 FROM_HERE, 500 FROM_HERE,
477 base::Bind(&DeveloperPrivateGetItemsInfoFunction::Finish, this)); 501 base::Bind(&DeveloperPrivateGetItemsInfoFunction::Finish, this));
478 } 502 }
479 503
480 void DeveloperPrivateGetItemsInfoFunction::Finish() { 504 void DeveloperPrivateGetItemsInfoFunction::Finish() {
481 Respond(ArgumentList(developer::GetItemsInfo::Results::Create(item_list_))); 505 Respond(ArgumentList(developer::GetItemsInfo::Results::Create(item_list_)));
482 } 506 }
483 507
508 DeveloperPrivateUpdateExtensionConfigurationFunction::
509 ~DeveloperPrivateUpdateExtensionConfigurationFunction() {}
510
484 ExtensionFunction::ResponseAction 511 ExtensionFunction::ResponseAction
485 DeveloperPrivateAllowFileAccessFunction::Run() { 512 DeveloperPrivateUpdateExtensionConfigurationFunction::Run() {
486 scoped_ptr<AllowFileAccess::Params> params( 513 scoped_ptr<developer::UpdateExtensionConfiguration::Params> params(
487 AllowFileAccess::Params::Create(*args_)); 514 developer::UpdateExtensionConfiguration::Params::Create(*args_));
488 EXTENSION_FUNCTION_VALIDATE(params.get()); 515 EXTENSION_FUNCTION_VALIDATE(params);
489 516
490 const Extension* extension = GetExtensionById(params->extension_id); 517 const developer::ExtensionConfigurationUpdate& update = params->update;
491 518
519 const Extension* extension = GetExtensionById(update.extension_id);
492 if (!extension) 520 if (!extension)
493 return RespondNow(Error(kNoSuchExtensionError)); 521 return RespondNow(Error(kNoSuchExtensionError));
494
495 if (!user_gesture()) 522 if (!user_gesture())
496 return RespondNow(Error(kRequiresUserGestureError)); 523 return RespondNow(Error(kRequiresUserGestureError));
497 524
498 if (util::IsExtensionSupervised( 525 if (update.file_access) {
499 extension, Profile::FromBrowserContext(browser_context()))) { 526 std::string error;
500 return RespondNow(Error(kSupervisedUserError)); 527 if (!UserCanModifyExtensionConfiguration(extension,
528 browser_context(),
529 &error)) {
530 return RespondNow(Error(error));
531 }
532 util::SetAllowFileAccess(
533 extension->id(), browser_context(), *update.file_access);
501 } 534 }
502 535 if (update.incognito_access) {
503 ManagementPolicy* management_policy = 536 util::SetIsIncognitoEnabled(
504 ExtensionSystem::Get(browser_context())->management_policy(); 537 extension->id(), browser_context(), *update.incognito_access);
505 if (!management_policy->UserMayModifySettings(extension, nullptr)) {
506 LOG(ERROR) << "Attempt to change allow file access of an extension that "
507 << "non-usermanagable was made. Extension id : "
508 << extension->id();
509 return RespondNow(Error(kCannotModifyPolicyExtensionError));
510 } 538 }
511 539 if (update.error_collection) {
512 util::SetAllowFileAccess(extension->id(), browser_context(), params->allow); 540 ErrorConsole::Get(browser_context())->SetReportingAllForExtension(
513 return RespondNow(NoArguments()); 541 extension->id(), *update.error_collection);
514 } 542 }
515 543 if (update.run_on_all_urls) {
516 DeveloperPrivateAllowFileAccessFunction:: 544 util::SetAllowedScriptingOnAllUrls(
517 ~DeveloperPrivateAllowFileAccessFunction() {} 545 extension->id(), browser_context(), *update.run_on_all_urls);
518 546 }
519 ExtensionFunction::ResponseAction 547 if (update.show_action_button) {
520 DeveloperPrivateAllowIncognitoFunction::Run() { 548 ExtensionActionAPI::SetBrowserActionVisibility(
521 scoped_ptr<AllowIncognito::Params> params( 549 ExtensionPrefs::Get(browser_context()),
522 AllowIncognito::Params::Create(*args_)); 550 extension->id(),
523 EXTENSION_FUNCTION_VALIDATE(params.get()); 551 *update.show_action_button);
524 552 }
525 const Extension* extension = GetExtensionById(params->extension_id);
526
527 if (!extension)
528 return RespondNow(Error(kNoSuchExtensionError));
529
530 if (!user_gesture())
531 return RespondNow(Error(kRequiresUserGestureError));
532
533 // Should this take into account policy settings?
534 util::SetIsIncognitoEnabled(
535 extension->id(), browser_context(), params->allow);
536 553
537 return RespondNow(NoArguments()); 554 return RespondNow(NoArguments());
538 } 555 }
539 556
540 DeveloperPrivateAllowIncognitoFunction::
541 ~DeveloperPrivateAllowIncognitoFunction() {}
542
543 DeveloperPrivateReloadFunction::~DeveloperPrivateReloadFunction() {} 557 DeveloperPrivateReloadFunction::~DeveloperPrivateReloadFunction() {}
544 558
545 ExtensionFunction::ResponseAction DeveloperPrivateReloadFunction::Run() { 559 ExtensionFunction::ResponseAction DeveloperPrivateReloadFunction::Run() {
546 scoped_ptr<Reload::Params> params(Reload::Params::Create(*args_)); 560 scoped_ptr<Reload::Params> params(Reload::Params::Create(*args_));
547 EXTENSION_FUNCTION_VALIDATE(params.get()); 561 EXTENSION_FUNCTION_VALIDATE(params.get());
548 562
549 const Extension* extension = GetExtensionById(params->extension_id); 563 const Extension* extension = GetExtensionById(params->extension_id);
550 if (!extension) 564 if (!extension)
551 return RespondNow(Error(kNoSuchExtensionError)); 565 return RespondNow(Error(kNoSuchExtensionError));
552 566
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 1239
1226 TabStripModel* tab_strip = browser->tab_strip_model(); 1240 TabStripModel* tab_strip = browser->tab_strip_model();
1227 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(web_contents), 1241 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(web_contents),
1228 false); // Not through direct user gesture. 1242 false); // Not through direct user gesture.
1229 return RespondNow(NoArguments()); 1243 return RespondNow(NoArguments());
1230 } 1244 }
1231 1245
1232 } // namespace api 1246 } // namespace api
1233 1247
1234 } // namespace extensions 1248 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698