Files
palemoon27/widget/PluginWidgetProxy.cpp
roytam1 07da6b90ed import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1248822 - In LayerManagerComposite::UpdateAndRender(), call PostProcessLayers() before LayerTreeInvalidation. r=mattwoodrow (503f81f51f)
- Bug 1259541 - Reduce clearing backbuffer in nsBaseWidget::CreateBackBufferDrawTarget() r=mattwoodrow (4f8cf8ab04)
- Bug 1174461 - [e10s] Return a cached result from SendGetNativePluginPort (r=jimm) a=kwierso (fff65b95ac)
- Bug 1263200 - Reset the APZ pointer in the base widget to null if the compositor creation fails. r=mstange (109d4a16a8)
- Bug 1264161 - Ensure we null out APZ pointers to the widget when it gets destroyed. r=botond (fdb516451e)
- Bug 1260018 - Route drag events to APZ, so it can accurately detect the end of a drag. r=kats (acd2b4a051)
- Remove drawWidgetAsOnScreen. (bug 1264393, r=mattwoodrow, webidl r=khuey) (b0ce23eacc)
- Bug 1254151 - use B8G8R8X8 for 24 bit depth visuals in nsShmImage with Cairo. r=jrmuizel (070ef9495d)
- Bug 1218955 - Remove nsIMEPicker, r=jchen (83adb6c582)
- Bug 1255655 - Const-ify keysymtab. r=karlt. (d9544cbf0c)
- Bug 1165048 - Music playback is getting stopped and is not resumed when modem is restarted. r=mwu (d3f99f8542)
- Bug 1264183. Remove unused argument to nsView::InvalidateHierarchy. r=mats (218ce04623)
- Bug 1210617 - [e10s] Implement PrivateBrowsingChannel for ExternalHelperAppParent. r=jduell (36e6ab7635)
- Bug 1258087 - Fix -Wunreachable-code warning in StartupCache.cpp on macosx64-mulet. r=froydnj (5f88df6993)
- Bug 1329798 - Include sys/sysmacros.h for major(), minor() on Linux. r=glandium, a=jcristau (a5c4073eb2)
- guard for non-linux system again or mac & FreeBSD fail to compile (6b5d2856b6)
2024-05-30 14:34:55 +08:00

183 lines
4.4 KiB
C++

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "PluginWidgetProxy.h"
#include "mozilla/dom/TabChild.h"
#include "mozilla/plugins/PluginWidgetChild.h"
#include "nsDebug.h"
#define PWLOG(...)
// #define PWLOG(...) printf_stderr(__VA_ARGS__)
/* static */
already_AddRefed<nsIWidget>
nsIWidget::CreatePluginProxyWidget(TabChild* aTabChild,
mozilla::plugins::PluginWidgetChild* aActor)
{
nsCOMPtr<nsIWidget> widget =
new mozilla::widget::PluginWidgetProxy(aTabChild, aActor);
return widget.forget();
}
namespace mozilla {
namespace widget {
NS_IMPL_ISUPPORTS_INHERITED(PluginWidgetProxy, PuppetWidget, nsIWidget)
#define ENSURE_CHANNEL do { \
if (!mActor) { \
NS_WARNING("called on an invalid channel."); \
return NS_ERROR_FAILURE; \
} \
} while (0)
PluginWidgetProxy::PluginWidgetProxy(dom::TabChild* aTabChild,
mozilla::plugins::PluginWidgetChild* aActor) :
PuppetWidget(aTabChild),
mActor(aActor),
mCachedPluginPort(0)
{
// See ChannelDestroyed() in the header
mActor->SetWidget(this);
}
PluginWidgetProxy::~PluginWidgetProxy()
{
PWLOG("PluginWidgetProxy::~PluginWidgetProxy()\n");
}
NS_IMETHODIMP
PluginWidgetProxy::Create(nsIWidget* aParent,
nsNativeWidget aNativeParent,
const LayoutDeviceIntRect& aRect,
nsWidgetInitData* aInitData)
{
ENSURE_CHANNEL;
PWLOG("PluginWidgetProxy::Create()\n");
nsresult rv = NS_ERROR_UNEXPECTED;
mActor->SendCreate(&rv);
if (NS_FAILED(rv)) {
NS_WARNING("failed to create chrome widget, plugins won't paint.");
return rv;
}
BaseCreate(aParent, aInitData);
mParent = aParent;
mBounds = aRect;
mEnabled = true;
mVisible = true;
return NS_OK;
}
NS_IMETHODIMP
PluginWidgetProxy::SetParent(nsIWidget* aNewParent)
{
nsCOMPtr<nsIWidget> kungFuDeathGrip(this);
nsIWidget* parent = GetParent();
if (parent) {
parent->RemoveChild(this);
}
if (aNewParent) {
aNewParent->AddChild(this);
}
mParent = aNewParent;
return NS_OK;
}
nsIWidget*
PluginWidgetProxy::GetParent(void)
{
return mParent.get();
}
NS_IMETHODIMP
PluginWidgetProxy::Destroy()
{
PWLOG("PluginWidgetProxy::Destroy()\n");
if (mActor) {
// Communicate that the layout widget has been torn down before the sub
// protocol.
mActor->ProxyShutdown();
mActor = nullptr;
}
return PuppetWidget::Destroy();
}
void
PluginWidgetProxy::GetWindowClipRegion(nsTArray<LayoutDeviceIntRect>* aRects)
{
if (mClipRects && mClipRectCount) {
aRects->AppendElements(mClipRects.get(), mClipRectCount);
}
}
void*
PluginWidgetProxy::GetNativeData(uint32_t aDataType)
{
if (!mActor) {
return nullptr;
}
auto tab = static_cast<mozilla::dom::TabChild*>(mActor->Manager());
if (tab && tab->IsDestroyed()) {
return nullptr;
}
switch (aDataType) {
case NS_NATIVE_PLUGIN_PORT:
case NS_NATIVE_WINDOW:
case NS_NATIVE_SHAREABLE_WINDOW:
break;
default:
NS_WARNING("PluginWidgetProxy::GetNativeData received request for unsupported data type.");
return nullptr;
}
// The parent side window handle or xid never changes so we can
// cache this for our lifetime.
if (mCachedPluginPort) {
return (void*)mCachedPluginPort;
}
mActor->SendGetNativePluginPort(&mCachedPluginPort);
PWLOG("PluginWidgetProxy::GetNativeData %p\n", (void*)mCachedPluginPort);
return (void*)mCachedPluginPort;
}
#if defined(XP_WIN)
void
PluginWidgetProxy::SetNativeData(uint32_t aDataType, uintptr_t aVal)
{
if (!mActor) {
return;
}
auto tab = static_cast<mozilla::dom::TabChild*>(mActor->Manager());
if (tab && tab->IsDestroyed()) {
return;
}
switch (aDataType) {
case NS_NATIVE_CHILD_WINDOW:
mActor->SendSetNativeChildWindow(aVal);
break;
default:
NS_ERROR("SetNativeData called with unsupported data type.");
}
}
#endif
NS_IMETHODIMP
PluginWidgetProxy::SetFocus(bool aRaise)
{
ENSURE_CHANNEL;
PWLOG("PluginWidgetProxy::SetFocus(%d)\n", aRaise);
mActor->SendSetFocus(aRaise);
return NS_OK;
}
} // namespace widget
} // namespace mozilla