Bug 1610630 [wpt PR 21320] - Add meta:timeout=long to FileSystemBaseHandle-postMessag...
[gecko.git] / widget / PluginWidgetProxy.cpp
bloba12cc164e39339fceaf172842260132bc4afea0d
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"
9 #include "nsDebug.h"
11 #define PWLOG(...)
12 // #define PWLOG(...) printf_stderr(__VA_ARGS__)
14 /* static */
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();
22 namespace mozilla {
23 namespace widget {
25 using mozilla::plugins::PluginInstanceParent;
27 NS_IMPL_ISUPPORTS_INHERITED(PluginWidgetProxy, PuppetWidget, nsIWidget)
29 #define ENSURE_CHANNEL \
30 do { \
31 if (!mActor) { \
32 NS_WARNING("called on an invalid channel."); \
33 return NS_ERROR_FAILURE; \
34 } \
35 } while (0)
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) {
53 ENSURE_CHANNEL;
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);
60 if (NS_FAILED(rv)) {
61 NS_WARNING("failed to create chrome widget, plugins won't paint.");
62 return rv;
65 BaseCreate(aParent, aInitData);
66 mParent = aParent;
68 mBounds = aRect;
69 mEnabled = true;
70 mVisible = true;
72 PluginInstanceParent* instance =
73 PluginInstanceParent::LookupPluginInstanceByID(pluginInstanceId);
74 if (instance) {
75 Unused << NS_WARN_IF(
76 NS_FAILED(instance->SetScrollCaptureId(scrollCaptureId)));
79 return NS_OK;
82 void PluginWidgetProxy::SetParent(nsIWidget* aNewParent) {
83 nsCOMPtr<nsIWidget> kungFuDeathGrip(this);
84 nsIWidget* parent = GetParent();
85 if (parent) {
86 parent->RemoveChild(this);
88 if (aNewParent) {
89 aNewParent->AddChild(this);
91 mParent = aNewParent;
94 nsIWidget* PluginWidgetProxy::GetParent(void) { return mParent.get(); }
96 void PluginWidgetProxy::Destroy() {
97 PWLOG("PluginWidgetProxy::Destroy()\n");
99 if (mActor) {
100 // Communicate that the layout widget has been torn down before the sub
101 // protocol.
102 mActor->ProxyShutdown();
103 mActor = nullptr;
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) {
117 if (!mActor) {
118 return nullptr;
120 auto tab = static_cast<mozilla::dom::BrowserChild*>(mActor->Manager());
121 if (tab && tab->IsDestroyed()) {
122 return nullptr;
124 switch (aDataType) {
125 case NS_NATIVE_PLUGIN_PORT:
126 case NS_NATIVE_WINDOW:
127 case NS_NATIVE_SHAREABLE_WINDOW:
128 break;
129 default:
130 NS_WARNING(
131 "PluginWidgetProxy::GetNativeData received request for unsupported "
132 "data type.");
133 return nullptr;
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) {
146 if (!mActor) {
147 return;
150 auto tab = static_cast<mozilla::dom::BrowserChild*>(mActor->Manager());
151 if (tab && tab->IsDestroyed()) {
152 return;
155 switch (aDataType) {
156 case NS_NATIVE_CHILD_WINDOW:
157 mActor->SendSetNativeChildWindow(aVal);
158 break;
159 default:
160 NS_ERROR("SetNativeData called with unsupported data type.");
164 void PluginWidgetProxy::SetFocus(Raise aRaise,
165 mozilla::dom::CallerType aCallerType) {
166 if (mActor) {
167 PWLOG("PluginWidgetProxy::SetFocus(%d)\n", aRaise == Raise::Yes);
168 mActor->SendSetFocus(aRaise == Raise::Yes, aCallerType);
172 } // namespace widget
173 } // namespace mozilla