Commit 1dd86255 authored by kinuko@chromium.org's avatar kinuko@chromium.org

Cleanup: Add fileapi::GetIsolatedFileSystemRootURIString

to hide the details how we create a root URI string for IsolatedFileSystems
from each extension code.

BUG=none
TEST=existing tests

Review URL: https://codereview.chromium.org/11833002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@176036 0039d316-1c4b-4281-b951-d872f2087c98
parent c902ec28
...@@ -35,21 +35,19 @@ static v8::Handle<v8::Value> GetIsolatedFileSystem( ...@@ -35,21 +35,19 @@ static v8::Handle<v8::Value> GetIsolatedFileSystem(
std::string name(fileapi::GetIsolatedFileSystemName(context_url.GetOrigin(), std::string name(fileapi::GetIsolatedFileSystemName(context_url.GetOrigin(),
file_system_id)); file_system_id));
std::string root(fileapi::GetFileSystemRootURI(
context_url.GetOrigin(),
fileapi::kFileSystemTypeIsolated).spec());
root.append(file_system_id);
root.append("/");
// The optional second argument is the subfolder within the isolated file // The optional second argument is the subfolder within the isolated file
// system at which to root the DOMFileSystem we're returning to the caller. // system at which to root the DOMFileSystem we're returning to the caller.
std::string optional_root_name;
if (args.Length() == 2) { if (args.Length() == 2) {
DCHECK(args[1]->IsString()); DCHECK(args[1]->IsString());
name = *v8::String::Utf8Value(args[1]); optional_root_name = *v8::String::Utf8Value(args[1]);
root.append(name);
root.append("/");
} }
std::string root(fileapi::GetIsolatedFileSystemRootURIString(
context_url.GetOrigin(),
file_system_id,
optional_root_name));
return webframe->createFileSystem( return webframe->createFileSystem(
WebKit::WebFileSystem::TypeIsolated, WebKit::WebFileSystem::TypeIsolated,
WebKit::WebString::fromUTF8(name), WebKit::WebString::fromUTF8(name),
......
...@@ -56,14 +56,12 @@ v8::Handle<v8::Value> MediaGalleriesCustomBindings::GetMediaFileSystemObject( ...@@ -56,14 +56,12 @@ v8::Handle<v8::Value> MediaGalleriesCustomBindings::GetMediaFileSystemObject(
WebKit::WebFrame* webframe = WebKit::WebFrame::frameForCurrentContext(); WebKit::WebFrame* webframe = WebKit::WebFrame::frameForCurrentContext();
const GURL origin = GURL(webframe->document().securityOrigin().toString()); const GURL origin = GURL(webframe->document().securityOrigin().toString());
const GURL root_url = const std::string root_url =
fileapi::GetFileSystemRootURI(origin, fileapi::kFileSystemTypeIsolated); fileapi::GetIsolatedFileSystemRootURIString(
const std::string url = origin, fsid, extension_misc::kMediaFileSystemPathPart);
base::StringPrintf("%s%s/%s/", root_url.spec().c_str(), fsid.c_str(),
extension_misc::kMediaFileSystemPathPart);
return webframe->createFileSystem(WebKit::WebFileSystem::TypeIsolated, return webframe->createFileSystem(WebKit::WebFileSystem::TypeIsolated,
WebKit::WebString::fromUTF8(name), WebKit::WebString::fromUTF8(name),
WebKit::WebString::fromUTF8(url)); WebKit::WebString::fromUTF8(root_url));
} }
v8::Handle<v8::Value> MediaGalleriesCustomBindings::ExtractEmbeddedThumbnails( v8::Handle<v8::Value> MediaGalleriesCustomBindings::ExtractEmbeddedThumbnails(
......
...@@ -273,4 +273,20 @@ bool CrackIsolatedFileSystemName(const std::string& filesystem_name, ...@@ -273,4 +273,20 @@ bool CrackIsolatedFileSystemName(const std::string& filesystem_name,
return true; return true;
} }
std::string GetIsolatedFileSystemRootURIString(
const GURL& origin_url,
const std::string& filesystem_id,
const std::string& optional_root_name) {
std::string root = GetFileSystemRootURI(origin_url,
kFileSystemTypeIsolated).spec();
root.append(filesystem_id);
root.append("/");
if (!optional_root_name.empty()) {
DCHECK(!FilePath::FromUTF8Unsafe(optional_root_name).ReferencesParent());
root.append(optional_root_name);
root.append("/");
}
return root;
}
} // namespace fileapi } // namespace fileapi
...@@ -123,6 +123,14 @@ WEBKIT_STORAGE_EXPORT bool CrackIsolatedFileSystemName( ...@@ -123,6 +123,14 @@ WEBKIT_STORAGE_EXPORT bool CrackIsolatedFileSystemName(
const std::string& filesystem_name, const std::string& filesystem_name,
std::string* filesystem_id); std::string* filesystem_id);
// Returns the root URI for an isolated filesystem for origin |origin_url|
// and |filesystem_id|. If the |optional_root_name| is given the resulting
// root URI will point to the subfolder within the isolated filesystem.
WEBKIT_STORAGE_EXPORT std::string GetIsolatedFileSystemRootURIString(
const GURL& origin_url,
const std::string& filesystem_id,
const std::string& optional_root_name);
} // namespace fileapi } // namespace fileapi
#endif // WEBKIT_FILEAPI_FILE_SYSTEM_UTIL_H_ #endif // WEBKIT_FILEAPI_FILE_SYSTEM_UTIL_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment