Commit 06a245bd authored by Jeremy Roman's avatar Jeremy Roman Committed by Commit Bot

Use [RaisesException] for immediate promise rejections in...

Use [RaisesException] for immediate promise rejections in /third_party/blink/renderer/modules/picture_in_picture.

The bindings layer implicitly converts thrown exceptions in promise-returning
functions to promise rejections, and using ExceptionState makes this more
similar to ordinarily throwing exceptions, notably by including the auto-
generated exception context that makes it easier to see what IDL operation
caused an exception to be thrown.

This CL was uploaded by git cl split.

R=beaufort.francois@gmail.com

Bug: 1001114
Change-Id: I0d6265ccaccab772bac9e7d2ff111ff111432000
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1786670
Auto-Submit: Jeremy Roman <jbroman@chromium.org>
Commit-Queue: François Beaufort <beaufort.francois@gmail.com>
Reviewed-by: default avatarFrançois Beaufort <beaufort.francois@gmail.com>
Cr-Commit-Position: refs/heads/master@{#693843}
parent 2cf9b457
...@@ -5,11 +5,12 @@ ...@@ -5,11 +5,12 @@
#include "third_party/blink/renderer/modules/picture_in_picture/document_picture_in_picture.h" #include "third_party/blink/renderer/modules/picture_in_picture/document_picture_in_picture.h"
#include "third_party/blink/renderer/core/dom/document.h" #include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/core/dom/element.h" #include "third_party/blink/renderer/core/dom/element.h"
#include "third_party/blink/renderer/core/dom/events/event.h" #include "third_party/blink/renderer/core/dom/events/event.h"
#include "third_party/blink/renderer/core/html/media/html_video_element.h" #include "third_party/blink/renderer/core/html/media/html_video_element.h"
#include "third_party/blink/renderer/modules/picture_in_picture/picture_in_picture_controller_impl.h" #include "third_party/blink/renderer/modules/picture_in_picture/picture_in_picture_controller_impl.h"
#include "third_party/blink/renderer/platform/bindings/exception_code.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/heap/heap.h" #include "third_party/blink/renderer/platform/heap/heap.h"
#include "third_party/blink/renderer/platform/wtf/functional.h" #include "third_party/blink/renderer/platform/wtf/functional.h"
...@@ -31,16 +32,16 @@ bool DocumentPictureInPicture::pictureInPictureEnabled(Document& document) { ...@@ -31,16 +32,16 @@ bool DocumentPictureInPicture::pictureInPictureEnabled(Document& document) {
// static // static
ScriptPromise DocumentPictureInPicture::exitPictureInPicture( ScriptPromise DocumentPictureInPicture::exitPictureInPicture(
ScriptState* script_state, ScriptState* script_state,
Document& document) { Document& document,
ExceptionState& exception_state) {
PictureInPictureControllerImpl& controller = PictureInPictureControllerImpl& controller =
PictureInPictureControllerImpl::From(document); PictureInPictureControllerImpl::From(document);
Element* picture_in_picture_element = controller.PictureInPictureElement(); Element* picture_in_picture_element = controller.PictureInPictureElement();
if (!picture_in_picture_element) { if (!picture_in_picture_element) {
return ScriptPromise::RejectWithDOMException( exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError,
script_state, kNoPictureInPictureElement);
MakeGarbageCollected<DOMException>(DOMExceptionCode::kInvalidStateError, return ScriptPromise();
kNoPictureInPictureElement));
} }
auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state); auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state);
......
...@@ -11,6 +11,7 @@ namespace blink { ...@@ -11,6 +11,7 @@ namespace blink {
class Document; class Document;
class Element; class Element;
class ExceptionState;
class ScriptPromise; class ScriptPromise;
class ScriptState; class ScriptState;
class TreeScope; class TreeScope;
...@@ -21,7 +22,9 @@ class DocumentPictureInPicture { ...@@ -21,7 +22,9 @@ class DocumentPictureInPicture {
public: public:
static bool pictureInPictureEnabled(Document&); static bool pictureInPictureEnabled(Document&);
static ScriptPromise exitPictureInPicture(ScriptState*, Document&); static ScriptPromise exitPictureInPicture(ScriptState*,
Document&,
ExceptionState&);
static Element* pictureInPictureElement(TreeScope&); static Element* pictureInPictureElement(TreeScope&);
}; };
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
partial interface Document { partial interface Document {
[Measure] readonly attribute boolean pictureInPictureEnabled; [Measure] readonly attribute boolean pictureInPictureEnabled;
[CallWith=ScriptState, Measure, NewObject] Promise<void> exitPictureInPicture(); [CallWith=ScriptState, RaisesException, Measure, NewObject] Promise<void> exitPictureInPicture();
// TODO(crbug.com/656517): Define this attribute in DocumentOrShadowRoot. // TODO(crbug.com/656517): Define this attribute in DocumentOrShadowRoot.
[Measure] readonly attribute HTMLVideoElement? pictureInPictureElement; [Measure] readonly attribute HTMLVideoElement? pictureInPictureElement;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment