1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "PluginWidgetProxy.h"
6 #include "mozilla/dom/BrowserChild.h"
7 #include "mozilla/plugins/PluginWidgetChild.h"
8 #include "mozilla/plugins/PluginInstanceParent.h"
12 // #define PWLOG(...) printf_stderr(__VA_ARGS__)
15 already_AddRefed
<nsIWidget
> nsIWidget::CreatePluginProxyWidget(
16 BrowserChild
* aBrowserChild
, mozilla::plugins::PluginWidgetChild
* aActor
) {
17 nsCOMPtr
<nsIWidget
> widget
=
18 new mozilla::widget::PluginWidgetProxy(aBrowserChild
, aActor
);
19 return widget
.forget();
25 using mozilla::plugins::PluginInstanceParent
;
27 NS_IMPL_ISUPPORTS_INHERITED(PluginWidgetProxy
, PuppetWidget
, nsIWidget
)
29 #define ENSURE_CHANNEL \
32 NS_WARNING("called on an invalid channel."); \
33 return NS_ERROR_FAILURE; \
37 PluginWidgetProxy::PluginWidgetProxy(
38 dom::BrowserChild
* aBrowserChild
,
39 mozilla::plugins::PluginWidgetChild
* aActor
)
40 : PuppetWidget(aBrowserChild
), mActor(aActor
), mCachedPluginPort(0) {
41 // See ChannelDestroyed() in the header
42 mActor
->SetWidget(this);
45 PluginWidgetProxy::~PluginWidgetProxy() {
46 PWLOG("PluginWidgetProxy::~PluginWidgetProxy()\n");
49 nsresult
PluginWidgetProxy::Create(nsIWidget
* aParent
,
50 nsNativeWidget aNativeParent
,
51 const LayoutDeviceIntRect
& aRect
,
52 nsWidgetInitData
* aInitData
) {
54 PWLOG("PluginWidgetProxy::Create()\n");
56 nsresult rv
= NS_ERROR_UNEXPECTED
;
57 uint64_t scrollCaptureId
;
58 uintptr_t pluginInstanceId
;
59 mActor
->SendCreate(&rv
, &scrollCaptureId
, &pluginInstanceId
);
61 NS_WARNING("failed to create chrome widget, plugins won't paint.");
65 BaseCreate(aParent
, aInitData
);
72 PluginInstanceParent
* instance
=
73 PluginInstanceParent::LookupPluginInstanceByID(pluginInstanceId
);
76 NS_FAILED(instance
->SetScrollCaptureId(scrollCaptureId
)));
82 void PluginWidgetProxy::SetParent(nsIWidget
* aNewParent
) {
83 nsCOMPtr
<nsIWidget
> kungFuDeathGrip(this);
84 nsIWidget
* parent
= GetParent();
86 parent
->RemoveChild(this);
89 aNewParent
->AddChild(this);
94 nsIWidget
* PluginWidgetProxy::GetParent(void) { return mParent
.get(); }
96 void PluginWidgetProxy::Destroy() {
97 PWLOG("PluginWidgetProxy::Destroy()\n");
100 // Communicate that the layout widget has been torn down before the sub
102 mActor
->ProxyShutdown();
106 PuppetWidget::Destroy();
109 void PluginWidgetProxy::GetWindowClipRegion(
110 nsTArray
<LayoutDeviceIntRect
>* aRects
) {
111 if (mClipRects
&& mClipRectCount
) {
112 aRects
->AppendElements(mClipRects
.get(), mClipRectCount
);
116 void* PluginWidgetProxy::GetNativeData(uint32_t aDataType
) {
120 auto tab
= static_cast<mozilla::dom::BrowserChild
*>(mActor
->Manager());
121 if (tab
&& tab
->IsDestroyed()) {
125 case NS_NATIVE_PLUGIN_PORT
:
126 case NS_NATIVE_WINDOW
:
127 case NS_NATIVE_SHAREABLE_WINDOW
:
131 "PluginWidgetProxy::GetNativeData received request for unsupported "
135 // The parent side window handle or xid never changes so we can
136 // cache this for our lifetime.
137 if (mCachedPluginPort
) {
138 return (void*)mCachedPluginPort
;
140 mActor
->SendGetNativePluginPort(&mCachedPluginPort
);
141 PWLOG("PluginWidgetProxy::GetNativeData %p\n", (void*)mCachedPluginPort
);
142 return (void*)mCachedPluginPort
;
145 void PluginWidgetProxy::SetNativeData(uint32_t aDataType
, uintptr_t aVal
) {
150 auto tab
= static_cast<mozilla::dom::BrowserChild
*>(mActor
->Manager());
151 if (tab
&& tab
->IsDestroyed()) {
156 case NS_NATIVE_CHILD_WINDOW
:
157 mActor
->SendSetNativeChildWindow(aVal
);
160 NS_ERROR("SetNativeData called with unsupported data type.");
164 void PluginWidgetProxy::SetFocus(Raise aRaise
,
165 mozilla::dom::CallerType aCallerType
) {
167 PWLOG("PluginWidgetProxy::SetFocus(%d)\n", aRaise
== Raise::Yes
);
168 mActor
->SendSetFocus(aRaise
== Raise::Yes
, aCallerType
);
172 } // namespace widget
173 } // namespace mozilla