Index: content/renderer/pepper/resource_converter.cc |
diff --git a/content/renderer/pepper/resource_converter.cc b/content/renderer/pepper/resource_converter.cc |
index 5b564f125de9dc7ec85c7e0ac62ea143c755b6c7..3118af669f2e05a7d288034c897e059f45de0b94 100644 |
--- a/content/renderer/pepper/resource_converter.cc |
+++ b/content/renderer/pepper/resource_converter.cc |
@@ -20,6 +20,11 @@ |
#include "third_party/WebKit/public/platform/WebMediaStreamSource.h" |
#include "third_party/WebKit/public/web/WebDOMFileSystem.h" |
#include "third_party/WebKit/public/web/WebDOMMediaStreamTrack.h" |
+#include "third_party/WebKit/public/web/WebFrame.h" |
+// TODO(mgiuca): This include is not allowed from content/renderer. This is |
+// needed to parse a file system URL. Perhaps it can be moved to webkit/common? |
+#include "webkit/browser/fileapi/file_system_url.h" |
+#include "webkit/common/fileapi/file_system_util.h" |
using ppapi::ResourceVar; |
@@ -54,6 +59,29 @@ PP_FileSystemType WebFileSystemTypeToPPAPI(blink::WebFileSystem::Type type) { |
} |
} |
+// Converts a fileapi::FileSystemType to a blink::WebFileSystemType. |
+// Returns true on success, false on failure. |
+bool FileApiFileSystemTypeToWebFileSystemType( |
+ fileapi::FileSystemType type, |
+ blink::WebFileSystemType* result_type) { |
+ switch (type) { |
+ case fileapi::kFileSystemTypeTemporary: |
+ *result_type = blink::WebFileSystemTypeTemporary; |
+ return true; |
+ case fileapi::kFileSystemTypePersistent: |
+ *result_type = blink::WebFileSystemTypePersistent; |
+ return true; |
+ case fileapi::kFileSystemTypeIsolated: |
+ *result_type = blink::WebFileSystemTypeIsolated; |
+ return true; |
+ case fileapi::kFileSystemTypeExternal: |
+ *result_type = blink::WebFileSystemTypeExternal; |
kinuko
2014/02/20 11:33:28
As you can see in file_system_types.h, these are g
Matt Giuca
2014/02/23 23:55:48
I'm uncomfortable relying on that fact. Besides, I
|
+ return true; |
+ default: |
+ return false; |
+ } |
+} |
+ |
// Given a V8 value containing a DOMFileSystem, creates a resource host and |
// returns the resource information for serialization. |
// On error, false. |
@@ -92,6 +120,26 @@ bool DOMFileSystemToResource( |
return true; |
} |
+v8::Handle<v8::Value> ResourceHostToDOMFileSystem( |
+ content::PepperFileSystemHost* file_system_host, |
+ v8::Handle<v8::Context> context) { |
+ GURL root_url = file_system_host->GetRootUrl(); |
+ GURL origin; |
+ fileapi::FileSystemType mount_type; |
+ base::FilePath virtual_path; |
+ fileapi::FileSystemURL::ParseFileSystemSchemeURL( |
+ root_url, &origin, &mount_type, &virtual_path); |
+ |
+ std::string name = GetFileSystemName(origin, mount_type); |
+ blink::WebFileSystemType blink_type; |
+ FileApiFileSystemTypeToWebFileSystemType(mount_type, &blink_type); |
+ blink::WebFrame* frame = blink::WebFrame::frameForContext(context); |
+ return frame->createSerializableFileSystem( |
+ blink_type, |
+ blink::WebString::fromUTF8(name), |
+ blink::WebString::fromUTF8(root_url.spec())); |
+} |
+ |
bool DOMMediaStreamTrackToResource( |
PP_Instance instance, |
RendererPpapiHost* host, |
@@ -233,11 +281,15 @@ bool ResourceConverterImpl::ToV8Value(const PP_Var& var, |
} |
// Convert to the appropriate type of resource host. |
- // TODO(mgiuca): Convert FileSystemHost resources into DOMFileSystem V8 |
- // objects. (http://crbug.com/345158) |
- LOG(ERROR) << "The type of resource #" << resource_id |
- << " cannot be converted to a JavaScript object."; |
- return false; |
+ if (resource_host->IsFileSystemHost()) { |
+ *result = ResourceHostToDOMFileSystem( |
+ static_cast<content::PepperFileSystemHost*>(resource_host), context); |
+ return true; |
+ } else { |
+ LOG(ERROR) << "The type of resource #" << resource_id |
+ << " cannot be converted to a JavaScript object."; |
+ return false; |
+ } |
} |
scoped_refptr<HostResourceVar> ResourceConverterImpl::CreateResourceVar( |