diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index c676e5f1f309..3ed57bdf8219 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -187,6 +187,7 @@ #include "mozilla/dom/MessagePort.h" #include "mozilla/dom/MessagePortBinding.h" #include "mozilla/dom/indexedDB/IDBFactory.h" +#include "mozilla/dom/Promise.h" #include "mozilla/dom/StructuredCloneTags.h" @@ -6370,6 +6371,14 @@ nsGlobalWindow::Confirm(const nsAString& aString, bool* aReturn) return rv.ErrorCode(); } +already_AddRefed +nsGlobalWindow::Fetch(const RequestOrScalarValueString& aInput, + const RequestInit& aInit, ErrorResult& aRv) +{ + aRv.Throw(NS_ERROR_NOT_IMPLEMENTED); + return nullptr; +} + void nsGlobalWindow::Prompt(const nsAString& aMessage, const nsAString& aInitial, nsAString& aReturn, ErrorResult& aError) diff --git a/dom/base/nsGlobalWindow.h b/dom/base/nsGlobalWindow.h index df3a119def27..a86310630a81 100644 --- a/dom/base/nsGlobalWindow.h +++ b/dom/base/nsGlobalWindow.h @@ -38,8 +38,10 @@ #include "nsSize.h" #include "mozFlushType.h" #include "prclist.h" +#include "mozilla/dom/RequestBinding.h" #include "mozilla/dom/StorageEvent.h" #include "mozilla/dom/StorageEventBinding.h" +#include "mozilla/dom/UnionTypes.h" #include "nsFrameMessageManager.h" #include "mozilla/LinkedList.h" #include "mozilla/TimeStamp.h" @@ -107,6 +109,7 @@ class MediaQueryList; class MozSelfSupport; class Navigator; class OwningExternalOrWindowProxy; +class Promise; class Selection; class SpeechSynthesis; class WakeLock; @@ -850,6 +853,9 @@ public: void Alert(mozilla::ErrorResult& aError); void Alert(const nsAString& aMessage, mozilla::ErrorResult& aError); bool Confirm(const nsAString& aMessage, mozilla::ErrorResult& aError); + already_AddRefed Fetch(const mozilla::dom::RequestOrScalarValueString& aInput, + const mozilla::dom::RequestInit& aInit, + mozilla::ErrorResult& aRv); void Prompt(const nsAString& aMessage, const nsAString& aInitial, nsAString& aReturn, mozilla::ErrorResult& aError); void Print(mozilla::ErrorResult& aError); diff --git a/dom/webidl/Fetch.webidl b/dom/webidl/Fetch.webidl index 26c9775e696a..a1c66f3579d8 100644 --- a/dom/webidl/Fetch.webidl +++ b/dom/webidl/Fetch.webidl @@ -27,3 +27,10 @@ interface Body { [Throws] Promise text(); }; + +[NoInterfaceObject, Exposed=(Window,Worker)] +interface GlobalFetch { + [Throws, Func="mozilla::dom::Headers::PrefEnabled"] + Promise fetch(RequestInfo input, optional RequestInit init); +}; + diff --git a/dom/webidl/Window.webidl b/dom/webidl/Window.webidl index 7bf30c1de773..2c6e2cc7e8b0 100644 --- a/dom/webidl/Window.webidl +++ b/dom/webidl/Window.webidl @@ -465,3 +465,4 @@ interface ChromeWindow { }; Window implements ChromeWindow; +Window implements GlobalFetch; diff --git a/dom/webidl/WorkerGlobalScope.webidl b/dom/webidl/WorkerGlobalScope.webidl index bc0b2135628e..bbd41aa5ef71 100644 --- a/dom/webidl/WorkerGlobalScope.webidl +++ b/dom/webidl/WorkerGlobalScope.webidl @@ -38,6 +38,7 @@ partial interface WorkerGlobalScope { WorkerGlobalScope implements WindowTimers; WorkerGlobalScope implements WindowBase64; +WorkerGlobalScope implements GlobalFetch; // Not implemented yet: bug 1072107. // WorkerGlobalScope implements FontFaceSource; diff --git a/dom/workers/WorkerScope.cpp b/dom/workers/WorkerScope.cpp index df34df4798e3..3e63247261aa 100644 --- a/dom/workers/WorkerScope.cpp +++ b/dom/workers/WorkerScope.cpp @@ -303,6 +303,14 @@ WorkerGlobalScope::GetPerformance() return mPerformance; } +already_AddRefed +WorkerGlobalScope::Fetch(const RequestOrScalarValueString& aInput, + const RequestInit& aInit, ErrorResult& aRv) +{ + aRv.Throw(NS_ERROR_NOT_IMPLEMENTED); + return nullptr; +} + DedicatedWorkerGlobalScope::DedicatedWorkerGlobalScope(WorkerPrivate* aWorkerPrivate) : WorkerGlobalScope(aWorkerPrivate) { diff --git a/dom/workers/WorkerScope.h b/dom/workers/WorkerScope.h index a683e0670cc6..b522bfe1a237 100644 --- a/dom/workers/WorkerScope.h +++ b/dom/workers/WorkerScope.h @@ -8,6 +8,8 @@ #include "Workers.h" #include "mozilla/DOMEventTargetHelper.h" +#include "mozilla/dom/RequestBinding.h" +#include "mozilla/dom/UnionTypes.h" namespace mozilla { namespace dom { @@ -120,6 +122,9 @@ public: Dump(const Optional& aString) const; Performance* GetPerformance(); + + already_AddRefed + Fetch(const RequestOrScalarValueString& aInput, const RequestInit& aInit, ErrorResult& aRv); }; class DedicatedWorkerGlobalScope MOZ_FINAL : public WorkerGlobalScope diff --git a/dom/workers/test/fetch/worker_interfaces.js b/dom/workers/test/fetch/worker_interfaces.js index 7b2749807815..e3c2700fe0e8 100644 --- a/dom/workers/test/fetch/worker_interfaces.js +++ b/dom/workers/test/fetch/worker_interfaces.js @@ -7,5 +7,6 @@ onmessage = function() { ok(typeof Headers === "function", "Headers should be defined"); ok(typeof Request === "function", "Request should be defined"); ok(typeof Response === "function", "Response should be defined"); + ok(typeof fetch === "function", "fetch() should be defined"); postMessage({ type: 'finish' }); }