Index: content/renderer/pepper/resource_converter.cc |
diff --git a/content/renderer/pepper/resource_converter.cc b/content/renderer/pepper/resource_converter.cc |
index c4590b84b99cf1c835fc1c10200335286d020ffd..130aff8f7f12dfc7604115a0139d82bfcdaada29 100644 |
--- a/content/renderer/pepper/resource_converter.cc |
+++ b/content/renderer/pepper/resource_converter.cc |
@@ -20,6 +20,8 @@ |
#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" |
+#include "webkit/common/fileapi/file_system_util.h" |
using ppapi::ResourceVar; |
@@ -54,6 +56,30 @@ PP_FileSystemType WebFileSystemTypeToPPAPI(blink::WebFileSystem::Type type) { |
} |
} |
+// Converts a fileapi::FileSystemType to a blink::WebFileSystemType. |
+// Returns true on success, false if |type| does not correspond to a |
+// WebFileSystemType. |
+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; |
+ 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 +118,31 @@ bool DOMFileSystemToResource( |
return true; |
} |
+bool ResourceHostToDOMFileSystem( |
+ content::PepperFileSystemHost* file_system_host, |
+ v8::Handle<v8::Context> context, |
+ v8::Handle<v8::Value>* dom_file_system) { |
+ GURL root_url = file_system_host->GetRootUrl(); |
+ GURL origin; |
+ fileapi::FileSystemType type; |
+ base::FilePath virtual_path; |
+ fileapi::ParseFileSystemSchemeURL(root_url, &origin, &type, &virtual_path); |
+ |
+ std::string name = fileapi::GetFileSystemName(origin, type); |
+ blink::WebFileSystemType blink_type; |
+ if (!FileApiFileSystemTypeToWebFileSystemType(type, &blink_type)) |
+ return false; |
+ blink::WebFrame* frame = blink::WebFrame::frameForContext(context); |
+ blink::WebDOMFileSystem web_dom_file_system = blink::WebDOMFileSystem::create( |
Ronghua Wu (Left Chromium)
2014/03/07 23:55:12
Hi Matt,
In the video track case, the pepper host
Matt Giuca
2014/03/10 04:51:42
Since this isn't relevant to reviewing the CL, I'd
|
+ frame, |
+ blink_type, |
+ blink::WebString::fromUTF8(name), |
+ root_url, |
+ blink::WebDOMFileSystem::SerializableTypeSerializable); |
+ *dom_file_system = web_dom_file_system.toV8Value(); |
+ return true; |
+} |
+ |
bool DOMMediaStreamTrackToResource( |
PP_Instance instance, |
RendererPpapiHost* host, |
@@ -239,11 +290,16 @@ 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()) { |
+ return ResourceHostToDOMFileSystem( |
+ static_cast<content::PepperFileSystemHost*>(resource_host), |
+ context, |
+ result); |
+ } else { |
+ LOG(ERROR) << "The type of resource #" << resource_id |
+ << " cannot be converted to a JavaScript object."; |
+ return false; |
+ } |
} |
scoped_refptr<HostResourceVar> ResourceConverterImpl::CreateResourceVar( |