2014-11-12 23:59:20 +03:00
|
|
|
/* 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"
|
2019-04-10 01:39:01 +03:00
|
|
|
#include "mozilla/dom/BrowserChild.h"
|
2014-11-12 23:59:20 +03:00
|
|
|
#include "mozilla/plugins/PluginWidgetChild.h"
|
2016-10-05 18:36:26 +03:00
|
|
|
#include "mozilla/plugins/PluginInstanceParent.h"
|
2014-11-12 23:59:20 +03:00
|
|
|
#include "nsDebug.h"
|
|
|
|
|
2015-01-22 16:20:13 +03:00
|
|
|
#define PWLOG(...)
|
2014-11-12 23:59:20 +03:00
|
|
|
// #define PWLOG(...) printf_stderr(__VA_ARGS__)
|
|
|
|
|
|
|
|
/* static */
|
|
|
|
already_AddRefed<nsIWidget> nsIWidget::CreatePluginProxyWidget(
|
2019-04-10 01:39:01 +03:00
|
|
|
BrowserChild* aBrowserChild, mozilla::plugins::PluginWidgetChild* aActor) {
|
2014-11-12 23:59:20 +03:00
|
|
|
nsCOMPtr<nsIWidget> widget =
|
2019-04-10 01:39:01 +03:00
|
|
|
new mozilla::widget::PluginWidgetProxy(aBrowserChild, aActor);
|
2014-11-12 23:59:20 +03:00
|
|
|
return widget.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace widget {
|
|
|
|
|
2016-10-05 18:36:26 +03:00
|
|
|
using mozilla::plugins::PluginInstanceParent;
|
|
|
|
|
2014-11-12 23:59:20 +03:00
|
|
|
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)
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-11-12 23:59:20 +03:00
|
|
|
PluginWidgetProxy::PluginWidgetProxy(
|
2019-04-10 01:39:01 +03:00
|
|
|
dom::BrowserChild* aBrowserChild,
|
|
|
|
mozilla::plugins::PluginWidgetChild* aActor)
|
|
|
|
: PuppetWidget(aBrowserChild), mActor(aActor), mCachedPluginPort(0) {
|
2014-11-12 23:59:20 +03:00
|
|
|
// See ChannelDestroyed() in the header
|
2015-02-19 16:05:12 +03:00
|
|
|
mActor->SetWidget(this);
|
2014-11-12 23:59:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PluginWidgetProxy::~PluginWidgetProxy() {
|
|
|
|
PWLOG("PluginWidgetProxy::~PluginWidgetProxy()\n");
|
|
|
|
}
|
|
|
|
|
2015-11-16 11:35:18 +03:00
|
|
|
nsresult PluginWidgetProxy::Create(nsIWidget* aParent,
|
|
|
|
nsNativeWidget aNativeParent,
|
|
|
|
const LayoutDeviceIntRect& aRect,
|
2014-11-12 23:59:20 +03:00
|
|
|
nsWidgetInitData* aInitData) {
|
|
|
|
ENSURE_CHANNEL;
|
|
|
|
PWLOG("PluginWidgetProxy::Create()\n");
|
|
|
|
|
2015-02-06 00:48:44 +03:00
|
|
|
nsresult rv = NS_ERROR_UNEXPECTED;
|
2016-10-05 18:36:26 +03:00
|
|
|
uint64_t scrollCaptureId;
|
|
|
|
uintptr_t pluginInstanceId;
|
|
|
|
mActor->SendCreate(&rv, &scrollCaptureId, &pluginInstanceId);
|
2015-02-06 00:48:44 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2014-11-12 23:59:20 +03:00
|
|
|
NS_WARNING("failed to create chrome widget, plugins won't paint.");
|
2015-02-06 00:48:44 +03:00
|
|
|
return rv;
|
2014-11-12 23:59:20 +03:00
|
|
|
}
|
|
|
|
|
2016-01-13 10:32:55 +03:00
|
|
|
BaseCreate(aParent, aInitData);
|
2016-03-12 07:25:59 +03:00
|
|
|
mParent = aParent;
|
2014-11-12 23:59:20 +03:00
|
|
|
|
2015-11-23 07:32:29 +03:00
|
|
|
mBounds = aRect;
|
2014-11-12 23:59:20 +03:00
|
|
|
mEnabled = true;
|
|
|
|
mVisible = true;
|
|
|
|
|
2016-10-05 18:36:26 +03:00
|
|
|
PluginInstanceParent* instance =
|
|
|
|
PluginInstanceParent::LookupPluginInstanceByID(pluginInstanceId);
|
|
|
|
if (instance) {
|
|
|
|
Unused << NS_WARN_IF(
|
|
|
|
NS_FAILED(instance->SetScrollCaptureId(scrollCaptureId)));
|
|
|
|
}
|
|
|
|
|
2014-11-12 23:59:20 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PluginWidgetProxy::SetParent(nsIWidget* aNewParent) {
|
|
|
|
nsCOMPtr<nsIWidget> kungFuDeathGrip(this);
|
|
|
|
nsIWidget* parent = GetParent();
|
|
|
|
if (parent) {
|
|
|
|
parent->RemoveChild(this);
|
|
|
|
}
|
|
|
|
if (aNewParent) {
|
|
|
|
aNewParent->AddChild(this);
|
|
|
|
}
|
2016-03-12 07:25:59 +03:00
|
|
|
mParent = aNewParent;
|
2014-11-12 23:59:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIWidget* PluginWidgetProxy::GetParent(void) { return mParent.get(); }
|
|
|
|
|
|
|
|
void PluginWidgetProxy::Destroy() {
|
|
|
|
PWLOG("PluginWidgetProxy::Destroy()\n");
|
|
|
|
|
|
|
|
if (mActor) {
|
2015-02-19 16:05:12 +03:00
|
|
|
// Communicate that the layout widget has been torn down before the sub
|
|
|
|
// protocol.
|
|
|
|
mActor->ProxyShutdown();
|
2014-11-12 23:59:20 +03:00
|
|
|
mActor = nullptr;
|
|
|
|
}
|
|
|
|
|
2016-08-10 03:04:11 +03:00
|
|
|
PuppetWidget::Destroy();
|
2014-11-12 23:59:20 +03:00
|
|
|
}
|
|
|
|
|
2015-12-03 01:32:55 +03:00
|
|
|
void PluginWidgetProxy::GetWindowClipRegion(
|
|
|
|
nsTArray<LayoutDeviceIntRect>* aRects) {
|
2015-01-29 22:41:55 +03:00
|
|
|
if (mClipRects && mClipRectCount) {
|
|
|
|
aRects->AppendElements(mClipRects.get(), mClipRectCount);
|
|
|
|
}
|
2014-11-12 23:59:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void* PluginWidgetProxy::GetNativeData(uint32_t aDataType) {
|
|
|
|
if (!mActor) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2019-04-10 01:39:01 +03:00
|
|
|
auto tab = static_cast<mozilla::dom::BrowserChild*>(mActor->Manager());
|
2015-04-07 16:17:27 +03:00
|
|
|
if (tab && tab->IsDestroyed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2014-11-12 23:59:20 +03:00
|
|
|
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;
|
|
|
|
}
|
2016-03-12 07:25:59 +03:00
|
|
|
// 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;
|
2014-11-12 23:59:20 +03:00
|
|
|
}
|
|
|
|
|
2015-06-15 18:08:51 +03:00
|
|
|
void PluginWidgetProxy::SetNativeData(uint32_t aDataType, uintptr_t aVal) {
|
|
|
|
if (!mActor) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-10 01:39:01 +03:00
|
|
|
auto tab = static_cast<mozilla::dom::BrowserChild*>(mActor->Manager());
|
2015-06-15 18:08:51 +03:00
|
|
|
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.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-16 17:38:40 +03:00
|
|
|
void PluginWidgetProxy::SetFocus(Raise aRaise,
|
|
|
|
mozilla::dom::CallerType aCallerType) {
|
2019-06-01 01:13:56 +03:00
|
|
|
if (mActor) {
|
|
|
|
PWLOG("PluginWidgetProxy::SetFocus(%d)\n", aRaise == Raise::Yes);
|
2020-01-16 17:38:40 +03:00
|
|
|
mActor->SendSetFocus(aRaise == Raise::Yes, aCallerType);
|
2019-06-01 01:13:56 +03:00
|
|
|
}
|
2014-11-12 23:59:20 +03:00
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|