Source code

Revision control

Other Tools

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 nsINetworkPredictorVerifier;
10
11
webidl Document;
12
13
typedef unsigned long PredictorPredictReason;
14
typedef unsigned long PredictorLearnReason;
15
16
[ref] native OriginAttributes(const mozilla::OriginAttributes);
17
18
/**
19
* nsINetworkPredictor - learn about pages users visit, and allow us to take
20
* predictive actions upon future visits.
21
* NOTE: nsINetworkPredictor should only
22
* be used on the main thread.
23
*/
24
[scriptable, builtinclass, uuid(acc88e7c-3f39-42c7-ac31-6377c2c3d73e)]
25
interface nsINetworkPredictor : nsISupports
26
{
27
/**
28
* Prediction reasons
29
*
30
* PREDICT_LINK - we are being asked to take predictive action because
31
* the user is hovering over a link.
32
*
33
* PREDICT_LOAD - we are being asked to take predictive action because
34
* the user has initiated a pageload.
35
*
36
* PREDICT_STARTUP - we are being asked to take predictive action
37
* because the browser is starting up.
38
*/
39
const PredictorPredictReason PREDICT_LINK = 0;
40
const PredictorPredictReason PREDICT_LOAD = 1;
41
const PredictorPredictReason PREDICT_STARTUP = 2;
42
43
/**
44
* Start taking predictive actions
45
*
46
* Calling this will cause the predictor to (possibly) start
47
* taking actions such as DNS prefetch and/or TCP preconnect based on
48
* (1) the host name that we are given, and (2) the reason we are being
49
* asked to take actions.
50
*
51
* @param targetURI - The URI we are being asked to take actions based on.
52
* @param sourceURI - The URI that is currently loaded. This is so we can
53
* avoid doing predictive actions for link hover on an HTTPS page (for
54
* example).
55
* @param reason - The reason we are being asked to take actions. Can be
56
* any of the PREDICT_* values above.
57
* In the case of PREDICT_LINK, targetURI should be the URI of the link
58
* that is being hovered over, and sourceURI should be the URI of the page
59
* on which the link appears.
60
* In the case of PREDICT_LOAD, targetURI should be the URI of the page that
61
* is being loaded and sourceURI should be null.
62
* In the case of PREDICT_STARTUP, both targetURI and sourceURI should be
63
* null.
64
* @param originAttributes - The originAttributes of the page load we are
65
* predicting about.
66
* @param verifier - An nsINetworkPredictorVerifier used in testing to ensure
67
* we're predicting the way we expect to. Not necessary (or desired) for
68
* normal operation.
69
*/
70
[implicit_jscontext]
71
void predict(in nsIURI targetURI,
72
in nsIURI sourceURI,
73
in PredictorPredictReason reason,
74
in jsval originAttributes,
75
in nsINetworkPredictorVerifier verifier);
76
77
[notxpcom]
78
nsresult predictNative(in nsIURI targetURI,
79
in nsIURI sourceURI,
80
in PredictorPredictReason reason,
81
in OriginAttributes originAttributes,
82
in nsINetworkPredictorVerifier verifier);
83
84
85
/*
86
* Reasons we are learning something
87
*
88
* LEARN_LOAD_TOPLEVEL - we are learning about the toplevel resource of a
89
* pageload (NOTE: this should ONLY be used by tests)
90
*
91
* LEARN_LOAD_SUBRESOURCE - we are learning a subresource from a pageload
92
*
93
* LEARN_LOAD_REDIRECT - we are learning about the re-direct of a URI
94
*
95
* LEARN_STARTUP - we are learning about a page loaded during startup
96
*/
97
const PredictorLearnReason LEARN_LOAD_TOPLEVEL = 0;
98
const PredictorLearnReason LEARN_LOAD_SUBRESOURCE = 1;
99
const PredictorLearnReason LEARN_LOAD_REDIRECT = 2;
100
const PredictorLearnReason LEARN_STARTUP = 3;
101
102
/**
103
* Add to our compendium of knowledge
104
*
105
* This adds to our prediction database to make things (hopefully)
106
* smarter next time we predict something.
107
*
108
* @param targetURI - The URI that was loaded that we are keeping track of.
109
* @param sourceURI - The URI that caused targetURI to be loaded (for page
110
* loads). This means the DOCUMENT URI.
111
* @param reason - The reason we are learning this bit of knowledge.
112
* Reason can be any of the LEARN_* values.
113
* In the case of LEARN_LOAD_SUBRESOURCE, targetURI should be the URI of a
114
* subresource of a page, and sourceURI should be the top-level URI.
115
* In the case of LEARN_LOAD_REDIRECT, targetURI is the NEW URI of a
116
* top-level resource that was redirected to, and sourceURI is the
117
* ORIGINAL URI of said top-level resource.
118
* In the case of LEARN_STARTUP, targetURI should be the URI of a page
119
* that was loaded immediately after browser startup, and sourceURI should
120
* be null.
121
* @param originAttributes - The originAttributes for the page load that we
122
* are learning about.
123
*/
124
[implicit_jscontext]
125
void learn(in nsIURI targetURI,
126
in nsIURI sourceURI,
127
in PredictorLearnReason reason,
128
in jsval originAttributes);
129
130
[notxpcom]
131
nsresult learnNative(in nsIURI targetURI,
132
in nsIURI sourceURI,
133
in PredictorLearnReason reason,
134
in OriginAttributes originAttributes);
135
136
/**
137
* Clear out all our learned knowledge
138
*
139
* This removes everything from our database so that any predictions begun
140
* after this completes will start from a blank slate.
141
*/
142
void reset();
143
};
144
145
%{C++
146
// Wrapper functions to make use of the predictor easier and less invasive
147
class nsIChannel;
148
149
class nsILoadContext;
150
class nsILoadGroup;
151
class nsINetworkPredictorVerifier;
152
153
namespace mozilla {
154
namespace net {
155
156
nsresult PredictorPredict(nsIURI *targetURI,
157
nsIURI *sourceURI,
158
PredictorPredictReason reason,
159
const OriginAttributes& originAttributes,
160
nsINetworkPredictorVerifier *verifier);
161
162
nsresult PredictorLearn(nsIURI *targetURI,
163
nsIURI *sourceURI,
164
PredictorLearnReason reason,
165
const OriginAttributes& originAttributes);
166
167
nsresult PredictorLearn(nsIURI *targetURI,
168
nsIURI *sourceURI,
169
PredictorLearnReason reason,
170
nsILoadGroup *loadGroup);
171
172
nsresult PredictorLearn(nsIURI *targetURI,
173
nsIURI *sourceURI,
174
PredictorLearnReason reason,
175
dom::Document *document);
176
177
nsresult PredictorLearnRedirect(nsIURI *targetURI,
178
nsIChannel *channel,
179
const OriginAttributes& originAttributes);
180
181
} // mozilla::net
182
} // mozilla
183
%}