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/media_galleries_custom_bindings.h" | 5 #include "chrome/renderer/extensions/media_galleries_custom_bindings.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/files/file_path.h" | |
10 #include "base/strings/stringprintf.h" | |
11 #include "chrome/common/extensions/extension_constants.h" | 9 #include "chrome/common/extensions/extension_constants.h" |
12 #include "third_party/WebKit/public/web/WebDocument.h" | 10 #include "third_party/WebKit/public/web/WebDocument.h" |
13 #include "third_party/WebKit/public/web/WebFrame.h" | 11 #include "third_party/WebKit/public/web/WebFrame.h" |
14 #include "v8/include/v8.h" | 12 #include "v8/include/v8.h" |
15 #include "webkit/common/fileapi/file_system_util.h" | 13 #include "webkit/common/fileapi/file_system_util.h" |
16 | 14 |
17 namespace extensions { | 15 namespace extensions { |
18 | 16 |
19 MediaGalleriesCustomBindings::MediaGalleriesCustomBindings( | 17 namespace { |
20 Dispatcher* dispatcher, ChromeV8Context* context) | |
21 : ChromeV8Extension(dispatcher, context) { | |
22 RouteFunction( | |
23 "GetMediaFileSystemObject", | |
24 base::Bind(&MediaGalleriesCustomBindings::GetMediaFileSystemObject, | |
25 base::Unretained(this))); | |
26 } | |
27 | 18 |
28 void MediaGalleriesCustomBindings::GetMediaFileSystemObject( | 19 // FileSystemObject GetMediaFileSystem(string file_system_url): construct |
29 const v8::FunctionCallbackInfo<v8::Value>& args) { | 20 // a file system object from a file system url. |
| 21 void GetMediaFileSystemObject(const v8::FunctionCallbackInfo<v8::Value>& args) { |
30 if (args.Length() != 1) { | 22 if (args.Length() != 1) { |
31 NOTREACHED(); | 23 NOTREACHED(); |
32 return; | 24 return; |
33 } | 25 } |
34 if (!args[0]->IsString()) { | 26 if (!args[0]->IsString()) { |
35 NOTREACHED(); | 27 NOTREACHED(); |
36 return; | 28 return; |
37 } | 29 } |
38 | 30 |
39 std::string fsid(*v8::String::Utf8Value(args[0])); | 31 std::string fsid(*v8::String::Utf8Value(args[0])); |
40 if (fsid.empty()) { | 32 if (fsid.empty()) { |
41 NOTREACHED(); | 33 NOTREACHED(); |
42 return; | 34 return; |
43 } | 35 } |
44 | 36 |
45 blink::WebFrame* webframe = blink::WebFrame::frameForCurrentContext(); | 37 blink::WebFrame* webframe = blink::WebFrame::frameForCurrentContext(); |
46 const GURL origin = GURL(webframe->document().securityOrigin().toString()); | 38 const GURL origin = GURL(webframe->document().securityOrigin().toString()); |
47 const std::string fs_name = fileapi::GetIsolatedFileSystemName(origin, fsid); | 39 const std::string fs_name = fileapi::GetIsolatedFileSystemName(origin, fsid); |
48 const std::string root_url = | 40 const std::string root_url = |
49 fileapi::GetIsolatedFileSystemRootURIString( | 41 fileapi::GetIsolatedFileSystemRootURIString( |
50 origin, fsid, extension_misc::kMediaFileSystemPathPart); | 42 origin, fsid, extension_misc::kMediaFileSystemPathPart); |
51 args.GetReturnValue().Set( | 43 args.GetReturnValue().Set( |
52 webframe->createFileSystem(blink::WebFileSystemTypeIsolated, | 44 webframe->createFileSystem(blink::WebFileSystemTypeIsolated, |
53 blink::WebString::fromUTF8(fs_name), | 45 blink::WebString::fromUTF8(fs_name), |
54 blink::WebString::fromUTF8(root_url))); | 46 blink::WebString::fromUTF8(root_url))); |
55 } | 47 } |
56 | 48 |
| 49 } // namespace |
| 50 |
| 51 MediaGalleriesCustomBindings::MediaGalleriesCustomBindings( |
| 52 Dispatcher* dispatcher, ChromeV8Context* context) |
| 53 : ChromeV8Extension(dispatcher, context) { |
| 54 RouteFunction("GetMediaFileSystemObject", |
| 55 base::Bind(&GetMediaFileSystemObject)); |
| 56 } |
| 57 |
57 } // namespace extensions | 58 } // namespace extensions |
OLD | NEW |