summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_protocols.cc
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-22 20:03:30 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-22 20:03:30 +0000
commit1712232b6e2beffa413af6d97cf63b30a3b6e7c7 (patch)
tree7346e88a8fa9d4c8bfc6aa417de8b30c60763e5f /chrome/browser/extensions/extension_protocols.cc
parentd938aed98c3e683586d37b6dcbb1b20d95eb771a (diff)
downloadchromium_src-1712232b6e2beffa413af6d97cf63b30a3b6e7c7.zip
chromium_src-1712232b6e2beffa413af6d97cf63b30a3b6e7c7.tar.gz
chromium_src-1712232b6e2beffa413af6d97cf63b30a3b6e7c7.tar.bz2
Revert "Parse more user script info out of the manifest and expose"
This reverts commit fc3fd1062c06f803775c16d11f742d85d540e415. Review URL: http://codereview.chromium.org/18681 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@8494 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_protocols.cc')
-rw-r--r--chrome/browser/extensions/extension_protocols.cc43
1 files changed, 40 insertions, 3 deletions
diff --git a/chrome/browser/extensions/extension_protocols.cc b/chrome/browser/extensions/extension_protocols.cc
index 4d83129..1643c4d6 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);
}