Closed Bug 1335890 Opened 7 years ago Closed 7 years ago

Factor out getting to the Principal from JSContext

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla54
Tracking Status
firefox54 --- fixed

People

(Reporter: zombie, Assigned: zombie)

Details

Attachments

(1 file)

If I understood Boris's comment in bug 1310318 comment #17, this is something we should do.
I can probably take this next week, provided my understanding above is correct.
Comment on attachment 8833810 [details]
Bug 1335890 - Factor out nsContentUtils::SubjectPrincipal version that takes JSContext

https://reviewboard.mozilla.org/r/109948/#review111068

::: dom/base/nsContentUtils.cpp:2818
(Diff revision 1)
>    //
>    // So we use a singleton null principal. To avoid it being accidentally
>    // inherited and becoming a "real" subject or object principal, we do a
>    // release-mode assert during compartment creation against using this
>    // principal on an actual global.
>    if (!compartment) {

This is my best guess at what each version of SubjectPrincipal() should do.  Because of the big comment wall above, this still returns a NullPrincipal without a compartment, even if it marely calls the other version when the JSContext has a compartment (since it requires one).
Attachment #8833810 - Flags: review?(bzbarsky)
Hope this is what you had in mind for a followup Boris?
Assignee: nobody → tomica
Status: NEW → ASSIGNED
Comment on attachment 8833810 [details]
Bug 1335890 - Factor out nsContentUtils::SubjectPrincipal version that takes JSContext

https://reviewboard.mozilla.org/r/109948/#review111184

r=me with the one nit below.  Thank you!

::: dom/base/nsContentUtils.cpp:2082
(Diff revision 1)
>  
>  // static
>  bool
>  nsContentUtils::CallerHasPermission(JSContext* aCx, const nsAString& aPerm)
>  {
>    // Chrome gets access by default.

So I think we should just make CallerHasPermission call PrincipalHasPermission(SubjectPrincipal(aCx)), and we should add such a PrincipalHasPermission.

Then we can also call that from nsContentUtils::IsCutCopyAllowed.
Attachment #8833810 - Flags: review?(bzbarsky) → review+
Comment on attachment 8833810 [details]
Bug 1335890 - Factor out nsContentUtils::SubjectPrincipal version that takes JSContext

https://reviewboard.mozilla.org/r/109948/#review111198

::: dom/base/nsContentUtils.cpp:2082
(Diff revision 1)
>  
>  // static
>  bool
>  nsContentUtils::CallerHasPermission(JSContext* aCx, const nsAString& aPerm)
>  {
>    // Chrome gets access by default.

I meant to do that in the next bug 1312260, where I'll actually need PrincipalHasPermission().
Keywords: checkin-needed
> I meant to do that in the next bug 1312260, where I'll actually need PrincipalHasPermission().

Works for me!
Pushed by ryanvm@gmail.com:
https://hg.mozilla.org/integration/autoland/rev/ec252adeb5c3
Factor out nsContentUtils::SubjectPrincipal version that takes JSContext r=bz
Keywords: checkin-needed
https://hg.mozilla.org/mozilla-central/rev/ec252adeb5c3
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla54
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: