LCOV - code coverage report
Current view: directory - content/html/content/src - nsHTMLDNSPrefetch.h (source / functions) Found Hit Coverage
Test: app.info Lines: 3 3 100.0 %
Date: 2012-06-02 Functions: 4 4 100.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is Mozilla.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Mozilla Corporation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2008
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Patrick McManus <mcmanus@ducksong.com>
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      27                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : #ifndef nsHTMLDNSPrefetch_h___
      40                 : #define nsHTMLDNSPrefetch_h___
      41                 : 
      42                 : #include "nsCOMPtr.h"
      43                 : #include "nsAutoPtr.h"
      44                 : #include "nsString.h"
      45                 : 
      46                 : #include "nsIDNSListener.h"
      47                 : #include "nsIWebProgressListener.h"
      48                 : #include "nsWeakReference.h"
      49                 : #include "nsIObserver.h"
      50                 : 
      51                 : class nsIDocument;
      52                 : class nsITimer;
      53                 : namespace mozilla {
      54                 : namespace dom {
      55                 : class Link;
      56                 : } // namespace dom
      57                 : } // namespace mozilla
      58                 : 
      59                 : namespace mozilla {
      60                 : namespace net {
      61                 : class NeckoParent;
      62                 : } // namespace net
      63                 : } // namespace mozilla
      64                 : 
      65                 : class nsHTMLDNSPrefetch 
      66                 : {
      67                 : public:
      68                 :   // The required aDocument parameter is the context requesting the prefetch - under
      69                 :   // certain circumstances (e.g. headers, or security context) associated with
      70                 :   // the context the prefetch will not be performed. 
      71                 :   static bool     IsAllowed(nsIDocument *aDocument);
      72                 :  
      73                 :   static nsresult Initialize();
      74                 :   static nsresult Shutdown();
      75                 :   
      76                 :   // Call one of the Prefetch* methods to start the lookup.
      77                 :   //
      78                 :   // The URI versions will defer DNS lookup until pageload is
      79                 :   // complete, while the string versions submit the lookup to 
      80                 :   // the DNS system immediately. The URI version is somewhat lighter
      81                 :   // weight, but its request is also more likely to be dropped due to a 
      82                 :   // full queue and it may only be used from the main thread.
      83                 : 
      84                 :   static nsresult PrefetchHigh(mozilla::dom::Link *aElement);
      85                 :   static nsresult PrefetchMedium(mozilla::dom::Link *aElement);
      86                 :   static nsresult PrefetchLow(mozilla::dom::Link *aElement);
      87                 :   static nsresult PrefetchHigh(const nsAString &host);
      88                 :   static nsresult PrefetchMedium(const nsAString &host);
      89                 :   static nsresult PrefetchLow(const nsAString &host);
      90                 :   static nsresult CancelPrefetchLow(const nsAString &host, nsresult aReason);
      91                 :   static nsresult CancelPrefetchLow(mozilla::dom::Link *aElement,
      92                 :                                     nsresult aReason);
      93                 : 
      94                 : private:
      95                 :   static nsresult Prefetch(const nsAString &host, PRUint16 flags);
      96                 :   static nsresult Prefetch(mozilla::dom::Link *aElement, PRUint16 flags);
      97                 :   static nsresult CancelPrefetch(const nsAString &hostname,
      98                 :                                  PRUint16 flags,
      99                 :                                  nsresult aReason);
     100                 :   static nsresult CancelPrefetch(mozilla::dom::Link *aElement,
     101                 :                                  PRUint16 flags,
     102                 :                                  nsresult aReason);
     103                 :   
     104                 : public:
     105                 :   class nsListener MOZ_FINAL : public nsIDNSListener
     106                 :   {
     107                 :     // This class exists to give a safe callback no-op DNSListener
     108                 :   public:
     109                 :     NS_DECL_ISUPPORTS
     110                 :     NS_DECL_NSIDNSLISTENER
     111                 : 
     112            1404 :     nsListener()  {}
     113                 :   private:
     114            1403 :     ~nsListener() {}
     115                 :   };
     116                 :   
     117                 :   class nsDeferrals MOZ_FINAL: public nsIWebProgressListener
     118                 :                              , public nsSupportsWeakReference
     119                 :                              , public nsIObserver
     120                 :   {
     121                 :   public:
     122                 :     NS_DECL_ISUPPORTS
     123                 :     NS_DECL_NSIWEBPROGRESSLISTENER
     124                 :     NS_DECL_NSIOBSERVER
     125                 : 
     126                 :     nsDeferrals();
     127                 :     
     128                 :     void Activate();
     129                 :     nsresult Add(PRUint16 flags, mozilla::dom::Link *aElement);
     130                 :     
     131                 :   private:
     132                 :     ~nsDeferrals();
     133                 :     void Flush();
     134                 :     
     135                 :     void SubmitQueue();
     136                 :     
     137                 :     PRUint16                  mHead;
     138                 :     PRUint16                  mTail;
     139                 :     PRUint32                  mActiveLoaderCount;
     140                 : 
     141                 :     nsCOMPtr<nsITimer>        mTimer;
     142                 :     bool                      mTimerArmed;
     143                 :     static void Tick(nsITimer *aTimer, void *aClosure);
     144                 :     
     145                 :     static const int          sMaxDeferred = 512;  // keep power of 2 for masking
     146                 :     static const int          sMaxDeferredMask = (sMaxDeferred - 1);
     147                 :     
     148                 :     struct deferred_entry
     149         1437184 :     {
     150                 :       PRUint16                         mFlags;
     151                 :       nsWeakPtr                        mElement;
     152                 :     } mEntries[sMaxDeferred];
     153                 :   };
     154                 : 
     155                 :   friend class mozilla::net::NeckoParent;
     156                 : };
     157                 : 
     158                 : #endif 

Generated by: LCOV version 1.7