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 "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 | 65 |
66 const char kDataURLPrefix[] = "data:image;base64,"; | 66 const char kDataURLPrefix[] = "data:image;base64,"; |
67 return GURL(kDataURLPrefix + contents_base64); | 67 return GURL(kDataURLPrefix + contents_base64); |
68 } | 68 } |
69 | 69 |
70 | 70 |
71 } // namespace | 71 } // namespace |
72 | 72 |
73 namespace extensions { | 73 namespace extensions { |
74 | 74 |
75 namespace AllowFileAccess = api::developer_private::AllowFileAccess; | |
76 namespace AllowIncognito = api::developer_private::AllowIncognito; | |
77 namespace ChoosePath = api::developer_private::ChoosePath; | |
78 namespace Enable = api::developer_private::Enable; | |
79 namespace GetItemsInfo = api::developer_private::GetItemsInfo; | |
80 namespace Inspect = api::developer_private::Inspect; | |
81 namespace PackDirectory = api::developer_private::PackDirectory; | |
82 namespace Reload = api::developer_private::Reload; | |
83 namespace Restart = api::developer_private::Restart; | |
84 | |
75 DeveloperPrivateAPI* DeveloperPrivateAPI::Get(Profile* profile) { | 85 DeveloperPrivateAPI* DeveloperPrivateAPI::Get(Profile* profile) { |
76 return DeveloperPrivateAPIFactory::GetForProfile(profile); | 86 return DeveloperPrivateAPIFactory::GetForProfile(profile); |
77 } | 87 } |
78 | 88 |
79 DeveloperPrivateAPI::DeveloperPrivateAPI(Profile* profile) { | 89 DeveloperPrivateAPI::DeveloperPrivateAPI(Profile* profile) { |
80 | 90 |
81 RegisterNotifications(); | 91 RegisterNotifications(); |
82 } | 92 } |
83 | 93 |
84 | 94 |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
378 base::Bind(&DeveloperPrivateGetItemsInfoFunction::GetIconsOnFileThread, | 388 base::Bind(&DeveloperPrivateGetItemsInfoFunction::GetIconsOnFileThread, |
379 this, | 389 this, |
380 item_list, | 390 item_list, |
381 id_to_icon)); | 391 id_to_icon)); |
382 return true; | 392 return true; |
383 } | 393 } |
384 | 394 |
385 DeveloperPrivateGetItemsInfoFunction::~DeveloperPrivateGetItemsInfoFunction() {} | 395 DeveloperPrivateGetItemsInfoFunction::~DeveloperPrivateGetItemsInfoFunction() {} |
386 | 396 |
387 bool DeveloperPrivateAllowFileAccessFunction::RunImpl() { | 397 bool DeveloperPrivateAllowFileAccessFunction::RunImpl() { |
388 std::string extension_id; | 398 scoped_ptr<AllowFileAccess::Params> params( |
389 bool allow = false; | 399 AllowFileAccess::Params::Create(*args_)); |
400 EXTENSION_FUNCTION_VALIDATE(params.get()); | |
401 | |
390 EXTENSION_FUNCTION_VALIDATE(user_gesture_); | 402 EXTENSION_FUNCTION_VALIDATE(user_gesture_); |
391 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id)); | |
392 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &allow)); | |
393 | 403 |
394 ExtensionSystem* system = ExtensionSystem::Get(profile()); | 404 ExtensionSystem* system = ExtensionSystem::Get(profile()); |
395 extensions::ManagementPolicy* management_policy = | 405 extensions::ManagementPolicy* management_policy = |
396 system->management_policy(); | 406 system->management_policy(); |
397 ExtensionService* service = profile()->GetExtensionService(); | 407 ExtensionService* service = profile()->GetExtensionService(); |
398 const Extension* extension = service->GetInstalledExtension(extension_id); | 408 const Extension* extension = service->GetInstalledExtension(params->item_id); |
399 bool result = true; | 409 bool result = true; |
400 | 410 |
401 if (!extension) { | 411 if (!extension) { |
402 result = false; | 412 result = false; |
403 } else if (!management_policy->UserMayModifySettings(extension, NULL)) { | 413 } else if (!management_policy->UserMayModifySettings(extension, NULL)) { |
404 LOG(ERROR) << "Attempt to change allow file access of an extension that " | 414 LOG(ERROR) << "Attempt to change allow file access of an extension that " |
405 << "non-usermanagable was made. Extension id : " | 415 << "non-usermanagable was made. Extension id : " |
406 << extension->id(); | 416 << extension->id(); |
407 result = false; | 417 result = false; |
408 } else { | 418 } else { |
409 service->SetAllowFileAccess(extension, allow); | 419 service->SetAllowFileAccess(extension, params->allow); |
410 result = true; | 420 result = true; |
411 } | 421 } |
412 | 422 |
413 return result; | 423 return result; |
414 } | 424 } |
415 | 425 |
416 DeveloperPrivateAllowFileAccessFunction:: | 426 DeveloperPrivateAllowFileAccessFunction:: |
417 ~DeveloperPrivateAllowFileAccessFunction() {} | 427 ~DeveloperPrivateAllowFileAccessFunction() {} |
418 | 428 |
419 bool DeveloperPrivateAllowIncognitoFunction::RunImpl() { | 429 bool DeveloperPrivateAllowIncognitoFunction::RunImpl() { |
420 std::string extension_id; | 430 scoped_ptr<AllowIncognito::Params> params( |
421 bool allow = false; | 431 AllowIncognito::Params::Create(*args_)); |
422 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id)); | 432 EXTENSION_FUNCTION_VALIDATE(params.get()); |
423 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &allow)); | |
424 | 433 |
425 ExtensionService* service = profile()->GetExtensionService(); | 434 ExtensionService* service = profile()->GetExtensionService(); |
426 const Extension* extension = service->GetInstalledExtension(extension_id); | 435 const Extension* extension = service->GetInstalledExtension(params->item_id); |
427 bool result = true; | 436 bool result = true; |
428 | 437 |
429 if (!extension) { | 438 if (!extension) |
430 result = false; | 439 result = false; |
431 } else { | 440 else |
432 service->SetIsIncognitoEnabled(extension->id(), allow); | 441 service->SetIsIncognitoEnabled(extension->id(), params->allow); |
433 } | |
434 | 442 |
435 return result; | 443 return result; |
436 } | 444 } |
437 | 445 |
438 DeveloperPrivateAllowIncognitoFunction:: | 446 DeveloperPrivateAllowIncognitoFunction:: |
439 ~DeveloperPrivateAllowIncognitoFunction() {} | 447 ~DeveloperPrivateAllowIncognitoFunction() {} |
440 | 448 |
441 | 449 |
442 bool DeveloperPrivateReloadFunction::RunImpl() { | 450 bool DeveloperPrivateReloadFunction::RunImpl() { |
443 std::string extension_id; | 451 scoped_ptr<Reload::Params> params(Reload::Params::Create(*args_)); |
444 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id)); | 452 EXTENSION_FUNCTION_VALIDATE(params.get()); |
453 | |
445 ExtensionService* service = profile()->GetExtensionService(); | 454 ExtensionService* service = profile()->GetExtensionService(); |
446 CHECK(!extension_id.empty()); | 455 CHECK(!params->item_id.empty()); |
447 service->ReloadExtension(extension_id); | 456 service->ReloadExtension(params->item_id); |
448 return true; | 457 return true; |
449 } | 458 } |
450 | 459 |
451 DeveloperPrivateReloadFunction::~DeveloperPrivateReloadFunction() {} | 460 DeveloperPrivateReloadFunction::~DeveloperPrivateReloadFunction() {} |
452 | 461 |
453 bool DeveloperPrivateRestartFunction::RunImpl() { | 462 bool DeveloperPrivateRestartFunction::RunImpl() { |
454 std::string extension_id; | 463 scoped_ptr<Restart::Params> params(Restart::Params::Create(*args_)); |
455 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id)); | 464 EXTENSION_FUNCTION_VALIDATE(params.get()); |
465 | |
456 ExtensionService* service = profile()->GetExtensionService(); | 466 ExtensionService* service = profile()->GetExtensionService(); |
457 EXTENSION_FUNCTION_VALIDATE(!extension_id.empty()); | 467 EXTENSION_FUNCTION_VALIDATE(!params->item_id.empty()); |
458 service->RestartExtension(extension_id); | 468 service->RestartExtension(params->item_id); |
459 return true; | 469 return true; |
460 } | 470 } |
461 | 471 |
462 DeveloperPrivateRestartFunction::~DeveloperPrivateRestartFunction() {} | 472 DeveloperPrivateRestartFunction::~DeveloperPrivateRestartFunction() {} |
463 | 473 |
464 DeveloperPrivateEnableFunction::DeveloperPrivateEnableFunction() {} | 474 DeveloperPrivateEnableFunction::DeveloperPrivateEnableFunction() {} |
465 | 475 |
466 bool DeveloperPrivateEnableFunction::RunImpl() { | 476 bool DeveloperPrivateEnableFunction::RunImpl() { |
467 std::string extension_id; | 477 scoped_ptr<Enable::Params> params(Enable::Params::Create(*args_)); |
468 bool enable = false; | 478 EXTENSION_FUNCTION_VALIDATE(params.get()); |
469 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &extension_id)); | 479 |
470 EXTENSION_FUNCTION_VALIDATE(args_->GetBoolean(1, &enable)); | 480 std::string extension_id = params->item_id; |
471 | 481 |
472 ExtensionSystem* system = ExtensionSystem::Get(profile()); | 482 ExtensionSystem* system = ExtensionSystem::Get(profile()); |
473 extensions::ManagementPolicy* management_policy = | 483 extensions::ManagementPolicy* management_policy = |
474 system->management_policy(); | 484 system->management_policy(); |
475 ExtensionService* service = profile()->GetExtensionService(); | 485 ExtensionService* service = profile()->GetExtensionService(); |
476 | 486 |
477 const Extension* extension = service->GetInstalledExtension(extension_id); | 487 const Extension* extension = service->GetInstalledExtension(extension_id); |
478 if (!extension || | 488 if (!extension || |
479 !management_policy->UserMayModifySettings(extension, NULL)) { | 489 !management_policy->UserMayModifySettings(extension, NULL)) { |
480 LOG(ERROR) << "Attempt to enable an extension that is non-usermanagable " | 490 LOG(ERROR) << "Attempt to enable an extension that is non-usermanagable " |
481 "was made. Extension id: " << extension->id(); | 491 "was made. Extension id: " << extension->id(); |
482 return false; | 492 return false; |
483 } | 493 } |
484 | 494 |
485 if (enable) { | 495 if (params->enable) { |
486 extensions::ExtensionPrefs* prefs = service->extension_prefs(); | 496 extensions::ExtensionPrefs* prefs = service->extension_prefs(); |
487 if (prefs->DidExtensionEscalatePermissions(extension_id)) { | 497 if (prefs->DidExtensionEscalatePermissions(extension_id)) { |
488 ShellWindowRegistry* registry = ShellWindowRegistry::Get(profile()); | 498 ShellWindowRegistry* registry = ShellWindowRegistry::Get(profile()); |
489 CHECK(registry); | 499 CHECK(registry); |
490 ShellWindow* shell_window = registry->GetShellWindowForRenderViewHost( | 500 ShellWindow* shell_window = registry->GetShellWindowForRenderViewHost( |
491 render_view_host()); | 501 render_view_host()); |
492 if (!shell_window) { | 502 if (!shell_window) { |
493 return false; | 503 return false; |
494 } | 504 } |
495 | 505 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
658 response.status = developer::PACK_STATUS_WARNING; | 668 response.status = developer::PACK_STATUS_WARNING; |
659 } else { | 669 } else { |
660 response.status = developer::PACK_STATUS_ERROR; | 670 response.status = developer::PACK_STATUS_ERROR; |
661 } | 671 } |
662 results_ = developer::PackDirectory::Results::Create(response); | 672 results_ = developer::PackDirectory::Results::Create(response); |
663 SendResponse(true); | 673 SendResponse(true); |
664 Release(); | 674 Release(); |
665 } | 675 } |
666 | 676 |
667 bool DeveloperPrivatePackDirectoryFunction::RunImpl() { | 677 bool DeveloperPrivatePackDirectoryFunction::RunImpl() { |
668 int flags; | 678 scoped_ptr<PackDirectory::Params> params( |
669 EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &item_path_str_)); | 679 PackDirectory::Params::Create(*args_)); |
670 EXTENSION_FUNCTION_VALIDATE(args_->GetString(1, &key_path_str_)); | 680 EXTENSION_FUNCTION_VALIDATE(params.get()); |
671 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(2, &flags)); | |
672 | 681 |
673 base::FilePath root_directory = | 682 int flags = params->flags; |
683 item_path_str_ = params->path; | |
684 key_path_str_ = params->private_key_path; | |
685 | |
686 base::FilePath root_directory = | |
674 base::FilePath::FromWStringHack(UTF8ToWide(item_path_str_)); | 687 base::FilePath::FromWStringHack(UTF8ToWide(item_path_str_)); |
cduvall
2013/03/07 22:43:33
four space indent from prev line
Aaron Jacobs
2013/03/07 22:45:48
Done.
| |
675 | 688 |
676 base::FilePath key_file = | 689 base::FilePath key_file = |
677 base::FilePath::FromWStringHack(UTF8ToWide(key_path_str_)); | 690 base::FilePath::FromWStringHack(UTF8ToWide(key_path_str_)); |
cduvall
2013/03/07 22:43:33
four space indent from prev line
Aaron Jacobs
2013/03/07 22:45:48
Done.
| |
678 | 691 |
679 developer::PackDirectoryResponse response; | 692 developer::PackDirectoryResponse response; |
680 if (root_directory.empty()) { | 693 if (root_directory.empty()) { |
681 if (item_path_str_.empty()) | 694 if (item_path_str_.empty()) |
682 response.message = l10n_util::GetStringUTF8( | 695 response.message = l10n_util::GetStringUTF8( |
683 IDS_EXTENSION_PACK_DIALOG_ERROR_ROOT_REQUIRED); | 696 IDS_EXTENSION_PACK_DIALOG_ERROR_ROOT_REQUIRED); |
684 else | 697 else |
685 response.message = l10n_util::GetStringUTF8( | 698 response.message = l10n_util::GetStringUTF8( |
686 IDS_EXTENSION_PACK_DIALOG_ERROR_ROOT_INVALID); | 699 IDS_EXTENSION_PACK_DIALOG_ERROR_ROOT_INVALID); |
687 | 700 |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
847 | 860 |
848 #undef SET_STRING | 861 #undef SET_STRING |
849 return true; | 862 return true; |
850 } | 863 } |
851 | 864 |
852 DeveloperPrivateGetStringsFunction::~DeveloperPrivateGetStringsFunction() {} | 865 DeveloperPrivateGetStringsFunction::~DeveloperPrivateGetStringsFunction() {} |
853 | 866 |
854 } // namespace api | 867 } // namespace api |
855 | 868 |
856 } // namespace extensions | 869 } // namespace extensions |
OLD | NEW |