1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/renderer/extensions/media_gallery_custom_bindings.h"
#include <string>
#include "base/file_path.h"
#include "base/stringprintf.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
#include "v8/include/v8.h"
#include "webkit/fileapi/file_system_util.h"
namespace extensions {
MediaGalleryCustomBindings::MediaGalleryCustomBindings()
: ChromeV8Extension(NULL) {
RouteFunction(
"GetMediaFileSystemObject",
base::Bind(&MediaGalleryCustomBindings::GetMediaFileSystemObject,
base::Unretained(this)));
RouteFunction(
"ExtractEmbeddedThumbnails",
base::Bind(&MediaGalleryCustomBindings::ExtractEmbeddedThumbnails,
base::Unretained(this)));
}
v8::Handle<v8::Value> MediaGalleryCustomBindings::GetMediaFileSystemObject(
const v8::Arguments& args) {
if (args.Length() != 2) {
NOTREACHED();
return v8::Undefined();
}
if (!args[0]->IsString()) {
NOTREACHED();
return v8::Undefined();
}
if (!args[1]->IsString()) {
NOTREACHED();
return v8::Undefined();
}
std::string fsid(*v8::String::Utf8Value(args[0]));
if (fsid.empty()) {
NOTREACHED();
return v8::Undefined();
}
std::string dirname(*v8::String::Utf8Value(args[1]));
if (dirname.empty()) {
NOTREACHED();
return v8::Undefined();
}
WebKit::WebFrame* webframe = WebKit::WebFrame::frameForCurrentContext();
const GURL origin = GURL(webframe->document().securityOrigin().toString());
const GURL root_url =
fileapi::GetFileSystemRootURI(origin, fileapi::kFileSystemTypeIsolated);
const std::string fsname_prefix =
fileapi::GetFileSystemName(origin, fileapi::kFileSystemTypeIsolated);
const std::string fsname =
base::StringPrintf("%s_%s", fsname_prefix.c_str(), fsid.c_str());
const std::string url = base::StringPrintf("%s%s/%s/",
root_url.spec().c_str(),
fsid.c_str(),
dirname.c_str());
return webframe->createFileSystem(WebKit::WebFileSystem::TypeIsolated,
WebKit::WebString::fromUTF8(fsname),
WebKit::WebString::fromUTF8(url));
}
v8::Handle<v8::Value> MediaGalleryCustomBindings::ExtractEmbeddedThumbnails(
const v8::Arguments& args) {
if (args.Length() != 1) {
NOTREACHED() << "Bad arguments";
return v8::Undefined();
}
// TODO(vandebo) Check that the object is a FileEntry.
// TODO(vandebo) Create and return a Directory entry object.
return v8::Null();
}
} // namespace extensions
|