Bug 1477919 [wpt PR 12154] - url: DecodeURLEscapeSequences() should not apply UTF...
[gecko.git] / widget / PluginWidgetProxy.cpp
blob638321241041ec972f30d9e8b0e949975346b113
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"
9 #include "nsDebug.h"
11 #define PWLOG(...)
12 // #define PWLOG(...) printf_stderr(__VA_ARGS__)
14 /* static */
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();
24 namespace mozilla {
25 namespace widget {
27 using mozilla::plugins::PluginInstanceParent;
29 NS_IMPL_ISUPPORTS_INHERITED(PluginWidgetProxy, PuppetWidget, nsIWidget)
31 #define ENSURE_CHANNEL do { \
32 if (!mActor) { \
33 NS_WARNING("called on an invalid channel."); \
34 return NS_ERROR_FAILURE; \
35 } \
36 } while (0)
38 PluginWidgetProxy::PluginWidgetProxy(dom::TabChild* aTabChild,
39 mozilla::plugins::PluginWidgetChild* aActor) :
40 PuppetWidget(aTabChild),
41 mActor(aActor),
42 mCachedPluginPort(0)
44 // See ChannelDestroyed() in the header
45 mActor->SetWidget(this);
48 PluginWidgetProxy::~PluginWidgetProxy()
50 PWLOG("PluginWidgetProxy::~PluginWidgetProxy()\n");
53 nsresult
54 PluginWidgetProxy::Create(nsIWidget* aParent,
55 nsNativeWidget aNativeParent,
56 const LayoutDeviceIntRect& aRect,
57 nsWidgetInitData* aInitData)
59 ENSURE_CHANNEL;
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);
66 if (NS_FAILED(rv)) {
67 NS_WARNING("failed to create chrome widget, plugins won't paint.");
68 return rv;
71 BaseCreate(aParent, aInitData);
72 mParent = aParent;
74 mBounds = aRect;
75 mEnabled = true;
76 mVisible = true;
78 PluginInstanceParent* instance =
79 PluginInstanceParent::LookupPluginInstanceByID(pluginInstanceId);
80 if (instance) {
81 Unused << NS_WARN_IF(NS_FAILED(instance->SetScrollCaptureId(scrollCaptureId)));
84 return NS_OK;
87 void
88 PluginWidgetProxy::SetParent(nsIWidget* aNewParent)
90 nsCOMPtr<nsIWidget> kungFuDeathGrip(this);
91 nsIWidget* parent = GetParent();
92 if (parent) {
93 parent->RemoveChild(this);
95 if (aNewParent) {
96 aNewParent->AddChild(this);
98 mParent = aNewParent;
101 nsIWidget*
102 PluginWidgetProxy::GetParent(void)
104 return mParent.get();
107 void
108 PluginWidgetProxy::Destroy()
110 PWLOG("PluginWidgetProxy::Destroy()\n");
112 if (mActor) {
113 // Communicate that the layout widget has been torn down before the sub
114 // protocol.
115 mActor->ProxyShutdown();
116 mActor = nullptr;
119 PuppetWidget::Destroy();
122 void
123 PluginWidgetProxy::GetWindowClipRegion(nsTArray<LayoutDeviceIntRect>* aRects)
125 if (mClipRects && mClipRectCount) {
126 aRects->AppendElements(mClipRects.get(), mClipRectCount);
130 void*
131 PluginWidgetProxy::GetNativeData(uint32_t aDataType)
133 if (!mActor) {
134 return nullptr;
136 auto tab = static_cast<mozilla::dom::TabChild*>(mActor->Manager());
137 if (tab && tab->IsDestroyed()) {
138 return nullptr;
140 switch (aDataType) {
141 case NS_NATIVE_PLUGIN_PORT:
142 case NS_NATIVE_WINDOW:
143 case NS_NATIVE_SHAREABLE_WINDOW:
144 break;
145 default:
146 NS_WARNING("PluginWidgetProxy::GetNativeData received request for unsupported data type.");
147 return nullptr;
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;
159 void
160 PluginWidgetProxy::SetNativeData(uint32_t aDataType, uintptr_t aVal)
162 if (!mActor) {
163 return;
166 auto tab = static_cast<mozilla::dom::TabChild*>(mActor->Manager());
167 if (tab && tab->IsDestroyed()) {
168 return;
171 switch (aDataType) {
172 case NS_NATIVE_CHILD_WINDOW:
173 mActor->SendSetNativeChildWindow(aVal);
174 break;
175 default:
176 NS_ERROR("SetNativeData called with unsupported data type.");
180 nsresult
181 PluginWidgetProxy::SetFocus(bool aRaise)
183 ENSURE_CHANNEL;
184 PWLOG("PluginWidgetProxy::SetFocus(%d)\n", aRaise);
185 mActor->SendSetFocus(aRaise);
186 return NS_OK;
189 } // namespace widget
190 } // namespace mozilla