Chromium Code Reviews| 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 DidOpenFileSystemURL( |
| 264 : public fileapi::FileSystemCallbackDispatcher { | 263 const webkit::ppapi::PluginDelegate::AsyncOpenFileSystemURLCallback& |
| 265 public: | 264 callback, |
| 266 AsyncOpenFileSystemURLCallbackTranslator( | 265 base::PlatformFile file, |
| 267 const webkit::ppapi::PluginDelegate::AsyncOpenFileSystemURLCallback& | 266 int file_open_id, |
| 268 callback) | 267 quota::QuotaLimitType quota_policy) { |
| 269 : callback_(callback) { | 268 callback.Run(base::PLATFORM_FILE_OK, |
| 269 base::PassPlatformFile(&file), | |
| 270 quota_policy, | |
| 271 base::Bind(&DoNotifyCloseFile, file_open_id)); | |
| 272 // Make sure we won't leak file handle if the requester has died. | |
| 273 if (file != base::kInvalidPlatformFileValue) { | |
| 274 base::FileUtilProxy::Close( | |
| 275 RenderThreadImpl::current()->GetFileThreadMessageLoopProxy(), file, | |
| 276 base::Bind(&DoNotifyCloseFile, file_open_id)); | |
| 270 } | 277 } |
| 278 } | |
| 271 | 279 |
| 272 virtual ~AsyncOpenFileSystemURLCallbackTranslator() {} | 280 void DidFailOpenFileSystemURL( |
| 273 | 281 const webkit::ppapi::PluginDelegate::AsyncOpenFileSystemURLCallback& |
| 274 virtual void DidSucceed() OVERRIDE { | 282 callback, |
| 275 NOTREACHED(); | 283 base::PlatformFileError error_code) { |
| 276 } | 284 base::PlatformFile invalid_file = base::kInvalidPlatformFileValue; |
| 277 virtual void DidReadMetadata( | 285 callback.Run(error_code, |
| 278 const base::PlatformFileInfo& file_info, | 286 base::PassPlatformFile(&invalid_file), |
| 279 const base::FilePath& platform_path) OVERRIDE { | 287 quota::kQuotaLimitTypeUnknown, |
| 280 NOTREACHED(); | 288 webkit::ppapi::PluginDelegate::NotifyCloseFileCallback()); |
| 281 } | 289 } |
| 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 | 290 |
| 328 void CreateHostForInProcessModule(RenderViewImpl* render_view, | 291 void CreateHostForInProcessModule(RenderViewImpl* render_view, |
| 329 webkit::ppapi::PluginModule* module, | 292 webkit::ppapi::PluginModule* module, |
| 330 const webkit::WebPluginInfo& webplugin_info) { | 293 const webkit::WebPluginInfo& webplugin_info) { |
| 331 // First time an in-process plugin was used, make a host for it. | 294 // First time an in-process plugin was used, make a host for it. |
| 332 const PepperPluginInfo* info = | 295 const PepperPluginInfo* info = |
| 333 PepperPluginRegistry::GetInstance()->GetInfoForPlugin(webplugin_info); | 296 PepperPluginRegistry::GetInstance()->GetInfoForPlugin(webplugin_info); |
| 334 DCHECK(!info->is_out_of_process); | 297 DCHECK(!info->is_out_of_process); |
| 335 | 298 |
| 336 ppapi::PpapiPermissions perms( | 299 ppapi::PpapiPermissions perms( |
| (...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1045 GURL PepperPluginDelegateImpl::GetFileSystemRootUrl( | 1008 GURL PepperPluginDelegateImpl::GetFileSystemRootUrl( |
| 1046 PP_Instance instance, PP_Resource resource) const { | 1009 PP_Instance instance, PP_Resource resource) const { |
| 1047 const PepperFileSystemHost* host = | 1010 const PepperFileSystemHost* host = |
| 1048 GetRendererResourceHost<PepperFileSystemHost>(instance, resource); | 1011 GetRendererResourceHost<PepperFileSystemHost>(instance, resource); |
| 1049 return host ? host->GetRootUrl() : GURL(); | 1012 return host ? host->GetRootUrl() : GURL(); |
| 1050 } | 1013 } |
| 1051 | 1014 |
| 1052 bool PepperPluginDelegateImpl::MakeDirectory( | 1015 bool PepperPluginDelegateImpl::MakeDirectory( |
| 1053 const GURL& path, | 1016 const GURL& path, |
| 1054 bool recursive, | 1017 bool recursive, |
| 1055 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 1018 const StatusCallback& callback) { |
| 1056 FileSystemDispatcher* file_system_dispatcher = | 1019 FileSystemDispatcher* file_system_dispatcher = |
| 1057 ChildThread::current()->file_system_dispatcher(); | 1020 ChildThread::current()->file_system_dispatcher(); |
| 1058 return file_system_dispatcher->Create( | 1021 return file_system_dispatcher->Create( |
| 1059 path, false, true, recursive, dispatcher); | 1022 path, false, true, recursive, callback); |
| 1060 } | 1023 } |
| 1061 | 1024 |
| 1062 bool PepperPluginDelegateImpl::Query( | 1025 bool PepperPluginDelegateImpl::Query( |
| 1063 const GURL& path, | 1026 const GURL& path, |
| 1064 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 1027 const MetadataCallback& success_callback, |
|
yzshen1
2013/05/15 18:13:54
IMO, it is easier to have only one callback instea
| |
| 1028 const StatusCallback& error_callback) { | |
| 1065 FileSystemDispatcher* file_system_dispatcher = | 1029 FileSystemDispatcher* file_system_dispatcher = |
| 1066 ChildThread::current()->file_system_dispatcher(); | 1030 ChildThread::current()->file_system_dispatcher(); |
| 1067 return file_system_dispatcher->ReadMetadata(path, dispatcher); | 1031 return file_system_dispatcher->ReadMetadata( |
| 1032 path, success_callback, error_callback); | |
| 1068 } | 1033 } |
| 1069 | 1034 |
| 1070 bool PepperPluginDelegateImpl::ReadDirectoryEntries( | 1035 bool PepperPluginDelegateImpl::ReadDirectoryEntries( |
| 1071 const GURL& path, | 1036 const GURL& path, |
| 1072 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 1037 const ReadDirectoryCallback& success_callback, |
| 1038 const StatusCallback& error_callback) { | |
| 1073 FileSystemDispatcher* file_system_dispatcher = | 1039 FileSystemDispatcher* file_system_dispatcher = |
| 1074 ChildThread::current()->file_system_dispatcher(); | 1040 ChildThread::current()->file_system_dispatcher(); |
| 1075 return file_system_dispatcher->ReadDirectory(path, dispatcher); | 1041 return file_system_dispatcher->ReadDirectory( |
| 1042 path, success_callback, error_callback); | |
| 1076 } | 1043 } |
| 1077 | 1044 |
| 1078 bool PepperPluginDelegateImpl::Touch( | 1045 bool PepperPluginDelegateImpl::Touch( |
| 1079 const GURL& path, | 1046 const GURL& path, |
| 1080 const base::Time& last_access_time, | 1047 const base::Time& last_access_time, |
| 1081 const base::Time& last_modified_time, | 1048 const base::Time& last_modified_time, |
| 1082 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 1049 const StatusCallback& callback) { |
| 1083 FileSystemDispatcher* file_system_dispatcher = | 1050 FileSystemDispatcher* file_system_dispatcher = |
| 1084 ChildThread::current()->file_system_dispatcher(); | 1051 ChildThread::current()->file_system_dispatcher(); |
| 1085 return file_system_dispatcher->TouchFile(path, last_access_time, | 1052 return file_system_dispatcher->TouchFile(path, last_access_time, |
| 1086 last_modified_time, dispatcher); | 1053 last_modified_time, callback); |
| 1087 } | 1054 } |
| 1088 | 1055 |
| 1089 bool PepperPluginDelegateImpl::SetLength( | 1056 bool PepperPluginDelegateImpl::SetLength( |
| 1090 const GURL& path, | 1057 const GURL& path, |
| 1091 int64_t length, | 1058 int64_t length, |
| 1092 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 1059 const StatusCallback& callback) { |
| 1093 FileSystemDispatcher* file_system_dispatcher = | 1060 FileSystemDispatcher* file_system_dispatcher = |
| 1094 ChildThread::current()->file_system_dispatcher(); | 1061 ChildThread::current()->file_system_dispatcher(); |
| 1095 return file_system_dispatcher->Truncate(path, length, NULL, dispatcher); | 1062 return file_system_dispatcher->Truncate(path, length, NULL, callback); |
| 1096 } | 1063 } |
| 1097 | 1064 |
| 1098 bool PepperPluginDelegateImpl::Delete( | 1065 bool PepperPluginDelegateImpl::Delete( |
| 1099 const GURL& path, | 1066 const GURL& path, |
| 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->Remove(path, false /* recursive */, | 1070 return file_system_dispatcher->Remove(path, false /* recursive */, callback); |
| 1104 dispatcher); | |
| 1105 } | 1071 } |
| 1106 | 1072 |
| 1107 bool PepperPluginDelegateImpl::Rename( | 1073 bool PepperPluginDelegateImpl::Rename( |
| 1108 const GURL& file_path, | 1074 const GURL& file_path, |
| 1109 const GURL& new_file_path, | 1075 const GURL& new_file_path, |
| 1110 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 1076 const StatusCallback& callback) { |
| 1111 FileSystemDispatcher* file_system_dispatcher = | 1077 FileSystemDispatcher* file_system_dispatcher = |
| 1112 ChildThread::current()->file_system_dispatcher(); | 1078 ChildThread::current()->file_system_dispatcher(); |
| 1113 return file_system_dispatcher->Move(file_path, new_file_path, dispatcher); | 1079 return file_system_dispatcher->Move(file_path, new_file_path, callback); |
| 1114 } | 1080 } |
| 1115 | 1081 |
| 1116 bool PepperPluginDelegateImpl::ReadDirectory( | 1082 bool PepperPluginDelegateImpl::ReadDirectory( |
| 1117 const GURL& directory_path, | 1083 const GURL& directory_path, |
| 1118 fileapi::FileSystemCallbackDispatcher* dispatcher) { | 1084 const ReadDirectoryCallback& success_callback, |
| 1085 const StatusCallback& error_callback) { | |
| 1119 FileSystemDispatcher* file_system_dispatcher = | 1086 FileSystemDispatcher* file_system_dispatcher = |
| 1120 ChildThread::current()->file_system_dispatcher(); | 1087 ChildThread::current()->file_system_dispatcher(); |
| 1121 return file_system_dispatcher->ReadDirectory(directory_path, dispatcher); | 1088 return file_system_dispatcher->ReadDirectory( |
| 1089 directory_path, success_callback, error_callback); | |
| 1122 } | 1090 } |
| 1123 | 1091 |
| 1124 void PepperPluginDelegateImpl::QueryAvailableSpace( | 1092 void PepperPluginDelegateImpl::QueryAvailableSpace( |
| 1125 const GURL& origin, quota::StorageType type, | 1093 const GURL& origin, quota::StorageType type, |
| 1126 const AvailableSpaceCallback& callback) { | 1094 const AvailableSpaceCallback& callback) { |
| 1127 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota( | 1095 ChildThread::current()->quota_dispatcher()->QueryStorageUsageAndQuota( |
| 1128 origin, type, new QuotaCallbackTranslator(callback)); | 1096 origin, type, new QuotaCallbackTranslator(callback)); |
| 1129 } | 1097 } |
| 1130 | 1098 |
| 1131 void PepperPluginDelegateImpl::WillUpdateFile(const GURL& path) { | 1099 void PepperPluginDelegateImpl::WillUpdateFile(const GURL& path) { |
| 1132 ChildThread::current()->Send(new FileSystemHostMsg_WillUpdate(path)); | 1100 ChildThread::current()->Send(new FileSystemHostMsg_WillUpdate(path)); |
| 1133 } | 1101 } |
| 1134 | 1102 |
| 1135 void PepperPluginDelegateImpl::DidUpdateFile(const GURL& path, int64_t delta) { | 1103 void PepperPluginDelegateImpl::DidUpdateFile(const GURL& path, int64_t delta) { |
| 1136 ChildThread::current()->Send(new FileSystemHostMsg_DidUpdate(path, delta)); | 1104 ChildThread::current()->Send(new FileSystemHostMsg_DidUpdate(path, delta)); |
| 1137 } | 1105 } |
| 1138 | 1106 |
| 1139 bool PepperPluginDelegateImpl::AsyncOpenFileSystemURL( | 1107 bool PepperPluginDelegateImpl::AsyncOpenFileSystemURL( |
| 1140 const GURL& path, | 1108 const GURL& path, |
| 1141 int flags, | 1109 int flags, |
| 1142 const AsyncOpenFileSystemURLCallback& callback) { | 1110 const AsyncOpenFileSystemURLCallback& callback) { |
| 1143 | 1111 |
| 1144 FileSystemDispatcher* file_system_dispatcher = | 1112 FileSystemDispatcher* file_system_dispatcher = |
| 1145 ChildThread::current()->file_system_dispatcher(); | 1113 ChildThread::current()->file_system_dispatcher(); |
| 1146 return file_system_dispatcher->OpenFile(path, flags, | 1114 return file_system_dispatcher->OpenFile( |
| 1147 new AsyncOpenFileSystemURLCallbackTranslator( | 1115 path, flags, |
| 1148 callback)); | 1116 base::Bind(&DidOpenFileSystemURL, callback), |
| 1117 base::Bind(&DidFailOpenFileSystemURL, callback)); | |
| 1149 } | 1118 } |
| 1150 | 1119 |
| 1151 void PepperPluginDelegateImpl::SyncGetFileSystemPlatformPath( | 1120 void PepperPluginDelegateImpl::SyncGetFileSystemPlatformPath( |
| 1152 const GURL& url, base::FilePath* platform_path) { | 1121 const GURL& url, base::FilePath* platform_path) { |
| 1153 RenderThreadImpl::current()->Send(new FileSystemHostMsg_SyncGetPlatformPath( | 1122 RenderThreadImpl::current()->Send(new FileSystemHostMsg_SyncGetPlatformPath( |
| 1154 url, platform_path)); | 1123 url, platform_path)); |
| 1155 } | 1124 } |
| 1156 | 1125 |
| 1157 scoped_refptr<base::MessageLoopProxy> | 1126 scoped_refptr<base::MessageLoopProxy> |
| 1158 PepperPluginDelegateImpl::GetFileThreadMessageLoopProxy() { | 1127 PepperPluginDelegateImpl::GetFileThreadMessageLoopProxy() { |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1650 should_close_source); | 1619 should_close_source); |
| 1651 } | 1620 } |
| 1652 | 1621 |
| 1653 bool PepperPluginDelegateImpl::IsRunningInProcess(PP_Instance instance) const { | 1622 bool PepperPluginDelegateImpl::IsRunningInProcess(PP_Instance instance) const { |
| 1654 RendererPpapiHostImpl* host = | 1623 RendererPpapiHostImpl* host = |
| 1655 RendererPpapiHostImpl::GetForPPInstance(instance); | 1624 RendererPpapiHostImpl::GetForPPInstance(instance); |
| 1656 return host && host->IsRunningInProcess(); | 1625 return host && host->IsRunningInProcess(); |
| 1657 } | 1626 } |
| 1658 | 1627 |
| 1659 } // namespace content | 1628 } // namespace content |
| OLD | NEW |