Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1095754 - In the content process provide a way to track and acces…
Browse files Browse the repository at this point in the history
…s PluginInstanceParent objects from PluginWidgetChild. r=aklotz
  • Loading branch information
jmathies committed Jan 29, 2015
1 parent ea35990 commit 31ab26c
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 16 deletions.
91 changes: 75 additions & 16 deletions dom/plugins/ipc/PluginInstanceParent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
#include <windowsx.h>
#include "gfxWindowsPlatform.h"
#include "mozilla/plugins/PluginSurfaceParent.h"

#include "nsClassHashtable.h"
#include "nsHashKeys.h"
// Plugin focus event for widget.
extern const wchar_t* kOOPPPluginFocusEventId;
UINT gOOPPPluginFocusEvent =
Expand Down Expand Up @@ -73,6 +74,29 @@ StreamNotifyParent::RecvRedirectNotifyResponse(const bool& allow)
return true;
}

#if defined(XP_WIN)
namespace mozilla {
namespace plugins {
/**
* e10s specific, used in cross referencing hwnds with plugin instances so we
* can access methods here from PluginWidgetChild.
*/
static nsClassHashtable<nsVoidPtrHashKey, PluginInstanceParent>* sPluginInstanceList;

// static
PluginInstanceParent*
PluginInstanceParent::LookupPluginInstanceByID(uintptr_t aId)
{
MOZ_ASSERT(NS_IsMainThread());
if (sPluginInstanceList) {
return sPluginInstanceList->Get((void*)aId);
}
return nullptr;
}
}
}
#endif

