PageRenderTime 20ms CodeModel.GetById 10ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 1ms

/parser/html/nsHtml5SpeculativeLoad.h

http://github.com/zpao/v8monkey
C Header | 157 lines | 72 code | 14 blank | 71 comment | 6 complexity | 9f138e126f886ab897e13cb6a0e6ce1a MD5 | raw file
  1/* ***** BEGIN LICENSE BLOCK *****
  2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3 *
  4 * The contents of this file are subject to the Mozilla Public License Version
  5 * 1.1 (the "License"); you may not use this file except in compliance with
  6 * the License. You may obtain a copy of the License at
  7 * http://www.mozilla.org/MPL/
  8 *
  9 * Software distributed under the License is distributed on an "AS IS" basis,
 10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 11 * for the specific language governing rights and limitations under the
 12 * License.
 13 *
 14 * The Original Code is HTML Parser C++ Translator code.
 15 *
 16 * The Initial Developer of the Original Code is
 17 * Mozilla Foundation.
 18 * Portions created by the Initial Developer are Copyright (C) 2010
 19 * the Initial Developer. All Rights Reserved.
 20 *
 21 * Contributor(s):
 22 *   Henri Sivonen <hsivonen@iki.fi>
 23 *
 24 * Alternatively, the contents of this file may be used under the terms of
 25 * either the GNU General Public License Version 2 or later (the "GPL"), or
 26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 27 * in which case the provisions of the GPL or the LGPL are applicable instead
 28 * of those above. If you wish to allow use of your version of this file only
 29 * under the terms of either the GPL or the LGPL, and not to allow others to
 30 * use your version of this file under the terms of the MPL, indicate your
 31 * decision by deleting the provisions above and replace them with the notice
 32 * and other provisions required by the GPL or the LGPL. If you do not delete
 33 * the provisions above, a recipient may use your version of this file under
 34 * the terms of any one of the MPL, the GPL or the LGPL.
 35 *
 36 * ***** END LICENSE BLOCK ***** */
 37 
 38#ifndef nsHtml5SpeculativeLoad_h_
 39#define nsHtml5SpeculativeLoad_h_
 40
 41#include "nsString.h"
 42
 43class nsHtml5TreeOpExecutor;
 44
 45enum eHtml5SpeculativeLoad {
 46#ifdef DEBUG
 47  eSpeculativeLoadUninitialized,
 48#endif
 49  eSpeculativeLoadBase,
 50  eSpeculativeLoadImage,
 51  eSpeculativeLoadScript,
 52  eSpeculativeLoadStyle,
 53  eSpeculativeLoadManifest,
 54  eSpeculativeLoadSetDocumentCharset
 55};
 56
 57class nsHtml5SpeculativeLoad {
 58  public:
 59    nsHtml5SpeculativeLoad();
 60    ~nsHtml5SpeculativeLoad();
 61    
 62    inline void InitBase(const nsAString& aUrl) {
 63      NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
 64                      "Trying to reinitialize a speculative load!");
 65      mOpCode = eSpeculativeLoadBase;
 66      mUrl.Assign(aUrl);
 67    }
 68
 69    inline void InitImage(const nsAString& aUrl,
 70                          const nsAString& aCrossOrigin) {
 71      NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
 72                      "Trying to reinitialize a speculative load!");
 73      mOpCode = eSpeculativeLoadImage;
 74      mUrl.Assign(aUrl);
 75      mCharsetOrCrossOrigin.Assign(aCrossOrigin);
 76    }
 77
 78    inline void InitScript(const nsAString& aUrl,
 79                      const nsAString& aCharset,
 80                      const nsAString& aType) {
 81      NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
 82                      "Trying to reinitialize a speculative load!");
 83      mOpCode = eSpeculativeLoadScript;
 84      mUrl.Assign(aUrl);
 85      mCharsetOrCrossOrigin.Assign(aCharset);
 86      mTypeOrCharsetSource.Assign(aType);
 87    }
 88    
 89    inline void InitStyle(const nsAString& aUrl, const nsAString& aCharset) {
 90      NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
 91                      "Trying to reinitialize a speculative load!");
 92      mOpCode = eSpeculativeLoadStyle;
 93      mUrl.Assign(aUrl);
 94      mCharsetOrCrossOrigin.Assign(aCharset);
 95    }
 96
 97    /**
 98     * "Speculative" manifest loads aren't truly speculative--if a manifest
 99     * gets loaded, we are committed to it. There can never be a <script>
100     * before the manifest, so the situation of having to undo a manifest due
101     * to document.write() never arises. The reason why a parser
102     * thread-discovered manifest gets loaded via the speculative load queue
103     * as opposed to tree operation queue is that the manifest must get
104     * processed before any actual speculative loads such as scripts. Thus,
105     * manifests seen by the parser thread have to maintain the queue order
106     * relative to true speculative loads. See bug 541079.
107     */
108    inline void InitManifest(const nsAString& aUrl) {
109      NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
110                      "Trying to reinitialize a speculative load!");
111      mOpCode = eSpeculativeLoadManifest;
112      mUrl.Assign(aUrl);
113    }
114
115    /**
116     * "Speculative" charset setting isn't truly speculative. If the charset
117     * is set via this operation, we are committed to it unless chardet or
118     * a late meta cause a reload. The reason why a parser
119     * thread-discovered charset gets communicated via the speculative load
120     * queue as opposed to tree operation queue is that the charset change
121     * must get processed before any actual speculative loads such as style
122     * sheets. Thus, encoding decisions by the parser thread have to maintain
123     * the queue order relative to true speculative loads. See bug 675499.
124     */
125    inline void InitSetDocumentCharset(nsACString& aCharset,
126                                       PRInt32 aCharsetSource) {
127      NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
128                      "Trying to reinitialize a speculative load!");
129      mOpCode = eSpeculativeLoadSetDocumentCharset;
130      CopyUTF8toUTF16(aCharset, mCharsetOrCrossOrigin);
131      mTypeOrCharsetSource.Assign((PRUnichar)aCharsetSource);
132    }
133
134    void Perform(nsHtml5TreeOpExecutor* aExecutor);
135    
136  private:
137    eHtml5SpeculativeLoad mOpCode;
138    nsString mUrl;
139    /**
140     * If mOpCode is eSpeculativeLoadImage, this is the value of the
141     * "crossorigin" attribute.  If mOpCode is eSpeculativeLoadStyle
142     * or eSpeculativeLoadScript then this is the value of the
143     * "charset" attribute. For eSpeculativeLoadSetDocumentCharset it is
144     * the charset that the document's charset is being set to. Otherwise
145     * it's empty.
146     */
147    nsString mCharsetOrCrossOrigin;
148    /**
149     * If mOpCode is eSpeculativeLoadSetDocumentCharset, this is a
150     * one-character string whose single character's code point is to be
151     * interpreted as a charset source integer. Otherwise, it is empty or
152     * the value of the type attribute.
153     */
154    nsString mTypeOrCharsetSource;
155};
156
157#endif // nsHtml5SpeculativeLoad_h_