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

Unified Diff: Source/modules/battery/NavigatorBattery.cpp

Issue 182613002: Add support to Battery Status API in blink. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add NeedsRebaseline for 4 tests for Mac. Created 6 years, 9 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/battery/NavigatorBattery.cpp
diff --git a/Source/modules/battery/NavigatorBattery.cpp b/Source/modules/battery/NavigatorBattery.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..612bb951e25d210bed10f56d2e179af06b12a6eb
--- /dev/null
+++ b/Source/modules/battery/NavigatorBattery.cpp
@@ -0,0 +1,48 @@
+// 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/battery/NavigatorBattery.h"
+
+#include "core/frame/LocalFrame.h"
+#include "modules/battery/BatteryManager.h"
+
+namespace WebCore {
+
+NavigatorBattery::NavigatorBattery()
+{
+}
+
+NavigatorBattery::~NavigatorBattery()
+{
+}
+
+BatteryManager* NavigatorBattery::battery(Navigator& navigator)
+{
+ return NavigatorBattery::from(navigator).batteryManager(navigator);
+}
+
+BatteryManager* NavigatorBattery::batteryManager(Navigator& navigator)
+{
+ if (!m_batteryManager && navigator.frame())
+ m_batteryManager = BatteryManager::create(navigator.frame()->document());
+ return m_batteryManager.get();
+}
+
+const char* NavigatorBattery::supplementName()
+{
+ return "NavigatorBattery";
+}
+
+NavigatorBattery& NavigatorBattery::from(Navigator& navigator)
+{
+ NavigatorBattery* supplement = static_cast<NavigatorBattery*>(Supplement<Navigator>::from(navigator, supplementName()));
+ if (!supplement) {
+ supplement = new NavigatorBattery();
+ provideTo(navigator, supplementName(), adoptPtr(supplement));
+ }
+ return *supplement;
+}
+
+} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698