| OLD | NEW |
| (Empty) |
| 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/media_gallery_custom_bindings.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/file_path.h" | |
| 10 #include "base/stringprintf.h" | |
| 11 #include "chrome/common/extensions/extension_constants.h" | |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | |
| 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | |
| 14 #include "v8/include/v8.h" | |
| 15 #include "webkit/fileapi/file_system_util.h" | |
| 16 | |
| 17 namespace extensions { | |
| 18 | |
| 19 MediaGalleryCustomBindings::MediaGalleryCustomBindings() | |
| 20 : ChromeV8Extension(NULL) { | |
| 21 RouteFunction( | |
| 22 "GetMediaFileSystemObject", | |
| 23 base::Bind(&MediaGalleryCustomBindings::GetMediaFileSystemObject, | |
| 24 base::Unretained(this))); | |
| 25 RouteFunction( | |
| 26 "ExtractEmbeddedThumbnails", | |
| 27 base::Bind(&MediaGalleryCustomBindings::ExtractEmbeddedThumbnails, | |
| 28 base::Unretained(this))); | |
| 29 } | |
| 30 | |
| 31 v8::Handle<v8::Value> MediaGalleryCustomBindings::GetMediaFileSystemObject( | |
| 32 const v8::Arguments& args) { | |
| 33 if (args.Length() != 2) { | |
| 34 NOTREACHED(); | |
| 35 return v8::Undefined(); | |
| 36 } | |
| 37 if (!args[0]->IsString()) { | |
| 38 NOTREACHED(); | |
| 39 return v8::Undefined(); | |
| 40 } | |
| 41 if (!args[1]->IsString()) { | |
| 42 NOTREACHED(); | |
| 43 return v8::Undefined(); | |
| 44 } | |
| 45 | |
| 46 std::string fsid(*v8::String::Utf8Value(args[0])); | |
| 47 if (fsid.empty()) { | |
| 48 NOTREACHED(); | |
| 49 return v8::Undefined(); | |
| 50 } | |
| 51 std::string name(*v8::String::Utf8Value(args[1])); | |
| 52 if (name.empty()) { | |
| 53 NOTREACHED(); | |
| 54 return v8::Undefined(); | |
| 55 } | |
| 56 | |
| 57 WebKit::WebFrame* webframe = WebKit::WebFrame::frameForCurrentContext(); | |
| 58 const GURL origin = GURL(webframe->document().securityOrigin().toString()); | |
| 59 const GURL root_url = | |
| 60 fileapi::GetFileSystemRootURI(origin, fileapi::kFileSystemTypeIsolated); | |
| 61 const std::string url = | |
| 62 base::StringPrintf("%s%s/%s/", root_url.spec().c_str(), fsid.c_str(), | |
| 63 extension_misc::kMediaFileSystemPathPart); | |
| 64 return webframe->createFileSystem(WebKit::WebFileSystem::TypeIsolated, | |
| 65 WebKit::WebString::fromUTF8(name), | |
| 66 WebKit::WebString::fromUTF8(url)); | |
| 67 } | |
| 68 | |
| 69 v8::Handle<v8::Value> MediaGalleryCustomBindings::ExtractEmbeddedThumbnails( | |
| 70 const v8::Arguments& args) { | |
| 71 if (args.Length() != 1) { | |
| 72 NOTREACHED() << "Bad arguments"; | |
| 73 return v8::Undefined(); | |
| 74 } | |
| 75 // TODO(vandebo) Check that the object is a FileEntry. | |
| 76 | |
| 77 // TODO(vandebo) Create and return a Directory entry object. | |
| 78 return v8::Null(); | |
| 79 } | |
| 80 | |
| 81 } // namespace extensions | |
| OLD | NEW |