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

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: 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
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..f97ae28ec74f741fe3881563ebee13837a66fcea
--- /dev/null
+++ b/Source/modules/webusb/NavigatorUSB.cpp
@@ -0,0 +1,51 @@
+// 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 {
+
+// static
haraken 2015/07/30 11:26:52 Drop the comment.
Ken Rockot(use gerrit already) 2015/07/30 18:06:54 Done.
+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;
+}
+
+// static
haraken 2015/07/30 11:26:51 Drop the comment.
Ken Rockot(use gerrit already) 2015/07/30 18:06:54 Done.
+USB* NavigatorUSB::usb(Navigator& navigator)
+{
+ return NavigatorUSB::from(navigator).usb();
+}
+
+USB* NavigatorUSB::usb()
+{
+ return m_usb.get();
haraken 2015/07/30 11:26:52 .get() won't be needed.
Ken Rockot(use gerrit already) 2015/07/30 18:06:54 Done.
+}
+
+DEFINE_TRACE(NavigatorUSB)
+{
+ visitor->trace(m_usb);
+ HeapSupplement<Navigator>::trace(visitor);
+}
+
+NavigatorUSB::NavigatorUSB(Navigator& navigator)
+ : m_usb(USB::create(*navigator.frame()))
haraken 2015/07/30 11:26:52 Is it guaranteed that navigator.frame() returns a
Ken Rockot(use gerrit already) 2015/07/30 18:06:54 That assumption seems to be made in a lot of place
+{
+}
+
+const char* NavigatorUSB::supplementName()
+{
+ return "NavigatorUSB";
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698