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

Unified Diff: chrome/common/extensions/extension_file_util.cc

Issue 9909019: Add schema chrome-extension-resource:// for extension resources (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add tests Created 8 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
Index: chrome/common/extensions/extension_file_util.cc
diff --git a/chrome/common/extensions/extension_file_util.cc b/chrome/common/extensions/extension_file_util.cc
index a7a5cc91f591ed0b113ebeb36da869c74515cef0..5dfa37c1a4ae8cb4ac9087853154955bbc777222 100644
--- a/chrome/common/extensions/extension_file_util.cc
+++ b/chrome/common/extensions/extension_file_util.cc
@@ -625,6 +625,40 @@ FilePath ExtensionURLToRelativeFilePath(const GURL& url) {
return path;
}
+FilePath ExtensionResourceURLToFilePath(const GURL& url, const FilePath& root) {
+ std::string host = net::UnescapeURLComponent(url.host(),
Aaron Boodman 2012/04/16 18:54:36 This is duplicating a lot of code from above. Can
Aaron Boodman 2012/04/16 18:59:57 Actually, on second thought, it is a bit weird to
Peng 2012/04/17 13:52:05 * Remove duplicated code. * Handle C-E-R:// in a n
+ net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS);
+ if (host.empty())
+ return FilePath();
+
+ std::string url_path = url.path();
+ if (url_path.empty() || url_path[0] != '/')
+ return FilePath();
+
+ // Drop the leading slashes and convert %-encoded UTF8 to regular UTF8.
+ std::string file_path = net::UnescapeURLComponent(url_path,
+ net::UnescapeRule::SPACES | net::UnescapeRule::URL_SPECIAL_CHARS);
+ size_t skip = file_path.find_first_not_of("/\\");
+ if (skip != file_path.npos)
+ file_path = file_path.substr(skip);
+
+#if defined(OS_POSIX)
+ FilePath path = root.Append(host).Append(file_path);
+#elif defined(OS_WIN)
+ FilePath path = root.Append(UTF8ToWide(host)).Append(UTF8ToWide(file_path));
+#else
+ NOTIMPLEMENTED();
+ return FilePath();
+#endif
+
+ if (!file_util::PathExists(path) ||
+ !file_util::AbsolutePath(&path) ||
+ !root.IsParent(path)) {
+ return FilePath();
+ }
+ return path;
+}
+
FilePath GetUserDataTempDir() {
// We do file IO in this function, but only when the current profile's
// Temp directory has never been used before, or in a rare error case.

Powered by Google App Engine
This is Rietveld 408576698