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 @@
#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/dom_exception.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/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/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/wtf/functional.h"
......@@ -31,16 +32,16 @@ bool DocumentPictureInPicture::pictureInPictureEnabled(Document& document) {
// static
ScriptPromise DocumentPictureInPicture::exitPictureInPicture(
ScriptState* script_state,
Document& document) {
Document& document,
ExceptionState& exception_state) {
PictureInPictureControllerImpl& controller =
PictureInPictureControllerImpl::From(document);
Element* picture_in_picture_element = controller.PictureInPictureElement();
if (!picture_in_picture_element) {
return ScriptPromise::RejectWithDOMException(
script_state,
MakeGarbageCollected<DOMException>(DOMExceptionCode::kInvalidStateError,
kNoPictureInPictureElement));
exception_state.ThrowDOMException(DOMExceptionCode::kInvalidStateError,
kNoPictureInPictureElement);
return ScriptPromise();
}
auto* resolver = MakeGarbageCollected<ScriptPromiseResolver>(script_state);
......
......@@ -11,6 +11,7 @@ namespace blink {
class Document;
class Element;
class ExceptionState;
class ScriptPromise;
class ScriptState;
class TreeScope;
......@@ -21,7 +22,9 @@ class DocumentPictureInPicture {
public:
static bool pictureInPictureEnabled(Document&);
static ScriptPromise exitPictureInPicture(ScriptState*, Document&);
static ScriptPromise exitPictureInPicture(ScriptState*,
Document&,
ExceptionState&);
static Element* pictureInPictureElement(TreeScope&);
};
......
......@@ -11,7 +11,7 @@
partial interface Document {
[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.
[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