139864df125850b207b1a1d8dd5578276b9cab11
[platform/framework/web/crosswalk.git] / src / chrome / renderer / extensions / media_galleries_custom_bindings.cc
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.
4
5 #include "chrome/renderer/extensions/media_galleries_custom_bindings.h"
6
7 #include <string>
8
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"
14
15 namespace extensions {
16
17 namespace {
18
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());
24
25   std::string fsid(*v8::String::Utf8Value(args[0]));
26   CHECK(!fsid.empty());
27
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)));
38 }
39
40 }  // namespace
41
42 MediaGalleriesCustomBindings::MediaGalleriesCustomBindings(
43     Dispatcher* dispatcher, ChromeV8Context* context)
44     : ChromeV8Extension(dispatcher, context) {
45   RouteFunction("GetMediaFileSystemObject",
46                 base::Bind(&GetMediaFileSystemObject));
47 }
48
49 }  // namespace extensions