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

Unified Diff: chrome/browser/extensions/extension_protocols.cc

Issue 13971005: Basic multi-module support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix copyright for presubmit Created 7 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/extensions/crx_installer.cc ('k') | chrome/browser/extensions/shared_module_apitest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/extension_protocols.cc
diff --git a/chrome/browser/extensions/extension_protocols.cc b/chrome/browser/extensions/extension_protocols.cc
index b0da9b0321838ef93d5fb5c7c1345af550ca7917..a6ed685ccfc96448d65ebf84854c0fdfa5b40030 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);
}
« no previous file with comments | « chrome/browser/extensions/crx_installer.cc ('k') | chrome/browser/extensions/shared_module_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698