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

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
« no previous file with comments | « Source/modules/wake_lock/WakeLock.h ('k') | Source/modules/wake_lock/WakeLock.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..f52669d118818b86cfd4231cb305375f5a147e2e
--- /dev/null
+++ b/Source/modules/wake_lock/WakeLock.cpp
@@ -0,0 +1,84 @@
+// 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 "modules/wake_lock/WakeLockPromiseResolver.h"
+#include "public/platform/WebWakeLockType.h"
+
+namespace blink {
+
+static WebWakeLockType stringToWakeLockType(const AtomicString& wakeLockString)
+{
+ WebWakeLockType type = WebWakeLockGuard;
+ 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());
+}
+
+Page* WakeLock::page() const
+{
+ return document() ? document()->page() : 0;
+}
+
+ScriptPromise WakeLock::request(ScriptState* scriptState, const AtomicString& stringType)
+{
+ WebWakeLockType type = stringToWakeLockType(stringType);
+ if (WakeLockController* controller = WakeLockController::from(page()))
+ return controller->requestWakeLock(scriptState, type);
+
+ WakeLockPromiseResolverOwnPtr resolver = WakeLockPromiseResolver::create(scriptState, type);
+ resolver->reject();
+ return resolver->promise();
+}
+
+ScriptPromise WakeLock::release(ScriptState* scriptState, const AtomicString& stringType)
+{
+ WebWakeLockType type = stringToWakeLockType(stringType);
+ if (WakeLockController* controller = WakeLockController::from(page()))
+ return controller->requestWakeUnlock(scriptState, type);
+
+ WakeLockPromiseResolverOwnPtr resolver = WakeLockPromiseResolver::create(scriptState, type);
+ resolver->reject();
+ return resolver->promise();
+}
+
+bool WakeLock::isHeld(const AtomicString& type)
+{
+ if (WakeLockController* controller = WakeLockController::from(page()))
+ return controller->isHeld(stringToWakeLockType(type));
+
+ return false;
+}
+
+} // namespace blink
« no previous file with comments | « Source/modules/wake_lock/WakeLock.h ('k') | Source/modules/wake_lock/WakeLock.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698