Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit b136b1f

Browse files
committed
Bug 1383215: Part 2 - Split out URI resolution code into ResolveURI helper. r=mccr8
MozReview-Commit-ID: Bfr67WQPq9l --HG-- extra : rebase_source : bbf9090d03c15d6c541aec12b090ab4dadcdab68 extra : histedit_source : 68a54268e601c1cb7521abb305fad2288ab4a03a
1 parent 8f64552 commit b136b1f

2 files changed

Lines changed: 50 additions & 33 deletions

File tree

startupcache/StartupCacheUtils.cpp

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -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) {

startupcache/StartupCacheUtils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ nsresult
3838
NewBufferFromStorageStream(nsIStorageStream *storageStream,
3939
UniquePtr<char[]>* buffer, uint32_t* len);
4040

41+
nsresult
42+
ResolveURI(nsIURI *in, nsIURI **out);
43+
4144
nsresult
4245
PathifyURI(nsIURI *in, nsACString &out);
4346
} // namespace scache

0 commit comments

Comments
 (0)