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 "base/files/file_path.h"
10 #include "base/strings/stringprintf.h"
11 #include "chrome/common/extensions/extension_constants.h"
12 #include "third_party/WebKit/public/web/WebDocument.h"
13 #include "third_party/WebKit/public/web/WebFrame.h"
14 #include "v8/include/v8.h"
15 #include "webkit/common/fileapi/file_system_util.h"
17 namespace extensions {
19 MediaGalleriesCustomBindings::MediaGalleriesCustomBindings(
20 Dispatcher* dispatcher, ChromeV8Context* context)
21 : ChromeV8Extension(dispatcher, context) {
23 "GetMediaFileSystemObject",
24 base::Bind(&MediaGalleriesCustomBindings::GetMediaFileSystemObject,
25 base::Unretained(this)));
28 void MediaGalleriesCustomBindings::GetMediaFileSystemObject(
29 const v8::FunctionCallbackInfo<v8::Value>& args) {
30 if (args.Length() != 1) {
34 if (!args[0]->IsString()) {
39 std::string fsid(*v8::String::Utf8Value(args[0]));
45 WebKit::WebFrame* webframe = WebKit::WebFrame::frameForCurrentContext();
46 const GURL origin = GURL(webframe->document().securityOrigin().toString());
47 const std::string fs_name = fileapi::GetIsolatedFileSystemName(origin, fsid);
48 const std::string root_url =
49 fileapi::GetIsolatedFileSystemRootURIString(
50 origin, fsid, extension_misc::kMediaFileSystemPathPart);
51 args.GetReturnValue().Set(
52 webframe->createFileSystem(WebKit::WebFileSystemTypeIsolated,
53 WebKit::WebString::fromUTF8(fs_name),
54 WebKit::WebString::fromUTF8(root_url)));
57 } // namespace extensions