Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / base / BindContext.cpp
bloba4088ff1744188cc8ad884c3a3e3cb52a854b89a
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"
13 #include "nsError.h"
14 #include "nsPIDOMWindow.h"
16 namespace mozilla::dom {
18 bool BindContext::AllowsAutoFocus() const {
19 if (!StaticPrefs::browser_autofocus()) {
20 return false;
22 if (!InUncomposedDoc()) {
23 return false;
25 if (mDoc.IsBeingUsedAsImage()) {
26 return false;
28 return IsSameOriginAsTop();
31 bool BindContext::IsSameOriginAsTop() const {
32 BrowsingContext* browsingContext = mDoc.GetBrowsingContext();
33 if (!browsingContext) {
34 return false;
37 nsPIDOMWindowOuter* topWindow = browsingContext->Top()->GetDOMWindow();
38 if (!topWindow) {
39 // If we don't have a DOMWindow, We are not in same origin.
40 return false;
43 Document* topLevelDocument = topWindow->GetExtantDoc();
44 if (!topLevelDocument) {
45 return false;
48 return NS_SUCCEEDED(nsContentUtils::CheckSameOrigin(topLevelDocument, &mDoc));
51 } // namespace mozilla::dom