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

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

Issue 12313142: Revert 184837 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 10 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/file_system_natives.h" 5 #include "chrome/renderer/extensions/file_system_natives.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "chrome/common/url_constants.h" 11 #include "chrome/common/url_constants.h"
12 #include "chrome/renderer/extensions/user_script_slave.h" 12 #include "chrome/renderer/extensions/user_script_slave.h"
13 #include "extensions/common/constants.h" 13 #include "extensions/common/constants.h"
14 #include "grit/renderer_resources.h" 14 #include "grit/renderer_resources.h"
15 #include "third_party/WebKit/Source/Platform/chromium/public/WebFileSystem.h" 15 #include "third_party/WebKit/Source/Platform/chromium/public/WebFileSystem.h"
16 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" 16 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
18 #include "webkit/fileapi/file_system_types.h" 18 #include "webkit/fileapi/file_system_types.h"
19 #include "webkit/fileapi/file_system_util.h" 19 #include "webkit/fileapi/file_system_util.h"
20 20
21 namespace extensions { 21 namespace {
22 22
23 FileSystemNatives::FileSystemNatives(v8::Handle<v8::Context> context) 23 static v8::Handle<v8::Value> GetIsolatedFileSystem(
24 : ObjectBackedNativeHandler(context) {
25 RouteFunction("GetFileEntry",
26 base::Bind(&FileSystemNatives::GetFileEntry, base::Unretained(this)));
27 RouteFunction("GetIsolatedFileSystem",
28 base::Bind(&FileSystemNatives::GetIsolatedFileSystem,
29 base::Unretained(this)));
30 }
31
32 v8::Handle<v8::Value> FileSystemNatives::GetIsolatedFileSystem(
33 const v8::Arguments& args) { 24 const v8::Arguments& args) {
34 DCHECK(args.Length() == 1 || args.Length() == 2); 25 DCHECK(args.Length() == 1 || args.Length() == 2);
35 DCHECK(args[0]->IsString()); 26 DCHECK(args[0]->IsString());
36 std::string file_system_id(*v8::String::Utf8Value(args[0])); 27 std::string file_system_id(*v8::String::Utf8Value(args[0]));
37 WebKit::WebFrame* webframe = WebKit::WebFrame::frameForContext(v8_context()); 28 WebKit::WebFrame* webframe = WebKit::WebFrame::frameForCurrentContext();
38 DCHECK(webframe); 29 DCHECK(webframe);
39 30
40 GURL context_url = 31 GURL context_url =
41 extensions::UserScriptSlave::GetDataSourceURLForFrame(webframe); 32 extensions::UserScriptSlave::GetDataSourceURLForFrame(webframe);
42 CHECK(context_url.SchemeIs(extensions::kExtensionScheme)); 33 CHECK(context_url.SchemeIs(extensions::kExtensionScheme));
43 34
44 std::string name(fileapi::GetIsolatedFileSystemName(context_url.GetOrigin(), 35 std::string name(fileapi::GetIsolatedFileSystemName(context_url.GetOrigin(),
45 file_system_id)); 36 file_system_id));
46 37
47 // The optional second argument is the subfolder within the isolated file 38 // The optional second argument is the subfolder within the isolated file
48 // system at which to root the DOMFileSystem we're returning to the caller. 39 // system at which to root the DOMFileSystem we're returning to the caller.
49 std::string optional_root_name; 40 std::string optional_root_name;
50 if (args.Length() == 2) { 41 if (args.Length() == 2) {
51 DCHECK(args[1]->IsString()); 42 DCHECK(args[1]->IsString());
52 optional_root_name = *v8::String::Utf8Value(args[1]); 43 optional_root_name = *v8::String::Utf8Value(args[1]);
53 } 44 }
54 45
55 std::string root(fileapi::GetIsolatedFileSystemRootURIString( 46 std::string root(fileapi::GetIsolatedFileSystemRootURIString(
56 context_url.GetOrigin(), 47 context_url.GetOrigin(),
57 file_system_id, 48 file_system_id,
58 optional_root_name)); 49 optional_root_name));
59 50
60 return webframe->createFileSystem( 51 return webframe->createFileSystem(
61 WebKit::WebFileSystem::TypeIsolated, 52 WebKit::WebFileSystem::TypeIsolated,
62 WebKit::WebString::fromUTF8(name), 53 WebKit::WebString::fromUTF8(name),
63 WebKit::WebString::fromUTF8(root)); 54 WebKit::WebString::fromUTF8(root));
64 } 55 }
65 56
66 v8::Handle<v8::Value> FileSystemNatives::GetFileEntry( 57 static v8::Handle<v8::Value> GetFileEntry(const v8::Arguments& args) {
67 const v8::Arguments& args) {
68 DCHECK(args.Length() == 5); 58 DCHECK(args.Length() == 5);
69 DCHECK(args[0]->IsString()); 59 DCHECK(args[0]->IsString());
70 std::string type_string = *v8::String::Utf8Value(args[0]->ToString()); 60 std::string type_string = *v8::String::Utf8Value(args[0]->ToString());
71 WebKit::WebFileSystem::Type type; 61 WebKit::WebFileSystem::Type type;
72 bool is_valid_type = fileapi::GetFileSystemPublicType(type_string, &type); 62 bool is_valid_type = fileapi::GetFileSystemPublicType(type_string, &type);
73 DCHECK(is_valid_type); 63 DCHECK(is_valid_type);
74 if (is_valid_type == false) { 64 if (is_valid_type == false) {
75 return v8::Undefined(); 65 return v8::Undefined();
76 } 66 }
77 67
78 DCHECK(args[1]->IsString()); 68 DCHECK(args[1]->IsString());
79 DCHECK(args[2]->IsString()); 69 DCHECK(args[2]->IsString());
80 DCHECK(args[3]->IsString()); 70 DCHECK(args[3]->IsString());
81 std::string file_system_name(*v8::String::Utf8Value(args[1]->ToString())); 71 std::string file_system_name(*v8::String::Utf8Value(args[1]->ToString()));
82 std::string file_system_root_url(*v8::String::Utf8Value(args[2]->ToString())); 72 std::string file_system_root_url(*v8::String::Utf8Value(args[2]->ToString()));
83 std::string file_path_string(*v8::String::Utf8Value(args[3]->ToString())); 73 std::string file_path_string(*v8::String::Utf8Value(args[3]->ToString()));
84 base::FilePath file_path = base::FilePath::FromUTF8Unsafe(file_path_string); 74 base::FilePath file_path = base::FilePath::FromUTF8Unsafe(file_path_string);
85 DCHECK(fileapi::VirtualPath::IsAbsolute(file_path.value())); 75 DCHECK(fileapi::VirtualPath::IsAbsolute(file_path.value()));
86 76
87 DCHECK(args[4]->IsBoolean()); 77 DCHECK(args[4]->IsBoolean());
88 bool is_directory = args[4]->BooleanValue(); 78 bool is_directory = args[4]->BooleanValue();
89 79
90 WebKit::WebFrame* webframe = WebKit::WebFrame::frameForContext(v8_context()); 80 WebKit::WebFrame* webframe = WebKit::WebFrame::frameForCurrentContext();
91 DCHECK(webframe); 81 DCHECK(webframe);
92 return webframe->createFileEntry( 82 return webframe->createFileEntry(
93 type, 83 type,
94 WebKit::WebString::fromUTF8(file_system_name), 84 WebKit::WebString::fromUTF8(file_system_name),
95 WebKit::WebString::fromUTF8(file_system_root_url), 85 WebKit::WebString::fromUTF8(file_system_root_url),
96 WebKit::WebString::fromUTF8(file_path_string), 86 WebKit::WebString::fromUTF8(file_path_string),
97 is_directory); 87 is_directory);
98 } 88 }
99 89
90 } // namespace
91
92 namespace extensions {
93
94 FileSystemNatives::FileSystemNatives()
95 : ChromeV8Extension(NULL) {
96 RouteStaticFunction("GetFileEntry", &GetFileEntry);
97 RouteStaticFunction("GetIsolatedFileSystem", &GetIsolatedFileSystem);
98 }
99
100 } // namespace extensions 100 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/renderer/extensions/file_system_natives.h ('k') | chrome/renderer/extensions/i18n_custom_bindings.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698