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

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@216744 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
teravest@chromium.org committed Aug 9, 2013
1 parent fc03448 commit c56d214
Show file tree
Hide file tree
Showing 64 changed files with 512 additions and 2,067 deletions.
31 changes: 22 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,26 @@ 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;
renderer_ppapi_host_->CreateBrowserResourceHost(
pp_instance(),
PpapiHostMsg_FileRef_CreateExternal(voucher_file),
base::Bind(&PepperFlashDRMRendererHost::DidCreateFileRefHost,
weak_factory_.GetWeakPtr(),
context->MakeReplyMessageContext(),
voucher_file));
return PP_OK_COMPLETIONPENDING;
}

void PepperFlashDRMRendererHost::DidCreateFileRefHost(
const ppapi::host::ReplyMessageContext& reply_context,
const base::FilePath& external_path,
int pending_resource_id) {
ppapi::FileRefCreateInfo create_info =
ppapi::MakeExternalFileRefCreateInfo(external_path,
std::string(),
pending_resource_id);
host()->SendReply(reply_context,
PpapiPluginMsg_FlashDRM_GetVoucherFileReply(create_info));
}

} // namespace chrome
Expand Down
12 changes: 12 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,16 @@ class PepperFlashDRMRendererHost : public ppapi::host::ResourceHost {
private:
int32_t OnGetVoucherFile(ppapi::host::HostMessageContext* context);

void DidCreateFileRefHost(
const ppapi::host::ReplyMessageContext& reply_context,
const base::FilePath& external_path,
int pending_resource_id);

// 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,7 +90,10 @@ 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,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 @@ -235,7 +235,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
37 changes: 22 additions & 15 deletions content/browser/renderer_host/pepper/pepper_renderer_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
#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"
#include "ppapi/shared_impl/file_ref_detailed_info.h"

namespace content {

Expand Down Expand Up @@ -76,6 +78,8 @@ bool PepperRendererConnection::OnMessageReceived(const IPC::Message& msg,
OnMsgCreateResourceHostFromHost)
IPC_MESSAGE_HANDLER(PpapiHostMsg_FileRef_GetInfoForRenderer,
OnMsgFileRefGetInfoForRenderer)
IPC_MESSAGE_HANDLER(PpapiHostMsg_FileRef_SyncGetInfoForRenderer,
OnMsgFileRefSyncGetInfoForRenderer)
IPC_MESSAGE_HANDLER(ViewHostMsg_DidCreateInProcessInstance,
OnMsgDidCreateInProcessInstance)
IPC_MESSAGE_HANDLER(ViewHostMsg_DidDeleteInProcessInstance,
Expand Down Expand Up @@ -132,33 +136,36 @@ void PepperRendererConnection::OnMsgFileRefGetInfoForRenderer(
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;
std::vector<ppapi::FileRefDetailedInfo> infos;
OnMsgFileRefSyncGetInfoForRenderer(child_process_id, resources, &infos);
Send(new PpapiHostMsg_FileRef_GetInfoForRendererReply(
routing_id,
sequence,
infos));
}

void PepperRendererConnection::OnMsgFileRefSyncGetInfoForRenderer(
int child_process_id,
const std::vector<PP_Resource>& resources,
std::vector<ppapi::FileRefDetailedInfo>* out_infos) {
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());
ppapi::FileRefDetailedInfo info;
info.resource = resources[i];
info.file_system_type = file_ref_host->GetFileSystemType();
info.file_system_url_spec = file_ref_host->GetFileSystemURLSpec();
info.external_path = file_ref_host->GetExternalPath();
out_infos->push_back(info);
}
}
}
Send(new PpapiHostMsg_FileRef_GetInfoForRendererReply(
routing_id,
sequence,
out_resources,
fs_types,
file_system_url_specs,
external_paths));
}

