@@ -145,6 +145,47 @@ canonicalizeBase(nsAutoCString &spec,
145145 return true ;
146146}
147147
148+ /* *
149+ * ResolveURI transforms a chrome: or resource: URI into the URI for its
150+ * underlying resource, or returns any other URI unchanged.
151+ */
152+ nsresult
153+ ResolveURI (nsIURI *in, nsIURI **out)
154+ {
155+ bool equals;
156+ nsresult rv;
157+
158+ // Resolve resource:// URIs. At the end of this if/else block, we
159+ // have both spec and uri variables identifying the same URI.
160+ if (NS_SUCCEEDED (in->SchemeIs (" resource" , &equals)) && equals) {
161+ nsCOMPtr<nsIIOService> ioService = do_GetIOService (&rv);
162+ NS_ENSURE_SUCCESS (rv, rv);
163+
164+ nsCOMPtr<nsIProtocolHandler> ph;
165+ rv = ioService->GetProtocolHandler (" resource" , getter_AddRefs (ph));
166+ NS_ENSURE_SUCCESS (rv, rv);
167+
168+ nsCOMPtr<nsIResProtocolHandler> irph (do_QueryInterface (ph, &rv));
169+ NS_ENSURE_SUCCESS (rv, rv);
170+
171+ nsAutoCString spec;
172+ rv = irph->ResolveURI (in, spec);
173+ NS_ENSURE_SUCCESS (rv, rv);
174+
175+ return ioService->NewURI (spec, nullptr , nullptr , out);
176+ } else if (NS_SUCCEEDED (in->SchemeIs (" chrome" , &equals)) && equals) {
177+ nsCOMPtr<nsIChromeRegistry> chromeReg =
178+ mozilla::services::GetChromeRegistryService ();
179+ if (!chromeReg)
180+ return NS_ERROR_UNEXPECTED ;
181+
182+ return chromeReg->ConvertChromeURL (in, out);
183+ }
184+
185+ *out = do_AddRef (in).take ();
186+ return NS_OK ;
187+ }
188+
148189/* *
149190 * PathifyURI transforms uris into useful zip paths
150191 * to make it easier to manipulate startup cache entries
@@ -175,41 +216,14 @@ PathifyURI(nsIURI *in, nsACString &out)
175216{
176217 bool equals;
177218 nsresult rv;
178- nsCOMPtr<nsIURI> uri = in;
179- nsAutoCString spec;
180-
181- // Resolve resource:// URIs. At the end of this if/else block, we
182- // have both spec and uri variables identifying the same URI.
183- if (NS_SUCCEEDED (in->SchemeIs (" resource" , &equals)) && equals) {
184- nsCOMPtr<nsIIOService> ioService = do_GetIOService (&rv);
185- NS_ENSURE_SUCCESS (rv, rv);
186-
187- nsCOMPtr<nsIProtocolHandler> ph;
188- rv = ioService->GetProtocolHandler (" resource" , getter_AddRefs (ph));
189- NS_ENSURE_SUCCESS (rv, rv);
190219
191- nsCOMPtr<nsIResProtocolHandler> irph (do_QueryInterface (ph, &rv));
192- NS_ENSURE_SUCCESS (rv, rv);
220+ nsCOMPtr<nsIURI> uri;
221+ rv = ResolveURI (in, getter_AddRefs (uri));
222+ NS_ENSURE_SUCCESS (rv, rv);
193223
194- rv = irph->ResolveURI (in, spec);
195- NS_ENSURE_SUCCESS (rv, rv);
196-
197- rv = ioService->NewURI (spec, nullptr , nullptr , getter_AddRefs (uri));
198- NS_ENSURE_SUCCESS (rv, rv);
199- } else {
200- if (NS_SUCCEEDED (in->SchemeIs (" chrome" , &equals)) && equals) {
201- nsCOMPtr<nsIChromeRegistry> chromeReg =
202- mozilla::services::GetChromeRegistryService ();
203- if (!chromeReg)
204- return NS_ERROR_UNEXPECTED ;
205-
206- rv = chromeReg->ConvertChromeURL (in, getter_AddRefs (uri));
207- NS_ENSURE_SUCCESS (rv, rv);
208- }
209-
210- rv = uri->GetSpec (spec);
211- NS_ENSURE_SUCCESS (rv, rv);
212- }
224+ nsAutoCString spec;
225+ rv = uri->GetSpec (spec);
226+ NS_ENSURE_SUCCESS (rv, rv);
213227
214228 if (!canonicalizeBase (spec, out)) {
215229 if (NS_SUCCEEDED (uri->SchemeIs (" file" , &equals)) && equals) {
0 commit comments