Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "apps/app_load_service.h" | 7 #include "apps/app_load_service.h" |
| 8 #include "apps/saved_files_service.h" | 8 #include "apps/saved_files_service.h" |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/files/file_util.h" | 11 #include "base/files/file_util.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "chrome/browser/devtools/devtools_window.h" | 16 #include "chrome/browser/devtools/devtools_window.h" |
| 17 #include "chrome/browser/extensions/api/developer_private/developer_private_mang le.h" | 17 #include "chrome/browser/extensions/api/developer_private/developer_private_mang le.h" |
| 18 #include "chrome/browser/extensions/api/developer_private/entry_picker.h" | 18 #include "chrome/browser/extensions/api/developer_private/entry_picker.h" |
| 19 #include "chrome/browser/extensions/api/developer_private/extension_info_generat or.h" | 19 #include "chrome/browser/extensions/api/developer_private/extension_info_generat or.h" |
| 20 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | |
| 20 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" | 21 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" |
| 21 #include "chrome/browser/extensions/devtools_util.h" | 22 #include "chrome/browser/extensions/devtools_util.h" |
| 22 #include "chrome/browser/extensions/extension_service.h" | 23 #include "chrome/browser/extensions/extension_service.h" |
| 23 #include "chrome/browser/extensions/extension_ui_util.h" | 24 #include "chrome/browser/extensions/extension_ui_util.h" |
| 24 #include "chrome/browser/extensions/extension_util.h" | 25 #include "chrome/browser/extensions/extension_util.h" |
| 25 #include "chrome/browser/extensions/shared_module_service.h" | 26 #include "chrome/browser/extensions/shared_module_service.h" |
| 26 #include "chrome/browser/extensions/unpacked_installer.h" | 27 #include "chrome/browser/extensions/unpacked_installer.h" |
| 27 #include "chrome/browser/extensions/updater/extension_updater.h" | 28 #include "chrome/browser/extensions/updater/extension_updater.h" |
| 28 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
| 29 #include "chrome/browser/ui/browser_finder.h" | 30 #include "chrome/browser/ui/browser_finder.h" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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) { |
|
not at google - send to devlin
2015/03/17 14:31:31
I like it.
| |
| 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 ExtensionFunction::ResponseAction DeveloperPrivateReloadFunction::Run() { | 557 ExtensionFunction::ResponseAction DeveloperPrivateReloadFunction::Run() { |
| 544 scoped_ptr<Reload::Params> params(Reload::Params::Create(*args_)); | 558 scoped_ptr<Reload::Params> params(Reload::Params::Create(*args_)); |
| 545 EXTENSION_FUNCTION_VALIDATE(params.get()); | 559 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 546 | 560 |
| 547 const Extension* extension = GetExtensionById(params->extension_id); | 561 const Extension* extension = GetExtensionById(params->extension_id); |
| 548 if (!extension) | 562 if (!extension) |
| 549 return RespondNow(Error(kNoSuchExtensionError)); | 563 return RespondNow(Error(kNoSuchExtensionError)); |
| 550 | 564 |
| 551 bool fail_quietly = params->options && | 565 bool fail_quietly = params->options && |
| 552 params->options->fail_quietly && | 566 params->options->fail_quietly && |
| (...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1255 | 1269 |
| 1256 TabStripModel* tab_strip = browser->tab_strip_model(); | 1270 TabStripModel* tab_strip = browser->tab_strip_model(); |
| 1257 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(web_contents), | 1271 tab_strip->ActivateTabAt(tab_strip->GetIndexOfWebContents(web_contents), |
| 1258 false); // Not through direct user gesture. | 1272 false); // Not through direct user gesture. |
| 1259 return RespondNow(NoArguments()); | 1273 return RespondNow(NoArguments()); |
| 1260 } | 1274 } |
| 1261 | 1275 |
| 1262 } // namespace api | 1276 } // namespace api |
| 1263 | 1277 |
| 1264 } // namespace extensions | 1278 } // namespace extensions |
| OLD | NEW |