nsINetworkPredictor.idl 6.1 KB

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