blob: ff65c93adc47d69d5cd14ba1b8b3cf1ae3c632a8 [file] [log] [blame]
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/renderer/extensions/file_browser_private_custom_bindings.h"
#include <string>
#include "base/basictypes.h"
#include "base/logging.h"
#include "chrome/renderer/extensions/chrome_v8_context.h"
#include "extensions/renderer/script_context.h"
#include "third_party/WebKit/public/platform/WebString.h"
#include "third_party/WebKit/public/web/WebDOMFileSystem.h"
#include "third_party/WebKit/public/web/WebLocalFrame.h"
namespace extensions {
FileBrowserPrivateCustomBindings::FileBrowserPrivateCustomBindings(
ScriptContext* context)
: ObjectBackedNativeHandler(context) {
RouteFunction(
"GetFileSystem",
base::Bind(&FileBrowserPrivateCustomBindings::GetFileSystem,
base::Unretained(this)));
}
void FileBrowserPrivateCustomBindings::GetFileSystem(
const v8::FunctionCallbackInfo<v8::Value>& args) {
DCHECK(args.Length() == 2);
DCHECK(args[0]->IsString());
DCHECK(args[1]->IsString());
std::string name(*v8::String::Utf8Value(args[0]));
std::string root_url(*v8::String::Utf8Value(args[1]));
blink::WebLocalFrame* webframe =
blink::WebLocalFrame::frameForContext(context()->v8_context());
DCHECK(webframe);
args.GetReturnValue().Set(
blink::WebDOMFileSystem::create(webframe,
blink::WebFileSystemTypeExternal,
blink::WebString::fromUTF8(name),
GURL(root_url))
.toV8Value(args.Holder(), args.GetIsolate()));
}
} // namespace extensions