Bug 894646 - Various dom deCOM cleanups r=Ms2ger

This commit is contained in:
David Zbarsky 2013-07-23 16:39:17 -07:00
parent 9c6bad4ee6
commit f6f620d05f
26 changed files with 183 additions and 213 deletions

View File

@ -5254,7 +5254,7 @@ nsDocument::Register(JSContext* aCx, const nsAString& aName,
nsINode* parentNode = oldNode->GetParentNode();
MOZ_ASSERT(parentNode, "Node obtained by GetElementsByTagName.");
nsCOMPtr<nsIDOMElement> newElement = do_QueryInterface(newNode);
nsCOMPtr<Element> newElement = do_QueryInterface(newNode);
MOZ_ASSERT(newElement, "Cloned of node obtained by GetElementsByTagName.");
parentNode->ReplaceChild(*newNode, *oldNode, rv);
@ -5279,8 +5279,9 @@ nsDocument::Register(JSContext* aCx, const nsAString& aName,
nsCOMPtr<nsIDOMElementReplaceEvent> ptEvent = do_QueryInterface(event);
MOZ_ASSERT(ptEvent);
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(newElement);
rv = ptEvent->InitElementReplaceEvent(NS_LITERAL_STRING("elementreplace"),
false, false, newElement);
false, false, element);
if (rv.Failed()) {
return nullptr;
}
@ -6619,19 +6620,16 @@ nsIDocument::AdoptNode(nsINode& aAdoptedNode, ErrorResult& rv)
case nsIDOMNode::ATTRIBUTE_NODE:
{
// Remove from ownerElement.
nsCOMPtr<nsIDOMAttr> adoptedAttr = do_QueryInterface(adoptedNode);
NS_ASSERTION(adoptedAttr, "Attribute not implementing nsIDOMAttr");
nsRefPtr<Attr> adoptedAttr = static_cast<Attr*>(adoptedNode);
nsCOMPtr<nsIDOMElement> ownerElement;
rv = adoptedAttr->GetOwnerElement(getter_AddRefs(ownerElement));
nsCOMPtr<Element> ownerElement = adoptedAttr->GetOwnerElement(rv);
if (rv.Failed()) {
return nullptr;
}
if (ownerElement) {
nsCOMPtr<nsIDOMAttr> newAttr;
rv = ownerElement->RemoveAttributeNode(adoptedAttr,
getter_AddRefs(newAttr));
nsRefPtr<Attr> newAttr =
ownerElement->RemoveAttributeNode(*adoptedAttr, rv);
if (rv.Failed()) {
return nullptr;
}

View File

@ -1120,9 +1120,9 @@ nsFrameLoader::SwapWithOtherLoader(nsFrameLoader* aOther,
nsCOMPtr<nsPIDOMWindow> ourWindow = do_GetInterface(ourDocshell);
nsCOMPtr<nsPIDOMWindow> otherWindow = do_GetInterface(otherDocshell);
nsCOMPtr<nsIDOMElement> ourFrameElement =
nsCOMPtr<Element> ourFrameElement =
ourWindow->GetFrameElementInternal();
nsCOMPtr<nsIDOMElement> otherFrameElement =
nsCOMPtr<Element> otherFrameElement =
otherWindow->GetFrameElementInternal();
nsCOMPtr<EventTarget> ourChromeEventHandler =
@ -1648,7 +1648,7 @@ nsFrameLoader::MaybeCreateDocShell()
// the right chrome event handler.
// Tell the window about the frame that hosts it.
nsCOMPtr<nsIDOMElement> frame_element(do_QueryInterface(mOwnerContent));
nsCOMPtr<Element> frame_element = mOwnerContent;
NS_ASSERTION(frame_element, "frame loader owner element not a DOM element!");
nsCOMPtr<nsPIDOMWindow> win_private(do_GetInterface(mDocShell));
@ -2063,7 +2063,7 @@ nsFrameLoader::TryRemoteBrowser()
context.SetTabContextForBrowserFrame(containingApp, scrollingBehavior);
}
nsCOMPtr<nsIDOMElement> ownerElement = do_QueryInterface(mOwnerContent);
nsCOMPtr<Element> ownerElement = mOwnerContent;
mRemoteBrowser = ContentParent::CreateBrowserOrApp(context, ownerElement);
if (mRemoteBrowser) {
nsCOMPtr<nsIDocShellTreeItem> rootItem;

View File

@ -33,6 +33,7 @@
#include "nsError.h"
#include "nsEventDispatcher.h"
#include "nsDOMClassInfoID.h"
#include "mozilla/dom/Element.h"
#ifdef PR_LOGGING
static PRLogModuleInfo* gLog;
@ -203,7 +204,8 @@ nsXULCommandDispatcher::SetFocusedWindow(nsIDOMWindow* aWindow)
// end up focusing whatever is currently focused inside the frame. Since
// setting the command dispatcher's focused window doesn't raise the window,
// setting it to a top-level window doesn't need to do anything.
nsCOMPtr<nsIDOMElement> frameElement = window->GetFrameElementInternal();
nsCOMPtr<nsIDOMElement> frameElement =
do_QueryInterface(window->GetFrameElementInternal());
if (frameElement)
return fm->SetFocus(frameElement, 0);

View File

@ -10,7 +10,7 @@
#include "SerializedLoadContext.h"
#include "mozilla/Attributes.h"
#include "nsWeakReference.h"
#include "nsIDOMElement.h"
#include "mozilla/dom/Element.h"
class mozIApplication;
@ -35,7 +35,7 @@ public:
// AppId/inBrowser arguments override those in SerializedLoadContext provided
// by child process.
LoadContext(const IPC::SerializedLoadContext& aToCopy,
nsIDOMElement* aTopFrameElement,
dom::Element* aTopFrameElement,
uint32_t aAppId, bool aInBrowser)
: mTopFrameElement(do_GetWeakReference(aTopFrameElement))
, mAppId(aAppId)

View File

@ -8624,7 +8624,7 @@ nsDocShell::InternalLoad(nsIURI * aURI,
// First, notify any nsIContentPolicy listeners about the document load.
// Only abort the load if a content policy listener explicitly vetos it!
//
nsCOMPtr<nsIDOMElement> requestingElement;
nsCOMPtr<Element> requestingElement;
// Use nsPIDOMWindow since we _want_ to cross the chrome boundary if needed
if (mScriptGlobal)
requestingElement = mScriptGlobal->GetFrameElementInternal();

View File

@ -8,6 +8,7 @@
#include "nsIDOMWindow.h"
#include "nsIDOMElement.h"
#include "nsIPrincipal.h"
#include "mozilla/dom/Element.h"
#include "mozilla/unused.h"
using mozilla::unused; // <snicker>
@ -92,7 +93,8 @@ nsContentPermissionRequestProxy::GetElement(nsIDOMElement * *aRequestingElement)
return NS_ERROR_FAILURE;
}
NS_IF_ADDREF(*aRequestingElement = mParent->mElement);
nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(mParent->mElement);
elem.forget(aRequestingElement);
return NS_OK;
}
@ -124,7 +126,7 @@ namespace dom {
ContentPermissionRequestParent::ContentPermissionRequestParent(const nsACString& aType,
const nsACString& aAccess,
nsIDOMElement *aElement,
Element* aElement,
const IPC::Principal& aPrincipal)
{
MOZ_COUNT_CTOR(ContentPermissionRequestParent);

View File

@ -9,7 +9,6 @@
#include "nsIContentPermissionPrompt.h"
#include "nsString.h"
#include "nsIDOMElement.h"
#include "mozilla/dom/PermissionMessageUtils.h"
#include "mozilla/dom/PContentPermissionRequestParent.h"
@ -19,14 +18,19 @@ class nsContentPermissionRequestProxy;
namespace mozilla {
namespace dom {
class Element;
class ContentPermissionRequestParent : public PContentPermissionRequestParent
{
public:
ContentPermissionRequestParent(const nsACString& type, const nsACString& access, nsIDOMElement *element, const IPC::Principal& principal);
ContentPermissionRequestParent(const nsACString& type,
const nsACString& access,
Element* element,
const IPC::Principal& principal);
virtual ~ContentPermissionRequestParent();
nsCOMPtr<nsIPrincipal> mPrincipal;
nsCOMPtr<nsIDOMElement> mElement;
nsCOMPtr<Element> mElement;
nsCOMPtr<nsContentPermissionRequestProxy> mProxy;
nsCString mType;
nsCString mAccess;

View File

@ -2505,15 +2505,9 @@ nsDOMWindowUtils::RenderDocument(const nsRect& aRect,
nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow);
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
// Get DOM Document
nsresult rv;
nsCOMPtr<nsIDOMDocument> ddoc;
rv = window->GetDocument(getter_AddRefs(ddoc));
NS_ENSURE_SUCCESS(rv, rv);
// Get Document
nsCOMPtr<nsIDocument> doc = do_QueryInterface(ddoc, &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDocument> doc = window->GetDoc();
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
// Get Primary Shell
nsCOMPtr<nsIPresShell> presShell = doc->GetShell();
@ -3217,23 +3211,15 @@ nsDOMWindowUtils::LoadSheet(nsIURI *aSheetURI, uint32_t aSheetType)
aSheetType == USER_SHEET ||
aSheetType == AUTHOR_SHEET);
nsCOMPtr<nsIDOMWindow> window = do_QueryReferent(mWindow);
nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow);
NS_ENSURE_TRUE(window, NS_ERROR_INVALID_ARG);
nsCOMPtr<nsIDOMDocument> ddoc;
nsresult rv = window->GetDocument(getter_AddRefs(ddoc));
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(ddoc, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocument> doc = do_QueryInterface(ddoc);
NS_ENSURE_TRUE(doc, NS_ERROR_INVALID_ARG);
nsCOMPtr<nsIDocument> doc = window->GetDoc();
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
nsIDocument::additionalSheetType type = convertSheetType(aSheetType);
rv = doc->LoadAdditionalStyleSheet(type, aSheetURI);
NS_ENSURE_SUCCESS(rv, rv);
return NS_OK;
return doc->LoadAdditionalStyleSheet(type, aSheetURI);
}
NS_IMETHODIMP
@ -3248,16 +3234,11 @@ nsDOMWindowUtils::RemoveSheet(nsIURI *aSheetURI, uint32_t aSheetType)
aSheetType == USER_SHEET ||
aSheetType == AUTHOR_SHEET);
nsCOMPtr<nsIDOMWindow> window = do_QueryReferent(mWindow);
nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mWindow);
NS_ENSURE_TRUE(window, NS_ERROR_INVALID_ARG);
nsCOMPtr<nsIDOMDocument> ddoc;
nsresult rv = window->GetDocument(getter_AddRefs(ddoc));
NS_ENSURE_SUCCESS(rv, rv);
NS_ENSURE_TRUE(ddoc, NS_ERROR_FAILURE);
nsCOMPtr<nsIDocument> doc = do_QueryInterface(ddoc);
NS_ENSURE_TRUE(doc, NS_ERROR_INVALID_ARG);
nsCOMPtr<nsIDocument> doc = window->GetDoc();
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
nsIDocument::additionalSheetType type = convertSheetType(aSheetType);

View File

@ -223,6 +223,7 @@
#include "mozilla/Telemetry.h"
#include "nsLocation.h"
#include "nsHTMLDocument.h"
#include "nsWrapperCacheInlines.h"
#include "nsDOMEventTargetHelper.h"
#include "nsIAppsService.h"
@ -2495,7 +2496,7 @@ nsGlobalWindow::SetNewDocument(nsIDocument* aDocument,
"outer and inner globals should have the same prototype");
#endif
nsCOMPtr<nsIContent> frame = do_QueryInterface(GetFrameElementInternal());
nsCOMPtr<Element> frame = GetFrameElementInternal();
if (frame) {
nsPIDOMWindow* parentWindow = frame->OwnerDoc()->GetWindow();
if (parentWindow && parentWindow->TimeoutSuspendCount()) {
@ -2835,7 +2836,7 @@ nsGlobalWindow::UpdateParentTarget()
// child global, and if it doesn't have one, just use the chrome event
// handler itself.
nsCOMPtr<nsIDOMElement> frameElement = GetFrameElementInternal();
nsCOMPtr<Element> frameElement = GetFrameElementInternal();
nsCOMPtr<EventTarget> eventTarget =
TryGetTabChildGlobalAsEventTarget(frameElement);
@ -3096,7 +3097,7 @@ nsGlobalWindow::PostHandleEvent(nsEventChainPostVisitor& aVisitor)
// @see nsDocument::PreHandleEvent.
mIsDocumentLoaded = true;
nsCOMPtr<nsIContent> content(do_QueryInterface(GetFrameElementInternal()));
nsCOMPtr<Element> element = GetFrameElementInternal();
nsIDocShell* docShell = GetDocShell();
int32_t itemType = nsIDocShellTreeItem::typeChrome;
@ -3105,7 +3106,7 @@ nsGlobalWindow::PostHandleEvent(nsEventChainPostVisitor& aVisitor)
docShell->GetItemType(&itemType);
}
if (content && GetParentInternal() &&
if (element && GetParentInternal() &&
itemType != nsIDocShellTreeItem::typeChrome) {
// If we're not in chrome, or at a chrome boundary, fire the
// onload event for the frame element.
@ -3119,7 +3120,7 @@ nsGlobalWindow::PostHandleEvent(nsEventChainPostVisitor& aVisitor)
// be a pres context available). Since we're not firing a GUI
// event we don't need a pres context anyway so we just pass
// null as the pres context all the time here.
nsEventDispatcher::Dispatch(content, nullptr, &event, nullptr, &status);
nsEventDispatcher::Dispatch(element, nullptr, &event, nullptr, &status);
}
}
@ -3277,6 +3278,37 @@ nsPIDOMWindow::MaybeCreateDoc()
}
}
Element*
nsPIDOMWindow::GetFrameElementInternal() const
{
if (mOuterWindow) {
return mOuterWindow->GetFrameElementInternal();
}
NS_ASSERTION(!IsInnerWindow(),
"GetFrameElementInternal() called on orphan inner window");
return mFrameElement;
}
void
nsPIDOMWindow::SetFrameElementInternal(Element* aFrameElement)
{
if (IsOuterWindow()) {
mFrameElement = aFrameElement;
return;
}
if (!mOuterWindow) {
NS_ERROR("frameElement set on inner window with no outer!");
return;
}
mOuterWindow->SetFrameElementInternal(aFrameElement);
}
void
nsPIDOMWindow::AddAudioContext(AudioContext* aAudioContext)
{
@ -5660,12 +5692,9 @@ nsGlobalWindow::Focus()
mDocShell->GetParent(getter_AddRefs(parentDsti));
// set the parent's current focus to the frame containing this window.
nsCOMPtr<nsIDOMWindow> parent(do_GetInterface(parentDsti));
nsCOMPtr<nsPIDOMWindow> parent = do_GetInterface(parentDsti);
if (parent) {
nsCOMPtr<nsIDOMDocument> parentdomdoc;
parent->GetDocument(getter_AddRefs(parentdomdoc));
nsCOMPtr<nsIDocument> parentdoc = do_QueryInterface(parentdomdoc);
nsCOMPtr<nsIDocument> parentdoc = parent->GetDoc();
if (!parentdoc)
return NS_OK;
@ -6260,11 +6289,10 @@ nsGlobalWindow::FirePopupBlockedEvent(nsIDocument* aDoc,
}
}
void FirePopupWindowEvent(nsIDOMDocument* aDoc)
static void FirePopupWindowEvent(nsIDocument* aDoc)
{
// Fire a "PopupWindow" event
nsCOMPtr<nsIDocument> doc(do_QueryInterface(aDoc));
nsContentUtils::DispatchTrustedEvent(doc, aDoc,
nsContentUtils::DispatchTrustedEvent(aDoc, aDoc,
NS_LITERAL_STRING("PopupWindow"),
true, true);
}
@ -6356,12 +6384,12 @@ nsGlobalWindow::FireAbuseEvents(bool aBlocked, bool aWindow,
nsCOMPtr<nsIDOMWindow> topWindow;
GetTop(getter_AddRefs(topWindow));
if (!topWindow)
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(topWindow);
if (!window) {
return;
}
nsCOMPtr<nsIDOMDocument> topDoc;
topWindow->GetDocument(getter_AddRefs(topDoc));
nsCOMPtr<nsIDocument> topDoc = window->GetDoc();
nsCOMPtr<nsIURI> popupURI;
// build the URI of the would-have-been popup window
@ -6369,10 +6397,10 @@ nsGlobalWindow::FireAbuseEvents(bool aBlocked, bool aWindow,
// first, fetch the opener's base URI
nsIURI *baseURL = 0;
nsIURI *baseURL = nullptr;
JSContext *cx = nsContentUtils::GetCurrentJSContext();
nsCOMPtr<nsIDOMWindow> contextWindow;
nsCOMPtr<nsPIDOMWindow> contextWindow;
if (cx) {
nsIScriptContext *currentCX = nsJSUtils::GetDynamicScriptContext(cx);
@ -6380,12 +6408,11 @@ nsGlobalWindow::FireAbuseEvents(bool aBlocked, bool aWindow,
contextWindow = do_QueryInterface(currentCX->GetGlobalObject());
}
}
if (!contextWindow)
contextWindow = static_cast<nsIDOMWindow*>(this);
if (!contextWindow) {
contextWindow = this;
}
nsCOMPtr<nsIDOMDocument> domdoc;
contextWindow->GetDocument(getter_AddRefs(domdoc));
nsCOMPtr<nsIDocument> doc(do_QueryInterface(domdoc));
nsCOMPtr<nsIDocument> doc = contextWindow->GetDoc();
if (doc)
baseURL = doc->GetDocBaseURI();
@ -6397,8 +6424,7 @@ nsGlobalWindow::FireAbuseEvents(bool aBlocked, bool aWindow,
// fire an event chock full of informative URIs
if (aBlocked) {
nsCOMPtr<nsIDocument> topDocument = do_QueryInterface(topDoc);
FirePopupBlockedEvent(topDocument, this, popupURI, aPopupWindowName,
FirePopupBlockedEvent(topDoc, this, popupURI, aPopupWindowName,
aPopupWindowFeatures);
}
if (aWindow)
@ -7608,9 +7634,9 @@ nsGlobalWindow::GetRealFrameElement(nsIDOMElement** aFrameElement)
return NS_OK;
}
*aFrameElement = mFrameElement;
NS_IF_ADDREF(*aFrameElement);
if (mFrameElement) {
CallQueryInterface(mFrameElement, aFrameElement);
}
return NS_OK;
}
@ -8178,8 +8204,7 @@ nsGlobalWindow::GetPrivateRoot()
}
}
return static_cast<nsGlobalWindow *>
(static_cast<nsIDOMWindow *>(top));
return static_cast<nsGlobalWindow*>(top.get());
}
@ -8368,10 +8393,9 @@ nsGlobalWindow::SetChromeEventHandler(EventTarget* aChromeEventHandler)
static bool IsLink(nsIContent* aContent)
{
nsCOMPtr<nsIDOMHTMLAnchorElement> anchor = do_QueryInterface(aContent);
return (anchor || (aContent &&
aContent->AttrValueIs(kNameSpaceID_XLink, nsGkAtoms::type,
nsGkAtoms::simple, eCaseMatters)));
return aContent && (aContent->IsHTML(nsGkAtoms::a) ||
aContent->AttrValueIs(kNameSpaceID_XLink, nsGkAtoms::type,
nsGkAtoms::simple, eCaseMatters));
}
void
@ -8772,7 +8796,7 @@ nsGlobalWindow::UpdateCanvasFocus(bool aFocusChanged, nsIContent* aNewContent)
if (canvasFrame) {
canvasFrame->SetHasFocus(false);
}
}
}
}
}
@ -9138,18 +9162,16 @@ nsGlobalWindow::FireOfflineStatusEvent()
}
// The event is fired at the body element, or if there is no body element,
// at the document.
nsCOMPtr<nsISupports> eventTarget = mDoc.get();
nsCOMPtr<nsIDOMHTMLDocument> htmlDoc = do_QueryInterface(mDoc);
nsCOMPtr<EventTarget> eventTarget = mDoc.get();
nsHTMLDocument* htmlDoc = mDoc->AsHTMLDocument();
if (htmlDoc) {
nsCOMPtr<nsIDOMHTMLElement> body;
htmlDoc->GetBody(getter_AddRefs(body));
Element* body = htmlDoc->GetBody();
if (body) {
eventTarget = body;
}
}
else {
} else {
Element* documentElement = mDoc->GetDocumentElement();
if(documentElement) {
if (documentElement) {
eventTarget = documentElement;
}
}
@ -9928,7 +9950,7 @@ nsGlobalWindow::OpenInternal(const nsAString& aUrl, const nsAString& aName,
FireAbuseEvents(true, false, aUrl, aName, aOptions);
return aDoJSFixups ? NS_OK : NS_ERROR_FAILURE;
}
}
}
nsCOMPtr<nsIDOMWindow> domReturn;
@ -9989,7 +10011,7 @@ nsGlobalWindow::OpenInternal(const nsAString& aUrl, const nsAString& aName,
NS_ENSURE_TRUE(domReturn, NS_OK);
domReturn.swap(*aReturn);
if (aDoJSFixups) {
if (aDoJSFixups) {
nsCOMPtr<nsIDOMChromeWindow> chrome_win(do_QueryInterface(*aReturn));
if (!chrome_win) {
// A new non-chrome window was created from a call to
@ -10857,7 +10879,7 @@ nsGlobalWindow::BuildURIfromBase(const char *aURL, nsIURI **aBuiltURI,
nsAutoCString charset(NS_LITERAL_CSTRING("UTF-8")); // default to utf-8
nsIURI* baseURI = nullptr;
nsCOMPtr<nsIURI> uriToLoad;
nsCOMPtr<nsIDOMWindow> sourceWindow;
nsCOMPtr<nsPIDOMWindow> sourceWindow;
if (cx) {
nsIScriptContext *scriptcx = nsJSUtils::GetDynamicScriptContext(cx);
@ -10866,14 +10888,12 @@ nsGlobalWindow::BuildURIfromBase(const char *aURL, nsIURI **aBuiltURI,
}
if (!sourceWindow) {
sourceWindow = do_QueryInterface(NS_ISUPPORTS_CAST(nsIDOMWindow *, this));
sourceWindow = this;
*aFreeSecurityPass = true;
}
if (sourceWindow) {
nsCOMPtr<nsIDOMDocument> domDoc;
sourceWindow->GetDocument(getter_AddRefs(domDoc));
nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc));
nsCOMPtr<nsIDocument> doc = sourceWindow->GetDoc();
if (doc) {
baseURI = doc->GetDocBaseURI();
charset = doc->GetDocumentCharacterSet();
@ -11069,7 +11089,7 @@ nsGlobalWindow::SuspendTimeouts(uint32_t aIncrease,
// This is a bit hackish. Only freeze/suspend windows which are truly our
// subwindows.
nsCOMPtr<nsIContent> frame = do_QueryInterface(pWin->GetFrameElementInternal());
nsCOMPtr<Element> frame = pWin->GetFrameElementInternal();
if (!mDoc || !frame || mDoc != frame->OwnerDoc() || !inner) {
continue;
}
@ -11181,7 +11201,7 @@ nsGlobalWindow::ResumeTimeouts(bool aThawChildren)
// This is a bit hackish. Only thaw/resume windows which are truly our
// subwindows.
nsCOMPtr<nsIContent> frame = do_QueryInterface(pWin->GetFrameElementInternal());
nsCOMPtr<Element> frame = pWin->GetFrameElementInternal();
if (!mDoc || !frame || mDoc != frame->OwnerDoc() || !inner) {
continue;
}

View File

@ -43,21 +43,13 @@ GetDocumentCharacterSetForURI(const nsAString& aHref, nsACString& aCharset)
{
aCharset.Truncate();
nsresult rv;
JSContext *cx = nsContentUtils::GetCurrentJSContext();
if (cx) {
nsCOMPtr<nsIDOMWindow> window =
nsCOMPtr<nsPIDOMWindow> window =
do_QueryInterface(nsJSUtils::GetDynamicScriptGlobal(cx));
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
nsCOMPtr<nsIDOMDocument> domDoc;
rv = window->GetDocument(getter_AddRefs(domDoc));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc));
if (doc) {
if (nsIDocument* doc = window->GetDoc()) {
aCharset = doc->GetDocumentCharacterSet();
}
}

View File

@ -19,7 +19,6 @@
#include "nsTArray.h"
#include "nsIURI.h"
#include "mozilla/dom/EventTarget.h"
#include "js/RootingAPI.h"
#define DOM_WINDOW_DESTROYED_TOPIC "dom-window-destroyed"
@ -54,6 +53,7 @@ class nsPIWindowRoot;
namespace mozilla {
namespace dom {
class AudioContext;
class Element;
}
}
@ -196,34 +196,8 @@ public:
// Internal getter/setter for the frame element, this version of the
// getter crosses chrome boundaries whereas the public scriptable
// one doesn't for security reasons.
nsIDOMElement* GetFrameElementInternal() const
{
if (mOuterWindow) {
return mOuterWindow->GetFrameElementInternal();
}
NS_ASSERTION(!IsInnerWindow(),
"GetFrameElementInternal() called on orphan inner window");
return mFrameElement;
}
void SetFrameElementInternal(nsIDOMElement *aFrameElement)
{
if (IsOuterWindow()) {
mFrameElement = aFrameElement;
return;
}
if (!mOuterWindow) {
NS_ERROR("frameElement set on inner window with no outer!");
return;
}
mOuterWindow->SetFrameElementInternal(aFrameElement);
}
mozilla::dom::Element* GetFrameElementInternal() const;
void SetFrameElementInternal(mozilla::dom::Element* aFrameElement);
bool IsLoadingOrRunningTimeout() const
{
@ -339,9 +313,8 @@ public:
nsPIDOMWindow *EnsureInnerWindow()
{
NS_ASSERTION(IsOuterWindow(), "EnsureInnerWindow called on inner window");
// GetDocument forces inner window creation if there isn't one already
nsCOMPtr<nsIDOMDocument> doc;
GetDocument(getter_AddRefs(doc));
// GetDoc forces inner window creation if there isn't one already
GetDoc();
return GetCurrentInnerWindow();
}
@ -698,7 +671,7 @@ protected:
nsCOMPtr<mozilla::dom::EventTarget> mParentTarget; // strong
// These members are only used on outer windows.
nsCOMPtr<nsIDOMElement> mFrameElement;
nsCOMPtr<mozilla::dom::Element> mFrameElement;
nsIDocShell *mDocShell; // Weak Reference
// mPerformance is only used on inner windows.

View File

@ -149,8 +149,7 @@ BrowserElementParent::OpenWindowOOP(TabParent* aOpenerTabParent,
const nsAString& aFeatures)
{
// Create an iframe owned by the same document which owns openerFrameElement.
nsCOMPtr<Element> openerFrameElement =
do_QueryInterface(aOpenerTabParent->GetOwnerElement());
nsCOMPtr<Element> openerFrameElement = aOpenerTabParent->GetOwnerElement();
NS_ENSURE_TRUE(openerFrameElement, false);
nsRefPtr<HTMLIFrameElement> popupFrameElement =
CreateIframe(openerFrameElement, aName, /* aRemote = */ true);
@ -262,8 +261,7 @@ private:
NS_IMETHODIMP DispatchAsyncScrollEventRunnable::Run()
{
nsIDOMElement* element = mTabParent->GetOwnerElement();
nsCOMPtr<Element> frameElement = do_QueryInterface(element);
nsCOMPtr<Element> frameElement = mTabParent->GetOwnerElement();
// Create the event's detail object.
nsRefPtr<nsAsyncScrollEventDetail> detail =
new nsAsyncScrollEventDetail(mContentRect.x, mContentRect.y,

View File

@ -461,7 +461,7 @@ PrivilegesForApp(mozIApplication* aApp)
}
/*static*/ ProcessPriority
ContentParent::GetInitialProcessPriority(nsIDOMElement* aFrameElement)
ContentParent::GetInitialProcessPriority(Element* aFrameElement)
{
// Frames with mozapptype == critical which are expecting a system message
// get FOREGROUND_HIGH priority. All other frames get FOREGROUND priority.
@ -470,10 +470,8 @@ ContentParent::GetInitialProcessPriority(nsIDOMElement* aFrameElement)
return PROCESS_PRIORITY_FOREGROUND;
}
nsAutoString appType;
nsCOMPtr<Element> frameElement = do_QueryInterface(aFrameElement);
frameElement->GetAttr(kNameSpaceID_None, nsGkAtoms::mozapptype, appType);
if (appType != NS_LITERAL_STRING("critical")) {
if (!aFrameElement->AttrValueIs(kNameSpaceID_None, nsGkAtoms::mozapptype,
NS_LITERAL_STRING("critical"), eCaseMatters)) {
return PROCESS_PRIORITY_FOREGROUND;
}
@ -490,7 +488,7 @@ ContentParent::GetInitialProcessPriority(nsIDOMElement* aFrameElement)
/*static*/ TabParent*
ContentParent::CreateBrowserOrApp(const TabContext& aContext,
nsIDOMElement* aFrameElement)
Element* aFrameElement)
{
if (!sCanLaunchSubprocesses) {
return nullptr;
@ -745,7 +743,7 @@ NS_IMPL_ISUPPORTS1(SystemMessageHandledListener,
} // anonymous namespace
void
ContentParent::MaybeTakeCPUWakeLock(nsIDOMElement* aFrameElement)
ContentParent::MaybeTakeCPUWakeLock(Element* aFrameElement)
{
// Take the CPU wake lock on behalf of this processs if it's expecting a
// system message. We'll release the CPU lock once the message is

View File

@ -103,7 +103,7 @@ public:
*/
static TabParent*
CreateBrowserOrApp(const TabContext& aContext,
nsIDOMElement* aFrameElement);
Element* aFrameElement);
static void GetAll(nsTArray<ContentParent*>& aArray);
static void GetAllEvenIfDead(nsTArray<ContentParent*>& aArray);
@ -195,7 +195,7 @@ private:
ChildPrivileges aPrivs,
hal::ProcessPriority aInitialPriority);
static hal::ProcessPriority GetInitialProcessPriority(nsIDOMElement* aFrameElement);
static hal::ProcessPriority GetInitialProcessPriority(Element* aFrameElement);
// Hide the raw constructor methods since we don't want client code
// using them.
@ -218,7 +218,7 @@ private:
// has a pending system message, this function acquires the CPU wake lock on
// behalf of the child. We'll release the lock when the system message is
// handled or after a timeout, whichever comes first.
void MaybeTakeCPUWakeLock(nsIDOMElement* aFrameElement);
void MaybeTakeCPUWakeLock(Element* aFrameElement);
// Set the child process's priority and then check whether the child is
// still alive. Returns true if the process is still alive, and false

View File

@ -7,6 +7,7 @@
#include "ProcessPriorityManager.h"
#include "mozilla/ClearOnShutdown.h"
#include "mozilla/dom/ContentParent.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/TabParent.h"
#include "mozilla/Hal.h"
#include "mozilla/Preferences.h"
@ -829,8 +830,7 @@ ParticularProcessPriorityManager::IsExpectingSystemMessage()
mContentParent->ManagedPBrowserParent();
for (uint32_t i = 0; i < browsers.Length(); i++) {
TabParent* tp = static_cast<TabParent*>(browsers[i]);
nsCOMPtr<nsIDOMElement> ownerElement = tp->GetOwnerElement();
nsCOMPtr<nsIMozBrowserFrame> bf = do_QueryInterface(ownerElement);
nsCOMPtr<nsIMozBrowserFrame> bf = do_QueryInterface(tp->GetOwnerElement());
if (!bf) {
continue;
}

View File

@ -544,13 +544,13 @@ TabChild::HandlePossibleViewportChange()
float minScale = 1.0f;
nsCOMPtr<nsIDOMElement> htmlDOMElement = do_QueryInterface(document->GetHtmlElement());
nsCOMPtr<Element> htmlDOMElement = document->GetHtmlElement();
HTMLBodyElement* bodyDOMElement = document->GetBodyElement();
int32_t htmlWidth = 0, htmlHeight = 0;
if (htmlDOMElement) {
htmlDOMElement->GetScrollWidth(&htmlWidth);
htmlDOMElement->GetScrollHeight(&htmlHeight);
htmlWidth = htmlDOMElement->ScrollWidth();
htmlHeight = htmlDOMElement->ScrollHeight();
}
int32_t bodyWidth = 0, bodyHeight = 0;
if (bodyDOMElement) {

View File

@ -217,7 +217,7 @@ TabParent::~TabParent()
}
void
TabParent::SetOwnerElement(nsIDOMElement* aElement)
TabParent::SetOwnerElement(Element* aElement)
{
mFrameElement = aElement;
TryCacheDPIAndScale();
@ -316,7 +316,8 @@ TabParent::RecvMoveFocus(const bool& aForward)
nsCOMPtr<nsIDOMElement> dummy;
uint32_t type = aForward ? uint32_t(nsIFocusManager::MOVEFOCUS_FORWARD)
: uint32_t(nsIFocusManager::MOVEFOCUS_BACKWARD);
fm->MoveFocus(nullptr, mFrameElement, type, nsIFocusManager::FLAG_BYKEY,
nsCOMPtr<nsIDOMElement> frame = do_QueryInterface(mFrameElement);
fm->MoveFocus(nullptr, frame, type, nsIFocusManager::FLAG_BYKEY,
getter_AddRefs(dummy));
}
return true;
@ -1242,9 +1243,8 @@ TabParent::HandleDelayedDialogs()
{
nsCOMPtr<nsIWindowWatcher> ww = do_GetService(NS_WINDOWWATCHER_CONTRACTID);
nsCOMPtr<nsIDOMWindow> window;
nsCOMPtr<nsIContent> frame = do_QueryInterface(mFrameElement);
if (frame) {
window = do_QueryInterface(frame->OwnerDoc()->GetWindow());
if (mFrameElement) {
window = do_QueryInterface(mFrameElement->OwnerDoc()->GetWindow());
}
nsCOMPtr<nsIDialogCreator> dialogCreator = do_QueryInterface(mBrowserDOMWindow);
while (!ShouldDelayDialogs() && mDelayedDialogs.Length()) {
@ -1255,9 +1255,10 @@ TabParent::HandleDelayedDialogs()
params.swap(data->mParams);
PContentDialogParent* dialog = data->mDialog;
if (dialogCreator) {
nsCOMPtr<nsIDOMElement> frame = do_QueryInterface(mFrameElement);
dialogCreator->OpenDialog(data->mType,
data->mName, data->mFeatures,
params, mFrameElement);
params, frame);
} else if (ww) {
nsAutoCString url;
if (data->mType) {
@ -1286,7 +1287,7 @@ TabParent::HandleDelayedDialogs()
}
}
if (ShouldDelayDialogs() && mDelayedDialogs.Length()) {
nsContentUtils::DispatchTrustedEvent(frame->OwnerDoc(), frame,
nsContentUtils::DispatchTrustedEvent(mFrameElement->OwnerDoc(), mFrameElement,
NS_LITERAL_STRING("MozDelayedModalDialog"),
true, true);
}
@ -1388,11 +1389,7 @@ TabParent::TryCacheDPIAndScale()
if (!widget && mFrameElement) {
// Even if we don't have a widget (e.g. because we're display:none), there's
// probably a widget somewhere in the hierarchy our frame element lives in.
nsCOMPtr<nsIDOMDocument> ownerDoc;
mFrameElement->GetOwnerDocument(getter_AddRefs(ownerDoc));
nsCOMPtr<nsIDocument> doc = do_QueryInterface(ownerDoc);
widget = nsContentUtils::WidgetForDocument(doc);
widget = nsContentUtils::WidgetForDocument(mFrameElement->OwnerDoc());
}
if (widget) {

View File

@ -29,7 +29,6 @@ struct JSContext;
class JSObject;
class mozIApplication;
class nsFrameLoader;
class nsIDOMElement;
class nsIURI;
class CpowHolder;
@ -47,6 +46,7 @@ class RenderFrameParent;
namespace dom {
class ClonedMessageData;
class Element;
struct StructuredCloneData;
class ContentDialogParent : public PContentDialogParent {};
@ -63,8 +63,8 @@ class TabParent : public PBrowserParent
public:
TabParent(ContentParent* aManager, const TabContext& aContext);
virtual ~TabParent();
nsIDOMElement* GetOwnerElement() { return mFrameElement; }
void SetOwnerElement(nsIDOMElement* aElement);
Element* GetOwnerElement() const { return mFrameElement; }
void SetOwnerElement(Element* aElement);
/**
* Get the mozapptype attribute from this TabParent's owner DOM element.
@ -254,7 +254,7 @@ protected:
const nsCString& aASCIIOrigin,
bool* aAllowed);
nsIDOMElement* mFrameElement;
Element* mFrameElement;
nsCOMPtr<nsIBrowserDOMWindow> mBrowserDOMWindow;
struct DelayedDialogData

View File

@ -68,7 +68,6 @@
#include "CoreLocationLocationProvider.h"
#endif
#include "nsIDOMDocument.h"
#include "nsIDocument.h"
// Some limit to the number of get or watch geolocation requests
@ -1049,9 +1048,7 @@ Geolocation::Init(nsIDOMWindow* aContentDom)
}
// Grab the principal of the document
nsCOMPtr<nsIDOMDocument> domdoc;
aContentDom->GetDocument(getter_AddRefs(domdoc));
nsCOMPtr<nsIDocument> doc = do_QueryInterface(domdoc);
nsCOMPtr<nsIDocument> doc = window->GetDoc();
if (!doc) {
return NS_ERROR_FAILURE;
}

View File

@ -8,10 +8,10 @@
#include "nsDeviceSensors.h"
#include "nsAutoPtr.h"
#include "nsIDocument.h"
#include "nsIDOMEvent.h"
#include "nsIDOMWindow.h"
#include "nsPIDOMWindow.h"
#include "nsIDOMDocument.h"
#include "nsIServiceManager.h"
#include "nsIServiceManager.h"
#include "GeneratedEvents.h"
@ -19,12 +19,16 @@
#include "mozilla/Attributes.h"
#include "nsIPermissionManager.h"
using namespace mozilla;
using namespace mozilla::dom;
using namespace hal;
#undef near
// Microsoft's API Name hackery sucks
#undef CreateEvent
// also see sDefaultSensorHint in mobile/android/base/GeckoAppShell.java
#define DEFAULT_SENSOR_POLL 100
@ -212,17 +216,16 @@ nsDeviceSensors::Notify(const mozilla::hal::SensorData& aSensorData)
continue;
}
nsCOMPtr<nsIDOMDocument> domdoc;
windowListeners[i]->GetDocument(getter_AddRefs(domdoc));
nsCOMPtr<nsIDocument> doc = pwindow->GetDoc();
if (domdoc) {
if (doc) {
nsCOMPtr<mozilla::dom::EventTarget> target = do_QueryInterface(windowListeners[i]);
if (type == nsIDeviceSensorData::TYPE_ACCELERATION ||
type == nsIDeviceSensorData::TYPE_LINEAR_ACCELERATION ||
type == nsIDeviceSensorData::TYPE_GYROSCOPE)
FireDOMMotionEvent(domdoc, target, type, x, y, z);
FireDOMMotionEvent(doc, target, type, x, y, z);
else if (type == nsIDeviceSensorData::TYPE_ORIENTATION)
FireDOMOrientationEvent(domdoc, target, x, y, z);
FireDOMOrientationEvent(doc, target, x, y, z);
else if (type == nsIDeviceSensorData::TYPE_PROXIMITY)
FireDOMProximityEvent(target, x, y, z);
else if (type == nsIDeviceSensorData::TYPE_LIGHT)
@ -305,17 +308,17 @@ nsDeviceSensors::FireDOMUserProximityEvent(mozilla::dom::EventTarget* aTarget,
}
void
nsDeviceSensors::FireDOMOrientationEvent(nsIDOMDocument* domdoc,
nsDeviceSensors::FireDOMOrientationEvent(nsIDocument* doc,
EventTarget* target,
double alpha,
double beta,
double gamma)
{
nsCOMPtr<nsIDOMEvent> event;
ErrorResult rv;
nsRefPtr<nsDOMEvent> event = doc->CreateEvent(NS_LITERAL_STRING("DeviceOrientationEvent"), rv);
bool defaultActionEnabled = true;
domdoc->CreateEvent(NS_LITERAL_STRING("DeviceOrientationEvent"), getter_AddRefs(event));
nsCOMPtr<nsIDOMDeviceOrientationEvent> oe = do_QueryInterface(event);
nsCOMPtr<nsIDOMDeviceOrientationEvent> oe = do_QueryObject(event);
if (!oe) {
return;
@ -336,7 +339,7 @@ nsDeviceSensors::FireDOMOrientationEvent(nsIDOMDocument* domdoc,
void
nsDeviceSensors::FireDOMMotionEvent(nsIDOMDocument *domdoc,
nsDeviceSensors::FireDOMMotionEvent(nsIDocument* doc,
EventTarget* target,
uint32_t type,
double x,
@ -362,10 +365,10 @@ nsDeviceSensors::FireDOMMotionEvent(nsIDOMDocument *domdoc,
return;
}
nsCOMPtr<nsIDOMEvent> event;
domdoc->CreateEvent(NS_LITERAL_STRING("DeviceMotionEvent"), getter_AddRefs(event));
ErrorResult rv;
nsRefPtr<nsDOMEvent> event = doc->CreateEvent(NS_LITERAL_STRING("DeviceMotionEvent"), rv);
nsCOMPtr<nsIDOMDeviceMotionEvent> me = do_QueryInterface(event);
nsCOMPtr<nsIDOMDeviceMotionEvent> me = do_QueryObject(event);
if (!me)
return;

View File

@ -27,6 +27,7 @@
#define NS_DEVICE_SENSORS_CONTRACTID "@mozilla.org/devicesensors;1"
class nsIDocument;
class nsIDOMWindow;
namespace mozilla {
@ -62,13 +63,13 @@ private:
void FireDOMUserProximityEvent(mozilla::dom::EventTarget* aTarget,
bool aNear);
void FireDOMOrientationEvent(class nsIDOMDocument *domDoc,
void FireDOMOrientationEvent(nsIDocument* doc,
mozilla::dom::EventTarget* target,
double alpha,
double beta,
double gamma);
void FireDOMMotionEvent(class nsIDOMDocument *domDoc,
void FireDOMMotionEvent(nsIDocument* doc,
mozilla::dom::EventTarget* target,
uint32_t type,
double x,

View File

@ -37,6 +37,7 @@
#include "nsError.h"
#include "nsFocusManager.h"
#include "mozilla/Services.h"
#include "mozilla/dom/Element.h"
#if DEBUG
#include "nsIWebNavigation.h"
@ -851,7 +852,8 @@ nsresult nsWebBrowserFind::OnFind(nsIDOMWindow *aFoundWindow)
nsCOMPtr<nsPIDOMWindow> window(do_QueryInterface(aFoundWindow));
NS_ENSURE_TRUE(window, NS_ERROR_FAILURE);
nsCOMPtr<nsIDOMElement> frameElement = window->GetFrameElementInternal();
nsCOMPtr<nsIDOMElement> frameElement =
do_QueryInterface(window->GetFrameElementInternal());
if (frameElement)
fm->SetFocus(frameElement, 0);

View File

@ -96,11 +96,11 @@ inDOMUtils::GetParentForNode(nsIDOMNode* aNode,
NS_ENSURE_ARG_POINTER(aNode);
// First do the special cases -- document nodes and anonymous content
nsCOMPtr<nsIDOMDocument> doc(do_QueryInterface(aNode));
nsCOMPtr<nsIDocument> doc(do_QueryInterface(aNode));
nsCOMPtr<nsIDOMNode> parent;
if (doc) {
parent = inLayoutUtils::GetContainerFor(doc);
parent = inLayoutUtils::GetContainerFor(*doc);
} else if (aShowingAnonymousContent) {
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
if (content) {

View File

@ -12,6 +12,7 @@
#include "nsIDocShell.h"
#include "nsIPresShell.h"
#include "nsPresContext.h"
#include "mozilla/dom/Element.h"
///////////////////////////////////////////////////////////////////////////////
@ -80,19 +81,19 @@ inLayoutUtils::GetSubDocumentFor(nsIDOMNode* aNode)
return domdoc;
}
}
return nullptr;
}
nsIDOMNode*
inLayoutUtils::GetContainerFor(nsIDOMDocument* aDoc)
inLayoutUtils::GetContainerFor(const nsIDocument& aDoc)
{
nsCOMPtr<nsIDocument> doc = do_QueryInterface(aDoc);
if (!doc) return nullptr;
nsPIDOMWindow* pwin = aDoc.GetWindow();
if (!pwin) {
return nullptr;
}
nsPIDOMWindow *pwin = doc->GetWindow();
if (!pwin) return nullptr;
return pwin->GetFrameElementInternal();
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(pwin->GetFrameElementInternal());
return node;
}

View File

@ -6,6 +6,7 @@
#ifndef __inLayoutUtils_h__
#define __inLayoutUtils_h__
class nsIDocument;
class nsIDOMDocument;
class nsIDOMElement;
class nsIDOMNode;
@ -24,7 +25,7 @@ public:
static nsIFrame* GetFrameFor(nsIDOMElement* aElement);
static nsEventStateManager* GetEventStateManagerFor(nsIDOMElement *aElement);
static nsIDOMDocument* GetSubDocumentFor(nsIDOMNode* aNode);
static nsIDOMNode* GetContainerFor(nsIDOMDocument* aDoc);
static nsIDOMNode* GetContainerFor(const nsIDocument& aDoc);
};
#endif // __inLayoutUtils_h__

View File

@ -137,7 +137,7 @@ NeckoParent::CreateChannelLoadContext(PBrowserParent* aBrowser,
{
uint32_t appId = NECKO_UNKNOWN_APP_ID;
bool inBrowser = false;
nsIDOMElement* topFrameElement = nullptr;
dom::Element* topFrameElement = nullptr;
const char* error = GetValidatedAppInfo(aSerialized, aBrowser, &appId, &inBrowser);
if (error) {
return error;