1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/renderer/extensions/media_galleries_custom_bindings.h"
9 #include "chrome/common/extensions/extension_constants.h"
10 #include "third_party/WebKit/public/web/WebDocument.h"
11 #include "third_party/WebKit/public/web/WebFrame.h"
12 #include "v8/include/v8.h"
13 #include "webkit/common/fileapi/file_system_util.h"
15 namespace extensions {
19 // FileSystemObject GetMediaFileSystem(string file_system_url): construct
20 // a file system object from a file system url.
21 void GetMediaFileSystemObject(const v8::FunctionCallbackInfo<v8::Value>& args) {
22 CHECK_EQ(1, args.Length());
23 CHECK(args[0]->IsString());
25 std::string fsid(*v8::String::Utf8Value(args[0]));
28 blink::WebFrame* webframe = blink::WebFrame::frameForCurrentContext();
29 const GURL origin = GURL(webframe->document().securityOrigin().toString());
30 const std::string fs_name = fileapi::GetIsolatedFileSystemName(origin, fsid);
31 const std::string root_url =
32 fileapi::GetIsolatedFileSystemRootURIString(
33 origin, fsid, extension_misc::kMediaFileSystemPathPart);
34 args.GetReturnValue().Set(
35 webframe->createFileSystem(blink::WebFileSystemTypeIsolated,
36 blink::WebString::fromUTF8(fs_name),
37 blink::WebString::fromUTF8(root_url)));
42 MediaGalleriesCustomBindings::MediaGalleriesCustomBindings(
43 Dispatcher* dispatcher, ChromeV8Context* context)
44 : ChromeV8Extension(dispatcher, context) {
45 RouteFunction("GetMediaFileSystemObject",
46 base::Bind(&GetMediaFileSystemObject));
49 } // namespace extensions