Closed Bug 1147699 Opened 9 years ago Closed 9 years ago

Enable FetchEvent.request.context to reflect the existing contexts supported by nsContentPolicyType

Categories

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

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla40
Tracking Status
firefox40 --- fixed

People

(Reporter: ehsan.akhgari, Assigned: ehsan.akhgari)

References

Details

Attachments

(19 files)

15.17 KB, patch
nsm
: review+
Details | Diff | Splinter Review
3.11 KB, patch
nsm
: review+
Details | Diff | Splinter Review
6.89 KB, patch
nsm
: review+
Details | Diff | Splinter Review
5.36 KB, patch
nsm
: review+
bzbarsky
: review+
Details | Diff | Splinter Review
9.75 KB, patch
nsm
: review+
Details | Diff | Splinter Review
2.54 KB, patch
nsm
: review+
Details | Diff | Splinter Review
5.42 KB, patch
nsm
: review+
Details | Diff | Splinter Review
5.06 KB, patch
nsm
: review+
Details | Diff | Splinter Review
4.01 KB, patch
nsm
: review+
Details | Diff | Splinter Review
2.78 KB, patch
nsm
: review+
Details | Diff | Splinter Review
3.38 KB, patch
nsm
: review+
Details | Diff | Splinter Review
3.05 KB, patch
nsm
: review+
Details | Diff | Splinter Review
5.42 KB, patch
nsm
: review+
Details | Diff | Splinter Review
5.20 KB, patch
nsm
: review+
Details | Diff | Splinter Review
2.74 KB, patch
nsm
: review+
Details | Diff | Splinter Review
2.82 KB, patch
nsm
: review+
Details | Diff | Splinter Review
2.91 KB, patch
nsm
: review+
Details | Diff | Splinter Review
2.67 KB, patch
nsm
: review+
Details | Diff | Splinter Review
4.75 KB, patch
nsm
: review+
Details | Diff | Splinter Review
      No description provided.
As the documentation in InternalRequest.h in this patch shows, the
mapping between nsContentPolicyType and RequestContext is not complete
yet.  Because the InternalRequest object needs to know the actual
nsContentPolicyType in order for FetchDriver to be able to use that
information, we can't just store the RequestContext.  Therefore, this
patch adds both of these to InternalRequest.  Once we get to a stage
where we have a complete mapping of these values, we can store only one
of them and compute the other from it.  That requires addressing all of
the TODO comments in the InternalRequest.h documentation.
Note that InternalRequest::SetContentPolicyType takes care of updating the
RequestContext value stored in InternalRequest too.
Note that currently our implementation incorrectly reflects this as
'audio'.  This will be fixed later.
Comment on attachment 8583517 [details] [diff] [review]
Part 1: Move Request::mContext to InternalRequest, and determine the mapping to nsContentPolicyType; r=nsm

(More patches to come tomorrow to add tests for the rest of the RequestContext types!)
Attachment #8583517 - Flags: review?(nsm.nikhil)
Attachment #8583518 - Flags: review?(nsm.nikhil)
Attachment #8583519 - Flags: review?(nsm.nikhil)
Attachment #8583520 - Flags: review?(nsm.nikhil)
Attachment #8583521 - Flags: review?(nsm.nikhil)
Attachment #8583522 - Flags: review?(nsm.nikhil)
Attachment #8583523 - Flags: review?(nsm.nikhil)
Depends on: 1126820
Comment on attachment 8583517 [details] [diff] [review]
Part 1: Move Request::mContext to InternalRequest, and determine the mapping to nsContentPolicyType; r=nsm

Review of attachment 8583517 [details] [diff] [review]:
-----------------------------------------------------------------

