| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/plugin/webplugin_delegate_stub.h" | 5 #include "chrome/plugin/webplugin_delegate_stub.h" |
| 6 | 6 |
| 7 #include "build/build_config.h" |
| 8 |
| 7 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 8 #include "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| 9 #include "chrome/common/gfx/emf.h" | |
| 10 #include "chrome/common/plugin_messages.h" | 11 #include "chrome/common/plugin_messages.h" |
| 11 #include "chrome/common/win_util.h" | |
| 12 #include "chrome/plugin/npobject_stub.h" | 12 #include "chrome/plugin/npobject_stub.h" |
| 13 #include "chrome/plugin/plugin_channel.h" | 13 #include "chrome/plugin/plugin_channel.h" |
| 14 #include "chrome/plugin/plugin_thread.h" | 14 #include "chrome/plugin/plugin_thread.h" |
| 15 #include "chrome/plugin/webplugin_proxy.h" | 15 #include "chrome/plugin/webplugin_proxy.h" |
| 16 #include "third_party/npapi/bindings/npapi.h" | 16 #include "third_party/npapi/bindings/npapi.h" |
| 17 #include "third_party/npapi/bindings/npruntime.h" | 17 #include "third_party/npapi/bindings/npruntime.h" |
| 18 #include "skia/ext/platform_device.h" | 18 #include "skia/ext/platform_device.h" |
| 19 #include "webkit/glue/webcursor.h" | 19 #include "webkit/glue/webcursor.h" |
| 20 #include "webkit/glue/webplugin_delegate.h" | 20 #include "webkit/glue/webplugin_delegate.h" |
| 21 | 21 |
| 22 #if defined(OS_WIN) |
| 23 #include "chrome/common/gfx/emf.h" |
| 24 #include "chrome/common/win_util.h" |
| 25 #endif |
| 26 |
| 22 class FinishDestructionTask : public Task { | 27 class FinishDestructionTask : public Task { |
| 23 public: | 28 public: |
| 24 FinishDestructionTask(WebPluginDelegate* delegate, WebPlugin* webplugin) | 29 FinishDestructionTask(WebPluginDelegate* delegate, WebPlugin* webplugin) |
| 25 : delegate_(delegate), webplugin_(webplugin) { } | 30 : delegate_(delegate), webplugin_(webplugin) { } |
| 26 | 31 |
| 27 void Run() { | 32 void Run() { |
| 28 // WebPlugin must outlive WebPluginDelegate. | 33 // WebPlugin must outlive WebPluginDelegate. |
| 29 if (delegate_) | 34 if (delegate_) |
| 30 delegate_->PluginDestroyed(); | 35 delegate_->PluginDestroyed(); |
| 31 | 36 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 } | 122 } |
| 118 | 123 |
| 119 char **argn = new char*[argc]; | 124 char **argn = new char*[argc]; |
| 120 char **argv = new char*[argc]; | 125 char **argv = new char*[argc]; |
| 121 for (int i = 0; i < argc; ++i) { | 126 for (int i = 0; i < argc; ++i) { |
| 122 argn[i] = const_cast<char*>(params.arg_names[i].c_str()); | 127 argn[i] = const_cast<char*>(params.arg_names[i].c_str()); |
| 123 argv[i] = const_cast<char*>(params.arg_values[i].c_str()); | 128 argv[i] = const_cast<char*>(params.arg_values[i].c_str()); |
| 124 } | 129 } |
| 125 | 130 |
| 126 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 131 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 127 FilePath path = | 132 FilePath path = FilePath::FromWStringHack( |
| 128 FilePath(command_line.GetSwitchValue(switches::kPluginPath)); | 133 command_line.GetSwitchValue(switches::kPluginPath)); |
| 129 delegate_ = WebPluginDelegate::Create( | 134 delegate_ = WebPluginDelegate::Create( |
| 130 path, mime_type_, gfx::NativeViewFromId(params.containing_window)); | 135 path, mime_type_, gfx::NativeViewFromId(params.containing_window)); |
| 131 if (delegate_) { | 136 if (delegate_) { |
| 132 webplugin_ = new WebPluginProxy(channel_, instance_id_, delegate_); | 137 webplugin_ = new WebPluginProxy(channel_, instance_id_, delegate_); |
| 133 #if defined(OS_WIN) | 138 #if defined(OS_WIN) |
| 134 webplugin_->SetModalDialogEvent(params.modal_dialog_event); | 139 webplugin_->SetModalDialogEvent(params.modal_dialog_event); |
| 135 #endif | 140 #endif |
| 136 *result = delegate_->Initialize( | 141 *result = delegate_->Initialize( |
| 137 params.url, argn, argv, argc, webplugin_, params.load_manually); | 142 params.url, argn, argv, argc, webplugin_, params.load_manually); |
| 138 } | 143 } |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 void WebPluginDelegateStub::OnPaint(const gfx::Rect& damaged_rect) { | 213 void WebPluginDelegateStub::OnPaint(const gfx::Rect& damaged_rect) { |
| 209 webplugin_->Paint(damaged_rect); | 214 webplugin_->Paint(damaged_rect); |
| 210 } | 215 } |
| 211 | 216 |
| 212 void WebPluginDelegateStub::OnDidPaint() { | 217 void WebPluginDelegateStub::OnDidPaint() { |
| 213 webplugin_->DidPaint(); | 218 webplugin_->DidPaint(); |
| 214 } | 219 } |
| 215 | 220 |
| 216 void WebPluginDelegateStub::OnPrint(base::SharedMemoryHandle* shared_memory, | 221 void WebPluginDelegateStub::OnPrint(base::SharedMemoryHandle* shared_memory, |
| 217 size_t* size) { | 222 size_t* size) { |
| 223 #if defined(OS_WIN) |
| 218 gfx::Emf emf; | 224 gfx::Emf emf; |
| 219 if (!emf.CreateDc(NULL, NULL)) { | 225 if (!emf.CreateDc(NULL, NULL)) { |
| 220 NOTREACHED(); | 226 NOTREACHED(); |
| 221 return; | 227 return; |
| 222 } | 228 } |
| 223 HDC hdc = emf.hdc(); | 229 HDC hdc = emf.hdc(); |
| 224 skia::PlatformDeviceWin::InitializeDC(hdc); | 230 skia::PlatformDeviceWin::InitializeDC(hdc); |
| 225 delegate_->Print(hdc); | 231 delegate_->Print(hdc); |
| 226 if (!emf.CloseDc()) { | 232 if (!emf.CloseDc()) { |
| 227 NOTREACHED(); | 233 NOTREACHED(); |
| 228 return; | 234 return; |
| 229 } | 235 } |
| 230 | 236 |
| 231 *size = emf.GetDataSize(); | 237 *size = emf.GetDataSize(); |
| 232 DCHECK(*size); | 238 DCHECK(*size); |
| 233 base::SharedMemory shared_buf; | 239 base::SharedMemory shared_buf; |
| 234 CreateSharedBuffer(*size, &shared_buf, shared_memory); | 240 CreateSharedBuffer(*size, &shared_buf, shared_memory); |
| 235 | 241 |
| 236 // Retrieve a copy of the data. | 242 // Retrieve a copy of the data. |
| 237 bool success = emf.GetData(shared_buf.memory(), *size); | 243 bool success = emf.GetData(shared_buf.memory(), *size); |
| 238 DCHECK(success); | 244 DCHECK(success); |
| 245 #else |
| 246 // TODO(port): plugin printing. |
| 247 NOTIMPLEMENTED(); |
| 248 #endif |
| 239 } | 249 } |
| 240 | 250 |
| 241 void WebPluginDelegateStub::OnUpdateGeometry( | 251 void WebPluginDelegateStub::OnUpdateGeometry( |
| 242 const gfx::Rect& window_rect, | 252 const gfx::Rect& window_rect, |
| 243 const gfx::Rect& clip_rect, | 253 const gfx::Rect& clip_rect, |
| 244 const base::SharedMemoryHandle& windowless_buffer, | 254 const TransportDIB::Id& windowless_buffer_id, |
| 245 const base::SharedMemoryHandle& background_buffer) { | 255 const TransportDIB::Id& background_buffer_id) { |
| 246 webplugin_->UpdateGeometry( | 256 webplugin_->UpdateGeometry( |
| 247 window_rect, clip_rect, windowless_buffer, background_buffer); | 257 window_rect, clip_rect, |
| 258 windowless_buffer_id, background_buffer_id); |
| 248 } | 259 } |
| 249 | 260 |
| 250 void WebPluginDelegateStub::OnGetPluginScriptableObject(int* route_id, | 261 void WebPluginDelegateStub::OnGetPluginScriptableObject(int* route_id, |
| 251 intptr_t* npobject_ptr)
{ | 262 intptr_t* npobject_ptr)
{ |
| 252 NPObject* object = delegate_->GetPluginScriptableObject(); | 263 NPObject* object = delegate_->GetPluginScriptableObject(); |
| 253 if (!object) { | 264 if (!object) { |
| 254 *route_id = MSG_ROUTING_NONE; | 265 *route_id = MSG_ROUTING_NONE; |
| 255 return; | 266 return; |
| 256 } | 267 } |
| 257 | 268 |
| 258 *route_id = channel_->GenerateRouteID(); | 269 *route_id = channel_->GenerateRouteID(); |
| 259 *npobject_ptr = reinterpret_cast<intptr_t>(object); | 270 *npobject_ptr = reinterpret_cast<intptr_t>(object); |
| 260 // The stub will delete itself when the proxy tells it that it's released, or | 271 // The stub will delete itself when the proxy tells it that it's released, or |
| 261 // otherwise when the channel is closed. | 272 // otherwise when the channel is closed. |
| 262 NPObjectStub* stub = new NPObjectStub( | 273 new NPObjectStub( |
| 263 object, channel_.get(), *route_id, webplugin_->modal_dialog_event()); | 274 object, channel_.get(), *route_id, webplugin_->modal_dialog_event()); |
| 264 | 275 |
| 265 // Release ref added by GetPluginScriptableObject (our stub holds its own). | 276 // Release ref added by GetPluginScriptableObject (our stub holds its own). |
| 266 NPN_ReleaseObject(object); | 277 NPN_ReleaseObject(object); |
| 267 } | 278 } |
| 268 | 279 |
| 269 void WebPluginDelegateStub::OnSendJavaScriptStream(const std::string& url, | 280 void WebPluginDelegateStub::OnSendJavaScriptStream(const std::string& url, |
| 270 const std::wstring& result, | 281 const std::wstring& result, |
| 271 bool success, | 282 bool success, |
| 272 bool notify_needed, | 283 bool notify_needed, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 if (!shared_buf->Create(std::wstring(), false, false, size)) { | 319 if (!shared_buf->Create(std::wstring(), false, false, size)) { |
| 309 NOTREACHED(); | 320 NOTREACHED(); |
| 310 return; | 321 return; |
| 311 } | 322 } |
| 312 if (!shared_buf->Map(size)) { | 323 if (!shared_buf->Map(size)) { |
| 313 NOTREACHED(); | 324 NOTREACHED(); |
| 314 shared_buf->Close(); | 325 shared_buf->Close(); |
| 315 return; | 326 return; |
| 316 } | 327 } |
| 317 | 328 |
| 329 #if defined(OS_WIN) |
| 318 BOOL result = DuplicateHandle(GetCurrentProcess(), | 330 BOOL result = DuplicateHandle(GetCurrentProcess(), |
| 319 shared_buf->handle(), | 331 shared_buf->handle(), |
| 320 channel_->renderer_handle(), | 332 channel_->renderer_handle(), |
| 321 remote_handle, 0, FALSE, | 333 remote_handle, 0, FALSE, |
| 322 DUPLICATE_SAME_ACCESS); | 334 DUPLICATE_SAME_ACCESS); |
| 323 DCHECK_NE(result, 0); | 335 DCHECK_NE(result, 0); |
| 324 | 336 |
| 325 // If the calling function's shared_buf is on the stack, its destructor will | 337 // If the calling function's shared_buf is on the stack, its destructor will |
| 326 // close the shared memory buffer handle. This is fine since we already | 338 // close the shared memory buffer handle. This is fine since we already |
| 327 // duplicated the handle to the renderer process so it will stay "alive". | 339 // duplicated the handle to the renderer process so it will stay "alive". |
| 340 #else |
| 341 // TODO(port): this should use TransportDIB. |
| 342 NOTIMPLEMENTED(); |
| 343 #endif |
| 328 } | 344 } |
| 329 | 345 |
| 330 void WebPluginDelegateStub::OnHandleURLRequestReply( | 346 void WebPluginDelegateStub::OnHandleURLRequestReply( |
| 331 const PluginMsg_URLRequestReply_Params& params) { | 347 const PluginMsg_URLRequestReply_Params& params) { |
| 332 WebPluginResourceClient* resource_client = | 348 WebPluginResourceClient* resource_client = |
| 333 delegate_->CreateResourceClient(params.resource_id, params.url, | 349 delegate_->CreateResourceClient(params.resource_id, params.url, |
| 334 params.notify_needed, | 350 params.notify_needed, |
| 335 params.notify_data, | 351 params.notify_data, |
| 336 params.stream); | 352 params.stream); |
| 337 webplugin_->OnResourceCreated(params.resource_id, resource_client); | 353 webplugin_->OnResourceCreated(params.resource_id, resource_client); |
| 338 } | 354 } |
| 339 | 355 |
| 340 void WebPluginDelegateStub::OnURLRequestRouted(const std::string& url, | 356 void WebPluginDelegateStub::OnURLRequestRouted(const std::string& url, |
| 341 bool notify_needed, | 357 bool notify_needed, |
| 342 intptr_t notify_data) { | 358 intptr_t notify_data) { |
| 343 delegate_->URLRequestRouted(url, notify_needed, notify_data); | 359 delegate_->URLRequestRouted(url, notify_needed, notify_data); |
| 344 } | 360 } |
| OLD | NEW |