bool PluginWidgetParent::RecvCreate() { PWLOG("PluginWidgetParent::RecvCreate()\n"); nsresult rv; mWidget = do_CreateInstance(kWidgetCID, &rv); #if defined(MOZ_WIDGET_GTK) // We need this currently just for GTK in setting up a socket widget // we can send over to content -> plugin. PLUG_NewPluginNativeWindow((nsPluginNativeWindow**)&mWrapper); if (!mWrapper) { return false; } #endif // This returns the top level window widget nsCOMPtr<nsIWidget> parentWidget = GetTabParent()->GetWidget(); nsWidgetInitData initData; initData.mWindowType = eWindowType_plugin_ipc_chrome; initData.mUnicode = false; initData.clipChildren = true; initData.clipSiblings = true; rv = mWidget->Create(parentWidget.get(), nullptr, nsIntRect(0,0,0,0), nullptr, &initData); if (NS_FAILED(rv)) { mWidget->Destroy(); mWidget = nullptr; return false; } mWidget->EnableDragDrop(true); mWidget->Show(false); mWidget->Enable(false); // Force the initial position down into content. If we miss an // initial position update this insures the widget doesn't overlap // chrome. RecvMove(0, 0); #if defined(MOZ_WIDGET_GTK) // For setup, initially GTK code expects 'window' to hold the parent. mWrapper->window = mWidget->GetNativeData(NS_NATIVE_PLUGIN_PORT); mWrapper->CreateXEmbedWindow(false); mWrapper->SetAllocation(); PWLOG("Plugin XID=%p\n", (void*)mWrapper->window); #endif return true; }
bool PluginWidgetParent::RecvGetNativePluginPort(uintptr_t* value) { ENSURE_CHANNEL; PWLOG("PluginWidgetParent::RecvGetNativeData()\n"); #if defined(MOZ_WIDGET_GTK) *value = (uintptr_t)mWrapper->window; #else *value = (uintptr_t)mWidget->GetNativeData(NS_NATIVE_PLUGIN_PORT); #endif PWLOG("PluginWidgetParent::RecvGetNativeData() %p\n", (void*)*value); return true; }
NS_IMETHODIMP PluginWidgetProxy::Destroy() { PWLOG("PluginWidgetProxy::Destroy()\n"); if (mActor) { /** * We need to communicate that the sub protocol is going to be torn down * before the sub protocol dies. Otherwise we can end up with async events * in transit from chrome to content, which on arrival will trigger an abort * in the content process, crashing all tabs. * * Note, this is one of two ways PluginWidget tear down initiates. Here we * are a plugin in content and content has just unloaded us for some reason, * usually due to swap out for flash ads or the user simply loaded a * different page. The other involves a full tear down of the tab (PBrowser) * which happens prior to widgets getting collected by ref counting in * layout. We still get this Destroy call, but in all likelyhood mActor is * already null via a call on ChannelDestroyed from PluginWidgetChild. */ mActor->SendDestroy(); mActor->mWidget = nullptr; mActor = nullptr; } return PuppetWidget::Destroy(); }
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; }
bool PluginWidgetParent::RecvInvalidate(const nsIntRect& aRect) { ENSURE_CHANNEL; PWLOG("PluginWidgetParent::RecvInvalidate(%d, %d, %d, %d)\n", aRect.x, aRect.y, aRect.width, aRect.height); mWidget->Invalidate(aRect); return true; }
bool PluginWidgetParent::RecvShow(const bool& aState) { ENSURE_CHANNEL; PWLOG("PluginWidgetParent::RecvShow(%d)\n", aState); mWidget->Show(aState); return true; }
NS_IMETHODIMP PluginWidgetProxy::SetFocus(bool aRaise) { ENSURE_CHANNEL; PWLOG("PluginWidgetProxy::SetFocus(%d)\n", aRaise); mActor->SendSetFocus(aRaise); return NS_OK; }
PluginWidgetParent::PluginWidgetParent() #if defined(MOZ_WIDGET_GTK) : mWrapper(nullptr) #endif { PWLOG("PluginWidgetParent::PluginWidgetParent()\n"); MOZ_COUNT_CTOR(PluginWidgetParent); }
bool PluginWidgetParent::RecvSetFocus(const bool& aRaise) { ENSURE_CHANNEL; PWLOG("PluginWidgetParent::RecvSetFocus(%d)\n", aRaise); mWidget->SetFocus(aRaise); return true; }
bool PluginWidgetParent::RecvSetWindowClipRegion(const nsTArray<nsIntRect>& Regions, const bool& aIntersectWithExisting) { ENSURE_CHANNEL; PWLOG("PluginWidgetParent::RecvSetWindowClipRegion()\n"); mWidget->SetWindowClipRegion(Regions, aIntersectWithExisting); return true; }
bool PluginWidgetParent::RecvDestroy() { ENSURE_CHANNEL; PWLOG("PluginWidgetParent::RecvDestroy()\n"); mWidget->Destroy(); mWidget = nullptr; return true; }
void PluginWidgetChild::KillWidget() { PWLOG("PluginWidgetChild::KillWidget()\n"); if (mWidget) { mWidget->ChannelDestroyed(); } mWidget = nullptr; }
PluginWidgetParent::~PluginWidgetParent() { PWLOG("PluginWidgetParent::~PluginWidgetParent()\n"); MOZ_COUNT_DTOR(PluginWidgetParent); // A destroy call can actually get skipped if a widget is associated // with the last out-of-process page, make sure and cleanup any left // over widgets if we have them. KillWidget(); }
// Called by the proxy widget when it is destroyed by layout. Only gets // called once. void PluginWidgetChild::ProxyShutdown() { PWLOG("PluginWidgetChild::ProxyShutdown()\n"); if (mWidget) { mWidget = nullptr; auto tab = static_cast<mozilla::dom::TabChild*>(Manager()); if (!tab->IsDestroyed()) { Unused << Send__delete__(this); } } }
bool PluginWidgetParent::RecvResize(const nsIntRect& aRect) { ENSURE_CHANNEL; PWLOG("PluginWidgetParent::RecvResize(%d, %d, %d, %d)\n", aRect.x, aRect.y, aRect.width, aRect.height); mWidget->Resize(aRect.width, aRect.height, true); #if defined(MOZ_WIDGET_GTK) mWrapper->width = aRect.width; mWrapper->height = aRect.height; mWrapper->SetAllocation(); #endif return true; }
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(); }
// Called by TabParent's Destroy() in response to an early tear down (Early // in that this is happening before layout in the child has had a chance // to destroy the child widget.) when the tab is closing. We will not receive // RecvDestroy here. void PluginWidgetParent::ParentDestroy() { if (mActorDestroyed || !mWidget) { return; } PWLOG("PluginWidgetParent::ParentDestroy()\n"); mWidget->UnregisterPluginWindowForRemoteUpdates(); DebugOnly<nsresult> rv = mWidget->Destroy(); NS_ASSERTION(NS_SUCCEEDED(rv), "widget destroy failure"); mWidget = nullptr; mActorDestroyed = true; return; }
bool PluginWidgetParent::RecvSetNativeChildWindow(const uintptr_t& aChildWindow) { #if defined(XP_WIN) ENSURE_CHANNEL; PWLOG("PluginWidgetParent::RecvSetNativeChildWindow(%p)\n", static_cast<void*>(aChildWindow)); mWidget->SetNativeData(NS_NATIVE_CHILD_WINDOW, aChildWindow); return true; #else NS_NOTREACHED("PluginWidgetParent::RecvSetNativeChildWindow not implemented!"); return false; #endif }
void PluginWidgetParent::KillWidget() { PWLOG("PluginWidgetParent::KillWidget() widget=%p\n", (void*)mWidget.get()); if (mWidget) { mWidget->UnregisterPluginWindowForRemoteUpdates(); DebugOnly<nsresult> rv = mWidget->Destroy(); NS_ASSERTION(NS_SUCCEEDED(rv), "widget destroy failure"); #if defined(MOZ_WIDGET_GTK) mWidget->SetNativeData(NS_NATIVE_PLUGIN_OBJECT_PTR, (uintptr_t)0); mWrapper = nullptr; #elif defined(XP_WIN) ::RemovePropW((HWND)mWidget->GetNativeData(NS_NATIVE_WINDOW), mozilla::dom::kPluginWidgetContentParentProperty); #endif mWidget = nullptr; } }
void* PluginWidgetProxy::GetNativeData(uint32_t aDataType) { if (!mActor) { 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; } uintptr_t value = 0; mActor->SendGetNativePluginPort(&value); PWLOG("PluginWidgetProxy::GetNativeData %p\n", (void*)value); return (void*)value; }
PluginWidgetParent::~PluginWidgetParent() { PWLOG("PluginWidgetParent::~PluginWidgetParent()\n"); MOZ_COUNT_DTOR(PluginWidgetParent); // A destroy call can actually get skipped if a widget is associated // with the last out-of-process page, make sure and cleanup any left // over widgets if we have them. if (mWidget) { #if defined(MOZ_WIDGET_GTK) mWidget->SetNativeData(NS_NATIVE_PLUGIN_OBJECT_PTR, (uintptr_t)0); mWrapper = nullptr; #elif defined(XP_WIN) ::RemovePropW((HWND)mWidget->GetNativeData(NS_NATIVE_WINDOW), kPluginWidgetParentProperty); #endif mWidget->UnregisterPluginWindowForRemoteUpdates(); mWidget->Destroy(); mWidget = nullptr; } }
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; } uintptr_t value = 0; mActor->SendGetNativePluginPort(&value); PWLOG("PluginWidgetProxy::GetNativeData %p\n", (void*)value); return (void*)value; }
bool PluginWidgetParent::RecvMove(const double& aX, const double& aY) { ENSURE_CHANNEL; PWLOG("PluginWidgetParent::RecvMove(%f, %f)\n", aX, aY); // This returns the top level window nsCOMPtr<nsIWidget> widget = GetTabParent()->GetWidget(); if (!widget) { // return true otherwise ipc will abort the content process, crashing // all tabs. return true; } // Passed in coords are at the tab origin, adjust to the main window. nsIntPoint offset = GetTabParent()->GetChildProcessOffset(); offset.x = abs(offset.x); offset.y = abs(offset.y); offset += nsIntPoint(ceil(aX), ceil(aY)); mWidget->Move(offset.x, offset.y); return true; }
bool PluginWidgetParent::RecvCreate(nsresult* aResult) { PWLOG("PluginWidgetParent::RecvCreate()\n"); mWidget = do_CreateInstance(kWidgetCID, aResult); NS_ASSERTION(NS_SUCCEEDED(*aResult), "widget create failure"); #if defined(MOZ_WIDGET_GTK) // We need this currently just for GTK in setting up a socket widget // we can send over to content -> plugin. PLUG_NewPluginNativeWindow((nsPluginNativeWindow**)&mWrapper); if (!mWrapper) { KillWidget(); return false; } // Give a copy of this to the widget, which handles some update // work for us. mWidget->SetNativeData(NS_NATIVE_PLUGIN_OBJECT_PTR, (uintptr_t)mWrapper.get()); #endif // This returns the top level window widget nsCOMPtr<nsIWidget> parentWidget = GetTabParent()->GetWidget(); // If this fails, bail. if (!parentWidget) { *aResult = NS_ERROR_NOT_AVAILABLE; KillWidget(); return true; } nsWidgetInitData initData; initData.mWindowType = eWindowType_plugin_ipc_chrome; initData.mUnicode = false; initData.clipChildren = true; initData.clipSiblings = true; *aResult = mWidget->Create(parentWidget.get(), nullptr, nsIntRect(0,0,0,0), &initData); if (NS_FAILED(*aResult)) { KillWidget(); // This should never fail, abort. return false; } DebugOnly<nsresult> drv; drv = mWidget->EnableDragDrop(true); NS_ASSERTION(NS_SUCCEEDED(drv), "widget call failure"); #if defined(MOZ_WIDGET_GTK) // For setup, initially GTK code expects 'window' to hold the parent. mWrapper->window = mWidget->GetNativeData(NS_NATIVE_PLUGIN_PORT); drv = mWrapper->CreateXEmbedWindow(false); NS_ASSERTION(NS_SUCCEEDED(drv), "widget call failure"); mWrapper->SetAllocation(); PWLOG("Plugin XID=%p\n", (void*)mWrapper->window); #elif defined(XP_WIN) DebugOnly<DWORD> winres = ::SetPropW((HWND)mWidget->GetNativeData(NS_NATIVE_WINDOW), mozilla::dom::kPluginWidgetContentParentProperty, GetTabParent()->Manager()->AsContentParent()); NS_ASSERTION(winres, "SetPropW call failure"); #endif // This is a special call we make to nsBaseWidget to register this // window as a remote plugin window which is expected to receive // visibility updates from the compositor, which ships this data // over with corresponding layer updates. mWidget->RegisterPluginWindowForRemoteUpdates(); return true; }
PluginWidgetChild::PluginWidgetChild() : mWidget(nullptr) { PWLOG("PluginWidgetChild::PluginWidgetChild()\n"); MOZ_COUNT_CTOR(PluginWidgetChild); }
PluginWidgetParent::PluginWidgetParent() { PWLOG("PluginWidgetParent::PluginWidgetParent()\n"); MOZ_COUNT_CTOR(PluginWidgetParent); }
PluginWidgetChild::~PluginWidgetChild() { PWLOG("PluginWidgetChild::~PluginWidgetChild()\n"); MOZ_COUNT_DTOR(PluginWidgetChild); }
// Called by TabParent's Destroy() in response to an early tear down (Early // in that this is happening before layout in the child has had a chance // to destroy the child widget.) when the tab is closing. void PluginWidgetParent::ParentDestroy() { PWLOG("PluginWidgetParent::ParentDestroy()\n"); }
void PluginWidgetParent::ActorDestroy(ActorDestroyReason aWhy) { PWLOG("PluginWidgetParent::ActorDestroy(%d)\n", aWhy); KillWidget(); }
void PluginWidgetParent::ActorDestroy(ActorDestroyReason aWhy) { PWLOG("PluginWidgetParent::ActorDestroy()\n"); }