Bug 864335 - Remove GetScriptGlobalObject. r=mrbkap

This commit is contained in:
Gabor Krizsanits 2013-06-21 16:25:20 +02:00
parent 08da62fdfd
commit 756a8f8c8c
26 changed files with 67 additions and 93 deletions

View File

@ -114,8 +114,8 @@ typedef CallbackObjectHolder<NodeFilter, nsIDOMNodeFilter> NodeFilterHolder;
} // namespace mozilla
#define NS_IDOCUMENT_IID \
{ 0x308f8444, 0x7679, 0x445a, \
{ 0xa6, 0xcc, 0xb9, 0x5c, 0x61, 0xff, 0xe2, 0x66 } }
{ 0x62cca591, 0xa030, 0x4117, \
{ 0x9b, 0x80, 0xdc, 0xd3, 0x66, 0xbb, 0xb5, 0x9 } }
// Flag for AddStyleSheet().
#define NS_STYLESHEET_FROM_CATALOG (1 << 0)
@ -770,13 +770,6 @@ public:
return mStyleAttrStyleSheet;
}
/**
* Get/set the object from which a document can get a script context
* and scope. This is the context within which all scripts (during
* document creation and during event handling) will run. Note that
* this is the *inner* window object.
*/
virtual nsIScriptGlobalObject* GetScriptGlobalObject() const = 0;
virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject) = 0;
/**
@ -1475,8 +1468,7 @@ public:
{
NS_PRECONDITION(!GetShell() &&
!nsCOMPtr<nsISupports>(GetContainer()) &&
!GetWindow() &&
!GetScriptGlobalObject(),
!GetWindow(),
"Shouldn't set mDisplayDocument on documents that already "
"have a presentation or a docshell or a window");
NS_PRECONDITION(aDisplayDocument != this, "Should be different document");

View File

@ -308,7 +308,7 @@ nsContentSink::ProcessHeaderData(nsIAtom* aHeader, const nsAString& aValue,
NS_ENSURE_TRUE(codebaseURI, rv);
nsCOMPtr<nsIPrompt> prompt;
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(mDocument->GetScriptGlobalObject());
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(mDocument->GetWindow());
if (window) {
window->GetPrompter(getter_AddRefs(prompt));
}

View File

@ -6100,10 +6100,10 @@ nsContentUtils::IsPatternMatching(nsAString& aValue, nsAString& aPattern,
nsIDocument* aDocument)
{
NS_ASSERTION(aDocument, "aDocument should be a valid pointer (not null)");
NS_ENSURE_TRUE(aDocument->GetScriptGlobalObject(), true);
nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(aDocument->GetWindow());
NS_ENSURE_TRUE(sgo, true);
AutoPushJSContext cx(aDocument->GetScriptGlobalObject()->
GetContext()->GetNativeContext());
AutoPushJSContext cx(sgo->GetContext()->GetNativeContext());
NS_ENSURE_TRUE(cx, true);
// The pattern has to match the entire value.

View File

@ -4078,28 +4078,6 @@ nsDocument::FirstAdditionalAuthorSheet()
return mAdditionalSheets[eAuthorSheet].SafeObjectAt(0);
}
nsIScriptGlobalObject*
nsDocument::GetScriptGlobalObject() const
{
// If we're going away, we've already released the reference to our
// ScriptGlobalObject. We can, however, try to obtain it for the
// caller through our docshell.
// We actually need to start returning the docshell's script global
// object as soon as nsDocumentViewer::Close has called
// RemovedFromDocShell on us.
if (mRemovedFromDocShell) {
nsCOMPtr<nsIInterfaceRequestor> requestor =
do_QueryReferent(mDocumentContainer);
if (requestor) {
nsCOMPtr<nsIScriptGlobalObject> globalObject = do_GetInterface(requestor);
return globalObject;
}
}
return mScriptGlobalObject;
}
nsIGlobalObject*
nsDocument::GetScopeObject() const
{
@ -4270,14 +4248,25 @@ nsPIDOMWindow *
nsDocument::GetWindowInternal() const
{
MOZ_ASSERT(!mWindow, "This should not be called when mWindow is not null!");
nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(GetScriptGlobalObject()));
if (!win) {
return nullptr;
// Let's use mScriptGlobalObject. Even if the document is already removed from
// the docshell, the outer window might be still obtainable from the it.
nsCOMPtr<nsPIDOMWindow> win;
if (mRemovedFromDocShell) {
nsCOMPtr<nsIInterfaceRequestor> requestor =
do_QueryReferent(mDocumentContainer);
if (requestor) {
// The docshell returns the outer window we are done.
win = do_GetInterface(requestor);
}
} else {
win = do_QueryInterface(mScriptGlobalObject);
if (win) {
// mScriptGlobalObject is always the inner window, let's get the outer.
win = win->GetOuterWindow();
}
}
return win->GetOuterWindow();
return win;
}
nsScriptLoader*
@ -7111,7 +7100,7 @@ nsDocument::IsScriptEnabled()
nsCOMPtr<nsIScriptSecurityManager> sm(do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID));
NS_ENSURE_TRUE(sm, false);
nsIScriptGlobalObject* globalObject = GetScriptGlobalObject();
nsCOMPtr<nsIScriptGlobalObject> globalObject = do_QueryInterface(GetWindow());
NS_ENSURE_TRUE(globalObject, false);
nsIScriptContext *scriptContext = globalObject->GetContext();
@ -8123,7 +8112,7 @@ nsDocument::MutationEventDispatched(nsINode* aTarget)
}
nsCOMPtr<nsPIDOMWindow> window;
window = do_QueryInterface(GetScriptGlobalObject());
window = do_QueryInterface(GetWindow());
if (window &&
!window->HasMutationListeners(NS_EVENT_BITS_MUTATION_SUBTREEMODIFIED)) {
mSubtreeModifiedTargets.Clear();
@ -11275,7 +11264,7 @@ nsIDocument::WrapObject(JSContext *aCx, JS::Handle<JSObject*> aScope)
return nullptr;
}
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(GetScriptGlobalObject());
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(GetInnerWindow());
if (!win) {
// No window, nothing else to do here
return obj;

View File

@ -640,12 +640,6 @@ public:
return mChannel;
}
/**
* Set the object from which a document can get a script context.
* This is the context within which all scripts (during document
* creation and during event handling) will run.
*/
virtual nsIScriptGlobalObject* GetScriptGlobalObject() const MOZ_OVERRIDE;
virtual void SetScriptGlobalObject(nsIScriptGlobalObject* aGlobalObject) MOZ_OVERRIDE;
virtual void SetScriptHandlingObject(nsIScriptGlobalObject* aScriptObject) MOZ_OVERRIDE;

