ScriptLoadHandler.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. /*
  6. * A class that handles loading and evaluation of <script> elements.
  7. */
  8. #ifndef mozilla_dom_ScriptLoadHandler_h
  9. #define mozilla_dom_ScriptLoadHandler_h
  10. #include "nsIIncrementalStreamLoader.h"
  11. #include "nsIUnicodeDecoder.h"
  12. #include "nsAutoPtr.h"
  13. #include "mozilla/Vector.h"
  14. namespace mozilla {
  15. namespace dom {
  16. class ScriptLoadRequest;
  17. class ScriptLoader;
  18. class SRICheckDataVerifier;
  19. class ScriptLoadHandler final : public nsIIncrementalStreamLoaderObserver
  20. {
  21. public:
  22. explicit ScriptLoadHandler(ScriptLoader* aScriptLoader,
  23. ScriptLoadRequest* aRequest,
  24. SRICheckDataVerifier* aSRIDataVerifier);
  25. NS_DECL_ISUPPORTS
  26. NS_DECL_NSIINCREMENTALSTREAMLOADEROBSERVER
  27. private:
  28. virtual ~ScriptLoadHandler();
  29. /*
  30. * Try to decode some raw data.
  31. */
  32. nsresult TryDecodeRawData(const uint8_t* aData, uint32_t aDataLength,
  33. bool aEndOfStream);
  34. /*
  35. * Discover the charset by looking at the stream data, the script
  36. * tag, and other indicators. Returns true if charset has been
  37. * discovered.
  38. */
  39. bool EnsureDecoder(nsIIncrementalStreamLoader *aLoader,
  40. const uint8_t* aData, uint32_t aDataLength,
  41. bool aEndOfStream);
  42. // ScriptLoader which will handle the parsed script.
  43. RefPtr<ScriptLoader> mScriptLoader;
  44. // The ScriptLoadRequest for this load.
  45. RefPtr<ScriptLoadRequest> mRequest;
  46. // SRI data verifier.
  47. nsAutoPtr<SRICheckDataVerifier> mSRIDataVerifier;
  48. // Status of SRI data operations.
  49. nsresult mSRIStatus;
  50. // Unicode decoder for charset.
  51. nsCOMPtr<nsIUnicodeDecoder> mDecoder;
  52. // Accumulated decoded char buffer.
  53. mozilla::Vector<char16_t> mBuffer;
  54. };
  55. } // namespace dom
  56. } // namespace mozilla
  57. #endif //mozilla_dom_ScriptLoader_h