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 
12 class nsIURI;
13 
14 namespace mozilla {
15 
16 namespace dom {
17 class Link;
18 }  // namespace dom
19 
20 // 0057c9d3-b98e-4933-bdc5-0275d06705e1
21 #define IHISTORY_IID                                 \
22   {                                                  \
23     0x0057c9d3, 0xb98e, 0x4933, {                    \
24       0xbd, 0xc5, 0x02, 0x75, 0xd0, 0x67, 0x05, 0xe1 \
25     }                                                \
26   }
27 
28 class IHistory : public nsISupports {
29  public:
30   NS_DECLARE_STATIC_IID_ACCESSOR(IHISTORY_IID)
31 
32   /**
33    * Registers the Link for notifications about the visited-ness of aURI.
34    * Consumers should assume that the URI is unvisited after calling this, and
35    * they will be notified if that state (unvisited) changes by having
36    * SetLinkState called on themselves.  This function is guaranteed to run to
37    * completion before aLink is notified.  After the node is notified, it will
38    * be unregistered.
39    *
40    * @note SetLinkState must not call RegisterVisitedCallback or
41    *       UnregisterVisitedCallback.
42    *
43    * @pre aURI must not be null.
44    * @pre aLink may be null only in the parent (chrome) process.
45    *
46    * @param aURI
47    *        The URI to check.
48    * @param aLink
49    *        The link to update whenever the history status changes.  The
50    *        implementation will only hold onto a raw pointer, so if this
51    *        object should be destroyed, be sure to call
52    *        UnregisterVistedCallback first.
53    */
54   NS_IMETHOD RegisterVisitedCallback(nsIURI* aURI, dom::Link* aLink) = 0;
55 
56   /**
57    * Unregisters a previously registered Link object.  This must be called
58    * before destroying the registered object.
59    *
60    * @pre aURI must not be null.
61    * @pre aLink must not be null.
62    *
63    * @param aURI
64    *        The URI that aLink was registered for.
65    * @param aLink
66    *        The link object to unregister for aURI.
67    */
68   NS_IMETHOD UnregisterVisitedCallback(nsIURI* aURI, dom::Link* aLink) = 0;
69 
70   enum VisitFlags {
71     /**
72      * Indicates whether the URI was loaded in a top-level window.
73      */
74     TOP_LEVEL = 1 << 0,
75     /**
76      * Indicates whether the URI was loaded as part of a permanent redirect.
77      */
78     REDIRECT_PERMANENT = 1 << 1,
79     /**
80      * Indicates whether the URI was loaded as part of a temporary redirect.
81      */
82     REDIRECT_TEMPORARY = 1 << 2,
83     /**
84      * Indicates the URI is redirecting  (Response code 3xx).
85      */
86     REDIRECT_SOURCE = 1 << 3,
87     /**
88      * Indicates the URI caused an error that is unlikely fixable by a
89      * retry, like a not found or unfetchable page.
90      */
91     UNRECOVERABLE_ERROR = 1 << 4
92   };
93 
94   /**
95    * Adds a history visit for the URI.
96    *
97    * @pre aURI must not be null.
98    *
99    * @param aURI
100    *        The URI of the page being visited.
101    * @param aLastVisitedURI
102    *        The URI of the last visit in the chain.
103    * @param aFlags
104    *        The VisitFlags describing this visit.
105    */
106   NS_IMETHOD VisitURI(nsIURI* aURI, nsIURI* aLastVisitedURI,
107                       uint32_t aFlags) = 0;
108 
109   /**
110    * Set the title of the URI.
111    *
112    * @pre aURI must not be null.
113    *
114    * @param aURI
115    *        The URI to set the title for.
116    * @param aTitle
117    *        The title string.
118    */
119   NS_IMETHOD SetURITitle(nsIURI* aURI, const nsAString& aTitle) = 0;
120 
121   /**
122    * Notifies about the visited status of a given URI.
123    *
124    * @param aURI
125    *        The URI to notify about.
126    */
127   NS_IMETHOD NotifyVisited(nsIURI* aURI) = 0;
128 };
129 
130 NS_DEFINE_STATIC_IID_ACCESSOR(IHistory, IHISTORY_IID)
131 
132 #define NS_DECL_IHISTORY                                                       \
133   NS_IMETHOD RegisterVisitedCallback(nsIURI* aURI,                             \
134                                      mozilla::dom::Link* aContent) override;   \
135   NS_IMETHOD UnregisterVisitedCallback(nsIURI* aURI,                           \
136                                        mozilla::dom::Link* aContent) override; \
137   NS_IMETHOD VisitURI(nsIURI* aURI, nsIURI* aLastVisitedURI, uint32_t aFlags)  \
138       override;                                                                \
139   NS_IMETHOD SetURITitle(nsIURI* aURI, const nsAString& aTitle) override;      \
140   NS_IMETHOD NotifyVisited(nsIURI* aURI) override;
141 
142 }  // namespace mozilla
143 
144 #endif  // mozilla_IHistory_h_
145