1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
|
// Copyright (c) 2006-2008 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 "chrome/renderer/webplugin_delegate_proxy.h"
#include <atlbase.h>
#include "base/logging.h"
#include "base/ref_counted.h"
#include "base/string_util.h"
#include "base/gfx/size.h"
#include "base/gfx/native_widget_types.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/common/gfx/chrome_canvas.h"
#include "chrome/common/gfx/emf.h"
#include "chrome/common/l10n_util.h"
#include "chrome/common/plugin_messages.h"
#include "chrome/common/render_messages.h"
#include "chrome/common/resource_bundle.h"
#include "chrome/common/win_util.h"
#include "chrome/plugin/npobject_proxy.h"
#include "chrome/plugin/npobject_stub.h"
#include "chrome/renderer/render_thread.h"
#include "chrome/renderer/render_view.h"
#include "googleurl/src/gurl.h"
#include "grit/generated_resources.h"
#include "net/base/mime_util.h"
#include "webkit/glue/webframe.h"
#include "webkit/glue/webkit_glue.h"
#include "webkit/glue/webplugin.h"
#include "webkit/glue/webview.h"
// Proxy for WebPluginResourceClient. The object owns itself after creation,
// deleting itself after its callback has been called.
class ResourceClientProxy : public WebPluginResourceClient {
public:
ResourceClientProxy(PluginChannelHost* channel, int instance_id)
: channel_(channel), instance_id_(instance_id), resource_id_(0),
notify_needed_(false), notify_data_(NULL),
multibyte_response_expected_(false) {
}
~ResourceClientProxy() {
}
void Initialize(int resource_id, const std::string &url, bool notify_needed,
void *notify_data, void* existing_stream) {
resource_id_ = resource_id;
url_ = url;
notify_needed_ = notify_needed;
notify_data_ = notify_data;
PluginMsg_URLRequestReply_Params params;
params.resource_id = resource_id;
params.url = url_;
params.notify_needed = notify_needed_;
params.notify_data = notify_data_;
params.stream = existing_stream;
multibyte_response_expected_ = (existing_stream != NULL);
channel_->Send(new PluginMsg_HandleURLRequestReply(instance_id_, params));
}
// PluginResourceClient implementation:
void WillSendRequest(const GURL& url) {
DCHECK(channel_ != NULL);
channel_->Send(new PluginMsg_WillSendRequest(instance_id_, resource_id_,
url));
}
void DidReceiveResponse(const std::string& mime_type,
const std::string& headers,
uint32 expected_length,
uint32 last_modified,
bool request_is_seekable,
bool* cancel) {
DCHECK(channel_ != NULL);
PluginMsg_DidReceiveResponseParams params;
params.id = resource_id_;
params.mime_type = mime_type;
params.headers = headers;
params.expected_length = expected_length;
params.last_modified = last_modified;
params.request_is_seekable = request_is_seekable;
// Grab a reference on the underlying channel so it does not get
// deleted from under us.
scoped_refptr<PluginChannelHost> channel_ref(channel_);
channel_->Send(new PluginMsg_DidReceiveResponse(instance_id_, params,
cancel));
}
void DidReceiveData(const char* buffer, int length, int data_offset) {
DCHECK(channel_ != NULL);
DCHECK(length > 0);
std::vector<char> data;
data.resize(static_cast<size_t>(length));
memcpy(&data.front(), buffer, length);
// Grab a reference on the underlying channel so it does not get
// deleted from under us.
scoped_refptr<PluginChannelHost> channel_ref(channel_);
channel_->Send(new PluginMsg_DidReceiveData(instance_id_, resource_id_,
data, data_offset));
}
void DidFinishLoading() {
DCHECK(channel_ != NULL);
channel_->Send(new PluginMsg_DidFinishLoading(instance_id_, resource_id_));
channel_ = NULL;
MessageLoop::current()->DeleteSoon(FROM_HERE, this);
}
void DidFail() {
DCHECK(channel_ != NULL);
channel_->Send(new PluginMsg_DidFail(instance_id_, resource_id_));
channel_ = NULL;
MessageLoop::current()->DeleteSoon(FROM_HERE, this);
}
bool IsMultiByteResponseExpected() {
return multibyte_response_expected_;
}
private:
int resource_id_;
int instance_id_;
scoped_refptr<PluginChannelHost> channel_;
std::string url_;
bool notify_needed_;
void* notify_data_;
// Set to true if the response expected is a multibyte response.
// For e.g. response for a HTTP byte range request.
bool multibyte_response_expected_;
};
WebPluginDelegateProxy* WebPluginDelegateProxy::Create(
const GURL& url,
const std::string& mime_type,
const std::string& clsid,
RenderView* render_view) {
return new WebPluginDelegateProxy(mime_type, clsid, render_view);
}
WebPluginDelegateProxy::WebPluginDelegateProxy(const std::string& mime_type,
const std::string& clsid,
RenderView* render_view)
: render_view_(render_view),
mime_type_(mime_type),
clsid_(clsid),
plugin_(NULL),
windowless_(false),
npobject_(NULL),
send_deferred_update_geometry_(false),
sad_plugin_(NULL),
window_script_object_(NULL),
transparent_(false),
invalidate_pending_(false) {
}
WebPluginDelegateProxy::~WebPluginDelegateProxy() {
}
void WebPluginDelegateProxy::PluginDestroyed() {
plugin_ = NULL;
if (npobject_) {
// When we destroy the plugin instance, the NPObjectStub NULLs out its
// pointer to the npobject (see NPObjectStub::OnChannelError). Therefore,
// we release the object before destroying the instance to avoid leaking.
NPN_ReleaseObject(npobject_);
npobject_ = NULL;
}
if (window_script_object_) {
// The ScriptController deallocates this object independent of its ref count
// to avoid leaks if the plugin forgets to release it. So mark the object
// invalid to avoid accessing it past this point.
window_script_object_->set_proxy(NULL);
window_script_object_->set_invalid();
}
if (channel_host_) {
channel_host_->RemoveRoute(instance_id_);
Send(new PluginMsg_DestroyInstance(instance_id_));
}
render_view_->PluginDestroyed(this);
MessageLoop::current()->DeleteSoon(FROM_HERE, this);
}
void WebPluginDelegateProxy::FlushGeometryUpdates() {
if (send_deferred_update_geometry_) {
send_deferred_update_geometry_ = false;
Send(new PluginMsg_UpdateGeometry(instance_id_,
plugin_rect_,
deferred_clip_rect_,
NULL,
NULL));
}
}
bool WebPluginDelegateProxy::Initialize(const GURL& url, char** argn,
char** argv, int argc,
WebPlugin* plugin,
bool load_manually) {
std::wstring channel_name;
FilePath plugin_path;
if (!RenderThread::current()->Send(new ViewHostMsg_OpenChannelToPlugin(
url, mime_type_, clsid_, webkit_glue::GetWebKitLocale(),
&channel_name, &plugin_path)))
return false;
MessageLoop* ipc_message_loop = RenderThread::current()->owner_loop();
scoped_refptr<PluginChannelHost> channel_host =
PluginChannelHost::GetPluginChannelHost(channel_name, ipc_message_loop);
if (!channel_host.get())
return false;
int instance_id;
bool result = channel_host->Send(new PluginMsg_CreateInstance(
mime_type_, &instance_id));
if (!result)
return false;
plugin_path_ = plugin_path;
channel_host_ = channel_host;
instance_id_ = instance_id;
channel_host_->AddRoute(instance_id_, this, false);
// Now tell the PluginInstance in the plugin process to initialize.
PluginMsg_Init_Params params;
params.containing_window = gfx::NativeViewFromId(render_view_->host_window());
params.url = url;
for (int i = 0; i < argc; ++i) {
params.arg_names.push_back(argn[i]);
params.arg_values.push_back(argv[i]);
if (LowerCaseEqualsASCII(params.arg_names.back(), "wmode") &&
LowerCaseEqualsASCII(params.arg_values.back(), "transparent")) {
transparent_ = true;
}
}
params.load_manually = load_manually;
params.modal_dialog_event = render_view_->modal_dialog_event()->handle();
plugin_ = plugin;
result = false;
IPC::Message* msg = new PluginMsg_Init(instance_id_, params, &result);
Send(msg);
return result;
}
bool WebPluginDelegateProxy::Send(IPC::Message* msg) {
if (!channel_host_) {
DLOG(WARNING) << "dropping message because channel host is null";
delete msg;
return false;
}
return channel_host_->Send(msg);
}
void WebPluginDelegateProxy::SendJavaScriptStream(const std::string& url,
const std::wstring& result,
bool success,
bool notify_needed,
int notify_data) {
PluginMsg_SendJavaScriptStream* msg =
new PluginMsg_SendJavaScriptStream(instance_id_, url, result,
success, notify_needed,
notify_data);
Send(msg);
}
void WebPluginDelegateProxy::DidReceiveManualResponse(
const std::string& url, const std::string& mime_type,
const std::string& headers, uint32 expected_length,
uint32 last_modified) {
PluginMsg_DidReceiveResponseParams params;
params.id = 0;
params.mime_type = mime_type;
params.headers = headers;
params.expected_length = expected_length;
params.last_modified = last_modified;
Send(new PluginMsg_DidReceiveManualResponse(instance_id_, url, params));
}
void WebPluginDelegateProxy::DidReceiveManualData(const char* buffer,
int length) {
DCHECK(length > 0);
std::vector<char> data;
data.resize(static_cast<size_t>(length));
memcpy(&data.front(), buffer, length);
Send(new PluginMsg_DidReceiveManualData(instance_id_, data));
}
void WebPluginDelegateProxy::DidFinishManualLoading() {
Send(new PluginMsg_DidFinishManualLoading(instance_id_));
}
void WebPluginDelegateProxy::DidManualLoadFail() {
Send(new PluginMsg_DidManualLoadFail(instance_id_));
}
FilePath WebPluginDelegateProxy::GetPluginPath() {
return plugin_path_;
}
void WebPluginDelegateProxy::InstallMissingPlugin() {
Send(new PluginMsg_InstallMissingPlugin(instance_id_));
}
void WebPluginDelegateProxy::OnMessageReceived(const IPC::Message& msg) {
IPC_BEGIN_MESSAGE_MAP(WebPluginDelegateProxy, msg)
IPC_MESSAGE_HANDLER(PluginHostMsg_SetWindow, OnSetWindow)
IPC_MESSAGE_HANDLER(PluginHostMsg_CancelResource, OnCancelResource)
IPC_MESSAGE_HANDLER(PluginHostMsg_InvalidateRect, OnInvalidateRect)
IPC_MESSAGE_HANDLER(PluginHostMsg_GetWindowScriptNPObject,
OnGetWindowScriptNPObject)
IPC_MESSAGE_HANDLER(PluginHostMsg_GetPluginElement,
OnGetPluginElement)
IPC_MESSAGE_HANDLER(PluginHostMsg_SetCookie, OnSetCookie)
IPC_MESSAGE_HANDLER(PluginHostMsg_GetCookies, OnGetCookies)
IPC_MESSAGE_HANDLER(PluginHostMsg_ShowModalHTMLDialog,
OnShowModalHTMLDialog)
IPC_MESSAGE_HANDLER(PluginHostMsg_MissingPluginStatus,
OnMissingPluginStatus)
IPC_MESSAGE_HANDLER(PluginHostMsg_URLRequest, OnHandleURLRequest)
IPC_MESSAGE_HANDLER(PluginHostMsg_GetCPBrowsingContext,
OnGetCPBrowsingContext)
IPC_MESSAGE_HANDLER(PluginHostMsg_CancelDocumentLoad, OnCancelDocumentLoad)
IPC_MESSAGE_HANDLER(PluginHostMsg_InitiateHTTPRangeRequest,
OnInitiateHTTPRangeRequest)
IPC_MESSAGE_UNHANDLED_ERROR()
IPC_END_MESSAGE_MAP()
}
void WebPluginDelegateProxy::OnChannelError() {
if (plugin_)
plugin_->Invalidate();
render_view_->PluginCrashed(plugin_path_);
}
void WebPluginDelegateProxy::UpdateGeometry(
const gfx::Rect& window_rect,
const gfx::Rect& clip_rect) {
plugin_rect_ = window_rect;
if (!windowless_) {
deferred_clip_rect_ = clip_rect;
send_deferred_update_geometry_ = true;
return;
}
HANDLE transport_store_handle = NULL;
HANDLE background_store_handle = NULL;
if (!backing_store_canvas_.get() ||
(window_rect.width() != backing_store_canvas_->getDevice()->width() ||
window_rect.height() != backing_store_canvas_->getDevice()->height())) {
// Create a shared memory section that the plugin paints into
// asynchronously.
ResetWindowlessBitmaps();
if (!window_rect.IsEmpty()) {
if (!CreateBitmap(&backing_store_, &backing_store_canvas_) ||
!CreateBitmap(&transport_store_, &transport_store_canvas_) ||
(transparent_ &&
!CreateBitmap(&background_store_, &background_store_canvas_))) {
DCHECK(false);
ResetWindowlessBitmaps();
return;
}
transport_store_handle = transport_store_->handle();
if (background_store_.get())
background_store_handle = background_store_->handle();
}
}
IPC::Message* msg = new PluginMsg_UpdateGeometry(
instance_id_, window_rect, clip_rect,
transport_store_handle, background_store_handle);
msg->set_unblock(true);
Send(msg);
}
// Copied from render_widget.cc
static size_t GetPaintBufSize(const gfx::Rect& rect) {
// TODO(darin): protect against overflow
return 4 * rect.width() * rect.height();
}
void WebPluginDelegateProxy::ResetWindowlessBitmaps() {
backing_store_.reset();
transport_store_.reset();
backing_store_canvas_.reset();
transport_store_canvas_.reset();
background_store_.reset();
background_store_canvas_.release();
backing_store_painted_ = gfx::Rect();
}
bool WebPluginDelegateProxy::CreateBitmap(
scoped_ptr<base::SharedMemory>* memory,
scoped_ptr<skia::PlatformCanvasWin>* canvas) {
size_t size = GetPaintBufSize(plugin_rect_);
scoped_ptr<base::SharedMemory> new_shared_memory(new base::SharedMemory());
if (!new_shared_memory->Create(L"", false, true, size))
return false;
scoped_ptr<skia::PlatformCanvasWin> new_canvas(new skia::PlatformCanvasWin);
if (!new_canvas->initialize(plugin_rect_.width(), plugin_rect_.height(),
true, new_shared_memory->handle())) {
return false;
}
memory->swap(new_shared_memory);
canvas->swap(new_canvas);
return true;
}
void WebPluginDelegateProxy::Paint(HDC hdc, const gfx::Rect& damaged_rect) {
// If the plugin is no longer connected (channel crashed) draw a crashed
// plugin bitmap
if (!channel_host_->channel_valid()) {
PaintSadPlugin(hdc, damaged_rect);
return;
}
// No paint events for windowed plugins.
if (!windowless_)
return;
// We got a paint before the plugin's coordinates, so there's no buffer to
// copy from.
if (!backing_store_canvas_.get())
return;
// Limit the damaged rectangle to whatever is contained inside the plugin
// rectangle, as that's the rectangle that we'll bitblt to the hdc.
gfx::Rect rect = damaged_rect.Intersect(plugin_rect_);
bool background_changed = false;
if (background_store_canvas_.get() && BackgroundChanged(hdc, rect)) {
background_changed = true;
HDC background_hdc =
background_store_canvas_->getTopPlatformDevice().getBitmapDC();
BitBlt(background_hdc, rect.x()-plugin_rect_.x(), rect.y()-plugin_rect_.y(),
rect.width(), rect.height(), hdc, rect.x(), rect.y(), SRCCOPY);
}
gfx::Rect offset_rect = rect;
offset_rect.Offset(-plugin_rect_.x(), -plugin_rect_.y());
if (background_changed || !backing_store_painted_.Contains(offset_rect)) {
Send(new PluginMsg_Paint(instance_id_, offset_rect));
CopyFromTransportToBacking(offset_rect);
}
HDC backing_hdc = backing_store_canvas_->getTopPlatformDevice().getBitmapDC();
BitBlt(hdc, rect.x(), rect.y(), rect.width(), rect.height(), backing_hdc,
rect.x()-plugin_rect_.x(), rect.y()-plugin_rect_.y(), SRCCOPY);
if (invalidate_pending_) {
// Only send the PaintAck message if this paint is in response to an
// invalidate from the plugin, since this message acts as an access token
// to ensure only one process is using the transport dib at a time.
invalidate_pending_ = false;
Send(new PluginMsg_DidPaint(instance_id_));
}
}
bool WebPluginDelegateProxy::BackgroundChanged(
HDC hdc,
const gfx::Rect& rect) {
HBITMAP hbitmap = static_cast<HBITMAP>(GetCurrentObject(hdc, OBJ_BITMAP));
if (hbitmap == NULL) {
NOTREACHED();
return true;
}
BITMAP bitmap = { 0 };
int result = GetObject(hbitmap, sizeof(bitmap), &bitmap);
if (!result) {
NOTREACHED();
return true;
}
XFORM xf;
if (!GetWorldTransform(hdc, &xf)) {
NOTREACHED();
return true;
}
// The damaged rect that we're given can be larger than the bitmap, so
// intersect their rects first.
gfx::Rect bitmap_rect(static_cast<int>(-xf.eDx), static_cast<int>(-xf.eDy),
bitmap.bmWidth, bitmap.bmHeight);
gfx::Rect check_rect = rect.Intersect(bitmap_rect);
int row_byte_size = check_rect.width() * (bitmap.bmBitsPixel / 8);
for (int y = check_rect.y(); y < check_rect.bottom(); y++) {
char* hdc_row_start = static_cast<char*>(bitmap.bmBits) +
(y + static_cast<int>(xf.eDy)) * bitmap.bmWidthBytes +
(check_rect.x() + static_cast<int>(xf.eDx)) * (bitmap.bmBitsPixel / 8);
// getAddr32 doesn't use the translation units, so we have to subtract
// the plugin origin from the coordinates.
uint32_t* canvas_row_start =
background_store_canvas_->getDevice()->accessBitmap(true).getAddr32(
check_rect.x() - plugin_rect_.x(), y - plugin_rect_.y());
if (memcmp(hdc_row_start, canvas_row_start, row_byte_size) != 0)
return true;
}
return false;
}
void WebPluginDelegateProxy::Print(HDC hdc) {
PluginMsg_PrintResponse_Params params = { 0 };
Send(new PluginMsg_Print(instance_id_, ¶ms));
base::SharedMemory memory(params.shared_memory, true);
if (!memory.Map(params.size)) {
NOTREACHED();
return;
}
gfx::Emf emf;
if (!emf.CreateFromData(memory.memory(), params.size)) {
NOTREACHED();
return;
}
// Playback the buffer.
emf.Playback(hdc, NULL);
}
NPObject* WebPluginDelegateProxy::GetPluginScriptableObject() {
if (npobject_)
return NPN_RetainObject(npobject_);
int route_id = MSG_ROUTING_NONE;
void* npobject_ptr;
Send(new PluginMsg_GetPluginScriptableObject(
instance_id_, &route_id, &npobject_ptr));
if (route_id == MSG_ROUTING_NONE)
return NULL;
npobject_ = NPObjectProxy::Create(
channel_host_.get(), route_id, npobject_ptr,
render_view_->modal_dialog_event());
return NPN_RetainObject(npobject_);
}
void WebPluginDelegateProxy::DidFinishLoadWithReason(NPReason reason) {
Send(new PluginMsg_DidFinishLoadWithReason(instance_id_, reason));
}
void WebPluginDelegateProxy::SetFocus() {
Send(new PluginMsg_SetFocus(instance_id_));
}
bool WebPluginDelegateProxy::HandleEvent(NPEvent* event, WebCursor* cursor) {
bool handled;
// A windowless plugin can enter a modal loop in the context of a
// NPP_HandleEvent call, in which case we need to pump messages to
// the plugin. We pass of the corresponding event handle to the
// plugin process, which is set if the plugin does enter a modal loop.
IPC::SyncMessage* message = new PluginMsg_HandleEvent(instance_id_,
*event, &handled,
cursor);
message->set_pump_messages_event(modal_loop_pump_messages_event_.get());
Send(message);
return handled;
}
int WebPluginDelegateProxy::GetProcessId() {
return channel_host_->peer_pid();
}
void WebPluginDelegateProxy::OnSetWindow(
HWND window, HANDLE modal_loop_pump_messages_event) {
windowless_ = window == NULL;
if (plugin_)
plugin_->SetWindow(window, modal_loop_pump_messages_event);
DCHECK(modal_loop_pump_messages_event_ == NULL);
if (modal_loop_pump_messages_event) {
modal_loop_pump_messages_event_.reset(
new base::WaitableEvent(modal_loop_pump_messages_event));
} else {
modal_loop_pump_messages_event_.reset();
}
}
void WebPluginDelegateProxy::OnCancelResource(int id) {
if (plugin_)
plugin_->CancelResource(id);
}
void WebPluginDelegateProxy::OnInvalidateRect(const gfx::Rect& rect) {
if (!plugin_)
return;
invalidate_pending_ = true;
CopyFromTransportToBacking(rect);
plugin_->InvalidateRect(rect);
}
void WebPluginDelegateProxy::OnGetWindowScriptNPObject(
int route_id, bool* success, void** npobject_ptr) {
*success = false;
NPObject* npobject = NULL;
if (plugin_)
npobject = plugin_->GetWindowScriptNPObject();
if (!npobject)
return;
// The stub will delete itself when the proxy tells it that it's released, or
// otherwise when the channel is closed.
NPObjectStub* stub = new NPObjectStub(
npobject, channel_host_.get(), route_id,
render_view_->modal_dialog_event());
window_script_object_ = stub;
window_script_object_->set_proxy(this);
*success = true;
*npobject_ptr = npobject;
}
void WebPluginDelegateProxy::OnGetPluginElement(
int route_id, bool* success, void** npobject_ptr) {
*success = false;
NPObject* npobject = NULL;
if (plugin_)
npobject = plugin_->GetPluginElement();
if (!npobject)
return;
// The stub will delete itself when the proxy tells it that it's released, or
// otherwise when the channel is closed.
NPObjectStub* stub = new NPObjectStub(
npobject, channel_host_.get(), route_id,
render_view_->modal_dialog_event());
*success = true;
*npobject_ptr = npobject;
}
void WebPluginDelegateProxy::OnSetCookie(const GURL& url,
const GURL& policy_url,
const std::string& cookie) {
if (plugin_)
plugin_->SetCookie(url, policy_url, cookie);
}
void WebPluginDelegateProxy::OnGetCookies(const GURL& url,
const GURL& policy_url,
std::string* cookies) {
DCHECK(cookies);
if (plugin_)
*cookies = plugin_->GetCookies(url, policy_url);
}
void WebPluginDelegateProxy::OnShowModalHTMLDialog(
const GURL& url, int width, int height, const std::string& json_arguments,
std::string* json_retval) {
DCHECK(json_retval);
if (render_view_)
render_view_->ShowModalHTMLDialog(url, width, height, json_arguments,
json_retval);
}
void WebPluginDelegateProxy::OnMissingPluginStatus(int status) {
if (render_view_)
render_view_->OnMissingPluginStatus(this, status);
}
void WebPluginDelegateProxy::OnGetCPBrowsingContext(uint32* context) {
*context = render_view_ ? render_view_->GetCPBrowsingContext() : 0;
}
void WebPluginDelegateProxy::PaintSadPlugin(HDC hdc, const gfx::Rect& rect) {
const int width = plugin_rect_.width();
const int height = plugin_rect_.height();
ChromeCanvas canvas(width, height, false);
SkPaint paint;
paint.setStyle(SkPaint::kFill_Style);
paint.setColor(SK_ColorBLACK);
canvas.drawRectCoords(0, 0, SkIntToScalar(width), SkIntToScalar(height),
paint);
if (!sad_plugin_) {
sad_plugin_ = ResourceBundle::GetSharedInstance().GetBitmapNamed(
IDR_SAD_PLUGIN);
}
if (sad_plugin_) {
canvas.DrawBitmapInt(*sad_plugin_,
std::max(0, (width - sad_plugin_->width())/2),
std::max(0, (height - sad_plugin_->height())/2));
}
canvas.getTopPlatformDevice().drawToHDC(
hdc, plugin_rect_.x(), plugin_rect_.y(), NULL);
return;
}
void WebPluginDelegateProxy::CopyFromTransportToBacking(const gfx::Rect& rect) {
if (!backing_store_canvas_.get())
return;
// Copy the damaged rect from the transport bitmap to the backing store.
HDC backing = backing_store_canvas_->getTopPlatformDevice().getBitmapDC();
HDC transport = transport_store_canvas_->getTopPlatformDevice().getBitmapDC();
BitBlt(backing, rect.x(), rect.y(), rect.width(), rect.height(),
transport, rect.x(), rect.y(), SRCCOPY);
backing_store_painted_ = backing_store_painted_.Union(rect);
}
void WebPluginDelegateProxy::OnHandleURLRequest(
const PluginHostMsg_URLRequest_Params& params) {
const char* data = NULL;
if (params.buffer.size())
data = ¶ms.buffer[0];
const char* target = NULL;
if (params.target.length())
target = params.target.c_str();
plugin_->HandleURLRequest(params.method.c_str(),
params.is_javascript_url, target,
static_cast<unsigned int>(params.buffer.size()),
data, params.is_file_data, params.notify,
params.url.c_str(), params.notify_data,
params.popups_allowed);
}
WebPluginResourceClient* WebPluginDelegateProxy::CreateResourceClient(
int resource_id, const std::string &url, bool notify_needed,
void* notify_data, void* npstream) {
ResourceClientProxy* proxy = new ResourceClientProxy(channel_host_,
instance_id_);
proxy->Initialize(resource_id, url, notify_needed, notify_data, npstream);
return proxy;
}
void WebPluginDelegateProxy::URLRequestRouted(const std::string& url,
bool notify_needed,
void* notify_data) {
Send(new PluginMsg_URLRequestRouted(instance_id_, url, notify_needed,
notify_data));
}
void WebPluginDelegateProxy::OnCancelDocumentLoad() {
plugin_->CancelDocumentLoad();
}
void WebPluginDelegateProxy::OnInitiateHTTPRangeRequest(
const std::string& url, const std::string& range_info,
HANDLE existing_stream, bool notify_needed, HANDLE notify_data) {
plugin_->InitiateHTTPRangeRequest(url.c_str(), range_info.c_str(),
existing_stream, notify_needed,
notify_data);
}
|