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

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

Issue 18681: Revert "Parse more user script info out of the manifest and expose" (Closed)
Patch Set: Created 11 years, 11 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
Index: chrome/browser/extensions/extension_protocols.cc
diff --git a/chrome/browser/extensions/extension_protocols.cc b/chrome/browser/extensions/extension_protocols.cc
index 4d8312953c5cd8dc67bb8ba1e0734812756575ea..1643c4d6b9c261222f53ac0f6418b4e8b6a05f54 100644
--- a/chrome/browser/extensions/extension_protocols.cc
+++ b/chrome/browser/extensions/extension_protocols.cc
@@ -5,7 +5,6 @@
#include "chrome/browser/extensions/extension_protocols.h"
#include "base/string_util.h"
-#include "chrome/browser/extensions/extension.h"
#include "chrome/browser/net/chrome_url_request_context.h"
#include "googleurl/src/url_util.h"
#include "net/base/net_util.h"
@@ -14,6 +13,44 @@
const char kExtensionURLScheme[] = "chrome-extension";
const char kUserScriptURLScheme[] = "chrome-user-script";
+FilePath GetPathForExtensionResource(const FilePath& extension_path,
+ const std::string& url_path) {
+ DCHECK(extension_path.IsAbsolute());
+ DCHECK(url_path.length() > 0 && url_path[0] == '/');
+
+ // Build up a file:// URL and convert that back to a FilePath. This avoids
+ // URL encoding and path separator issues.
+
+ // Convert the extension's root to a file:// URL.
+ GURL extension_url = net::FilePathToFileURL(extension_path);
+ if (!extension_url.is_valid())
+ return FilePath();
+
+ // Append the requested path.
+ GURL::Replacements replacements;
+ std::string new_path(extension_url.path());
+ new_path += url_path;
+ replacements.SetPathStr(new_path);
+ GURL file_url = extension_url.ReplaceComponents(replacements);
+ if (!file_url.is_valid())
+ return FilePath();
+
+ // Convert the result back to a FilePath.
+ FilePath ret_val;
+ if (!net::FileURLToFilePath(file_url, &ret_val))
+ return FilePath();
+
+ // Double-check that the path we ended up with is actually inside the
+ // extension root. We can do this with a simple prefix match because:
+ // a) We control the prefix on both sides, and they should match.
+ // b) GURL normalizes things like "../" and "//" before it gets to us.
+ if (ret_val.value().find(extension_path.value() +
+ FilePath::kSeparators[0]) != 0)
+ return FilePath();
+
+ return ret_val;
+}
+
// Factory registered with URLRequest to create URLRequestJobs for extension://
// URLs.
static URLRequestJob* CreateExtensionURLRequestJob(URLRequest* request,
@@ -27,7 +64,7 @@ static URLRequestJob* CreateExtensionURLRequestJob(URLRequest* request,
return NULL;
std::string resource = request->url().path();
- FilePath path = Extension::GetResourcePath(directory_path, resource);
+ FilePath path = GetPathForExtensionResource(directory_path, resource);
return new URLRequestFileJob(request, path);
}
@@ -43,7 +80,7 @@ static URLRequestJob* CreateUserScriptURLRequestJob(URLRequest* request,
FilePath directory_path = context->user_script_dir_path();
std::string resource = request->url().path();
- FilePath path = Extension::GetResourcePath(directory_path, resource);
+ FilePath path = GetPathForExtensionResource(directory_path, resource);
return new URLRequestFileJob(request, path);
}
« no previous file with comments | « chrome/browser/extensions/extension_protocols.h ('k') | chrome/browser/extensions/extension_protocols_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698