Home | History | Annotate | Download | only in extensions
      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/file_browser_handler_custom_bindings.h"
      6 
      7 #include <string>
      8 
      9 #include "base/basictypes.h"
     10 #include "base/logging.h"
     11 #include "chrome/renderer/extensions/chrome_v8_context.h"
     12 #include "grit/renderer_resources.h"
     13 #include "third_party/WebKit/public/platform/WebFileSystem.h"
     14 #include "third_party/WebKit/public/platform/WebFileSystemType.h"
     15 #include "third_party/WebKit/public/platform/WebString.h"
     16 #include "third_party/WebKit/public/web/WebFrame.h"
     17 
     18 namespace extensions {
     19 
     20 FileBrowserHandlerCustomBindings::FileBrowserHandlerCustomBindings(
     21     Dispatcher* dispatcher, ChromeV8Context* context)
     22     : ChromeV8Extension(dispatcher, context) {
     23   RouteFunction(
     24       "GetExternalFileEntry",
     25       base::Bind(&FileBrowserHandlerCustomBindings::GetExternalFileEntry,
     26                  base::Unretained(this)));
     27 }
     28 
     29 void FileBrowserHandlerCustomBindings::GetExternalFileEntry(
     30     const v8::FunctionCallbackInfo<v8::Value>& args) {
     31   // TODO(zelidrag): Make this magic work on other platforms when file browser
     32   // matures enough on ChromeOS.
     33 #if defined(OS_CHROMEOS)
     34     CHECK(args.Length() == 1);
     35     CHECK(args[0]->IsObject());
     36     v8::Local<v8::Object> file_def = args[0]->ToObject();
     37     std::string file_system_name(
     38         *v8::String::Utf8Value(file_def->Get(
     39             v8::String::New("fileSystemName"))));
     40     std::string file_system_path(
     41         *v8::String::Utf8Value(file_def->Get(
     42             v8::String::New("fileSystemRoot"))));
     43     std::string file_full_path(
     44         *v8::String::Utf8Value(file_def->Get(
     45             v8::String::New("fileFullPath"))));
     46     bool is_directory =
     47         file_def->Get(v8::String::New("fileIsDirectory"))->ToBoolean()->Value();
     48     WebKit::WebFrame* webframe =
     49         WebKit::WebFrame::frameForContext(context()->v8_context());
     50     args.GetReturnValue().Set(webframe->createFileEntry(
     51         WebKit::WebFileSystemTypeExternal,
     52         WebKit::WebString::fromUTF8(file_system_name.c_str()),
     53         WebKit::WebString::fromUTF8(file_system_path.c_str()),
     54         WebKit::WebString::fromUTF8(file_full_path.c_str()),
     55         is_directory));
     56 #endif
     57 }
     58 
     59 }  // namespace extensions
     60