| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 #include "ppapi/thunk/ppb_tcp_server_socket_private_api.h" | 76 #include "ppapi/thunk/ppb_tcp_server_socket_private_api.h" |
| 77 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | 77 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
| 78 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 78 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| 79 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" | 79 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" |
| 80 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 80 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| 81 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 81 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 82 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 82 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
| 83 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" | 83 #include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h" |
| 84 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 84 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
| 85 #include "ui/gfx/size.h" | 85 #include "ui/gfx/size.h" |
| 86 #include "webkit/fileapi/file_system_callback_dispatcher.h" | |
| 87 #include "webkit/plugins/npapi/webplugin.h" | 86 #include "webkit/plugins/npapi/webplugin.h" |
| 88 #include "webkit/plugins/ppapi/plugin_module.h" | 87 #include "webkit/plugins/ppapi/plugin_module.h" |
| 89 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 88 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
| 90 #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h" | 89 #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h" |
| 91 #include "webkit/plugins/ppapi/ppb_tcp_server_socket_private_impl.h" | 90 #include "webkit/plugins/ppapi/ppb_tcp_server_socket_private_impl.h" |
| 92 #include "webkit/plugins/ppapi/ppb_tcp_socket_private_impl.h" | 91 #include "webkit/plugins/ppapi/ppb_tcp_socket_private_impl.h" |
| 93 #include "webkit/plugins/ppapi/resource_helper.h" | 92 #include "webkit/plugins/ppapi/resource_helper.h" |
| 94 #include "webkit/plugins/webplugininfo.h" | 93 #include "webkit/plugins/webplugininfo.h" |
| 95 | 94 |
| 96 using WebKit::WebView; | 95 using WebKit::WebView; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 | 252 |
| 254 private: | 253 private: |
| 255 webkit::ppapi::PluginInstance* plugin_; | 254 webkit::ppapi::PluginInstance* plugin_; |
| 256 }; | 255 }; |
| 257 | 256 |
| 258 void DoNotifyCloseFile(int file_open_id, base::PlatformFileError /* unused */) { | 257 void DoNotifyCloseFile(int file_open_id, base::PlatformFileError /* unused */) { |
| 259 ChildThread::current()->file_system_dispatcher()->NotifyCloseFile( | 258 ChildThread::current()->file_system_dispatcher()->NotifyCloseFile( |
| 260 file_open_id); | 259 file_open_id); |
| 261 } | 260 } |
| 262 | 261 |
| 263 class AsyncOpenFileSystemURLCallbackTranslator | 262 void AsyncOpenFileSystemURLCallbackAdapter( |
| 264 : public fileapi::FileSystemCallbackDispatcher { | 263 const webkit::ppapi::PluginDelegate::AsyncOpenFileSystemURLCallback& |
| 265 public: | 264 callback, |
| 266 AsyncOpenFileSystemURLCallbackTranslator( | 265 base::PlatformFileError error, |
| 267 const webkit::ppapi::PluginDelegate::AsyncOpenFileSystemURLCallback& | 266 base::PlatformFile file, |
| 268 callback) | 267 int file_open_id, |
| 269 : callback_(callback) { | 268 quota::QuotaLimitType quota_policy) { |
| 269 webkit::ppapi::PluginDelegate::NotifyCloseFileCallback close_callback; |
| 270 if (error == base::PLATFORM_FILE_OK) |
| 271 close_callback = base::Bind(&DoNotifyCloseFile, file_open_id); |
| 272 |
| 273 callback.Run(error, |
| 274 base::PassPlatformFile(&file), |
| 275 quota_policy, |
| 276 close_callback); |
| 277 // Make sure we won't leak file handle if the requester has died. |
| 278 if (file != base::kInvalidPlatformFileValue) { |
| 279 base::FileUtilProxy::Close( |
| 280 RenderThreadImpl::current()->GetFileThreadMessageLoopProxy(), file, |
| 281 close_callback); |
| 270 } | 282 } |
| 271 | 283 } |
| 272 virtual ~AsyncOpenFileSystemURLCallbackTranslator() {} | |
| 273 | |
| 274 virtual void DidSucceed() OVERRIDE { | |
| 275 NOTREACHED(); | |
| 276 } | |
| 277 virtual void DidReadMetadata( | |
| 278 const base::PlatformFileInfo& file_info, | |
| 279 const base::FilePath& platform_path) OVERRIDE { | |
| 280 NOTREACHED(); | |
| 281 } | |
| 282 virtual void DidCreateSnapshotFile( | |
| 283 const base::PlatformFileInfo& file_info, | |
| 284 const base::FilePath& platform_path) OVERRIDE { | |
| 285 NOTREACHED(); | |
| 286 } | |
| 287 virtual void DidReadDirectory( | |
| 288 const std::vector<base::FileUtilProxy::Entry>& entries, | |
| 289 bool has_more) OVERRIDE { | |
| 290 NOTREACHED(); | |
| 291 } | |
| 292 virtual void DidOpenFileSystem(const std::string& name, | |
| 293 const GURL& root) OVERRIDE { | |
| 294 NOTREACHED(); | |
| 295 } | |
| 296 | |
| 297 virtual void DidFail(base::PlatformFileError error_code) OVERRIDE { | |
| 298 base::PlatformFile invalid_file = base::kInvalidPlatformFileValue; | |
| 299 callback_.Run(error_code, | |
| 300 base::PassPlatformFile(&invalid_file), | |
| 301 quota::kQuotaLimitTypeUnknown, | |
| 302 webkit::ppapi::PluginDelegate::NotifyCloseFileCallback()); | |
| 303 } | |
| 304 | |
| 305 virtual void DidWrite(int64 bytes, bool complete) OVERRIDE { | |
| 306 NOTREACHED(); | |
| 307 } | |
| 308 | |
| 309 virtual void DidOpenFile(base::PlatformFile file, | |
| 310 int file_open_id, | |
| 311 quota::QuotaLimitType quota_policy) OVERRIDE { | |
| 312 callback_.Run(base::PLATFORM_FILE_OK, | |
| 313 base::PassPlatformFile(&file), | |
| 314 quota_policy, | |
| 315 base::Bind(&DoNotifyCloseFile, file_open_id)); | |
| 316 // Make sure we won't leak file handle if the requester has died. | |
| 317 if (file != base::kInvalidPlatformFileValue) { | |
| 318 base::FileUtilProxy::Close( | |
| 319 RenderThreadImpl::current()->GetFileThreadMessageLoopProxy(), file, | |
| 320 base::Bind(&DoNotifyCloseFile, file_open_id)); | |
| 321 } | |
| 322 } | |
| 323 | |
| 324 private: | |
| 325 webkit::ppapi::PluginDelegate::AsyncOpenFileSystemURLCallback callback_; | |
| 326 }; | |
| 327 | 284 |
| 328 void CreateHostForInProcessModule(RenderViewImpl* render_view, | 285 void CreateHostForInProcessModule(RenderViewImpl* render_view, |
| 329 webkit::ppapi::PluginModule* module, | 286 webkit::ppapi::PluginModule* module, |
| 330 const webkit::WebPluginInfo& webplugin_info) { | 287 const webkit::WebPluginInfo& webplugin_info) { |
| 331 // First time an in-process plugin was used, make a host for it. | 288 // First time an in-process plugin was used, make a host for it. |
| 332 const PepperPluginInfo* info = | 289 const PepperPluginInfo* info = |
| 333 PepperPluginRegistry::GetInstance()->GetInfoForPlugin(webplugin_info); | 290 PepperPluginRegistry::GetInstance()->GetInfoForPlugin(webplugin_info); |
| 334 DCHECK(!info->is_out_of_process); | 291 DCHECK(!info->is_out_of_process); |
| 335 | 292 |
| 336 ppapi::PpapiPermissions perms( | 293 ppapi::PpapiPermissions perms( |
| (...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1045 GURL PepperPluginDelegateImpl::GetFileSystemRootUrl( | 1002 GURL PepperPluginDelegateImpl::GetFileSystemRootUrl( |
| 1046 PP_Instance instance, PP_Resource resource) const { | 1003 PP_Instance instance, PP_Resource resource) const { |
| 1047 const PepperFileSystemHost* host = | 1004 const PepperFileSystemHost* host = |
| 1048 GetRendererResourceHost<PepperFileSystemHost>(instance, resource); | 1005 GetRendererResourceHost<PepperFileSystemHost>(instance, resource); |
| 1049 return host ? host->GetRootUrl() : GURL(); | 1006 return host ? host->GetRootUrl() : GURL(); |
| 1050 } | 1007 } |
| 1051 | 1008 |
| 1052 bool PepperPluginDelegateImpl::MakeDirectory( | 1009 bool PepperPluginDelegateImpl::MakeDirectory( |
| 1053 const GURL& path, | 1010 const GURL& path, |
| 1054 bool recursive, | 1011 bool recursive, |
| 1055 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 1012 const StatusCallback& callback) { |
| 1056 FileSystemDispatcher* file_system_dispatcher = | 1013 FileSystemDispatcher* file_system_dispatcher = |
| 1057 ChildThread::current()->file_system_dispatcher(); | 1014 ChildThread::current()->file_system_dispatcher(); |
| 1058 return file_system_dispatcher->Create( | 1015 return file_system_dispatcher->Create( |
| 1059 path, false, true, recursive, dispatcher); | 1016 path, false, true, recursive, callback); |
| 1060 } | 1017 } |
| 1061 | 1018 |
| 1062 bool PepperPluginDelegateImpl::Query( | 1019 bool PepperPluginDelegateImpl::Query( |
| 1063 const GURL& path, | 1020 const GURL& path, |
| 1064 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 1021 const MetadataCallback& callback) { |
| 1065 FileSystemDispatcher* file_system_dispatcher = | 1022 FileSystemDispatcher* file_system_dispatcher = |
| 1066 ChildThread::current()->file_system_dispatcher(); | 1023 ChildThread::current()->file_system_dispatcher(); |
| 1067 return file_system_dispatcher->ReadMetadata(path, dispatcher); | 1024 return file_system_dispatcher->ReadMetadata(path, callback); |
| 1068 } | 1025 } |
| 1069 | 1026 |
| 1070 bool PepperPluginDelegateImpl::ReadDirectoryEntries( | 1027 bool PepperPluginDelegateImpl::ReadDirectoryEntries( |
| 1071 const GURL& path, | 1028 const GURL& path, |
| 1072 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 1029 const ReadDirectoryCallback& callback) { |
| 1073 FileSystemDispatcher* file_system_dispatcher = | 1030 FileSystemDispatcher* file_system_dispatcher = |
| 1074 ChildThread::current()->file_system_dispatcher(); | 1031 ChildThread::current()->file_system_dispatcher(); |
| 1075 return file_system_dispatcher->ReadDirectory(path, dispatcher); | 1032 return file_system_dispatcher->ReadDirectory(path, callback); |
| 1076 } | 1033 } |
| 1077 | 1034 |
| 1078 bool PepperPluginDelegateImpl::Touch( | 1035 bool PepperPluginDelegateImpl::Touch( |
| 1079 const GURL& path, | 1036 const GURL& path, |
| 1080 const base::Time& last_access_time, | 1037 const base::Time& last_access_time, |
| 1081 const base::Time& last_modified_time, | 1038 const base::Time& last_modified_time, |
| 1082 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 1039 const StatusCallback& callback) { |
| 1083 FileSystemDispatcher* file_system_dispatcher = | 1040 FileSystemDispatcher* file_system_dispatcher = |
| 1084 ChildThread::current()->file_system_dispatcher(); | 1041 ChildThread::current()->file_system_dispatcher(); |
| 1085 return file_system_dispatcher->TouchFile(path, last_access_time, | 1042 return file_system_dispatcher->TouchFile(path, last_access_time, |
| 1086 last_modified_time, dispatcher); | 1043 last_modified_time, callback); |
| 1087 } | 1044 } |
| 1088 | 1045 |
| 1089 bool PepperPluginDelegateImpl::SetLength( | 1046 bool PepperPluginDelegateImpl::SetLength( |
| 1090 const GURL& path, | 1047 const GURL& path, |
| 1091 int64_t length, | 1048 int64_t length, |
| 1092 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 1049 const StatusCallback& callback) { |
| 1093 FileSystemDispatcher* file_system_dispatcher = | 1050 FileSystemDispatcher* file_system_dispatcher = |
| 1094 ChildThread::current()->file_system_dispatcher(); | 1051 ChildThread::current()->file_system_dispatcher(); |
| 1095 return file_system_dispatcher->Truncate(path, length, NULL, dispatcher); | 1052 return file_system_dispatcher->Truncate(path, length, NULL, callback); |
| 1096 } | 1053 } |
| 1097 | 1054 |
| 1098 bool PepperPluginDelegateImpl::Delete( | 1055 bool PepperPluginDelegateImpl::Delete( |
| 1099 const GURL& path, | 1056 const GURL& path, |
| 1100 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 1057 const StatusCallback& callback) { |
| 1101 FileSystemDispatcher* file_system_dispatcher = | 1058 FileSystemDispatcher* file_system_dispatcher = |
| 1102 ChildThread::current()->file_system_dispatcher(); | 1059 ChildThread::current()->file_system_dispatcher(); |
| 1103 return file_system_dispatcher->Remove(path, false /* recursive */, | 1060 return file_system_dispatcher->Remove(path, false /* recursive */, callback); |
| 1104 dispatcher); | |
| 1105 } | 1061 } |
| 1106 | 1062 |
| 1107 bool PepperPluginDelegateImpl::Rename( | 1063 bool PepperPluginDelegateImpl::Rename( |
| 1108 const GURL& file_path, | 1064 const GURL& file_path, |
| 1109 const GURL& new_file_path, | 1065 const GURL& new_file_path, |
| 1110 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 1066 const StatusCallback& callback) { |
| 1111 FileSystemDispatcher* file_system_dispatcher = | 1067 FileSystemDispatcher* file_system_dispatcher = |
| 1112 ChildThread::current()->file_system_dispatcher(); | 1068 ChildThread::current()->file_system_dispatcher(); |
| 1113 return file_system_dispatcher->Move(file_path, new_file_path, dispatcher); | 1069 return file_system_dispatcher->Move(file_path, new_file_path, callback); |
| 1114 } | 1070 } |
| 1115 | 1071 |
| 1116 bool PepperPluginDelegateImpl::ReadDirectory( | 1072 bool PepperPluginDelegateImpl::ReadDirectory( |
| 1117 const GURL& directory_path, | 1073 const GURL& directory_path, |
| 1118 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 1074 const ReadDirectoryCallback& callback) { |
| 1119 FileSystemDispatcher* file_system_dispatcher = | 1075 FileSystemDispatcher* file_system_dispatcher = |
| 1120 ChildThread::current()->file_system_dispatcher(); | 1076 ChildThread::current()->file_system_dispatcher(); |
| 1121 return file_system_dispatcher->ReadDirectory(directory_path, dispatcher); | 1077 return file_system_dispatcher->ReadDirectory(directory_path, callback); |
| 1122 } | 1078 } |
| 1123 | 1079 |
| 1124 void PepperPluginDelegateImpl::QueryAvailableSpace( | 1080 void PepperPluginDelegateImpl::QueryAvailableSpace( |
| 1125 const GURL& origin, quota::StorageType type, | 1081 const GURL& origin, quota::StorageType type, |
| 1126 const AvailableSpaceCallback& callback) { | 1082 const AvailableSpaceCallback& callback) { |
| 1127 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota( | 1083 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota( |
| 1128 origin, type, new QuotaCallbackTranslator(callback)); | 1084 origin, type, new QuotaCallbackTranslator(callback)); |
| 1129 } | 1085 } |
| 1130 | 1086 |
| 1131 void PepperPluginDelegateImpl::WillUpdateFile(const GURL& path) { | 1087 void PepperPluginDelegateImpl::WillUpdateFile(const GURL& path) { |
| 1132 ChildThread::current()->Send(new FileSystemHostMsg_WillUpdate(path)); | 1088 ChildThread::current()->Send(new FileSystemHostMsg_WillUpdate(path)); |
| 1133 } | 1089 } |
| 1134 | 1090 |
| 1135 void PepperPluginDelegateImpl::DidUpdateFile(const GURL& path, int64_t delta) { | 1091 void PepperPluginDelegateImpl::DidUpdateFile(const GURL& path, int64_t delta) { |
| 1136 ChildThread::current()->Send(new FileSystemHostMsg_DidUpdate(path, delta)); | 1092 ChildThread::current()->Send(new FileSystemHostMsg_DidUpdate(path, delta)); |
| 1137 } | 1093 } |
| 1138 | 1094 |
| 1139 bool PepperPluginDelegateImpl::AsyncOpenFileSystemURL( | 1095 bool PepperPluginDelegateImpl::AsyncOpenFileSystemURL( |
| 1140 const GURL& path, | 1096 const GURL& path, |
| 1141 int flags, | 1097 int flags, |
| 1142 const AsyncOpenFileSystemURLCallback& callback) { | 1098 const AsyncOpenFileSystemURLCallback& callback) { |
| 1143 | 1099 |
| 1144 FileSystemDispatcher* file_system_dispatcher = | 1100 FileSystemDispatcher* file_system_dispatcher = |
| 1145 ChildThread::current()->file_system_dispatcher(); | 1101 ChildThread::current()->file_system_dispatcher(); |
| 1146 return file_system_dispatcher->OpenFile(path, flags, | 1102 return file_system_dispatcher->OpenFile( |
| 1147 new AsyncOpenFileSystemURLCallbackTranslator( | 1103 path, flags, |
| 1148 callback)); | 1104 base::Bind(&AsyncOpenFileSystemURLCallbackAdapter, callback)); |
| 1149 } | 1105 } |
| 1150 | 1106 |
| 1151 void PepperPluginDelegateImpl::SyncGetFileSystemPlatformPath( | 1107 void PepperPluginDelegateImpl::SyncGetFileSystemPlatformPath( |
| 1152 const GURL& url, base::FilePath* platform_path) { | 1108 const GURL& url, base::FilePath* platform_path) { |
| 1153 RenderThreadImpl::current()->Send(new FileSystemHostMsg_SyncGetPlatformPath( | 1109 RenderThreadImpl::current()->Send(new FileSystemHostMsg_SyncGetPlatformPath( |
| 1154 url, platform_path)); | 1110 url, platform_path)); |
| 1155 } | 1111 } |
| 1156 | 1112 |
| 1157 scoped_refptr<base::MessageLoopProxy> | 1113 scoped_refptr<base::MessageLoopProxy> |
| 1158 PepperPluginDelegateImpl::GetFileThreadMessageLoopProxy() { | 1114 PepperPluginDelegateImpl::GetFileThreadMessageLoopProxy() { |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1650 should_close_source); | 1606 should_close_source); |
| 1651 } | 1607 } |
| 1652 | 1608 |
| 1653 bool PepperPluginDelegateImpl::IsRunningInProcess(PP_Instance instance) const { | 1609 bool PepperPluginDelegateImpl::IsRunningInProcess(PP_Instance instance) const { |
| 1654 RendererPpapiHostImpl* host = | 1610 RendererPpapiHostImpl* host = |
| 1655 RendererPpapiHostImpl::GetForPPInstance(instance); | 1611 RendererPpapiHostImpl::GetForPPInstance(instance); |
| 1656 return host && host->IsRunningInProcess(); | 1612 return host && host->IsRunningInProcess(); |
| 1657 } | 1613 } |
| 1658 | 1614 |
| 1659 } // namespace content | 1615 } // namespace content |
| OLD | NEW |