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 if (args
.Length() != 1) {
26 if (!args
[0]->IsString()) {
31 std::string
fsid(*v8::String::Utf8Value(args
[0]));
37 blink::WebFrame
* webframe
= blink::WebFrame::frameForCurrentContext();
38 const GURL origin
= GURL(webframe
->document().securityOrigin().toString());
39 const std::string fs_name
= fileapi::GetIsolatedFileSystemName(origin
, fsid
);
40 const std::string root_url
=
41 fileapi::GetIsolatedFileSystemRootURIString(
42 origin
, fsid
, extension_misc::kMediaFileSystemPathPart
);
43 args
.GetReturnValue().Set(
44 webframe
->createFileSystem(blink::WebFileSystemTypeIsolated
,
45 blink::WebString::fromUTF8(fs_name
),
46 blink::WebString::fromUTF8(root_url
)));
51 MediaGalleriesCustomBindings::MediaGalleriesCustomBindings(
52 Dispatcher
* dispatcher
, ChromeV8Context
* context
)
53 : ChromeV8Extension(dispatcher
, context
) {
54 RouteFunction("GetMediaFileSystemObject",
55 base::Bind(&GetMediaFileSystemObject
));
58 } // namespace extensions