diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-26 00:16:05 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-02-26 00:16:05 +0000 |
commit | 494184c1d68dfbdaa51af78f680e59dd0bfc6143 (patch) | |
tree | f897b02dc34dbc4e860c9dad561311d1a9e16e34 /content | |
parent | 287b86bfa8405f38377eb4b6c33c28b8a926fb2a (diff) | |
download | chromium_src-494184c1d68dfbdaa51af78f680e59dd0bfc6143.zip chromium_src-494184c1d68dfbdaa51af78f680e59dd0bfc6143.tar.gz chromium_src-494184c1d68dfbdaa51af78f680e59dd0bfc6143.tar.bz2 |
Pepper/Flapper: Refactor module-local file stuff to make it easier/nicer to add file ref versions.
BUG=none
TEST=everything still works
Review URL: http://codereview.chromium.org/6599015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76124 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r-- | content/browser/renderer_host/pepper_file_message_filter.cc | 96 | ||||
-rw-r--r-- | content/browser/renderer_host/pepper_file_message_filter.h | 42 |
2 files changed, 79 insertions, 59 deletions
diff --git a/content/browser/renderer_host/pepper_file_message_filter.cc b/content/browser/renderer_host/pepper_file_message_filter.cc index 9f7f9d9..4d81dc5 100644 --- a/content/browser/renderer_host/pepper_file_message_filter.cc +++ b/content/browser/renderer_host/pepper_file_message_filter.cc @@ -1,12 +1,12 @@ -// Copyright (c) 2010 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. #include "content/browser/renderer_host/pepper_file_message_filter.h" #include "base/callback.h" -#include "base/file_util.h" #include "base/file_path.h" +#include "base/file_util.h" #include "base/process_util.h" #include "chrome/browser/browser_thread.h" #include "chrome/browser/profiles/profile.h" @@ -14,11 +14,35 @@ #include "chrome/common/child_process_host.h" #include "chrome/common/pepper_file_messages.h" #include "ipc/ipc_platform_file.h" +#include "webkit/plugins/ppapi/file_path.h" #if defined(OS_POSIX) #include "base/file_descriptor_posix.h" #endif +namespace { + +FilePath ConvertPepperFilePath( + const webkit::ppapi::PepperFilePath& pepper_path) { + FilePath file_path; + switch(pepper_path.domain()) { + case webkit::ppapi::PepperFilePath::DOMAIN_ABSOLUTE: + NOTIMPLEMENTED(); + break; + case webkit::ppapi::PepperFilePath::DOMAIN_MODULE_LOCAL: + if (!pepper_path.path().IsAbsolute() && + !pepper_path.path().ReferencesParent()) + file_path = pepper_path.path(); + break; + default: + NOTREACHED(); + break; + } + return file_path; +} + +} // namespace + PepperFileMessageFilter::PepperFileMessageFilter( int child_id, Profile* profile) { pepper_path_ = profile->GetPath().Append(FILE_PATH_LITERAL("Pepper Data")); @@ -36,17 +60,16 @@ void PepperFileMessageFilter::OverrideThreadForMessage( *thread = BrowserThread::FILE; } -bool PepperFileMessageFilter::OnMessageReceived( - const IPC::Message& message, - bool* message_was_ok) { +bool PepperFileMessageFilter::OnMessageReceived(const IPC::Message& message, + bool* message_was_ok) { bool handled = true; IPC_BEGIN_MESSAGE_MAP_EX(PepperFileMessageFilter, message, *message_was_ok) - IPC_MESSAGE_HANDLER(PepperFileMsg_OpenFile, OnPepperOpenFile) - IPC_MESSAGE_HANDLER(PepperFileMsg_RenameFile, OnPepperRenameFile) - IPC_MESSAGE_HANDLER(PepperFileMsg_DeleteFileOrDir, OnPepperDeleteFileOrDir) - IPC_MESSAGE_HANDLER(PepperFileMsg_CreateDir, OnPepperCreateDir) - IPC_MESSAGE_HANDLER(PepperFileMsg_QueryFile, OnPepperQueryFile) - IPC_MESSAGE_HANDLER(PepperFileMsg_GetDirContents, OnPepperGetDirContents) + IPC_MESSAGE_HANDLER(PepperFileMsg_OpenFile, OnOpenFile) + IPC_MESSAGE_HANDLER(PepperFileMsg_RenameFile, OnRenameFile) + IPC_MESSAGE_HANDLER(PepperFileMsg_DeleteFileOrDir, OnDeleteFileOrDir) + IPC_MESSAGE_HANDLER(PepperFileMsg_CreateDir, OnCreateDir) + IPC_MESSAGE_HANDLER(PepperFileMsg_QueryFile, OnQueryFile) + IPC_MESSAGE_HANDLER(PepperFileMsg_GetDirContents, OnGetDirContents) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP_EX() return handled; @@ -57,12 +80,12 @@ void PepperFileMessageFilter::OnDestruct() const { } // Called on the FILE thread: -void PepperFileMessageFilter::OnPepperOpenFile( - const FilePath& path, +void PepperFileMessageFilter::OnOpenFile( + const webkit::ppapi::PepperFilePath& path, int flags, base::PlatformFileError* error, IPC::PlatformFileForTransit* file) { - FilePath full_path = MakePepperPath(path); + FilePath full_path = ConvertPepperFilePath(path); if (full_path.empty()) { *error = base::PLATFORM_FILE_ERROR_ACCESS_DENIED; *file = IPC::InvalidPlatformFileForTransit(); @@ -101,27 +124,27 @@ void PepperFileMessageFilter::OnPepperOpenFile( #endif } -void PepperFileMessageFilter::OnPepperRenameFile( - const FilePath& path_from, - const FilePath& path_to, +void PepperFileMessageFilter::OnRenameFile( + const webkit::ppapi::PepperFilePath& from_path, + const webkit::ppapi::PepperFilePath& to_path, base::PlatformFileError* error) { - FilePath full_path_from = MakePepperPath(path_from); - FilePath full_path_to = MakePepperPath(path_to); - if (full_path_from.empty() || full_path_to.empty()) { + FilePath from_full_path = ConvertPepperFilePath(from_path); + FilePath to_full_path = ConvertPepperFilePath(to_path); + if (from_full_path.empty() || to_full_path.empty()) { *error = base::PLATFORM_FILE_ERROR_ACCESS_DENIED; return; } - bool result = file_util::Move(full_path_from, full_path_to); + bool result = file_util::Move(from_full_path, to_full_path); *error = result ? base::PLATFORM_FILE_OK : base::PLATFORM_FILE_ERROR_ACCESS_DENIED; } -void PepperFileMessageFilter::OnPepperDeleteFileOrDir( - const FilePath& path, +void PepperFileMessageFilter::OnDeleteFileOrDir( + const webkit::ppapi::PepperFilePath& path, bool recursive, base::PlatformFileError* error) { - FilePath full_path = MakePepperPath(path); + FilePath full_path = ConvertPepperFilePath(path); if (full_path.empty()) { *error = base::PLATFORM_FILE_ERROR_ACCESS_DENIED; return; @@ -132,10 +155,10 @@ void PepperFileMessageFilter::OnPepperDeleteFileOrDir( : base::PLATFORM_FILE_ERROR_ACCESS_DENIED; } -void PepperFileMessageFilter::OnPepperCreateDir( - const FilePath& path, +void PepperFileMessageFilter::OnCreateDir( + const webkit::ppapi::PepperFilePath& path, base::PlatformFileError* error) { - FilePath full_path = MakePepperPath(path); + FilePath full_path = ConvertPepperFilePath(path); if (full_path.empty()) { *error = base::PLATFORM_FILE_ERROR_ACCESS_DENIED; return; @@ -146,11 +169,11 @@ void PepperFileMessageFilter::OnPepperCreateDir( : base::PLATFORM_FILE_ERROR_ACCESS_DENIED; } -void PepperFileMessageFilter::OnPepperQueryFile( - const FilePath& path, +void PepperFileMessageFilter::OnQueryFile( + const webkit::ppapi::PepperFilePath& path, base::PlatformFileInfo* info, base::PlatformFileError* error) { - FilePath full_path = MakePepperPath(path); + FilePath full_path = ConvertPepperFilePath(path); if (full_path.empty()) { *error = base::PLATFORM_FILE_ERROR_ACCESS_DENIED; return; @@ -161,11 +184,11 @@ void PepperFileMessageFilter::OnPepperQueryFile( : base::PLATFORM_FILE_ERROR_ACCESS_DENIED; } -void PepperFileMessageFilter::OnPepperGetDirContents( - const FilePath& path, +void PepperFileMessageFilter::OnGetDirContents( + const webkit::ppapi::PepperFilePath& path, webkit::ppapi::DirContents* contents, base::PlatformFileError* error) { - FilePath full_path = MakePepperPath(path); + FilePath full_path = ConvertPepperFilePath(path); if (full_path.empty()) { *error = base::PLATFORM_FILE_ERROR_ACCESS_DENIED; return; @@ -192,10 +215,3 @@ void PepperFileMessageFilter::OnPepperGetDirContents( *error = base::PLATFORM_FILE_OK; } - -FilePath PepperFileMessageFilter::MakePepperPath(const FilePath& base_path) { - if (base_path.IsAbsolute() || base_path.ReferencesParent()) { - return FilePath(); - } - return pepper_path_.Append(base_path); -} diff --git a/content/browser/renderer_host/pepper_file_message_filter.h b/content/browser/renderer_host/pepper_file_message_filter.h index a06d9a4..24bb1f1 100644 --- a/content/browser/renderer_host/pepper_file_message_filter.h +++ b/content/browser/renderer_host/pepper_file_message_filter.h @@ -20,6 +20,12 @@ class Profile; +namespace webkit { +namespace ppapi { +class PepperFilePath; +} +} + // A message filter for Pepper-specific File I/O messages. class PepperFileMessageFilter : public BrowserMessageFilter { public: @@ -38,26 +44,24 @@ class PepperFileMessageFilter : public BrowserMessageFilter { virtual ~PepperFileMessageFilter(); // Called on the FILE thread: - void OnPepperOpenFile(const FilePath& path, - int flags, - base::PlatformFileError* error, - IPC::PlatformFileForTransit* file); - void OnPepperRenameFile(const FilePath& path_from, - const FilePath& path_to, - base::PlatformFileError* error); - void OnPepperDeleteFileOrDir(const FilePath& path, - bool recursive, - base::PlatformFileError* error); - void OnPepperCreateDir(const FilePath& path, - base::PlatformFileError* error); - void OnPepperQueryFile(const FilePath& path, - base::PlatformFileInfo* info, + void OnOpenFile(const webkit::ppapi::PepperFilePath& path, + int flags, + base::PlatformFileError* error, + IPC::PlatformFileForTransit* file); + void OnRenameFile(const webkit::ppapi::PepperFilePath& from_path, + const webkit::ppapi::PepperFilePath& to_path, + base::PlatformFileError* error); + void OnDeleteFileOrDir(const webkit::ppapi::PepperFilePath& path, + bool recursive, base::PlatformFileError* error); - void OnPepperGetDirContents(const FilePath& path, - webkit::ppapi::DirContents* contents, - base::PlatformFileError* error); - - FilePath MakePepperPath(const FilePath& base_path); + void OnCreateDir(const webkit::ppapi::PepperFilePath& path, + base::PlatformFileError* error); + void OnQueryFile(const webkit::ppapi::PepperFilePath& path, + base::PlatformFileInfo* info, + base::PlatformFileError* error); + void OnGetDirContents(const webkit::ppapi::PepperFilePath& path, + webkit::ppapi::DirContents* contents, + base::PlatformFileError* error); // The channel associated with the renderer connection. This pointer is not // owned by this class. |