diff --git a/dom/ipc/TabChild.h b/dom/ipc/TabChild.h index 4d959db2c205..fec4f9521f5a 100644 --- a/dom/ipc/TabChild.h +++ b/dom/ipc/TabChild.h @@ -60,12 +60,16 @@ #include "nsIXPConnect.h" #include "nsIDOMWindow.h" #include "nsIDocShell.h" +#include "nsIDocShellTreeItem.h" +#include "nsIDocShellTreeOwner.h" +#include "nsIDocument.h" #include "nsNetUtil.h" #include "nsFrameMessageManager.h" #include "nsIScriptContext.h" #include "nsDOMEventTargetHelper.h" #include "nsIDialogCreator.h" #include "nsIDialogParamBlock.h" +#include "nsIPresShell.h" #include "nsIPrincipal.h" #include "nsIScriptObjectPrincipal.h" #include "nsIScriptContext.h" @@ -293,6 +297,25 @@ private: DISALLOW_EVIL_CONSTRUCTORS(TabChild); }; +inline TabChild* +GetTabChildFrom(nsIDocShell* aDocShell) +{ + nsCOMPtr tc = do_GetInterface(aDocShell); + return static_cast(tc.get()); +} + +inline TabChild* +GetTabChildFrom(nsIPresShell* aPresShell) +{ + nsIDocument* doc = aPresShell->GetDocument(); + if (!doc) { + return nsnull; + } + nsCOMPtr container = doc->GetContainer(); + nsCOMPtr docShell(do_QueryInterface(container)); + return GetTabChildFrom(docShell); +} + } } diff --git a/dom/ipc/TabParent.cpp b/dom/ipc/TabParent.cpp index ee5e4b62adfc..caa5cd8b1e39 100644 --- a/dom/ipc/TabParent.cpp +++ b/dom/ipc/TabParent.cpp @@ -95,12 +95,9 @@ TabParent::~TabParent() void TabParent::ActorDestroy(ActorDestroyReason why) { - nsCOMPtr frameLoaderOwner = do_QueryInterface(mFrameElement); - if (frameLoaderOwner) { - nsRefPtr frameLoader = frameLoaderOwner->GetFrameLoader(); - if (frameLoader) { - frameLoader->DestroyChild(); - } + nsRefPtr frameLoader = GetFrameLoader(); + if (frameLoader) { + frameLoader->DestroyChild(); } } @@ -516,29 +513,25 @@ TabParent::ReceiveMessage(const nsString& aMessage, const nsString& aJSON, nsTArray* aJSONRetVal) { - nsCOMPtr frameLoaderOwner = - do_QueryInterface(mFrameElement); - if (frameLoaderOwner) { - nsRefPtr frameLoader = frameLoaderOwner->GetFrameLoader(); - if (frameLoader && frameLoader->GetFrameMessageManager()) { - nsFrameMessageManager* manager = frameLoader->GetFrameMessageManager(); - JSContext* ctx = manager->GetJSContext(); - JSAutoRequest ar(ctx); - PRUint32 len = 0; //TODO: obtain a real value in bug 572685 - // Because we want JS messages to have always the same properties, - // create array even if len == 0. - JSObject* objectsArray = JS_NewArrayObject(ctx, len, NULL); - if (!objectsArray) { - return false; - } - - manager->ReceiveMessage(mFrameElement, - aMessage, - aSync, - aJSON, - objectsArray, - aJSONRetVal); + nsRefPtr frameLoader = GetFrameLoader(); + if (frameLoader && frameLoader->GetFrameMessageManager()) { + nsFrameMessageManager* manager = frameLoader->GetFrameMessageManager(); + JSContext* ctx = manager->GetJSContext(); + JSAutoRequest ar(ctx); + PRUint32 len = 0; //TODO: obtain a real value in bug 572685 + // Because we want JS messages to have always the same properties, + // create array even if len == 0. + JSObject* objectsArray = JS_NewArrayObject(ctx, len, NULL); + if (!objectsArray) { + return false; } + + manager->ReceiveMessage(mFrameElement, + aMessage, + aSync, + aJSON, + objectsArray, + aJSONRetVal); } return true; } @@ -709,14 +702,19 @@ TabParent::HandleDelayedDialogs() PRBool TabParent::ShouldDelayDialogs() { - nsCOMPtr frameLoaderOwner = do_QueryInterface(mFrameElement); - NS_ENSURE_TRUE(frameLoaderOwner, PR_TRUE); - nsRefPtr frameLoader = frameLoaderOwner->GetFrameLoader(); + nsRefPtr frameLoader = GetFrameLoader(); NS_ENSURE_TRUE(frameLoader, PR_TRUE); PRBool delay = PR_FALSE; frameLoader->GetDelayRemoteDialogs(&delay); return delay; } +already_AddRefed +TabParent::GetFrameLoader() const +{ + nsCOMPtr frameLoaderOwner = do_QueryInterface(mFrameElement); + return frameLoaderOwner ? frameLoaderOwner->GetFrameLoader() : nsnull; +} + } // namespace tabs } // namespace mozilla diff --git a/dom/ipc/TabParent.h b/dom/ipc/TabParent.h index 198ba076172e..800a7e5dea96 100644 --- a/dom/ipc/TabParent.h +++ b/dom/ipc/TabParent.h @@ -53,6 +53,7 @@ #include "nsIDialogParamBlock.h" #include "nsIAuthPromptProvider.h" +class nsFrameLoader; class nsIURI; class nsIDOMElement; struct gfxMatrix; @@ -222,6 +223,9 @@ protected: nsTArray mDelayedDialogs; PRBool ShouldDelayDialogs(); + +private: + already_AddRefed GetFrameLoader() const; }; } // namespace dom diff --git a/dom/src/geolocation/nsGeolocation.cpp b/dom/src/geolocation/nsGeolocation.cpp index 6326678da606..cde662ae2787 100644 --- a/dom/src/geolocation/nsGeolocation.cpp +++ b/dom/src/geolocation/nsGeolocation.cpp @@ -96,6 +96,7 @@ #define MAX_GEO_REQUESTS_PER_WINDOW 1500 using mozilla::unused; // +using namespace mozilla::dom; //////////////////////////////////////////////////// // nsDOMGeoPositionError @@ -1014,27 +1015,12 @@ nsGeolocation::RegisterRequestWithPrompt(nsGeolocationRequest* request) if (!window) return; - nsIDocShell *docshell = window->GetDocShell(); - - nsCOMPtr item = do_QueryInterface(docshell); - NS_ASSERTION(item, "doc shell tree item is null"); - if (!item) - return; - - nsCOMPtr owner; - item->GetTreeOwner(getter_AddRefs(owner)); - NS_ASSERTION(owner, "doc shell tree owner is null"); - - nsCOMPtr tabchild = do_GetInterface(owner); - if (!tabchild) - return; - // because owner implements nsITabChild, we can assume that it is // the one and only TabChild. - mozilla::dom::TabChild* child = static_cast(tabchild.get()); + TabChild* child = GetTabChildFrom(window->GetDocShell()); - mozilla::dom::PGeolocationRequestChild* a = - child->SendPGeolocationRequestConstructor(request, IPC::URI(mURI)); + PGeolocationRequestChild* a = + child->SendPGeolocationRequestConstructor(request, IPC::URI(mURI)); (void) a->Sendprompt(); return;