Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wake lock: Implement new proposed API.
This is another big update to the implementation, which now follows the API proposed in https://github.com/w3c/wake-lock/issues/226. From a Blink/Chromium internals perspective, things have not changed much, and we still perform the same permission checks and connect to the wake lock service via WakeLockStateRecord. The biggest change is that WakeLockController was merged into WakeLock itself. From an end-user perspective, though, the API now looks like a mix of the old, navigator-based API and the one we implemented a few months ago: * The main idea is that WakeLock.request() no longer returns a promise that does not resolve while the lock is held, as that is not very intuitive. Instead, it returns a new WakeLockSentinel object. * WakeLockSentinel is a new interface that can release() a lock and receive "release" events. * We do go back to a Navigator-based API, but we also support WorkerNavigator. * There is no WakeLockRequest interface or state tracking in the WakeLock interface. * WakeLock.requestPermission() was removed. * Consequently, we now have a WakeLockEvent interface. The changes to the spec still need to land, but there is some rough consensus on what the API should look like, and we do not want to miss the M79 branch cut. Bug: 257511, 1010162 Change-Id: If1baed914ccd9eb7103a1bb71a40529976777ec2 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1849683 Reviewed-by: Kentaro Hara <haraken@chromium.org> Reviewed-by: Bo <boliu@chromium.org> Reviewed-by: Reilly Grant <reillyg@chromium.org> Commit-Queue: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com> Cr-Commit-Position: refs/heads/master@{#705632}
- Loading branch information
Showing
60 changed files
with
1,281 additions
and
1,217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,5 +77,6 @@ | |
ImplementedAs: "DOMWebSocket", | ||
}, | ||
"USB", | ||
"WakeLockSentinel", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
third_party/blink/renderer/modules/wake_lock/navigator_wake_lock.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "third_party/blink/renderer/modules/wake_lock/navigator_wake_lock.h" | ||
|
||
#include "third_party/blink/renderer/core/dom/document.h" | ||
#include "third_party/blink/renderer/core/frame/local_frame.h" | ||
#include "third_party/blink/renderer/core/frame/navigator.h" | ||
#include "third_party/blink/renderer/modules/wake_lock/wake_lock.h" | ||
|
||
namespace blink { | ||
|
||
NavigatorWakeLock::NavigatorWakeLock(Navigator& navigator) | ||
: Supplement<Navigator>(navigator) {} | ||
|
||
WakeLock* NavigatorWakeLock::GetWakeLock() { | ||
if (!wake_lock_) { | ||
auto* frame = GetSupplementable()->GetFrame(); | ||
if (frame) { | ||
DCHECK(frame->GetDocument()); | ||
wake_lock_ = MakeGarbageCollected<WakeLock>(*frame->GetDocument()); | ||
} | ||
} | ||
return wake_lock_; | ||
} | ||
|
||
// static | ||
const char NavigatorWakeLock::kSupplementName[] = "NavigatorWakeLock"; | ||
|
||
// static | ||
NavigatorWakeLock& NavigatorWakeLock::From(Navigator& navigator) { | ||
NavigatorWakeLock* supplement = | ||
Supplement<Navigator>::From<NavigatorWakeLock>(navigator); | ||
if (!supplement) { | ||
supplement = MakeGarbageCollected<NavigatorWakeLock>(navigator); | ||
ProvideTo(navigator, supplement); | ||
} | ||
return *supplement; | ||
} | ||
|
||
// static | ||
WakeLock* NavigatorWakeLock::wakeLock(Navigator& navigator) { | ||
return NavigatorWakeLock::From(navigator).GetWakeLock(); | ||
} | ||
|
||
void NavigatorWakeLock::Trace(blink::Visitor* visitor) { | ||
visitor->Trace(wake_lock_); | ||
Supplement<Navigator>::Trace(visitor); | ||
} | ||
|
||
} // namespace blink |
39 changes: 39 additions & 0 deletions
39
third_party/blink/renderer/modules/wake_lock/navigator_wake_lock.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_WAKE_LOCK_NAVIGATOR_WAKE_LOCK_H_ | ||
#define THIRD_PARTY_BLINK_RENDERER_MODULES_WAKE_LOCK_NAVIGATOR_WAKE_LOCK_H_ | ||
|
||
#include "third_party/blink/renderer/platform/heap/handle.h" | ||
#include "third_party/blink/renderer/platform/supplementable.h" | ||
|
||
namespace blink { | ||
|
||
class Navigator; | ||
class WakeLock; | ||
|
||
class NavigatorWakeLock final : public GarbageCollected<NavigatorWakeLock>, | ||
public Supplement<Navigator> { | ||
USING_GARBAGE_COLLECTED_MIXIN(NavigatorWakeLock); | ||
|
||
public: | ||
static const char kSupplementName[]; | ||
|
||
static NavigatorWakeLock& From(Navigator&); | ||
|
||
static WakeLock* wakeLock(Navigator&); | ||
|
||
explicit NavigatorWakeLock(Navigator&); | ||
|
||
void Trace(blink::Visitor*) override; | ||
|
||
private: | ||
WakeLock* GetWakeLock(); | ||
|
||
Member<WakeLock> wake_lock_; | ||
}; | ||
|
||
} // namespace blink | ||
|
||
#endif // THIRD_PARTY_BLINK_RENDERER_MODULES_WAKE_LOCK_NAVIGATOR_WAKE_LOCK_H_ |
11 changes: 11 additions & 0 deletions
11
third_party/blink/renderer/modules/wake_lock/navigator_wake_lock.idl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright 2019 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
[ | ||
ImplementedAs=NavigatorWakeLock, | ||
RuntimeEnabled=WakeLock, | ||
SecureContext | ||
] partial interface Navigator { | ||
[SameObject] readonly attribute WakeLock wakeLock; | ||
}; |
Oops, something went wrong.