Skip to content

Commit

Permalink
Pepper: Move FileRef to the "new" resource proxy.
Browse files Browse the repository at this point in the history
This change moves the FileRef implementation from the previous one in the "old"
resource model (ppb_file_ref_impl.cc) to the "new" resource model
(pepper_file_ref_host.cc), and from the renderer to the browser.

As many as possible of the supporting changes were split off to other changes
to minimize the size of this change. Unfortunately, a lot of changes for
URLLoader had to be rolled into this change.

The data structures for CreateInfo have changed, and all users of FileRef have
to be moved over, which is what causes this change to be so large.

TBR=dmichael@chromium.org, jschuh@chromium.org, yzshen@chromium.org
BUG=225441

Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=216744

Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=218305

Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=219911

Review URL: https://codereview.chromium.org/21966004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@221284 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
teravest@chromium.org committed Sep 4, 2013
1 parent e87fd3f commit 66c8f3c
Show file tree
Hide file tree
Showing 72 changed files with 653 additions and 2,134 deletions.
48 changes: 39 additions & 9 deletions chrome/renderer/pepper/pepper_flash_drm_renderer_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "ppapi/host/host_message_context.h"
#include "ppapi/host/ppapi_host.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/proxy/ppb_file_ref_proxy.h"

namespace chrome {

Expand All @@ -28,7 +27,8 @@ PepperFlashDRMRendererHost::PepperFlashDRMRendererHost(
PP_Instance instance,
PP_Resource resource)
: ResourceHost(host->GetPpapiHost(), instance, resource),
renderer_ppapi_host_(host) {
renderer_ppapi_host_(host),
weak_factory_(this) {
}

PepperFlashDRMRendererHost::~PepperFlashDRMRendererHost() {
Expand Down Expand Up @@ -56,13 +56,43 @@ int32_t PepperFlashDRMRendererHost::OnGetVoucherFile(
base::FilePath voucher_file = plugin_dir.Append(
base::FilePath(kVoucherFilename));

ppapi::PPB_FileRef_CreateInfo create_info;
ppapi::proxy::PPB_FileRef_Proxy::SerializeFileRef(
plugin_instance->CreateExternalFileReference(voucher_file),
&create_info);
context->reply_msg =
PpapiPluginMsg_FlashDRM_GetVoucherFileReply(create_info);
return PP_OK;
int renderer_pending_host_id =
plugin_instance->MakePendingFileRefRendererHost(voucher_file);
if (renderer_pending_host_id == 0)
return PP_ERROR_FAILED;

std::vector<IPC::Message> create_msgs;
create_msgs.push_back(PpapiHostMsg_FileRef_CreateExternal(voucher_file));

renderer_ppapi_host_->CreateBrowserResourceHosts(
pp_instance(),
create_msgs,
base::Bind(&PepperFlashDRMRendererHost::DidCreateFileRefHosts,
weak_factory_.GetWeakPtr(),
context->MakeReplyMessageContext(),
voucher_file,
renderer_pending_host_id));
return PP_OK_COMPLETIONPENDING;
}

void PepperFlashDRMRendererHost::DidCreateFileRefHosts(
const ppapi::host::ReplyMessageContext& reply_context,
const base::FilePath& external_path,
int renderer_pending_host_id,
const std::vector<int>& browser_pending_host_ids) {
DCHECK(browser_pending_host_ids.size() == 1);

int browser_pending_host_id = 0;
if (browser_pending_host_ids.size() == 1)
browser_pending_host_id = browser_pending_host_ids[0];

ppapi::FileRefCreateInfo create_info =
ppapi::MakeExternalFileRefCreateInfo(external_path,
std::string(),
browser_pending_host_id,
renderer_pending_host_id);
host()->SendReply(reply_context,
PpapiPluginMsg_FlashDRM_GetVoucherFileReply(create_info));
}

} // namespace chrome
Expand Down
13 changes: 13 additions & 0 deletions chrome/renderer/pepper/pepper_flash_drm_renderer_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,13 @@

#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/weak_ptr.h"
#include "ppapi/host/resource_host.h"

namespace base {
class FilePath;
}

namespace content {
class RendererPpapiHost;
}
Expand All @@ -31,9 +36,17 @@ class PepperFlashDRMRendererHost : public ppapi::host::ResourceHost {
private:
int32_t OnGetVoucherFile(ppapi::host::HostMessageContext* context);

void DidCreateFileRefHosts(
const ppapi::host::ReplyMessageContext& reply_context,
const base::FilePath& external_path,
int renderer_pending_host_id,
const std::vector<int>& browser_pending_host_ids);

// Non-owning pointer.
content::RendererPpapiHost* renderer_ppapi_host_;

base::WeakPtrFactory<PepperFlashDRMRendererHost> weak_factory_;

DISALLOW_COPY_AND_ASSIGN(PepperFlashDRMRendererHost);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,16 @@ int32_t PepperExternalFileRefBackend::GetAbsolutePath(
ppapi::host::ReplyMessageContext reply_context) {
host_->SendReply(reply_context,
PpapiPluginMsg_FileRef_GetAbsolutePathReply(path_.AsUTF8Unsafe()));
return PP_OK;

// Use PP_OK_COMPLETIONPENDING instead of PP_OK since we've already sent our
// reply above.
return PP_OK_COMPLETIONPENDING;
}

fileapi::FileSystemURL PepperExternalFileRefBackend::GetFileSystemURL() const {
return fileapi::FileSystemURL();
}

std::string PepperExternalFileRefBackend::GetFileSystemURLSpec() const {
return std::string();
}

base::FilePath PepperExternalFileRefBackend::GetExternalPath() const {
return path_;
}

int32_t PepperExternalFileRefBackend::CanRead() const {
if (!ChildProcessSecurityPolicyImpl::GetInstance()->
CanReadFile(render_process_id_, path_)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ class PepperExternalFileRefBackend : public PepperFileRefBackend {
virtual int32_t GetAbsolutePath(ppapi::host::ReplyMessageContext context)
OVERRIDE;
virtual fileapi::FileSystemURL GetFileSystemURL() const OVERRIDE;
virtual std::string GetFileSystemURLSpec() const OVERRIDE;
virtual base::FilePath GetExternalPath() const OVERRIDE;

virtual int32_t CanRead() const OVERRIDE;
virtual int32_t CanWrite() const OVERRIDE;
Expand Down
16 changes: 2 additions & 14 deletions content/browser/renderer_host/pepper/pepper_file_ref_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ PepperFileRefHost::PepperFileRefHost(BrowserPpapiHost* host,
}

fs_type_ = fs_host->GetType();
// TODO(teravest): Add support for isolated filesystems.
if ((fs_type_ != PP_FILESYSTEMTYPE_LOCALPERSISTENT) &&
(fs_type_ != PP_FILESYSTEMTYPE_LOCALTEMPORARY)) {
(fs_type_ != PP_FILESYSTEMTYPE_LOCALTEMPORARY) &&
(fs_type_ != PP_FILESYSTEMTYPE_ISOLATED)) {
DLOG(ERROR) << "Unsupported filesystem type: " << fs_type_;
return;
}
Expand Down Expand Up @@ -116,18 +116,6 @@ fileapi::FileSystemURL PepperFileRefHost::GetFileSystemURL() const {
return fileapi::FileSystemURL();
}

std::string PepperFileRefHost::GetFileSystemURLSpec() const {
if (backend_)
return backend_->GetFileSystemURLSpec();
return std::string();
}

base::FilePath PepperFileRefHost::GetExternalPath() const {
if (backend_)
return backend_->GetExternalPath();
return base::FilePath();
}

int32_t PepperFileRefHost::CanRead() const {
if (backend_)
return backend_->CanRead();
Expand Down
6 changes: 0 additions & 6 deletions content/browser/renderer_host/pepper/pepper_file_ref_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ class PepperFileRefBackend {
virtual int32_t GetAbsolutePath(
ppapi::host::ReplyMessageContext context) = 0;
virtual fileapi::FileSystemURL GetFileSystemURL() const = 0;
virtual std::string GetFileSystemURLSpec() const = 0;
virtual base::FilePath GetExternalPath() const = 0;

// Returns an error from the pp_errors.h enum.
virtual int32_t CanRead() const = 0;
Expand Down Expand Up @@ -79,10 +77,6 @@ class CONTENT_EXPORT PepperFileRefHost
PP_FileSystemType GetFileSystemType() const;
fileapi::FileSystemURL GetFileSystemURL() const;

// Required to support FileIO.
std::string GetFileSystemURLSpec() const;
base::FilePath GetExternalPath() const;

int32_t CanRead() const;
int32_t CanWrite() const;
int32_t CanCreate() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,6 @@ fileapi::FileSystemURL PepperInternalFileRefBackend::GetFileSystemURL() const {
return fs_url_;
}

std::string PepperInternalFileRefBackend::GetFileSystemURLSpec() const {
if (fs_host_.get() && fs_host_->IsOpened() &&
fs_host_->GetRootUrl().is_valid()) {
return fs_host_->GetRootUrl().Resolve(
net::EscapePath(path_.substr(1))).spec();
}
return std::string();
}

base::FilePath PepperInternalFileRefBackend::GetExternalPath() const {
return base::FilePath();
}

scoped_refptr<fileapi::FileSystemContext>
PepperInternalFileRefBackend::GetFileSystemContext() const {
if (!fs_host_.get())
Expand Down Expand Up @@ -223,7 +210,7 @@ void PepperInternalFileRefBackend::ReadDirectoryComplete(

context.params.set_result(ppapi::PlatformFileErrorToPepperError(error));

std::vector<ppapi::FileRef_CreateInfo> infos;
std::vector<ppapi::FileRefCreateInfo> infos;
std::vector<PP_FileType> file_types;
if (error == base::PLATFORM_FILE_OK && fs_host_.get()) {
std::string dir_path = path_;
Expand All @@ -237,7 +224,7 @@ void PepperInternalFileRefBackend::ReadDirectoryComplete(
else
file_types.push_back(PP_FILETYPE_REGULAR);

ppapi::FileRef_CreateInfo info;
ppapi::FileRefCreateInfo info;
info.file_system_type = fs_type_;
info.file_system_plugin_resource = fs_host_->pp_resource();
std::string path =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ class PepperInternalFileRefBackend : public PepperFileRefBackend {
OVERRIDE;

virtual fileapi::FileSystemURL GetFileSystemURL() const OVERRIDE;
virtual std::string GetFileSystemURLSpec() const OVERRIDE;
virtual base::FilePath GetExternalPath() const OVERRIDE;

virtual int32_t CanRead() const OVERRIDE;
virtual int32_t CanWrite() const OVERRIDE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "ppapi/host/resource_host.h"
#include "ppapi/proxy/ppapi_message_utils.h"
#include "ppapi/proxy/ppapi_messages.h"
#include "ppapi/proxy/ppapi_message_utils.h"
#include "ppapi/proxy/resource_message_params.h"

namespace content {
Expand Down Expand Up @@ -73,8 +74,6 @@ bool PepperRendererConnection::OnMessageReceived(const IPC::Message& msg,
IPC_BEGIN_MESSAGE_MAP_EX(PepperRendererConnection, msg, *message_was_ok)
IPC_MESSAGE_HANDLER(PpapiHostMsg_CreateResourceHostsFromHost,
OnMsgCreateResourceHostsFromHost)
IPC_MESSAGE_HANDLER(PpapiHostMsg_FileRef_GetInfoForRenderer,
OnMsgFileRefGetInfoForRenderer)
IPC_MESSAGE_HANDLER(ViewHostMsg_DidCreateInProcessInstance,
OnMsgDidCreateInProcessInstance)
IPC_MESSAGE_HANDLER(ViewHostMsg_DidDeleteInProcessInstance,
Expand Down Expand Up @@ -129,40 +128,6 @@ void PepperRendererConnection::OnMsgCreateResourceHostsFromHost(
routing_id, params.sequence(), pending_resource_host_ids));
}

void PepperRendererConnection::OnMsgFileRefGetInfoForRenderer(
int routing_id,
int child_process_id,
int32_t sequence,
const std::vector<PP_Resource>& resources) {
std::vector<PP_Resource> out_resources;
std::vector<PP_FileSystemType> fs_types;
std::vector<std::string> file_system_url_specs;
std::vector<base::FilePath> external_paths;

BrowserPpapiHostImpl* host = GetHostForChildProcess(child_process_id);
if (host) {
for (size_t i = 0; i < resources.size(); ++i) {
ppapi::host::ResourceHost* resource_host =
host->GetPpapiHost()->GetResourceHost(resources[i]);
if (resource_host && resource_host->IsFileRefHost()) {
PepperFileRefHost* file_ref_host =
static_cast<PepperFileRefHost*>(resource_host);
out_resources.push_back(resources[i]);
fs_types.push_back(file_ref_host->GetFileSystemType());
file_system_url_specs.push_back(file_ref_host->GetFileSystemURLSpec());
external_paths.push_back(file_ref_host->GetExternalPath());
}
}
}
Send(new PpapiHostMsg_FileRef_GetInfoForRendererReply(
routing_id,
sequence,
out_resources,
fs_types,
file_system_url_specs,
external_paths));
}

void PepperRendererConnection::OnMsgDidCreateInProcessInstance(
PP_Instance instance,
const PepperRendererInstanceData& instance_data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ class PepperRendererConnection : public BrowserMessageFilter {
PP_Instance instance,
const std::vector<IPC::Message>& nested_msgs);

void OnMsgFileRefGetInfoForRenderer(
int routing_id,
int child_process_id,
int32_t sequence_num,
const std::vector<PP_Resource>& resources);

void OnMsgDidCreateInProcessInstance(
PP_Instance instance,
const PepperRendererInstanceData& instance_data);
Expand Down
4 changes: 2 additions & 2 deletions content/content_renderer.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@
'renderer/pepper/pepper_file_chooser_host.h',
'renderer/pepper/pepper_file_io_host.cc',
'renderer/pepper/pepper_file_io_host.h',
'renderer/pepper/pepper_file_ref_renderer_host.cc',
'renderer/pepper/pepper_file_ref_renderer_host.h',
'renderer/pepper/pepper_file_system_host.cc',
'renderer/pepper/pepper_file_system_host.h',
'renderer/pepper/pepper_graphics_2d_host.cc',
Expand Down Expand Up @@ -353,8 +355,6 @@
'renderer/pepper/ppb_broker_impl.h',
'renderer/pepper/ppb_buffer_impl.cc',
'renderer/pepper/ppb_buffer_impl.h',
'renderer/pepper/ppb_file_ref_impl.cc',
'renderer/pepper/ppb_file_ref_impl.h',
'renderer/pepper/ppb_flash_message_loop_impl.cc',
'renderer/pepper/ppb_flash_message_loop_impl.h',
'renderer/pepper/ppb_graphics_3d_impl.cc',
Expand Down
7 changes: 2 additions & 5 deletions content/public/renderer/pepper_plugin_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ class PepperPluginInstance {
// Returns the location of this module.
virtual base::FilePath GetModulePath() = 0;

// Returns a reference to a file with the given path.
// The returned object will have a refcount of 0 (just like "new").
virtual PP_Resource CreateExternalFileReference(
const base::FilePath& external_file_path) = 0;

// Creates a PPB_ImageData given a Skia image.
virtual PP_Resource CreateImage(gfx::ImageSkia* source_image,
float scale) = 0;
Expand Down Expand Up @@ -93,6 +88,8 @@ class PepperPluginInstance {
const char* target,
bool from_user_action) = 0;

// Creates a pending PepperFileRefRendererHost. Returns 0 on failure.
virtual int MakePendingFileRefRendererHost(const base::FilePath& path) = 0;
};

} // namespace content
Expand Down
5 changes: 5 additions & 0 deletions content/public/renderer/renderer_ppapi_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ class RendererPpapiHost {
public:
// Returns the RendererPpapiHost associated with the given PP_Instance,
// or NULL if the instance is invalid.
//
// Do NOT use this when dealing with an "external plugin" that serves as a
// bootstrap to load a second plugin. This is because the two will share a
// PP_Instance, and the RendererPpapiHost* for the second plugin will be
// returned after we switch the proxy on.
CONTENT_EXPORT static RendererPpapiHost* GetForPPInstance(
PP_Instance instance);

Expand Down
13 changes: 13 additions & 0 deletions content/renderer/pepper/content_renderer_pepper_host_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "content/renderer/pepper/pepper_audio_input_host.h"
#include "content/renderer/pepper/pepper_file_chooser_host.h"
#include "content/renderer/pepper/pepper_file_io_host.h"
#include "content/renderer/pepper/pepper_file_ref_renderer_host.h"
#include "content/renderer/pepper/pepper_file_system_host.h"
#include "content/renderer/pepper/pepper_graphics_2d_host.h"
#include "content/renderer/pepper/pepper_truetype_font_host.h"
Expand Down Expand Up @@ -75,6 +76,18 @@ scoped_ptr<ResourceHost> ContentRendererPepperHostFactory::CreateResourceHost(
case PpapiHostMsg_FileIO_Create::ID:
return scoped_ptr<ResourceHost>(new PepperFileIOHost(
host_, instance, params.pp_resource()));
case PpapiHostMsg_FileRef_CreateInternal::ID: {
PP_Resource file_system;
std::string internal_path;
if (!UnpackMessage<PpapiHostMsg_FileRef_CreateInternal>(message,
&file_system,
&internal_path)) {
NOTREACHED();
return scoped_ptr<ResourceHost>();
}
return scoped_ptr<ResourceHost>(new PepperFileRefRendererHost(
host_, instance, params.pp_resource(), file_system, internal_path));
}
case PpapiHostMsg_FileSystem_Create::ID: {
PP_FileSystemType file_system_type;
if (!UnpackMessage<PpapiHostMsg_FileSystem_Create>(message,
Expand Down
5 changes: 2 additions & 3 deletions content/renderer/pepper/mock_renderer_ppapi_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,9 @@ bool MockRendererPpapiHost::IsRunningInProcess() const {

void MockRendererPpapiHost::CreateBrowserResourceHosts(
PP_Instance instance,
const std::vector<IPC::Message>& nested_msg,
const std::vector<IPC::Message>& nested_msgs,
const base::Callback<void(const std::vector<int>&)>& callback) const {
NOTIMPLEMENTED();
callback.Run(std::vector<int>());
callback.Run(std::vector<int>(nested_msgs.size(), 0));
return;
}

Expand Down
Loading

0 comments on commit 66c8f3c

Please sign in to comment.