mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 12:51:06 +00:00
Bug 1341738 - Implement FetchController and FetObserver - part 4 - FetchObserver WebIDL, r=bkelly
This commit is contained in:
parent
e6ad00d782
commit
cd6bd71606
@ -905,7 +905,9 @@ GK_ATOM(onreadystatechange, "onreadystatechange")
|
||||
GK_ATOM(onreceived, "onreceived")
|
||||
GK_ATOM(onremoteheld, "onremoteheld")
|
||||
GK_ATOM(onremoteresumed, "onremoteresumed")
|
||||
GK_ATOM(onrequestprogress, "onrequestprogress")
|
||||
GK_ATOM(onresourcetimingbufferfull, "onresourcetimingbufferfull")
|
||||
GK_ATOM(onresponseprogress, "onresponseprogress")
|
||||
GK_ATOM(onretrieving, "onretrieving")
|
||||
GK_ATOM(onRequest, "onRequest")
|
||||
GK_ATOM(onrequestmediaplaystatus, "onrequestmediaplaystatus")
|
||||
|
65
dom/fetch/FetchObserver.cpp
Normal file
65
dom/fetch/FetchObserver.cpp
Normal file
@ -0,0 +1,65 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "FetchObserver.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_CLASS(FetchObserver)
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(FetchObserver,
|
||||
DOMEventTargetHelper)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(FetchObserver,
|
||||
DOMEventTargetHelper)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(FetchObserver)
|
||||
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(FetchObserver, DOMEventTargetHelper)
|
||||
NS_IMPL_RELEASE_INHERITED(FetchObserver, DOMEventTargetHelper)
|
||||
|
||||
/* static */ bool
|
||||
FetchObserver::IsEnabled(JSContext* aCx, JSObject* aGlobal)
|
||||
{
|
||||
if (NS_IsMainThread()) {
|
||||
return Preferences::GetBool("dom.fetchObserver.enabled", false);
|
||||
}
|
||||
|
||||
using namespace workers;
|
||||
|
||||
// Otherwise, check the pref via the WorkerPrivate
|
||||
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
|
||||
if (!workerPrivate) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return workerPrivate->FetchObserverEnabled();
|
||||
}
|
||||
|
||||
FetchObserver::FetchObserver(nsIGlobalObject* aGlobal,
|
||||
FetchState aState)
|
||||
: DOMEventTargetHelper(aGlobal)
|
||||
, mState(aState)
|
||||
{}
|
||||
|
||||
JSObject*
|
||||
FetchObserver::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
||||
{
|
||||
return FetchObserverBinding::Wrap(aCx, this, aGivenProto);
|
||||
}
|
||||
|
||||
FetchState
|
||||
FetchObserver::State() const
|
||||
{
|
||||
return mState;
|
||||
}
|
||||
|
||||
} // dom namespace
|
||||
} // mozilla namespace
|
46
dom/fetch/FetchObserver.h
Normal file
46
dom/fetch/FetchObserver.h
Normal file
@ -0,0 +1,46 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef mozilla_dom_FetchObserver_h
|
||||
#define mozilla_dom_FetchObserver_h
|
||||
|
||||
#include "mozilla/DOMEventTargetHelper.h"
|
||||
#include "mozilla/dom/FetchObserverBinding.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class FetchObserver final : public DOMEventTargetHelper
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FetchObserver, DOMEventTargetHelper)
|
||||
|
||||
static bool
|
||||
IsEnabled(JSContext* aCx, JSObject* aGlobal);
|
||||
|
||||
FetchObserver(nsIGlobalObject* aGlobal, FetchState aState);
|
||||
|
||||
JSObject*
|
||||
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
FetchState
|
||||
State() const;
|
||||
|
||||
IMPL_EVENT_HANDLER(statechange);
|
||||
IMPL_EVENT_HANDLER(requestprogress);
|
||||
IMPL_EVENT_HANDLER(responseprogress);
|
||||
|
||||
private:
|
||||
~FetchObserver() = default;
|
||||
|
||||
FetchState mState;
|
||||
};
|
||||
|
||||
} // dom namespace
|
||||
} // mozilla namespace
|
||||
|
||||
#endif // mozilla_dom_FetchObserver_h
|
@ -14,6 +14,7 @@ EXPORTS.mozilla.dom += [
|
||||
'FetchController.h',
|
||||
'FetchDriver.h',
|
||||
'FetchIPCTypes.h',
|
||||
'FetchObserver.h',
|
||||
'FetchSignal.h',
|
||||
'FetchUtil.h',
|
||||
'Headers.h',
|
||||
@ -30,6 +31,7 @@ UNIFIED_SOURCES += [
|
||||
'Fetch.cpp',
|
||||
'FetchController.cpp',
|
||||
'FetchDriver.cpp',
|
||||
'FetchObserver.cpp',
|
||||
'FetchSignal.cpp',
|
||||
'FetchUtil.cpp',
|
||||
'Headers.cpp',
|
||||
|
33
dom/tests/mochitest/fetch/file_fetch_observer.html
Normal file
33
dom/tests/mochitest/fetch/file_fetch_observer.html
Normal file
@ -0,0 +1,33 @@
|
||||
<script>
|
||||
function ok(a, msg) {
|
||||
parent.postMessage({ type: "check", status: !!a, message: msg }, "*");
|
||||
}
|
||||
|
||||
function is(a, b, msg) {
|
||||
ok(a === b, msg);
|
||||
}
|
||||
|
||||
function testObserver() {
|
||||
ok("FetchObserver" in self, "We have a FetchObserver prototype");
|
||||
|
||||
fetch('data:,foo', { observe: o => {
|
||||
}});
|
||||
}
|
||||
|
||||
var steps = [
|
||||
testObserver,
|
||||
];
|
||||
|
||||
function next() {
|
||||
if (!steps.length) {
|
||||
parent.postMessage({ type: "finish" }, "*");
|
||||
return;
|
||||
}
|
||||
|
||||
var step = steps.shift();
|
||||
step();
|
||||
}
|
||||
|
||||
next();
|
||||
|
||||
</script>
|
@ -7,6 +7,7 @@ support-files =
|
||||
test_fetch_basic.js
|
||||
test_fetch_basic_http.js
|
||||
test_fetch_cors.js
|
||||
file_fetch_observer.html
|
||||
test_formdataparsing.js
|
||||
test_headers_common.js
|
||||
test_request.js
|
||||
@ -55,6 +56,7 @@ skip-if = toolkit == 'android' && debug # Bug 1210282
|
||||
[test_fetch_cors_sw_empty_reroute.html]
|
||||
skip-if = toolkit == 'android' && debug # Bug 1210282
|
||||
[test_fetch_csp_block.html]
|
||||
[test_fetch_observer.html]
|
||||
[test_fetch_user_control_rp.html]
|
||||
[test_formdataparsing.html]
|
||||
[test_formdataparsing_sw_reroute.html]
|
||||
|
40
dom/tests/mochitest/fetch/test_fetch_observer.html
Normal file
40
dom/tests/mochitest/fetch/test_fetch_observer.html
Normal file
@ -0,0 +1,40 @@
|
||||
<!--
|
||||
Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/
|
||||
-->
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test FetchObserver</title>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
||||
</head>
|
||||
<body>
|
||||
<script class="testbody" type="text/javascript">
|
||||
|
||||
SpecialPowers.pushPrefEnv({"set": [["dom.fetchObserver.enabled", true ]]}, () => {
|
||||
let ifr = document.createElement('iframe');
|
||||
ifr.src = "file_fetch_observer.html";
|
||||
document.body.appendChild(ifr);
|
||||
|
||||
onmessage = function(e) {
|
||||
if (e.data.type == "finish") {
|
||||
SimpleTest.finish();
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.data.type == "check") {
|
||||
ok(e.data.status, e.data.message);
|
||||
return;
|
||||
}
|
||||
|
||||
ok(false, "Something when wrong.");
|
||||
}
|
||||
});
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
27
dom/webidl/FetchObserver.webidl
Normal file
27
dom/webidl/FetchObserver.webidl
Normal file
@ -0,0 +1,27 @@
|
||||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
callback interface ObserverCallback {
|
||||
void handleEvent(FetchObserver observer);
|
||||
};
|
||||
|
||||
enum FetchState {
|
||||
// Pending states
|
||||
"requesting", "responding",
|
||||
// Final states
|
||||
"aborted", "errored", "complete"
|
||||
};
|
||||
|
||||
[Exposed=(Window,Worker),
|
||||
Func="FetchObserver::IsEnabled"]
|
||||
interface FetchObserver : EventTarget {
|
||||
readonly attribute FetchState state;
|
||||
|
||||
// Events
|
||||
attribute EventHandler onstatechange;
|
||||
attribute EventHandler onrequestprogress;
|
||||
attribute EventHandler onresponseprogress;
|
||||
};
|
@ -50,6 +50,9 @@ dictionary RequestInit {
|
||||
|
||||
[Func="FetchController::IsEnabled"]
|
||||
FetchSignal signal;
|
||||
|
||||
[Func="FetchObserver::IsEnabled"]
|
||||
ObserverCallback observe;
|
||||
};
|
||||
|
||||
// Gecko currently does not ship RequestContext, so please don't use it in IDL
|
||||
|
@ -518,6 +518,7 @@ WEBIDL_FILES = [
|
||||
'Fetch.webidl',
|
||||
'FetchController.webidl',
|
||||
'FetchEvent.webidl',
|
||||
'FetchObserver.webidl',
|
||||
'FetchSignal.webidl',
|
||||
'File.webidl',
|
||||
'FileList.webidl',
|
||||
|
@ -41,6 +41,7 @@ WORKER_SIMPLE_PREF("gfx.offscreencanvas.enabled", OffscreenCanvasEnabled, OFFSCR
|
||||
WORKER_SIMPLE_PREF("dom.webkitBlink.dirPicker.enabled", WebkitBlinkDirectoryPickerEnabled, DOM_WEBKITBLINK_DIRPICKER_WEBKITBLINK)
|
||||
WORKER_SIMPLE_PREF("dom.netinfo.enabled", NetworkInformationEnabled, NETWORKINFORMATION_ENABLED)
|
||||
WORKER_SIMPLE_PREF("dom.fetchController.enabled", FetchControllerEnabled, FETCHCONTROLLER_ENABLED)
|
||||
WORKER_SIMPLE_PREF("dom.fetchObserver.enabled", FetchObserverEnabled, FETCHOBSERVER_ENABLED)
|
||||
WORKER_PREF("intl.accept_languages", PrefLanguagesChanged)
|
||||
WORKER_PREF("general.appname.override", AppNameOverrideChanged)
|
||||
WORKER_PREF("general.appversion.override", AppVersionOverrideChanged)
|
||||
|
Loading…
Reference in New Issue
Block a user