OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "config.h" |
| 6 #include "modules/wake_lock/WakeLock.h" |
| 7 |
| 8 #include "core/dom/Document.h" |
| 9 #include "modules/wake_lock/WakeLockController.h" |
| 10 #include "modules/wake_lock/WakeLockPromiseResolver.h" |
| 11 #include "public/platform/WebWakeLockType.h" |
| 12 |
| 13 namespace blink { |
| 14 |
| 15 static WebWakeLockType stringToWakeLockType(const AtomicString& wakeLockString) |
| 16 { |
| 17 WebWakeLockType type = WebWakeLockGuard; |
| 18 if (wakeLockString == "screen") |
| 19 type = WebWakeLockScreen; |
| 20 else if (wakeLockString == "system") |
| 21 type = WebWakeLockSystem; |
| 22 else |
| 23 ASSERT_NOT_REACHED(); |
| 24 return type; |
| 25 } |
| 26 |
| 27 PassRefPtrWillBeRawPtr<WakeLock> WakeLock::create(ExecutionContext* context) |
| 28 { |
| 29 RefPtrWillBeRawPtr<WakeLock> wakeLock = adoptRefWillBeNoop(new WakeLock(cont
ext)); |
| 30 wakeLock->suspendIfNeeded(); |
| 31 return wakeLock.release(); |
| 32 } |
| 33 |
| 34 WakeLock::WakeLock(ExecutionContext* context) |
| 35 : ActiveDOMObject(context) |
| 36 { |
| 37 ScriptWrappable::init(this); |
| 38 } |
| 39 |
| 40 WakeLock::~WakeLock() |
| 41 { |
| 42 } |
| 43 |
| 44 Document* WakeLock::document() const |
| 45 { |
| 46 return toDocument(executionContext()); |
| 47 } |
| 48 |
| 49 Page* WakeLock::page() const |
| 50 { |
| 51 return document() ? document()->page() : 0; |
| 52 } |
| 53 |
| 54 ScriptPromise WakeLock::request(ScriptState* scriptState, const AtomicString& st
ringType) |
| 55 { |
| 56 WebWakeLockType type = stringToWakeLockType(stringType); |
| 57 if (WakeLockController* controller = WakeLockController::from(page())) |
| 58 return controller->requestWakeLock(scriptState, type); |
| 59 |
| 60 WakeLockPromiseResolverOwnPtr resolver = WakeLockPromiseResolver::create(scr
iptState, type); |
| 61 resolver->reject(); |
| 62 return resolver->promise(); |
| 63 } |
| 64 |
| 65 ScriptPromise WakeLock::release(ScriptState* scriptState, const AtomicString& st
ringType) |
| 66 { |
| 67 WebWakeLockType type = stringToWakeLockType(stringType); |
| 68 if (WakeLockController* controller = WakeLockController::from(page())) |
| 69 return controller->requestWakeUnlock(scriptState, type); |
| 70 |
| 71 WakeLockPromiseResolverOwnPtr resolver = WakeLockPromiseResolver::create(scr
iptState, type); |
| 72 resolver->reject(); |
| 73 return resolver->promise(); |
| 74 } |
| 75 |
| 76 bool WakeLock::isHeld(const AtomicString& type) |
| 77 { |
| 78 if (WakeLockController* controller = WakeLockController::from(page())) |
| 79 return controller->isHeld(stringToWakeLockType(type)); |
| 80 |
| 81 return false; |
| 82 } |
| 83 |
| 84 } // namespace blink |
OLD | NEW |