Bug 1186732 - Implement an about:blank page inside of moz-extension. r=billm

This commit is contained in:
Bobby Holley 2015-07-28 17:04:06 -07:00
Родитель 2acaa47690
Коммит 5da44c2396
4 изменённых файлов: 39 добавлений и 5 удалений

Просмотреть файл

@ -89,10 +89,18 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1161831
ifr.onload = function() {
ok(true, 'Loaded ' + url);
var prin = SpecialPowers.wrap(ifr.contentWindow).document.nodePrincipal;
is(prin.originNoSuffix, url, 'Principal origin is correct: ' + url);
function stripTrailingSlash(s) { return s.replace(/\/$/, ''); };
is(stripTrailingSlash(prin.URI.spec), url, 'Principal uri is correct: ' + url);
function stripPath(s) { return s.replace(/(.*\/\/.+)\/.*/, '$1'); };
is(prin.originNoSuffix, stripPath(url), 'Principal origin is correct: ' + prin.originNoSuffix);
is(prin.originAttributes.addonId, 'imaginaryaddon-' + url[url.indexOf('/') + 2], 'addonId is correct');
is(SpecialPowers.wrap(ifr.contentWindow).document.title, 'resource test file',
'document looks right');
if (/_blank/.test(url)) {
is(SpecialPowers.wrap(ifr.contentWindow).document.documentElement.innerHTML,
'<head></head><body></body>', 'blank document looks right');
} else {
is(SpecialPowers.wrap(ifr.contentWindow).document.title, 'resource test file',
'document looks right');
}
ifr.remove();
resolve();
};
@ -126,6 +134,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1161831
.then(testLoad.bind(null, 'moz-extension://liebchen', navigateWithLocation))
.then(testLoad.bind(null, 'moz-extension://liebchen', navigateWithSrc))
.then(testLoad.bind(null, 'moz-extension://cherise', navigateWithSrc))
.then(testLoad.bind(null, 'moz-extension://cherise/_blank.html', navigateWithSrc))
.then(SimpleTest.finish.bind(SimpleTest),
function(e) { ok(false, "rejected promise: " + e); SimpleTest.finish() }
);

Просмотреть файл

@ -26,6 +26,19 @@ public:
protected:
~ExtensionProtocolHandler() {}
bool ResolveSpecialCases(const nsACString& aHost, const nsACString& aPath, nsACString& aResult) override
{
// Create a special about:blank-like moz-extension://foo/_blank.html for all
// registered extensions. We can't just do this as a substitution because
// substitutions can only match on host.
if (SubstitutingProtocolHandler::HasSubstitution(aHost) && aPath.EqualsLiteral("/_blank.html")) {
aResult.AssignLiteral("about:blank");
return true;
}
return false;
}
};
} // namespace mozilla

Просмотреть файл

@ -347,8 +347,7 @@ nsresult
SubstitutingProtocolHandler::HasSubstitution(const nsACString& root, bool *result)
{
NS_ENSURE_ARG_POINTER(result);
*result = mSubstitutions.Get(root, nullptr);
*result = HasSubstitution(root);
return NS_OK;
}
@ -366,6 +365,10 @@ SubstitutingProtocolHandler::ResolveURI(nsIURI *uri, nsACString &result)
rv = uri->GetPath(path);
if (NS_FAILED(rv)) return rv;
if (ResolveSpecialCases(host, path, result)) {
return NS_OK;
}
// Unescape the path so we can perform some checks on it.
nsAutoCString unescapedPath(path);
NS_UnescapeURL(unescapedPath);

Просмотреть файл

@ -34,6 +34,8 @@ public:
NS_DECL_NON_VIRTUAL_NSIPROTOCOLHANDLER;
NS_DECL_NON_VIRTUAL_NSISUBSTITUTINGPROTOCOLHANDLER;
bool HasSubstitution(const nsACString& aRoot) const { return mSubstitutions.Get(aRoot, nullptr); }
void CollectSubstitutions(InfallibleTArray<SubstitutionMapping>& aResources);
protected:
@ -50,6 +52,13 @@ protected:
return NS_ERROR_NOT_AVAILABLE;
}
// Override this in the subclass to check for special case when resolving URIs
// _before_ checking substitutions.
virtual bool ResolveSpecialCases(const nsACString& aHost, const nsACString& aPath, nsACString& aResult)
{
return false;
}
nsIIOService* IOService() { return mIOService; }
private: