mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-15 14:25:52 +00:00
Bug 774633 - Factor nsWindowWatcher call to SetOpenerScriptPrincipal into a method on nsGlobalWindow. r=jst
This doesn't change any functionality in the code. Note that the name is currently a bit of a misnomer, but we change that in the next patch when we rip out the arguments.
This commit is contained in:
parent
00e03faa6d
commit
9a637e122b
@ -1546,6 +1546,39 @@ nsGlobalWindow::SetOpenerScriptPrincipal(nsIPrincipal* aPrincipal)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsGlobalWindow::SetInitialPrincipalToSubject(nsIDocShellTreeItem* aItem,
|
||||
nsIDOMWindow* aParent)
|
||||
{
|
||||
nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager();
|
||||
MOZ_ASSERT(ssm);
|
||||
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPrincipal> newWindowPrincipal;
|
||||
rv = ssm->GetSubjectPrincipal(getter_AddRefs(newWindowPrincipal));
|
||||
MOZ_ASSERT(NS_SUCCEEDED(rv));
|
||||
|
||||
if (!newWindowPrincipal && aParent) {
|
||||
nsCOMPtr<nsIScriptObjectPrincipal> sop(do_QueryInterface(aParent));
|
||||
if (sop) {
|
||||
newWindowPrincipal = sop->GetPrincipal();
|
||||
}
|
||||
}
|
||||
|
||||
bool isSystem;
|
||||
rv = ssm->IsSystemPrincipal(newWindowPrincipal, &isSystem);
|
||||
if (NS_FAILED(rv) || isSystem) {
|
||||
// Don't pass this principal along to content windows
|
||||
int32_t itemType;
|
||||
rv = aItem->GetItemType(&itemType);
|
||||
if (NS_FAILED(rv) || itemType != nsIDocShellTreeItem::typeChrome) {
|
||||
newWindowPrincipal = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
SetOpenerScriptPrincipal(newWindowPrincipal);
|
||||
}
|
||||
|
||||
nsIPrincipal*
|
||||
nsGlobalWindow::GetOpenerScriptPrincipal()
|
||||
{
|
||||
|
@ -343,6 +343,8 @@ public:
|
||||
virtual NS_HIDDEN_(void) SetChromeEventHandler(nsIDOMEventTarget* aChromeEventHandler);
|
||||
|
||||
virtual NS_HIDDEN_(void) SetOpenerScriptPrincipal(nsIPrincipal* aPrincipal);
|
||||
virtual NS_HIDDEN_(void) SetInitialPrincipalToSubject(nsIDocShellTreeItem* aItem,
|
||||
nsIDOMWindow* aParent);
|
||||
virtual NS_HIDDEN_(nsIPrincipal*) GetOpenerScriptPrincipal();
|
||||
|
||||
virtual NS_HIDDEN_(PopupControlState) PushPopupControlState(PopupControlState state, bool aForce) const;
|
||||
|
@ -24,6 +24,7 @@
|
||||
|
||||
class nsIIdleObserver;
|
||||
class nsIPrincipal;
|
||||
class nsIDocShellTreeItem; // XXX - Temporary! Goes away in the next patch
|
||||
|
||||
// Popup control state enum. The values in this enum must go from most
|
||||
// permissive to least permissive so that it's safe to push state in
|
||||
@ -48,8 +49,8 @@ class nsIArray;
|
||||
class nsPIWindowRoot;
|
||||
|
||||
#define NS_PIDOMWINDOW_IID \
|
||||
{0x66660102, 0xd875, 0x47e2, \
|
||||
{0xa1, 0xf7, 0x12, 0xbc, 0x83, 0xc9, 0x93, 0xa9}}
|
||||
{ 0x0c5763c6, 0x5e87, 0x4f6f, \
|
||||
{ 0xa2, 0xef, 0xcf, 0x4d, 0xeb, 0xd1, 0xbc, 0xc3 } }
|
||||
|
||||
class nsPIDOMWindow : public nsIDOMWindowInternal
|
||||
{
|
||||
@ -286,6 +287,9 @@ public:
|
||||
// preloaded into it when it was created, or created by
|
||||
// CreateAboutBlankContentViewer()).
|
||||
virtual void SetOpenerScriptPrincipal(nsIPrincipal* aPrincipal) = 0;
|
||||
virtual void SetInitialPrincipalToSubject(nsIDocShellTreeItem* aItem,
|
||||
nsIDOMWindow* aParent) = 0;
|
||||
|
||||
// Ask this window who opened it.
|
||||
virtual nsIPrincipal* GetOpenerScriptPrincipal() = 0;
|
||||
|
||||
|
@ -873,32 +873,13 @@ nsWindowWatcher::OpenWindowInternal(nsIDOMWindow *aParent,
|
||||
// the JS stack, just use the principal of our parent window. In those
|
||||
// cases we do _not_ set the parent window principal as the owner of the
|
||||
// load--since we really don't know who the owner is, just leave it null.
|
||||
nsIPrincipal* newWindowPrincipal = subjectPrincipal;
|
||||
if (!newWindowPrincipal && aParent) {
|
||||
nsCOMPtr<nsIScriptObjectPrincipal> sop(do_QueryInterface(aParent));
|
||||
if (sop) {
|
||||
newWindowPrincipal = sop->GetPrincipal();
|
||||
}
|
||||
}
|
||||
|
||||
bool isSystem;
|
||||
rv = sm->IsSystemPrincipal(newWindowPrincipal, &isSystem);
|
||||
if (NS_FAILED(rv) || isSystem) {
|
||||
// Don't pass this principal along to content windows
|
||||
int32_t itemType;
|
||||
rv = newDocShellItem->GetItemType(&itemType);
|
||||
if (NS_FAILED(rv) || itemType != nsIDocShellTreeItem::typeChrome) {
|
||||
newWindowPrincipal = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsPIDOMWindow> newWindow = do_QueryInterface(*_retval);
|
||||
#ifdef DEBUG
|
||||
nsCOMPtr<nsPIDOMWindow> newDebugWindow = do_GetInterface(newDocShell);
|
||||
NS_ASSERTION(newWindow == newDebugWindow, "Different windows??");
|
||||
#endif
|
||||
if (newWindow) {
|
||||
newWindow->SetOpenerScriptPrincipal(newWindowPrincipal);
|
||||
newWindow->SetInitialPrincipalToSubject(newDocShellItem, aParent);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user