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

Unified Diff: Source/modules/wake_lock/NavigatorWakeLock.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/NavigatorWakeLock.cpp
diff --git a/Source/modules/wake_lock/NavigatorWakeLock.cpp b/Source/modules/wake_lock/NavigatorWakeLock.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..283546e33771ec340b680da66bda060180f6a422
--- /dev/null
+++ b/Source/modules/wake_lock/NavigatorWakeLock.cpp
@@ -0,0 +1,58 @@
+// 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/NavigatorWakeLock.h"
+
+#include "core/dom/Document.h"
+#include "core/frame/LocalFrame.h"
+#include "core/frame/Navigator.h"
+#include "modules/wake_lock/WakeLock.h"
+
+namespace blink {
+
+NavigatorWakeLock::NavigatorWakeLock(LocalFrame* frame)
+ : DOMWindowProperty(frame)
mlamouri (slow - plz ping) 2014/08/18 12:15:52 I would keep this ctor as a default ctor (ie. no L
redchenko 2014/08/19 16:42:19 Done.
+{
+}
+
+NavigatorWakeLock::~NavigatorWakeLock()
+{
+}
+
+const char* NavigatorWakeLock::supplementName()
+{
+ return "NavigatorWakeLock";
+}
+
+NavigatorWakeLock& NavigatorWakeLock::from(Navigator& navigator)
+{
+ NavigatorWakeLock* supplement = static_cast<NavigatorWakeLock*>(WillBeHeapSupplement<Navigator>::from(navigator, supplementName()));
+ if (!supplement) {
+ supplement = new NavigatorWakeLock(navigator.frame());
+ provideTo(navigator, supplementName(), adoptPtrWillBeNoop(supplement));
+ }
+ return *supplement;
+}
+
+WakeLock* NavigatorWakeLock::wakeLock(Navigator& navigator)
+{
+ return NavigatorWakeLock::from(navigator).wakeLock();
+}
+
+WakeLock* NavigatorWakeLock::wakeLock() const
+{
+ if (!m_wakeLock && frame())
+ m_wakeLock = WakeLock::create(frame()->document());
mlamouri (slow - plz ping) 2014/08/18 12:15:52 It seems that what you really want here is not a f
redchenko 2014/08/19 16:42:19 Done.
+ return m_wakeLock.get();
+}
+
+void NavigatorWakeLock::trace(Visitor* visitor)
+{
+ ASSERT(visitor);
mlamouri (slow - plz ping) 2014/08/18 12:15:52 I don't think you need that.
redchenko 2014/08/19 16:42:19 Done.
+ visitor->trace(m_wakeLock);
+ WillBeHeapSupplement<Navigator>::trace(visitor);
+}
+
+} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698