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

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

Issue 11786003: Move Icons out of Extension class (Closed) Base URL: http://git.chromium.org/chromium/src.git@dc_unref_browser_action
Patch Set: Created 7 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
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/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/weak_ptr.h" 12 #include "base/memory/weak_ptr.h"
13 #include "base/message_loop.h" 13 #include "base/message_loop.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "base/stringprintf.h" 16 #include "base/stringprintf.h"
17 #include "base/threading/thread_restrictions.h" 17 #include "base/threading/thread_restrictions.h"
18 #include "base/threading/worker_pool.h" 18 #include "base/threading/worker_pool.h"
19 #include "build/build_config.h" 19 #include "build/build_config.h"
20 #include "chrome/browser/extensions/extension_info_map.h" 20 #include "chrome/browser/extensions/extension_info_map.h"
21 #include "chrome/browser/extensions/image_loader.h" 21 #include "chrome/browser/extensions/image_loader.h"
22 #include "chrome/browser/net/chrome_url_request_context.h" 22 #include "chrome/browser/net/chrome_url_request_context.h"
23 #include "chrome/common/chrome_paths.h" 23 #include "chrome/common/chrome_paths.h"
24 #include "chrome/common/extensions/api/icons/icons_handler.h"
24 #include "chrome/common/extensions/extension.h" 25 #include "chrome/common/extensions/extension.h"
25 #include "chrome/common/extensions/extension_file_util.h" 26 #include "chrome/common/extensions/extension_file_util.h"
26 #include "chrome/common/extensions/extension_resource.h" 27 #include "chrome/common/extensions/extension_resource.h"
27 #include "chrome/common/extensions/manifest_url_handler.h" 28 #include "chrome/common/extensions/manifest_url_handler.h"
28 #include "chrome/common/extensions/web_accessible_resources_handler.h" 29 #include "chrome/common/extensions/web_accessible_resources_handler.h"
29 #include "chrome/common/url_constants.h" 30 #include "chrome/common/url_constants.h"
30 #include "content/public/browser/resource_request_info.h" 31 #include "content/public/browser/resource_request_info.h"
31 #include "extensions/common/constants.h" 32 #include "extensions/common/constants.h"
32 #include "googleurl/src/url_util.h" 33 #include "googleurl/src/url_util.h"
33 #include "grit/component_extension_resources_map.h" 34 #include "grit/component_extension_resources_map.h"
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 if (!extension) 310 if (!extension)
310 return true; 311 return true;
311 312
312 // Disallow loading of packaged resources for hosted apps. We don't allow 313 // Disallow loading of packaged resources for hosted apps. We don't allow
313 // hybrid hosted/packaged apps. The one exception is access to icons, since 314 // hybrid hosted/packaged apps. The one exception is access to icons, since
314 // some extensions want to be able to do things like create their own 315 // some extensions want to be able to do things like create their own
315 // launchers. 316 // launchers.
316 std::string resource_root_relative_path = 317 std::string resource_root_relative_path =
317 request->url().path().empty() ? "" : request->url().path().substr(1); 318 request->url().path().empty() ? "" : request->url().path().substr(1);
318 if (extension->is_hosted_app() && 319 if (extension->is_hosted_app() &&
319 !extension->icons().ContainsPath(resource_root_relative_path)) { 320 !extensions::IconsInfo::GetIcons(extension).ContainsPath(
321 resource_root_relative_path)) {
320 LOG(ERROR) << "Denying load of " << request->url().spec() << " from " 322 LOG(ERROR) << "Denying load of " << request->url().spec() << " from "
321 << "hosted app."; 323 << "hosted app.";
322 return false; 324 return false;
323 } 325 }
324 326
325 // If the resource is not expicitly marked as web accessible, it should only 327 // If the resource is not expicitly marked as web accessible, it should only
326 // be allowed if it is being loaded by DevTools. A close approximation is 328 // be allowed if it is being loaded by DevTools. A close approximation is
327 // checking if the extension contains DevTools page. 329 // checking if the extension contains DevTools page.
328 // IsResourceWebAccessible already does the manifest version check, so no 330 // IsResourceWebAccessible already does the manifest version check, so no
329 // need to explicitly do it. 331 // need to explicitly do it.
(...skipping 10 matching lines...) Expand all
340 bool URLIsForExtensionIcon(const GURL& url, const Extension* extension) { 342 bool URLIsForExtensionIcon(const GURL& url, const Extension* extension) {
341 DCHECK(url.SchemeIs(extensions::kExtensionScheme)); 343 DCHECK(url.SchemeIs(extensions::kExtensionScheme));
342 344
343 if (!extension) 345 if (!extension)
344 return false; 346 return false;
345 347
346 std::string path = url.path(); 348 std::string path = url.path();
347 DCHECK_EQ(url.host(), extension->id()); 349 DCHECK_EQ(url.host(), extension->id());
348 DCHECK(path.length() > 0 && path[0] == '/'); 350 DCHECK(path.length() > 0 && path[0] == '/');
349 path = path.substr(1); 351 path = path.substr(1);
350 return extension->icons().ContainsPath(path); 352 return extensions::IconsInfo::GetIcons(extension).ContainsPath(path);
351 } 353 }
352 354
353 class ExtensionProtocolHandler 355 class ExtensionProtocolHandler
354 : public net::URLRequestJobFactory::ProtocolHandler { 356 : public net::URLRequestJobFactory::ProtocolHandler {
355 public: 357 public:
356 ExtensionProtocolHandler(bool is_incognito, 358 ExtensionProtocolHandler(bool is_incognito,
357 ExtensionInfoMap* extension_info_map) 359 ExtensionInfoMap* extension_info_map)
358 : is_incognito_(is_incognito), 360 : is_incognito_(is_incognito),
359 extension_info_map_(extension_info_map) {} 361 extension_info_map_(extension_info_map) {}
360 362
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 send_cors_header); 458 send_cors_header);
457 } 459 }
458 460
459 } // namespace 461 } // namespace
460 462
461 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler( 463 net::URLRequestJobFactory::ProtocolHandler* CreateExtensionProtocolHandler(
462 bool is_incognito, 464 bool is_incognito,
463 ExtensionInfoMap* extension_info_map) { 465 ExtensionInfoMap* extension_info_map) {
464 return new ExtensionProtocolHandler(is_incognito, extension_info_map); 466 return new ExtensionProtocolHandler(is_incognito, extension_info_map);
465 } 467 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698