Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: chrome/renderer/extensions/media_gallery_custom_bindings.cc

Issue 10409084: Media Gallery: Implement a basic version of GetMediaFileSystems(). (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_gallery_custom_bindings.h" 5 #include "chrome/renderer/extensions/media_gallery_custom_bindings.h"
6 6
7 #include "content/public/renderer/render_view.h" 7 #include <string>
8 #include "grit/renderer_resources.h" 8
9 #include "base/file_path.h"
10 #include "base/stringprintf.h"
11 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
9 #include "v8/include/v8.h" 13 #include "v8/include/v8.h"
14 #include "webkit/fileapi/file_system_util.h"
10 15
11 namespace extensions { 16 namespace extensions {
12 17
13 MediaGalleryCustomBindings::MediaGalleryCustomBindings() 18 MediaGalleryCustomBindings::MediaGalleryCustomBindings()
14 : ChromeV8Extension(NULL) { 19 : ChromeV8Extension(NULL) {
15 RouteFunction( 20 RouteFunction(
16 "GetMediaFileSystemObject", 21 "GetMediaFileSystemObject",
17 base::Bind(&MediaGalleryCustomBindings::GetMediaFileSystemObject, 22 base::Bind(&MediaGalleryCustomBindings::GetMediaFileSystemObject,
18 base::Unretained(this))); 23 base::Unretained(this)));
19 RouteFunction( 24 RouteFunction(
20 "ExtractEmbeddedThumbnails", 25 "ExtractEmbeddedThumbnails",
21 base::Bind(&MediaGalleryCustomBindings::ExtractEmbeddedThumbnails, 26 base::Bind(&MediaGalleryCustomBindings::ExtractEmbeddedThumbnails,
22 base::Unretained(this))); 27 base::Unretained(this)));
23 } 28 }
24 29
25 v8::Handle<v8::Value> MediaGalleryCustomBindings::GetMediaFileSystemObject( 30 v8::Handle<v8::Value> MediaGalleryCustomBindings::GetMediaFileSystemObject(
26 const v8::Arguments& args) { 31 const v8::Arguments& args) {
27 if (args.Length() != 1) { 32 if (args.Length() != 2) {
28 NOTREACHED(); 33 NOTREACHED();
29 return v8::Undefined(); 34 return v8::Undefined();
30 } 35 }
31 if (!args[0]->IsString()) { 36 if (!args[0]->IsString()) {
32 NOTREACHED(); 37 NOTREACHED();
33 return v8::Undefined(); 38 return v8::Undefined();
34 } 39 }
40 if (!args[1]->IsString()) {
41 NOTREACHED();
42 return v8::Undefined();
43 }
35 44
36 std::string file_system_url; 45 std::string fsid(*v8::String::Utf8Value(args[0]));
37 file_system_url = *v8::String::Utf8Value(args[1]->ToString()); 46 if (fsid.empty()) {
38 if (file_system_url.empty()) 47 NOTREACHED();
39 return v8::Undefined(); 48 return v8::Undefined();
49 }
50 std::string dirname(*v8::String::Utf8Value(args[1]));
51 if (dirname.empty()) {
52 NOTREACHED();
53 return v8::Undefined();
54 }
40 55
41 // TODO(vandebo) Create and return a FileSystem object. 56 WebKit::WebFrame* webframe = WebKit::WebFrame::frameForCurrentContext();
42 return v8::Undefined(); 57 const GURL origin = GURL(webframe->document().securityOrigin().toString());
58 const GURL root_url =
59 fileapi::GetFileSystemRootURI(origin, fileapi::kFileSystemTypeIsolated);
60 const std::string fsname_prefix =
61 fileapi::GetFileSystemName(origin, fileapi::kFileSystemTypeIsolated);
62 const std::string fsname =
63 base::StringPrintf("%s_%s", fsname_prefix.c_str(), fsid.c_str());
64 const std::string url = base::StringPrintf("%s%s/%s/",
65 root_url.spec().c_str(),
66 fsid.c_str(),
67 dirname.c_str());
68 return webframe->createFileSystem(WebKit::WebFileSystem::TypeIsolated,
69 WebKit::WebString::fromUTF8(fsname),
70 WebKit::WebString::fromUTF8(url));
43 } 71 }
44 72
45 v8::Handle<v8::Value> MediaGalleryCustomBindings::ExtractEmbeddedThumbnails( 73 v8::Handle<v8::Value> MediaGalleryCustomBindings::ExtractEmbeddedThumbnails(
46 const v8::Arguments& args) { 74 const v8::Arguments& args) {
47 if (args.Length() != 1) { 75 if (args.Length() != 1) {
48 NOTREACHED() << "Bad arguments"; 76 NOTREACHED() << "Bad arguments";
49 return v8::Undefined(); 77 return v8::Undefined();
50 } 78 }
51 // TODO(vandebo) Check that the object is a FileEntry. 79 // TODO(vandebo) Check that the object is a FileEntry.
52 80
53 // TODO(vandebo) Create and return a Directory entry object. 81 // TODO(vandebo) Create and return a Directory entry object.
54 return v8::Null(); 82 return v8::Null();
55 } 83 }
56 84
57 } // namespace extensions 85 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698