/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. #ifndef nsHtml5SpeculativeLoad_h_
  38. #define nsHtml5SpeculativeLoad_h_
  39. #include "nsString.h"
  40. class nsHtml5TreeOpExecutor;
  41. enum eHtml5SpeculativeLoad {
  42. #ifdef DEBUG
  43. eSpeculativeLoadUninitialized,
  44. #endif
  45. eSpeculativeLoadBase,
  46. eSpeculativeLoadImage,
  47. eSpeculativeLoadScript,
  48. eSpeculativeLoadStyle,
  49. eSpeculativeLoadManifest,
  50. eSpeculativeLoadSetDocumentCharset
  51. };
  52. class nsHtml5SpeculativeLoad {
  53. public:
  54. nsHtml5SpeculativeLoad();
  55. ~nsHtml5SpeculativeLoad();
  56. inline void InitBase(const nsAString& aUrl) {
  57. NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
  58. "Trying to reinitialize a speculative load!");
  59. mOpCode = eSpeculativeLoadBase;
  60. mUrl.Assign(aUrl);
  61. }
  62. inline void InitImage(const nsAString& aUrl,
  63. const nsAString& aCrossOrigin) {
  64. NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
  65. "Trying to reinitialize a speculative load!");
  66. mOpCode = eSpeculativeLoadImage;
  67. mUrl.Assign(aUrl);
  68. mCharsetOrCrossOrigin.Assign(aCrossOrigin);
  69. }
  70. inline void InitScript(const nsAString& aUrl,
  71. const nsAString& aCharset,
  72. const nsAString& aType) {
  73. NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
  74. "Trying to reinitialize a speculative load!");
  75. mOpCode = eSpeculativeLoadScript;
  76. mUrl.Assign(aUrl);
  77. mCharsetOrCrossOrigin.Assign(aCharset);
  78. mTypeOrCharsetSource.Assign(aType);
  79. }
  80. inline void InitStyle(const nsAString& aUrl, const nsAString& aCharset) {
  81. NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
  82. "Trying to reinitialize a speculative load!");
  83. mOpCode = eSpeculativeLoadStyle;
  84. mUrl.Assign(aUrl);
  85. mCharsetOrCrossOrigin.Assign(aCharset);
  86. }
  87. /**
  88. * "Speculative" manifest loads aren't truly speculative--if a manifest
  89. * gets loaded, we are committed to it. There can never be a <script>
  90. * before the manifest, so the situation of having to undo a manifest due
  91. * to document.write() never arises. The reason why a parser
  92. * thread-discovered manifest gets loaded via the speculative load queue
  93. * as opposed to tree operation queue is that the manifest must get
  94. * processed before any actual speculative loads such as scripts. Thus,
  95. * manifests seen by the parser thread have to maintain the queue order
  96. * relative to true speculative loads. See bug 541079.
  97. */
  98. inline void InitManifest(const nsAString& aUrl) {
  99. NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
  100. "Trying to reinitialize a speculative load!");
  101. mOpCode = eSpeculativeLoadManifest;
  102. mUrl.Assign(aUrl);
  103. }
  104. /**
  105. * "Speculative" charset setting isn't truly speculative. If the charset
  106. * is set via this operation, we are committed to it unless chardet or
  107. * a late meta cause a reload. The reason why a parser
  108. * thread-discovered charset gets communicated via the speculative load
  109. * queue as opposed to tree operation queue is that the charset change
  110. * must get processed before any actual speculative loads such as style
  111. * sheets. Thus, encoding decisions by the parser thread have to maintain
  112. * the queue order relative to true speculative loads. See bug 675499.
  113. */
  114. inline void InitSetDocumentCharset(nsACString& aCharset,
  115. PRInt32 aCharsetSource) {
  116. NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
  117. "Trying to reinitialize a speculative load!");
  118. mOpCode = eSpeculativeLoadSetDocumentCharset;
  119. CopyUTF8toUTF16(aCharset, mCharsetOrCrossOrigin);
  120. mTypeOrCharsetSource.Assign((PRUnichar)aCharsetSource);
  121. }
  122. void Perform(nsHtml5TreeOpExecutor* aExecutor);
  123. private:
  124. eHtml5SpeculativeLoad mOpCode;
  125. nsString mUrl;
  126. /**
  127. * If mOpCode is eSpeculativeLoadImage, this is the value of the
  128. * "crossorigin" attribute. If mOpCode is eSpeculativeLoadStyle
  129. * or eSpeculativeLoadScript then this is the value of the
  130. * "charset" attribute. For eSpeculativeLoadSetDocumentCharset it is
  131. * the charset that the document's charset is being set to. Otherwise
  132. * it's empty.
  133. */
  134. nsString mCharsetOrCrossOrigin;
  135. /**
  136. * If mOpCode is eSpeculativeLoadSetDocumentCharset, this is a
  137. * one-character string whose single character's code point is to be
  138. * interpreted as a charset source integer. Otherwise, it is empty or
  139. * the value of the type attribute.
  140. */
  141. nsString mTypeOrCharsetSource;
  142. };
  143. #endif // nsHtml5SpeculativeLoad_h_