Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 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/sync_file_system_custom_bindings.h" |
| 6 | |
| 7 | #include <string> |
| 8 | |
| 9 | #include "chrome/common/extensions/extension_constants.h" |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 10 | #include "chrome/renderer/extensions/chrome_v8_context.h" |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 11 | #include "third_party/WebKit/public/web/WebFrame.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 12 | #include "v8/include/v8.h" |
Torne (Richard Coles) | 90dce4d | 2013-05-29 14:40:03 +0100 | [diff] [blame] | 13 | #include "webkit/common/fileapi/file_system_util.h" |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 14 | |
| 15 | namespace extensions { |
| 16 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 17 | SyncFileSystemCustomBindings::SyncFileSystemCustomBindings( |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 18 | Dispatcher* dispatcher, ChromeV8Context* context) |
| 19 | : ChromeV8Extension(dispatcher, context) { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 20 | RouteFunction( |
| 21 | "GetSyncFileSystemObject", |
| 22 | base::Bind(&SyncFileSystemCustomBindings::GetSyncFileSystemObject, |
| 23 | base::Unretained(this))); |
| 24 | } |
| 25 | |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 26 | void SyncFileSystemCustomBindings::GetSyncFileSystemObject( |
| 27 | const v8::FunctionCallbackInfo<v8::Value>& args) { |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 28 | if (args.Length() != 2) { |
| 29 | NOTREACHED(); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 30 | return; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 31 | } |
| 32 | if (!args[0]->IsString()) { |
| 33 | NOTREACHED(); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 34 | return; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 35 | } |
| 36 | if (!args[1]->IsString()) { |
| 37 | NOTREACHED(); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 38 | return; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | std::string name(*v8::String::Utf8Value(args[0])); |
| 42 | if (name.empty()) { |
| 43 | NOTREACHED(); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 44 | return; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 45 | } |
| 46 | std::string root_url(*v8::String::Utf8Value(args[1])); |
| 47 | if (root_url.empty()) { |
| 48 | NOTREACHED(); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 49 | return; |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Torne (Richard Coles) | 2a99a7e | 2013-03-28 15:31:22 +0000 | [diff] [blame] | 52 | WebKit::WebFrame* webframe = |
Torne (Richard Coles) | 868fa2f | 2013-06-11 10:57:03 +0100 | [diff] [blame] | 53 | WebKit::WebFrame::frameForContext(context()->v8_context()); |
Torne (Richard Coles) | 7d4cd47 | 2013-06-19 11:58:07 +0100 | [diff] [blame] | 54 | args.GetReturnValue().Set( |
| 55 | webframe->createFileSystem(WebKit::WebFileSystemTypeExternal, |
| 56 | WebKit::WebString::fromUTF8(name), |
| 57 | WebKit::WebString::fromUTF8(root_url))); |
Torne (Richard Coles) | 5821806 | 2012-11-14 11:43:16 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | } // namespace extensions |