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/sync_file_system_custom_bindings.h" 6 7 #include <string> 8 9 #include "chrome/common/extensions/extension_constants.h" 10 #include "chrome/renderer/extensions/chrome_v8_context.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 SyncFileSystemCustomBindings(Dispatcher * dispatcher,ChromeV8Context * context)17SyncFileSystemCustomBindings::SyncFileSystemCustomBindings( 18 Dispatcher* dispatcher, ChromeV8Context* context) 19 : ChromeV8Extension(dispatcher, context) { 20 RouteFunction( 21 "GetSyncFileSystemObject", 22 base::Bind(&SyncFileSystemCustomBindings::GetSyncFileSystemObject, 23 base::Unretained(this))); 24 } 25 GetSyncFileSystemObject(const v8::FunctionCallbackInfo<v8::Value> & args)26void SyncFileSystemCustomBindings::GetSyncFileSystemObject( 27 const v8::FunctionCallbackInfo<v8::Value>& args) { 28 if (args.Length() != 2) { 29 NOTREACHED(); 30 return; 31 } 32 if (!args[0]->IsString()) { 33 NOTREACHED(); 34 return; 35 } 36 if (!args[1]->IsString()) { 37 NOTREACHED(); 38 return; 39 } 40 41 std::string name(*v8::String::Utf8Value(args[0])); 42 if (name.empty()) { 43 NOTREACHED(); 44 return; 45 } 46 std::string root_url(*v8::String::Utf8Value(args[1])); 47 if (root_url.empty()) { 48 NOTREACHED(); 49 return; 50 } 51 52 blink::WebFrame* webframe = 53 blink::WebFrame::frameForContext(context()->v8_context()); 54 args.GetReturnValue().Set( 55 webframe->createFileSystem(blink::WebFileSystemTypeExternal, 56 blink::WebString::fromUTF8(name), 57 blink::WebString::fromUTF8(root_url))); 58 } 59 60 } // namespace extensions 61