| 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/common/extensions/extension.h" | 5 #include "chrome/common/extensions/extension.h" |
| 6 | 6 |
| 7 #include "base/format_macros.h" | |
| 8 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 9 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/format_macros.h" |
| 10 #include "base/json/json_file_value_serializer.h" | 10 #include "base/json/json_file_value_serializer.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/string_number_conversions.h" |
| 12 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 13 #include "base/string_number_conversions.h" | |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
| 16 #include "chrome/common/extensions/command.h" | 16 #include "chrome/common/extensions/command.h" |
| 17 #include "chrome/common/extensions/extension_error_utils.h" | |
| 18 #include "chrome/common/extensions/extension_file_util.h" | 17 #include "chrome/common/extensions/extension_file_util.h" |
| 19 #include "chrome/common/extensions/extension_manifest_constants.h" | 18 #include "chrome/common/extensions/extension_manifest_constants.h" |
| 20 #include "chrome/common/extensions/extension_resource.h" | 19 #include "chrome/common/extensions/extension_resource.h" |
| 21 #include "chrome/common/extensions/features/feature.h" | 20 #include "chrome/common/extensions/features/feature.h" |
| 22 #include "chrome/common/extensions/permissions/api_permission.h" | 21 #include "chrome/common/extensions/permissions/api_permission.h" |
| 23 #include "chrome/common/extensions/permissions/permission_set.h" | 22 #include "chrome/common/extensions/permissions/permission_set.h" |
| 24 #include "chrome/common/extensions/permissions/socket_permission.h" | 23 #include "chrome/common/extensions/permissions/socket_permission.h" |
| 25 #include "chrome/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
| 25 #include "extensions/common/error_utils.h" |
| 26 #include "googleurl/src/gurl.h" | 26 #include "googleurl/src/gurl.h" |
| 27 #include "net/base/mime_sniffer.h" | 27 #include "net/base/mime_sniffer.h" |
| 28 #include "net/base/mock_host_resolver.h" |
| 28 #include "skia/ext/image_operations.h" | 29 #include "skia/ext/image_operations.h" |
| 29 #include "net/base/mock_host_resolver.h" | |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 31 #include "third_party/skia/include/core/SkBitmap.h" | 31 #include "third_party/skia/include/core/SkBitmap.h" |
| 32 #include "ui/gfx/codec/png_codec.h" | 32 #include "ui/gfx/codec/png_codec.h" |
| 33 | 33 |
| 34 using content::SocketPermissionRequest; | 34 using content::SocketPermissionRequest; |
| 35 using extensions::APIPermission; | 35 using extensions::APIPermission; |
| 36 using extensions::APIPermissionSet; | 36 using extensions::APIPermissionSet; |
| 37 using extensions::ErrorUtils; |
| 37 using extensions::Extension; | 38 using extensions::Extension; |
| 38 using extensions::Feature; | 39 using extensions::Feature; |
| 39 using extensions::PermissionSet; | 40 using extensions::PermissionSet; |
| 40 using extensions::SocketPermission; | 41 using extensions::SocketPermission; |
| 42 using extensions::URLPatternSet; |
| 41 | 43 |
| 42 namespace keys = extension_manifest_keys; | 44 namespace keys = extension_manifest_keys; |
| 43 namespace values = extension_manifest_values; | 45 namespace values = extension_manifest_values; |
| 44 namespace errors = extension_manifest_errors; | 46 namespace errors = extension_manifest_errors; |
| 45 | 47 |
| 46 namespace { | 48 namespace { |
| 47 | 49 |
| 48 scoped_refptr<Extension> LoadManifestUnchecked( | 50 scoped_refptr<Extension> LoadManifestUnchecked( |
| 49 const std::string& dir, | 51 const std::string& dir, |
| 50 const std::string& test_file, | 52 const std::string& test_file, |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 scoped_refptr<Extension> extension = LoadManifest("page_action", | 280 scoped_refptr<Extension> extension = LoadManifest("page_action", |
| 279 "page_action_popup.json"); | 281 "page_action_popup.json"); |
| 280 action = LoadAction("page_action_popup.json"); | 282 action = LoadAction("page_action_popup.json"); |
| 281 ASSERT_TRUE(NULL != action.get()); | 283 ASSERT_TRUE(NULL != action.get()); |
| 282 ASSERT_STREQ( | 284 ASSERT_STREQ( |
| 283 extension->url().Resolve(kPopupHtmlFile).spec().c_str(), | 285 extension->url().Resolve(kPopupHtmlFile).spec().c_str(), |
| 284 action->default_popup_url.spec().c_str()); | 286 action->default_popup_url.spec().c_str()); |
| 285 | 287 |
| 286 // Use both "popup" and "default_popup", expect failure. | 288 // Use both "popup" and "default_popup", expect failure. |
| 287 LoadActionAndExpectError("page_action_popup_and_default_popup.json", | 289 LoadActionAndExpectError("page_action_popup_and_default_popup.json", |
| 288 ExtensionErrorUtils::FormatErrorMessage( | 290 ErrorUtils::FormatErrorMessage( |
| 289 errors::kInvalidPageActionOldAndNewKeys, | 291 errors::kInvalidPageActionOldAndNewKeys, |
| 290 keys::kPageActionDefaultPopup, | 292 keys::kPageActionDefaultPopup, |
| 291 keys::kPageActionPopup)); | 293 keys::kPageActionPopup)); |
| 292 | 294 |
| 293 // Use only "default_popup", expect success. | 295 // Use only "default_popup", expect success. |
| 294 extension = LoadManifest("page_action", "page_action_popup.json"); | 296 extension = LoadManifest("page_action", "page_action_popup.json"); |
| 295 action = LoadAction("page_action_default_popup.json"); | 297 action = LoadAction("page_action_default_popup.json"); |
| 296 ASSERT_TRUE(NULL != action.get()); | 298 ASSERT_TRUE(NULL != action.get()); |
| 297 ASSERT_STREQ( | 299 ASSERT_STREQ( |
| 298 extension->url().Resolve(kPopupHtmlFile).spec().c_str(), | 300 extension->url().Resolve(kPopupHtmlFile).spec().c_str(), |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 | 467 |
| 466 extension = LoadManifest("socket_permissions", "empty.json"); | 468 extension = LoadManifest("socket_permissions", "empty.json"); |
| 467 EXPECT_FALSE(CheckSocketPermission(extension, | 469 EXPECT_FALSE(CheckSocketPermission(extension, |
| 468 SocketPermissionRequest::TCP_CONNECT, "www.example.com", 80)); | 470 SocketPermissionRequest::TCP_CONNECT, "www.example.com", 80)); |
| 469 | 471 |
| 470 extension = LoadManifestUnchecked("socket_permissions", | 472 extension = LoadManifestUnchecked("socket_permissions", |
| 471 "socket1.json", | 473 "socket1.json", |
| 472 Extension::INTERNAL, Extension::NO_FLAGS, | 474 Extension::INTERNAL, Extension::NO_FLAGS, |
| 473 &error); | 475 &error); |
| 474 EXPECT_TRUE(extension == NULL); | 476 EXPECT_TRUE(extension == NULL); |
| 475 ASSERT_EQ(ExtensionErrorUtils::FormatErrorMessage( | 477 ASSERT_EQ(ErrorUtils::FormatErrorMessage( |
| 476 errors::kInvalidPermission, "socket"), error); | 478 errors::kInvalidPermission, "socket"), error); |
| 477 | 479 |
| 478 extension = LoadManifest("socket_permissions", "socket2.json"); | 480 extension = LoadManifest("socket_permissions", "socket2.json"); |
| 479 EXPECT_TRUE(CheckSocketPermission(extension, | 481 EXPECT_TRUE(CheckSocketPermission(extension, |
| 480 SocketPermissionRequest::TCP_CONNECT, "www.example.com", 80)); | 482 SocketPermissionRequest::TCP_CONNECT, "www.example.com", 80)); |
| 481 EXPECT_FALSE(CheckSocketPermission( | 483 EXPECT_FALSE(CheckSocketPermission( |
| 482 extension, SocketPermissionRequest::UDP_BIND, "", 80)); | 484 extension, SocketPermissionRequest::UDP_BIND, "", 80)); |
| 483 EXPECT_TRUE(CheckSocketPermission( | 485 EXPECT_TRUE(CheckSocketPermission( |
| 484 extension, SocketPermissionRequest::UDP_BIND, "", 8888)); | 486 extension, SocketPermissionRequest::UDP_BIND, "", 8888)); |
| 485 | 487 |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 EXPECT_TRUE(Blocked(extension, settings_url)); | 897 EXPECT_TRUE(Blocked(extension, settings_url)); |
| 896 | 898 |
| 897 // Having chrome://*/ should not work for regular extensions. Note that | 899 // Having chrome://*/ should not work for regular extensions. Note that |
| 898 // for favicon access, we require the explicit pattern chrome://favicon/*. | 900 // for favicon access, we require the explicit pattern chrome://favicon/*. |
| 899 std::string error; | 901 std::string error; |
| 900 extension = LoadManifestUnchecked("script_and_capture", | 902 extension = LoadManifestUnchecked("script_and_capture", |
| 901 "extension_wildcard_chrome.json", | 903 "extension_wildcard_chrome.json", |
| 902 Extension::INTERNAL, Extension::NO_FLAGS, | 904 Extension::INTERNAL, Extension::NO_FLAGS, |
| 903 &error); | 905 &error); |
| 904 EXPECT_TRUE(extension == NULL); | 906 EXPECT_TRUE(extension == NULL); |
| 905 EXPECT_EQ(ExtensionErrorUtils::FormatErrorMessage( | 907 EXPECT_EQ(ErrorUtils::FormatErrorMessage( |
| 906 errors::kInvalidPermissionScheme, "chrome://*/"), error); | 908 errors::kInvalidPermissionScheme, "chrome://*/"), error); |
| 907 | 909 |
| 908 // Having chrome://favicon/* should not give you chrome://* | 910 // Having chrome://favicon/* should not give you chrome://* |
| 909 extension = LoadManifestStrict("script_and_capture", | 911 extension = LoadManifestStrict("script_and_capture", |
| 910 "extension_chrome_favicon_wildcard.json"); | 912 "extension_chrome_favicon_wildcard.json"); |
| 911 EXPECT_TRUE(Blocked(extension, settings_url)); | 913 EXPECT_TRUE(Blocked(extension, settings_url)); |
| 912 EXPECT_TRUE(CaptureOnly(extension, favicon_url)); | 914 EXPECT_TRUE(CaptureOnly(extension, favicon_url)); |
| 913 EXPECT_TRUE(Blocked(extension, about_url)); | 915 EXPECT_TRUE(Blocked(extension, about_url)); |
| 914 EXPECT_TRUE(extension->HasHostPermission(favicon_url)); | 916 EXPECT_TRUE(extension->HasHostPermission(favicon_url)); |
| 915 | 917 |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1258 | 1260 |
| 1259 TEST(ExtensionTest, GetSyncTypeExtensionWithTwoPlugins) { | 1261 TEST(ExtensionTest, GetSyncTypeExtensionWithTwoPlugins) { |
| 1260 scoped_refptr<Extension> extension( | 1262 scoped_refptr<Extension> extension( |
| 1261 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), | 1263 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), |
| 1262 Extension::INTERNAL, 2, FilePath(), | 1264 Extension::INTERNAL, 2, FilePath(), |
| 1263 Extension::NO_FLAGS)); | 1265 Extension::NO_FLAGS)); |
| 1264 if (extension) | 1266 if (extension) |
| 1265 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); | 1267 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); |
| 1266 } | 1268 } |
| 1267 #endif // !defined(OS_CHROMEOS) | 1269 #endif // !defined(OS_CHROMEOS) |
| OLD | NEW |