| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/common/extensions/extension.h" | 5 #include "chrome/common/extensions/extension.h" |
| 6 | 6 |
| 7 #if defined(TOOLKIT_GTK) | 7 #if defined(TOOLKIT_GTK) |
| 8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 for (ExtensionAPIPermissionSet::iterator i = api_perms.begin(); | 633 for (ExtensionAPIPermissionSet::iterator i = api_perms.begin(); |
| 634 i != api_perms.end(); ++i) { | 634 i != api_perms.end(); ++i) { |
| 635 if (*i == ExtensionAPIPermission::kExperimental) | 635 if (*i == ExtensionAPIPermission::kExperimental) |
| 636 continue; | 636 continue; |
| 637 | 637 |
| 638 ExtensionAPIPermission* permission = info->GetByID(*i); | 638 ExtensionAPIPermission* permission = info->GetByID(*i); |
| 639 const char* name = permission->name(); | 639 const char* name = permission->name(); |
| 640 StringValue* p = new StringValue(name); | 640 StringValue* p = new StringValue(name); |
| 641 permissions->Clear(); | 641 permissions->Clear(); |
| 642 permissions->Append(p); | 642 permissions->Append(p); |
| 643 Extension::Location location = Extension::INTERNAL; | |
| 644 | 643 |
| 645 // Many permissions are not available to hosted apps. | 644 // Some permissions are only available to component hosted apps. |
| 646 if (!permission->is_hosted_app() || permission->is_component_only()) { | 645 if (permission->is_component_only()) { |
| 647 LoadAndExpectError(Manifest(manifest.get(), name), | 646 LoadAndExpectError(Manifest(manifest.get(), name), |
| 648 errors::kPermissionNotAllowed); | 647 errors::kPermissionNotAllowed, |
| 648 Extension::INTERNAL); |
| 649 scoped_refptr<Extension> extension( |
| 650 LoadAndExpectSuccess(Manifest(manifest.get(), name), |
| 651 Extension::COMPONENT)); |
| 652 EXPECT_TRUE(extension->GetActivePermissions()->HasAPIPermission( |
| 653 permission->id())); |
| 649 | 654 |
| 650 // ... unless the hosted app is a component app. | 655 } else if (!permission->is_hosted_app()) { |
| 651 location = Extension::COMPONENT; | 656 // Most normal extension permissions also aren't available to hosted apps. |
| 657 // For these, the error is only reported in strict mode for legacy |
| 658 // reasons: crbug.com/101993. |
| 659 LoadAndExpectError(Manifest(manifest.get(), name), |
| 660 errors::kPermissionNotAllowed, |
| 661 Extension::INTERNAL, |
| 662 Extension::STRICT_ERROR_CHECKS); |
| 663 scoped_refptr<Extension> extension( |
| 664 LoadAndExpectSuccess(Manifest(manifest.get(), name), |
| 665 Extension::INTERNAL)); |
| 666 EXPECT_FALSE(extension->GetActivePermissions()->HasAPIPermission( |
| 667 permission->id())); |
| 668 |
| 669 // These permissions are also allowed for component hosted apps. |
| 670 extension = LoadAndExpectSuccess(Manifest(manifest.get(), name), |
| 671 Extension::COMPONENT); |
| 672 EXPECT_TRUE(extension->GetActivePermissions()->HasAPIPermission( |
| 673 permission->id())); |
| 674 |
| 675 } else { |
| 676 scoped_refptr<Extension> extension( |
| 677 LoadAndExpectSuccess(Manifest(manifest.get(), name))); |
| 678 EXPECT_TRUE(extension->GetActivePermissions()->HasAPIPermission( |
| 679 permission->id())); |
| 652 } | 680 } |
| 653 | |
| 654 LoadAndExpectSuccess(Manifest(manifest.get(), name), location); | |
| 655 } | 681 } |
| 656 } | 682 } |
| 657 | 683 |
| 658 TEST_F(ExtensionManifestTest, ComponentOnlyPermission) { | 684 TEST_F(ExtensionManifestTest, ComponentOnlyPermission) { |
| 659 std::string error; | 685 std::string error; |
| 660 scoped_ptr<DictionaryValue> manifest( | 686 scoped_ptr<DictionaryValue> manifest( |
| 661 LoadManifestFile("init_valid_minimal.json", &error)); | 687 LoadManifestFile("init_valid_minimal.json", &error)); |
| 662 ASSERT_TRUE(manifest.get()); | 688 ASSERT_TRUE(manifest.get()); |
| 663 ListValue* permissions = new ListValue(); | 689 ListValue* permissions = new ListValue(); |
| 664 manifest->Set("permissions", permissions); | 690 manifest->Set("permissions", permissions); |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 927 scoped_refptr<Extension> extension_2( | 953 scoped_refptr<Extension> extension_2( |
| 928 LoadAndExpectSuccess("offline_disabled_packaged_app.json")); | 954 LoadAndExpectSuccess("offline_disabled_packaged_app.json")); |
| 929 EXPECT_FALSE(extension_2->offline_enabled()); | 955 EXPECT_FALSE(extension_2->offline_enabled()); |
| 930 scoped_refptr<Extension> extension_3( | 956 scoped_refptr<Extension> extension_3( |
| 931 LoadAndExpectSuccess("offline_default_packaged_app.json")); | 957 LoadAndExpectSuccess("offline_default_packaged_app.json")); |
| 932 EXPECT_FALSE(extension_3->offline_enabled()); | 958 EXPECT_FALSE(extension_3->offline_enabled()); |
| 933 scoped_refptr<Extension> extension_4( | 959 scoped_refptr<Extension> extension_4( |
| 934 LoadAndExpectSuccess("offline_enabled_hosted_app.json")); | 960 LoadAndExpectSuccess("offline_enabled_hosted_app.json")); |
| 935 EXPECT_TRUE(extension_4->offline_enabled()); | 961 EXPECT_TRUE(extension_4->offline_enabled()); |
| 936 } | 962 } |
| OLD | NEW |