Commit daddb975 authored by Mounir Lamouri's avatar Mounir Lamouri Committed by Commit Bot

Screen Orientation: do not fire the event on the PageVisibilityChanged stack.

This is also delaying resolving the promise to make sure the order stays the
same.

Bug: 960657
Change-Id: I92095affb8223dd60346796eec1b6cd7d3f0efc1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1617552Reviewed-by: default avatarHiroshige Hayashizaki <hiroshige@chromium.org>
Commit-Queue: Mounir Lamouri <mlamouri@chromium.org>
Cr-Commit-Position: refs/heads/master@{#660953}
parent 8b941999
......@@ -4,9 +4,11 @@
#include "third_party/blink/renderer/modules/screen_orientation/lock_orientation_callback.h"
#include "third_party/blink/public/platform/task_type.h"
#include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h"
#include "third_party/blink/renderer/core/dom/dom_exception.h"
#include "third_party/blink/renderer/modules/screen_orientation/screen_orientation.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
namespace blink {
......@@ -17,7 +19,16 @@ LockOrientationCallback::LockOrientationCallback(
LockOrientationCallback::~LockOrientationCallback() = default;
void LockOrientationCallback::OnSuccess() {
resolver_->Resolve();
// Resolving the promise should be done after the event is fired which is
// delayed to avoid running script on the stack. We then have to delay
// resolving the promise.
resolver_->GetExecutionContext()
->GetTaskRunner(TaskType::kMiscPlatformAPI)
->PostTask(FROM_HERE, WTF::Bind(
[](ScriptPromiseResolver* resolver) {
resolver->Resolve();
},
std::move(resolver_)));
}
void LockOrientationCallback::OnError(WebLockOrientationError error) {
......
......@@ -153,9 +153,17 @@ void ScreenOrientationControllerImpl::NotifyOrientationChanged() {
// Notify current orientation object.
if (IsActive() && orientation_) {
ScopedAllowFullscreen allow_fullscreen(
ScopedAllowFullscreen::kOrientationChange);
orientation_->DispatchEvent(*Event::Create(event_type_names::kChange));
GetExecutionContext()
->GetTaskRunner(TaskType::kMiscPlatformAPI)
->PostTask(FROM_HERE,
WTF::Bind(
[](ScreenOrientation* orientation) {
ScopedAllowFullscreen allow_fullscreen(
ScopedAllowFullscreen::kOrientationChange);
orientation->DispatchEvent(
*Event::Create(event_type_names::kChange));
},
WrapPersistent(orientation_.Get())));
}
// ... and child frames, if they have a ScreenOrientationControllerImpl.
......
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