tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

BindContext.cpp (1394B)


      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/. */
      6 
      7 #include "mozilla/dom/BindContext.h"
      8 
      9 #include "mozilla/StaticPrefs_browser.h"
     10 #include "mozilla/dom/BrowsingContext.h"
     11 #include "mozilla/dom/Document.h"
     12 #include "nsContentUtils.h"
     13 #include "nsError.h"
     14 #include "nsPIDOMWindow.h"
     15 
     16 namespace mozilla::dom {
     17 
     18 bool BindContext::AllowsAutoFocus() const {
     19  if (!StaticPrefs::browser_autofocus()) {
     20    return false;
     21  }
     22  if (!InUncomposedDoc()) {
     23    return false;
     24  }
     25  if (mDoc.IsBeingUsedAsImage()) {
     26    return false;
     27  }
     28  return IsSameOriginAsTop();
     29 }
     30 
     31 bool BindContext::IsSameOriginAsTop() const {
     32  BrowsingContext* browsingContext = mDoc.GetBrowsingContext();
     33  if (!browsingContext) {
     34    return false;
     35  }
     36 
     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;
     41  }
     42 
     43  Document* topLevelDocument = topWindow->GetExtantDoc();
     44  if (!topLevelDocument) {
     45    return false;
     46  }
     47 
     48  return NS_SUCCEEDED(nsContentUtils::CheckSameOrigin(topLevelDocument, &mDoc));
     49 }
     50 
     51 }  // namespace mozilla::dom