2018-07-06 03:14:18 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsFrameLoader.h"
|
2018-07-06 03:14:29 +03:00
|
|
|
#include "mozilla/AsyncEventDispatcher.h"
|
|
|
|
#include "mozilla/dom/HTMLIFrameElement.h"
|
2019-01-03 10:11:00 +03:00
|
|
|
#include "mozilla/dom/WindowProxyHolder.h"
|
2018-07-06 03:14:18 +03:00
|
|
|
#include "mozilla/dom/XULFrameElement.h"
|
|
|
|
#include "mozilla/dom/XULFrameElementBinding.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2018-07-06 03:14:29 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(XULFrameElement)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(XULFrameElement, nsXULElement)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mFrameLoader);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOpener);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(XULFrameElement, nsXULElement)
|
|
|
|
if (tmp->mFrameLoader) {
|
|
|
|
tmp->mFrameLoader->Destroy();
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mFrameLoader, mOpener)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(XULFrameElement, nsXULElement,
|
2019-02-16 01:20:53 +03:00
|
|
|
nsFrameLoaderOwner)
|
2018-07-06 03:14:29 +03:00
|
|
|
|
2018-07-06 03:14:18 +03:00
|
|
|
JSObject* XULFrameElement::WrapNode(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
|
|
|
return XULFrameElement_Binding::Wrap(aCx, this, aGivenProto);
|
|
|
|
}
|
|
|
|
|
2019-01-02 16:27:05 +03:00
|
|
|
nsDocShell* XULFrameElement::GetDocShell() {
|
2018-07-06 03:14:18 +03:00
|
|
|
RefPtr<nsFrameLoader> frameLoader = GetFrameLoader();
|
|
|
|
return frameLoader ? frameLoader->GetDocShell(IgnoreErrors()) : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsIWebNavigation> XULFrameElement::GetWebNavigation() {
|
|
|
|
nsCOMPtr<nsIDocShell> docShell = GetDocShell();
|
|
|
|
nsCOMPtr<nsIWebNavigation> webnav = do_QueryInterface(docShell);
|
|
|
|
return webnav.forget();
|
|
|
|
}
|
|
|
|
|
2019-01-02 16:26:56 +03:00
|
|
|
Nullable<WindowProxyHolder> XULFrameElement::GetContentWindow() {
|
2019-01-02 16:27:05 +03:00
|
|
|
RefPtr<nsDocShell> docShell = GetDocShell();
|
2018-07-06 03:14:18 +03:00
|
|
|
if (docShell) {
|
2019-01-02 16:27:05 +03:00
|
|
|
return WindowProxyHolder(docShell->GetWindowProxy());
|
2018-07-06 03:14:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
Document* XULFrameElement::GetContentDocument() {
|
2019-01-02 16:26:56 +03:00
|
|
|
nsCOMPtr<nsIDocShell> docShell = GetDocShell();
|
|
|
|
if (docShell) {
|
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> win = docShell->GetWindow();
|
|
|
|
if (win) {
|
|
|
|
return win->GetDoc();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
2018-07-06 03:14:18 +03:00
|
|
|
}
|
|
|
|
|
2018-07-06 03:14:29 +03:00
|
|
|
void XULFrameElement::LoadSrc() {
|
2018-03-29 04:20:04 +03:00
|
|
|
if (!IsInUncomposedDoc() || !OwnerDoc()->GetRootElement()) {
|
2018-07-06 03:14:29 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
RefPtr<nsFrameLoader> frameLoader = GetFrameLoader();
|
|
|
|
if (!frameLoader) {
|
|
|
|
// Check if we have an opener we need to be setting
|
2019-01-02 16:27:05 +03:00
|
|
|
RefPtr<BrowsingContext> opener = mOpener;
|
2018-07-06 03:14:29 +03:00
|
|
|
if (!opener) {
|
|
|
|
// If we are a primary xul-browser, we want to take the opener property!
|
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> window = OwnerDoc()->GetWindow();
|
|
|
|
if (AttrValueIs(kNameSpaceID_None, nsGkAtoms::primary, nsGkAtoms::_true,
|
|
|
|
eIgnoreCase) &&
|
|
|
|
window) {
|
|
|
|
opener = window->TakeOpenerForInitialContentBrowser();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mOpener = nullptr;
|
|
|
|
|
|
|
|
// false as the last parameter so that xul:iframe/browser/editor
|
|
|
|
// session history handling works like dynamic html:iframes.
|
|
|
|
// Usually xul elements are used in chrome, which doesn't have
|
|
|
|
// session history at all.
|
2019-04-15 18:14:54 +03:00
|
|
|
mFrameLoader = nsFrameLoader::Create(this, opener, false);
|
2018-07-06 03:14:29 +03:00
|
|
|
if (NS_WARN_IF(!mFrameLoader)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
(new AsyncEventDispatcher(this, NS_LITERAL_STRING("XULFrameLoaderCreated"),
|
|
|
|
CanBubble::eYes))
|
|
|
|
->RunDOMEventWhenSafe();
|
|
|
|
}
|
|
|
|
|
|
|
|
mFrameLoader->LoadFrame(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void XULFrameElement::SwapFrameLoaders(HTMLIFrameElement& aOtherLoaderOwner,
|
|
|
|
ErrorResult& rv) {
|
|
|
|
aOtherLoaderOwner.SwapFrameLoaders(this, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void XULFrameElement::SwapFrameLoaders(XULFrameElement& aOtherLoaderOwner,
|
|
|
|
ErrorResult& rv) {
|
|
|
|
if (&aOtherLoaderOwner == this) {
|
|
|
|
// nothing to do
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aOtherLoaderOwner.SwapFrameLoaders(this, rv);
|
|
|
|
}
|
|
|
|
|
2019-02-16 01:20:53 +03:00
|
|
|
void XULFrameElement::SwapFrameLoaders(nsFrameLoaderOwner* aOtherLoaderOwner,
|
2018-07-06 03:14:29 +03:00
|
|
|
mozilla::ErrorResult& rv) {
|
2019-04-29 21:45:03 +03:00
|
|
|
if (RefPtr<Document> doc = GetComposedDoc()) {
|
|
|
|
// SwapWithOtherLoader relies on frames being up-to-date.
|
|
|
|
doc->FlushPendingNotifications(FlushType::Frames);
|
|
|
|
}
|
|
|
|
|
2018-07-06 03:14:29 +03:00
|
|
|
RefPtr<nsFrameLoader> loader = GetFrameLoader();
|
|
|
|
RefPtr<nsFrameLoader> otherLoader = aOtherLoaderOwner->GetFrameLoader();
|
|
|
|
if (!loader || !otherLoader) {
|
|
|
|
rv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = loader->SwapWithOtherLoader(otherLoader, this, aOtherLoaderOwner);
|
|
|
|
}
|
|
|
|
|
2019-01-02 16:05:23 +03:00
|
|
|
nsresult XULFrameElement::BindToTree(Document* aDocument, nsIContent* aParent,
|
2018-07-31 21:18:38 +03:00
|
|
|
nsIContent* aBindingParent) {
|
|
|
|
nsresult rv = nsXULElement::BindToTree(aDocument, aParent, aBindingParent);
|
2018-07-06 03:14:29 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (aDocument) {
|
|
|
|
NS_ASSERTION(!nsContentUtils::IsSafeToRunScript(),
|
|
|
|
"Missing a script blocker!");
|
|
|
|
// We're in a document now. Kick off the frame load.
|
|
|
|
LoadSrc();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2019-05-29 01:47:08 +03:00
|
|
|
void XULFrameElement::UnbindFromTree(bool aNullParent) {
|
2018-07-06 03:14:29 +03:00
|
|
|
RefPtr<nsFrameLoader> frameLoader = GetFrameLoader();
|
|
|
|
if (frameLoader) {
|
|
|
|
frameLoader->Destroy();
|
|
|
|
}
|
|
|
|
mFrameLoader = nullptr;
|
|
|
|
|
2019-05-29 01:47:08 +03:00
|
|
|
nsXULElement::UnbindFromTree(aNullParent);
|
2018-07-06 03:14:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void XULFrameElement::DestroyContent() {
|
|
|
|
RefPtr<nsFrameLoader> frameLoader = GetFrameLoader();
|
|
|
|
if (frameLoader) {
|
|
|
|
frameLoader->Destroy();
|
|
|
|
}
|
|
|
|
mFrameLoader = nullptr;
|
|
|
|
|
|
|
|
nsXULElement::DestroyContent();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult XULFrameElement::AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
|
|
|
|
const nsAttrValue* aValue,
|
|
|
|
const nsAttrValue* aOldValue,
|
|
|
|
nsIPrincipal* aSubjectPrincipal,
|
|
|
|
bool aNotify) {
|
|
|
|
if (aNamespaceID == kNameSpaceID_None && aName == nsGkAtoms::src && aValue) {
|
|
|
|
LoadSrc();
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsXULElement::AfterSetAttr(aNamespaceID, aName, aValue, aOldValue,
|
|
|
|
aSubjectPrincipal, aNotify);
|
|
|
|
}
|
|
|
|
|
2018-07-06 03:14:18 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|