Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Side by Side Diff: chrome/browser/extensions/extension_protocols.cc

Issue 9726025: Fix bug where we'd allow chrome-extension URLs to be loaded in incognito mode (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: getcurrentdir Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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) {
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 "
199 << "incognito tab.";
200 return false; 204 return false;
201 } 205 }
202 206
203 return true; 207 return true;
204 } 208 }
205 209
206 // Returns true if the given URL references an icon in the given extension. 210 // Returns true if the given URL references an icon in the given extension.
207 bool URLIsForExtensionIcon(const GURL& url, const Extension* extension) { 211 bool URLIsForExtensionIcon(const GURL& url, const Extension* extension) {
208 DCHECK(url.SchemeIs(chrome::kExtensionScheme)); 212 DCHECK(url.SchemeIs(chrome::kExtensionScheme));
209 213
(...skipping 25 matching lines...) Expand all
235 ExtensionInfoMap* const extension_info_map_; 239 ExtensionInfoMap* const extension_info_map_;
236 DISALLOW_COPY_AND_ASSIGN(ExtensionProtocolHandler); 240 DISALLOW_COPY_AND_ASSIGN(ExtensionProtocolHandler);
237 }; 241 };
238 242
239 // Creates URLRequestJobs for extension:// URLs. 243 // Creates URLRequestJobs for extension:// URLs.
240 net::URLRequestJob* 244 net::URLRequestJob*
241 ExtensionProtocolHandler::MaybeCreateJob(net::URLRequest* request) const { 245 ExtensionProtocolHandler::MaybeCreateJob(net::URLRequest* request) const {
242 // TODO(mpcomplete): better error code. 246 // TODO(mpcomplete): better error code.
243 if (!AllowExtensionResourceLoad( 247 if (!AllowExtensionResourceLoad(
244 request, is_incognito_, extension_info_map_)) { 248 request, is_incognito_, extension_info_map_)) {
245 LOG(ERROR) << "disallowed in extension protocols";
246 return new net::URLRequestErrorJob(request, net::ERR_ADDRESS_UNREACHABLE); 249 return new net::URLRequestErrorJob(request, net::ERR_ADDRESS_UNREACHABLE);
247 } 250 }
248 251
249 // chrome-extension://extension-id/resource/path.js 252 // chrome-extension://extension-id/resource/path.js
250 const std::string& extension_id = request->url().host(); 253 const std::string& extension_id = request->url().host();
251 const Extension* extension = 254 const Extension* extension =
252 extension_info_map_->extensions().GetByID(extension_id); 255 extension_info_map_->extensions().GetByID(extension_id);
253 FilePath directory_path; 256 FilePath directory_path;
254 if (extension) 257 if (extension)
255 directory_path = extension->path(); 258 directory_path = extension->path();
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 content_security_policy, send_cors_header); 322 content_security_policy, send_cors_header);
320 } 323 }
321 324
322 } // namespace 325 } // namespace
323 326
324 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler( 327 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler(
325 bool is_incognito, 328 bool is_incognito,
326 ExtensionInfoMap* extension_info_map) { 329 ExtensionInfoMap* extension_info_map) {
327 return new ExtensionProtocolHandler(is_incognito, extension_info_map); 330 return new ExtensionProtocolHandler(is_incognito, extension_info_map);
328 } 331 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698