PluginInstanceParent::PluginInstanceParent(PluginModuleParent* parent,
NPP npp,
const nsCString& aMimeType,
Expand All @@ -95,6 +119,11 @@ PluginInstanceParent::PluginInstanceParent(PluginModuleParent* parent,
, mShColorSpace(nullptr)
#endif
{
#if defined(OS_WIN)
if (!sPluginInstanceList) {
sPluginInstanceList = new nsClassHashtable<nsVoidPtrHashKey, PluginInstanceParent>();
}
#endif
}

PluginInstanceParent::~PluginInstanceParent()
Expand Down Expand Up @@ -1756,30 +1785,60 @@ PluginInstanceParent::PluginWindowHookProc(HWND hWnd,
void
PluginInstanceParent::SubclassPluginWindow(HWND aWnd)
{
if ((aWnd && mPluginHWND == aWnd) || (!aWnd && mPluginHWND)) {
return;
}

#if defined(XP_WIN)
if (XRE_GetProcessType() == GeckoProcessType_Content) {
mPluginHWND = aWnd; // now a remote window, we can't subclass this
mPluginWndProc = nullptr;
return;
if (!aWnd) {
NS_WARNING("PluginInstanceParent::SubclassPluginWindow unexpected null window");
return;
}
mPluginHWND = aWnd; // now a remote window, we can't subclass this
mPluginWndProc = nullptr;
// Note sPluginInstanceList wil delete 'this' if we do not remove
// it on shutdown.
sPluginInstanceList->Put((void*)mPluginHWND, this);
return;
}
#endif

NS_ASSERTION(!(mPluginHWND && aWnd != mPluginHWND),
"PluginInstanceParent::SubclassPluginWindow hwnd is not our window!");
"PluginInstanceParent::SubclassPluginWindow hwnd is not our window!");

if (!mPluginHWND) {
mPluginHWND = aWnd;
mPluginWndProc =
(WNDPROC)::SetWindowLongPtrA(mPluginHWND, GWLP_WNDPROC,
reinterpret_cast<LONG_PTR>(PluginWindowHookProc));
DebugOnly<bool> bRes = ::SetPropW(mPluginHWND, kPluginInstanceParentProperty, this);
NS_ASSERTION(mPluginWndProc,
"PluginInstanceParent::SubclassPluginWindow failed to set subclass!");
NS_ASSERTION(bRes,
"PluginInstanceParent::SubclassPluginWindow failed to set prop!");
}
mPluginHWND = aWnd;
mPluginWndProc =
(WNDPROC)::SetWindowLongPtrA(mPluginHWND, GWLP_WNDPROC,
reinterpret_cast<LONG_PTR>(PluginWindowHookProc));
DebugOnly<bool> bRes = ::SetPropW(mPluginHWND, kPluginInstanceParentProperty, this);
NS_ASSERTION(mPluginWndProc,
"PluginInstanceParent::SubclassPluginWindow failed to set subclass!");
NS_ASSERTION(bRes,
"PluginInstanceParent::SubclassPluginWindow failed to set prop!");
}

void
PluginInstanceParent::UnsubclassPluginWindow()
{
#if defined(XP_WIN)
if (XRE_GetProcessType() == GeckoProcessType_Content) {
if (mPluginHWND) {
// Remove 'this' from the plugin list safely
nsAutoPtr<PluginInstanceParent> tmp;
MOZ_ASSERT(sPluginInstanceList);
sPluginInstanceList->RemoveAndForget((void*)mPluginHWND, tmp);
tmp.forget();
if (!sPluginInstanceList->Count()) {
delete sPluginInstanceList;
sPluginInstanceList = nullptr;
}
}
mPluginHWND = nullptr;
return;
}
#endif

if (mPluginHWND && mPluginWndProc) {
::SetWindowLongPtrA(mPluginHWND, GWLP_WNDPROC,
reinterpret_cast<LONG_PTR>(mPluginWndProc));
Expand Down
9 changes: 9 additions & 0 deletions dom/plugins/ipc/PluginInstanceParent.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ class PluginInstanceParent : public PPluginInstanceParent
friend class PluginStreamParent;
friend class StreamNotifyParent;

#if defined(XP_WIN)
public:
/**
* Helper method for looking up instances based on a supplied id.
*/
static PluginInstanceParent*
LookupPluginInstanceByID(uintptr_t aId);
#endif // defined(XP_WIN)

public:
PluginInstanceParent(PluginModuleParent* parent,
NPP npp,
Expand Down
27 changes: 27 additions & 0 deletions dom/plugins/ipc/PluginWidgetChild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

#include "mozilla/plugins/PluginWidgetChild.h"
#include "PluginWidgetProxy.h"
#include "mozilla/DebugOnly.h"
#include "nsDebug.h"

#if defined(XP_WIN)
#include "mozilla/plugins/PluginInstanceParent.h"
using mozilla::plugins::PluginInstanceParent;
#endif

namespace mozilla {
namespace plugins {
Expand All @@ -28,6 +35,26 @@ PluginWidgetChild::ActorDestroy(ActorDestroyReason aWhy)
mWidget = nullptr;
}

bool
PluginWidgetChild::RecvUpdateWindow(const uintptr_t& aChildId)
{
#if defined(XP_WIN)
NS_ASSERTION(aChildId, "Expected child hwnd value for remote plugin instance.");
PluginInstanceParent* parentInstance =
PluginInstanceParent::LookupPluginInstanceByID(aChildId);
NS_ASSERTION(parentInstance, "Expected matching plugin instance");
if (parentInstance) {
// sync! update call to the plugin instance that forces the
// plugin to paint its child window.
parentInstance->CallUpdateWindow();
}
return true;
#else
NS_NOTREACHED("PluginWidgetChild::RecvUpdateWindow calls unexpected on this platform.");
return false;
#endif
}

} // namespace plugins
} // namespace mozilla

Expand Down
1 change: 1 addition & 0 deletions dom/plugins/ipc/PluginWidgetChild.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class PluginWidgetChild : public PPluginWidgetChild
PluginWidgetChild();
virtual ~PluginWidgetChild();

virtual bool RecvUpdateWindow(const uintptr_t& aChildId) MOZ_OVERRIDE;
virtual void ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE;

mozilla::widget::PluginWidgetProxy* mWidget;
Expand Down

0 comments on commit 31ab26c

Please sign in to comment.