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 "config.h" | 5 #include "config.h" |
6 #include "modules/bluetooth/BluetoothSupplement.h" | 6 #include "modules/bluetooth/BluetoothSupplement.h" |
7 | 7 |
8 #include "core/frame/LocalDOMWindow.h" | 8 #include "core/dom/Document.h" |
9 #include "public/platform/Platform.h" | |
10 | 9 |
11 namespace blink { | 10 namespace blink { |
12 | 11 |
13 const char* BluetoothSupplement::supplementName() | 12 const char* BluetoothSupplement::supplementName() |
14 { | 13 { |
15 return "BluetoothSupplement"; | 14 return "BluetoothSupplement"; |
16 } | 15 } |
17 | 16 |
18 BluetoothSupplement::BluetoothSupplement(WebBluetooth* bluetooth) | 17 BluetoothSupplement::BluetoothSupplement(WebBluetooth* bluetooth) |
19 : m_bluetooth(bluetooth) | 18 : m_bluetooth(bluetooth) |
20 { | 19 { |
21 } | 20 } |
22 | 21 |
23 void BluetoothSupplement::provideTo(LocalFrame& frame, WebBluetooth* bluetooth) | 22 void BluetoothSupplement::provideTo(LocalFrame& frame, WebBluetooth* bluetooth) |
24 { | 23 { |
25 OwnPtrWillBeRawPtr<BluetoothSupplement> bluetoothSupplement = adoptPtrWillBe Noop(new BluetoothSupplement(bluetooth)); | 24 OwnPtrWillBeRawPtr<BluetoothSupplement> bluetoothSupplement = adoptPtrWillBe Noop(new BluetoothSupplement(bluetooth)); |
26 WillBeHeapSupplement<LocalFrame>::provideTo(frame, supplementName(), bluetoo thSupplement.release()); | 25 WillBeHeapSupplement<LocalFrame>::provideTo(frame, supplementName(), bluetoo thSupplement.release()); |
27 }; | 26 }; |
28 | 27 |
29 WebBluetooth* BluetoothSupplement::from(ScriptState* scriptState) | 28 WebBluetooth* BluetoothSupplement::from(LocalFrame* frame) |
30 { | 29 { |
31 LocalDOMWindow* window = scriptState->domWindow(); | 30 BluetoothSupplement* supplement = static_cast<BluetoothSupplement*>(WillBeHe apSupplement<LocalFrame>::from(frame, supplementName())); |
32 if (window && window->frame()) { | 31 |
33 BluetoothSupplement* supplement = static_cast<BluetoothSupplement*>(Will BeHeapSupplement<LocalFrame>::from(window->frame(), supplementName())); | 32 ASSERT(supplement); |
34 if (supplement && supplement->m_bluetooth) | 33 ASSERT(supplement->m_bluetooth); |
35 return supplement->m_bluetooth; | 34 |
35 return supplement->m_bluetooth; | |
36 } | |
37 | |
38 WebBluetooth* BluetoothSupplement::fromScriptState(ScriptState* scriptState) | |
39 { | |
40 if (!scriptState->executionContext()->isDocument()) { | |
41 return nullptr; | |
36 } | 42 } |
37 return Platform::current()->bluetooth(); | 43 return BluetoothSupplement::from(static_cast<Document*>(scriptState->executi onContext())->frame()); |
haraken
2015/10/13 02:05:09
After landing the other CL, you should replace the
ortuno
2015/10/13 15:40:29
This CL is meant to land first. The other CL chang
| |
38 } | 44 } |
39 | 45 |
40 DEFINE_TRACE(BluetoothSupplement) | 46 DEFINE_TRACE(BluetoothSupplement) |
41 { | 47 { |
42 WillBeHeapSupplement<LocalFrame>::trace(visitor); | 48 WillBeHeapSupplement<LocalFrame>::trace(visitor); |
43 } | 49 } |
44 | 50 |
45 }; // blink | 51 }; // blink |
OLD | NEW |