Chromium Code Reviews| 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..3543405b60d8852c07d12adf7d53f45a47740661 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( |
|
Matt Giuca
2014/02/24 04:45:37
See Kinuko's comment on Patch Set 4 (not yet resol
kinuko
2014/02/25 05:07:05
I'm fine with this code.
|
| + 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: |
|
kinuko
2014/02/25 05:07:05
nit: do we want to put NOTREACHED() here?
Matt Giuca
2014/03/06 01:06:26
I don't think we want to. It isn't a programming e
kinuko
2014/03/06 05:20:40
Ok (btw NOTREACHED won't crash renderer in product
Matt Giuca
2014/03/06 06:53:54
Yeah, I know, but the debug build still shouldn't
|
| + 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,29 @@ 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 mount_type; |
| + base::FilePath virtual_path; |
| + fileapi::ParseFileSystemSchemeURL( |
| + root_url, &origin, &mount_type, &virtual_path); |
| + |
| + std::string name = GetFileSystemName(origin, mount_type); |
|
raymes
2014/02/25 04:55:44
missing namespace
kinuko
2014/02/25 05:07:05
Hmm.. does it mean we may not get the same .name v
Matt Giuca
2014/03/06 01:06:26
I don't understand this concern. Can you elaborate
kinuko
2014/03/06 05:20:40
I could be mistaken something. If we pass a DOMFil
kinuko
2014/03/06 05:30:44
Probably this code's main target is to convert a p
Matt Giuca
2014/03/06 06:53:54
OK thanks for explaining. You can also get other t
kinuko
2014/03/06 07:05:51
Most (or possibly all) filesystems use the standar
|
| + blink::WebFileSystemType blink_type; |
| + if (!FileApiFileSystemTypeToWebFileSystemType(mount_type, &blink_type)) |
| + return false; |
| + blink::WebFrame* frame = blink::WebFrame::frameForContext(context); |
| + *dom_file_system = frame->createSerializableFileSystem( |
|
kinuko
2014/02/25 05:07:05
Let me make sure once more (recalling past discuss
kinuko
2014/02/26 03:53:56
Btw can you instead use new WebDOMFileSystem::crea
Matt Giuca
2014/03/06 01:06:26
I don't know what you mean exactly. Can you explai
kinuko
2014/03/06 05:20:40
Yes, that's what I was asking. Serializable FileSy
Matt Giuca
2014/03/06 06:53:54
Yes, I think I remember this conversation now. I b
kinuko
2014/03/06 07:05:51
Thanks. lgtm then (as far as Raymes says yes to th
|
| + blink_type, |
| + blink::WebString::fromUTF8(name), |
| + blink::WebString::fromUTF8(root_url.spec())); |
|
raymes
2014/02/25 04:55:44
I defer to kinuko for the creation of the dom file
|
| + return true; |
| +} |
| + |
| bool DOMMediaStreamTrackToResource( |
| PP_Instance instance, |
| RendererPpapiHost* host, |
| @@ -239,11 +288,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( |