From 319c7870ef7d1f45abe2754d9dd125b877de5d4c Mon Sep 17 00:00:00 2001 From: Samael Wang Date: Tue, 9 Aug 2016 14:28:17 +0800 Subject: [PATCH] Bug 1268962 - Add load / error event to prefetch link. r=bz --- dom/base/test/file_bug1268962.sjs | 64 +++++++++++++++ dom/base/test/mochitest.ini | 2 + dom/base/test/test_bug1268962.html | 80 +++++++++++++++++++ dom/base/test/test_link_prefetch.html | 11 --- .../allowed.https.html.ini | 5 +- .../no-redirect/allowed.https.html.ini | 5 +- .../no-redirect/allowed.https.html.ini | 5 +- .../allowed.https.html.ini | 5 +- .../no-redirect/allowed.https.html.ini | 5 +- .../opt-in-blocks.https.html.ini | 6 -- .../no-redirect/opt-in-blocks.https.html.ini | 6 -- .../opt-in-blocks.https.html.ini | 6 -- .../opt-in-blocks.https.html.ini | 6 -- .../no-redirect/opt-in-blocks.https.html.ini | 6 -- .../opt-in-blocks.https.html.ini | 6 -- .../no-redirect/opt-in-blocks.https.html.ini | 6 -- .../no-redirect/opt-in-blocks.https.html.ini | 6 -- .../no-opt-in-allows.https.html.ini | 5 +- .../no-opt-in-allows.https.html.ini | 5 +- .../no-opt-in-allows.https.html.ini | 5 +- .../no-opt-in-allows.https.html.ini | 5 +- .../no-opt-in-allows.https.html.ini | 5 +- .../no-opt-in-allows.https.html.ini | 5 +- uriloader/prefetch/nsPrefetchService.cpp | 63 ++++++++++++++- uriloader/prefetch/nsPrefetchService.h | 8 ++ 25 files changed, 238 insertions(+), 93 deletions(-) create mode 100644 dom/base/test/file_bug1268962.sjs create mode 100644 dom/base/test/test_bug1268962.html delete mode 100644 testing/web-platform/meta/mixed-content/optionally-blockable/http-csp/cross-origin-http/link-prefetch-tag/top-level/keep-scheme-redirect/opt-in-blocks.https.html.ini delete mode 100644 testing/web-platform/meta/mixed-content/optionally-blockable/http-csp/cross-origin-http/link-prefetch-tag/top-level/no-redirect/opt-in-blocks.https.html.ini delete mode 100644 testing/web-platform/meta/mixed-content/optionally-blockable/http-csp/cross-origin-http/link-prefetch-tag/top-level/swap-scheme-redirect/opt-in-blocks.https.html.ini delete mode 100644 testing/web-platform/meta/mixed-content/optionally-blockable/http-csp/same-host-http/link-prefetch-tag/top-level/keep-scheme-redirect/opt-in-blocks.https.html.ini delete mode 100644 testing/web-platform/meta/mixed-content/optionally-blockable/http-csp/same-host-http/link-prefetch-tag/top-level/no-redirect/opt-in-blocks.https.html.ini delete mode 100644 testing/web-platform/meta/mixed-content/optionally-blockable/http-csp/same-host-http/link-prefetch-tag/top-level/swap-scheme-redirect/opt-in-blocks.https.html.ini delete mode 100644 testing/web-platform/meta/mixed-content/optionally-blockable/meta-csp/cross-origin-http/link-prefetch-tag/top-level/no-redirect/opt-in-blocks.https.html.ini delete mode 100644 testing/web-platform/meta/mixed-content/optionally-blockable/meta-csp/same-host-http/link-prefetch-tag/top-level/no-redirect/opt-in-blocks.https.html.ini diff --git a/dom/base/test/file_bug1268962.sjs b/dom/base/test/file_bug1268962.sjs new file mode 100644 index 000000000000..1cbaef57d7aa --- /dev/null +++ b/dom/base/test/file_bug1268962.sjs @@ -0,0 +1,64 @@ +// Test server for bug 1268962 +'use strict'; +Components.utils.importGlobalProperties(["URLSearchParams"]); +const HTTPStatus = new Map([ + [100, 'Continue'], + [101, 'Switching Protocol'], + [200, 'OK'], + [201, 'Created'], + [202, 'Accepted'], + [203, 'Non-Authoritative Information'], + [204, 'No Content'], + [205, 'Reset Content'], + [206, 'Partial Content'], + [300, 'Multiple Choice'], + [301, 'Moved Permanently'], + [302, 'Found'], + [303, 'See Other'], + [304, 'Not Modified'], + [305, 'Use Proxy'], + [306, 'unused'], + [307, 'Temporary Redirect'], + [308, 'Permanent Redirect'], + [400, 'Bad Request'], + [401, 'Unauthorized'], + [402, 'Payment Required'], + [403, 'Forbidden'], + [404, 'Not Found'], + [405, 'Method Not Allowed'], + [406, 'Not Acceptable'], + [407, 'Proxy Authentication Required'], + [408, 'Request Timeout'], + [409, 'Conflict'], + [410, 'Gone'], + [411, 'Length Required'], + [412, 'Precondition Failed'], + [413, 'Request Entity Too Large'], + [414, 'Request-URI Too Long'], + [415, 'Unsupported Media Type'], + [416, 'Requested Range Not Satisfiable'], + [417, 'Expectation Failed'], + [500, 'Internal Server Error'], + [501, 'Not Implemented'], + [502, 'Bad Gateway'], + [503, 'Service Unavailable'], + [504, 'Gateway Timeout'], + [505, 'HTTP Version Not Supported'] +]); + +function handleRequest(request, response) { + const queryMap = new URLSearchParams(request.queryString); + if (queryMap.has('statusCode')) { + let statusCode = parseInt(queryMap.get('statusCode')); + let statusText = HTTPStatus.get(statusCode); + response.setStatusLine('1.1', statusCode, statusText); + } + if (queryMap.has('cacheControl')) { + let cacheControl = queryMap.get('cacheControl'); + response.setHeader('Cache-Control', cacheControl); + } + if (queryMap.has('allowOrigin')) { + let allowOrigin = queryMap.get('allowOrigin'); + response.setHeader('Access-Control-Allow-Origin', allowOrigin); + } +} diff --git a/dom/base/test/mochitest.ini b/dom/base/test/mochitest.ini index c676e93e8190..0337eaba5429 100644 --- a/dom/base/test/mochitest.ini +++ b/dom/base/test/mochitest.ini @@ -226,6 +226,7 @@ support-files = file_change_policy_redirect.html file_bug1198095.js file_bug1250148.sjs + file_bug1268962.sjs mozbrowser_api_utils.js websocket_helpers.js websocket_tests.js @@ -627,6 +628,7 @@ skip-if = buildapp == 'b2g' [test_bug1250148.html] [test_bug1259588.html] [test_bug1263696.html] +[test_bug1268962.html] [test_bug1274806.html] [test_bug1281963.html] [test_caretPositionFromPoint.html] diff --git a/dom/base/test/test_bug1268962.html b/dom/base/test/test_bug1268962.html new file mode 100644 index 000000000000..19e86b5b214a --- /dev/null +++ b/dom/base/test/test_bug1268962.html @@ -0,0 +1,80 @@ + + + + + Test for Bug 1268962 + + + + +Mozilla Bug 1268962 +