::: dom/fetch/InternalRequest.h
@@ +24,5 @@
>  
>  namespace mozilla {
>  namespace dom {
>  
> +/*

This comment has some trailing whitespace.

::: dom/workers/test/serviceworkers/fetch/context/index.html
@@ +23,5 @@
>    testFetch()
>    .then(function() {
>      finish();
> +  }, function(e) {
> +    ok(false, "A promise was rejected: " + e);

call finish() in this branch too.
Attachment #8583517 - Flags: review?(nsm.nikhil) → review+
Comment on attachment 8583519 [details] [diff] [review]
Part 3: Add a test for FetchEvent.request.context when intercepting an image load; r=nsm

Review of attachment 8583519 [details] [diff] [review]:
-----------------------------------------------------------------

image file is missing!

::: dom/workers/test/serviceworkers/fetch/context/context_test.js
@@ +12,5 @@
>      event.respondWith(new Response(body));
> +  } else if (event.request.url.indexOf("img.jpg") >= 0) {
> +    if (event.request.context == "image") {
> +      event.respondWith(fetch("realimg.jpg"));
> +    }

else {
  event.respondWith(Promise.reject());
}

::: dom/workers/test/serviceworkers/fetch/context/index.html
@@ +39,4 @@
>    .then(function() {
>      finish();
>    }, function(e) {
>      ok(false, "A promise was rejected: " + e);

Why not just call finish() here instead of waiting for the test to time out? The test above will fail and we will know something went wrong. Update comment accordingly.
Attachment #8583519 - Flags: review?(nsm.nikhil) → review+
Comment on attachment 8583520 [details] [diff] [review]
Part 4: Add a test for FetchEvent.request.context when intercepting a responsive image load; r=nsm

Review of attachment 8583520 [details] [diff] [review]:
-----------------------------------------------------------------

Please get review from someone else on the imgLoader changes.

::: dom/workers/test/serviceworkers/fetch/context/context_test.js
@@ +21,1 @@
>    } else {

If you remove the else and always call respondWith, you can get rejection by default for when you want to fail the test (context does not match). Just like Promises, respondWith() does not do anything when called a second time, so it won't always fail.
Attachment #8583520 - Flags: review?(nsm.nikhil) → review+
Comment on attachment 8583521 [details] [diff] [review]
Part 5: Add a test for FetchEvent.request.context when intercepting an audio element load; r=nsm

Review of attachment 8583521 [details] [diff] [review]:
-----------------------------------------------------------------

ignore earlier review about image file being missing, i see that it shows in the splinter comment.
Attachment #8583521 - Flags: review?(nsm.nikhil) → review+
Comment on attachment 8583523 [details] [diff] [review]
Part 7: Add a test for FetchEvent.request.context when intercepting a beacon load; r=nsm

Review of attachment 8583523 [details] [diff] [review]:
-----------------------------------------------------------------

::: dom/workers/test/serviceworkers/fetch/context/context_test.js
@@ +34,3 @@
>    } else {
>      // Fail any request that we don't know about.
>      event.respondWith(Promise.reject());

also, to add to earlier patch about making this the default, you can reject with event.request.url so we know exactly which test failed.
Attachment #8583523 - Flags: review?(nsm.nikhil) → review+
Comment on attachment 8583520 [details] [diff] [review]
Part 4: Add a test for FetchEvent.request.context when intercepting a responsive image load; r=nsm

Review of attachment 8583520 [details] [diff] [review]:
-----------------------------------------------------------------

::: image/src/imgLoader.cpp
@@ +784,5 @@
>      rv = NS_NewChannel(aResult,
>                         aURI,
>                         triggeringPrincipal,
>                         securityFlags,
> +                       aPolicyType,

This was done in <http://hg.mozilla.org/mozilla-central/rev/b292b91c6755#l7.44> which Boris reviewed, and it seems wrong to me, so asking for his review on this code again.
Attachment #8583520 - Flags: review?(bzbarsky)
Thanks for doing all of these reviews, Nikhil!
> This was done in <http://hg.mozilla.org/mozilla-central/rev/b292b91c6755#l7.44> which
> Boris reviewed

Ugh.  yes, that's clearly wrong; looks like a merge conflict partway through the patches in bug 1083422 which I didn't catch.  :(
Comment on attachment 8583520 [details] [diff] [review]
Part 4: Add a test for FetchEvent.request.context when intercepting a responsive image load; r=nsm

That said, it's a bit disturbing that we had no testcases for this....  I guess now we will!

r=me
Attachment #8583520 - Flags: review?(bzbarsky) → review+
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: