Bug 879475 - Make PBrowser manually keep track of its manager r=jlebar

This commit is contained in:
David Zbarsky 2013-07-10 13:07:51 -04:00
Родитель de9c375135
Коммит 72c136129d
9 изменённых файлов: 38 добавлений и 25 удалений

Просмотреть файл

@ -2066,7 +2066,7 @@ nsFrameLoader::TryRemoteBrowser()
rootChromeWin->GetBrowserDOMWindow(getter_AddRefs(browserDOMWin));
mRemoteBrowser->SetBrowserDOMWindow(browserDOMWin);
mChildHost = static_cast<ContentParent*>(mRemoteBrowser->Manager());
mChildHost = mRemoteBrowser->Manager();
}
return true;
}
@ -2240,10 +2240,10 @@ bool
nsFrameLoader::DoSendAsyncMessage(const nsAString& aMessage,
const StructuredCloneData& aData)
{
PBrowserParent* tabParent = GetRemoteBrowser();
TabParent* tabParent = mRemoteBrowser;
if (tabParent) {
ClonedMessageData data;
ContentParent* cp = static_cast<ContentParent*>(tabParent->Manager());
ContentParent* cp = tabParent->Manager();
if (!BuildClonedMessageDataForParent(cp, aData, data)) {
return false;
}

Просмотреть файл

@ -58,7 +58,7 @@ AssertAppProcess(PBrowserParent* aActor,
if (!aValid) {
printf_stderr("Security problem: Content process does not have `%s'. It will be killed.\n", aCapability);
ContentParent* process = static_cast<ContentParent*>(aActor->Manager());
ContentParent* process = tab->Manager();
process->KillHard();
}
return aValid;

Просмотреть файл

@ -589,7 +589,7 @@ ContentChild::AllocPBrowserChild(const IPCTabContext& aContext,
// check that it's of a certain type for security purposes, because we
// believe whatever the parent process tells us.
nsRefPtr<TabChild> child = TabChild::Create(TabContext(aContext), aChromeFlags);
nsRefPtr<TabChild> child = TabChild::Create(this, TabContext(aContext), aChromeFlags);
// The ref here is released in DeallocPBrowserChild.
return child.forget().get();

Просмотреть файл

@ -53,6 +53,8 @@ class ContentChild : public PContentChild
public:
ContentChild();
virtual ~ContentChild();
nsrefcnt AddRef() { return 1; }
nsrefcnt Release() { return 1; }
struct AppInfo
{

Просмотреть файл

@ -422,7 +422,7 @@ ContentParent::CreateBrowserOrApp(const TabContext& aContext,
if (aContext.IsBrowserElement() || !aContext.HasOwnApp()) {
if (nsRefPtr<ContentParent> cp = GetNewOrUsed(aContext.IsBrowserElement())) {
nsRefPtr<TabParent> tp(new TabParent(aContext));
nsRefPtr<TabParent> tp(new TabParent(cp, aContext));
tp->SetOwnerElement(aFrameElement);
uint32_t chromeFlags = 0;
@ -498,7 +498,7 @@ ContentParent::CreateBrowserOrApp(const TabContext& aContext,
sAppContentParents->Put(manifestURL, p);
}
nsRefPtr<TabParent> tp = new TabParent(aContext);
nsRefPtr<TabParent> tp = new TabParent(p, aContext);
tp->SetOwnerElement(aFrameElement);
PBrowserParent* browser = p->SendPBrowserConstructor(
nsRefPtr<TabParent>(tp).forget().get(), // DeallocPBrowserParent() releases this ref.
@ -1640,7 +1640,7 @@ ContentParent::AllocPBrowserParent(const IPCTabContext& aContext,
return nullptr;
}
TabParent* parent = new TabParent(TabContext(aContext));
TabParent* parent = new TabParent(this, TabContext(aContext));
// We release this ref in DeallocPBrowserParent()
NS_ADDREF(parent);

Просмотреть файл

@ -223,7 +223,8 @@ TabChild::PreloadSlowThings()
{
MOZ_ASSERT(!sPreallocatedTab);
nsRefPtr<TabChild> tab(new TabChild(TabContext(), /* chromeFlags */ 0));
nsRefPtr<TabChild> tab(new TabChild(ContentChild::GetSingleton(),
TabContext(), /* chromeFlags */ 0));
if (!NS_SUCCEEDED(tab->Init()) ||
!tab->InitTabChildGlobal(DONT_LOAD_SCRIPTS)) {
return;
@ -251,7 +252,7 @@ TabChild::PreloadSlowThings()
}
/*static*/ already_AddRefed<TabChild>
TabChild::Create(const TabContext &aContext, uint32_t aChromeFlags)
TabChild::Create(ContentChild* aManager, const TabContext &aContext, uint32_t aChromeFlags)
{
if (sPreallocatedTab &&
sPreallocatedTab->mChromeFlags == aChromeFlags &&
@ -267,14 +268,16 @@ TabChild::Create(const TabContext &aContext, uint32_t aChromeFlags)
return child.forget();
}
nsRefPtr<TabChild> iframe = new TabChild(aContext, aChromeFlags);
nsRefPtr<TabChild> iframe = new TabChild(aManager,
aContext, aChromeFlags);
return NS_SUCCEEDED(iframe->Init()) ? iframe.forget() : nullptr;
}
TabChild::TabChild(const TabContext& aContext, uint32_t aChromeFlags)
TabChild::TabChild(ContentChild* aManager, const TabContext& aContext, uint32_t aChromeFlags)
: TabContext(aContext)
, mRemoteFrame(nullptr)
, mManager(aManager)
, mTabChildGlobal(nullptr)
, mChromeFlags(aChromeFlags)
, mOuterRect(0, 0, 0, 0)
@ -976,7 +979,8 @@ TabChild::BrowserFrameProvideWindow(nsIDOMWindow* aOpener,
*aReturn = nullptr;
nsRefPtr<TabChild> newChild =
new TabChild(/* TabContext */ *this, /* chromeFlags */ 0);
new TabChild(ContentChild::GetSingleton(),
/* TabContext */ *this, /* chromeFlags */ 0);
if (!NS_SUCCEEDED(newChild->Init())) {
return NS_ERROR_ABORT;
}
@ -2332,7 +2336,7 @@ TabChild::DoSendSyncMessage(const nsAString& aMessage,
const StructuredCloneData& aData,
InfallibleTArray<nsString>* aJSONRetVal)
{
ContentChild* cc = static_cast<ContentChild*>(Manager());
ContentChild* cc = Manager();
ClonedMessageData data;
if (!BuildClonedMessageDataForChild(cc, aData, data)) {
return false;
@ -2344,7 +2348,7 @@ bool
TabChild::DoSendAsyncMessage(const nsAString& aMessage,
const StructuredCloneData& aData)
{
ContentChild* cc = static_cast<ContentChild*>(Manager());
ContentChild* cc = Manager();
ClonedMessageData data;
if (!BuildClonedMessageDataForChild(cc, aData, data)) {
return false;

Просмотреть файл

@ -44,6 +44,7 @@
#include "FrameMetrics.h"
#include "ProcessUtils.h"
#include "mozilla/dom/TabContext.h"
#include "mozilla/dom/ContentChild.h"
struct gfxMatrix;
class nsICachedFileDescriptorListener;
@ -163,8 +164,8 @@ public:
static void PreloadSlowThings();
/** Return a TabChild with the given attributes. */
static already_AddRefed<TabChild>
Create(const TabContext& aContext, uint32_t aChromeFlags);
static already_AddRefed<TabChild>
Create(ContentChild* aManager, const TabContext& aContext, uint32_t aChromeFlags);
virtual ~TabChild();
@ -326,6 +327,8 @@ public:
const nsAString& aPath,
nsICachedFileDescriptorListener* aCallback);
ContentChild* Manager() { return mManager; }
protected:
virtual PRenderFrameChild* AllocPRenderFrameChild(ScrollingBehavior* aScrolling,
TextureFactoryIdentifier* aTextureFactoryIdentifier,
@ -349,7 +352,7 @@ private:
*
* |aIsBrowserElement| indicates whether we're a browser (but not an app).
*/
TabChild(const TabContext& aContext, uint32_t aChromeFlags);
TabChild(ContentChild* aManager, const TabContext& aContext, uint32_t aChromeFlags);
nsresult Init();
@ -429,6 +432,7 @@ private:
nsCOMPtr<nsIURI> mLastURI;
FrameMetrics mLastMetrics;
RenderFrameChild* mRemoteFrame;
nsRefPtr<ContentChild> mManager;
nsRefPtr<TabChildGlobal> mTabChildGlobal;
uint32_t mChromeFlags;
nsIntRect mOuterRect;

Просмотреть файл

@ -186,7 +186,7 @@ TabParent *TabParent::mIMETabParent = nullptr;
NS_IMPL_ISUPPORTS3(TabParent, nsITabParent, nsIAuthPromptProvider, nsISecureBrowserUI)
TabParent::TabParent(const TabContext& aContext)
TabParent::TabParent(ContentParent* aManager, const TabContext& aContext)
: TabContext(aContext)
, mFrameElement(NULL)
, mIMESelectionAnchor(0)
@ -203,6 +203,7 @@ TabParent::TabParent(const TabContext& aContext)
, mDefaultScale(0)
, mShown(false)
, mUpdatedDimensions(false)
, mManager(aManager)
, mMarkedDestroying(false)
, mIsDestroyed(false)
, mAppPackageFileDescriptorSent(false)
@ -268,16 +269,14 @@ TabParent::Destroy()
}
mIsDestroyed = true;
ContentParent* cp = static_cast<ContentParent*>(Manager());
cp->NotifyTabDestroying(this);
Manager()->NotifyTabDestroying(this);
mMarkedDestroying = true;
}
bool
TabParent::Recv__delete__()
{
ContentParent* cp = static_cast<ContentParent*>(Manager());
cp->NotifyTabDestroyed(this, mMarkedDestroying);
Manager()->NotifyTabDestroyed(this, mMarkedDestroying);
return true;
}
@ -1175,7 +1174,7 @@ TabParent::RecvPIndexedDBConstructor(PIndexedDBParent* aActor,
return true;
}
ContentParent* contentParent = static_cast<ContentParent*>(Manager());
ContentParent* contentParent = Manager();
NS_ASSERTION(contentParent, "Null manager?!");
nsRefPtr<IDBFactory> factory;

Просмотреть файл

@ -10,6 +10,7 @@
#include "base/basictypes.h"
#include "jsapi.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/PBrowserParent.h"
#include "mozilla/dom/PContentDialogParent.h"
#include "mozilla/dom/TabContext.h"
@ -58,7 +59,7 @@ class TabParent : public PBrowserParent
typedef mozilla::layout::ScrollingBehavior ScrollingBehavior;
public:
TabParent(const TabContext& aContext);
TabParent(ContentParent* aManager, const TabContext& aContext);
virtual ~TabParent();
nsIDOMElement* GetOwnerElement() { return mFrameElement; }
void SetOwnerElement(nsIDOMElement* aElement);
@ -226,6 +227,8 @@ public:
static TabParent* GetFrom(nsFrameLoader* aFrameLoader);
static TabParent* GetFrom(nsIContent* aContent);
ContentParent* Manager() { return mManager; }
protected:
bool ReceiveMessage(const nsString& aMessage,
bool aSync,
@ -302,6 +305,7 @@ private:
already_AddRefed<nsFrameLoader> GetFrameLoader() const;
already_AddRefed<nsIWidget> GetWidget() const;
layout::RenderFrameParent* GetRenderFrame();
nsRefPtr<ContentParent> mManager;
void TryCacheDPIAndScale();
// When true, we create a pan/zoom controller for our frame and