Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 nsIPrincipal;
10
interface mozIPlacesPendingOperation;
11
interface nsIFaviconDataCallback;
12
13
[scriptable, uuid(e81e0b0c-b9f1-4c2e-8f3c-b809933cf73c)]
14
interface nsIFaviconService : nsISupports
15
{
16
// The favicon is being loaded from a private browsing window
17
const unsigned long FAVICON_LOAD_PRIVATE = 1;
18
// The favicon is being loaded from a non-private browsing window
19
const unsigned long FAVICON_LOAD_NON_PRIVATE = 2;
20
21
/**
22
* The limit in bytes of the size of favicons in memory and passed via the
23
* favicon protocol.
24
*/
25
const unsigned long MAX_FAVICON_BUFFER_SIZE = 65536;
26
27
/**
28
* For a given icon URI, this will return a URI that will result in the image.
29
* In most cases, this is an annotation URI. For chrome URIs, this will do
30
* nothing but returning the input URI.
31
*
32
* No validity checking is done. If you pass an icon URI that we've never
33
* seen, you'll get back a URI that references an invalid icon. The moz-anno
34
* protocol handler's special case for "favicon" annotations will resolve
35
* invalid icons to the default icon, although without caching.
36
* For invalid chrome URIs, you'll get a broken image.
37
*
38
* @param aFaviconURI
39
* The URI of an icon in the favicon service.
40
* @return A URI that will give you the icon image. This is NOT the URI of
41
* the icon as set on the page, but a URI that will give you the
42
* data out of the favicon service. For a normal page with a
43
* favicon we've stored, this will be an annotation URI which will
44
* then cause the corresponding favicon data to be loaded async from
45
* this service. For pages where we don't have a favicon, this will
46
* be a chrome URI of the default icon. For chrome URIs, the
47
* output will be the same as the input.
48
*/
49
nsIURI getFaviconLinkForIcon(in nsIURI aFaviconURI);
50
51
/**
52
* Expire all known favicons from the database.
53
*
54
* @note This is an async method.
55
* On successful completion a "places-favicons-expired" notification is
56
* dispatched through observer's service.
57
*/
58
void expireAllFavicons();
59
60
/**
61
* Sets the default size returned by preferredSizeFromURI when the uri doesn't
62
* specify a size ref. If this is not invoked first, or 0 is passed to it,
63
* preferredSizeFromURI() will return UINT16_MAX, that matches the biggest
64
* icon available.
65
*/
66
void setDefaultIconURIPreferredSize(in unsigned short aDefaultSize);
67
68
/**
69
* Tries to extract the preferred size from an icon uri ref fragment.
70
*
71
* @param aURI
72
* The URI to parse.
73
* @return The preferred size, or a default size set through
74
* setDefaultIconURIPreferredSize, or UINT16_MAX if neither are set.
75
*/
76
unsigned short preferredSizeFromURI(in nsIURI aURI);
77
78
/**
79
* The default favicon URI
80
*/
81
readonly attribute nsIURI defaultFavicon;
82
83
/**
84
* The default favicon mimeType
85
*/
86
readonly attribute AUTF8String defaultFaviconMimeType;
87
88
/**
89
* Declares that a given page uses a favicon with the given URI and
90
* attempts to fetch and save the icon data by loading the favicon URI
91
* through an async network request.
92
*
93
* If the icon data already exists, we won't try to reload the icon unless
94
* aForceReload is true. Similarly, if the icon is in the failed favicon
95
* cache we won't do anything unless aForceReload is true, in which case
96
* we'll try to reload the favicon.
97
*
98
* This function will only save favicons for pages that are already stored in
99
* the database, like visited pages or bookmarks. For any other URIs, it
100
* will succeed but do nothing. This function will also ignore the error
101
* page favicon URI (see FAVICON_ERRORPAGE_URL below).
102
*
103
* Icons that fail to load will automatically be added to the failed favicon
104
* cache, and this function will not save favicons for non-bookmarked URIs
105
* when history is disabled.
106
*
107
* @note This function is identical to
108
* nsIFaviconService::setAndLoadFaviconForPage.
109
*
110
* @param aPageURI
111
* URI of the page whose favicon is being set.
112
* @param aFaviconURI
113
* URI of the favicon to associate with the page.
114
* @param aForceReload
115
* If aForceReload is false, we try to reload the favicon only if we
116
* don't have it or it has expired from the cache. Setting
117
* aForceReload to true causes us to reload the favicon even if we
118
* have a usable copy.
119
* @param aFaviconLoadType
120
* Set to FAVICON_LOAD_PRIVATE if the favicon is loaded from a private
121
* browsing window. Set to FAVICON_LOAD_NON_PRIVATE otherwise.
122
* @param [optional] aCallback
123
* Once we're done setting and/or fetching the favicon, we invoke this
124
* callback.
125
* @param [optional] aLoadingPrincipal
126
* Principal of the page whose favicon is being set. If this argument
127
* is omitted, the loadingPrincipal defaults to the nullPrincipal.
128
* @param [optional] aRequestContextID
129
* used to inform Necko of how to link the
130
* favicon request with other requests in the same tab.
131
*
132
* @see nsIFaviconDataCallback in nsIFaviconService.idl.
133
*/
134
mozIPlacesPendingOperation setAndFetchFaviconForPage(
135
in nsIURI aPageURI,
136
in nsIURI aFaviconURI,
137
in boolean aForceReload,
138
in unsigned long aFaviconLoadType,
139
[optional] in nsIFaviconDataCallback aCallback,
140
[optional] in nsIPrincipal aLoadingPrincipal,
141
[optional] in unsigned long long aRequestContextID);
142
143
/**
144
* Sets the data for a given favicon URI either by replacing existing data in
145
* the database or taking the place of otherwise fetched icon data when
146
* calling setAndFetchFaviconForPage later.
147
*
148
* Favicon data for favicon URIs that are not associated with a page URI via
149
* setAndFetchFaviconForPage will be stored in memory, but may be expired at
150
* any time, so you should make an effort to associate favicon URIs with page
151
* URIs as soon as possible.
152
*
153
* It's better to not use this function for chrome: icon URIs since you can
154
* reference the chrome image yourself. getFaviconLinkForIcon/Page will ignore
155
* any associated data if the favicon URI is "chrome:" and just return the
156
* same chrome URI.
157
*
158
* This function does NOT send out notifications that the data has changed.
159
* Pages using this favicons that are visible in history or bookmarks views
160
* will keep the old icon until they have been refreshed by other means.
161
*
162
* This function tries to optimize the favicon size, if it is bigger
163
* than a defined limit we will try to convert it to a 16x16 png image.
164
* If the conversion fails and favicon is still bigger than our max accepted
165
* size it won't be saved.
166
*
167
* @param aFaviconURI
168
* URI of the favicon whose data is being set.
169
* @param aData
170
* Binary contents of the favicon to save
171
* @param aMimeType
172
* MIME type of the data to store. This is important so that we know
173
* what to report when the favicon is used. You should always set this
174
* param unless you are clearing an icon.
175
* @param [optional] aExpiration
176
* Time in microseconds since the epoch when this favicon expires.
177
* Until this time, we won't try to load it again.
178
* @throws NS_ERROR_FAILURE
179
* Thrown if the favicon is overbloated and won't be saved to the db.
180
*/
181
void replaceFaviconData(in nsIURI aFaviconURI,
182
in Array<octet> aData,
183
in AUTF8String aMimeType,
184
[optional] in PRTime aExpiration);
185
186
/**
187
* Same as replaceFaviconData but the data is provided by a string
188
* containing a data URL.
189
*
190
* @see replaceFaviconData
191
*
192
* @param aFaviconURI
193
* URI of the favicon whose data is being set.
194
* @param aDataURL
195
* string containing a data URL that represents the contents of
196
* the favicon to save
197
* @param [optional] aExpiration
198
* Time in microseconds since the epoch when this favicon expires.
199
* Until this time, we won't try to load it again.
200
* @param [optional] aLoadingPrincipal
201
* Principal of the page whose favicon is being set. If this argument
202
* is omitted, the loadingPrincipal defaults to the nullPrincipal.
203
* @throws NS_ERROR_FAILURE
204
* Thrown if the favicon is overbloated and won't be saved to the db.
205
*/
206
void replaceFaviconDataFromDataURL(in nsIURI aFaviconURI,
207
in AString aDataURL,
208
[optional] in PRTime aExpiration,
209
[optional] in nsIPrincipal aLoadingPrincipal);
210
211
/**
212
* Retrieves the favicon URI associated to the given page, if any.
213
*
214
* @param aPageURI
215
* URI of the page whose favicon URI we're looking up.
216
* @param aCallback
217
* This callback is always invoked to notify the result of the lookup.
218
* The aURI parameter will be the favicon URI, or null when no favicon
219
* is associated with the page or an error occurred while fetching it.
220
* aDataLen will be always 0, aData will be an empty array, and
221
* aMimeType will be an empty string, regardless of whether a favicon
222
* was found.
223
* @param [optional] aPreferredWidth
224
* The preferred icon width, 0 for the biggest available.
225
*
226
* @note If a favicon specific to this page cannot be found, this will try to
227
* fallback to the /favicon.ico for the root domain.
228
*
229
* @see nsIFaviconDataCallback in nsIFaviconService.idl.
230
*/
231
void getFaviconURLForPage(in nsIURI aPageURI,
232
in nsIFaviconDataCallback aCallback,
233
[optional] in unsigned short aPreferredWidth);
234
235
/**
236
* Retrieves the favicon URI and data associated to the given page, if any.
237
* If the page icon is not available, it will try to return the root domain
238
* icon data, when it's known.
239
*
240
* @param aPageURI
241
* URI of the page whose favicon URI and data we're looking up.
242
* @param aCallback
243
* This callback is always invoked to notify the result of the lookup. The aURI
244
* parameter will be the favicon URI, or null when no favicon is
245
* associated with the page or an error occurred while fetching it. If
246
* aURI is not null, the other parameters may contain the favicon data.
247
* However, if no favicon data is currently associated with the favicon
248
* URI, aDataLen will be 0, aData will be an empty array, and aMimeType
249
* will be an empty string.
250
* @param [optional] aPreferredWidth
251
* The preferred icon width, 0 for the biggest available.
252
* @note If a favicon specific to this page cannot be found, this will try to
253
* fallback to the /favicon.ico for the root domain.
254
*
255
* @see nsIFaviconDataCallback in nsIFaviconService.idl.
256
*/
257
void getFaviconDataForPage(in nsIURI aPageURI,
258
in nsIFaviconDataCallback aCallback,
259
[optional] in unsigned short aPreferredWidth);
260
261
/**
262
* Copies cached favicons from a page to another one.
263
*
264
* @param aFromPageURI
265
* URI of the originating page.
266
* @param aToPageURI
267
* URI of the destination page.
268
* @param aFaviconLoadType
269
* Set to FAVICON_LOAD_PRIVATE if the copy is started from a private
270
* browsing window. Set to FAVICON_LOAD_NON_PRIVATE otherwise.
271
* @param [optional] aCallback
272
* Once we're done copying the favicon, we invoke this callback.
273
* If a copy has been done, the callback will report one of the
274
* favicons uri as aFaviconURI, otherwise all the params will be null.
275
*/
276
void copyFavicons(in nsIURI aFromPageURI,
277
in nsIURI aToPageURI,
278
in unsigned long aFaviconLoadType,
279
[optional] in nsIFaviconDataCallback aCallback);
280
};
281
282
[scriptable, function, uuid(c85e5c82-b70f-4621-9528-beb2aa47fb44)]
283
interface nsIFaviconDataCallback : nsISupports
284
{
285
/**
286
* Called when the required favicon's information is available.
287
*
288
* It's up to the invoking method to state if the callback is always invoked,
289
* or called on success only. Check the method documentation to ensure that.
290
*
291
* The caller will receive the most information we can gather on the icon,
292
* but it's not guaranteed that all of them will be set. For some method
293
* we could not know the favicon's data (it could just be too expensive to
294
* get it, or the method does not require we actually have any data).
295
* It's up to the caller to check aDataLen > 0 before using any data-related
296
* information like mime-type or data itself.
297
*
298
* @param aFaviconURI
299
* Receives the "favicon URI" (not the "favicon link URI") associated
300
* to the requested page. This can be null if there is no associated
301
* favicon URI, or the callback is notifying a failure.
302
* @param aDataLen
303
* Size of the icon data in bytes. Notice that a value of 0 does not
304
* necessarily mean that we don't have an icon.
305
* @param aData
306
* Icon data, or an empty array if aDataLen is 0.
307
* @param aMimeType
308
* Mime type of the icon, or an empty string if aDataLen is 0.
309
* @param aWidth
310
* Width of the icon. 0 if the width is unknown or if the icon is
311
* vectorial.
312
*
313
* @note If you want to open a network channel to access the favicon, it's
314
* recommended that you call the getFaviconLinkForIcon method to convert
315
* the "favicon URI" into a "favicon link URI".
316
*/
317
void onComplete(in nsIURI aFaviconURI,
318
in unsigned long aDataLen,
319
[const,array,size_is(aDataLen)] in octet aData,
320
in AUTF8String aMimeType,
321
in unsigned short aWidth);
322
};
323
324
%{C++
325
326
/**
327
* Notification sent when all favicons are expired.
328
*/
329
#define NS_PLACES_FAVICONS_EXPIRED_TOPIC_ID "places-favicons-expired"
330
331
#define FAVICON_DEFAULT_URL "chrome://mozapps/skin/places/defaultFavicon.svg"
332
#define FAVICON_DEFAULT_MIMETYPE "image/svg+xml"
333
334
#define FAVICON_ERRORPAGE_URL "chrome://global/skin/icons/warning.svg"
335
336
%}