Skip to content

Commit

Permalink
Revert 140093 - Open pepper files directly in browser.
Browse files Browse the repository at this point in the history
This CL merges in the changes for the per-profile plugin process from the
previously retired CL.
Review URL: https://chromiumcodereview.appspot.com/10387195

TBR=tsepez@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10477006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@140094 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
tsepez@chromium.org committed Jun 1, 2012
1 parent 7e1dc3d commit 042ba85
Show file tree
Hide file tree
Showing 27 changed files with 431 additions and 385 deletions.
3 changes: 1 addition & 2 deletions chrome/common/all_messages.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

Expand All @@ -17,5 +17,4 @@
#include "chrome/common/common_message_generator.h"
#include "chrome/common/nacl_messages.h"
#include "content/common/content_message_generator.h"
#include "ppapi/proxy/pepper_file_messages.h"
#include "ppapi/proxy/ppapi_messages.h"
17 changes: 5 additions & 12 deletions content/browser/ppapi_plugin_process_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ PpapiPluginProcessHost* PpapiPluginProcessHost::CreatePluginHost(
const content::PepperPluginInfo& info,
const FilePath& profile_data_directory,
net::HostResolver* host_resolver) {
PpapiPluginProcessHost* plugin_host = new PpapiPluginProcessHost(
info.name, profile_data_directory, host_resolver);
PpapiPluginProcessHost* plugin_host =
new PpapiPluginProcessHost(profile_data_directory, host_resolver);
if (plugin_host->Init(info))
return plugin_host;

Expand Down Expand Up @@ -112,23 +112,16 @@ void PpapiPluginProcessHost::OpenChannelToPlugin(Client* client) {
}

PpapiPluginProcessHost::PpapiPluginProcessHost(
const std::string& plugin_name,
const FilePath& profile_data_directory,
net::HostResolver* host_resolver)
: network_observer_(new PluginNetworkObserver(this)),
: filter_(new PepperMessageFilter(PepperMessageFilter::PLUGIN,
host_resolver)),
network_observer_(new PluginNetworkObserver(this)),
profile_data_directory_(profile_data_directory),
is_broker_(false) {
process_.reset(new BrowserChildProcessHostImpl(
content::PROCESS_TYPE_PPAPI_PLUGIN, this));

filter_ = new PepperMessageFilter(
PepperMessageFilter::PLUGIN, host_resolver);

file_filter_ = new PepperTrustedFileMessageFilter(
process_->GetData().id, plugin_name, profile_data_directory);

process_->GetHost()->AddFilter(filter_.get());
process_->GetHost()->AddFilter(file_filter_.get());
}

PpapiPluginProcessHost::PpapiPluginProcessHost()
Expand Down
13 changes: 3 additions & 10 deletions content/browser/ppapi_plugin_process_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
#define CONTENT_BROWSER_PPAPI_PLUGIN_PROCESS_HOST_H_
#pragma once

#include <string>
#include <queue>

#include "base/basictypes.h"
#include "base/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "content/browser/renderer_host/pepper_file_message_filter.h"
#include "base/memory/ref_counted.h"
#include "content/browser/renderer_host/pepper_message_filter.h"
#include "content/public/browser/browser_child_process_host_delegate.h"
#include "content/public/browser/browser_child_process_host_iterator.h"
Expand Down Expand Up @@ -81,8 +79,7 @@ class PpapiPluginProcessHost : public content::BrowserChildProcessHostDelegate,

const FilePath& plugin_path() const { return plugin_path_; }
const FilePath& profile_data_directory() const {
return profile_data_directory_;
}
return profile_data_directory_; }

// The client pointer must remain valid until its callback is issued.

Expand All @@ -91,8 +88,7 @@ class PpapiPluginProcessHost : public content::BrowserChildProcessHostDelegate,

