Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / renderer / extensions / file_browser_handler_custom_bindings.cc
blob521e43479c4fef05215ef21baeecaa2de354cdf8
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/file_browser_handler_custom_bindings.h"
7 #include <string>
9 #include "base/basictypes.h"
10 #include "base/logging.h"
11 #include "extensions/renderer/script_context.h"
12 #include "third_party/WebKit/public/platform/WebString.h"
13 #include "third_party/WebKit/public/web/WebDOMFileSystem.h"
14 #include "third_party/WebKit/public/web/WebLocalFrame.h"
15 #include "third_party/WebKit/public/web/WebScriptBindings.h"
17 namespace extensions {
19 FileBrowserHandlerCustomBindings::FileBrowserHandlerCustomBindings(
20 ScriptContext* context)
21 : ObjectBackedNativeHandler(context) {
22 RouteFunction(
23 "GetExternalFileEntry",
24 base::Bind(&FileBrowserHandlerCustomBindings::GetExternalFileEntry,
25 base::Unretained(this)));
26 RouteFunction("GetEntryURL",
27 base::Bind(&FileBrowserHandlerCustomBindings::GetEntryURL,
28 base::Unretained(this)));
31 void FileBrowserHandlerCustomBindings::GetExternalFileEntry(
32 const v8::FunctionCallbackInfo<v8::Value>& args) {
33 // TODO(zelidrag): Make this magic work on other platforms when file browser
34 // matures enough on ChromeOS.
35 #if defined(OS_CHROMEOS)
36 CHECK(args.Length() == 1);
37 CHECK(args[0]->IsObject());
38 v8::Local<v8::Object> file_def = args[0]->ToObject();
39 std::string file_system_name(
40 *v8::String::Utf8Value(file_def->Get(
41 v8::String::NewFromUtf8(args.GetIsolate(), "fileSystemName"))));
42 GURL file_system_root(
43 *v8::String::Utf8Value(file_def->Get(
44 v8::String::NewFromUtf8(args.GetIsolate(), "fileSystemRoot"))));
45 std::string file_full_path(
46 *v8::String::Utf8Value(file_def->Get(
47 v8::String::NewFromUtf8(args.GetIsolate(), "fileFullPath"))));
48 bool is_directory = file_def->Get(v8::String::NewFromUtf8(
49 args.GetIsolate(), "fileIsDirectory"))->ToBoolean()->Value();
50 blink::WebDOMFileSystem::EntryType entry_type =
51 is_directory ? blink::WebDOMFileSystem::EntryTypeDirectory
52 : blink::WebDOMFileSystem::EntryTypeFile;
53 blink::WebLocalFrame* webframe =
54 blink::WebLocalFrame::frameForContext(context()->v8_context());
55 args.GetReturnValue().Set(
56 blink::WebDOMFileSystem::create(
57 webframe,
58 blink::WebFileSystemTypeExternal,
59 blink::WebString::fromUTF8(file_system_name),
60 file_system_root)
61 .createV8Entry(blink::WebString::fromUTF8(file_full_path),
62 entry_type,
63 args.Holder(),
64 args.GetIsolate()));
65 #endif
68 void FileBrowserHandlerCustomBindings::GetEntryURL(
69 const v8::FunctionCallbackInfo<v8::Value>& args) {
70 CHECK(args.Length() == 1);
71 CHECK(args[0]->IsObject());
72 const blink::WebURL& url =
73 blink::WebDOMFileSystem::createFileSystemURL(args[0]);
74 args.GetReturnValue().Set(
75 blink::WebScriptBindings::toV8String(url.string(), args.GetIsolate()));
78 } // namespace extensions