diff --git a/modules/libjar/nsIJARURI.idl b/modules/libjar/nsIJARURI.idl index bbbfe9c45418..3b61c610345b 100644 --- a/modules/libjar/nsIJARURI.idl +++ b/modules/libjar/nsIJARURI.idl @@ -36,3 +36,12 @@ interface nsIJARURI : nsIURL { */ nsIJARURI cloneWithJARFile(in nsIURI jarFile); }; + +[builtinclass, uuid(d66df117-eda7-4324-b4e4-1f670ff6718e)] +interface nsIJARURIMutator : nsISupports +{ + /** + * Will initalize a URI using the passed spec, baseURI and charset. + */ + void setSpecBaseCharset(in AUTF8String aSpec, in nsIURI aBase, in string aCharset); +}; diff --git a/modules/libjar/nsJARProtocolHandler.cpp b/modules/libjar/nsJARProtocolHandler.cpp index f6f3e47deed6..41bfcb7489e1 100644 --- a/modules/libjar/nsJARProtocolHandler.cpp +++ b/modules/libjar/nsJARProtocolHandler.cpp @@ -118,21 +118,11 @@ nsJARProtocolHandler::NewURI(const nsACString &aSpec, nsIURI *aBaseURI, nsIURI **result) { - nsresult rv = NS_OK; - - RefPtr jarURI = new nsJARURI(); - if (!jarURI) - return NS_ERROR_OUT_OF_MEMORY; - - rv = jarURI->Init(aCharset); - NS_ENSURE_SUCCESS(rv, rv); - - rv = jarURI->SetSpecWithBase(aSpec, aBaseURI); - if (NS_FAILED(rv)) - return rv; - - NS_ADDREF(*result = jarURI); - return rv; + nsCOMPtr base(aBaseURI); + return NS_MutateURI(new nsJARURI::Mutator()) + .Apply(NS_MutatorMethod(&nsIJARURIMutator::SetSpecBaseCharset, + nsCString(aSpec), base, aCharset)) + .Finalize(result); } NS_IMETHODIMP diff --git a/modules/libjar/nsJARURI.cpp b/modules/libjar/nsJARURI.cpp index 242854d4b48d..0382cf51937c 100644 --- a/modules/libjar/nsJARURI.cpp +++ b/modules/libjar/nsJARURI.cpp @@ -268,7 +268,8 @@ NS_IMPL_NSIURIMUTATOR_ISUPPORTS(nsJARURI::Mutator, nsIURISetters, nsIURIMutator, nsIURLMutator, - nsISerializable) + nsISerializable, + nsIJARURIMutator) NS_IMETHODIMP nsJARURI::Mutator::SetFileName(const nsACString& aFileName, nsIURIMutator** aMutator) diff --git a/modules/libjar/nsJARURI.h b/modules/libjar/nsJARURI.h index 8669bf13ac9f..942f7cd493db 100644 --- a/modules/libjar/nsJARURI.h +++ b/modules/libjar/nsJARURI.h @@ -59,19 +59,18 @@ public: NS_DECLARE_STATIC_IID_ACCESSOR(NS_THIS_JARURI_IMPL_CID) // nsJARURI - nsJARURI(); - - nsresult Init(const char *charsetHint); nsresult FormatSpec(const nsACString &entryPath, nsACString &result, bool aIncludeScheme = true); nsresult CreateEntryURL(const nsACString& entryFilename, const char* charset, nsIURL** url); - nsresult SetSpecWithBase(const nsACString& aSpec, nsIURI* aBaseURL); protected: + nsJARURI(); virtual ~nsJARURI(); nsresult SetJAREntry(const nsACString &entryPath); + nsresult Init(const char *charsetHint); + nsresult SetSpecWithBase(const nsACString& aSpec, nsIURI* aBaseURL); // enum used in a few places to specify how .ref attribute should be handled enum RefHandlingEnum { @@ -126,6 +125,7 @@ public: , public BaseURIMutator , public nsIURLMutator , public nsISerializable + , public nsIJARURIMutator { NS_DECL_ISUPPORTS NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI) @@ -144,6 +144,30 @@ public: return InitFromInputStream(aStream); } + NS_IMETHOD + SetSpecBaseCharset(const nsACString& aSpec, + nsIURI* aBaseURI, + const char* aCharset) override + { + RefPtr uri; + if (mURI) { + mURI.swap(uri); + } else { + uri = new nsJARURI(); + } + + nsresult rv = uri->Init(aCharset); + NS_ENSURE_SUCCESS(rv, rv); + + rv = uri->SetSpecWithBase(aSpec, aBaseURI); + if (NS_FAILED(rv)) { + return rv; + } + + mURI.swap(uri); + return NS_OK; + } + explicit Mutator() { } private: virtual ~Mutator() { }