Index: Source/modules/wake_lock/WakeLock.cpp |
diff --git a/Source/modules/wake_lock/WakeLock.cpp b/Source/modules/wake_lock/WakeLock.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1854543ed7edf58fd8282e95d757e304051c395e |
--- /dev/null |
+++ b/Source/modules/wake_lock/WakeLock.cpp |
@@ -0,0 +1,73 @@ |
+// Copyright 2014 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 "config.h" |
+#include "modules/wake_lock/WakeLock.h" |
+ |
+#include "core/dom/Document.h" |
+#include "modules/wake_lock/WakeLockController.h" |
+#include "public/platform/WebWakeLockType.h" |
+ |
+namespace blink { |
+ |
+static WebWakeLockType stringToWakeLockType(const AtomicString& wakeLockString) |
+{ |
+ WebWakeLockType type = WebWakeLockNone; |
+ if (wakeLockString == "screen") |
+ type = WebWakeLockScreen; |
+ else if (wakeLockString == "system") |
+ type = WebWakeLockSystem; |
+ else |
+ ASSERT_NOT_REACHED(); |
+ return type; |
+} |
+ |
+PassRefPtrWillBeRawPtr<WakeLock> WakeLock::create(ExecutionContext* context) |
+{ |
+ RefPtrWillBeRawPtr<WakeLock> wakeLock = adoptRefWillBeNoop(new WakeLock(context)); |
+ wakeLock->suspendIfNeeded(); |
+ return wakeLock.release(); |
+} |
+ |
+WakeLock::WakeLock(ExecutionContext* context) |
+ : ActiveDOMObject(context) |
+{ |
+ ScriptWrappable::init(this); |
+} |
+ |
+WakeLock::~WakeLock() |
+{ |
+} |
+ |
+Document* WakeLock::document() const |
+{ |
+ return toDocument(executionContext()); |
+} |
+ |
+LocalFrame* WakeLock::frame() const |
+{ |
+ return document() ? document()->frame() : 0; |
+} |
+ |
+Page* WakeLock::page() const |
+{ |
+ return document() ? document()->page() : 0; |
+} |
+ |
+ScriptPromise WakeLock::request(ScriptState* scriptState, const AtomicString& type) |
+{ |
+ return WakeLockController::from(page())->requestWakeLock(scriptState, stringToWakeLockType(type)); |
+} |
+ |
+ScriptPromise WakeLock::release(ScriptState* scriptState, const AtomicString& type) |
+{ |
+ return WakeLockController::from(page())->requestWakeUnlock(scriptState, stringToWakeLockType(type)); |
+} |
+ |
+bool WakeLock::isHeld(const AtomicString& type) |
+{ |
+ return WakeLockController::from(page())->isHeld(stringToWakeLockType(type)); |
+} |
+ |
+} // namespace WebCore |