зеркало из https://github.com/mozilla/gecko-dev.git
Bug 842495 - Cleanup contentDocument/contentWindow getters; r=mounir
This commit is contained in:
Родитель
dd3dacfa62
Коммит
b6caaefa66
|
@ -116,33 +116,6 @@ HTMLFrameElement::GetAttributeMappingFunction() const
|
||||||
return &MapAttributesIntoRule;
|
return &MapAttributesIntoRule;
|
||||||
}
|
}
|
||||||
|
|
||||||
already_AddRefed<nsIDocument>
|
|
||||||
HTMLFrameElement::GetContentDocument(ErrorResult& aRv)
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsIDOMDocument> doc;
|
|
||||||
nsresult rv = nsGenericHTMLFrameElement::GetContentDocument(getter_AddRefs(doc));
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
aRv.Throw(rv);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
nsCOMPtr<nsIDocument> ret = do_QueryInterface(doc);
|
|
||||||
return ret.forget();
|
|
||||||
}
|
|
||||||
|
|
||||||
already_AddRefed<nsIDOMWindow>
|
|
||||||
HTMLFrameElement::GetContentWindow(ErrorResult& aRv)
|
|
||||||
{
|
|
||||||
nsCOMPtr<nsIDOMWindow> win;
|
|
||||||
nsresult rv = nsGenericHTMLFrameElement::GetContentWindow(getter_AddRefs(win));
|
|
||||||
if (NS_FAILED(rv)) {
|
|
||||||
aRv.Throw(rv);
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
return win.forget();
|
|
||||||
}
|
|
||||||
|
|
||||||
JSObject*
|
JSObject*
|
||||||
HTMLFrameElement::WrapNode(JSContext* aCx, JSObject* aScope,
|
HTMLFrameElement::WrapNode(JSContext* aCx, JSObject* aScope,
|
||||||
bool* aTriedToWrap)
|
bool* aTriedToWrap)
|
||||||
|
|
|
@ -102,9 +102,8 @@ public:
|
||||||
SetAttrHelper(nsGkAtoms::src, aSrc);
|
SetAttrHelper(nsGkAtoms::src, aSrc);
|
||||||
}
|
}
|
||||||
|
|
||||||
already_AddRefed<nsIDocument> GetContentDocument(ErrorResult& aRv);
|
using nsGenericHTMLFrameElement::GetContentDocument;
|
||||||
|
using nsGenericHTMLFrameElement::GetContentWindow;
|
||||||
already_AddRefed<nsIDOMWindow> GetContentWindow(ErrorResult& aRv);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual JSObject* WrapNode(JSContext* aCx, JSObject* aScope,
|
virtual JSObject* WrapNode(JSContext* aCx, JSObject* aScope,
|
||||||
|
|
|
@ -51,69 +51,71 @@ nsresult
|
||||||
nsGenericHTMLFrameElement::GetContentDocument(nsIDOMDocument** aContentDocument)
|
nsGenericHTMLFrameElement::GetContentDocument(nsIDOMDocument** aContentDocument)
|
||||||
{
|
{
|
||||||
NS_PRECONDITION(aContentDocument, "Null out param");
|
NS_PRECONDITION(aContentDocument, "Null out param");
|
||||||
*aContentDocument = nullptr;
|
nsIDocument* document = GetContentDocument();
|
||||||
|
nsIDOMDocument* domDocument =
|
||||||
|
static_cast<nsIDOMDocument*>(document->AsDOMNode());
|
||||||
|
NS_ADDREF(*aContentDocument = domDocument);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIDOMWindow> win;
|
nsIDocument*
|
||||||
GetContentWindow(getter_AddRefs(win));
|
nsGenericHTMLFrameElement::GetContentDocument()
|
||||||
|
{
|
||||||
if (!win) {
|
nsCOMPtr<nsPIDOMWindow> win = GetContentWindow();
|
||||||
return NS_OK;
|
return win ? win->GetDoc() : nullptr;
|
||||||
}
|
|
||||||
|
|
||||||
return win->GetDocument(aContentDocument);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
nsGenericHTMLFrameElement::GetContentWindow(nsIDOMWindow** aContentWindow)
|
nsGenericHTMLFrameElement::GetContentWindow(nsIDOMWindow** aContentWindow)
|
||||||
{
|
{
|
||||||
NS_PRECONDITION(aContentWindow, "Null out param");
|
NS_PRECONDITION(aContentWindow, "Null out param");
|
||||||
*aContentWindow = nullptr;
|
nsCOMPtr<nsPIDOMWindow> window = GetContentWindow();
|
||||||
|
window.forget(aContentWindow);
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
nsresult rv = EnsureFrameLoader();
|
already_AddRefed<nsPIDOMWindow>
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
nsGenericHTMLFrameElement::GetContentWindow()
|
||||||
|
{
|
||||||
|
EnsureFrameLoader();
|
||||||
|
|
||||||
if (!mFrameLoader) {
|
if (!mFrameLoader) {
|
||||||
return NS_OK;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool depthTooGreat = false;
|
bool depthTooGreat = false;
|
||||||
mFrameLoader->GetDepthTooGreat(&depthTooGreat);
|
mFrameLoader->GetDepthTooGreat(&depthTooGreat);
|
||||||
if (depthTooGreat) {
|
if (depthTooGreat) {
|
||||||
// Claim to have no contentWindow
|
// Claim to have no contentWindow
|
||||||
return NS_OK;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
nsCOMPtr<nsIDocShell> doc_shell;
|
nsCOMPtr<nsIDocShell> doc_shell;
|
||||||
mFrameLoader->GetDocShell(getter_AddRefs(doc_shell));
|
mFrameLoader->GetDocShell(getter_AddRefs(doc_shell));
|
||||||
|
|
||||||
nsCOMPtr<nsPIDOMWindow> win(do_GetInterface(doc_shell));
|
nsCOMPtr<nsPIDOMWindow> win = do_GetInterface(doc_shell);
|
||||||
|
|
||||||
if (!win) {
|
if (!win) {
|
||||||
return NS_OK;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_ASSERTION(win->IsOuterWindow(),
|
NS_ASSERTION(win->IsOuterWindow(),
|
||||||
"Uh, this window should always be an outer window!");
|
"Uh, this window should always be an outer window!");
|
||||||
|
|
||||||
return CallQueryInterface(win, aContentWindow);
|
return win.forget();
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
void
|
||||||
nsGenericHTMLFrameElement::EnsureFrameLoader()
|
nsGenericHTMLFrameElement::EnsureFrameLoader()
|
||||||
{
|
{
|
||||||
if (!GetParent() || !IsInDoc() || mFrameLoader || mFrameLoaderCreationDisallowed) {
|
if (!GetParent() || !IsInDoc() || mFrameLoader || mFrameLoaderCreationDisallowed) {
|
||||||
// If frame loader is there, we just keep it around, cached
|
// If frame loader is there, we just keep it around, cached
|
||||||
return NS_OK;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Strangely enough, this method doesn't actually ensure that the
|
||||||
|
// frameloader exists. It's more of a best-effort kind of thing.
|
||||||
mFrameLoader = nsFrameLoader::Create(this, mNetworkCreated);
|
mFrameLoader = nsFrameLoader::Create(this, mNetworkCreated);
|
||||||
if (!mFrameLoader) {
|
|
||||||
// Strangely enough, this method doesn't actually ensure that the
|
|
||||||
// frameloader exists. It's more of a best-effort kind of thing.
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NS_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
|
@ -150,14 +152,13 @@ nsGenericHTMLFrameElement::SwapFrameLoaders(nsIFrameLoaderOwner* aOtherOwner)
|
||||||
nsresult
|
nsresult
|
||||||
nsGenericHTMLFrameElement::LoadSrc()
|
nsGenericHTMLFrameElement::LoadSrc()
|
||||||
{
|
{
|
||||||
nsresult rv = EnsureFrameLoader();
|
EnsureFrameLoader();
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
|
|
||||||
if (!mFrameLoader) {
|
if (!mFrameLoader) {
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
rv = mFrameLoader->LoadFrame();
|
nsresult rv = mFrameLoader->LoadFrame();
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
NS_WARNING("failed to load URL");
|
NS_WARNING("failed to load URL");
|
||||||
|
|
|
@ -90,9 +90,11 @@ protected:
|
||||||
|
|
||||||
// This doesn't really ensure a frame loade in all cases, only when
|
// This doesn't really ensure a frame loade in all cases, only when
|
||||||
// it makes sense.
|
// it makes sense.
|
||||||
nsresult EnsureFrameLoader();
|
void EnsureFrameLoader();
|
||||||
nsresult LoadSrc();
|
nsresult LoadSrc();
|
||||||
|
nsIDocument* GetContentDocument();
|
||||||
nsresult GetContentDocument(nsIDOMDocument** aContentDocument);
|
nsresult GetContentDocument(nsIDOMDocument** aContentDocument);
|
||||||
|
already_AddRefed<nsPIDOMWindow> GetContentWindow();
|
||||||
nsresult GetContentWindow(nsIDOMWindow** aContentWindow);
|
nsresult GetContentWindow(nsIDOMWindow** aContentWindow);
|
||||||
|
|
||||||
nsRefPtr<nsFrameLoader> mFrameLoader;
|
nsRefPtr<nsFrameLoader> mFrameLoader;
|
||||||
|
|
|
@ -24,9 +24,7 @@ interface HTMLFrameElement : HTMLElement {
|
||||||
attribute DOMString longDesc;
|
attribute DOMString longDesc;
|
||||||
[SetterThrows]
|
[SetterThrows]
|
||||||
attribute boolean noResize;
|
attribute boolean noResize;
|
||||||
[GetterThrows]
|
|
||||||
readonly attribute Document? contentDocument;
|
readonly attribute Document? contentDocument;
|
||||||
[GetterThrows]
|
|
||||||
readonly attribute WindowProxy? contentWindow;
|
readonly attribute WindowProxy? contentWindow;
|
||||||
|
|
||||||
[TreatNullAs=EmptyString, SetterThrows] attribute DOMString marginHeight;
|
[TreatNullAs=EmptyString, SetterThrows] attribute DOMString marginHeight;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче