Bug 1416066 - Enable caching for scripts with codebase URLs of about:home, about:newtab, and about:welcome.
MozReview-Commit-ID: HC3cNVxWLe6
--- a/caps/moz.build
+++ b/caps/moz.build
@@ -19,19 +19,22 @@ XPIDL_SOURCES += [
'nsIDomainPolicy.idl',
'nsIPrincipal.idl',
'nsIScriptSecurityManager.idl',
]
XPIDL_MODULE = 'caps'
EXPORTS += [
+ 'ContentPrincipal.h',
'nsJSPrincipals.h',
+ 'nsScriptSecurityManager.h',
'NullPrincipal.h',
'NullPrincipalURI.h',
+ 'SystemPrincipal.h',
]
EXPORTS.mozilla = [
'BasePrincipal.h',
'OriginAttributes.h',
]
SOURCES += [
--- a/js/xpconnect/loader/mozJSSubScriptLoader.cpp
+++ b/js/xpconnect/loader/mozJSSubScriptLoader.cpp
@@ -10,16 +10,18 @@
#include "nsIURI.h"
#include "nsIIOService.h"
#include "nsIChannel.h"
#include "nsIInputStream.h"
#include "nsNetCID.h"
#include "nsNetUtil.h"
#include "nsIFileURL.h"
+#include "ContentPrincipal.h"
+#include "SystemPrincipal.h"
#include "jsapi.h"
#include "jsfriendapi.h"
#include "xpcprivate.h" // For xpc::OptionsBase
#include "js/Wrapper.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/ToJSValue.h"
@@ -685,19 +687,37 @@ mozJSSubScriptLoader::DoLoadSubScriptWit
tmp.AppendLiteral(" -> ");
tmp.Append(uriStr);
uriStr = tmp;
}
// Suppress caching if we're compiling as content or if we're loading a
// blob: URI.
- bool ignoreCache = options.ignoreCache
- || !GetObjectPrincipal(targetObj)->GetIsSystemPrincipal()
- || scheme.EqualsLiteral("blob");
+ auto* principal = BasePrincipal::Cast(GetObjectPrincipal(targetObj));
+ bool isSystem = principal->Is<SystemPrincipal>();
+ if (!isSystem && principal->Is<ContentPrincipal>()) {
+ auto* content = principal->As<ContentPrincipal>();
+
+ nsAutoCString scheme;
+ content->mCodebase->GetScheme(scheme);
+
+ // We want to enable caching for scripts with Activity Stream's
+ // codebase URLs.
+ if (scheme.EqualsLiteral("about")) {
+ nsAutoCString filePath;
+ content->mCodebase->GetFilePath(filePath);
+
+ isSystem = filePath.EqualsLiteral("home") ||
+ filePath.EqualsLiteral("newtab") ||
+ filePath.EqualsLiteral("welcome");
+ }
+ }
+ bool ignoreCache = options.ignoreCache || !isSystem || scheme.EqualsLiteral("blob");
+
StartupCache* cache = ignoreCache ? nullptr : StartupCache::GetSingleton();
nsAutoCString cachePath;
SubscriptCachePath(cx, uri, targetObj, cachePath);
RootedScript script(cx);
if (!options.ignoreCache) {
if (!options.wantReturnValue)