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

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

Issue 16032015: Extensions: pass ChromeV8Context around instead of v8::Handle. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 7 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/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/chrome_v8_context.h"
12 #include "chrome/renderer/extensions/user_script_slave.h" 13 #include "chrome/renderer/extensions/user_script_slave.h"
13 #include "extensions/common/constants.h" 14 #include "extensions/common/constants.h"
14 #include "grit/renderer_resources.h" 15 #include "grit/renderer_resources.h"
15 #include "third_party/WebKit/public/platform/WebFileSystem.h" 16 #include "third_party/WebKit/public/platform/WebFileSystem.h"
16 #include "third_party/WebKit/public/platform/WebFileSystemType.h" 17 #include "third_party/WebKit/public/platform/WebFileSystemType.h"
17 #include "third_party/WebKit/public/platform/WebString.h" 18 #include "third_party/WebKit/public/platform/WebString.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
19 #include "webkit/common/fileapi/file_system_types.h" 20 #include "webkit/common/fileapi/file_system_types.h"
20 #include "webkit/common/fileapi/file_system_util.h" 21 #include "webkit/common/fileapi/file_system_util.h"
21 22
22 namespace extensions { 23 namespace extensions {
23 24
24 FileSystemNatives::FileSystemNatives(v8::Handle<v8::Context> context) 25 FileSystemNatives::FileSystemNatives(ChromeV8Context* context)
25 : ObjectBackedNativeHandler(context) { 26 : ObjectBackedNativeHandler(context) {
26 RouteFunction("GetFileEntry", 27 RouteFunction("GetFileEntry",
27 base::Bind(&FileSystemNatives::GetFileEntry, base::Unretained(this))); 28 base::Bind(&FileSystemNatives::GetFileEntry, base::Unretained(this)));
28 RouteFunction("GetIsolatedFileSystem", 29 RouteFunction("GetIsolatedFileSystem",
29 base::Bind(&FileSystemNatives::GetIsolatedFileSystem, 30 base::Bind(&FileSystemNatives::GetIsolatedFileSystem,
30 base::Unretained(this))); 31 base::Unretained(this)));
31 RouteFunction("CrackIsolatedFileSystemName", 32 RouteFunction("CrackIsolatedFileSystemName",
32 base::Bind(&FileSystemNatives::CrackIsolatedFileSystemName, 33 base::Bind(&FileSystemNatives::CrackIsolatedFileSystemName,
33 base::Unretained(this))); 34 base::Unretained(this)));
34 } 35 }
35 36
36 v8::Handle<v8::Value> FileSystemNatives::GetIsolatedFileSystem( 37 v8::Handle<v8::Value> FileSystemNatives::GetIsolatedFileSystem(
37 const v8::Arguments& args) { 38 const v8::Arguments& args) {
38 DCHECK(args.Length() == 1 || args.Length() == 2); 39 DCHECK(args.Length() == 1 || args.Length() == 2);
39 DCHECK(args[0]->IsString()); 40 DCHECK(args[0]->IsString());
40 std::string file_system_id(*v8::String::Utf8Value(args[0])); 41 std::string file_system_id(*v8::String::Utf8Value(args[0]));
41 WebKit::WebFrame* webframe = WebKit::WebFrame::frameForContext(v8_context()); 42 WebKit::WebFrame* webframe =
43 WebKit::WebFrame::frameForContext(context()->v8_context());
42 DCHECK(webframe); 44 DCHECK(webframe);
43 45
44 GURL context_url = 46 GURL context_url =
45 extensions::UserScriptSlave::GetDataSourceURLForFrame(webframe); 47 extensions::UserScriptSlave::GetDataSourceURLForFrame(webframe);
46 CHECK(context_url.SchemeIs(extensions::kExtensionScheme)); 48 CHECK(context_url.SchemeIs(extensions::kExtensionScheme));
47 49
48 std::string name(fileapi::GetIsolatedFileSystemName(context_url.GetOrigin(), 50 std::string name(fileapi::GetIsolatedFileSystemName(context_url.GetOrigin(),
49 file_system_id)); 51 file_system_id));
50 52
51 // The optional second argument is the subfolder within the isolated file 53 // The optional second argument is the subfolder within the isolated file
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 DCHECK(args[3]->IsString()); 86 DCHECK(args[3]->IsString());
85 std::string file_system_name(*v8::String::Utf8Value(args[1]->ToString())); 87 std::string file_system_name(*v8::String::Utf8Value(args[1]->ToString()));
86 std::string file_system_root_url(*v8::String::Utf8Value(args[2]->ToString())); 88 std::string file_system_root_url(*v8::String::Utf8Value(args[2]->ToString()));
87 std::string file_path_string(*v8::String::Utf8Value(args[3]->ToString())); 89 std::string file_path_string(*v8::String::Utf8Value(args[3]->ToString()));
88 base::FilePath file_path = base::FilePath::FromUTF8Unsafe(file_path_string); 90 base::FilePath file_path = base::FilePath::FromUTF8Unsafe(file_path_string);
89 DCHECK(fileapi::VirtualPath::IsAbsolute(file_path.value())); 91 DCHECK(fileapi::VirtualPath::IsAbsolute(file_path.value()));
90 92
91 DCHECK(args[4]->IsBoolean()); 93 DCHECK(args[4]->IsBoolean());
92 bool is_directory = args[4]->BooleanValue(); 94 bool is_directory = args[4]->BooleanValue();
93 95
94 WebKit::WebFrame* webframe = WebKit::WebFrame::frameForContext(v8_context()); 96 WebKit::WebFrame* webframe =
97 WebKit::WebFrame::frameForContext(context()->v8_context());
95 DCHECK(webframe); 98 DCHECK(webframe);
96 return webframe->createFileEntry( 99 return webframe->createFileEntry(
97 type, 100 type,
98 WebKit::WebString::fromUTF8(file_system_name), 101 WebKit::WebString::fromUTF8(file_system_name),
99 WebKit::WebString::fromUTF8(file_system_root_url), 102 WebKit::WebString::fromUTF8(file_system_root_url),
100 WebKit::WebString::fromUTF8(file_path_string), 103 WebKit::WebString::fromUTF8(file_path_string),
101 is_directory); 104 is_directory);
102 } 105 }
103 106
104 v8::Handle<v8::Value> FileSystemNatives::CrackIsolatedFileSystemName( 107 v8::Handle<v8::Value> FileSystemNatives::CrackIsolatedFileSystemName(
105 const v8::Arguments& args) { 108 const v8::Arguments& args) {
106 DCHECK_EQ(args.Length(), 1); 109 DCHECK_EQ(args.Length(), 1);
107 DCHECK(args[0]->IsString()); 110 DCHECK(args[0]->IsString());
108 std::string filesystem_name = *v8::String::Utf8Value(args[0]->ToString()); 111 std::string filesystem_name = *v8::String::Utf8Value(args[0]->ToString());
109 std::string filesystem_id; 112 std::string filesystem_id;
110 if (!fileapi::CrackIsolatedFileSystemName(filesystem_name, &filesystem_id)) 113 if (!fileapi::CrackIsolatedFileSystemName(filesystem_name, &filesystem_id))
111 return v8::Undefined(); 114 return v8::Undefined();
112 115
113 return v8::String::New(filesystem_id.c_str(), filesystem_id.size()); 116 return v8::String::New(filesystem_id.c_str(), filesystem_id.size());
114 } 117 }
115 118
116 } // namespace extensions 119 } // 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