| 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 "extensions/browser/api/web_request/web_request_permissions.h" | 5 #include "extensions/browser/api/web_request/web_request_permissions.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "chrome/common/extensions/extension_test_util.h" | 9 #include "chrome/common/extensions/extension_test_util.h" |
| 10 #include "content/public/browser/resource_request_info.h" | 10 #include "content/public/browser/resource_request_info.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 "inlineinstall/detail/kcnhkahnjcbndmmehfkdnkjomaanaooo" | 93 "inlineinstall/detail/kcnhkahnjcbndmmehfkdnkjomaanaooo" |
| 94 }; | 94 }; |
| 95 const char* const non_sensitive_urls[] = { | 95 const char* const non_sensitive_urls[] = { |
| 96 "http://www.google.com/" | 96 "http://www.google.com/" |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 // Check that requests are rejected based on the destination | 99 // Check that requests are rejected based on the destination |
| 100 for (size_t i = 0; i < arraysize(sensitive_urls); ++i) { | 100 for (size_t i = 0; i < arraysize(sensitive_urls); ++i) { |
| 101 GURL sensitive_url(sensitive_urls[i]); | 101 GURL sensitive_url(sensitive_urls[i]); |
| 102 scoped_ptr<net::URLRequest> request(context.CreateRequest( | 102 scoped_ptr<net::URLRequest> request(context.CreateRequest( |
| 103 sensitive_url, net::DEFAULT_PRIORITY, NULL, NULL)); | 103 sensitive_url, net::DEFAULT_PRIORITY, NULL)); |
| 104 EXPECT_TRUE(WebRequestPermissions::HideRequest( | 104 EXPECT_TRUE(WebRequestPermissions::HideRequest( |
| 105 extension_info_map_.get(), request.get())) << sensitive_urls[i]; | 105 extension_info_map_.get(), request.get())) << sensitive_urls[i]; |
| 106 } | 106 } |
| 107 // Check that requests are accepted if they don't touch sensitive urls. | 107 // Check that requests are accepted if they don't touch sensitive urls. |
| 108 for (size_t i = 0; i < arraysize(non_sensitive_urls); ++i) { | 108 for (size_t i = 0; i < arraysize(non_sensitive_urls); ++i) { |
| 109 GURL non_sensitive_url(non_sensitive_urls[i]); | 109 GURL non_sensitive_url(non_sensitive_urls[i]); |
| 110 scoped_ptr<net::URLRequest> request(context.CreateRequest( | 110 scoped_ptr<net::URLRequest> request(context.CreateRequest( |
| 111 non_sensitive_url, net::DEFAULT_PRIORITY, NULL, NULL)); | 111 non_sensitive_url, net::DEFAULT_PRIORITY, NULL)); |
| 112 EXPECT_FALSE(WebRequestPermissions::HideRequest( | 112 EXPECT_FALSE(WebRequestPermissions::HideRequest( |
| 113 extension_info_map_.get(), request.get())) << non_sensitive_urls[i]; | 113 extension_info_map_.get(), request.get())) << non_sensitive_urls[i]; |
| 114 } | 114 } |
| 115 | 115 |
| 116 // Check protection of requests originating from the frame showing the Chrome | 116 // Check protection of requests originating from the frame showing the Chrome |
| 117 // WebStore. | 117 // WebStore. |
| 118 // Normally this request is not protected: | 118 // Normally this request is not protected: |
| 119 GURL non_sensitive_url("http://www.google.com/test.js"); | 119 GURL non_sensitive_url("http://www.google.com/test.js"); |
| 120 scoped_ptr<net::URLRequest> non_sensitive_request(context.CreateRequest( | 120 scoped_ptr<net::URLRequest> non_sensitive_request(context.CreateRequest( |
| 121 non_sensitive_url, net::DEFAULT_PRIORITY, NULL, NULL)); | 121 non_sensitive_url, net::DEFAULT_PRIORITY, NULL)); |
| 122 EXPECT_FALSE(WebRequestPermissions::HideRequest( | 122 EXPECT_FALSE(WebRequestPermissions::HideRequest( |
| 123 extension_info_map_.get(), non_sensitive_request.get())); | 123 extension_info_map_.get(), non_sensitive_request.get())); |
| 124 // If the origin is labeled by the WebStoreAppId, it becomes protected. | 124 // If the origin is labeled by the WebStoreAppId, it becomes protected. |
| 125 { | 125 { |
| 126 int process_id = 42; | 126 int process_id = 42; |
| 127 int site_instance_id = 23; | 127 int site_instance_id = 23; |
| 128 int view_id = 17; | 128 int view_id = 17; |
| 129 scoped_ptr<net::URLRequest> sensitive_request(context.CreateRequest( | 129 scoped_ptr<net::URLRequest> sensitive_request(context.CreateRequest( |
| 130 non_sensitive_url, net::DEFAULT_PRIORITY, NULL, NULL)); | 130 non_sensitive_url, net::DEFAULT_PRIORITY, NULL)); |
| 131 ResourceRequestInfo::AllocateForTesting(sensitive_request.get(), | 131 ResourceRequestInfo::AllocateForTesting(sensitive_request.get(), |
| 132 content::RESOURCE_TYPE_SCRIPT, | 132 content::RESOURCE_TYPE_SCRIPT, |
| 133 NULL, | 133 NULL, |
| 134 process_id, | 134 process_id, |
| 135 view_id, | 135 view_id, |
| 136 MSG_ROUTING_NONE, | 136 MSG_ROUTING_NONE, |
| 137 false, // is_main_frame | 137 false, // is_main_frame |
| 138 false, // parent_is_main_frame | 138 false, // parent_is_main_frame |
| 139 true, // allow_download | 139 true, // allow_download |
| 140 false); // is_async | 140 false); // is_async |
| 141 extension_info_map_->RegisterExtensionProcess( | 141 extension_info_map_->RegisterExtensionProcess( |
| 142 extensions::kWebStoreAppId, process_id, site_instance_id); | 142 extensions::kWebStoreAppId, process_id, site_instance_id); |
| 143 EXPECT_TRUE(WebRequestPermissions::HideRequest( | 143 EXPECT_TRUE(WebRequestPermissions::HideRequest( |
| 144 extension_info_map_.get(), sensitive_request.get())); | 144 extension_info_map_.get(), sensitive_request.get())); |
| 145 } | 145 } |
| 146 } | 146 } |
| 147 | 147 |
| 148 TEST_F(ExtensionWebRequestHelpersTestWithThreadsTest, | 148 TEST_F(ExtensionWebRequestHelpersTestWithThreadsTest, |
| 149 TestCanExtensionAccessURL_HostPermissions) { | 149 TestCanExtensionAccessURL_HostPermissions) { |
| 150 scoped_ptr<net::URLRequest> request(context.CreateRequest( | 150 scoped_ptr<net::URLRequest> request(context.CreateRequest( |
| 151 GURL("http://example.com"), net::DEFAULT_PRIORITY, NULL, NULL)); | 151 GURL("http://example.com"), net::DEFAULT_PRIORITY, NULL)); |
| 152 | 152 |
| 153 EXPECT_TRUE(WebRequestPermissions::CanExtensionAccessURL( | 153 EXPECT_TRUE(WebRequestPermissions::CanExtensionAccessURL( |
| 154 extension_info_map_.get(), | 154 extension_info_map_.get(), |
| 155 permissionless_extension_->id(), | 155 permissionless_extension_->id(), |
| 156 request->url(), | 156 request->url(), |
| 157 false /*crosses_incognito*/, | 157 false /*crosses_incognito*/, |
| 158 WebRequestPermissions::DO_NOT_CHECK_HOST)); | 158 WebRequestPermissions::DO_NOT_CHECK_HOST)); |
| 159 EXPECT_FALSE(WebRequestPermissions::CanExtensionAccessURL( | 159 EXPECT_FALSE(WebRequestPermissions::CanExtensionAccessURL( |
| 160 extension_info_map_.get(), | 160 extension_info_map_.get(), |
| 161 permissionless_extension_->id(), | 161 permissionless_extension_->id(), |
| 162 request->url(), | 162 request->url(), |
| 163 false /*crosses_incognito*/, | 163 false /*crosses_incognito*/, |
| 164 WebRequestPermissions::REQUIRE_HOST_PERMISSION)); | 164 WebRequestPermissions::REQUIRE_HOST_PERMISSION)); |
| 165 EXPECT_TRUE(WebRequestPermissions::CanExtensionAccessURL( | 165 EXPECT_TRUE(WebRequestPermissions::CanExtensionAccessURL( |
| 166 extension_info_map_.get(), | 166 extension_info_map_.get(), |
| 167 com_extension_->id(), | 167 com_extension_->id(), |
| 168 request->url(), | 168 request->url(), |
| 169 false /*crosses_incognito*/, | 169 false /*crosses_incognito*/, |
| 170 WebRequestPermissions::REQUIRE_HOST_PERMISSION)); | 170 WebRequestPermissions::REQUIRE_HOST_PERMISSION)); |
| 171 EXPECT_FALSE(WebRequestPermissions::CanExtensionAccessURL( | 171 EXPECT_FALSE(WebRequestPermissions::CanExtensionAccessURL( |
| 172 extension_info_map_.get(), | 172 extension_info_map_.get(), |
| 173 com_extension_->id(), | 173 com_extension_->id(), |
| 174 request->url(), | 174 request->url(), |
| 175 false /*crosses_incognito*/, | 175 false /*crosses_incognito*/, |
| 176 WebRequestPermissions::REQUIRE_ALL_URLS)); | 176 WebRequestPermissions::REQUIRE_ALL_URLS)); |
| 177 } | 177 } |
| OLD | NEW |