1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/dom/BindContext.h"
8 #include "mozilla/dom/BrowsingContext.h"
10 #include "mozilla/dom/Document.h"
11 #include "mozilla/StaticPrefs_browser.h"
12 #include "nsContentUtils.h"
14 #include "nsPIDOMWindow.h"
16 namespace mozilla::dom
{
18 bool BindContext::AllowsAutoFocus() const {
19 if (!StaticPrefs::browser_autofocus()) {
22 if (!InUncomposedDoc()) {
25 if (mDoc
.IsBeingUsedAsImage()) {
28 return IsSameOriginAsTop();
31 bool BindContext::IsSameOriginAsTop() const {
32 BrowsingContext
* browsingContext
= mDoc
.GetBrowsingContext();
33 if (!browsingContext
) {
37 nsPIDOMWindowOuter
* topWindow
= browsingContext
->Top()->GetDOMWindow();
39 // If we don't have a DOMWindow, We are not in same origin.
43 Document
* topLevelDocument
= topWindow
->GetExtantDoc();
44 if (!topLevelDocument
) {
48 return NS_SUCCEEDED(nsContentUtils::CheckSameOrigin(topLevelDocument
, &mDoc
));
51 } // namespace mozilla::dom