Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(995)

Unified Diff: Source/modules/wake_lock/WakeLock.cpp

Issue 399313003: Initial implementation of API WakeLock. Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Implementation of WakeLock API on JavaScript side Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698