| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "modules/nfc/NavigatorNFC.h" | 5 #include "modules/nfc/NavigatorNFC.h" |
| 6 | 6 |
| 7 #include "core/frame/Navigator.h" | 7 #include "core/frame/Navigator.h" |
| 8 #include "modules/nfc/NFC.h" | 8 #include "modules/nfc/NFC.h" |
| 9 | 9 |
| 10 namespace blink { | 10 namespace blink { |
| 11 | 11 |
| 12 NavigatorNFC::NavigatorNFC() {} | 12 NavigatorNFC::NavigatorNFC(Navigator& navigator) |
| 13 : Supplement<Navigator>(navigator) {} |
| 13 | 14 |
| 14 const char* NavigatorNFC::supplementName() { | 15 const char* NavigatorNFC::supplementName() { |
| 15 return "NavigatorNFC"; | 16 return "NavigatorNFC"; |
| 16 } | 17 } |
| 17 | 18 |
| 18 NavigatorNFC& NavigatorNFC::from(Navigator& navigator) { | 19 NavigatorNFC& NavigatorNFC::from(Navigator& navigator) { |
| 19 NavigatorNFC* supplement = static_cast<NavigatorNFC*>( | 20 NavigatorNFC* supplement = static_cast<NavigatorNFC*>( |
| 20 Supplement<Navigator>::from(navigator, supplementName())); | 21 Supplement<Navigator>::from(navigator, supplementName())); |
| 21 if (!supplement) { | 22 if (!supplement) { |
| 22 supplement = new NavigatorNFC(); | 23 supplement = new NavigatorNFC(navigator); |
| 23 provideTo(navigator, supplementName(), supplement); | 24 provideTo(navigator, supplementName(), supplement); |
| 24 } | 25 } |
| 25 return *supplement; | 26 return *supplement; |
| 26 } | 27 } |
| 27 | 28 |
| 28 NFC* NavigatorNFC::nfc(Navigator& navigator) { | 29 NFC* NavigatorNFC::nfc(Navigator& navigator) { |
| 29 NavigatorNFC& self = NavigatorNFC::from(navigator); | 30 NavigatorNFC& self = NavigatorNFC::from(navigator); |
| 30 if (!self.m_nfc) { | 31 if (!self.m_nfc) { |
| 31 if (!navigator.frame()) | 32 if (!navigator.frame()) |
| 32 return nullptr; | 33 return nullptr; |
| 33 self.m_nfc = NFC::create(navigator.frame()); | 34 self.m_nfc = NFC::create(navigator.frame()); |
| 34 } | 35 } |
| 35 return self.m_nfc.get(); | 36 return self.m_nfc.get(); |
| 36 } | 37 } |
| 37 | 38 |
| 38 DEFINE_TRACE(NavigatorNFC) { | 39 DEFINE_TRACE(NavigatorNFC) { |
| 39 visitor->trace(m_nfc); | 40 visitor->trace(m_nfc); |
| 40 Supplement<Navigator>::trace(visitor); | 41 Supplement<Navigator>::trace(visitor); |
| 41 } | 42 } |
| 42 | 43 |
| 43 } // namespace blink | 44 } // namespace blink |
| OLD | NEW |