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 "extensions/renderer/script_context.h" 10#include "storage/common/fileapi/file_system_util.h" 11#include "third_party/WebKit/public/web/WebDOMFileSystem.h" 12#include "third_party/WebKit/public/web/WebDocument.h" 13#include "third_party/WebKit/public/web/WebLocalFrame.h" 14#include "v8/include/v8.h" 15 16namespace extensions { 17 18namespace { 19 20// FileSystemObject GetMediaFileSystem(string file_system_url): construct 21// a file system object from a file system url. 22void GetMediaFileSystemObject(const v8::FunctionCallbackInfo<v8::Value>& args) { 23 CHECK_EQ(1, args.Length()); 24 CHECK(args[0]->IsString()); 25 26 std::string fs_mount(*v8::String::Utf8Value(args[0])); 27 CHECK(!fs_mount.empty()); 28 29 blink::WebLocalFrame* webframe = 30 blink::WebLocalFrame::frameForCurrentContext(); 31 const GURL origin = GURL(webframe->document().securityOrigin().toString()); 32 std::string fs_name = 33 storage::GetFileSystemName(origin, storage::kFileSystemTypeExternal); 34 fs_name.append("_"); 35 fs_name.append(fs_mount); 36 const GURL root_url( 37 storage::GetExternalFileSystemRootURIString(origin, fs_mount)); 38 args.GetReturnValue().Set( 39 blink::WebDOMFileSystem::create(webframe, 40 blink::WebFileSystemTypeExternal, 41 blink::WebString::fromUTF8(fs_name), 42 root_url) 43 .toV8Value(args.Holder(), args.GetIsolate())); 44} 45 46} // namespace 47 48MediaGalleriesCustomBindings::MediaGalleriesCustomBindings( 49 ScriptContext* context) 50 : ObjectBackedNativeHandler(context) { 51 RouteFunction("GetMediaFileSystemObject", 52 base::Bind(&GetMediaFileSystemObject)); 53} 54 55} // namespace extensions 56