+ + + + diff --git a/dom/base/test/test_link_prefetch.html b/dom/base/test/test_link_prefetch.html index f38ce369953e..55a244917ea7 100644 --- a/dom/base/test/test_link_prefetch.html +++ b/dom/base/test/test_link_prefetch.html @@ -160,17 +160,6 @@ - diff --git a/testing/web-platform/meta/mixed-content/allowed/http-csp/same-host-https/link-prefetch-tag/top-level/keep-scheme-redirect/allowed.https.html.ini b/testing/web-platform/meta/mixed-content/allowed/http-csp/same-host-https/link-prefetch-tag/top-level/keep-scheme-redirect/allowed.https.html.ini index abc68ca7ff1b..961ef1f2bfa2 100644 --- a/testing/web-platform/meta/mixed-content/allowed/http-csp/same-host-https/link-prefetch-tag/top-level/keep-scheme-redirect/allowed.https.html.ini +++ b/testing/web-platform/meta/mixed-content/allowed/http-csp/same-host-https/link-prefetch-tag/top-level/keep-scheme-redirect/allowed.https.html.ini @@ -1,6 +1,5 @@ [allowed.https.html] type: testharness - expected: TIMEOUT [opt_in_method: http-csp\n origin: same-host-https\n source_scheme: https\n context_nesting: top-level\n redirection: keep-scheme-redirect\n subresource: link-prefetch-tag\n expectation: allowed] - expected: NOTRUN - + expected: FAIL + bug: the test case uses "no-cache" HTTP header. send an error until we have conclusion at https://github.com/w3c/resource-hints/issues/62 diff --git a/testing/web-platform/meta/mixed-content/allowed/http-csp/same-host-https/link-prefetch-tag/top-level/no-redirect/allowed.https.html.ini b/testing/web-platform/meta/mixed-content/allowed/http-csp/same-host-https/link-prefetch-tag/top-level/no-redirect/allowed.https.html.ini index cd9c1398da26..1579eaa07c8a 100644 --- a/testing/web-platform/meta/mixed-content/allowed/http-csp/same-host-https/link-prefetch-tag/top-level/no-redirect/allowed.https.html.ini +++ b/testing/web-platform/meta/mixed-content/allowed/http-csp/same-host-https/link-prefetch-tag/top-level/no-redirect/allowed.https.html.ini @@ -1,6 +1,5 @@ [allowed.https.html] type: testharness - expected: TIMEOUT [opt_in_method: http-csp\n origin: same-host-https\n source_scheme: https\n context_nesting: top-level\n redirection: no-redirect\n subresource: link-prefetch-tag\n expectation: allowed] - expected: NOTRUN - + expected: FAIL + bug: the test case uses "no-cache" HTTP header. send an error until we have conclusion at https://github.com/w3c/resource-hints/issues/62 diff --git a/testing/web-platform/meta/mixed-content/allowed/meta-csp/same-host-https/link-prefetch-tag/top-level/no-redirect/allowed.https.html.ini b/testing/web-platform/meta/mixed-content/allowed/meta-csp/same-host-https/link-prefetch-tag/top-level/no-redirect/allowed.https.html.ini index 9d7b944a9699..a12dd96aa2b9 100644 --- a/testing/web-platform/meta/mixed-content/allowed/meta-csp/same-host-https/link-prefetch-tag/top-level/no-redirect/allowed.https.html.ini +++ b/testing/web-platform/meta/mixed-content/allowed/meta-csp/same-host-https/link-prefetch-tag/top-level/no-redirect/allowed.https.html.ini @@ -1,6 +1,5 @@ [allowed.https.html] type: testharness - expected: TIMEOUT [opt_in_method: meta-csp\n origin: same-host-https\n source_scheme: https\n context_nesting: top-level\n redirection: no-redirect\n subresource: link-prefetch-tag\n expectation: allowed] - expected: NOTRUN - + expected: FAIL + bug: the test case uses "no-cache" HTTP header. send an error until we have conclusion at https://github.com/w3c/resource-hints/issues/62 diff --git a/testing/web-platform/meta/mixed-content/allowed/no-opt-in/same-host-https/link-prefetch-tag/top-level/keep-scheme-redirect/allowed.https.html.ini b/testing/web-platform/meta/mixed-content/allowed/no-opt-in/same-host-https/link-prefetch-tag/top-level/keep-scheme-redirect/allowed.https.html.ini index f0087ab36b42..3204662dbf08 100644 --- a/testing/web-platform/meta/mixed-content/allowed/no-opt-in/same-host-https/link-prefetch-tag/top-level/keep-scheme-redirect/allowed.https.html.ini +++ b/testing/web-platform/meta/mixed-content/allowed/no-opt-in/same-host-https/link-prefetch-tag/top-level/keep-scheme-redirect/allowed.https.html.ini @@ -1,6 +1,5 @@ [allowed.https.html] type: testharness - expected: TIMEOUT [opt_in_method: no-opt-in\n origin: same-host-https\n source_scheme: https\n context_nesting: top-level\n redirection: keep-scheme-redirect\n subresource: link-prefetch-tag\n expectation: allowed] - expected: NOTRUN - + expected: FAIL + bug: the test case uses "no-cache" HTTP header. send an error until we have conclusion at https://github.com/w3c/resource-hints/issues/62 diff --git a/testing/web-platform/meta/mixed-content/allowed/no-opt-in/same-host-https/link-prefetch-tag/top-level/no-redirect/allowed.https.html.ini b/testing/web-platform/meta/mixed-content/allowed/no-opt-in/same-host-https/link-prefetch-tag/top-level/no-redirect/allowed.https.html.ini index c455279290f6..aa6e6f4ffffe 100644 --- a/testing/web-platform/meta/mixed-content/allowed/no-opt-in/same-host-https/link-prefetch-tag/top-level/no-redirect/allowed.https.html.ini +++ b/testing/web-platform/meta/mixed-content/allowed/no-opt-in/same-host-https/link-prefetch-tag/top-level/no-redirect/allowed.https.html.ini @@ -1,6 +1,5 @@ [allowed.https.html] type: testharness - expected: TIMEOUT [opt_in_method: no-opt-in\n origin: same-host-https\n source_scheme: https\n context_nesting: top-level\n redirection: no-redirect\n subresource: link-prefetch-tag\n expectation: allowed] - expected: NOTRUN - + expected: FAIL + bug: the test case uses "no-cache" HTTP header. send an error until we have conclusion at https://github.com/w3c/resource-hints/issues/62 diff --git a/testing/web-platform/meta/mixed-content/optionally-blockable/http-csp/cross-origin-http/link-prefetch-tag/top-level/keep-scheme-redirect/opt-in-blocks.https.html.ini b/testing/web-platform/meta/mixed-content/optionally-blockable/http-csp/cross-origin-http/link-prefetch-tag/top-level/keep-scheme-redirect/opt-in-blocks.https.html.ini deleted file mode 100644 index 0524d01dbc2f..000000000000 --- a/testing/web-platform/meta/mixed-content/optionally-blockable/http-csp/cross-origin-http/link-prefetch-tag/top-level/keep-scheme-redirect/opt-in-blocks.https.html.ini +++ /dev/null @@ -1,6 +0,0 @@ -[opt-in-blocks.https.html] - type: testharness - expected: TIMEOUT - [opt_in_method: http-csp\n origin: cross-origin-http\n source_scheme: https\n context_nesting: top-level\n redirection: keep-scheme-redirect\n subresource: link-prefetch-tag\n expectation: blocked] - expected: NOTRUN - diff --git a/testing/web-platform/meta/mixed-content/optionally-blockable/http-csp/cross-origin-http/link-prefetch-tag/top-level/no-redirect/opt-in-blocks.https.html.ini b/testing/web-platform/meta/mixed-content/optionally-blockable/http-csp/cross-origin-http/link-prefetch-tag/top-level/no-redirect/opt-in-blocks.https.html.ini deleted file mode 100644 index bd8dd44c17e6..000000000000 --- a/testing/web-platform/meta/mixed-content/optionally-blockable/http-csp/cross-origin-http/link-prefetch-tag/top-level/no-redirect/opt-in-blocks.https.html.ini +++ /dev/null @@ -1,6 +0,0 @@ -[opt-in-blocks.https.html] - type: testharness - expected: TIMEOUT - [opt_in_method: http-csp\n origin: cross-origin-http\n source_scheme: https\n context_nesting: top-level\n redirection: no-redirect\n subresource: link-prefetch-tag\n expectation: blocked] - expected: NOTRUN - diff --git a/testing/web-platform/meta/mixed-content/optionally-blockable/http-csp/cross-origin-http/link-prefetch-tag/top-level/swap-scheme-redirect/opt-in-blocks.https.html.ini b/testing/web-platform/meta/mixed-content/optionally-blockable/http-csp/cross-origin-http/link-prefetch-tag/top-level/swap-scheme-redirect/opt-in-blocks.https.html.ini deleted file mode 100644 index e5e615ad9fd2..000000000000 --- a/testing/web-platform/meta/mixed-content/optionally-blockable/http-csp/cross-origin-http/link-prefetch-tag/top-level/swap-scheme-redirect/opt-in-blocks.https.html.ini +++ /dev/null @@ -1,6 +0,0 @@ -[opt-in-blocks.https.html] - type: testharness - expected: TIMEOUT - [opt_in_method: http-csp\n origin: cross-origin-http\n source_scheme: https\n context_nesting: top-level\n redirection: swap-scheme-redirect\n subresource: link-prefetch-tag\n expectation: blocked] - expected: NOTRUN - diff --git a/testing/web-platform/meta/mixed-content/optionally-blockable/http-csp/same-host-http/link-prefetch-tag/top-level/keep-scheme-redirect/opt-in-blocks.https.html.ini b/testing/web-platform/meta/mixed-content/optionally-blockable/http-csp/same-host-http/link-prefetch-tag/top-level/keep-scheme-redirect/opt-in-blocks.https.html.ini deleted file mode 100644 index 076f1419ed4c..000000000000 --- a/testing/web-platform/meta/mixed-content/optionally-blockable/http-csp/same-host-http/link-prefetch-tag/top-level/keep-scheme-redirect/opt-in-blocks.https.html.ini +++ /dev/null @@ -1,6 +0,0 @@ -[opt-in-blocks.https.html] - type: testharness - expected: TIMEOUT - [opt_in_method: http-csp\n origin: same-host-http\n source_scheme: https\n context_nesting: top-level\n redirection: keep-scheme-redirect\n subresource: link-prefetch-tag\n expectation: blocked] - expected: NOTRUN - diff --git a/testing/web-platform/meta/mixed-content/optionally-blockable/http-csp/same-host-http/link-prefetch-tag/top-level/no-redirect/opt-in-blocks.https.html.ini b/testing/web-platform/meta/mixed-content/optionally-blockable/http-csp/same-host-http/link-prefetch-tag/top-level/no-redirect/opt-in-blocks.https.html.ini deleted file mode 100644 index 43e02911df9c..000000000000 --- a/testing/web-platform/meta/mixed-content/optionally-blockable/http-csp/same-host-http/link-prefetch-tag/top-level/no-redirect/opt-in-blocks.https.html.ini +++ /dev/null @@ -1,6 +0,0 @@ -[opt-in-blocks.https.html] - type: testharness - expected: TIMEOUT - [opt_in_method: http-csp\n origin: same-host-http\n source_scheme: https\n context_nesting: top-level\n redirection: no-redirect\n subresource: link-prefetch-tag\n expectation: blocked] - expected: NOTRUN - diff --git a/testing/web-platform/meta/mixed-content/optionally-blockable/http-csp/same-host-http/link-prefetch-tag/top-level/swap-scheme-redirect/opt-in-blocks.https.html.ini b/testing/web-platform/meta/mixed-content/optionally-blockable/http-csp/same-host-http/link-prefetch-tag/top-level/swap-scheme-redirect/opt-in-blocks.https.html.ini deleted file mode 100644 index 1f3900c5d917..000000000000 --- a/testing/web-platform/meta/mixed-content/optionally-blockable/http-csp/same-host-http/link-prefetch-tag/top-level/swap-scheme-redirect/opt-in-blocks.https.html.ini +++ /dev/null @@ -1,6 +0,0 @@ -[opt-in-blocks.https.html] - type: testharness - expected: TIMEOUT - [opt_in_method: http-csp\n origin: same-host-http\n source_scheme: https\n context_nesting: top-level\n redirection: swap-scheme-redirect\n subresource: link-prefetch-tag\n expectation: blocked] - expected: NOTRUN - diff --git a/testing/web-platform/meta/mixed-content/optionally-blockable/meta-csp/cross-origin-http/link-prefetch-tag/top-level/no-redirect/opt-in-blocks.https.html.ini b/testing/web-platform/meta/mixed-content/optionally-blockable/meta-csp/cross-origin-http/link-prefetch-tag/top-level/no-redirect/opt-in-blocks.https.html.ini deleted file mode 100644 index f2dd41a27745..000000000000 --- a/testing/web-platform/meta/mixed-content/optionally-blockable/meta-csp/cross-origin-http/link-prefetch-tag/top-level/no-redirect/opt-in-blocks.https.html.ini +++ /dev/null @@ -1,6 +0,0 @@ -[opt-in-blocks.https.html] - type: testharness - expected: TIMEOUT - [opt_in_method: meta-csp\n origin: cross-origin-http\n source_scheme: https\n context_nesting: top-level\n redirection: no-redirect\n subresource: link-prefetch-tag\n expectation: blocked] - expected: NOTRUN - diff --git a/testing/web-platform/meta/mixed-content/optionally-blockable/meta-csp/same-host-http/link-prefetch-tag/top-level/no-redirect/opt-in-blocks.https.html.ini b/testing/web-platform/meta/mixed-content/optionally-blockable/meta-csp/same-host-http/link-prefetch-tag/top-level/no-redirect/opt-in-blocks.https.html.ini deleted file mode 100644 index 1236d0d2ee11..000000000000 --- a/testing/web-platform/meta/mixed-content/optionally-blockable/meta-csp/same-host-http/link-prefetch-tag/top-level/no-redirect/opt-in-blocks.https.html.ini +++ /dev/null @@ -1,6 +0,0 @@ -[opt-in-blocks.https.html] - type: testharness - expected: TIMEOUT - [opt_in_method: meta-csp\n origin: same-host-http\n source_scheme: https\n context_nesting: top-level\n redirection: no-redirect\n subresource: link-prefetch-tag\n expectation: blocked] - expected: NOTRUN - diff --git a/testing/web-platform/meta/mixed-content/optionally-blockable/no-opt-in/cross-origin-http/link-prefetch-tag/top-level/keep-scheme-redirect/no-opt-in-allows.https.html.ini b/testing/web-platform/meta/mixed-content/optionally-blockable/no-opt-in/cross-origin-http/link-prefetch-tag/top-level/keep-scheme-redirect/no-opt-in-allows.https.html.ini index 743f5d670ed7..c0f49250621b 100644 --- a/testing/web-platform/meta/mixed-content/optionally-blockable/no-opt-in/cross-origin-http/link-prefetch-tag/top-level/keep-scheme-redirect/no-opt-in-allows.https.html.ini +++ b/testing/web-platform/meta/mixed-content/optionally-blockable/no-opt-in/cross-origin-http/link-prefetch-tag/top-level/keep-scheme-redirect/no-opt-in-allows.https.html.ini @@ -1,6 +1,5 @@ [no-opt-in-allows.https.html] type: testharness - expected: TIMEOUT [opt_in_method: no-opt-in\n origin: cross-origin-http\n source_scheme: https\n context_nesting: top-level\n redirection: keep-scheme-redirect\n subresource: link-prefetch-tag\n expectation: allowed] - expected: NOTRUN - + expected: FAIL + bug: haven't implement prefetch link as an optionally blockable item diff --git a/testing/web-platform/meta/mixed-content/optionally-blockable/no-opt-in/cross-origin-http/link-prefetch-tag/top-level/no-redirect/no-opt-in-allows.https.html.ini b/testing/web-platform/meta/mixed-content/optionally-blockable/no-opt-in/cross-origin-http/link-prefetch-tag/top-level/no-redirect/no-opt-in-allows.https.html.ini index fa1abb817877..e1b70b895864 100644 --- a/testing/web-platform/meta/mixed-content/optionally-blockable/no-opt-in/cross-origin-http/link-prefetch-tag/top-level/no-redirect/no-opt-in-allows.https.html.ini +++ b/testing/web-platform/meta/mixed-content/optionally-blockable/no-opt-in/cross-origin-http/link-prefetch-tag/top-level/no-redirect/no-opt-in-allows.https.html.ini @@ -1,6 +1,5 @@ [no-opt-in-allows.https.html] type: testharness - expected: TIMEOUT [opt_in_method: no-opt-in\n origin: cross-origin-http\n source_scheme: https\n context_nesting: top-level\n redirection: no-redirect\n subresource: link-prefetch-tag\n expectation: allowed] - expected: NOTRUN - + expected: FAIL + bug: haven't implement prefetch link as an optionally blockable item diff --git a/testing/web-platform/meta/mixed-content/optionally-blockable/no-opt-in/cross-origin-http/link-prefetch-tag/top-level/swap-scheme-redirect/no-opt-in-allows.https.html.ini b/testing/web-platform/meta/mixed-content/optionally-blockable/no-opt-in/cross-origin-http/link-prefetch-tag/top-level/swap-scheme-redirect/no-opt-in-allows.https.html.ini index 9149669c88d0..ab2cdb43bf8f 100644 --- a/testing/web-platform/meta/mixed-content/optionally-blockable/no-opt-in/cross-origin-http/link-prefetch-tag/top-level/swap-scheme-redirect/no-opt-in-allows.https.html.ini +++ b/testing/web-platform/meta/mixed-content/optionally-blockable/no-opt-in/cross-origin-http/link-prefetch-tag/top-level/swap-scheme-redirect/no-opt-in-allows.https.html.ini @@ -1,6 +1,5 @@ [no-opt-in-allows.https.html] type: testharness - expected: TIMEOUT [opt_in_method: no-opt-in\n origin: cross-origin-http\n source_scheme: https\n context_nesting: top-level\n redirection: swap-scheme-redirect\n subresource: link-prefetch-tag\n expectation: allowed] - expected: NOTRUN - + expected: FAIL + bug: haven't implement prefetch link as an optionally blockable item diff --git a/testing/web-platform/meta/mixed-content/optionally-blockable/no-opt-in/same-host-http/link-prefetch-tag/top-level/keep-scheme-redirect/no-opt-in-allows.https.html.ini b/testing/web-platform/meta/mixed-content/optionally-blockable/no-opt-in/same-host-http/link-prefetch-tag/top-level/keep-scheme-redirect/no-opt-in-allows.https.html.ini index 44a96d0e7e8a..689a4fbfaf88 100644 --- a/testing/web-platform/meta/mixed-content/optionally-blockable/no-opt-in/same-host-http/link-prefetch-tag/top-level/keep-scheme-redirect/no-opt-in-allows.https.html.ini +++ b/testing/web-platform/meta/mixed-content/optionally-blockable/no-opt-in/same-host-http/link-prefetch-tag/top-level/keep-scheme-redirect/no-opt-in-allows.https.html.ini @@ -1,6 +1,5 @@ [no-opt-in-allows.https.html] type: testharness - expected: TIMEOUT [opt_in_method: no-opt-in\n origin: same-host-http\n source_scheme: https\n context_nesting: top-level\n redirection: keep-scheme-redirect\n subresource: link-prefetch-tag\n expectation: allowed] - expected: NOTRUN - + expected: FAIL + bug: haven't implement prefetch link as an optionally blockable item diff --git a/testing/web-platform/meta/mixed-content/optionally-blockable/no-opt-in/same-host-http/link-prefetch-tag/top-level/no-redirect/no-opt-in-allows.https.html.ini b/testing/web-platform/meta/mixed-content/optionally-blockable/no-opt-in/same-host-http/link-prefetch-tag/top-level/no-redirect/no-opt-in-allows.https.html.ini index a4d274ad6368..7f3f10082b08 100644 --- a/testing/web-platform/meta/mixed-content/optionally-blockable/no-opt-in/same-host-http/link-prefetch-tag/top-level/no-redirect/no-opt-in-allows.https.html.ini +++ b/testing/web-platform/meta/mixed-content/optionally-blockable/no-opt-in/same-host-http/link-prefetch-tag/top-level/no-redirect/no-opt-in-allows.https.html.ini @@ -1,6 +1,5 @@ [no-opt-in-allows.https.html] type: testharness - expected: TIMEOUT [opt_in_method: no-opt-in\n origin: same-host-http\n source_scheme: https\n context_nesting: top-level\n redirection: no-redirect\n subresource: link-prefetch-tag\n expectation: allowed] - expected: NOTRUN - + expected: FAIL + bug: haven't implement prefetch link as an optionally blockable item diff --git a/testing/web-platform/meta/mixed-content/optionally-blockable/no-opt-in/same-host-http/link-prefetch-tag/top-level/swap-scheme-redirect/no-opt-in-allows.https.html.ini b/testing/web-platform/meta/mixed-content/optionally-blockable/no-opt-in/same-host-http/link-prefetch-tag/top-level/swap-scheme-redirect/no-opt-in-allows.https.html.ini index e2798ea00a73..15e55c1ff5aa 100644 --- a/testing/web-platform/meta/mixed-content/optionally-blockable/no-opt-in/same-host-http/link-prefetch-tag/top-level/swap-scheme-redirect/no-opt-in-allows.https.html.ini +++ b/testing/web-platform/meta/mixed-content/optionally-blockable/no-opt-in/same-host-http/link-prefetch-tag/top-level/swap-scheme-redirect/no-opt-in-allows.https.html.ini @@ -1,6 +1,5 @@ [no-opt-in-allows.https.html] type: testharness - expected: TIMEOUT [opt_in_method: no-opt-in\n origin: same-host-http\n source_scheme: https\n context_nesting: top-level\n redirection: swap-scheme-redirect\n subresource: link-prefetch-tag\n expectation: allowed] - expected: NOTRUN - + expected: FAIL + bug: haven't implement prefetch link as an optionally blockable item diff --git a/uriloader/prefetch/nsPrefetchService.cpp b/uriloader/prefetch/nsPrefetchService.cpp index cad6240ae6fe..2f1b6c57501a 100644 --- a/uriloader/prefetch/nsPrefetchService.cpp +++ b/uriloader/prefetch/nsPrefetchService.cpp @@ -54,6 +54,7 @@ static LazyLogModule gPrefetchLog("nsPrefetch"); #define PREFETCH_PREF "network.prefetch-next" #define PARALLELISM_PREF "network.prefetch-next.parallelism" +#define AGGRESSIVE_PREF "network.prefetch-next.aggressive" //----------------------------------------------------------------------------- // helpers @@ -81,6 +82,7 @@ nsPrefetchNode::nsPrefetchNode(nsPrefetchService *aService, , mService(aService) , mChannel(nullptr) , mBytesRead(0) + , mShouldFireLoadEvent(false) { nsCOMPtr source = do_GetWeakReference(aSource); mSources.AppendElement(source); @@ -187,6 +189,25 @@ nsPrefetchNode::OnStartRequest(nsIRequest *aRequest, { nsresult rv; + nsCOMPtr httpChannel = + do_QueryInterface(aRequest, &rv); + if (NS_FAILED(rv)) return rv; + + // if the load is cross origin without CORS, or the CORS access is rejected, + // always fire load event to avoid leaking site information. + nsCOMPtr loadInfo = mChannel->GetLoadInfo(); + mShouldFireLoadEvent = loadInfo->GetTainting() == LoadTainting::Opaque || + (loadInfo->GetTainting() == LoadTainting::CORS && + (NS_FAILED(mChannel->GetStatus(&rv)) || + NS_FAILED(rv))); + + // no need to prefetch http error page + bool requestSucceeded; + if (NS_FAILED(httpChannel->GetRequestSucceeded(&requestSucceeded)) || + !requestSucceeded) { + return NS_BINDING_ABORTED; + } + nsCOMPtr cacheInfoChannel = do_QueryInterface(aRequest, &rv); if (NS_FAILED(rv)) return rv; @@ -196,6 +217,8 @@ nsPrefetchNode::OnStartRequest(nsIRequest *aRequest, if (NS_SUCCEEDED(cacheInfoChannel->IsFromCache(&fromCache)) && fromCache) { LOG(("document is already in the cache; canceling prefetch\n")); + // although it's canceled we still want to fire load event + mShouldFireLoadEvent = true; return NS_BINDING_ABORTED; } @@ -245,6 +268,7 @@ nsPrefetchNode::OnStopRequest(nsIRequest *aRequest, } mService->NotifyLoadCompleted(this); + mService->DispatchEvent(this, mShouldFireLoadEvent || NS_SUCCEEDED(aStatus)); mService->ProcessNextURI(this); return NS_OK; } @@ -336,6 +360,7 @@ nsPrefetchService::nsPrefetchService() , mStopCount(0) , mHaveProcessed(false) , mDisabled(true) + , mAggressive(false) { } @@ -343,6 +368,7 @@ nsPrefetchService::~nsPrefetchService() { Preferences::RemoveObserver(this, PREFETCH_PREF); Preferences::RemoveObserver(this, PARALLELISM_PREF); + Preferences::RemoveObserver(this, AGGRESSIVE_PREF); // cannot reach destructor if prefetch in progress (listener owns reference // to this service) EmptyQueue(); @@ -363,6 +389,9 @@ nsPrefetchService::Init() } Preferences::AddWeakObserver(this, PARALLELISM_PREF); + mAggressive = Preferences::GetBool(AGGRESSIVE_PREF, false); + Preferences::AddWeakObserver(this, AGGRESSIVE_PREF); + // Observe xpcom-shutdown event nsCOMPtr observerService = mozilla::services::GetObserverService(); @@ -408,11 +437,14 @@ nsPrefetchService::ProcessNextURI(nsPrefetchNode *aFinished) } // - // if opening the channel fails, then just skip to the next uri + // if opening the channel fails (e.g. security check returns an error), + // send an error event and then just skip to the next uri // rv = node->OpenChannel(); if (NS_SUCCEEDED(rv)) { mCurrentNodes.AppendElement(node); + } else { + DispatchEvent(node, false); } } while (NS_FAILED(rv)); @@ -442,6 +474,23 @@ nsPrefetchService::NotifyLoadCompleted(nsPrefetchNode *node) "prefetch-load-completed", nullptr); } +void +nsPrefetchService::DispatchEvent(nsPrefetchNode *node, bool aSuccess) +{ + for (uint32_t i = 0; i < node->mSources.Length(); i++) { + nsCOMPtr domNode = do_QueryReferent(node->mSources.ElementAt(i)); + if (domNode && domNode->IsInComposedDoc()) { + nsContentUtils::DispatchTrustedEvent(domNode->OwnerDoc(), + domNode, + aSuccess ? + NS_LITERAL_STRING("load") : + NS_LITERAL_STRING("error"), + /* aCanBubble = */ false, + /* aCancelable = */ false); + } + } +} + //----------------------------------------------------------------------------- // nsPrefetchService //----------------------------------------------------------------------------- @@ -775,6 +824,11 @@ nsPrefetchService::OnStateChange(nsIWebProgress* aWebProgress, uint32_t progressStateFlags, nsresult aStatus) { + if (mAggressive) { + LOG(("Document load state is ignored in aggressive mode")); + return NS_OK; + } + if (progressStateFlags & STATE_IS_DOCUMENT) { if (progressStateFlags & STATE_STOP) StartPrefetching(); @@ -862,6 +916,13 @@ nsPrefetchService::Observe(nsISupports *aSubject, while (!mQueue.empty() && mCurrentNodes.Length() < static_cast(mMaxParallelism)) { ProcessNextURI(nullptr); } + } else if (!strcmp(pref, AGGRESSIVE_PREF)) { + mAggressive = Preferences::GetBool(AGGRESSIVE_PREF, false); + // in aggressive mode, clear stop count and start prefetching immediately + if (mAggressive) { + mStopCount = 0; + StartPrefetching(); + } } } diff --git a/uriloader/prefetch/nsPrefetchService.h b/uriloader/prefetch/nsPrefetchService.h index 1ca80f8316d2..883449e68999 100644 --- a/uriloader/prefetch/nsPrefetchService.h +++ b/uriloader/prefetch/nsPrefetchService.h @@ -45,6 +45,7 @@ public: void NotifyLoadRequested(nsPrefetchNode *node); void NotifyLoadCompleted(nsPrefetchNode *node); + void DispatchEvent(nsPrefetchNode *node, bool aSuccess); private: ~nsPrefetchService(); @@ -70,6 +71,12 @@ private: // true if pending document loads have ever reached zero. int32_t mHaveProcessed; bool mDisabled; + + // In usual case prefetch does not start until all normal loads are done. + // Aggressive mode ignores normal loads and just start prefetch ASAP. + // It's mainly for testing purpose and discoraged for normal use; + // see https://bugzilla.mozilla.org/show_bug.cgi?id=1281415 for details. + bool mAggressive; }; //----------------------------------------------------------------------------- @@ -108,6 +115,7 @@ private: nsCOMPtr mChannel; nsCOMPtr mRedirectChannel; int64_t mBytesRead; + bool mShouldFireLoadEvent; }; #endif // !nsPrefetchService_h__