| 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_manager_private_custom_bindings.h" | 5 #include "chrome/renderer/extensions/file_manager_private_custom_bindings.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h" |
| 10 #include "extensions/renderer/script_context.h" | 11 #include "extensions/renderer/script_context.h" |
| 12 #include "extensions/renderer/v8_helpers.h" |
| 11 #include "third_party/WebKit/public/platform/WebString.h" | 13 #include "third_party/WebKit/public/platform/WebString.h" |
| 12 #include "third_party/WebKit/public/web/WebDOMFileSystem.h" | 14 #include "third_party/WebKit/public/web/WebDOMFileSystem.h" |
| 13 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 15 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 14 | 16 |
| 15 namespace extensions { | 17 namespace extensions { |
| 16 | 18 |
| 17 FileManagerPrivateCustomBindings::FileManagerPrivateCustomBindings( | 19 FileManagerPrivateCustomBindings::FileManagerPrivateCustomBindings( |
| 18 ScriptContext* context) | 20 ScriptContext* context) |
| 19 : ObjectBackedNativeHandler(context) { | 21 : ObjectBackedNativeHandler(context) { |
| 22 RouteFunction("GetFileSystem", "fileManagerPrivate", |
| 23 base::Bind(&FileManagerPrivateCustomBindings::GetFileSystem, |
| 24 base::Unretained(this))); |
| 20 RouteFunction( | 25 RouteFunction( |
| 21 "GetFileSystem", | 26 "GetExternalFileEntry", "fileManagerPrivate", |
| 22 base::Bind(&FileManagerPrivateCustomBindings::GetFileSystem, | 27 base::Bind(&FileManagerPrivateCustomBindings::GetExternalFileEntry, |
| 23 base::Unretained(this))); | 28 base::Unretained(this))); |
| 29 RouteFunction("GetEntryURL", "fileManagerPrivate", |
| 30 base::Bind(&FileManagerPrivateCustomBindings::GetEntryURL, |
| 31 base::Unretained(this))); |
| 24 } | 32 } |
| 25 | 33 |
| 26 void FileManagerPrivateCustomBindings::GetFileSystem( | 34 void FileManagerPrivateCustomBindings::GetFileSystem( |
| 27 const v8::FunctionCallbackInfo<v8::Value>& args) { | 35 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 28 DCHECK(args.Length() == 2); | 36 DCHECK(args.Length() == 2); |
| 29 DCHECK(args[0]->IsString()); | 37 DCHECK(args[0]->IsString()); |
| 30 DCHECK(args[1]->IsString()); | 38 DCHECK(args[1]->IsString()); |
| 31 std::string name(*v8::String::Utf8Value(args[0])); | 39 std::string name(*v8::String::Utf8Value(args[0])); |
| 32 std::string root_url(*v8::String::Utf8Value(args[1])); | 40 std::string root_url(*v8::String::Utf8Value(args[1])); |
| 33 | 41 |
| 34 blink::WebLocalFrame* webframe = | 42 blink::WebLocalFrame* webframe = |
| 35 blink::WebLocalFrame::frameForContext(context()->v8_context()); | 43 blink::WebLocalFrame::frameForContext(context()->v8_context()); |
| 36 DCHECK(webframe); | 44 DCHECK(webframe); |
| 37 args.GetReturnValue().Set( | 45 args.GetReturnValue().Set( |
| 38 blink::WebDOMFileSystem::create(webframe, | 46 blink::WebDOMFileSystem::create(webframe, |
| 39 blink::WebFileSystemTypeExternal, | 47 blink::WebFileSystemTypeExternal, |
| 40 blink::WebString::fromUTF8(name), | 48 blink::WebString::fromUTF8(name), |
| 41 GURL(root_url)) | 49 GURL(root_url)) |
| 42 .toV8Value(context()->v8_context()->Global(), args.GetIsolate())); | 50 .toV8Value(context()->v8_context()->Global(), args.GetIsolate())); |
| 43 } | 51 } |
| 44 | 52 |
| 53 void FileManagerPrivateCustomBindings::GetExternalFileEntry( |
| 54 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 55 FileBrowserHandlerCustomBindings::GetExternalFileEntry(args, context()); |
| 56 } |
| 57 |
| 58 void FileManagerPrivateCustomBindings::GetEntryURL( |
| 59 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 60 CHECK(args.Length() == 1); |
| 61 CHECK(args[0]->IsObject()); |
| 62 const blink::WebURL& url = |
| 63 blink::WebDOMFileSystem::createFileSystemURL(args[0]); |
| 64 args.GetReturnValue().Set(v8_helpers::ToV8StringUnsafe( |
| 65 args.GetIsolate(), url.string().utf8().c_str())); |
| 66 } |
| 67 |
| 45 } // namespace extensions | 68 } // namespace extensions |
| OLD | NEW |