nsJSProtocolHandler.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  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. #ifndef nsJSProtocolHandler_h___
  6. #define nsJSProtocolHandler_h___
  7. #include "mozilla/Attributes.h"
  8. #include "nsIProtocolHandler.h"
  9. #include "nsITextToSubURI.h"
  10. #include "nsIURI.h"
  11. #include "nsIMutable.h"
  12. #include "nsISerializable.h"
  13. #include "nsIClassInfo.h"
  14. #include "nsSimpleURI.h"
  15. #define NS_JSPROTOCOLHANDLER_CID \
  16. { /* bfc310d2-38a0-11d3-8cd3-0060b0fc14a3 */ \
  17. 0xbfc310d2, \
  18. 0x38a0, \
  19. 0x11d3, \
  20. {0x8c, 0xd3, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \
  21. }
  22. #define NS_JSURI_CID \
  23. { /* 58f089ee-512a-42d2-a935-d0c874128930 */ \
  24. 0x58f089ee, \
  25. 0x512a, \
  26. 0x42d2, \
  27. {0xa9, 0x35, 0xd0, 0xc8, 0x74, 0x12, 0x89, 0x30} \
  28. }
  29. #define NS_JSPROTOCOLHANDLER_CONTRACTID \
  30. NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "javascript"
  31. class nsJSProtocolHandler : public nsIProtocolHandler
  32. {
  33. public:
  34. NS_DECL_ISUPPORTS
  35. // nsIProtocolHandler methods:
  36. NS_DECL_NSIPROTOCOLHANDLER
  37. // nsJSProtocolHandler methods:
  38. nsJSProtocolHandler();
  39. static nsresult
  40. Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
  41. nsresult Init();
  42. protected:
  43. virtual ~nsJSProtocolHandler();
  44. nsresult EnsureUTF8Spec(const nsAFlatCString &aSpec, const char *aCharset,
  45. nsACString &aUTF8Spec);
  46. nsCOMPtr<nsITextToSubURI> mTextToSubURI;
  47. };
  48. class nsJSURI : public mozilla::net::nsSimpleURI
  49. {
  50. public:
  51. using mozilla::net::nsSimpleURI::Read;
  52. using mozilla::net::nsSimpleURI::Write;
  53. nsJSURI() {}
  54. explicit nsJSURI(nsIURI* aBaseURI) : mBaseURI(aBaseURI) {}
  55. nsIURI* GetBaseURI() const
  56. {
  57. return mBaseURI;
  58. }
  59. NS_DECL_ISUPPORTS_INHERITED
  60. // nsIURI overrides
  61. virtual mozilla::net::nsSimpleURI* StartClone(RefHandlingEnum refHandlingMode,
  62. const nsACString& newRef) override;
  63. // nsISerializable overrides
  64. NS_IMETHOD Read(nsIObjectInputStream* aStream) override;
  65. NS_IMETHOD Write(nsIObjectOutputStream* aStream) override;
  66. // nsIIPCSerializableURI overrides
  67. NS_DECL_NSIIPCSERIALIZABLEURI
  68. // Override the nsIClassInfo method GetClassIDNoAlloc to make sure our
  69. // nsISerializable impl works right.
  70. NS_IMETHOD GetClassIDNoAlloc(nsCID *aClassIDNoAlloc) override;
  71. //NS_IMETHOD QueryInterface( const nsIID& aIID, void** aInstancePtr );
  72. protected:
  73. virtual ~nsJSURI() {}
  74. virtual nsresult EqualsInternal(nsIURI* other,
  75. RefHandlingEnum refHandlingMode,
  76. bool* result) override;
  77. private:
  78. nsCOMPtr<nsIURI> mBaseURI;
  79. };
  80. #endif /* nsJSProtocolHandler_h___ */