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