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