netwerk/base/public/nsINetworkSeer.idl

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:e221250c3b5e
1 /* vim: set ts=2 sts=2 et sw=2: */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #include "nsISupports.idl"
7
8 interface nsIURI;
9 interface nsILoadContext;
10 interface nsINetworkSeerVerifier;
11
12 typedef unsigned long SeerPredictReason;
13 typedef unsigned long SeerLearnReason;
14
15 /**
16 * nsINetworkSeer - learn about pages users visit, and allow us to take
17 * predictive actions upon future visits.
18 * NOTE: nsINetworkSeer should only be used on the main thread
19 */
20 [scriptable, uuid(25e323b6-99e0-4274-b5b3-1a9eb56e28ac)]
21 interface nsINetworkSeer : nsISupports
22 {
23 /**
24 * Prediction reasons
25 *
26 * PREDICT_LINK - we are being asked to take predictive action because
27 * the user is hovering over a link.
28 *
29 * PREDICT_LOAD - we are being asked to take predictive action because
30 * the user has initiated a pageload.
31 *
32 * PREDICT_STARTUP - we are being asked to take predictive action
33 * because the browser is starting up.
34 */
35 const SeerPredictReason PREDICT_LINK = 0;
36 const SeerPredictReason PREDICT_LOAD = 1;
37 const SeerPredictReason PREDICT_STARTUP = 2;
38
39 /**
40 * Start taking predictive actions
41 *
42 * Calling this will cause the seer to (possibly) start
43 * taking actions such as DNS prefetch and/or TCP preconnect based on
44 * (1) the host name that we are given, and (2) the reason we are being
45 * asked to take actions.
46 *
47 * @param targetURI - The URI we are being asked to take actions based on.
48 * @param sourceURI - The URI that is currently loaded. This is so we can
49 * avoid doing predictive actions for link hover on an HTTPS page (for
50 * example).
51 * @param reason - The reason we are being asked to take actions. Can be
52 * any of the PREDICT_* values above.
53 * In the case of PREDICT_LINK, targetURI should be the URI of the link
54 * that is being hovered over, and sourceURI should be the URI of the page
55 * on which the link appears.
56 * In the case of PREDICT_LOAD, targetURI should be the URI of the page that
57 * is being loaded and sourceURI should be null.
58 * In the case of PREDICT_STARTUP, both targetURI and sourceURI should be
59 * null.
60 * @param loadContext - The nsILoadContext of the page load we are predicting
61 * about.
62 * @param verifier - An nsINetworkSeerVerifier used in testing to ensure we're
63 * predicting the way we expect to. Not necessary (or desired) for normal
64 * operation.
65 */
66 void predict(in nsIURI targetURI,
67 in nsIURI sourceURI,
68 in SeerPredictReason reason,
69 in nsILoadContext loadContext,
70 in nsINetworkSeerVerifier verifier);
71
72
73 /*
74 * Reasons we are learning something
75 *
76 * LEARN_LOAD_TOPLEVEL - we are learning about the toplevel resource of a
77 * pageload (NOTE: this should ONLY be used by tests)
78 *
79 * LEARN_LOAD_SUBRESOURCE - we are learning a subresource from a pageload
80 *
81 * LEARN_LOAD_REDIRECT - we are learning about the re-direct of a URI
82 *
83 * LEARN_STARTUP - we are learning about a page loaded during startup
84 */
85 const SeerLearnReason LEARN_LOAD_TOPLEVEL = 0;
86 const SeerLearnReason LEARN_LOAD_SUBRESOURCE = 1;
87 const SeerLearnReason LEARN_LOAD_REDIRECT = 2;
88 const SeerLearnReason LEARN_STARTUP = 3;
89
90 /**
91 * Add to our compendium of knowledge
92 *
93 * This adds to our prediction database to make things (hopefully)
94 * smarter next time we predict something.
95 *
96 * @param targetURI - The URI that was loaded that we are keeping track of.
97 * @param sourceURI - The URI that caused targetURI to be loaded (for page
98 * loads). This means the DOCUMENT URI.
99 * @param reason - The reason we are learning this bit of knowledge.
100 * Reason can be any of the LEARN_* values.
101 * In the case of LEARN_LOAD_SUBRESOURCE, targetURI should be the URI of a
102 * subresource of a page, and sourceURI should be the top-level URI.
103 * In the case of LEARN_LOAD_REDIRECT, targetURI is the NEW URI of a
104 * top-level resource that was redirected to, and sourceURI is the
105 * ORIGINAL URI of said top-level resource.
106 * In the case of LEARN_STARTUP, targetURI should be the URI of a page
107 * that was loaded immediately after browser startup, and sourceURI should
108 * be null.
109 * @param loadContext - The nsILoadContext for the page load that we are
110 * learning about.
111 */
112 void learn(in nsIURI targetURI,
113 in nsIURI sourceURI,
114 in SeerLearnReason reason,
115 in nsILoadContext loadContext);
116
117 /**
118 * Clear out all our learned knowledge
119 *
120 * This removes everything from our database so that any predictions begun
121 * after this completes will start from a blank slate.
122 */
123 void reset();
124
125 /**
126 * @deprecated THIS API IS FOR TESTING ONLY. IF YOU DON'T KNOW WHAT IT DOES,
127 * DON'T USE IT
128 */
129 void prepareForDnsTest(in long long timestamp, in string uri);
130 };
131
132 %{C++
133 // Wrapper functions to make use of the seer easier and less invasive
134 class nsIChannel;
135 class nsIDocument;
136 class nsILoadContext;
137 class nsILoadGroup;
138 class nsINetworkSeerVerifier;
139
140 namespace mozilla {
141 namespace net {
142
143 nsresult SeerPredict(nsIURI *targetURI,
144 nsIURI *sourceURI,
145 SeerPredictReason reason,
146 nsILoadContext *loadContext,
147 nsINetworkSeerVerifier *verifier);
148
149 nsresult SeerLearn(nsIURI *targetURI,
150 nsIURI *sourceURI,
151 SeerLearnReason reason,
152 nsILoadContext *loadContext);
153
154 nsresult SeerLearn(nsIURI *targetURI,
155 nsIURI *sourceURI,
156 SeerLearnReason reason,
157 nsILoadGroup *loadGroup);
158
159 nsresult SeerLearn(nsIURI *targetURI,
160 nsIURI *sourceURI,
161 SeerLearnReason reason,
162 nsIDocument *document);
163
164 nsresult SeerLearnRedirect(nsIURI *targetURI,
165 nsIChannel *channel,
166 nsILoadContext *loadContext);
167
168 } // mozilla::net
169 } // mozilla
170 %}

mercurial