| 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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 const int kSigninProcessId = 99; | 98 const int kSigninProcessId = 99; |
| 99 extension_info_map_->SetSigninProcess(kSigninProcessId); | 99 extension_info_map_->SetSigninProcess(kSigninProcessId); |
| 100 | 100 |
| 101 // Check that requests are rejected based on the destination | 101 // Check that requests are rejected based on the destination |
| 102 for (size_t i = 0; i < arraysize(sensitive_urls); ++i) { | 102 for (size_t i = 0; i < arraysize(sensitive_urls); ++i) { |
| 103 GURL sensitive_url(sensitive_urls[i]); | 103 GURL sensitive_url(sensitive_urls[i]); |
| 104 scoped_ptr<net::URLRequest> request(context.CreateRequest( | 104 scoped_ptr<net::URLRequest> request(context.CreateRequest( |
| 105 sensitive_url, net::DEFAULT_PRIORITY, NULL, NULL)); | 105 sensitive_url, net::DEFAULT_PRIORITY, NULL)); |
| 106 EXPECT_TRUE(WebRequestPermissions::HideRequest( | 106 EXPECT_TRUE(WebRequestPermissions::HideRequest( |
| 107 extension_info_map_.get(), request.get())) << sensitive_urls[i]; | 107 extension_info_map_.get(), request.get())) << sensitive_urls[i]; |
| 108 } | 108 } |
| 109 // Check that requests are accepted if they don't touch sensitive urls. | 109 // Check that requests are accepted if they don't touch sensitive urls. |
| 110 for (size_t i = 0; i < arraysize(non_sensitive_urls); ++i) { | 110 for (size_t i = 0; i < arraysize(non_sensitive_urls); ++i) { |
| 111 GURL non_sensitive_url(non_sensitive_urls[i]); | 111 GURL non_sensitive_url(non_sensitive_urls[i]); |
| 112 scoped_ptr<net::URLRequest> request(context.CreateRequest( | 112 scoped_ptr<net::URLRequest> request(context.CreateRequest( |
| 113 non_sensitive_url, net::DEFAULT_PRIORITY, NULL, NULL)); | 113 non_sensitive_url, net::DEFAULT_PRIORITY, NULL)); |
| 114 EXPECT_FALSE(WebRequestPermissions::HideRequest( | 114 EXPECT_FALSE(WebRequestPermissions::HideRequest( |
| 115 extension_info_map_.get(), request.get())) << non_sensitive_urls[i]; | 115 extension_info_map_.get(), request.get())) << non_sensitive_urls[i]; |
| 116 } | 116 } |
| 117 | 117 |
| 118 // Check protection of requests originating from the frame showing the Chrome | 118 // Check protection of requests originating from the frame showing the Chrome |
| 119 // WebStore. | 119 // WebStore. |
| 120 // Normally this request is not protected: | 120 // Normally this request is not protected: |
| 121 GURL non_sensitive_url("http://www.google.com/test.js"); | 121 GURL non_sensitive_url("http://www.google.com/test.js"); |
| 122 scoped_ptr<net::URLRequest> non_sensitive_request(context.CreateRequest( | 122 scoped_ptr<net::URLRequest> non_sensitive_request(context.CreateRequest( |
| 123 non_sensitive_url, net::DEFAULT_PRIORITY, NULL, NULL)); | 123 non_sensitive_url, net::DEFAULT_PRIORITY, NULL)); |
| 124 EXPECT_FALSE(WebRequestPermissions::HideRequest( | 124 EXPECT_FALSE(WebRequestPermissions::HideRequest( |
| 125 extension_info_map_.get(), non_sensitive_request.get())); | 125 extension_info_map_.get(), non_sensitive_request.get())); |
| 126 // If the origin is labeled by the WebStoreAppId, it becomes protected. | 126 // If the origin is labeled by the WebStoreAppId, it becomes protected. |
| 127 { | 127 { |
| 128 int process_id = 42; | 128 int process_id = 42; |
| 129 int site_instance_id = 23; | 129 int site_instance_id = 23; |
| 130 int view_id = 17; | 130 int view_id = 17; |
| 131 scoped_ptr<net::URLRequest> sensitive_request(context.CreateRequest( | 131 scoped_ptr<net::URLRequest> sensitive_request(context.CreateRequest( |
| 132 non_sensitive_url, net::DEFAULT_PRIORITY, NULL, NULL)); | 132 non_sensitive_url, net::DEFAULT_PRIORITY, NULL)); |
| 133 ResourceRequestInfo::AllocateForTesting(sensitive_request.get(), | 133 ResourceRequestInfo::AllocateForTesting(sensitive_request.get(), |
| 134 content::RESOURCE_TYPE_SCRIPT, | 134 content::RESOURCE_TYPE_SCRIPT, |
| 135 NULL, | 135 NULL, |
| 136 process_id, | 136 process_id, |
| 137 view_id, | 137 view_id, |
| 138 MSG_ROUTING_NONE, | 138 MSG_ROUTING_NONE, |
| 139 false, // is_main_frame | 139 false, // is_main_frame |
| 140 false, // parent_is_main_frame | 140 false, // parent_is_main_frame |
| 141 true, // allow_download | 141 true, // allow_download |
| 142 false); // is_async | 142 false); // is_async |
| 143 extension_info_map_->RegisterExtensionProcess( | 143 extension_info_map_->RegisterExtensionProcess( |
| 144 extensions::kWebStoreAppId, process_id, site_instance_id); | 144 extensions::kWebStoreAppId, process_id, site_instance_id); |
| 145 EXPECT_TRUE(WebRequestPermissions::HideRequest( | 145 EXPECT_TRUE(WebRequestPermissions::HideRequest( |
| 146 extension_info_map_.get(), sensitive_request.get())); | 146 extension_info_map_.get(), sensitive_request.get())); |
| 147 } | 147 } |
| 148 // If the process is the signin process, it becomes protected. | 148 // If the process is the signin process, it becomes protected. |
| 149 { | 149 { |
| 150 int process_id = kSigninProcessId; | 150 int process_id = kSigninProcessId; |
| 151 int view_id = 19; | 151 int view_id = 19; |
| 152 scoped_ptr<net::URLRequest> sensitive_request(context.CreateRequest( | 152 scoped_ptr<net::URLRequest> sensitive_request(context.CreateRequest( |
| 153 non_sensitive_url, net::DEFAULT_PRIORITY, NULL, NULL)); | 153 non_sensitive_url, net::DEFAULT_PRIORITY, NULL)); |
| 154 ResourceRequestInfo::AllocateForTesting(sensitive_request.get(), | 154 ResourceRequestInfo::AllocateForTesting(sensitive_request.get(), |
| 155 content::RESOURCE_TYPE_SCRIPT, | 155 content::RESOURCE_TYPE_SCRIPT, |
| 156 NULL, | 156 NULL, |
| 157 process_id, | 157 process_id, |
| 158 view_id, | 158 view_id, |
| 159 MSG_ROUTING_NONE, | 159 MSG_ROUTING_NONE, |
| 160 false, // is_main_frame | 160 false, // is_main_frame |
| 161 false, // parent_is_main_frame | 161 false, // parent_is_main_frame |
| 162 true, // allow_download | 162 true, // allow_download |
| 163 false); // is_async | 163 false); // is_async |
| 164 EXPECT_TRUE(WebRequestPermissions::HideRequest( | 164 EXPECT_TRUE(WebRequestPermissions::HideRequest( |
| 165 extension_info_map_.get(), sensitive_request.get())); | 165 extension_info_map_.get(), sensitive_request.get())); |
| 166 } | 166 } |
| 167 } | 167 } |
| 168 | 168 |
| 169 TEST_F(ExtensionWebRequestHelpersTestWithThreadsTest, | 169 TEST_F(ExtensionWebRequestHelpersTestWithThreadsTest, |
| 170 TestCanExtensionAccessURL_HostPermissions) { | 170 TestCanExtensionAccessURL_HostPermissions) { |
| 171 scoped_ptr<net::URLRequest> request(context.CreateRequest( | 171 scoped_ptr<net::URLRequest> request(context.CreateRequest( |
| 172 GURL("http://example.com"), net::DEFAULT_PRIORITY, NULL, NULL)); | 172 GURL("http://example.com"), net::DEFAULT_PRIORITY, NULL)); |
| 173 | 173 |
| 174 EXPECT_TRUE(WebRequestPermissions::CanExtensionAccessURL( | 174 EXPECT_TRUE(WebRequestPermissions::CanExtensionAccessURL( |
| 175 extension_info_map_.get(), | 175 extension_info_map_.get(), |
| 176 permissionless_extension_->id(), | 176 permissionless_extension_->id(), |
| 177 request->url(), | 177 request->url(), |
| 178 false /*crosses_incognito*/, | 178 false /*crosses_incognito*/, |
| 179 WebRequestPermissions::DO_NOT_CHECK_HOST)); | 179 WebRequestPermissions::DO_NOT_CHECK_HOST)); |
| 180 EXPECT_FALSE(WebRequestPermissions::CanExtensionAccessURL( | 180 EXPECT_FALSE(WebRequestPermissions::CanExtensionAccessURL( |
| 181 extension_info_map_.get(), | 181 extension_info_map_.get(), |
| 182 permissionless_extension_->id(), | 182 permissionless_extension_->id(), |
| 183 request->url(), | 183 request->url(), |
| 184 false /*crosses_incognito*/, | 184 false /*crosses_incognito*/, |
| 185 WebRequestPermissions::REQUIRE_HOST_PERMISSION)); | 185 WebRequestPermissions::REQUIRE_HOST_PERMISSION)); |
| 186 EXPECT_TRUE(WebRequestPermissions::CanExtensionAccessURL( | 186 EXPECT_TRUE(WebRequestPermissions::CanExtensionAccessURL( |
| 187 extension_info_map_.get(), | 187 extension_info_map_.get(), |
| 188 com_extension_->id(), | 188 com_extension_->id(), |
| 189 request->url(), | 189 request->url(), |
| 190 false /*crosses_incognito*/, | 190 false /*crosses_incognito*/, |
| 191 WebRequestPermissions::REQUIRE_HOST_PERMISSION)); | 191 WebRequestPermissions::REQUIRE_HOST_PERMISSION)); |
| 192 EXPECT_FALSE(WebRequestPermissions::CanExtensionAccessURL( | 192 EXPECT_FALSE(WebRequestPermissions::CanExtensionAccessURL( |
| 193 extension_info_map_.get(), | 193 extension_info_map_.get(), |
| 194 com_extension_->id(), | 194 com_extension_->id(), |
| 195 request->url(), | 195 request->url(), |
| 196 false /*crosses_incognito*/, | 196 false /*crosses_incognito*/, |
| 197 WebRequestPermissions::REQUIRE_ALL_URLS)); | 197 WebRequestPermissions::REQUIRE_ALL_URLS)); |
| 198 } | 198 } |
| OLD | NEW |