Bug 369306 - If dom.disable_window_flip is enable, block .blur() and .focus() if opener is different from the caller. r=jst a2.0=blocking

This commit is contained in:
James Darpinian 2010-09-09 20:18:23 +02:00
parent d442ca13c6
commit f09185a36c
3 changed files with 38 additions and 10 deletions

View File

@ -133,6 +133,7 @@ class nsIObserver;
class nsPresContext;
class nsIChannel;
struct nsIntMargin;
class nsPIDOMWindow;
#ifndef have_PrefChangedFunc_typedef
typedef int (*PR_CALLBACK PrefChangedFunc)(const char *, void *);
@ -444,6 +445,12 @@ public:
*/
static nsIDocShell *GetDocShellFromCaller();
/**
* Get the window through the JS context that's currently on the stack.
* If there's no JS context currently on the stack, returns null.
*/
static nsPIDOMWindow *GetWindowFromCaller();
/**
* The two GetDocumentFrom* functions below allow a caller to get at a
* document that is relevant to the currently executing script.

View File

@ -1522,6 +1522,21 @@ nsContentUtils::GetDocShellFromCaller()
return nsnull;
}
nsPIDOMWindow *
nsContentUtils::GetWindowFromCaller()
{
JSContext *cx = nsnull;
sThreadJSContextStack->Peek(&cx);
if (cx) {
nsCOMPtr<nsPIDOMWindow> win =
do_QueryInterface(nsJSUtils::GetDynamicScriptGlobal(cx));
return win;
}
return nsnull;
}
nsIDOMDocument *
nsContentUtils::GetDocumentFromCaller()
{

View File

@ -4359,17 +4359,17 @@ nsGlobalWindow::Focus()
return NS_OK;
}
/*
* If caller is not chrome and dom.disable_window_flip is true,
* prevent bringing a window to the front if the window is not the
* currently active window, but do change the currently focused
* window in the focus controller so that focus is in the right
* place when the window is activated again.
*/
nsIDOMWindowInternal *caller =
static_cast<nsIDOMWindowInternal*>(nsContentUtils::GetWindowFromCaller());
nsCOMPtr<nsIDOMWindowInternal> opener;
GetOpener(getter_AddRefs(opener));
PRBool canFocus =
CanSetProperty("dom.disable_window_flip") ||
RevisePopupAbuseLevel(gPopupControlState) < openAbused;
// Enforce dom.disable_window_flip (for non-chrome), but still allow the
// window which opened us to raise us at times when popups are allowed
// (bugs 355482 and 369306).
PRBool canFocus = CanSetProperty("dom.disable_window_flip") ||
(opener == caller &&
RevisePopupAbuseLevel(gPopupControlState) < openAbused);
nsCOMPtr<nsIDOMWindow> activeWindow;
fm->GetActiveWindow(getter_AddRefs(activeWindow));
@ -4458,6 +4458,12 @@ nsGlobalWindow::Blur()
{
FORWARD_TO_OUTER(Blur, (), NS_ERROR_NOT_INITIALIZED);
// If dom.disable_window_flip == true, then content should not be allowed
// to call this function (this would allow popunders, bug 369306)
if (!CanSetProperty("dom.disable_window_flip")) {
return NS_OK;
}
// If embedding apps don't implement nsIEmbeddingSiteWindow2, we
// shouldn't throw exceptions to web content.
nsresult rv = NS_OK;