View File

@ -1797,7 +1797,7 @@ nsFrameLoader::GetWindowDimensions(nsRect& aRect)
}
nsCOMPtr<nsIWebNavigation> parentAsWebNav =
do_GetInterface(doc->GetScriptGlobalObject());
do_GetInterface(doc->GetWindow());
if (!parentAsWebNav) {
return NS_ERROR_FAILURE;
@ -1973,7 +1973,7 @@ nsFrameLoader::TryRemoteBrowser()
}
nsCOMPtr<nsIWebNavigation> parentAsWebNav =
do_GetInterface(doc->GetScriptGlobalObject());
do_GetInterface(doc->GetWindow());
if (!parentAsWebNav) {
return false;

View File

@ -603,7 +603,7 @@ nsObjectLoadingContent::IsSupportedDocument(const nsCString& aMimeType)
nsCOMPtr<nsIWebNavigation> webNav;
nsIDocument* currentDoc = thisContent->GetCurrentDoc();
if (currentDoc) {
webNav = do_GetInterface(currentDoc->GetScriptGlobalObject());
webNav = do_GetInterface(currentDoc->GetWindow());
}
uint32_t supported;

View File

@ -273,7 +273,7 @@ nsScriptLoader::StartLoad(nsScriptLoadRequest *aRequest, const nsAString &aType,
nsCOMPtr<nsILoadGroup> loadGroup = mDocument->GetDocumentLoadGroup();
nsCOMPtr<nsPIDOMWindow> window(do_QueryInterface(mDocument->GetScriptGlobalObject()));
nsCOMPtr<nsPIDOMWindow> window(do_QueryInterface(mDocument->GetWindow()));
if (!window) {
return NS_ERROR_NULL_POINTER;
}
@ -430,7 +430,8 @@ nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement)
// For now though, if JS is disabled we assume every language is
// disabled.
// XXX is this different from the mDocument->IsScriptEnabled() call?
nsIScriptGlobalObject *globalObject = mDocument->GetScriptGlobalObject();
nsCOMPtr<nsIScriptGlobalObject> globalObject =
do_QueryInterface(mDocument->GetWindow());
if (!globalObject) {
return false;
}

View File

@ -889,10 +889,11 @@ HTMLCanvasElement::InvalidateCanvasContent(const gfx::Rect* damageRect)
* invalidating a canvas will feed into heuristics and cause JIT code to be
* kept around longer, for smoother animations.
*/
nsIScriptGlobalObject *scope = OwnerDoc()->GetScriptGlobalObject();
if (scope) {
JSObject *obj = scope->GetGlobalJSObject();
if (obj) {
nsCOMPtr<nsIGlobalObject> global =
do_QueryInterface(OwnerDoc()->GetInnerWindow());
if (global) {
if (JSObject *obj = global->GetGlobalJSObject()) {
js::NotifyAnimationActivity(obj);
}
}

View File

@ -81,8 +81,7 @@ ImageListener::OnStartRequest(nsIRequest* request, nsISupports *ctxt)
return NS_ERROR_FAILURE;
}
nsCOMPtr<nsPIDOMWindow> domWindow =
do_QueryInterface(imgDoc->GetScriptGlobalObject());
nsCOMPtr<nsPIDOMWindow> domWindow = imgDoc->GetWindow();
NS_ENSURE_TRUE(domWindow, NS_ERROR_UNEXPECTED);
// Do a ShouldProcess check to see whether to keep loading the image.

View File

@ -1321,7 +1321,8 @@ IsScriptEnabled(nsIDocument *aDoc, nsIDocShell *aContainer)
{
NS_ENSURE_TRUE(aDoc && aContainer, true);
nsCOMPtr<nsIScriptGlobalObject> globalObject = aDoc->GetScriptGlobalObject();
nsCOMPtr<nsIScriptGlobalObject> globalObject =
do_QueryInterface(aDoc->GetWindow());
// Getting context is tricky if the document hasn't had its
// GlobalObject set yet

View File

@ -1172,7 +1172,8 @@ nsBindingManager::GetBindingImplementation(nsIContent* aContent, REFNSIID aIID,
nsIDocument* doc = aContent->OwnerDoc();
nsIScriptGlobalObject *global = doc->GetScriptGlobalObject();
nsCOMPtr<nsIScriptGlobalObject> global =
do_QueryInterface(doc->GetWindow());
if (!global)
return NS_NOINTERFACE;

View File

@ -1254,7 +1254,7 @@ nsXBLBinding::AllowScripts()
return false;
}
nsIScriptGlobalObject* global = doc->GetScriptGlobalObject();
nsCOMPtr<nsIScriptGlobalObject> global = do_QueryInterface(doc->GetWindow());
if (!global) {
return false;
}

View File

@ -195,7 +195,8 @@ InstallXBLField(JSContext* cx,
MOZ_ASSERT(field);
// This mirrors code in nsXBLProtoImpl::InstallImplementation
nsIScriptGlobalObject* global = xblNode->OwnerDoc()->GetScriptGlobalObject();
nsCOMPtr<nsIScriptGlobalObject> global =
do_QueryInterface(xblNode->OwnerDoc()->GetWindow());
if (!global) {
return true;
}

View File

@ -281,7 +281,8 @@ nsXBLProtoImplAnonymousMethod::Execute(nsIContent* aBoundElement)
// nsXBLProtoImpl::InstallImplementation does.
nsIDocument* document = aBoundElement->OwnerDoc();
nsIScriptGlobalObject* global = document->GetScriptGlobalObject();
nsCOMPtr<nsIScriptGlobalObject> global =
do_QueryInterface(document->GetWindow());
if (!global) {
return NS_OK;
}

View File

@ -454,7 +454,7 @@ nsXBLPrototypeHandler::DispatchXBLCommand(EventTarget* aTarget, nsIDOMEvent* aEv
if (!doc)
return NS_ERROR_FAILURE;
privateWindow = do_QueryInterface(doc->GetScriptGlobalObject());
privateWindow = doc->GetWindow();
if (!privateWindow)
return NS_ERROR_FAILURE;
}

View File

@ -97,7 +97,7 @@ already_AddRefed<nsPIWindowRoot>
nsXULCommandDispatcher::GetWindowRoot()
{
if (mDocument) {
nsCOMPtr<nsPIDOMWindow> window(do_QueryInterface(mDocument->GetScriptGlobalObject()));
nsCOMPtr<nsPIDOMWindow> window(mDocument->GetWindow());
if (window) {
return window->GetTopWindowRoot();
}

View File

@ -945,9 +945,9 @@ XULContentSinkImpl::OpenScript(const PRUnichar** aAttributes,
// Don't process scripts that aren't known
if (langID != nsIProgrammingLanguage::UNKNOWN) {
nsIScriptGlobalObject* globalObject = nullptr; // borrowed reference
nsCOMPtr<nsIScriptGlobalObject> globalObject;
if (doc)
globalObject = doc->GetScriptGlobalObject();
globalObject = do_QueryInterface(doc->GetWindow());
nsRefPtr<nsXULPrototypeScript> script =
new nsXULPrototypeScript(aLineNumber, version);
if (! script)

View File

@ -1371,7 +1371,8 @@ nsXULTemplateBuilder::InitHTMLTemplateRoot()
if (! doc)
return NS_ERROR_UNEXPECTED;
nsIScriptGlobalObject *global = doc->GetScriptGlobalObject();
nsCOMPtr<nsIScriptGlobalObject> global =
do_QueryInterface(doc->GetWindow());
if (! global)
return NS_ERROR_UNEXPECTED;

View File

@ -8074,11 +8074,7 @@ nsGlobalWindow::GetPrivateParent()
if (!doc)
return nullptr; // This is ok, just means a null parent.
nsIScriptGlobalObject *globalObject = doc->GetScriptGlobalObject();
if (!globalObject)
return nullptr; // This is ok, just means a null parent.
parent = do_QueryInterface(globalObject);
return doc->GetWindow();
}
if (parent) {

View File

@ -644,7 +644,7 @@ GetDocumentFromNPP(NPP npp)
static JSContext *
GetJSContextFromDoc(nsIDocument *doc)
{
nsIScriptGlobalObject *sgo = doc->GetScriptGlobalObject();
nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(doc->GetWindow());
NS_ENSURE_TRUE(sgo, nullptr);
nsIScriptContext *scx = sgo->GetContext();

View File

@ -1618,7 +1618,8 @@ nsNPAPIPluginInstance::GetJSContext(JSContext* *outContext)
nsresult rv = mOwner->GetDocument(getter_AddRefs(document));
if (NS_SUCCEEDED(rv) && document) {
nsIScriptGlobalObject *global = document->GetScriptGlobalObject();
nsCOMPtr<nsIScriptGlobalObject> global =
do_QueryInterface(document->GetWindow());
if (global) {
nsIScriptContext *context = global->GetContext();

View File

@ -3518,12 +3518,8 @@ nsPrintEngine::TurnScriptingOn(bool aDoTurnOn)
continue;
}
// get the script global object
nsIScriptGlobalObject *scriptGlobalObj = doc->GetScriptGlobalObject();
if (scriptGlobalObj) {
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(scriptGlobalObj);
NS_ASSERTION(window, "Can't get nsPIDOMWindow");
if (nsCOMPtr<nsPIDOMWindow> window = doc->GetWindow()) {
nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObj = do_QueryInterface(window);
nsIScriptContext *scx = scriptGlobalObj->GetContext();
NS_WARN_IF_FALSE(scx, "Can't get nsIScriptContext");
nsresult propThere = NS_PROPTABLE_PROP_NOT_THERE;

View File

@ -2776,7 +2776,7 @@ nsTreeBodyFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
// Bail out now if there's no view or we can't run script because the
// document is a zombie
if (!mView || !GetContent()->GetCurrentDoc()->GetScriptGlobalObject())
if (!mView || !GetContent()->GetCurrentDoc()->GetWindow())
return;
aLists.Content()->AppendNewToTop(new (aBuilder)

View File

@ -101,7 +101,7 @@ nsHtml5TreeOpExecutor::WillParse()
NS_IMETHODIMP
nsHtml5TreeOpExecutor::WillBuildModel(nsDTDMode aDTDMode)
{
if (mDocShell && !GetDocument()->GetScriptGlobalObject() &&
if (mDocShell && !GetDocument()->GetWindow() &&
!IsExternalViewSource()) {
// Not loading as data but script global object not ready
return MarkAsBroken(NS_ERROR_DOM_INVALID_STATE_ERR);
@ -682,13 +682,13 @@ nsHtml5TreeOpExecutor::IsScriptEnabled()
{
if (!mDocument || !mDocShell)
return true;
nsCOMPtr<nsIScriptGlobalObject> globalObject = mDocument->GetScriptGlobalObject();
nsCOMPtr<nsIScriptGlobalObject> globalObject = do_QueryInterface(mDocument->GetWindow());
// Getting context is tricky if the document hasn't had its
// GlobalObject set yet
if (!globalObject) {
nsCOMPtr<nsIScriptGlobalObjectOwner> owner = do_GetInterface(mDocShell);
NS_ENSURE_TRUE(owner, true);
globalObject = owner->GetScriptGlobalObject();
globalObject = do_QueryInterface(mDocument->GetWindow());
NS_ENSURE_TRUE(globalObject, true);
}
nsIScriptContext *scriptContext = globalObject->GetContext();

View File

@ -412,8 +412,8 @@ void nsMenuX::MenuConstruct()
do_GetService(nsIXPConnect::GetCID(), &rv);
if (NS_SUCCEEDED(rv)) {
nsIDocument* ownerDoc = menuPopup->OwnerDoc();
nsIScriptGlobalObject* sgo;
if (ownerDoc && (sgo = ownerDoc->GetScriptGlobalObject())) {
nsCOMPtr<nsIScriptGlobalObject> sgo;
if (ownerDoc && (sgo = do_QueryInterface(ownerDoc->GetWindow()))) {
nsCOMPtr<nsIScriptContext> scriptContext = sgo->GetContext();
JSObject* global = sgo->GetGlobalJSObject();
if (scriptContext && global) {