OLD | NEW |
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/chrome_v8_context.h" |
13 #include "chrome/renderer/extensions/user_script_slave.h" | 13 #include "chrome/renderer/extensions/user_script_slave.h" |
14 #include "extensions/common/constants.h" | 14 #include "extensions/common/constants.h" |
15 #include "grit/renderer_resources.h" | 15 #include "grit/renderer_resources.h" |
16 #include "third_party/WebKit/public/platform/WebFileSystem.h" | 16 #include "third_party/WebKit/public/platform/WebFileSystem.h" |
17 #include "third_party/WebKit/public/platform/WebFileSystemType.h" | 17 #include "third_party/WebKit/public/platform/WebFileSystemType.h" |
18 #include "third_party/WebKit/public/platform/WebString.h" | 18 #include "third_party/WebKit/public/platform/WebString.h" |
| 19 #include "third_party/WebKit/public/web/WebDOMError.h" |
19 #include "third_party/WebKit/public/web/WebFrame.h" | 20 #include "third_party/WebKit/public/web/WebFrame.h" |
20 #include "webkit/common/fileapi/file_system_types.h" | 21 #include "webkit/common/fileapi/file_system_types.h" |
21 #include "webkit/common/fileapi/file_system_util.h" | 22 #include "webkit/common/fileapi/file_system_util.h" |
22 | 23 |
23 namespace extensions { | 24 namespace extensions { |
24 | 25 |
25 FileSystemNatives::FileSystemNatives(ChromeV8Context* context) | 26 FileSystemNatives::FileSystemNatives(ChromeV8Context* context) |
26 : ObjectBackedNativeHandler(context) { | 27 : ObjectBackedNativeHandler(context) { |
27 RouteFunction("GetFileEntry", | 28 RouteFunction("GetFileEntry", |
28 base::Bind(&FileSystemNatives::GetFileEntry, base::Unretained(this))); | 29 base::Bind(&FileSystemNatives::GetFileEntry, base::Unretained(this))); |
29 RouteFunction("GetIsolatedFileSystem", | 30 RouteFunction("GetIsolatedFileSystem", |
30 base::Bind(&FileSystemNatives::GetIsolatedFileSystem, | 31 base::Bind(&FileSystemNatives::GetIsolatedFileSystem, |
31 base::Unretained(this))); | 32 base::Unretained(this))); |
32 RouteFunction("CrackIsolatedFileSystemName", | 33 RouteFunction("CrackIsolatedFileSystemName", |
33 base::Bind(&FileSystemNatives::CrackIsolatedFileSystemName, | 34 base::Bind(&FileSystemNatives::CrackIsolatedFileSystemName, |
34 base::Unretained(this))); | 35 base::Unretained(this))); |
| 36 RouteFunction("GetDOMError", |
| 37 base::Bind(&FileSystemNatives::GetDOMError, |
| 38 base::Unretained(this))); |
35 } | 39 } |
36 | 40 |
37 void FileSystemNatives::GetIsolatedFileSystem( | 41 void FileSystemNatives::GetIsolatedFileSystem( |
38 const v8::FunctionCallbackInfo<v8::Value>& args) { | 42 const v8::FunctionCallbackInfo<v8::Value>& args) { |
39 DCHECK(args.Length() == 1 || args.Length() == 2); | 43 DCHECK(args.Length() == 1 || args.Length() == 2); |
40 DCHECK(args[0]->IsString()); | 44 DCHECK(args[0]->IsString()); |
41 std::string file_system_id(*v8::String::Utf8Value(args[0])); | 45 std::string file_system_id(*v8::String::Utf8Value(args[0])); |
42 blink::WebFrame* webframe = | 46 blink::WebFrame* webframe = |
43 blink::WebFrame::frameForContext(context()->v8_context()); | 47 blink::WebFrame::frameForContext(context()->v8_context()); |
44 DCHECK(webframe); | 48 DCHECK(webframe); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 DCHECK(args[0]->IsString()); | 114 DCHECK(args[0]->IsString()); |
111 std::string filesystem_name = *v8::String::Utf8Value(args[0]->ToString()); | 115 std::string filesystem_name = *v8::String::Utf8Value(args[0]->ToString()); |
112 std::string filesystem_id; | 116 std::string filesystem_id; |
113 if (!fileapi::CrackIsolatedFileSystemName(filesystem_name, &filesystem_id)) | 117 if (!fileapi::CrackIsolatedFileSystemName(filesystem_name, &filesystem_id)) |
114 return; | 118 return; |
115 | 119 |
116 args.GetReturnValue().Set( | 120 args.GetReturnValue().Set( |
117 v8::String::New(filesystem_id.c_str(), filesystem_id.size())); | 121 v8::String::New(filesystem_id.c_str(), filesystem_id.size())); |
118 } | 122 } |
119 | 123 |
| 124 void FileSystemNatives::GetDOMError( |
| 125 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 126 if (args.Length() != 2) { |
| 127 NOTREACHED(); |
| 128 return; |
| 129 } |
| 130 if (!args[0]->IsString()) { |
| 131 NOTREACHED(); |
| 132 return; |
| 133 } |
| 134 if (!args[1]->IsString()) { |
| 135 NOTREACHED(); |
| 136 return; |
| 137 } |
| 138 |
| 139 std::string name(*v8::String::Utf8Value(args[0])); |
| 140 if (name.empty()) { |
| 141 NOTREACHED(); |
| 142 return; |
| 143 } |
| 144 std::string message(*v8::String::Utf8Value(args[1])); |
| 145 // message is optional hence empty is fine. |
| 146 |
| 147 blink::WebDOMError dom_error = blink::WebDOMError::create( |
| 148 blink::WebString::fromUTF8(name), |
| 149 blink::WebString::fromUTF8(message)); |
| 150 args.GetReturnValue().Set(dom_error.toV8Value()); |
| 151 } |
| 152 |
120 } // namespace extensions | 153 } // namespace extensions |
OLD | NEW |