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" |
| 11 #include "extensions/renderer/v8_maybe_helpers.h" |
11 #include "storage/common/fileapi/file_system_types.h" | 12 #include "storage/common/fileapi/file_system_types.h" |
12 #include "storage/common/fileapi/file_system_util.h" | 13 #include "storage/common/fileapi/file_system_util.h" |
13 #include "third_party/WebKit/public/platform/WebString.h" | 14 #include "third_party/WebKit/public/platform/WebString.h" |
14 #include "third_party/WebKit/public/web/WebDOMError.h" | 15 #include "third_party/WebKit/public/web/WebDOMError.h" |
15 #include "third_party/WebKit/public/web/WebDOMFileSystem.h" | 16 #include "third_party/WebKit/public/web/WebDOMFileSystem.h" |
16 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 17 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
17 | 18 |
18 namespace extensions { | 19 namespace extensions { |
19 | 20 |
20 FileSystemNatives::FileSystemNatives(ScriptContext* context) | 21 FileSystemNatives::FileSystemNatives(ScriptContext* context) |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 DCHECK(args[2]->IsString()); | 85 DCHECK(args[2]->IsString()); |
85 DCHECK(args[3]->IsString()); | 86 DCHECK(args[3]->IsString()); |
86 std::string file_system_name(*v8::String::Utf8Value(args[1])); | 87 std::string file_system_name(*v8::String::Utf8Value(args[1])); |
87 GURL file_system_root_url(*v8::String::Utf8Value(args[2])); | 88 GURL file_system_root_url(*v8::String::Utf8Value(args[2])); |
88 std::string file_path_string(*v8::String::Utf8Value(args[3])); | 89 std::string file_path_string(*v8::String::Utf8Value(args[3])); |
89 base::FilePath file_path = base::FilePath::FromUTF8Unsafe(file_path_string); | 90 base::FilePath file_path = base::FilePath::FromUTF8Unsafe(file_path_string); |
90 DCHECK(storage::VirtualPath::IsAbsolute(file_path.value())); | 91 DCHECK(storage::VirtualPath::IsAbsolute(file_path.value())); |
91 | 92 |
92 DCHECK(args[4]->IsBoolean()); | 93 DCHECK(args[4]->IsBoolean()); |
93 blink::WebDOMFileSystem::EntryType entry_type = | 94 blink::WebDOMFileSystem::EntryType entry_type = |
94 args[4]->BooleanValue() ? blink::WebDOMFileSystem::EntryTypeDirectory | 95 args[4].As<v8::Boolean>()->Value() |
95 : blink::WebDOMFileSystem::EntryTypeFile; | 96 ? blink::WebDOMFileSystem::EntryTypeDirectory |
| 97 : blink::WebDOMFileSystem::EntryTypeFile; |
96 | 98 |
97 blink::WebLocalFrame* webframe = | 99 blink::WebLocalFrame* webframe = |
98 blink::WebLocalFrame::frameForContext(context()->v8_context()); | 100 blink::WebLocalFrame::frameForContext(context()->v8_context()); |
99 DCHECK(webframe); | 101 DCHECK(webframe); |
100 args.GetReturnValue().Set( | 102 args.GetReturnValue().Set( |
101 blink::WebDOMFileSystem::create( | 103 blink::WebDOMFileSystem::create( |
102 webframe, | 104 webframe, |
103 type, | 105 type, |
104 blink::WebString::fromUTF8(file_system_name), | 106 blink::WebString::fromUTF8(file_system_name), |
105 file_system_root_url) | 107 file_system_root_url) |
106 .createV8Entry(blink::WebString::fromUTF8(file_path_string), | 108 .createV8Entry(blink::WebString::fromUTF8(file_path_string), |
107 entry_type, | 109 entry_type, |
108 args.Holder(), | 110 args.Holder(), |
109 args.GetIsolate())); | 111 args.GetIsolate())); |
110 } | 112 } |
111 | 113 |
112 void FileSystemNatives::CrackIsolatedFileSystemName( | 114 void FileSystemNatives::CrackIsolatedFileSystemName( |
113 const v8::FunctionCallbackInfo<v8::Value>& args) { | 115 const v8::FunctionCallbackInfo<v8::Value>& args) { |
114 DCHECK_EQ(args.Length(), 1); | 116 DCHECK_EQ(args.Length(), 1); |
115 DCHECK(args[0]->IsString()); | 117 DCHECK(args[0]->IsString()); |
116 std::string filesystem_name = *v8::String::Utf8Value(args[0]); | 118 std::string filesystem_name = *v8::String::Utf8Value(args[0]); |
117 std::string filesystem_id; | 119 std::string filesystem_id; |
118 if (!storage::CrackIsolatedFileSystemName(filesystem_name, &filesystem_id)) | 120 if (!storage::CrackIsolatedFileSystemName(filesystem_name, &filesystem_id)) |
119 return; | 121 return; |
| 122 if (filesystem_id.size() >= v8::String::kMaxLength) |
| 123 return; |
120 | 124 |
121 args.GetReturnValue().Set(v8::String::NewFromUtf8(args.GetIsolate(), | 125 args.GetReturnValue().Set( |
122 filesystem_id.c_str(), | 126 ToV8String(args.GetIsolate(), filesystem_id.c_str())); |
123 v8::String::kNormalString, | |
124 filesystem_id.size())); | |
125 } | 127 } |
126 | 128 |
127 void FileSystemNatives::GetDOMError( | 129 void FileSystemNatives::GetDOMError( |
128 const v8::FunctionCallbackInfo<v8::Value>& args) { | 130 const v8::FunctionCallbackInfo<v8::Value>& args) { |
129 if (args.Length() != 2) { | 131 if (args.Length() != 2) { |
130 NOTREACHED(); | 132 NOTREACHED(); |
131 return; | 133 return; |
132 } | 134 } |
133 if (!args[0]->IsString()) { | 135 if (!args[0]->IsString()) { |
134 NOTREACHED(); | 136 NOTREACHED(); |
(...skipping 12 matching lines...) Expand all Loading... |
147 std::string message(*v8::String::Utf8Value(args[1])); | 149 std::string message(*v8::String::Utf8Value(args[1])); |
148 // message is optional hence empty is fine. | 150 // message is optional hence empty is fine. |
149 | 151 |
150 blink::WebDOMError dom_error = blink::WebDOMError::create( | 152 blink::WebDOMError dom_error = blink::WebDOMError::create( |
151 blink::WebString::fromUTF8(name), blink::WebString::fromUTF8(message)); | 153 blink::WebString::fromUTF8(name), blink::WebString::fromUTF8(message)); |
152 args.GetReturnValue().Set( | 154 args.GetReturnValue().Set( |
153 dom_error.toV8Value(args.Holder(), args.GetIsolate())); | 155 dom_error.toV8Value(args.Holder(), args.GetIsolate())); |
154 } | 156 } |
155 | 157 |
156 } // namespace extensions | 158 } // namespace extensions |
OLD | NEW |