зеркало из https://github.com/mozilla/gecko-dev.git
scrollbars=no ignored for window.open() calls. Implement a stack-based helper class that will push a null JSContext to make our calls into Gecko privileged. sr=smfr, b=324907
This commit is contained in:
Родитель
72a64308b9
Коммит
d61226bfbb
|
@ -35,9 +35,8 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
struct JSContext; // allow nsIJSContextStack to be included without sucking in JS headers
|
||||
#include "nsIJSContextStack.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "GeckoUtils.h"
|
||||
|
||||
#import "nsAlertController.h"
|
||||
#import "CHBrowserService.h"
|
||||
|
@ -133,9 +132,9 @@ const int kLabelCheckboxAdjustment = 2; // # pixels the label must be pushed dow
|
|||
}
|
||||
|
||||
int result = NSAlertErrorReturn;
|
||||
|
||||
nsCOMPtr<nsIJSContextStack> stack(do_GetService("@mozilla.org/js/xpc/ContextStack;1"));
|
||||
if (stack && NS_SUCCEEDED(stack->Push(nsnull)))
|
||||
nsresult rv = NS_OK;
|
||||
StNullJSContextScope hack(&rv);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
// be paranoid; we don't want to throw Obj-C exceptions over C++ code
|
||||
NS_DURING
|
||||
|
@ -146,10 +145,6 @@ const int kLabelCheckboxAdjustment = 2; // # pixels the label must be pushed dow
|
|||
NS_HANDLER
|
||||
NSLog(@"Exception caught in safeRunModalForWindow:relativeToWindow: %@", localException);
|
||||
NS_ENDHANDLER
|
||||
|
||||
JSContext* cx;
|
||||
stack->Pop(&cx);
|
||||
NS_ASSERTION(cx == nsnull, "JSContextStack mismatch");
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
@ -55,6 +55,7 @@
|
|||
#include "nsIMIMEInfo.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "GeckoUtils.h"
|
||||
|
||||
NSString* const InitEmbeddingNotificationName = @"InitEmebedding"; // this is actually broadcast from MainController
|
||||
NSString* const TermEmbeddingNotificationName = @"TermEmbedding";
|
||||
|
@ -224,7 +225,16 @@ CHBrowserService::CreateChromeWindow(nsIWebBrowserChrome *parent,
|
|||
#endif
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
// Push a null JSContext on the JS stack, before we create the chrome window.
|
||||
// Otherwise, a webpage invoking some JS to do window.open() will be last on the JS stack.
|
||||
// And once we start fixing up our newly created chrome window (to hide the scrollbar,
|
||||
// for example) Gecko will think it's the *webpage*, and webpages are not allowed
|
||||
// to do that. see bug 324907.
|
||||
nsresult rv = NS_OK;
|
||||
StNullJSContextScope hack(&rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIWindowCreator> browserChrome(do_QueryInterface(parent));
|
||||
return browserChrome->CreateChromeWindow(parent, chromeFlags, _retval);
|
||||
}
|
||||
|
|
|
@ -38,7 +38,10 @@
|
|||
#ifndef __GeckoUtils_h__
|
||||
#define __GeckoUtils_h__
|
||||
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsString.h"
|
||||
#include "jsapi.h"
|
||||
#include "nsIJSContextStack.h"
|
||||
|
||||
class nsIDOMNode;
|
||||
class nsIDOMElement;
|
||||
|
@ -46,6 +49,7 @@ class nsIDocShell;
|
|||
class nsIURI;
|
||||
class nsIEditor;
|
||||
|
||||
|
||||
class GeckoUtils
|
||||
{
|
||||
public:
|
||||
|
@ -66,5 +70,32 @@ class GeckoUtils
|
|||
static void FindDocShellForURI(nsIURI *aURI, nsIDocShell *aRoot, nsIDocShell **outMatch);
|
||||
};
|
||||
|
||||
/* Stack-based utility that will push a null JSContext onto the JS stack during the
|
||||
length of its lifetime.
|
||||
|
||||
For example, this is needed when some unprivileged JS code executes from a webpage.
|
||||
If we try to call into Gecko then, the current JSContext will be the webpage, and so
|
||||
Gecko might deny *us* the right to do something. For this reason we push a null JSContext,
|
||||
to make sure that whatever we want to do will be allowed.
|
||||
*/
|
||||
class StNullJSContextScope {
|
||||
public:
|
||||
StNullJSContextScope(nsresult *rv) {
|
||||
mStack = do_GetService("@mozilla.org/js/xpc/ContextStack;1", rv);
|
||||
if (NS_SUCCEEDED(*rv) && mStack)
|
||||
*rv = mStack->Push(nsnull);
|
||||
}
|
||||
|
||||
~StNullJSContextScope() {
|
||||
if (mStack) {
|
||||
JSContext *ctx;
|
||||
mStack->Pop(&ctx);
|
||||
NS_ASSERTION(!ctx, "Popped JSContext not null!");
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIJSContextStack> mStack;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Загрузка…
Ссылка в новой задаче