| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/pepper/pepper_plugin_delegate_impl.h" | 5 #include "content/renderer/pepper/pepper_plugin_delegate_impl.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <cstddef> | 8 #include <cstddef> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <queue> | 10 #include <queue> |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 #include "ppapi/thunk/ppb_tcp_server_socket_private_api.h" | 83 #include "ppapi/thunk/ppb_tcp_server_socket_private_api.h" |
| 84 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | 84 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
| 85 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 85 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 86 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 86 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 87 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 87 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 88 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 88 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 89 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 89 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
| 90 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" | 90 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" |
| 91 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 91 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 92 #include "ui/gfx/size.h" | 92 #include "ui/gfx/size.h" |
| 93 #include "webkit/fileapi/file_system_callback_dispatcher.h" | |
| 94 #include "webkit/plugins/npapi/webplugin.h" | 93 #include "webkit/plugins/npapi/webplugin.h" |
| 95 #include "webkit/plugins/ppapi/plugin_module.h" | 94 #include "webkit/plugins/ppapi/plugin_module.h" |
| 96 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 95 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 97 #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h" | 96 #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h" |
| 98 #include "webkit/plugins/ppapi/ppb_tcp_server_socket_private_impl.h" | 97 #include "webkit/plugins/ppapi/ppb_tcp_server_socket_private_impl.h" |
| 99 #include "webkit/plugins/ppapi/ppb_tcp_socket_private_impl.h" | 98 #include "webkit/plugins/ppapi/ppb_tcp_socket_private_impl.h" |
| 100 #include "webkit/plugins/ppapi/resource_helper.h" | 99 #include "webkit/plugins/ppapi/resource_helper.h" |
| 101 #include "webkit/plugins/ppapi/url_response_info_util.h" | 100 #include "webkit/plugins/ppapi/url_response_info_util.h" |
| 102 #include "webkit/plugins/webplugininfo.h" | 101 #include "webkit/plugins/webplugininfo.h" |
| 103 | 102 |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 | 260 |
| 262 private: | 261 private: |
| 263 webkit::ppapi::PluginInstance* plugin_; | 262 webkit::ppapi::PluginInstance* plugin_; |
| 264 }; | 263 }; |
| 265 | 264 |
| 266 void DoNotifyCloseFile(int file_open_id, base::PlatformFileError /* unused */) { | 265 void DoNotifyCloseFile(int file_open_id, base::PlatformFileError /* unused */) { |
| 267 ChildThread::current()->file_system_dispatcher()->NotifyCloseFile( | 266 ChildThread::current()->file_system_dispatcher()->NotifyCloseFile( |
| 268 file_open_id); | 267 file_open_id); |
| 269 } | 268 } |
| 270 | 269 |
| 271 class AsyncOpenFileSystemURLCallbackTranslator | 270 void DidOpenFileSystemURL( |
| 272 : public fileapi::FileSystemCallbackDispatcher { | 271 const webkit::ppapi::PluginDelegate::AsyncOpenFileSystemURLCallback& |
| 273 public: | 272 callback, |
| 274 AsyncOpenFileSystemURLCallbackTranslator( | 273 base::PlatformFile file, |
| 275 const webkit::ppapi::PluginDelegate::AsyncOpenFileSystemURLCallback& | 274 int file_open_id, |
| 276 callback) | 275 quota::QuotaLimitType quota_policy) { |
| 277 : callback_(callback) { | 276 callback.Run(base::PLATFORM_FILE_OK, |
| 277 base::PassPlatformFile(&file), |
| 278 quota_policy, |
| 279 base::Bind(&DoNotifyCloseFile, file_open_id)); |
| 280 // Make sure we won't leak file handle if the requester has died. |
| 281 if (file != base::kInvalidPlatformFileValue) { |
| 282 base::FileUtilProxy::Close( |
| 283 RenderThreadImpl::current()->GetFileThreadMessageLoopProxy(), file, |
| 284 base::Bind(&DoNotifyCloseFile, file_open_id)); |
| 278 } | 285 } |
| 286 } |
| 279 | 287 |
| 280 virtual ~AsyncOpenFileSystemURLCallbackTranslator() {} | 288 void DidFailOpenFileSystemURL( |
| 281 | 289 const webkit::ppapi::PluginDelegate::AsyncOpenFileSystemURLCallback& |
| 282 virtual void DidSucceed() OVERRIDE { | 290 callback, |
| 283 NOTREACHED(); | 291 base::PlatformFileError error_code) { |
| 284 } | 292 base::PlatformFile invalid_file = base::kInvalidPlatformFileValue; |
| 285 virtual void DidReadMetadata( | 293 callback.Run(error_code, |
| 286 const base::PlatformFileInfo& file_info, | 294 base::PassPlatformFile(&invalid_file), |
| 287 const base::FilePath& platform_path) OVERRIDE { | 295 quota::kQuotaLimitTypeUnknown, |
| 288 NOTREACHED(); | 296 webkit::ppapi::PluginDelegate::NotifyCloseFileCallback()); |
| 289 } | 297 } |
| 290 virtual void DidCreateSnapshotFile( | |
| 291 const base::PlatformFileInfo& file_info, | |
| 292 const base::FilePath& platform_path) OVERRIDE { | |
| 293 NOTREACHED(); | |
| 294 } | |
| 295 virtual void DidReadDirectory( | |
| 296 const std::vector<base::FileUtilProxy::Entry>& entries, | |
| 297 bool has_more) OVERRIDE { | |
| 298 NOTREACHED(); | |
| 299 } | |
| 300 virtual void DidOpenFileSystem(const std::string& name, | |
| 301 const GURL& root) OVERRIDE { | |
| 302 NOTREACHED(); | |
| 303 } | |
| 304 | |
| 305 virtual void DidFail(base::PlatformFileError error_code) OVERRIDE { | |
| 306 base::PlatformFile invalid_file = base::kInvalidPlatformFileValue; | |
| 307 callback_.Run(error_code, | |
| 308 base::PassPlatformFile(&invalid_file), | |
| 309 quota::kQuotaLimitTypeUnknown, | |
| 310 webkit::ppapi::PluginDelegate::NotifyCloseFileCallback()); | |
| 311 } | |
| 312 | |
| 313 virtual void DidWrite(int64 bytes, bool complete) OVERRIDE { | |
| 314 NOTREACHED(); | |
| 315 } | |
| 316 | |
| 317 virtual void DidOpenFile(base::PlatformFile file, | |
| 318 int file_open_id, | |
| 319 quota::QuotaLimitType quota_policy) OVERRIDE { | |
| 320 callback_.Run(base::PLATFORM_FILE_OK, | |
| 321 base::PassPlatformFile(&file), | |
| 322 quota_policy, | |
| 323 base::Bind(&DoNotifyCloseFile, file_open_id)); | |
| 324 // Make sure we won't leak file handle if the requester has died. | |
| 325 if (file != base::kInvalidPlatformFileValue) { | |
| 326 base::FileUtilProxy::Close( | |
| 327 RenderThreadImpl::current()->GetFileThreadMessageLoopProxy(), file, | |
| 328 base::Bind(&DoNotifyCloseFile, file_open_id)); | |
| 329 } | |
| 330 } | |
| 331 | |
| 332 private: | |
| 333 webkit::ppapi::PluginDelegate::AsyncOpenFileSystemURLCallback callback_; | |
| 334 }; | |
| 335 | 298 |
| 336 void CreateHostForInProcessModule(RenderViewImpl* render_view, | 299 void CreateHostForInProcessModule(RenderViewImpl* render_view, |
| 337 webkit::ppapi::PluginModule* module, | 300 webkit::ppapi::PluginModule* module, |
| 338 const webkit::WebPluginInfo& webplugin_info) { | 301 const webkit::WebPluginInfo& webplugin_info) { |
| 339 // First time an in-process plugin was used, make a host for it. | 302 // First time an in-process plugin was used, make a host for it. |
| 340 const PepperPluginInfo* info = | 303 const PepperPluginInfo* info = |
| 341 PepperPluginRegistry::GetInstance()->GetInfoForPlugin(webplugin_info); | 304 PepperPluginRegistry::GetInstance()->GetInfoForPlugin(webplugin_info); |
| 342 DCHECK(!info->is_out_of_process); | 305 DCHECK(!info->is_out_of_process); |
| 343 | 306 |
| 344 ppapi::PpapiPermissions perms( | 307 ppapi::PpapiPermissions perms( |
| (...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1053 GURL PepperPluginDelegateImpl::GetFileSystemRootUrl( | 1016 GURL PepperPluginDelegateImpl::GetFileSystemRootUrl( |
| 1054 PP_Instance instance, PP_Resource resource) const { | 1017 PP_Instance instance, PP_Resource resource) const { |
| 1055 const PepperFileSystemHost* host = | 1018 const PepperFileSystemHost* host = |
| 1056 GetRendererResourceHost<PepperFileSystemHost>(instance, resource); | 1019 GetRendererResourceHost<PepperFileSystemHost>(instance, resource); |
| 1057 return host ? host->GetRootUrl() : GURL(); | 1020 return host ? host->GetRootUrl() : GURL(); |
| 1058 } | 1021 } |
| 1059 | 1022 |
| 1060 bool PepperPluginDelegateImpl::MakeDirectory( | 1023 bool PepperPluginDelegateImpl::MakeDirectory( |
| 1061 const GURL& path, | 1024 const GURL& path, |
| 1062 bool recursive, | 1025 bool recursive, |
| 1063 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 1026 const StatusCallback& callback) { |
| 1064 FileSystemDispatcher* file_system_dispatcher = | 1027 FileSystemDispatcher* file_system_dispatcher = |
| 1065 ChildThread::current()->file_system_dispatcher(); | 1028 ChildThread::current()->file_system_dispatcher(); |
| 1066 return file_system_dispatcher->Create( | 1029 return file_system_dispatcher->Create( |
| 1067 path, false, true, recursive, dispatcher); | 1030 path, false, true, recursive, callback); |
| 1068 } | 1031 } |
| 1069 | 1032 |
| 1070 bool PepperPluginDelegateImpl::Query( | 1033 bool PepperPluginDelegateImpl::Query( |
| 1071 const GURL& path, | 1034 const GURL& path, |
| 1072 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 1035 const MetadataCallback& success_callback, |
| 1036 const StatusCallback& error_callback) { |
| 1073 FileSystemDispatcher* file_system_dispatcher = | 1037 FileSystemDispatcher* file_system_dispatcher = |
| 1074 ChildThread::current()->file_system_dispatcher(); | 1038 ChildThread::current()->file_system_dispatcher(); |
| 1075 return file_system_dispatcher->ReadMetadata(path, dispatcher); | 1039 return file_system_dispatcher->ReadMetadata( |
| 1040 path, success_callback, error_callback); |
| 1076 } | 1041 } |
| 1077 | 1042 |
| 1078 bool PepperPluginDelegateImpl::ReadDirectoryEntries( | 1043 bool PepperPluginDelegateImpl::ReadDirectoryEntries( |
| 1079 const GURL& path, | 1044 const GURL& path, |
| 1080 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 1045 const ReadDirectoryCallback& success_callback, |
| 1046 const StatusCallback& error_callback) { |
| 1081 FileSystemDispatcher* file_system_dispatcher = | 1047 FileSystemDispatcher* file_system_dispatcher = |
| 1082 ChildThread::current()->file_system_dispatcher(); | 1048 ChildThread::current()->file_system_dispatcher(); |
| 1083 return file_system_dispatcher->ReadDirectory(path, dispatcher); | 1049 return file_system_dispatcher->ReadDirectory( |
| 1050 path, success_callback, error_callback); |
| 1084 } | 1051 } |
| 1085 | 1052 |
| 1086 bool PepperPluginDelegateImpl::Touch( | 1053 bool PepperPluginDelegateImpl::Touch( |
| 1087 const GURL& path, | 1054 const GURL& path, |
| 1088 const base::Time& last_access_time, | 1055 const base::Time& last_access_time, |
| 1089 const base::Time& last_modified_time, | 1056 const base::Time& last_modified_time, |
| 1090 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 1057 const StatusCallback& callback) { |
| 1091 FileSystemDispatcher* file_system_dispatcher = | 1058 FileSystemDispatcher* file_system_dispatcher = |
| 1092 ChildThread::current()->file_system_dispatcher(); | 1059 ChildThread::current()->file_system_dispatcher(); |
| 1093 return file_system_dispatcher->TouchFile(path, last_access_time, | 1060 return file_system_dispatcher->TouchFile(path, last_access_time, |
| 1094 last_modified_time, dispatcher); | 1061 last_modified_time, callback); |
| 1095 } | 1062 } |
| 1096 | 1063 |
| 1097 bool PepperPluginDelegateImpl::SetLength( | 1064 bool PepperPluginDelegateImpl::SetLength( |
| 1098 const GURL& path, | 1065 const GURL& path, |
| 1099 int64_t length, | 1066 int64_t length, |
| 1100 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 1067 const StatusCallback& callback) { |
| 1101 FileSystemDispatcher* file_system_dispatcher = | 1068 FileSystemDispatcher* file_system_dispatcher = |
| 1102 ChildThread::current()->file_system_dispatcher(); | 1069 ChildThread::current()->file_system_dispatcher(); |
| 1103 return file_system_dispatcher->Truncate(path, length, NULL, dispatcher); | 1070 return file_system_dispatcher->Truncate(path, length, NULL, callback); |
| 1104 } | 1071 } |
| 1105 | 1072 |
| 1106 bool PepperPluginDelegateImpl::Delete( | 1073 bool PepperPluginDelegateImpl::Delete( |
| 1107 const GURL& path, | 1074 const GURL& path, |
| 1108 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 1075 const StatusCallback& callback) { |
| 1109 FileSystemDispatcher* file_system_dispatcher = | 1076 FileSystemDispatcher* file_system_dispatcher = |
| 1110 ChildThread::current()->file_system_dispatcher(); | 1077 ChildThread::current()->file_system_dispatcher(); |
| 1111 return file_system_dispatcher->Remove(path, false /* recursive */, | 1078 return file_system_dispatcher->Remove(path, false /* recursive */, callback); |
| 1112 dispatcher); | |
| 1113 } | 1079 } |
| 1114 | 1080 |
| 1115 bool PepperPluginDelegateImpl::Rename( | 1081 bool PepperPluginDelegateImpl::Rename( |
| 1116 const GURL& file_path, | 1082 const GURL& file_path, |
| 1117 const GURL& new_file_path, | 1083 const GURL& new_file_path, |
| 1118 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 1084 const StatusCallback& callback) { |
| 1119 FileSystemDispatcher* file_system_dispatcher = | 1085 FileSystemDispatcher* file_system_dispatcher = |
| 1120 ChildThread::current()->file_system_dispatcher(); | 1086 ChildThread::current()->file_system_dispatcher(); |
| 1121 return file_system_dispatcher->Move(file_path, new_file_path, dispatcher); | 1087 return file_system_dispatcher->Move(file_path, new_file_path, callback); |
| 1122 } | 1088 } |
| 1123 | 1089 |
| 1124 bool PepperPluginDelegateImpl::ReadDirectory( | 1090 bool PepperPluginDelegateImpl::ReadDirectory( |
| 1125 const GURL& directory_path, | 1091 const GURL& directory_path, |
| 1126 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 1092 const ReadDirectoryCallback& success_callback, |
| 1093 const StatusCallback& error_callback) { |
| 1127 FileSystemDispatcher* file_system_dispatcher = | 1094 FileSystemDispatcher* file_system_dispatcher = |
| 1128 ChildThread::current()->file_system_dispatcher(); | 1095 ChildThread::current()->file_system_dispatcher(); |
| 1129 return file_system_dispatcher->ReadDirectory(directory_path, dispatcher); | 1096 return file_system_dispatcher->ReadDirectory( |
| 1097 directory_path, success_callback, error_callback); |
| 1130 } | 1098 } |
| 1131 | 1099 |
| 1132 void PepperPluginDelegateImpl::QueryAvailableSpace( | 1100 void PepperPluginDelegateImpl::QueryAvailableSpace( |
| 1133 const GURL& origin, quota::StorageType type, | 1101 const GURL& origin, quota::StorageType type, |
| 1134 const AvailableSpaceCallback& callback) { | 1102 const AvailableSpaceCallback& callback) { |
| 1135 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota( | 1103 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota( |
| 1136 origin, type, new QuotaCallbackTranslator(callback)); | 1104 origin, type, new QuotaCallbackTranslator(callback)); |
| 1137 } | 1105 } |
| 1138 | 1106 |
| 1139 void PepperPluginDelegateImpl::WillUpdateFile(const GURL& path) { | 1107 void PepperPluginDelegateImpl::WillUpdateFile(const GURL& path) { |
| 1140 ChildThread::current()->Send(new FileSystemHostMsg_WillUpdate(path)); | 1108 ChildThread::current()->Send(new FileSystemHostMsg_WillUpdate(path)); |
| 1141 } | 1109 } |
| 1142 | 1110 |
| 1143 void PepperPluginDelegateImpl::DidUpdateFile(const GURL& path, int64_t delta) { | 1111 void PepperPluginDelegateImpl::DidUpdateFile(const GURL& path, int64_t delta) { |
| 1144 ChildThread::current()->Send(new FileSystemHostMsg_DidUpdate(path, delta)); | 1112 ChildThread::current()->Send(new FileSystemHostMsg_DidUpdate(path, delta)); |
| 1145 } | 1113 } |
| 1146 | 1114 |
| 1147 bool PepperPluginDelegateImpl::AsyncOpenFileSystemURL( | 1115 bool PepperPluginDelegateImpl::AsyncOpenFileSystemURL( |
| 1148 const GURL& path, | 1116 const GURL& path, |
| 1149 int flags, | 1117 int flags, |
| 1150 const AsyncOpenFileSystemURLCallback& callback) { | 1118 const AsyncOpenFileSystemURLCallback& callback) { |
| 1151 | 1119 |
| 1152 FileSystemDispatcher* file_system_dispatcher = | 1120 FileSystemDispatcher* file_system_dispatcher = |
| 1153 ChildThread::current()->file_system_dispatcher(); | 1121 ChildThread::current()->file_system_dispatcher(); |
| 1154 return file_system_dispatcher->OpenFile(path, flags, | 1122 return file_system_dispatcher->OpenFile( |
| 1155 new AsyncOpenFileSystemURLCallbackTranslator( | 1123 path, flags, |
| 1156 callback)); | 1124 base::Bind(&DidOpenFileSystemURL, callback), |
| 1125 base::Bind(&DidFailOpenFileSystemURL, callback)); |
| 1157 } | 1126 } |
| 1158 | 1127 |
| 1159 void PepperPluginDelegateImpl::SyncGetFileSystemPlatformPath( | 1128 void PepperPluginDelegateImpl::SyncGetFileSystemPlatformPath( |
| 1160 const GURL& url, base::FilePath* platform_path) { | 1129 const GURL& url, base::FilePath* platform_path) { |
| 1161 RenderThreadImpl::current()->Send(new FileSystemHostMsg_SyncGetPlatformPath( | 1130 RenderThreadImpl::current()->Send(new FileSystemHostMsg_SyncGetPlatformPath( |
| 1162 url, platform_path)); | 1131 url, platform_path)); |
| 1163 } | 1132 } |
| 1164 | 1133 |
| 1165 scoped_refptr<base::MessageLoopProxy> | 1134 scoped_refptr<base::MessageLoopProxy> |
| 1166 PepperPluginDelegateImpl::GetFileThreadMessageLoopProxy() { | 1135 PepperPluginDelegateImpl::GetFileThreadMessageLoopProxy() { |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1716 should_close_source); | 1685 should_close_source); |
| 1717 } | 1686 } |
| 1718 | 1687 |
| 1719 bool PepperPluginDelegateImpl::IsRunningInProcess(PP_Instance instance) const { | 1688 bool PepperPluginDelegateImpl::IsRunningInProcess(PP_Instance instance) const { |
| 1720 RendererPpapiHostImpl* host = | 1689 RendererPpapiHostImpl* host = |
| 1721 RendererPpapiHostImpl::GetForPPInstance(instance); | 1690 RendererPpapiHostImpl::GetForPPInstance(instance); |
| 1722 return host && host->IsRunningInProcess(); | 1691 return host && host->IsRunningInProcess(); |
| 1723 } | 1692 } |
| 1724 | 1693 |
| 1725 } // namespace content | 1694 } // namespace content |
| OLD | NEW |