// Constructors for plugin and broker process hosts, respectively.
// You must call Init before doing anything else.
PpapiPluginProcessHost(const std::string& plugin_name,
const FilePath& profile_data_directory,
PpapiPluginProcessHost(const FilePath& profile_data_directory,
net::HostResolver* host_resolver);
PpapiPluginProcessHost();

Expand All @@ -116,9 +112,6 @@ class PpapiPluginProcessHost : public content::BrowserChildProcessHostDelegate,
// Handles most requests from the plugin. May be NULL.
scoped_refptr<PepperMessageFilter> filter_;

// Handles filesystem requests from flash plugins. May be NULL.
scoped_refptr<PepperFileMessageFilter> file_filter_;

// Observes network changes. May be NULL.
scoped_ptr<PluginNetworkObserver> network_observer_;

Expand Down
60 changes: 19 additions & 41 deletions content/browser/renderer_host/pepper_file_message_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
#include "base/process_util.h"
#include "content/browser/child_process_security_policy_impl.h"
#include "content/browser/renderer_host/render_process_host_impl.h"
#include "content/common/pepper_file_messages.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/common/content_constants.h"
#include "ipc/ipc_platform_file.h"
#include "ppapi/proxy/pepper_file_messages.h"
#include "ppapi/shared_impl/file_path.h"
#include "webkit/plugins/ppapi/file_path.h"

#if defined(OS_POSIX)
#include "base/file_descriptor_posix.h"
Expand All @@ -37,9 +38,11 @@ const int kWritePermissions = base::PLATFORM_FILE_OPEN |
base::PLATFORM_FILE_EXCLUSIVE_WRITE |
base::PLATFORM_FILE_WRITE_ATTRIBUTES;

PepperFileMessageFilter::PepperFileMessageFilter(int child_id)
PepperFileMessageFilter::PepperFileMessageFilter(
int child_id, content::BrowserContext* browser_context)
: child_id_(child_id),
channel_(NULL) {
pepper_path_ = GetDataDirName(browser_context->GetPath());
}

void PepperFileMessageFilter::OverrideThreadForMessage(
Expand Down Expand Up @@ -80,7 +83,7 @@ PepperFileMessageFilter::~PepperFileMessageFilter() {

// Called on the FILE thread:
void PepperFileMessageFilter::OnOpenFile(
const ppapi::PepperFilePath& path,
const webkit::ppapi::PepperFilePath& path,
int flags,
base::PlatformFileError* error,
IPC::PlatformFileForTransit* file) {
Expand Down Expand Up @@ -125,8 +128,8 @@ void PepperFileMessageFilter::OnOpenFile(
}

void PepperFileMessageFilter::OnRenameFile(
const ppapi::PepperFilePath& from_path,
const ppapi::PepperFilePath& to_path,
const webkit::ppapi::PepperFilePath& from_path,
const webkit::ppapi::PepperFilePath& to_path,
base::PlatformFileError* error) {
FilePath from_full_path = ValidateAndConvertPepperFilePath(from_path,
kWritePermissions);
Expand All @@ -143,7 +146,7 @@ void PepperFileMessageFilter::OnRenameFile(
}

void PepperFileMessageFilter::OnDeleteFileOrDir(
const ppapi::PepperFilePath& path,
const webkit::ppapi::PepperFilePath& path,
bool recursive,
base::PlatformFileError* error) {
FilePath full_path = ValidateAndConvertPepperFilePath(path,
Expand All @@ -159,7 +162,7 @@ void PepperFileMessageFilter::OnDeleteFileOrDir(
}

void PepperFileMessageFilter::OnCreateDir(
const ppapi::PepperFilePath& path,
const webkit::ppapi::PepperFilePath& path,
base::PlatformFileError* error) {
FilePath full_path = ValidateAndConvertPepperFilePath(path,
kWritePermissions);
Expand All @@ -174,7 +177,7 @@ void PepperFileMessageFilter::OnCreateDir(
}

void PepperFileMessageFilter::OnQueryFile(
const ppapi::PepperFilePath& path,
const webkit::ppapi::PepperFilePath& path,
base::PlatformFileInfo* info,
base::PlatformFileError* error) {
FilePath full_path = ValidateAndConvertPepperFilePath(path, kReadPermissions);
Expand All @@ -189,8 +192,8 @@ void PepperFileMessageFilter::OnQueryFile(
}

void PepperFileMessageFilter::OnGetDirContents(
const ppapi::PepperFilePath& path,
ppapi::DirContents* contents,
const webkit::ppapi::PepperFilePath& path,
webkit::ppapi::DirContents* contents,
base::PlatformFileError* error) {
FilePath full_path = ValidateAndConvertPepperFilePath(path, kReadPermissions);
if (full_path.empty()) {
Expand All @@ -210,7 +213,7 @@ void PepperFileMessageFilter::OnGetDirContents(
while (!enumerator.Next().empty()) {
file_util::FileEnumerator::FindInfo info;
enumerator.GetFindInfo(&info);
ppapi::DirEntry entry = {
webkit::ppapi::DirEntry entry = {
file_util::FileEnumerator::GetFilename(info),
file_util::FileEnumerator::IsDirectory(info)
};
Expand All @@ -221,44 +224,19 @@ void PepperFileMessageFilter::OnGetDirContents(
}

FilePath PepperFileMessageFilter::ValidateAndConvertPepperFilePath(
const ppapi::PepperFilePath& pepper_path, int flags) {
FilePath file_path; // Empty path returned on error.
if (pepper_path.domain() == ppapi::PepperFilePath::DOMAIN_ABSOLUTE) {
if (pepper_path.path().IsAbsolute() &&
ChildProcessSecurityPolicyImpl::GetInstance()->HasPermissionsForFile(
child_id(), pepper_path.path(), flags))
file_path = pepper_path.path();
}
return file_path;
}

PepperTrustedFileMessageFilter::PepperTrustedFileMessageFilter(
int child_id,
const std::string& plugin_name,
const FilePath& profile_data_directory)
: PepperFileMessageFilter(child_id) {
plugin_data_directory_ =
GetDataDirName(profile_data_directory).Append(plugin_name);
}

PepperTrustedFileMessageFilter::~PepperTrustedFileMessageFilter() {
}

FilePath PepperTrustedFileMessageFilter::ValidateAndConvertPepperFilePath(
const ppapi::PepperFilePath& pepper_path,
int flags) {
const webkit::ppapi::PepperFilePath& pepper_path, int flags) {
FilePath file_path; // Empty path returned on error.
switch(pepper_path.domain()) {
case ppapi::PepperFilePath::DOMAIN_ABSOLUTE:
case webkit::ppapi::PepperFilePath::DOMAIN_ABSOLUTE:
if (pepper_path.path().IsAbsolute() &&
ChildProcessSecurityPolicyImpl::GetInstance()->HasPermissionsForFile(
child_id(), pepper_path.path(), flags))
file_path = pepper_path.path();
break;
case ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL:
case webkit::ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL:
if (!pepper_path.path().IsAbsolute() &&
!pepper_path.path().ReferencesParent())
file_path = plugin_data_directory_.Append(pepper_path.path());
file_path = pepper_path_.Append(pepper_path.path());
break;
default:
NOTREACHED();
Expand Down
50 changes: 18 additions & 32 deletions content/browser/renderer_host/pepper_file_message_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,23 @@
#include "build/build_config.h"
#include "content/public/browser/browser_message_filter.h"
#include "ipc/ipc_platform_file.h"
#include "ppapi/shared_impl/dir_contents.h"
#include "webkit/plugins/ppapi/dir_contents.h"

namespace content {
class BrowserContext;
}

namespace webkit {
namespace ppapi {
class PepperFilePath;
}
}

// A message filter for Pepper-specific File I/O messages.
class PepperFileMessageFilter : public content::BrowserMessageFilter {
public:
explicit PepperFileMessageFilter(int child_id);
PepperFileMessageFilter(int child_id,
content::BrowserContext* browser_context);

// content::BrowserMessageFilter methods:
virtual void OverrideThreadForMessage(
Expand All @@ -54,29 +57,29 @@ class PepperFileMessageFilter : public content::BrowserMessageFilter {
friend class base::DeleteHelper<PepperFileMessageFilter>;

// Called on the FILE thread:
void OnOpenFile(const ppapi::PepperFilePath& path,
void OnOpenFile(const webkit::ppapi::PepperFilePath& path,
int flags,
base::PlatformFileError* error,
IPC::PlatformFileForTransit* file);
void OnRenameFile(const ppapi::PepperFilePath& from_path,
const ppapi::PepperFilePath& to_path,
void OnRenameFile(const webkit::ppapi::PepperFilePath& from_path,
const webkit::ppapi::PepperFilePath& to_path,
base::PlatformFileError* error);
void OnDeleteFileOrDir(const ppapi::PepperFilePath& path,
void OnDeleteFileOrDir(const webkit::ppapi::PepperFilePath& path,
bool recursive,
base::PlatformFileError* error);
void OnCreateDir(const ppapi::PepperFilePath& path,
void OnCreateDir(const webkit::ppapi::PepperFilePath& path,
base::PlatformFileError* error);
void OnQueryFile(const ppapi::PepperFilePath& path,
void OnQueryFile(const webkit::ppapi::PepperFilePath& path,
base::PlatformFileInfo* info,
base::PlatformFileError* error);
void OnGetDirContents(const ppapi::PepperFilePath& path,
ppapi::DirContents* contents,
void OnGetDirContents(const webkit::ppapi::PepperFilePath& path,
webkit::ppapi::DirContents* contents,
base::PlatformFileError* error);

// Validate and convert the Pepper file path to a "real" |FilePath|. Returns
// an empty |FilePath| on error.
virtual FilePath ValidateAndConvertPepperFilePath(
const ppapi::PepperFilePath& pepper_path, int flags);
FilePath ValidateAndConvertPepperFilePath(
const webkit::ppapi::PepperFilePath& pepper_path, int flags);

// The ID of the child process.
const int child_id_;
Expand All @@ -85,27 +88,10 @@ class PepperFileMessageFilter : public content::BrowserMessageFilter {
// owned by this class.
IPC::Channel* channel_;

DISALLOW_COPY_AND_ASSIGN(PepperFileMessageFilter);
};

// Class for out-of-process plugins providing relaxed path validation.
class PepperTrustedFileMessageFilter : public PepperFileMessageFilter {
public:
PepperTrustedFileMessageFilter(int child_id,
const std::string& plugin_name,
const FilePath& profile_data_directory);
// The base path for the pepper data.
FilePath pepper_path_;

protected:
virtual ~PepperTrustedFileMessageFilter();

private:
virtual FilePath ValidateAndConvertPepperFilePath(
const ppapi::PepperFilePath& pepper_path, int flags) OVERRIDE;

// The path to the per-plugin directory under the per-profile data directory.
FilePath plugin_data_directory_;

DISALLOW_COPY_AND_ASSIGN(PepperTrustedFileMessageFilter);
DISALLOW_COPY_AND_ASSIGN(PepperFileMessageFilter);
};

#endif // CONTENT_BROWSER_RENDERER_HOST_PEPPER_FILE_MESSAGE_FILTER_H_
2 changes: 1 addition & 1 deletion content/browser/renderer_host/render_process_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ void RenderProcessHostImpl::CreateMessageFilters() {
channel_->AddFilter(new media_stream::MediaStreamDispatcherHost(
resource_context, GetID(), BrowserMainLoop::GetAudioManager()));
#endif
channel_->AddFilter(new PepperFileMessageFilter(GetID()));
channel_->AddFilter(new PepperFileMessageFilter(GetID(), browser_context));
channel_->AddFilter(new PepperMessageFilter(PepperMessageFilter::RENDERER,
GetID(), browser_context));
#if defined(ENABLE_INPUT_SPEECH)
Expand Down
1 change: 1 addition & 0 deletions content/common/content_message_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "content/common/media/video_capture_messages.h"
#include "content/common/mime_registry_messages.h"
#include "content/common/p2p_messages.h"
#include "content/common/pepper_file_messages.h"
#include "content/common/pepper_messages.h"
#include "content/common/plugin_messages.h"
#include "content/common/quota_messages.h"
Expand Down
39 changes: 39 additions & 0 deletions content/common/pepper_file_messages.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/common/pepper_file_messages.h"

namespace IPC {

void ParamTraits<webkit::ppapi::PepperFilePath>::Write(Message* m,
const param_type& p) {
WriteParam(m, static_cast<unsigned>(p.domain()));
WriteParam(m, p.path());
}

bool ParamTraits<webkit::ppapi::PepperFilePath>::Read(const Message* m,
PickleIterator* iter,
param_type* p) {
unsigned domain;
FilePath path;
if (!ReadParam(m, iter, &domain) || !ReadParam(m, iter, &path))
return false;
if (domain > webkit::ppapi::PepperFilePath::DOMAIN_MAX_VALID)
return false;

*p = webkit::ppapi::PepperFilePath(
static_cast<webkit::ppapi::PepperFilePath::Domain>(domain), path);
return true;
}

void ParamTraits<webkit::ppapi::PepperFilePath>::Log(const param_type& p,
std::string* l) {
l->append("(");
LogParam(static_cast<unsigned>(p.domain()), l);
l->append(", ");
LogParam(p.path(), l);
l->append(")");
}

} // namespace IPC
Loading

0 comments on commit 042ba85

Please sign in to comment.