tor-browser

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

IHistory.h (5338B)


      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 mozilla_IHistory_h_
      8 #define mozilla_IHistory_h_
      9 
     10 #include "nsISupports.h"
     11 #include "nsURIHashKey.h"
     12 #include "nsTHashSet.h"
     13 #include "nsTObserverArray.h"
     14 
     15 class nsIURI;
     16 class nsIWidget;
     17 
     18 namespace mozilla {
     19 
     20 namespace dom {
     21 class ContentParent;
     22 class Document;
     23 class Link;
     24 }  // namespace dom
     25 
     26 // 0057c9d3-b98e-4933-bdc5-0275d06705e1
     27 #define IHISTORY_IID \
     28  {0x0057c9d3, 0xb98e, 0x4933, {0xbd, 0xc5, 0x02, 0x75, 0xd0, 0x67, 0x05, 0xe1}}
     29 
     30 class IHistory : public nsISupports {
     31 public:
     32  NS_INLINE_DECL_STATIC_IID(IHISTORY_IID)
     33 
     34  using ContentParentSet = nsTHashSet<RefPtr<dom::ContentParent>>;
     35 
     36  /**
     37   * Registers the Link for notifications about the visited-ness of aURI.
     38   * Consumers should assume that the URI is unvisited after calling this, and
     39   * they will be notified if that state (unvisited) changes by having
     40   * VisitedQueryFinished called on themselves. Note that it may call
     41   * synchronously if the answer is already known.
     42   *
     43   * @note VisitedQueryFinished must not call RegisterVisitedCallback or
     44   *       UnregisterVisitedCallback.
     45   *
     46   * @pre aURI must not be null.
     47   * @pre aLink may be null only in the parent (chrome) process.
     48   *
     49   * @param aURI
     50   *        The URI to check.
     51   * @param aLink
     52   *        The link to update whenever the history status changes.  The
     53   *        implementation will only hold onto a raw pointer, so if this
     54   *        object should be destroyed, be sure to call
     55   *        UnregisterVistedCallback first.
     56   */
     57  virtual void RegisterVisitedCallback(nsIURI* aURI, dom::Link* aLink) = 0;
     58 
     59  /**
     60   * Schedules a single visited query from a given child process.
     61   *
     62   * @param aURI the URI to query.
     63   * @param ContentParent the process interested in knowing about the visited
     64   *                      state of this URI.
     65   */
     66  virtual void ScheduleVisitedQuery(nsIURI* aURI, dom::ContentParent*) = 0;
     67 
     68  /**
     69   * Unregisters a previously registered Link object.  This must be called
     70   * before destroying the registered object, and asserts when misused.
     71   *
     72   * @pre aURI must not be null.
     73   * @pre aLink must not be null.
     74   *
     75   * @param aURI
     76   *        The URI that aLink was registered for.
     77   * @param aLink
     78   *        The link object to unregister for aURI.
     79   */
     80  virtual void UnregisterVisitedCallback(nsIURI* aURI, dom::Link* aLink) = 0;
     81 
     82  enum class VisitedStatus : uint8_t {
     83    Unknown,
     84    Visited,
     85    Unvisited,
     86  };
     87 
     88  /**
     89   * Notifies about the visited status of a given URI. The visited status cannot
     90   * be unknown, otherwise there's no point in notifying of anything.
     91   *
     92   * @param ContentParentSet a set of content processes that are interested on
     93   *                         this change. If null, it is broadcasted to all
     94   *                         child processes.
     95   */
     96  virtual void NotifyVisited(nsIURI*, VisitedStatus,
     97                             const ContentParentSet* = nullptr) = 0;
     98 
     99  enum VisitFlags {
    100    /**
    101     * Indicates whether the URI was loaded in a top-level window.
    102     */
    103    TOP_LEVEL = 1 << 0,
    104    /**
    105     * Indicates whether the URI is the target of a permanent redirect.
    106     */
    107    REDIRECT_PERMANENT = 1 << 1,
    108    /**
    109     * Indicates whether the URI is the target of a temporary redirect.
    110     */
    111    REDIRECT_TEMPORARY = 1 << 2,
    112    /**
    113     * Indicates the URI will redirect  (Response code 3xx).
    114     */
    115    REDIRECT_SOURCE = 1 << 3,
    116    /**
    117     * Indicates the URI caused an error that is unlikely fixable by a
    118     * retry, like a not found or unfetchable page.
    119     */
    120    UNRECOVERABLE_ERROR = 1 << 4,
    121    /**
    122     * If REDIRECT_SOURCE is set, this indicates that the redirect is permanent.
    123     * Note this differs from REDIRECT_PERMANENT because that one refers to how
    124     * we reached the URI, while this is used when the URI itself redirects.
    125     */
    126    REDIRECT_SOURCE_PERMANENT = 1 << 5,
    127    /**
    128     * If REDIRECT_SOURCE is set, this indicates that this is a special redirect
    129     * caused by HSTS or HTTPS-Only/First upgrading to the HTTPS version of the
    130     * URI.
    131     */
    132    REDIRECT_SOURCE_UPGRADED = 1 << 6
    133  };
    134 
    135  /**
    136   * Adds a history visit for the URI.
    137   *
    138   * @pre aURI must not be null.
    139   *
    140   * @param aWidget
    141   *        The widget for the DocShell.
    142   * @param aURI
    143   *        The URI of the page being visited.
    144   * @param aLastVisitedURI
    145   *        The URI of the last visit in the chain.
    146   * @param aFlags
    147   *        The VisitFlags describing this visit.
    148   * @param aBrowserId
    149   *        The id of browser used for this visit.
    150   */
    151  NS_IMETHOD VisitURI(nsIWidget* aWidget, nsIURI* aURI, nsIURI* aLastVisitedURI,
    152                      uint32_t aFlags, uint64_t aBrowserId) = 0;
    153 
    154  /**
    155   * Set the title of the URI.
    156   *
    157   * @pre aURI must not be null.
    158   *
    159   * @param aURI
    160   *        The URI to set the title for.
    161   * @param aTitle
    162   *        The title string.
    163   */
    164  NS_IMETHOD SetURITitle(nsIURI* aURI, const nsAString& aTitle) = 0;
    165 };
    166 
    167 }  // namespace mozilla
    168 
    169 #endif  // mozilla_IHistory_h_