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 "public/platform/WebWakeLockType.h" |
| 11 |
| 12 namespace blink { |
| 13 |
| 14 static WebWakeLockType stringToWakeLockType(const AtomicString& wakeLockString) |
| 15 { |
| 16 WebWakeLockType type = WebWakeLockNone; |
| 17 if (wakeLockString == "screen") |
| 18 type = WebWakeLockScreen; |
| 19 else if (wakeLockString == "system") |
| 20 type = WebWakeLockSystem; |
| 21 else |
| 22 ASSERT_NOT_REACHED(); |
| 23 return type; |
| 24 } |
| 25 |
| 26 PassRefPtrWillBeRawPtr<WakeLock> WakeLock::create(ExecutionContext* context) |
| 27 { |
| 28 RefPtrWillBeRawPtr<WakeLock> wakeLock = adoptRefWillBeNoop(new WakeLock(cont
ext)); |
| 29 wakeLock->suspendIfNeeded(); |
| 30 return wakeLock.release(); |
| 31 } |
| 32 |
| 33 WakeLock::WakeLock(ExecutionContext* context) |
| 34 : ActiveDOMObject(context) |
| 35 { |
| 36 ScriptWrappable::init(this); |
| 37 } |
| 38 |
| 39 WakeLock::~WakeLock() |
| 40 { |
| 41 } |
| 42 |
| 43 Document* WakeLock::document() const |
| 44 { |
| 45 return toDocument(executionContext()); |
| 46 } |
| 47 |
| 48 LocalFrame* WakeLock::frame() const |
| 49 { |
| 50 return document() ? document()->frame() : 0; |
| 51 } |
| 52 |
| 53 Page* WakeLock::page() const |
| 54 { |
| 55 return document() ? document()->page() : 0; |
| 56 } |
| 57 |
| 58 ScriptPromise WakeLock::request(ScriptState* scriptState, const AtomicString& ty
pe) |
| 59 { |
| 60 return WakeLockController::from(page())->requestWakeLock(scriptState, string
ToWakeLockType(type)); |
| 61 } |
| 62 |
| 63 ScriptPromise WakeLock::release(ScriptState* scriptState, const AtomicString& ty
pe) |
| 64 { |
| 65 return WakeLockController::from(page())->requestWakeUnlock(scriptState, stri
ngToWakeLockType(type)); |
| 66 } |
| 67 |
| 68 bool WakeLock::isHeld(const AtomicString& type) |
| 69 { |
| 70 return WakeLockController::from(page())->isHeld(stringToWakeLockType(type)); |
| 71 } |
| 72 |
| 73 } // namespace WebCore |
OLD | NEW |