Chromium Code Reviews| 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/user_script_slave.h" | 12 #include "chrome/renderer/extensions/user_script_slave.h" |
| 13 #include "grit/renderer_resources.h" | 13 #include "grit/renderer_resources.h" |
| 14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFileSyste m.h" | 14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebFileSyste m.h" |
| 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
| 17 #include "webkit/fileapi/file_system_types.h" | 17 #include "webkit/fileapi/file_system_types.h" |
| 18 #include "webkit/fileapi/file_system_util.h" | 18 #include "webkit/fileapi/file_system_util.h" |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 static v8::Handle<v8::Value> GetIsolatedFileSystem( | 22 static v8::Handle<v8::Value> GetIsolatedFileSystem( |
| 23 const v8::Arguments& args) { | 23 const v8::Arguments& args) { |
| 24 DCHECK(args.Length() == 1); | 24 DCHECK(args.Length() == 1 || args.Length() == 2); |
| 25 DCHECK(args[0]->IsString()); | 25 DCHECK(args[0]->IsString()); |
| 26 std::string file_system_id(*v8::String::Utf8Value(args[0])); | 26 std::string file_system_id(*v8::String::Utf8Value(args[0])); |
| 27 WebKit::WebFrame* webframe = WebKit::WebFrame::frameForCurrentContext(); | 27 WebKit::WebFrame* webframe = WebKit::WebFrame::frameForCurrentContext(); |
| 28 DCHECK(webframe); | 28 DCHECK(webframe); |
| 29 | 29 |
| 30 GURL context_url = | 30 GURL context_url = |
| 31 extensions::UserScriptSlave::GetDataSourceURLForFrame(webframe); | 31 extensions::UserScriptSlave::GetDataSourceURLForFrame(webframe); |
| 32 CHECK(context_url.SchemeIs(chrome::kExtensionScheme)); | 32 CHECK(context_url.SchemeIs(chrome::kExtensionScheme)); |
| 33 | 33 |
| 34 std::string name(fileapi::GetIsolatedFileSystemName(context_url.GetOrigin(), | 34 std::string name(fileapi::GetIsolatedFileSystemName(context_url.GetOrigin(), |
| 35 file_system_id)); | 35 file_system_id)); |
| 36 | 36 |
| 37 std::string root(fileapi::GetFileSystemRootURI(context_url.GetOrigin(), | 37 std::string root(fileapi::GetFileSystemRootURI(context_url.GetOrigin(), |
| 38 fileapi::kFileSystemTypeIsolated).spec()); | 38 fileapi::kFileSystemTypeIsolated).spec()); |
| 39 root.append(file_system_id); | 39 root.append(file_system_id); |
| 40 root.append("/"); | 40 root.append("/"); |
| 41 | 41 |
| 42 // Optionally create the DOMFileSystem rooted at a subdirectory. | |
|
James Hawkins
2012/08/29 22:46:51
Optionally?
thorogood
2012/08/30 01:36:28
I've expanded this comment slightly.
| |
| 43 if (args.Length() == 2) { | |
| 44 DCHECK(args[1]->IsString()); | |
| 45 name = *v8::String::Utf8Value(args[1]); | |
| 46 root.append(name); | |
| 47 root.append("/"); | |
| 48 } | |
| 49 | |
| 42 return webframe->createFileSystem( | 50 return webframe->createFileSystem( |
| 43 WebKit::WebFileSystem::TypeIsolated, | 51 WebKit::WebFileSystem::TypeIsolated, |
| 44 WebKit::WebString::fromUTF8(name.c_str()), | 52 WebKit::WebString::fromUTF8(name), |
| 45 WebKit::WebString::fromUTF8(root.c_str())); | 53 WebKit::WebString::fromUTF8(root)); |
| 46 } | 54 } |
| 47 | 55 |
| 48 } // namespace | 56 } // namespace |
| 49 | 57 |
| 50 namespace extensions { | 58 namespace extensions { |
| 51 | 59 |
| 52 FileSystemNatives::FileSystemNatives() | 60 FileSystemNatives::FileSystemNatives() |
| 53 : ChromeV8Extension(NULL) { | 61 : ChromeV8Extension(NULL) { |
| 54 RouteStaticFunction("GetIsolatedFileSystem", &GetIsolatedFileSystem); | 62 RouteStaticFunction("GetIsolatedFileSystem", &GetIsolatedFileSystem); |
| 55 } | 63 } |
| 56 | 64 |
| 57 } // namespace extensions | 65 } // namespace extensions |
| OLD | NEW |