Suppression for crbug/241044.
[chromium-blink-merge.git] / chrome / renderer / extensions / file_browser_handler_custom_bindings.cc
blob7fd556787b3fca09e865e9fb6f85198c3024b9d5
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 "grit/renderer_resources.h"
12 #include "third_party/WebKit/Source/Platform/chromium/public/WebFileSystem.h"
13 #include "third_party/WebKit/Source/Platform/chromium/public/WebFileSystemType.h"
14 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
17 namespace extensions {
19 FileBrowserHandlerCustomBindings::FileBrowserHandlerCustomBindings(
20 Dispatcher* dispatcher, v8::Handle<v8::Context> context)
21 : ChromeV8Extension(dispatcher, context) {
22 RouteFunction(
23 "GetExternalFileEntry",
24 base::Bind(&FileBrowserHandlerCustomBindings::GetExternalFileEntry,
25 base::Unretained(this)));
28 v8::Handle<v8::Value> FileBrowserHandlerCustomBindings::GetExternalFileEntry(
29 const v8::Arguments& args) {
30 // TODO(zelidrag): Make this magic work on other platforms when file browser
31 // matures enough on ChromeOS.
32 #if defined(OS_CHROMEOS)
33 CHECK(args.Length() == 1);
34 CHECK(args[0]->IsObject());
35 v8::Local<v8::Object> file_def = args[0]->ToObject();
36 std::string file_system_name(
37 *v8::String::Utf8Value(file_def->Get(
38 v8::String::New("fileSystemName"))));
39 std::string file_system_path(
40 *v8::String::Utf8Value(file_def->Get(
41 v8::String::New("fileSystemRoot"))));
42 std::string file_full_path(
43 *v8::String::Utf8Value(file_def->Get(
44 v8::String::New("fileFullPath"))));
45 bool is_directory =
46 file_def->Get(v8::String::New("fileIsDirectory"))->ToBoolean()->Value();
47 WebKit::WebFrame* webframe =
48 WebKit::WebFrame::frameForContext(v8_context());
49 return webframe->createFileEntry(
50 WebKit::WebFileSystemTypeExternal,
51 WebKit::WebString::fromUTF8(file_system_name.c_str()),
52 WebKit::WebString::fromUTF8(file_system_path.c_str()),
53 WebKit::WebString::fromUTF8(file_full_path.c_str()),
54 is_directory);
55 #else
56 return v8::Undefined();
57 #endif
60 } // namespace extensions