OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h" | 5 #include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "chrome/renderer/extensions/chrome_v8_context.h" |
11 #include "grit/renderer_resources.h" | 12 #include "grit/renderer_resources.h" |
12 #include "third_party/WebKit/public/platform/WebFileSystem.h" | 13 #include "third_party/WebKit/public/platform/WebFileSystem.h" |
13 #include "third_party/WebKit/public/platform/WebFileSystemType.h" | 14 #include "third_party/WebKit/public/platform/WebFileSystemType.h" |
14 #include "third_party/WebKit/public/platform/WebString.h" | 15 #include "third_party/WebKit/public/platform/WebString.h" |
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
16 | 17 |
17 namespace extensions { | 18 namespace extensions { |
18 | 19 |
19 FileBrowserHandlerCustomBindings::FileBrowserHandlerCustomBindings( | 20 FileBrowserHandlerCustomBindings::FileBrowserHandlerCustomBindings( |
20 Dispatcher* dispatcher, v8::Handle<v8::Context> context) | 21 Dispatcher* dispatcher, ChromeV8Context* context) |
21 : ChromeV8Extension(dispatcher, context) { | 22 : ChromeV8Extension(dispatcher, context) { |
22 RouteFunction( | 23 RouteFunction( |
23 "GetExternalFileEntry", | 24 "GetExternalFileEntry", |
24 base::Bind(&FileBrowserHandlerCustomBindings::GetExternalFileEntry, | 25 base::Bind(&FileBrowserHandlerCustomBindings::GetExternalFileEntry, |
25 base::Unretained(this))); | 26 base::Unretained(this))); |
26 } | 27 } |
27 | 28 |
28 v8::Handle<v8::Value> FileBrowserHandlerCustomBindings::GetExternalFileEntry( | 29 v8::Handle<v8::Value> FileBrowserHandlerCustomBindings::GetExternalFileEntry( |
29 const v8::Arguments& args) { | 30 const v8::Arguments& args) { |
30 // TODO(zelidrag): Make this magic work on other platforms when file browser | 31 // TODO(zelidrag): Make this magic work on other platforms when file browser |
31 // matures enough on ChromeOS. | 32 // matures enough on ChromeOS. |
32 #if defined(OS_CHROMEOS) | 33 #if defined(OS_CHROMEOS) |
33 CHECK(args.Length() == 1); | 34 CHECK(args.Length() == 1); |
34 CHECK(args[0]->IsObject()); | 35 CHECK(args[0]->IsObject()); |
35 v8::Local<v8::Object> file_def = args[0]->ToObject(); | 36 v8::Local<v8::Object> file_def = args[0]->ToObject(); |
36 std::string file_system_name( | 37 std::string file_system_name( |
37 *v8::String::Utf8Value(file_def->Get( | 38 *v8::String::Utf8Value(file_def->Get( |
38 v8::String::New("fileSystemName")))); | 39 v8::String::New("fileSystemName")))); |
39 std::string file_system_path( | 40 std::string file_system_path( |
40 *v8::String::Utf8Value(file_def->Get( | 41 *v8::String::Utf8Value(file_def->Get( |
41 v8::String::New("fileSystemRoot")))); | 42 v8::String::New("fileSystemRoot")))); |
42 std::string file_full_path( | 43 std::string file_full_path( |
43 *v8::String::Utf8Value(file_def->Get( | 44 *v8::String::Utf8Value(file_def->Get( |
44 v8::String::New("fileFullPath")))); | 45 v8::String::New("fileFullPath")))); |
45 bool is_directory = | 46 bool is_directory = |
46 file_def->Get(v8::String::New("fileIsDirectory"))->ToBoolean()->Value(); | 47 file_def->Get(v8::String::New("fileIsDirectory"))->ToBoolean()->Value(); |
47 WebKit::WebFrame* webframe = | 48 WebKit::WebFrame* webframe = |
48 WebKit::WebFrame::frameForContext(v8_context()); | 49 WebKit::WebFrame::frameForContext(context()->v8_context()); |
49 return webframe->createFileEntry( | 50 return webframe->createFileEntry( |
50 WebKit::WebFileSystemTypeExternal, | 51 WebKit::WebFileSystemTypeExternal, |
51 WebKit::WebString::fromUTF8(file_system_name.c_str()), | 52 WebKit::WebString::fromUTF8(file_system_name.c_str()), |
52 WebKit::WebString::fromUTF8(file_system_path.c_str()), | 53 WebKit::WebString::fromUTF8(file_system_path.c_str()), |
53 WebKit::WebString::fromUTF8(file_full_path.c_str()), | 54 WebKit::WebString::fromUTF8(file_full_path.c_str()), |
54 is_directory); | 55 is_directory); |
55 #else | 56 #else |
56 return v8::Undefined(); | 57 return v8::Undefined(); |
57 #endif | 58 #endif |
58 } | 59 } |
59 | 60 |
60 } // namespace extensions | 61 } // namespace extensions |
OLD | NEW |