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

Unified Diff: Source/modules/webusb/NavigatorUSB.cpp

Issue 1262163003: Add WebUSB bindings and client interface [part 1] (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Handle null navigator.frame() without ASSERT Created 5 years, 5 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/webusb/NavigatorUSB.h ('k') | Source/modules/webusb/NavigatorUSB.idl » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/webusb/NavigatorUSB.cpp
diff --git a/Source/modules/webusb/NavigatorUSB.cpp b/Source/modules/webusb/NavigatorUSB.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..bd854f0bcb3e176561105e5b2986469d237f25c2
--- /dev/null
+++ b/Source/modules/webusb/NavigatorUSB.cpp
@@ -0,0 +1,50 @@
+// Copyright 2015 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/webusb/NavigatorUSB.h"
+
+#include "core/frame/Navigator.h"
+#include "modules/webusb/USB.h"
+
+namespace blink {
+
+NavigatorUSB& NavigatorUSB::from(Navigator& navigator)
+{
+ NavigatorUSB* supplement = static_cast<NavigatorUSB*>(HeapSupplement<Navigator>::from(navigator, supplementName()));
+ if (!supplement) {
+ supplement = new NavigatorUSB(navigator);
+ provideTo(navigator, supplementName(), supplement);
+ }
+ return *supplement;
+}
+
+USB* NavigatorUSB::usb(Navigator& navigator)
+{
+ return NavigatorUSB::from(navigator).usb();
+}
+
+USB* NavigatorUSB::usb()
+{
+ return m_usb;
+}
+
+DEFINE_TRACE(NavigatorUSB)
+{
+ visitor->trace(m_usb);
+ HeapSupplement<Navigator>::trace(visitor);
+}
+
+NavigatorUSB::NavigatorUSB(Navigator& navigator)
+{
+ if (navigator.frame())
+ m_usb = USB::create(*navigator.frame());
+}
+
+const char* NavigatorUSB::supplementName()
+{
+ return "NavigatorUSB";
+}
+
+} // namespace blink
« no previous file with comments | « Source/modules/webusb/NavigatorUSB.h ('k') | Source/modules/webusb/NavigatorUSB.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698