зеркало из https://github.com/mozilla/pjs.git
Make <frame> elements own their own content viewer/docshell/dom like iframes
already do. Refactors some code the two shared into a superclass. Bug 170588, r+sr=jst
This commit is contained in:
Родитель
7305fc5758
Коммит
54bc744311
|
@ -56,6 +56,8 @@
|
|||
#include "nsIDOMDocumentFragment.h"
|
||||
#include "nsIDOMNSHTMLElement.h"
|
||||
#include "nsIDOMElementCSSInlineStyle.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIEventListenerManager.h"
|
||||
#include "nsIFocusController.h"
|
||||
#include "nsMappedAttributes.h"
|
||||
|
@ -3349,6 +3351,179 @@ nsGenericHTMLFormElement::FindAndSetForm()
|
|||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
nsGenericHTMLFrameElement::nsGenericHTMLFrameElement()
|
||||
{
|
||||
}
|
||||
|
||||
nsGenericHTMLFrameElement::~nsGenericHTMLFrameElement()
|
||||
{
|
||||
if (mFrameLoader) {
|
||||
mFrameLoader->Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsGenericHTMLFrameElement)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLFrameElement)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIChromeEventHandler)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIFrameLoaderOwner)
|
||||
NS_INTERFACE_MAP_END_INHERITING(nsGenericHTMLElement)
|
||||
|
||||
nsresult
|
||||
nsGenericHTMLFrameElement::GetContentDocument(nsIDOMDocument** aContentDocument)
|
||||
{
|
||||
NS_PRECONDITION(aContentDocument, "Null out param");
|
||||
*aContentDocument = nsnull;
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> win;
|
||||
GetContentWindow(getter_AddRefs(win));
|
||||
|
||||
if (!win) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return win->GetDocument(aContentDocument);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGenericHTMLFrameElement::GetContentWindow(nsIDOMWindow** aContentWindow)
|
||||
{
|
||||
NS_PRECONDITION(aContentWindow, "Null out param");
|
||||
*aContentWindow = nsnull;
|
||||
|
||||
nsresult rv = EnsureFrameLoader();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!mFrameLoader) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocShell> doc_shell;
|
||||
mFrameLoader->GetDocShell(getter_AddRefs(doc_shell));
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> win(do_GetInterface(doc_shell));
|
||||
win.swap(*aContentWindow);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGenericHTMLFrameElement::EnsureFrameLoader()
|
||||
{
|
||||
if (!GetParent() || !mDocument || mFrameLoader) {
|
||||
// If frame loader is there, we just keep it around, cached
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult rv = NS_NewFrameLoader(getter_AddRefs(mFrameLoader));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = mFrameLoader->Init(this);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGenericHTMLFrameElement::GetFrameLoader(nsIFrameLoader **aFrameLoader)
|
||||
{
|
||||
NS_IF_ADDREF(*aFrameLoader = mFrameLoader);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGenericHTMLFrameElement::SetFrameLoader(nsIFrameLoader *aFrameLoader)
|
||||
{
|
||||
mFrameLoader = aFrameLoader;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGenericHTMLFrameElement::LoadSrc()
|
||||
{
|
||||
nsresult rv = EnsureFrameLoader();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!mFrameLoader) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
rv = mFrameLoader->LoadFrame();
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to load URL");
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
void
|
||||
nsGenericHTMLFrameElement::SetParent(nsIContent *aParent)
|
||||
{
|
||||
nsGenericHTMLElement::SetParent(aParent);
|
||||
|
||||
// When parent is being set to null on the element's destruction, do not
|
||||
// call LoadSrc().
|
||||
if (!GetParent() || !mDocument) {
|
||||
return;
|
||||
}
|
||||
|
||||
LoadSrc();
|
||||
}
|
||||
|
||||
void
|
||||
nsGenericHTMLFrameElement::SetDocument(nsIDocument *aDocument, PRBool aDeep,
|
||||
PRBool aCompileEventHandlers)
|
||||
{
|
||||
const nsIDocument *old_doc = mDocument;
|
||||
|
||||
nsGenericHTMLElement::SetDocument(aDocument, aDeep,
|
||||
aCompileEventHandlers);
|
||||
|
||||
if (!aDocument && mFrameLoader) {
|
||||
// This iframe is being taken out of the document, destroy the
|
||||
// iframe's frame loader (doing that will tear down the window in
|
||||
// this iframe).
|
||||
|
||||
mFrameLoader->Destroy();
|
||||
|
||||
mFrameLoader = nsnull;
|
||||
}
|
||||
|
||||
// When document is being set to null on the element's destruction,
|
||||
// or when the document is being set to what the document already
|
||||
// is, do not call LoadSrc().
|
||||
if (GetParent() && aDocument && aDocument != old_doc) {
|
||||
LoadSrc();
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsGenericHTMLFrameElement::SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
|
||||
nsIAtom* aPrefix, const nsAString& aValue,
|
||||
PRBool aNotify)
|
||||
{
|
||||
nsresult rv = nsGenericHTMLElement::SetAttr(aNameSpaceID, aName, aPrefix,
|
||||
aValue, aNotify);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && aNameSpaceID == kNameSpaceID_None &&
|
||||
aName == nsHTMLAtoms::src) {
|
||||
return LoadSrc();
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsGenericHTMLFrameElement::HandleChromeEvent(nsIPresContext* aPresContext,
|
||||
nsEvent* aEvent,
|
||||
nsIDOMEvent** aDOMEvent,
|
||||
PRUint32 aFlags,
|
||||
nsEventStatus* aEventStatus)
|
||||
{
|
||||
return HandleDOMEvent(aPresContext, aEvent, aDOMEvent, aFlags,aEventStatus);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
void
|
||||
nsGenericHTMLElement::SetElementFocus(PRBool aDoFocus)
|
||||
{
|
||||
|
|
|
@ -47,6 +47,9 @@
|
|||
#include "nsVoidArray.h"
|
||||
#include "nsINameSpaceManager.h" // for kNameSpaceID_None
|
||||
#include "nsIFormControl.h"
|
||||
#include "nsIDOMNSHTMLFrameElement.h"
|
||||
#include "nsIChromeEventHandler.h"
|
||||
#include "nsIFrameLoader.h"
|
||||
|
||||
#include "nsIStatefulFrame.h"
|
||||
|
||||
|
@ -878,6 +881,56 @@ protected:
|
|||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* A helper class for frame elements
|
||||
*/
|
||||
|
||||
class nsGenericHTMLFrameElement : public nsGenericHTMLElement,
|
||||
public nsIDOMNSHTMLFrameElement,
|
||||
public nsIChromeEventHandler,
|
||||
public nsIFrameLoaderOwner
|
||||
{
|
||||
public:
|
||||
nsGenericHTMLFrameElement();
|
||||
virtual ~nsGenericHTMLFrameElement();
|
||||
|
||||
NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
|
||||
|
||||
// nsIDOMNSHTMLFrameElement
|
||||
NS_DECL_NSIDOMNSHTMLFRAMEELEMENT
|
||||
|
||||
// nsIChromeEventHandler
|
||||
NS_DECL_NSICHROMEEVENTHANDLER
|
||||
|
||||
// nsIFrameLoaderOwner
|
||||
NS_IMETHOD GetFrameLoader(nsIFrameLoader **aFrameLoader);
|
||||
NS_IMETHOD SetFrameLoader(nsIFrameLoader *aFrameLoader);
|
||||
|
||||
// nsIContent
|
||||
virtual void SetParent(nsIContent *aParent);
|
||||
virtual void SetDocument(nsIDocument *aDocument, PRBool aDeep,
|
||||
PRBool aCompileEventHandlers);
|
||||
nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
|
||||
const nsAString& aValue, PRBool aNotify)
|
||||
{
|
||||
return SetAttr(aNameSpaceID, aName, nsnull, aValue, aNotify);
|
||||
}
|
||||
virtual nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
|
||||
nsIAtom* aPrefix, const nsAString& aValue,
|
||||
PRBool aNotify);
|
||||
|
||||
protected:
|
||||
// This doesn't really ensure a frame loade in all cases, only when
|
||||
// it makes sense.
|
||||
nsresult EnsureFrameLoader();
|
||||
nsresult LoadSrc();
|
||||
nsresult GetContentDocument(nsIDOMDocument** aContentDocument);
|
||||
|
||||
nsCOMPtr<nsIFrameLoader> mFrameLoader;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* A macro to implement the getter and setter for a given string
|
||||
* valued content property. The method uses the generic GetAttr and
|
||||
|
|
|
@ -36,26 +36,17 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#include "nsIDOMHTMLFrameElement.h"
|
||||
#include "nsIDOMNSHTMLFrameElement.h"
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIHTMLContent.h"
|
||||
#include "nsGenericHTMLElement.h"
|
||||
#include "nsHTMLAtoms.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIWebNavigation.h"
|
||||
#include "nsIChromeEventHandler.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsDOMError.h"
|
||||
|
||||
|
||||
class nsHTMLFrameElement : public nsGenericHTMLElement,
|
||||
public nsIDOMHTMLFrameElement,
|
||||
public nsIDOMNSHTMLFrameElement,
|
||||
public nsIChromeEventHandler
|
||||
class nsHTMLFrameElement : public nsGenericHTMLFrameElement,
|
||||
public nsIDOMHTMLFrameElement
|
||||
{
|
||||
public:
|
||||
nsHTMLFrameElement();
|
||||
|
@ -65,29 +56,25 @@ public:
|
|||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// nsIDOMNode
|
||||
NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLElement::)
|
||||
NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLFrameElement::)
|
||||
|
||||
// nsIDOMElement
|
||||
NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
|
||||
NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLFrameElement::)
|
||||
|
||||
// nsIDOMHTMLElement
|
||||
NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
|
||||
NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLFrameElement::)
|
||||
|
||||
// nsIDOMHTMLFrameElement
|
||||
NS_DECL_NSIDOMHTMLFRAMEELEMENT
|
||||
|
||||
// nsIDOMNSHTMLFrameElement
|
||||
NS_DECL_NSIDOMNSHTMLFRAMEELEMENT
|
||||
|
||||
// nsIChromeEventHandler
|
||||
NS_DECL_NSICHROMEEVENTHANDLER
|
||||
|
||||
// nsIContent
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
|
||||
NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
|
||||
NS_IMETHOD GetAttributeMappingFunction(nsMapRuleToAttributesFunc& aMapRuleFunc) const;
|
||||
};
|
||||
|
@ -133,10 +120,8 @@ NS_IMPL_RELEASE_INHERITED(nsHTMLFrameElement, nsGenericElement)
|
|||
|
||||
|
||||
// QueryInterface implementation for nsHTMLFrameElement
|
||||
NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLFrameElement, nsGenericHTMLElement)
|
||||
NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLFrameElement, nsGenericHTMLFrameElement)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLFrameElement)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLFrameElement)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIChromeEventHandler)
|
||||
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLFrameElement)
|
||||
NS_HTML_CONTENT_INTERFACE_MAP_END
|
||||
|
||||
|
@ -183,45 +168,7 @@ NS_IMPL_URI_ATTR(nsHTMLFrameElement, Src, src)
|
|||
NS_IMETHODIMP
|
||||
nsHTMLFrameElement::GetContentDocument(nsIDOMDocument** aContentDocument)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aContentDocument);
|
||||
*aContentDocument = nsnull;
|
||||
|
||||
if (!mDocument) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIDocument* content_document = mDocument->GetSubDocumentFor(this);
|
||||
|
||||
if (!content_document) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return CallQueryInterface(content_document, aContentDocument);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLFrameElement::GetContentWindow(nsIDOMWindow** aContentWindow)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aContentWindow);
|
||||
*aContentWindow = nsnull;
|
||||
|
||||
nsCOMPtr<nsIDOMDocument> content_doc;
|
||||
|
||||
nsresult rv = GetContentDocument(getter_AddRefs(content_doc));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIDocument> doc(do_QueryInterface(content_doc));
|
||||
|
||||
if (!doc) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> window (do_QueryInterface(doc->GetScriptGlobalObject()));
|
||||
|
||||
*aContentWindow = window;
|
||||
NS_IF_ADDREF(*aContentWindow);
|
||||
|
||||
return NS_OK;
|
||||
return nsGenericHTMLFrameElement::GetContentDocument(aContentDocument);
|
||||
}
|
||||
|
||||
PRBool
|
||||
|
@ -230,7 +177,7 @@ nsHTMLFrameElement::ParseAttribute(nsIAtom* aAttribute,
|
|||
nsAttrValue& aResult)
|
||||
{
|
||||
if (aAttribute == nsHTMLAtoms::bordercolor) {
|
||||
return aResult.ParseColor(aValue, nsGenericHTMLElement::GetOwnerDocument());
|
||||
return aResult.ParseColor(aValue, nsGenericHTMLFrameElement::GetOwnerDocument());
|
||||
}
|
||||
if (aAttribute == nsHTMLAtoms::frameborder) {
|
||||
return ParseFrameborderValue(aValue, aResult);
|
||||
|
@ -245,7 +192,7 @@ nsHTMLFrameElement::ParseAttribute(nsIAtom* aAttribute,
|
|||
return ParseScrollingValue(aValue, aResult);
|
||||
}
|
||||
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
return nsGenericHTMLFrameElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -262,7 +209,8 @@ nsHTMLFrameElement::AttributeToString(nsIAtom* aAttribute,
|
|||
return NS_CONTENT_ATTR_HAS_VALUE;
|
||||
}
|
||||
|
||||
return nsGenericHTMLElement::AttributeToString(aAttribute, aValue, aResult);
|
||||
return nsGenericHTMLFrameElement::AttributeToString(aAttribute, aValue,
|
||||
aResult);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -290,19 +238,3 @@ nsHTMLFrameElement::GetAttributeMappingFunction(nsMapRuleToAttributesFunc& aMapR
|
|||
aMapRuleFunc = &MapAttributesIntoRule;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//*****************************************************************************
|
||||
// nsHTMLFrameElement::nsIChromeEventHandler
|
||||
//*****************************************************************************
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLFrameElement::HandleChromeEvent(nsIPresContext* aPresContext,
|
||||
nsEvent* aEvent,
|
||||
nsIDOMEvent** aDOMEvent,
|
||||
PRUint32 aFlags,
|
||||
nsEventStatus* aEventStatus)
|
||||
{
|
||||
return HandleDOMEvent(aPresContext, aEvent, aDOMEvent, aFlags,aEventStatus);
|
||||
}
|
||||
|
||||
|
|
|
@ -36,30 +36,18 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
#include "nsIDOMHTMLIFrameElement.h"
|
||||
#include "nsIDOMNSHTMLFrameElement.h"
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIFrameLoader.h"
|
||||
#include "nsIHTMLContent.h"
|
||||
#include "nsGenericHTMLElement.h"
|
||||
#include "nsHTMLAtoms.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsIPresShell.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDOMDocument.h"
|
||||
#include "nsIWebNavigation.h"
|
||||
#include "nsMappedAttributes.h"
|
||||
#include "nsIChromeEventHandler.h"
|
||||
#include "nsDOMError.h"
|
||||
#include "nsRuleNode.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIInterfaceRequestorUtils.h"
|
||||
|
||||
class nsHTMLIFrameElement : public nsGenericHTMLElement,
|
||||
public nsIDOMHTMLIFrameElement,
|
||||
public nsIDOMNSHTMLFrameElement,
|
||||
public nsIChromeEventHandler,
|
||||
public nsIFrameLoaderOwner
|
||||
class nsHTMLIFrameElement : public nsGenericHTMLFrameElement,
|
||||
public nsIDOMHTMLIFrameElement
|
||||
{
|
||||
public:
|
||||
nsHTMLIFrameElement();
|
||||
|
@ -69,68 +57,27 @@ public:
|
|||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// nsIDOMNode
|
||||
NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLElement::)
|
||||
NS_FORWARD_NSIDOMNODE_NO_CLONENODE(nsGenericHTMLFrameElement::)
|
||||
|
||||
// nsIDOMElement
|
||||
NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
|
||||
NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLFrameElement::)
|
||||
|
||||
// nsIDOMHTMLElement
|
||||
NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
|
||||
NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLFrameElement::)
|
||||
|
||||
// nsIDOMHTMLIFrameElement
|
||||
NS_DECL_NSIDOMHTMLIFRAMEELEMENT
|
||||
|
||||
// nsIDOMNSHTMLFrameElement
|
||||
NS_DECL_NSIDOMNSHTMLFRAMEELEMENT
|
||||
|
||||
// nsIChromeEventHandler
|
||||
NS_DECL_NSICHROMEEVENTHANDLER
|
||||
|
||||
// nsIFrameLoaderOwner
|
||||
NS_IMETHOD GetFrameLoader(nsIFrameLoader **aFrameLoader);
|
||||
NS_IMETHOD SetFrameLoader(nsIFrameLoader *aFrameLoader);
|
||||
|
||||
// nsIContent
|
||||
virtual void SetParent(nsIContent *aParent);
|
||||
virtual void SetDocument(nsIDocument *aDocument, PRBool aDeep,
|
||||
PRBool aCompileEventHandlers);
|
||||
|
||||
virtual PRBool ParseAttribute(nsIAtom* aAttribute,
|
||||
const nsAString& aValue,
|
||||
nsAttrValue& aResult);
|
||||
NS_IMETHOD AttributeToString(nsIAtom* aAttribute,
|
||||
const nsHTMLValue& aValue,
|
||||
nsAString& aResult) const;
|
||||
nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
|
||||
const nsAString& aValue, PRBool aNotify)
|
||||
{
|
||||
return SetAttr(aNameSpaceID, aName, nsnull, aValue, aNotify);
|
||||
}
|
||||
virtual nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
|
||||
nsIAtom* aPrefix, const nsAString& aValue,
|
||||
PRBool aNotify)
|
||||
{
|
||||
nsresult rv = nsGenericHTMLElement::SetAttr(aNameSpaceID, aName, aPrefix,
|
||||
aValue, aNotify);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && aNameSpaceID == kNameSpaceID_None &&
|
||||
aName == nsHTMLAtoms::src) {
|
||||
return LoadSrc();
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
|
||||
NS_IMETHOD GetAttributeMappingFunction(nsMapRuleToAttributesFunc& aMapRuleFunc) const;
|
||||
|
||||
protected:
|
||||
// This doesn't really ensure a frame loade in all cases, only when
|
||||
// it makes sense.
|
||||
nsresult EnsureFrameLoader();
|
||||
nsresult LoadSrc();
|
||||
|
||||
nsCOMPtr<nsIFrameLoader> mFrameLoader;
|
||||
};
|
||||
|
||||
nsresult
|
||||
|
@ -166,9 +113,6 @@ nsHTMLIFrameElement::nsHTMLIFrameElement()
|
|||
|
||||
nsHTMLIFrameElement::~nsHTMLIFrameElement()
|
||||
{
|
||||
if (mFrameLoader) {
|
||||
mFrameLoader->Destroy();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -176,11 +120,8 @@ NS_IMPL_ADDREF(nsHTMLIFrameElement)
|
|||
NS_IMPL_RELEASE(nsHTMLIFrameElement)
|
||||
|
||||
// QueryInterface implementation for nsHTMLIFrameElement
|
||||
NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLIFrameElement, nsGenericHTMLElement)
|
||||
NS_HTML_CONTENT_INTERFACE_MAP_BEGIN(nsHTMLIFrameElement, nsGenericHTMLFrameElement)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLIFrameElement)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLFrameElement)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIChromeEventHandler)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIFrameLoaderOwner)
|
||||
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLIFrameElement)
|
||||
NS_HTML_CONTENT_INTERFACE_MAP_END
|
||||
|
||||
|
@ -227,139 +168,7 @@ NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Width, width)
|
|||
NS_IMETHODIMP
|
||||
nsHTMLIFrameElement::GetContentDocument(nsIDOMDocument** aContentDocument)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aContentDocument);
|
||||
*aContentDocument = nsnull;
|
||||
|
||||
nsresult rv = EnsureFrameLoader();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!mFrameLoader) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocShell> doc_shell;
|
||||
mFrameLoader->GetDocShell(getter_AddRefs(doc_shell));
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> win(do_GetInterface(doc_shell));
|
||||
|
||||
if (!win) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return win->GetDocument(aContentDocument);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLIFrameElement::GetContentWindow(nsIDOMWindow** aContentWindow)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aContentWindow);
|
||||
|
||||
nsresult rv = EnsureFrameLoader();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!mFrameLoader) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocShell> doc_shell;
|
||||
mFrameLoader->GetDocShell(getter_AddRefs(doc_shell));
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> win(do_GetInterface(doc_shell));
|
||||
|
||||
*aContentWindow = win;
|
||||
NS_IF_ADDREF(*aContentWindow);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsHTMLIFrameElement::EnsureFrameLoader()
|
||||
{
|
||||
if (!GetParent() || !mDocument || mFrameLoader) {
|
||||
// If frame loader is there, we just keep it around, cached
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult rv = NS_NewFrameLoader(getter_AddRefs(mFrameLoader));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = mFrameLoader->Init(this);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLIFrameElement::GetFrameLoader(nsIFrameLoader **aFrameLoader)
|
||||
{
|
||||
*aFrameLoader = mFrameLoader;
|
||||
NS_IF_ADDREF(*aFrameLoader);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLIFrameElement::SetFrameLoader(nsIFrameLoader *aFrameLoader)
|
||||
{
|
||||
mFrameLoader = aFrameLoader;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsHTMLIFrameElement::LoadSrc()
|
||||
{
|
||||
nsresult rv = EnsureFrameLoader();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!mFrameLoader) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
rv = mFrameLoader->LoadFrame();
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "failed to load URL");
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsHTMLIFrameElement::SetParent(nsIContent *aParent)
|
||||
{
|
||||
nsGenericHTMLElement::SetParent(aParent);
|
||||
|
||||
// When parent is being set to null on the element's destruction, do not
|
||||
// call LoadSrc().
|
||||
if (!GetParent() || !mDocument) {
|
||||
return;
|
||||
}
|
||||
|
||||
LoadSrc();
|
||||
}
|
||||
|
||||
void
|
||||
nsHTMLIFrameElement::SetDocument(nsIDocument *aDocument, PRBool aDeep,
|
||||
PRBool aCompileEventHandlers)
|
||||
{
|
||||
const nsIDocument *old_doc = mDocument;
|
||||
|
||||
nsGenericHTMLElement::SetDocument(aDocument, aDeep,
|
||||
aCompileEventHandlers);
|
||||
|
||||
if (!aDocument && mFrameLoader) {
|
||||
// This iframe is being taken out of the document, destroy the
|
||||
// iframe's frame loader (doing that will tear down the window in
|
||||
// this iframe).
|
||||
|
||||
mFrameLoader->Destroy();
|
||||
|
||||
mFrameLoader = nsnull;
|
||||
}
|
||||
|
||||
// When document is being set to null on the element's destruction,
|
||||
// or when the document is being set to what the document already
|
||||
// is, do not call LoadSrc().
|
||||
if (GetParent() && aDocument && aDocument != old_doc) {
|
||||
LoadSrc();
|
||||
}
|
||||
return nsGenericHTMLFrameElement::GetContentDocument(aContentDocument);
|
||||
}
|
||||
|
||||
PRBool
|
||||
|
@ -389,7 +198,7 @@ nsHTMLIFrameElement::ParseAttribute(nsIAtom* aAttribute,
|
|||
return ParseAlignValue(aValue, aResult);
|
||||
}
|
||||
|
||||
return nsGenericHTMLElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
return nsGenericHTMLFrameElement::ParseAttribute(aAttribute, aValue, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -412,7 +221,8 @@ nsHTMLIFrameElement::AttributeToString(nsIAtom* aAttribute,
|
|||
}
|
||||
}
|
||||
|
||||
return nsGenericHTMLElement::AttributeToString(aAttribute, aValue, aResult);
|
||||
return nsGenericHTMLFrameElement::AttributeToString(aAttribute, aValue,
|
||||
aResult);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -496,18 +306,3 @@ nsHTMLIFrameElement::GetAttributeMappingFunction(nsMapRuleToAttributesFunc& aMap
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//*****************************************************************************
|
||||
// nsHTMLIFrameElement::nsIChromeEventHandler
|
||||
//*****************************************************************************
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLIFrameElement::HandleChromeEvent(nsIPresContext* aPresContext,
|
||||
nsEvent* aEvent,
|
||||
nsIDOMEvent** aDOMEvent,
|
||||
PRUint32 aFlags,
|
||||
nsEventStatus* aEventStatus)
|
||||
{
|
||||
return HandleDOMEvent(aPresContext, aEvent, aDOMEvent, aFlags,aEventStatus);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче