1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 sw=2 et tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "ContentPrincipal.h"
9 #include "mozIThirdPartyUtil.h"
10 #include "nsContentUtils.h"
12 #include "nsScriptSecurityManager.h"
14 #include "nsReadableUtils.h"
18 #include "nsIStandardURL.h"
19 #include "nsIURIWithSpecialOrigin.h"
20 #include "nsIURIMutator.h"
21 #include "nsJSPrincipals.h"
22 #include "nsIEffectiveTLDService.h"
23 #include "nsIClassInfoImpl.h"
24 #include "nsIObjectInputStream.h"
25 #include "nsIObjectOutputStream.h"
26 #include "nsIProtocolHandler.h"
28 #include "nsIContentSecurityPolicy.h"
30 #include "js/RealmIterators.h"
31 #include "js/Wrapper.h"
33 #include "mozilla/dom/BlobURLProtocolHandler.h"
34 #include "mozilla/dom/ScriptSettings.h"
35 #include "mozilla/ClearOnShutdown.h"
36 #include "mozilla/ExtensionPolicyService.h"
37 #include "mozilla/Preferences.h"
38 #include "mozilla/HashFunctions.h"
40 #include "nsSerializationHelper.h"
41 #include "json/json.h"
43 using namespace mozilla
;
45 static inline ExtensionPolicyService
& EPS() {
46 return ExtensionPolicyService::GetSingleton();
49 NS_IMPL_CLASSINFO(ContentPrincipal
, nullptr, nsIClassInfo::MAIN_THREAD_ONLY
,
51 NS_IMPL_QUERY_INTERFACE_CI(ContentPrincipal
, nsIPrincipal
)
52 NS_IMPL_CI_INTERFACE_GETTER(ContentPrincipal
, nsIPrincipal
)
54 ContentPrincipal::ContentPrincipal(nsIURI
* aURI
,
55 const OriginAttributes
& aOriginAttributes
,
56 const nsACString
& aOriginNoSuffix
)
57 : BasePrincipal(eContentPrincipal
, aOriginNoSuffix
, aOriginAttributes
),
59 #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
60 // Assert that the URI we get here isn't any of the schemes that we know we
61 // should not get here. These schemes always either inherit their principal
62 // or fall back to a null principal. These are schemes which return
63 // URI_INHERITS_SECURITY_CONTEXT from their protocol handler's
64 // GetProtocolFlags function.
66 MOZ_DIAGNOSTIC_ASSERT(
67 NS_SUCCEEDED(NS_URIChainHasFlags(
68 aURI
, nsIProtocolHandler::URI_INHERITS_SECURITY_CONTEXT
, &hasFlag
)) &&
73 ContentPrincipal::ContentPrincipal(ContentPrincipal
* aOther
,
74 const OriginAttributes
& aOriginAttributes
)
75 : BasePrincipal(aOther
, aOriginAttributes
),
77 mDomain(aOther
->mDomain
),
78 mAddon(aOther
->mAddon
) {}
80 ContentPrincipal::~ContentPrincipal() = default;
82 nsresult
ContentPrincipal::GetScriptLocation(nsACString
& aStr
) {
83 return mURI
->GetSpec(aStr
);
87 nsresult
ContentPrincipal::GenerateOriginNoSuffixFromURI(
88 nsIURI
* aURI
, nsACString
& aOriginNoSuffix
) {
90 return NS_ERROR_FAILURE
;
93 nsCOMPtr
<nsIURI
> origin
= NS_GetInnermostURI(aURI
);
95 return NS_ERROR_FAILURE
;
98 MOZ_ASSERT(!NS_IsAboutBlank(origin
),
99 "The inner URI for about:blank must be moz-safe-about:blank");
101 // Handle non-strict file:// uris.
102 if (!nsScriptSecurityManager::GetStrictFileOriginPolicy() &&
103 NS_URIIsLocalFile(origin
)) {
104 // If strict file origin policy is not in effect, all local files are
105 // considered to be same-origin, so return a known dummy origin here.
106 aOriginNoSuffix
.AssignLiteral("file://UNIVERSAL_FILE_URI_ORIGIN");
111 // NB: This is only compiled for Thunderbird/Suite.
112 #if IS_ORIGIN_IS_FULL_SPEC_DEFINED
113 bool fullSpec
= false;
114 rv
= NS_URIChainHasFlags(origin
, nsIProtocolHandler::ORIGIN_IS_FULL_SPEC
,
116 NS_ENSURE_SUCCESS(rv
, rv
);
118 return origin
->GetAsciiSpec(aOriginNoSuffix
);
122 // We want the invariant that prinA.origin == prinB.origin i.f.f.
123 // prinA.equals(prinB). However, this requires that we impose certain
124 // constraints on the behavior and origin semantics of principals, and in
125 // particular, forbid creating origin strings for principals whose equality
126 // constraints are not expressible as strings (i.e. object equality).
127 // Moreover, we want to forbid URIs containing the magic "^" we use as a
128 // separating character for origin attributes.
130 // These constraints can generally be achieved by restricting .origin to
131 // nsIStandardURL-based URIs, but there are a few other URI schemes that we
133 if (origin
->SchemeIs("about") ||
134 (origin
->SchemeIs("moz-safe-about") &&
135 // We generally consider two about:foo origins to be same-origin, but
136 // about:blank is special since it can be generated from different
137 // sources. We check for moz-safe-about:blank since origin is an
139 !StringBeginsWith(origin
->GetSpecOrDefault(),
140 "moz-safe-about:blank"_ns
))) {
141 rv
= origin
->GetAsciiSpec(aOriginNoSuffix
);
142 NS_ENSURE_SUCCESS(rv
, rv
);
144 int32_t pos
= aOriginNoSuffix
.FindChar('?');
145 int32_t hashPos
= aOriginNoSuffix
.FindChar('#');
147 if (hashPos
!= kNotFound
&& (pos
== kNotFound
|| hashPos
< pos
)) {
151 if (pos
!= kNotFound
) {
152 aOriginNoSuffix
.Truncate(pos
);
155 // These URIs could technically contain a '^', but they never should.
156 if (NS_WARN_IF(aOriginNoSuffix
.FindChar('^', 0) != -1)) {
157 aOriginNoSuffix
.Truncate();
158 return NS_ERROR_FAILURE
;
163 // This URL can be a blobURL. In this case, we should use the 'parent'
164 // principal instead.
165 nsCOMPtr
<nsIPrincipal
> blobPrincipal
;
166 if (dom::BlobURLProtocolHandler::GetBlobURLPrincipal(
167 origin
, getter_AddRefs(blobPrincipal
))) {
168 MOZ_ASSERT(blobPrincipal
);
169 return blobPrincipal
->GetOriginNoSuffix(aOriginNoSuffix
);
172 // If we reached this branch, we can only create an origin if we have a
173 // nsIStandardURL. So, we query to a nsIStandardURL, and fail if we aren't
174 // an instance of an nsIStandardURL nsIStandardURLs have the good property
175 // of escaping the '^' character in their specs, which means that we can be
176 // sure that the caret character (which is reserved for delimiting the end
177 // of the spec, and the beginning of the origin attributes) is not present
178 // in the origin string
179 nsCOMPtr
<nsIStandardURL
> standardURL
= do_QueryInterface(origin
);
181 return NS_ERROR_FAILURE
;
184 // See whether we have a useful hostPort. If we do, use that.
185 nsAutoCString hostPort
;
186 if (!origin
->SchemeIs("chrome")) {
187 rv
= origin
->GetAsciiHostPort(hostPort
);
188 NS_ENSURE_SUCCESS(rv
, rv
);
190 if (!hostPort
.IsEmpty()) {
191 rv
= origin
->GetScheme(aOriginNoSuffix
);
192 NS_ENSURE_SUCCESS(rv
, rv
);
193 aOriginNoSuffix
.AppendLiteral("://");
194 aOriginNoSuffix
.Append(hostPort
);
198 rv
= aURI
->GetAsciiSpec(aOriginNoSuffix
);
199 NS_ENSURE_SUCCESS(rv
, rv
);
201 // The origin, when taken from the spec, should not contain the ref part of
204 int32_t pos
= aOriginNoSuffix
.FindChar('?');
205 int32_t hashPos
= aOriginNoSuffix
.FindChar('#');
207 if (hashPos
!= kNotFound
&& (pos
== kNotFound
|| hashPos
< pos
)) {
211 if (pos
!= kNotFound
) {
212 aOriginNoSuffix
.Truncate(pos
);
218 bool ContentPrincipal::SubsumesInternal(
219 nsIPrincipal
* aOther
,
220 BasePrincipal::DocumentDomainConsideration aConsideration
) {
223 // For ContentPrincipal, Subsumes is equivalent to Equals.
224 if (aOther
== this) {
228 // If either the subject or the object has changed its principal by
229 // explicitly setting document.domain then the other must also have
230 // done so in order to be considered the same origin. This prevents
231 // DNS spoofing based on document.domain (154930)
232 if (aConsideration
== ConsiderDocumentDomain
) {
233 // Get .domain on each principal.
234 nsCOMPtr
<nsIURI
> thisDomain
, otherDomain
;
235 GetDomain(getter_AddRefs(thisDomain
));
236 aOther
->GetDomain(getter_AddRefs(otherDomain
));
238 // If either has .domain set, we have equality i.f.f. the domains match.
239 // Otherwise, we fall through to the non-document-domain-considering case.
240 if (thisDomain
|| otherDomain
) {
242 nsScriptSecurityManager::SecurityCompareURIs(thisDomain
, otherDomain
);
245 nsAutoCString thisSiteOrigin
, otherSiteOrigin
;
246 MOZ_ALWAYS_SUCCEEDS(GetSiteOrigin(thisSiteOrigin
));
247 MOZ_ALWAYS_SUCCEEDS(aOther
->GetSiteOrigin(otherSiteOrigin
));
249 thisSiteOrigin
== otherSiteOrigin
,
250 "SubsumesConsideringDomain passed with mismatched siteOrigin!");
258 return aOther
->IsSameOrigin(mURI
);
262 ContentPrincipal::GetURI(nsIURI
** aURI
) {
263 *aURI
= do_AddRef(mURI
).take();
267 bool ContentPrincipal::MayLoadInternal(nsIURI
* aURI
) {
270 #if defined(MOZ_THUNDERBIRD) || defined(MOZ_SUITE)
271 nsCOMPtr
<nsIURIWithSpecialOrigin
> uriWithSpecialOrigin
=
272 do_QueryInterface(aURI
);
273 if (uriWithSpecialOrigin
) {
274 nsCOMPtr
<nsIURI
> origin
;
275 nsresult rv
= uriWithSpecialOrigin
->GetOrigin(getter_AddRefs(origin
));
276 if (NS_WARN_IF(NS_FAILED(rv
))) {
280 OriginAttributes attrs
;
281 RefPtr
<BasePrincipal
> principal
=
282 BasePrincipal::CreateContentPrincipal(origin
, attrs
);
283 return nsIPrincipal::Subsumes(principal
);
287 nsCOMPtr
<nsIPrincipal
> blobPrincipal
;
288 if (dom::BlobURLProtocolHandler::GetBlobURLPrincipal(
289 aURI
, getter_AddRefs(blobPrincipal
))) {
290 MOZ_ASSERT(blobPrincipal
);
291 return nsIPrincipal::Subsumes(blobPrincipal
);
294 // If this principal is associated with an addon, check whether that addon
295 // has been given permission to load from this domain.
296 if (AddonAllowsLoad(aURI
)) {
300 if (nsScriptSecurityManager::SecurityCompareURIs(mURI
, aURI
)) {
304 // If strict file origin policy is in effect, local files will always fail
305 // SecurityCompareURIs unless they are identical. Explicitly check file origin
306 // policy, in that case.
307 if (nsScriptSecurityManager::GetStrictFileOriginPolicy() &&
308 NS_URIIsLocalFile(aURI
) && NS_RelaxStrictFileOriginPolicy(aURI
, mURI
)) {
315 uint32_t ContentPrincipal::GetHashValue() {
316 MOZ_ASSERT(mURI
, "Need a principal URI");
318 nsCOMPtr
<nsIURI
> uri
;
319 GetDomain(getter_AddRefs(uri
));
321 GetURI(getter_AddRefs(uri
));
323 return NS_SecurityHashURI(uri
);
327 ContentPrincipal::GetDomain(nsIURI
** aDomain
) {
333 NS_ADDREF(*aDomain
= mDomain
);
338 ContentPrincipal::SetDomain(nsIURI
* aDomain
) {
342 SetHasExplicitDomain();
344 // Set the changed-document-domain flag on compartments containing realms
345 // using this principal.
346 auto cb
= [](JSContext
*, void*, JS::Realm
* aRealm
,
347 const JS::AutoRequireNoGC
& nogc
) {
348 JS::Compartment
* comp
= JS::GetCompartmentForRealm(aRealm
);
349 xpc::SetCompartmentChangedDocumentDomain(comp
);
351 JSPrincipals
* principals
=
352 nsJSPrincipals::get(static_cast<nsIPrincipal
*>(this));
354 dom::AutoJSAPI jsapi
;
356 JS::IterateRealmsWithPrincipals(jsapi
.cx(), principals
, nullptr, cb
);
361 static nsresult
GetSpecialBaseDomain(const nsCOMPtr
<nsIURI
>& aURI
,
362 bool* aHandled
, nsACString
& aBaseDomain
) {
365 // Special handling for a file URI.
366 if (NS_URIIsLocalFile(aURI
)) {
367 // If strict file origin policy is not in effect, all local files are
368 // considered to be same-origin, so return a known dummy domain here.
369 if (!nsScriptSecurityManager::GetStrictFileOriginPolicy()) {
371 aBaseDomain
.AssignLiteral("UNIVERSAL_FILE_URI_ORIGIN");
375 // Otherwise, we return the file path.
376 nsCOMPtr
<nsIURL
> url
= do_QueryInterface(aURI
);
380 return url
->GetFilePath(aBaseDomain
);
384 bool hasNoRelativeFlag
;
385 nsresult rv
= NS_URIChainHasFlags(aURI
, nsIProtocolHandler::URI_NORELATIVE
,
387 if (NS_WARN_IF(NS_FAILED(rv
))) {
391 // In case of FTP we want to get base domain via TLD service even if FTP
392 // protocol handler is disabled and the scheme is handled by external protocol
393 // handler which returns URI_NORELATIVE flag.
394 if (hasNoRelativeFlag
&& !aURI
->SchemeIs("ftp")) {
396 return aURI
->GetSpec(aBaseDomain
);
399 if (aURI
->SchemeIs("indexeddb")) {
401 return aURI
->GetSpec(aBaseDomain
);
408 ContentPrincipal::GetBaseDomain(nsACString
& aBaseDomain
) {
409 // Handle some special URIs first.
411 nsresult rv
= GetSpecialBaseDomain(mURI
, &handled
, aBaseDomain
);
412 NS_ENSURE_SUCCESS(rv
, rv
);
418 // For everything else, we ask the TLD service via the ThirdPartyUtil.
419 nsCOMPtr
<mozIThirdPartyUtil
> thirdPartyUtil
=
420 do_GetService(THIRDPARTYUTIL_CONTRACTID
);
421 if (!thirdPartyUtil
) {
422 return NS_ERROR_FAILURE
;
425 return thirdPartyUtil
->GetBaseDomain(mURI
, aBaseDomain
);
429 ContentPrincipal::GetSiteOriginNoSuffix(nsACString
& aSiteOrigin
) {
430 nsresult rv
= GetOriginNoSuffix(aSiteOrigin
);
431 NS_ENSURE_SUCCESS(rv
, rv
);
433 // It is possible for two principals with the same origin to have different
434 // mURI values. In order to ensure that two principals with matching origins
435 // also have matching siteOrigins, we derive the siteOrigin entirely from the
436 // origin string and do not rely on mURI at all here.
437 nsCOMPtr
<nsIURI
> origin
;
438 rv
= NS_NewURI(getter_AddRefs(origin
), aSiteOrigin
);
440 // We got an error parsing the origin as a URI? siteOrigin == origin
441 // aSiteOrigin was already filled with `OriginNoSuffix`
445 // Handle some special URIs first.
446 nsAutoCString baseDomain
;
448 rv
= GetSpecialBaseDomain(origin
, &handled
, baseDomain
);
449 NS_ENSURE_SUCCESS(rv
, rv
);
452 // This is a special URI ("file:", "about:", "view-source:", etc). Just
453 // return the origin.
457 // For everything else, we ask the TLD service. Note that, unlike in
458 // GetBaseDomain, we don't use ThirdPartyUtil.getBaseDomain because if the
459 // host is an IP address that returns the raw address and we can't use it with
460 // SetHost below because SetHost expects '[' and ']' around IPv6 addresses.
462 nsCOMPtr
<nsIEffectiveTLDService
> tldService
=
463 do_GetService(NS_EFFECTIVETLDSERVICE_CONTRACTID
);
465 return NS_ERROR_FAILURE
;
468 bool gotBaseDomain
= false;
469 rv
= tldService
->GetBaseDomain(origin
, 0, baseDomain
);
470 if (NS_SUCCEEDED(rv
)) {
471 gotBaseDomain
= true;
473 // If this is an IP address or something like "localhost", we just continue
474 // with gotBaseDomain = false.
475 if (rv
!= NS_ERROR_HOST_IS_IP_ADDRESS
&&
476 rv
!= NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS
) {
481 // NOTE: Calling `SetHostPort` with a portless domain is insufficient to clear
482 // the port, so an extra `SetPort` call has to be made.
483 nsCOMPtr
<nsIURI
> siteUri
;
484 NS_MutateURI
mutator(origin
);
485 mutator
.SetUserPass(""_ns
).SetPort(-1);
487 mutator
.SetHost(baseDomain
);
489 rv
= mutator
.Finalize(siteUri
);
490 MOZ_ASSERT(NS_SUCCEEDED(rv
), "failed to create siteUri");
491 NS_ENSURE_SUCCESS(rv
, rv
);
493 aSiteOrigin
.Truncate();
494 rv
= GenerateOriginNoSuffixFromURI(siteUri
, aSiteOrigin
);
495 MOZ_ASSERT(NS_SUCCEEDED(rv
), "failed to create siteOriginNoSuffix");
499 nsresult
ContentPrincipal::GetSiteIdentifier(SiteIdentifier
& aSite
) {
500 nsCString siteOrigin
;
501 nsresult rv
= GetSiteOrigin(siteOrigin
);
502 NS_ENSURE_SUCCESS(rv
, rv
);
504 RefPtr
<BasePrincipal
> principal
= CreateContentPrincipal(siteOrigin
);
506 NS_WARNING("could not instantiate content principal");
507 return NS_ERROR_FAILURE
;
510 aSite
.Init(principal
);
514 WebExtensionPolicy
* ContentPrincipal::AddonPolicy() {
515 if (!mAddon
.isSome()) {
516 NS_ENSURE_TRUE(mURI
, nullptr);
518 if (mURI
->SchemeIs("moz-extension")) {
519 mAddon
.emplace(EPS().GetByURL(mURI
.get()));
521 mAddon
.emplace(nullptr);
525 return mAddon
.value();
529 ContentPrincipal::GetAddonId(nsAString
& aAddonId
) {
530 auto* policy
= AddonPolicy();
532 policy
->GetId(aAddonId
);
540 ContentPrincipal::Deserializer::Read(nsIObjectInputStream
* aStream
) {
541 MOZ_ASSERT(!mPrincipal
);
543 nsCOMPtr
<nsISupports
> supports
;
544 nsCOMPtr
<nsIURI
> principalURI
;
545 nsresult rv
= NS_ReadOptionalObject(aStream
, true, getter_AddRefs(supports
));
550 principalURI
= do_QueryInterface(supports
);
551 // Enforce re-parsing about: URIs so that if they change, we continue to use
552 // their new principals correctly.
553 if (principalURI
->SchemeIs("about")) {
555 principalURI
->GetSpec(spec
);
556 NS_ENSURE_SUCCESS(NS_NewURI(getter_AddRefs(principalURI
), spec
),
560 nsCOMPtr
<nsIURI
> domain
;
561 rv
= NS_ReadOptionalObject(aStream
, true, getter_AddRefs(supports
));
566 domain
= do_QueryInterface(supports
);
568 nsAutoCString suffix
;
569 rv
= aStream
->ReadCString(suffix
);
570 NS_ENSURE_SUCCESS(rv
, rv
);
572 OriginAttributes attrs
;
573 bool ok
= attrs
.PopulateFromSuffix(suffix
);
574 NS_ENSURE_TRUE(ok
, NS_ERROR_FAILURE
);
576 // Since Bug 965637 we do not serialize the CSP within the
577 // Principal anymore. Nevertheless there might still be
578 // serialized Principals that do have a serialized CSP.
579 // For now, we just read the CSP here but do not actually
580 // consume it. Please note that we deliberately ignore
581 // the return value to avoid CSP deserialization problems.
582 // After Bug 1508939 we will have a new serialization for
583 // Principals which allows us to update the code here.
584 // Additionally, the format for serialized CSPs changed
585 // within Bug 965637 which also can cause failures within
586 // the CSP deserialization code.
587 Unused
<< NS_ReadOptionalObject(aStream
, true, getter_AddRefs(supports
));
589 nsAutoCString originNoSuffix
;
590 rv
= GenerateOriginNoSuffixFromURI(principalURI
, originNoSuffix
);
591 NS_ENSURE_SUCCESS(rv
, rv
);
593 RefPtr
<ContentPrincipal
> principal
=
594 new ContentPrincipal(principalURI
, attrs
, originNoSuffix
);
596 // Note: we don't call SetDomain here because we don't need the wrapper
597 // recomputation code there (we just created this principal).
599 principal
->mDomain
= domain
;
600 principal
->SetHasExplicitDomain();
603 mPrincipal
= principal
.forget();
607 nsresult
ContentPrincipal::PopulateJSONObject(Json::Value
& aObject
) {
608 nsAutoCString principalURI
;
609 nsresult rv
= mURI
->GetSpec(principalURI
);
610 NS_ENSURE_SUCCESS(rv
, rv
);
612 // We turn each int enum field into a JSON string key of the object
613 // aObject is the inner JSON object that has stringified enum keys
614 // An example aObject might be:
618 // {"0": "https://mozilla.com", "2": "^privateBrowsingId=1"}
620 // ----------------------------- |
622 // Key ----------------------
625 aObject
[std::to_string(eURI
)] = principalURI
.get();
628 nsAutoCString domainStr
;
629 rv
= mDomain
->GetSpec(domainStr
);
630 NS_ENSURE_SUCCESS(rv
, rv
);
631 aObject
[std::to_string(eDomain
)] = domainStr
.get();
634 nsAutoCString suffix
;
635 OriginAttributesRef().CreateSuffix(suffix
);
636 if (suffix
.Length() > 0) {
637 aObject
[std::to_string(eSuffix
)] = suffix
.get();
643 already_AddRefed
<BasePrincipal
> ContentPrincipal::FromProperties(
644 nsTArray
<ContentPrincipal::KeyVal
>& aFields
) {
645 MOZ_ASSERT(aFields
.Length() == eMax
+ 1, "Must have all the keys");
647 nsCOMPtr
<nsIURI
> principalURI
;
648 nsCOMPtr
<nsIURI
> domain
;
649 nsCOMPtr
<nsIContentSecurityPolicy
> csp
;
650 OriginAttributes attrs
;
652 // The odd structure here is to make the code to not compile
653 // if all the switch enum cases haven't been codified
654 for (const auto& field
: aFields
) {
656 case ContentPrincipal::eURI
:
657 if (!field
.valueWasSerialized
) {
660 "Content principals require a principal URI in serialized JSON");
663 rv
= NS_NewURI(getter_AddRefs(principalURI
), field
.value
.get());
664 NS_ENSURE_SUCCESS(rv
, nullptr);
667 // Enforce re-parsing about: URIs so that if they change, we
668 // continue to use their new principals correctly.
669 if (principalURI
->SchemeIs("about")) {
671 principalURI
->GetSpec(spec
);
672 if (NS_FAILED(NS_NewURI(getter_AddRefs(principalURI
), spec
))) {
678 case ContentPrincipal::eDomain
:
679 if (field
.valueWasSerialized
) {
680 rv
= NS_NewURI(getter_AddRefs(domain
), field
.value
.get());
681 NS_ENSURE_SUCCESS(rv
, nullptr);
684 case ContentPrincipal::eSuffix
:
685 if (field
.valueWasSerialized
) {
686 bool ok
= attrs
.PopulateFromSuffix(field
.value
);
694 nsAutoCString originNoSuffix
;
695 rv
= ContentPrincipal::GenerateOriginNoSuffixFromURI(principalURI
,
701 RefPtr
<ContentPrincipal
> principal
=
702 new ContentPrincipal(principalURI
, attrs
, originNoSuffix
);
704 principal
->mDomain
= domain
;
705 if (principal
->mDomain
) {
706 principal
->SetHasExplicitDomain();
709 return principal
.forget();