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"
|
|
|
|
#include "mozilla/dom/TabChild.h"
|
|
|
|
#include "mozilla/plugins/PluginWidgetChild.h"
|
|
|
|
#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(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),
|
2015-07-15 19:44:01 +03:00
|
|
|
mActor(aActor)
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PluginWidgetProxy::Create(nsIWidget* aParent,
|
|
|
|
nsNativeWidget aNativeParent,
|
|
|
|
const nsIntRect& aRect,
|
|
|
|
nsWidgetInitData* aInitData)
|
|
|
|
{
|
|
|
|
ENSURE_CHANNEL;
|
|
|
|
PWLOG("PluginWidgetProxy::Create()\n");
|
|
|
|
|
2015-02-06 00:48:44 +03:00
|
|
|
nsresult rv = NS_ERROR_UNEXPECTED;
|
|
|
|
mActor->SendCreate(&rv);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-02-05 08:18:30 +03:00
|
|
|
BaseCreate(aParent, aRect, aInitData);
|
2014-11-12 23:59:20 +03:00
|
|
|
|
|
|
|
mBounds = aRect;
|
|
|
|
mEnabled = true;
|
|
|
|
mVisible = true;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
PluginWidgetProxy::SetParent(nsIWidget* aNewParent)
|
|
|
|
{
|
2015-07-15 19:44:01 +03:00
|
|
|
mParent = aNewParent;
|
|
|
|
|
2014-11-12 23:59:20 +03:00
|
|
|
nsCOMPtr<nsIWidget> kungFuDeathGrip(this);
|
|
|
|
nsIWidget* parent = GetParent();
|
|
|
|
if (parent) {
|
|
|
|
parent->RemoveChild(this);
|
|
|
|
}
|
|
|
|
if (aNewParent) {
|
|
|
|
aNewParent->AddChild(this);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIWidget*
|
|
|
|
PluginWidgetProxy::GetParent(void)
|
|
|
|
{
|
|
|
|
return mParent.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return PuppetWidget::Destroy();
|
|
|
|
}
|
|
|
|
|
2015-01-29 22:41:55 +03:00
|
|
|
void
|
|
|
|
PluginWidgetProxy::GetWindowClipRegion(nsTArray<nsIntRect>* aRects)
|
2014-11-12 23:59:20 +03:00
|
|
|
{
|
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;
|
|
|
|
}
|
2015-04-07 16:17:27 +03:00
|
|
|
auto tab = static_cast<mozilla::dom::TabChild*>(mActor->Manager());
|
|
|
|
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;
|
|
|
|
}
|
2015-07-15 19:44:01 +03:00
|
|
|
uintptr_t value = 0;
|
|
|
|
mActor->SendGetNativePluginPort(&value);
|
|
|
|
PWLOG("PluginWidgetProxy::GetNativeData %p\n", (void*)value);
|
|
|
|
return (void*)value;
|
2014-11-12 23:59:20 +03:00
|
|
|
}
|
|
|
|
|
2015-06-15 18:08:51 +03:00
|
|
|
#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
|
|
|
|
|
2014-11-12 23:59:20 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
PluginWidgetProxy::SetFocus(bool aRaise)
|
|
|
|
{
|
|
|
|
ENSURE_CHANNEL;
|
|
|
|
PWLOG("PluginWidgetProxy::SetFocus(%d)\n", aRaise);
|
|
|
|
mActor->SendSetFocus(aRaise);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|