Chromium Code Reviews| 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/extension_protocols.h" | 5 #include "chrome/browser/extensions/extension_protocols.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 send_cors_header); | 158 send_cors_header); |
| 159 } | 159 } |
| 160 | 160 |
| 161 virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE { | 161 virtual void GetResponseInfo(net::HttpResponseInfo* info) OVERRIDE { |
| 162 *info = response_info_; | 162 *info = response_info_; |
| 163 } | 163 } |
| 164 | 164 |
| 165 net::HttpResponseInfo response_info_; | 165 net::HttpResponseInfo response_info_; |
| 166 }; | 166 }; |
| 167 | 167 |
| 168 bool ExtensionCanLoadInIncognito(const std::string& extension_id, | 168 bool ExtensionCanLoadInIncognito(const ResourceRequestInfo* info, |
| 169 const std::string& extension_id, | |
| 169 ExtensionInfoMap* extension_info_map) { | 170 ExtensionInfoMap* extension_info_map) { |
| 170 const Extension* extension = | 171 if (!extension_info_map->IsIncognitoEnabled(extension_id)) |
| 171 extension_info_map->extensions().GetByID(extension_id); | 172 return false; |
| 172 // Only split-mode extensions can load in incognito profiles. | 173 |
| 173 return extension && extension->incognito_split_mode(); | 174 // Only allow incognito toplevel navigations to extension resources in |
| 175 // split mode. In spanning mode, the extension must run in a single process, | |
| 176 // and an incognito tab prevents that. | |
| 177 if (info->GetResourceType() == ResourceType::MAIN_FRAME) { | |
|
Aaron Boodman
2012/03/20 02:19:29
Why only the main frame? Shouldn't we prevent all
Matt Perry
2012/03/20 17:27:33
We prevent all resources if the extension is not i
Aaron Boodman
2012/03/21 19:29:44
Ah, I remember. Thanks.
| |
| 178 const Extension* extension = | |
| 179 extension_info_map->extensions().GetByID(extension_id); | |
| 180 return extension && extension->incognito_split_mode(); | |
| 181 } | |
| 182 | |
| 183 return true; | |
| 174 } | 184 } |
| 175 | 185 |
| 176 // Returns true if an chrome-extension:// resource should be allowed to load. | 186 // Returns true if an chrome-extension:// resource should be allowed to load. |
| 177 // TODO(aa): This should be moved into ExtensionResourceRequestPolicy, but we | 187 // TODO(aa): This should be moved into ExtensionResourceRequestPolicy, but we |
| 178 // first need to find a way to get CanLoadInIncognito state into the renderers. | 188 // first need to find a way to get CanLoadInIncognito state into the renderers. |
| 179 bool AllowExtensionResourceLoad(net::URLRequest* request, | 189 bool AllowExtensionResourceLoad(net::URLRequest* request, |
| 180 bool is_incognito, | 190 bool is_incognito, |
| 181 ExtensionInfoMap* extension_info_map) { | 191 ExtensionInfoMap* extension_info_map) { |
| 182 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); | 192 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); |
| 183 | 193 |
| 184 // We have seen crashes where info is NULL: crbug.com/52374. | 194 // We have seen crashes where info is NULL: crbug.com/52374. |
| 185 if (!info) { | 195 if (!info) { |
| 186 LOG(ERROR) << "Allowing load of " << request->url().spec() | 196 LOG(ERROR) << "Allowing load of " << request->url().spec() |
| 187 << "from unknown origin. Could not find user data for " | 197 << "from unknown origin. Could not find user data for " |
| 188 << "request."; | 198 << "request."; |
| 189 return true; | 199 return true; |
| 190 } | 200 } |
| 191 | 201 |
| 192 // Don't allow toplevel navigations to extension resources in incognito mode. | 202 if (is_incognito && !ExtensionCanLoadInIncognito(info, request->url().host(), |
| 193 // This is because an extension must run in a single process, and an | 203 extension_info_map)) { |
| 194 // incognito tab prevents that. | |
| 195 if (is_incognito && | |
| 196 info->GetResourceType() == ResourceType::MAIN_FRAME && | |
| 197 !ExtensionCanLoadInIncognito(request->url().host(), extension_info_map)) { | |
| 198 LOG(ERROR) << "Denying load of " << request->url().spec() << " from " | 204 LOG(ERROR) << "Denying load of " << request->url().spec() << " from " |
| 199 << "incognito tab."; | 205 << "incognito tab."; |
| 200 return false; | 206 return false; |
| 201 } | 207 } |
| 202 | 208 |
| 203 return true; | 209 return true; |
| 204 } | 210 } |
| 205 | 211 |
| 206 // Returns true if the given URL references an icon in the given extension. | 212 // Returns true if the given URL references an icon in the given extension. |
| 207 bool URLIsForExtensionIcon(const GURL& url, const Extension* extension) { | 213 bool URLIsForExtensionIcon(const GURL& url, const Extension* extension) { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 content_security_policy, send_cors_header); | 325 content_security_policy, send_cors_header); |
| 320 } | 326 } |
| 321 | 327 |
| 322 } // namespace | 328 } // namespace |
| 323 | 329 |
| 324 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler( | 330 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler( |
| 325 bool is_incognito, | 331 bool is_incognito, |
| 326 ExtensionInfoMap* extension_info_map) { | 332 ExtensionInfoMap* extension_info_map) { |
| 327 return new ExtensionProtocolHandler(is_incognito, extension_info_map); | 333 return new ExtensionProtocolHandler(is_incognito, extension_info_map); |
| 328 } | 334 } |
| OLD | NEW |