tor-browser

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

nsFrameLoaderOwner.h (5243B)


      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 #ifndef nsFrameLoaderOwner_h_
      8 #define nsFrameLoaderOwner_h_
      9 
     10 #include <functional>
     11 
     12 #include "nsFrameLoader.h"
     13 #include "nsISupports.h"
     14 
     15 namespace mozilla {
     16 class ErrorResult;
     17 namespace dom {
     18 class BrowsingContext;
     19 class BrowsingContextGroup;
     20 class BrowserBridgeChild;
     21 class ContentParent;
     22 class Element;
     23 struct RemotenessOptions;
     24 struct NavigationIsolationOptions;
     25 }  // namespace dom
     26 }  // namespace mozilla
     27 
     28 // IID for the FrameLoaderOwner interface
     29 #define NS_FRAMELOADEROWNER_IID \
     30  {0x1b4fd25c, 0x2e57, 0x11e9, {0x9e, 0x5a, 0x5b, 0x86, 0xe9, 0x89, 0xa5, 0xc0}}
     31 
     32 // Mixin that handles ownership of nsFrameLoader for Frame elements
     33 // (XULFrameElement, HTMLI/FrameElement, etc...). Manages information when doing
     34 // FrameLoader swaps.
     35 //
     36 // This class is considered an XPCOM mixin. This means that while we inherit
     37 // from ISupports in order to be QI'able, we expect the classes that inherit
     38 // nsFrameLoaderOwner to actually implement ISupports for us.
     39 class nsFrameLoaderOwner : public nsISupports {
     40 public:
     41  NS_INLINE_DECL_STATIC_IID(NS_FRAMELOADEROWNER_IID)
     42 
     43  nsFrameLoaderOwner() = default;
     44  already_AddRefed<nsFrameLoader> GetFrameLoader();
     45  void SetFrameLoader(nsFrameLoader* aNewFrameLoader);
     46 
     47  mozilla::dom::BrowsingContext* GetBrowsingContext();
     48  mozilla::dom::BrowsingContext* GetExtantBrowsingContext();
     49 
     50  // Destroy (if it exists) and recreate our frameloader, based on new
     51  // remoteness requirements.
     52  //
     53  // This method is called by frontend code when it wants to perform a
     54  // remoteness update, and allows for behaviour such as preserving
     55  // BrowsingContexts across process switches during navigation.
     56  //
     57  // See the WebIDL definition for more details.
     58  MOZ_CAN_RUN_SCRIPT
     59  void ChangeRemoteness(const mozilla::dom::RemotenessOptions& aOptions,
     60                        mozilla::ErrorResult& rv);
     61 
     62  // Like `ChangeRemoteness` but switches to an already-created
     63  // `BrowserBridgeChild`. This method is used when performing remote subframe
     64  // process switches.
     65  MOZ_CAN_RUN_SCRIPT
     66  void ChangeRemotenessWithBridge(mozilla::dom::BrowserBridgeChild* aBridge,
     67                                  mozilla::ErrorResult& rv);
     68 
     69  // Like `ChangeRemoteness`, but switches into an already-created
     70  // `ContentParent`. This method is used when performing toplevel process
     71  // switches. If `aContentParent` is nullptr, switches into the parent process.
     72  //
     73  // If `aReplaceBrowsingContext` is set, BrowsingContext preservation will be
     74  // disabled for this process switch.
     75  MOZ_CAN_RUN_SCRIPT
     76  void ChangeRemotenessToProcess(
     77      mozilla::dom::ContentParent* aContentParent,
     78      const mozilla::dom::NavigationIsolationOptions& aOptions,
     79      mozilla::dom::BrowsingContextGroup* aGroup, mozilla::ErrorResult& rv);
     80 
     81  MOZ_CAN_RUN_SCRIPT
     82  void SubframeCrashed();
     83 
     84  void RestoreFrameLoaderFromBFCache(nsFrameLoader* aNewFrameLoader);
     85 
     86  MOZ_CAN_RUN_SCRIPT
     87  void UpdateFocusAndMouseEnterStateAfterFrameLoaderChange();
     88 
     89  void AttachFrameLoader(nsFrameLoader* aFrameLoader);
     90  void DetachFrameLoader(nsFrameLoader* aFrameLoader);
     91  // If aDestroyBFCached is true and aFrameLoader is the current frameloader
     92  // (mFrameLoader) then this will also call nsFrameLoader::Destroy on all the
     93  // other frame loaders in mFrameLoaderList and remove them from the list.
     94  void FrameLoaderDestroying(nsFrameLoader* aFrameLoader,
     95                             bool aDestroyBFCached);
     96 
     97 private:
     98  bool UseRemoteSubframes();
     99 
    100  // The enum class for determine how to handle previous BrowsingContext during
    101  // the change remoteness. It could be followings
    102  // 1. DONT_PRESERVE
    103  //    Create a whole new BrowsingContext.
    104  // 2. PRESERVE
    105  //    Preserve the previous BrowsingContext.
    106  enum class ChangeRemotenessContextType {
    107    DONT_PRESERVE = 0,
    108    PRESERVE = 1,
    109  };
    110  ChangeRemotenessContextType ShouldPreserveBrowsingContext(
    111      bool aIsRemote, bool aReplaceBrowsingContext);
    112 
    113  MOZ_CAN_RUN_SCRIPT
    114  void ChangeRemotenessCommon(
    115      const ChangeRemotenessContextType& aContextType,
    116      const mozilla::dom::NavigationIsolationOptions& aOptions,
    117      bool aSwitchingInProgressLoad, bool aIsRemote,
    118      mozilla::dom::BrowsingContextGroup* aGroup,
    119      std::function<void()>& aFrameLoaderInit, mozilla::ErrorResult& aRv);
    120 
    121  void ChangeFrameLoaderCommon(mozilla::dom::Element* aOwner,
    122                               bool aRetainPaint);
    123 
    124  MOZ_CAN_RUN_SCRIPT
    125  void UpdateFocusAndMouseEnterStateAfterFrameLoaderChange(
    126      mozilla::dom::Element* aOwner);
    127 
    128 protected:
    129  virtual ~nsFrameLoaderOwner() = default;
    130  RefPtr<nsFrameLoader> mFrameLoader;
    131 
    132  // The list contains all the nsFrameLoaders created for this owner or moved
    133  // from another nsFrameLoaderOwner which haven't been destroyed yet.
    134  // In particular it contains all the nsFrameLoaders which are in bfcache.
    135  mozilla::LinkedList<nsFrameLoader> mFrameLoaderList;
    136 };
    137 
    138 #endif  // nsFrameLoaderOwner_h_