1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 * 3 * This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_image_decoders_icon_nsIconURI_h 8 #define mozilla_image_decoders_icon_nsIconURI_h 9 10 #include "nsIIconURI.h" 11 #include "nsCOMPtr.h" 12 #include "nsString.h" 13 #include "nsINestedURI.h" 14 #include "nsIURIMutator.h" 15 #include "nsISerializable.h" 16 17 #define NS_THIS_ICONURI_IMPLEMENTATION_CID \ 18 { /* 0b9bb0c2-fee6-470b-b9b9-9fd9462b5e19 */ \ 19 0x5c3e417f, 0xb686, 0x4105, { \ 20 0x86, 0xe7, 0xf9, 0x1b, 0xac, 0x97, 0x4d, 0x5c \ 21 } \ 22 } 23 24 namespace mozilla { 25 class Encoding; 26 } 27 28 class nsMozIconURI final : public nsIMozIconURI, 29 public nsINestedURI, 30 public nsISerializable { 31 public: 32 NS_DECL_THREADSAFE_ISUPPORTS 33 NS_DECL_NSIURI 34 NS_DECL_NSIMOZICONURI 35 NS_DECL_NSINESTEDURI 36 NS_DECL_NSISERIALIZABLE 37 38 protected: 39 nsMozIconURI(); 40 virtual ~nsMozIconURI(); 41 nsCOMPtr<nsIURL> mIconURL; // a URL that we want the icon for 42 uint32_t mSize; // the # of pixels in a row that we want for this image. 43 // Typically 16, 32, 128, etc. 44 nsCString mContentType; // optional field explicitly specifying the content 45 // type 46 nsCString mFileName; // for if we don't have an actual file path, we're just 47 // given a filename with an extension 48 nsCString mStockIcon; 49 int32_t mIconSize; // -1 if not specified, otherwise index into 50 // kSizeStrings 51 int32_t mIconState; // -1 if not specified, otherwise index into 52 // kStateStrings 53 54 private: 55 nsresult Clone(nsIURI** aURI); 56 nsresult SetSpecInternal(const nsACString& input); 57 nsresult SetScheme(const nsACString& input); 58 nsresult SetUserPass(const nsACString& input); 59 nsresult SetUsername(const nsACString& input); 60 nsresult SetPassword(const nsACString& input); 61 nsresult SetHostPort(const nsACString& aValue); 62 nsresult SetHost(const nsACString& input); 63 nsresult SetPort(int32_t port); 64 nsresult SetPathQueryRef(const nsACString& input); 65 nsresult SetRef(const nsACString& input); 66 nsresult SetFilePath(const nsACString& input); 67 nsresult SetQuery(const nsACString& input); 68 nsresult SetQueryWithEncoding(const nsACString& input, 69 const mozilla::Encoding* encoding); 70 nsresult ReadPrivate(nsIObjectInputStream* stream); 71 bool Deserialize(const mozilla::ipc::URIParams&); 72 73 public: 74 class Mutator final : public nsIURIMutator, 75 public BaseURIMutator<nsMozIconURI>, 76 public nsISerializable { 77 NS_DECL_ISUPPORTS NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI)78 NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI) 79 80 NS_IMETHOD 81 Write(nsIObjectOutputStream* aOutputStream) override { 82 return NS_ERROR_NOT_IMPLEMENTED; 83 } 84 Read(nsIObjectInputStream * aStream)85 [[nodiscard]] NS_IMETHOD Read(nsIObjectInputStream* aStream) override { 86 return InitFromInputStream(aStream); 87 } 88 Deserialize(const mozilla::ipc::URIParams & aParams)89 NS_IMETHOD Deserialize(const mozilla::ipc::URIParams& aParams) override { 90 return InitFromIPCParams(aParams); 91 } 92 Finalize(nsIURI ** aURI)93 NS_IMETHOD Finalize(nsIURI** aURI) override { 94 mURI.forget(aURI); 95 return NS_OK; 96 } 97 SetSpec(const nsACString & aSpec,nsIURIMutator ** aMutator)98 NS_IMETHOD SetSpec(const nsACString& aSpec, 99 nsIURIMutator** aMutator) override { 100 if (aMutator) { 101 nsCOMPtr<nsIURIMutator> mutator = this; 102 mutator.forget(aMutator); 103 } 104 return InitFromSpec(aSpec); 105 } 106 Mutator()107 explicit Mutator() {} 108 109 private: ~Mutator()110 virtual ~Mutator() {} 111 112 friend class nsMozIconURI; 113 }; 114 115 friend BaseURIMutator<nsMozIconURI>; 116 }; 117 118 #endif // mozilla_image_decoders_icon_nsIconURI_h 119