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/TabChild.h"
7 #include "mozilla/plugins/PluginWidgetChild.h"
8 #include "mozilla/plugins/PluginInstanceParent.h"
12 // #define PWLOG(...) printf_stderr(__VA_ARGS__)
15 already_AddRefed
<nsIWidget
>
16 nsIWidget::CreatePluginProxyWidget(TabChild
* aTabChild
,
17 mozilla::plugins::PluginWidgetChild
* aActor
)
19 nsCOMPtr
<nsIWidget
> widget
=
20 new mozilla::widget::PluginWidgetProxy(aTabChild
, aActor
);
21 return widget
.forget();
27 using mozilla::plugins::PluginInstanceParent
;
29 NS_IMPL_ISUPPORTS_INHERITED(PluginWidgetProxy
, PuppetWidget
, nsIWidget
)
31 #define ENSURE_CHANNEL do { \
33 NS_WARNING("called on an invalid channel."); \
34 return NS_ERROR_FAILURE; \
38 PluginWidgetProxy::PluginWidgetProxy(dom::TabChild
* aTabChild
,
39 mozilla::plugins::PluginWidgetChild
* aActor
) :
40 PuppetWidget(aTabChild
),
44 // See ChannelDestroyed() in the header
45 mActor
->SetWidget(this);
48 PluginWidgetProxy::~PluginWidgetProxy()
50 PWLOG("PluginWidgetProxy::~PluginWidgetProxy()\n");
54 PluginWidgetProxy::Create(nsIWidget
* aParent
,
55 nsNativeWidget aNativeParent
,
56 const LayoutDeviceIntRect
& aRect
,
57 nsWidgetInitData
* aInitData
)
60 PWLOG("PluginWidgetProxy::Create()\n");
62 nsresult rv
= NS_ERROR_UNEXPECTED
;
63 uint64_t scrollCaptureId
;
64 uintptr_t pluginInstanceId
;
65 mActor
->SendCreate(&rv
, &scrollCaptureId
, &pluginInstanceId
);
67 NS_WARNING("failed to create chrome widget, plugins won't paint.");
71 BaseCreate(aParent
, aInitData
);
78 PluginInstanceParent
* instance
=
79 PluginInstanceParent::LookupPluginInstanceByID(pluginInstanceId
);
81 Unused
<< NS_WARN_IF(NS_FAILED(instance
->SetScrollCaptureId(scrollCaptureId
)));
88 PluginWidgetProxy::SetParent(nsIWidget
* aNewParent
)
90 nsCOMPtr
<nsIWidget
> kungFuDeathGrip(this);
91 nsIWidget
* parent
= GetParent();
93 parent
->RemoveChild(this);
96 aNewParent
->AddChild(this);
102 PluginWidgetProxy::GetParent(void)
104 return mParent
.get();
108 PluginWidgetProxy::Destroy()
110 PWLOG("PluginWidgetProxy::Destroy()\n");
113 // Communicate that the layout widget has been torn down before the sub
115 mActor
->ProxyShutdown();
119 PuppetWidget::Destroy();
123 PluginWidgetProxy::GetWindowClipRegion(nsTArray
<LayoutDeviceIntRect
>* aRects
)
125 if (mClipRects
&& mClipRectCount
) {
126 aRects
->AppendElements(mClipRects
.get(), mClipRectCount
);
131 PluginWidgetProxy::GetNativeData(uint32_t aDataType
)
136 auto tab
= static_cast<mozilla::dom::TabChild
*>(mActor
->Manager());
137 if (tab
&& tab
->IsDestroyed()) {
141 case NS_NATIVE_PLUGIN_PORT
:
142 case NS_NATIVE_WINDOW
:
143 case NS_NATIVE_SHAREABLE_WINDOW
:
146 NS_WARNING("PluginWidgetProxy::GetNativeData received request for unsupported data type.");
149 // The parent side window handle or xid never changes so we can
150 // cache this for our lifetime.
151 if (mCachedPluginPort
) {
152 return (void*)mCachedPluginPort
;
154 mActor
->SendGetNativePluginPort(&mCachedPluginPort
);
155 PWLOG("PluginWidgetProxy::GetNativeData %p\n", (void*)mCachedPluginPort
);
156 return (void*)mCachedPluginPort
;
160 PluginWidgetProxy::SetNativeData(uint32_t aDataType
, uintptr_t aVal
)
166 auto tab
= static_cast<mozilla::dom::TabChild
*>(mActor
->Manager());
167 if (tab
&& tab
->IsDestroyed()) {
172 case NS_NATIVE_CHILD_WINDOW
:
173 mActor
->SendSetNativeChildWindow(aVal
);
176 NS_ERROR("SetNativeData called with unsupported data type.");
181 PluginWidgetProxy::SetFocus(bool aRaise
)
184 PWLOG("PluginWidgetProxy::SetFocus(%d)\n", aRaise
);
185 mActor
->SendSetFocus(aRaise
);
189 } // namespace widget
190 } // namespace mozilla