diff options
author | elijahtaylor@chromium.org <elijahtaylor@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-30 01:04:35 +0000 |
---|---|---|
committer | elijahtaylor@chromium.org <elijahtaylor@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-30 01:04:35 +0000 |
commit | b56d3c7fc3e61736747d63aac703bab4a51df8db (patch) | |
tree | 16bc7b6de6144cf8b633c7b3f5d0982fc1c79b1e /chrome/browser/extensions/extension_protocols.cc | |
parent | aa249b505342a9e1203440dcd04b94901fbf8f80 (diff) | |
download | chromium_src-b56d3c7fc3e61736747d63aac703bab4a51df8db.zip chromium_src-b56d3c7fc3e61736747d63aac703bab4a51df8db.tar.gz chromium_src-b56d3c7fc3e61736747d63aac703bab4a51df8db.tar.bz2 |
Basic multi-module support
Allows resource export from one extension that can
be imported into another extension's namespace.
BUG=236044
TEST=browser_tests ExtensionApiTest.SharedModule
TEST=unit_tests SharedModuleManifestTest.*
Review URL: https://chromiumcodereview.appspot.com/13971005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@197201 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_protocols.cc')
-rw-r--r-- | chrome/browser/extensions/extension_protocols.cc | 54 |
1 files changed, 50 insertions, 4 deletions
diff --git a/chrome/browser/extensions/extension_protocols.cc b/chrome/browser/extensions/extension_protocols.cc index b0da9b0..a6ed685 100644 --- a/chrome/browser/extensions/extension_protocols.cc +++ b/chrome/browser/extensions/extension_protocols.cc @@ -16,6 +16,7 @@ #include "base/stringprintf.h" #include "base/threading/thread_restrictions.h" #include "base/threading/worker_pool.h" +#include "base/utf_string_conversions.h" #include "build/build_config.h" #include "chrome/browser/extensions/extension_info_map.h" #include "chrome/browser/extensions/image_loader.h" @@ -26,6 +27,7 @@ #include "chrome/common/extensions/extension_file_util.h" #include "chrome/common/extensions/incognito_handler.h" #include "chrome/common/extensions/manifest_handlers/icons_handler.h" +#include "chrome/common/extensions/manifest_handlers/shared_module_info.h" #include "chrome/common/extensions/manifest_url_handler.h" #include "chrome/common/extensions/web_accessible_resources_handler.h" #include "chrome/common/url_constants.h" @@ -45,6 +47,7 @@ using content::ResourceRequestInfo; using extensions::Extension; +using extensions::SharedModuleInfo; namespace { @@ -205,14 +208,13 @@ class URLRequestExtensionJob : public net::URLRequestFileJob { net::NetworkDelegate* network_delegate, const std::string& extension_id, const base::FilePath& directory_path, + const base::FilePath& relative_path, const std::string& content_security_policy, bool send_cors_header) : net::URLRequestFileJob(request, network_delegate, base::FilePath()), // TODO(tc): Move all of these files into resources.pak so we don't break // when updating on Linux. - resource_(extension_id, directory_path, - extension_file_util::ExtensionURLToRelativeFilePath( - request->url())), + resource_(extension_id, directory_path, relative_path), weak_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { response_info_.headers = BuildHttpHeaders(content_security_policy, send_cors_header); @@ -388,7 +390,7 @@ net::URLRequestJob* ExtensionProtocolHandler::MaybeCreateJob( net::URLRequest* request, net::NetworkDelegate* network_delegate) const { // chrome-extension://extension-id/resource/path.js - const std::string& extension_id = request->url().host(); + std::string extension_id = request->url().host(); const Extension* extension = extension_info_map_->extensions().GetByID(extension_id); @@ -462,10 +464,54 @@ ExtensionProtocolHandler::MaybeCreateJob( } } + relative_path = + extension_file_util::ExtensionURLToRelativeFilePath(request->url()); + + if (SharedModuleInfo::IsImportedPath(path)) { + std::string new_extension_id; + std::string new_relative_path; + SharedModuleInfo::ParseImportedPath(path, &new_extension_id, + &new_relative_path); + const Extension* new_extension = + extension_info_map_->extensions().GetByID(new_extension_id); + + bool first_party_in_import = false; + // NB: This first_party_for_cookies call is not for security, it is only + // used so an exported extension can limit the visible surface to the + // extension that imports it, more or less constituting its API. + const std::string& first_party_path = + request->first_party_for_cookies().path(); + if (SharedModuleInfo::IsImportedPath(first_party_path)) { + std::string first_party_id; + std::string dummy; + SharedModuleInfo::ParseImportedPath(first_party_path, &first_party_id, + &dummy); + if (first_party_id == new_extension_id) { + first_party_in_import = true; + } + } + + if (SharedModuleInfo::ImportsExtensionById(extension, new_extension_id) && + new_extension && + (first_party_in_import || + SharedModuleInfo::IsExportAllowed(new_extension, new_relative_path))) { + directory_path = new_extension->path(); + extension_id = new_extension_id; +#if defined(OS_POSIX) + relative_path = base::FilePath(new_relative_path); +#elif defined(OS_WIN) + relative_path = base::FilePath(UTF8ToWide(new_relative_path)); +#endif + } else { + return NULL; + } + } + return new URLRequestExtensionJob(request, network_delegate, extension_id, directory_path, + relative_path, content_security_policy, send_cors_header); } |