void PepperRendererConnection::OnMsgDidCreateInProcessInstance(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "content/public/browser/browser_message_filter.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_resource.h"
#include "ppapi/shared_impl/file_ref_detailed_info.h"

class GURL;

Expand Down Expand Up @@ -58,6 +59,11 @@ class PepperRendererConnection : public BrowserMessageFilter {
int32_t sequence_num,
const std::vector<PP_Resource>& resources);

void OnMsgFileRefSyncGetInfoForRenderer(
int child_process_id,
const std::vector<PP_Resource>& resources,
std::vector<ppapi::FileRefDetailedInfo>* out_infos);

void OnMsgDidCreateInProcessInstance(
PP_Instance instance,
const PepperRendererInstanceData& instance_data);
Expand Down
2 changes: 0 additions & 2 deletions content/content_renderer.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,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_gpu_blacklist_private_impl.cc',
Expand Down
6 changes: 0 additions & 6 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 @@ -92,7 +87,6 @@ class PepperPluginInstance {
virtual int32_t Navigate(const ppapi::URLRequestInfoData& request,
const char* target,
bool from_user_action) = 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 @@ -47,6 +47,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 the "NaCl trusted plugin". That plugin
// and the "untrusted plugin" (the NaCl application) that will be loaded
// share a PP_Instance, and the RendererPpapiHost* for the "untrusted plugin"
// will be returned after we switch the proxy on.
CONTENT_EXPORT static RendererPpapiHost* GetForPPInstance(
PP_Instance instance);

Expand Down
10 changes: 4 additions & 6 deletions content/renderer/pepper/pepper_browser_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ bool PepperBrowserConnection::OnMessageReceived(const IPC::Message& msg) {
IPC_BEGIN_MESSAGE_MAP(PepperBrowserConnection, msg)
IPC_MESSAGE_HANDLER(PpapiHostMsg_CreateResourceHostFromHostReply,
OnMsgCreateResourceHostFromHostReply)
IPC_MESSAGE_HANDLER(PpapiHostMsg_FileRef_GetInfoForRendererReply,
OnMsgFileRefGetInfoReply)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()

return handled;
}

Expand Down Expand Up @@ -101,18 +102,15 @@ void PepperBrowserConnection::OnMsgCreateResourceHostFromHostReply(

void PepperBrowserConnection::OnMsgFileRefGetInfoReply(
int32_t sequence_number,
const std::vector<PP_Resource>& resources,
const std::vector<PP_FileSystemType>& types,
const std::vector<std::string>& file_system_url_specs,
const std::vector<base::FilePath>& external_paths) {
const std::vector<ppapi::FileRefDetailedInfo>& infos) {
// Check that the message is destined for the plugin this object is associated
// with.
std::map<int32_t, FileRefGetInfoCallback>::iterator it =
get_info_map_.find(sequence_number);
if (it != get_info_map_.end()) {
FileRefGetInfoCallback callback = it->second;
get_info_map_.erase(it);
callback.Run(resources, types, file_system_url_specs, external_paths);
callback.Run(infos);
} else {
NOTREACHED();
}
Expand Down
11 changes: 3 additions & 8 deletions content/renderer/pepper/pepper_browser_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "ppapi/c/pp_file_info.h"
#include "ppapi/c/pp_instance.h"
#include "ppapi/c/pp_resource.h"
#include "ppapi/shared_impl/file_ref_detailed_info.h"

namespace content {

Expand All @@ -28,10 +29,7 @@ class PepperBrowserConnection
public:
typedef base::Callback<void(int)> PendingResourceIDCallback;
typedef base::Callback<void(
const std::vector<PP_Resource>&,
const std::vector<PP_FileSystemType>&,
const std::vector<std::string>&,
const std::vector<base::FilePath>&)> FileRefGetInfoCallback;
const std::vector<ppapi::FileRefDetailedInfo>&)> FileRefGetInfoCallback;

explicit PepperBrowserConnection(RenderView* render_view);
virtual ~PepperBrowserConnection();
Expand Down Expand Up @@ -71,10 +69,7 @@ class PepperBrowserConnection
int pending_resource_host_id);
void OnMsgFileRefGetInfoReply(
int32_t sequence_number,
const std::vector<PP_Resource>& resources,
const std::vector<PP_FileSystemType>& types,
const std::vector<std::string>& file_system_url_specs,
const std::vector<base::FilePath>& external_paths);
const std::vector<ppapi::FileRefDetailedInfo>& infos);

// Return the next sequence number.
int32_t GetNextSequence();
Expand Down
Loading

0 comments on commit c56d214

Please sign in to comment.