OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/renderer/file_system_natives.h" | 5 #include "extensions/renderer/file_system_natives.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "extensions/common/constants.h" | 9 #include "extensions/common/constants.h" |
10 #include "extensions/renderer/script_context.h" | 10 #include "extensions/renderer/script_context.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 RouteFunction("GetIsolatedFileSystem", | 24 RouteFunction("GetIsolatedFileSystem", |
25 base::Bind(&FileSystemNatives::GetIsolatedFileSystem, | 25 base::Bind(&FileSystemNatives::GetIsolatedFileSystem, |
26 base::Unretained(this))); | 26 base::Unretained(this))); |
27 RouteFunction("CrackIsolatedFileSystemName", | 27 RouteFunction("CrackIsolatedFileSystemName", |
28 base::Bind(&FileSystemNatives::CrackIsolatedFileSystemName, | 28 base::Bind(&FileSystemNatives::CrackIsolatedFileSystemName, |
29 base::Unretained(this))); | 29 base::Unretained(this))); |
30 } | 30 } |
31 | 31 |
32 void FileSystemNatives::GetIsolatedFileSystem( | 32 void FileSystemNatives::GetIsolatedFileSystem( |
33 const v8::FunctionCallbackInfo<v8::Value>& args) { | 33 const v8::FunctionCallbackInfo<v8::Value>& args) { |
34 DCHECK(args.Length() == 1 || args.Length() == 2); | 34 CHECK(args.Length() == 1 || args.Length() == 2); |
35 DCHECK(args[0]->IsString()); | 35 CHECK(args[0]->IsString()); |
36 std::string file_system_id(*v8::String::Utf8Value(args[0])); | 36 std::string file_system_id(*v8::String::Utf8Value(args[0])); |
37 blink::WebLocalFrame* webframe = | 37 blink::WebLocalFrame* webframe = |
38 blink::WebLocalFrame::frameForContext(context()->v8_context()); | 38 blink::WebLocalFrame::frameForContext(context()->v8_context()); |
39 DCHECK(webframe); | 39 DCHECK(webframe); |
40 | 40 |
41 GURL context_url = | 41 GURL context_url = |
42 extensions::ScriptContext::GetDataSourceURLForFrame(webframe); | 42 extensions::ScriptContext::GetDataSourceURLForFrame(webframe); |
43 CHECK(context_url.SchemeIs(extensions::kExtensionScheme)); | 43 CHECK(context_url.SchemeIs(extensions::kExtensionScheme)); |
44 | 44 |
45 std::string name(storage::GetIsolatedFileSystemName(context_url.GetOrigin(), | 45 std::string name(storage::GetIsolatedFileSystemName(context_url.GetOrigin(), |
46 file_system_id)); | 46 file_system_id)); |
47 | 47 |
48 // The optional second argument is the subfolder within the isolated file | 48 // The optional second argument is the subfolder within the isolated file |
49 // system at which to root the DOMFileSystem we're returning to the caller. | 49 // system at which to root the DOMFileSystem we're returning to the caller. |
50 std::string optional_root_name; | 50 std::string optional_root_name; |
51 if (args.Length() == 2) { | 51 if (args.Length() == 2) { |
52 DCHECK(args[1]->IsString()); | 52 CHECK(args[1]->IsString()); |
53 optional_root_name = *v8::String::Utf8Value(args[1]); | 53 optional_root_name = *v8::String::Utf8Value(args[1]); |
54 } | 54 } |
55 | 55 |
56 GURL root_url(storage::GetIsolatedFileSystemRootURIString( | 56 GURL root_url(storage::GetIsolatedFileSystemRootURIString( |
57 context_url.GetOrigin(), file_system_id, optional_root_name)); | 57 context_url.GetOrigin(), file_system_id, optional_root_name)); |
58 | 58 |
59 args.GetReturnValue().Set( | 59 args.GetReturnValue().Set( |
60 blink::WebDOMFileSystem::create(webframe, | 60 blink::WebDOMFileSystem::create(webframe, |
61 blink::WebFileSystemTypeIsolated, | 61 blink::WebFileSystemTypeIsolated, |
62 blink::WebString::fromUTF8(name), | 62 blink::WebString::fromUTF8(name), |
63 root_url) | 63 root_url) |
64 .toV8Value(context()->v8_context()->Global(), args.GetIsolate())); | 64 .toV8Value(context()->v8_context()->Global(), args.GetIsolate())); |
65 } | 65 } |
66 | 66 |
67 void FileSystemNatives::GetFileEntry( | 67 void FileSystemNatives::GetFileEntry( |
68 const v8::FunctionCallbackInfo<v8::Value>& args) { | 68 const v8::FunctionCallbackInfo<v8::Value>& args) { |
69 DCHECK(args.Length() == 5); | 69 CHECK_EQ(5, args.Length()); |
70 DCHECK(args[0]->IsString()); | 70 CHECK(args[0]->IsString()); |
71 std::string type_string = *v8::String::Utf8Value(args[0]); | 71 std::string type_string = *v8::String::Utf8Value(args[0]); |
72 blink::WebFileSystemType type; | 72 blink::WebFileSystemType type; |
73 bool is_valid_type = storage::GetFileSystemPublicType(type_string, &type); | 73 bool is_valid_type = storage::GetFileSystemPublicType(type_string, &type); |
74 DCHECK(is_valid_type); | 74 DCHECK(is_valid_type); |
75 if (is_valid_type == false) { | 75 if (is_valid_type == false) { |
76 return; | 76 return; |
77 } | 77 } |
78 | 78 |
79 DCHECK(args[1]->IsString()); | 79 CHECK(args[1]->IsString()); |
80 DCHECK(args[2]->IsString()); | 80 CHECK(args[2]->IsString()); |
81 DCHECK(args[3]->IsString()); | 81 CHECK(args[3]->IsString()); |
82 std::string file_system_name(*v8::String::Utf8Value(args[1])); | 82 std::string file_system_name(*v8::String::Utf8Value(args[1])); |
83 GURL file_system_root_url(*v8::String::Utf8Value(args[2])); | 83 GURL file_system_root_url(*v8::String::Utf8Value(args[2])); |
84 std::string file_path_string(*v8::String::Utf8Value(args[3])); | 84 std::string file_path_string(*v8::String::Utf8Value(args[3])); |
85 base::FilePath file_path = base::FilePath::FromUTF8Unsafe(file_path_string); | 85 base::FilePath file_path = base::FilePath::FromUTF8Unsafe(file_path_string); |
86 DCHECK(storage::VirtualPath::IsAbsolute(file_path.value())); | 86 DCHECK(storage::VirtualPath::IsAbsolute(file_path.value())); |
87 | 87 |
88 DCHECK(args[4]->IsBoolean()); | 88 CHECK(args[4]->IsBoolean()); |
89 blink::WebDOMFileSystem::EntryType entry_type = | 89 blink::WebDOMFileSystem::EntryType entry_type = |
90 args[4]->BooleanValue() ? blink::WebDOMFileSystem::EntryTypeDirectory | 90 args[4]->BooleanValue() ? blink::WebDOMFileSystem::EntryTypeDirectory |
91 : blink::WebDOMFileSystem::EntryTypeFile; | 91 : blink::WebDOMFileSystem::EntryTypeFile; |
92 | 92 |
93 blink::WebLocalFrame* webframe = | 93 blink::WebLocalFrame* webframe = |
94 blink::WebLocalFrame::frameForContext(context()->v8_context()); | 94 blink::WebLocalFrame::frameForContext(context()->v8_context()); |
95 DCHECK(webframe); | 95 DCHECK(webframe); |
96 args.GetReturnValue().Set( | 96 args.GetReturnValue().Set( |
97 blink::WebDOMFileSystem::create( | 97 blink::WebDOMFileSystem::create( |
98 webframe, | 98 webframe, |
(...skipping 15 matching lines...) Expand all Loading... |
114 if (!storage::CrackIsolatedFileSystemName(filesystem_name, &filesystem_id)) | 114 if (!storage::CrackIsolatedFileSystemName(filesystem_name, &filesystem_id)) |
115 return; | 115 return; |
116 | 116 |
117 args.GetReturnValue().Set(v8::String::NewFromUtf8(args.GetIsolate(), | 117 args.GetReturnValue().Set(v8::String::NewFromUtf8(args.GetIsolate(), |
118 filesystem_id.c_str(), | 118 filesystem_id.c_str(), |
119 v8::String::kNormalString, | 119 v8::String::kNormalString, |
120 filesystem_id.size())); | 120 filesystem_id.size())); |
121 } | 121 } |
122 | 122 |
123 } // namespace extensions | 123 } // namespace extensions |
OLD | NEW |