https://bugs.webkit.org/show_bug.cgi?id=181103
Reviewed by Youenn Fablet.
LayoutTests/imported/w3c:
Rebaseline WPT test now that it fails later. The test expects that the registration promise be
rejected with a SecurityError. However, we reject it with a TypeError instead, which is the
result of the Network error from importScripts().
The spec does say that importScripts() should report a network error when the MIME type is
invalid:
- https://w3c.github.io/ServiceWorker/#importscripts (step 6)
Later on, the spec says that if "an uncaught runtime script error occurs" when running the script,
we should resolve the registration with a TypeError:
- https://w3c.github.io/ServiceWorker/#update (step 9.6)
Therefore, our behavior seems correct and I cannot find in the spec a reason why the test would
expect a SecurityError here.
* web-platform-tests/service-workers/service-worker/registration-mime-types.https-expected.txt:
Source/WebCore:
importScripts() inside a service worker should ensure that the response has a JavaScript
MIME type, as per:
- https://w3c.github.io/ServiceWorker/#importscripts (step 6)
No new tests, rebaselined existing test.
* workers/WorkerGlobalScope.cpp:
(WebCore::WorkerGlobalScope::importScripts):
* workers/WorkerScriptLoader.cpp:
(WebCore::WorkerScriptLoader::didReceiveResponse):
* workers/WorkerScriptLoader.h:
(WebCore::WorkerScriptLoader::responseMIMEType const):
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@226275
268f45cc-cd09-0410-ab3c-
d52691b4dbfc
2017-12-22 Chris Dumez <cdumez@apple.com>
+ importScripts() inside a service worker should ensure that the response has a JavaScript MIME type
+ https://bugs.webkit.org/show_bug.cgi?id=181103
+
+ Reviewed by Youenn Fablet.
+
+ Rebaseline WPT test now that it fails later. The test expects that the registration promise be
+ rejected with a SecurityError. However, we reject it with a TypeError instead, which is the
+ result of the Network error from importScripts().
+
+ The spec does say that importScripts() should report a network error when the MIME type is
+ invalid:
+ - https://w3c.github.io/ServiceWorker/#importscripts (step 6)
+
+ Later on, the spec says that if "an uncaught runtime script error occurs" when running the script,
+ we should resolve the registration with a TypeError:
+ - https://w3c.github.io/ServiceWorker/#update (step 9.6)
+
+ Therefore, our behavior seems correct and I cannot find in the spec a reason why the test would
+ expect a SecurityError here.
+
+ * web-platform-tests/service-workers/service-worker/registration-mime-types.https-expected.txt:
+
+2017-12-22 Chris Dumez <cdumez@apple.com>
+
[Service Workers] Implement "Soft Update" algorithm
https://bugs.webkit.org/show_bug.cgi?id=180702
<rdar://problem/36163461>
PASS Registering script with no MIME type
PASS Registering script with bad MIME type
-FAIL Registering script that imports script with no MIME type assert_unreached: Should have rejected: Registration of no MIME type imported script should fail. Reached unreachable code
-FAIL Registering script that imports script with bad MIME type assert_unreached: Should have rejected: Registration of plain text imported script should fail. Reached unreachable code
+FAIL Registering script that imports script with no MIME type assert_throws: Registration of no MIME type imported script should fail. function "function () { throw e }" threw object "TypeError: NetworkError: A network error occurred." that is not a DOMException SecurityError: property "code" is equal to undefined, expected 18
+FAIL Registering script that imports script with bad MIME type assert_throws: Registration of plain text imported script should fail. function "function () { throw e }" threw object "TypeError: NetworkError: A network error occurred." that is not a DOMException SecurityError: property "code" is equal to undefined, expected 18
PASS Registering script with good MIME type application/ecmascript
PASS Registering script that imports script with good MIME type application/ecmascript
PASS Registering script with good MIME type application/javascript
2017-12-22 Chris Dumez <cdumez@apple.com>
+ importScripts() inside a service worker should ensure that the response has a JavaScript MIME type
+ https://bugs.webkit.org/show_bug.cgi?id=181103
+
+ Reviewed by Youenn Fablet.
+
+ importScripts() inside a service worker should ensure that the response has a JavaScript
+ MIME type, as per:
+ - https://w3c.github.io/ServiceWorker/#importscripts (step 6)
+
+ No new tests, rebaselined existing test.
+
+ * workers/WorkerGlobalScope.cpp:
+ (WebCore::WorkerGlobalScope::importScripts):
+ * workers/WorkerScriptLoader.cpp:
+ (WebCore::WorkerScriptLoader::didReceiveResponse):
+ * workers/WorkerScriptLoader.h:
+ (WebCore::WorkerScriptLoader::responseMIMEType const):
+
+2017-12-22 Chris Dumez <cdumez@apple.com>
+
[Service Workers] Implement "Soft Update" algorithm
https://bugs.webkit.org/show_bug.cgi?id=180702
<rdar://problem/36163461>
#include "IDBConnectionProxy.h"
#include "ImageBitmapOptions.h"
#include "InspectorInstrumentation.h"
+#include "MIMETypeRegistry.h"
#include "Performance.h"
#include "ScheduledAction.h"
#include "ScriptSourceCode.h"
FetchOptions::Cache cachePolicy = FetchOptions::Cache::Default;
#if ENABLE(SERVICE_WORKER)
- if (is<ServiceWorkerGlobalScope>(*this)) {
- // FIXME: Fully implement https://w3c.github.io/ServiceWorker/#importscripts.
+ bool isServiceWorkerGlobalScope = is<ServiceWorkerGlobalScope>(*this);
+ if (isServiceWorkerGlobalScope) {
+ // FIXME: We need to add support for the 'imported scripts updated' flag as per:
+ // https://w3c.github.io/ServiceWorker/#importscripts
auto& serviceWorkerGlobalScope = downcast<ServiceWorkerGlobalScope>(*this);
auto& registration = serviceWorkerGlobalScope.registration();
if (registration.updateViaCache() == ServiceWorkerUpdateViaCache::None || registration.needsUpdate())
if (scriptLoader->failed())
return Exception { NetworkError };
+#if ENABLE(SERVICE_WORKER)
+ if (isServiceWorkerGlobalScope && !MIMETypeRegistry::isSupportedJavaScriptMIMEType(scriptLoader->responseMIMEType()))
+ return Exception { NetworkError };
+#endif
+
InspectorInstrumentation::scriptImported(*this, scriptLoader->identifier(), scriptLoader->script());
NakedPtr<JSC::Exception> exception;
}
m_responseURL = response.url();
+ m_responseMIMEType = response.mimeType();
m_responseEncoding = response.textEncodingName();
if (m_client)
m_client->didReceiveResponse(identifier, response);
String script();
const URL& url() const { return m_url; }
const URL& responseURL() const;
+ const String& responseMIMEType() const { return m_responseMIMEType; }
bool failed() const { return m_failed; }
unsigned long identifier() const { return m_identifier; }
const ResourceError& error() const { return m_error; }
StringBuilder m_script;
URL m_url;
URL m_responseURL;
+ String m_responseMIMEType;
unsigned long m_identifier { 0 };
bool m_failed { false };
bool m_finishing { false };