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/sync_file_system_custom_bindings.h"
9 #include "chrome/common/extensions/extension_constants.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
11 #include "v8/include/v8.h"
12 #include "webkit/fileapi/file_system_util.h"
14 namespace extensions
{
16 SyncFileSystemCustomBindings::SyncFileSystemCustomBindings(
17 Dispatcher
* dispatcher
, v8::Handle
<v8::Context
> v8_context
)
18 : ChromeV8Extension(dispatcher
, v8_context
) {
20 "GetSyncFileSystemObject",
21 base::Bind(&SyncFileSystemCustomBindings::GetSyncFileSystemObject
,
22 base::Unretained(this)));
25 v8::Handle
<v8::Value
> SyncFileSystemCustomBindings::GetSyncFileSystemObject(
26 const v8::Arguments
& args
) {
27 if (args
.Length() != 2) {
29 return v8::Undefined();
31 if (!args
[0]->IsString()) {
33 return v8::Undefined();
35 if (!args
[1]->IsString()) {
37 return v8::Undefined();
40 std::string
name(*v8::String::Utf8Value(args
[0]));
43 return v8::Undefined();
45 std::string
root_url(*v8::String::Utf8Value(args
[1]));
46 if (root_url
.empty()) {
48 return v8::Undefined();
51 WebKit::WebFrame
* webframe
=
52 WebKit::WebFrame::frameForContext(v8_context());
53 return webframe
->createFileSystem(
54 WebKit::WebFileSystemTypeExternal
,
55 WebKit::WebString::fromUTF8(name
),
56 WebKit::WebString::fromUTF8(root_url
));
59 } // namespace extensions