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 "content/shell/browser/layout_test/layout_test_bluetooth_chooser_factor
y.h" | 5 #include "content/shell/browser/layout_test/layout_test_bluetooth_chooser_factor
y.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "content/public/browser/render_frame_host.h" |
9 #include "url/origin.h" | 10 #include "url/origin.h" |
10 | 11 |
11 namespace content { | 12 namespace content { |
12 | 13 |
13 class WebContents; | 14 class WebContents; |
14 | 15 |
15 // Implements a Bluetooth chooser that records events it's sent, instead of | 16 // Implements a Bluetooth chooser that records events it's sent, instead of |
16 // showing a dialog. It allows tests to control how the chooser responds. | 17 // showing a dialog. It allows tests to control how the chooser responds. |
17 class LayoutTestBluetoothChooserFactory::Chooser : public BluetoothChooser { | 18 class LayoutTestBluetoothChooserFactory::Chooser : public BluetoothChooser { |
18 public: | 19 public: |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 94 |
94 LayoutTestBluetoothChooserFactory::LayoutTestBluetoothChooserFactory() | 95 LayoutTestBluetoothChooserFactory::LayoutTestBluetoothChooserFactory() |
95 : weak_this_(this) {} | 96 : weak_this_(this) {} |
96 | 97 |
97 LayoutTestBluetoothChooserFactory::~LayoutTestBluetoothChooserFactory() { | 98 LayoutTestBluetoothChooserFactory::~LayoutTestBluetoothChooserFactory() { |
98 SendEvent(BluetoothChooser::Event::CANCELLED, ""); | 99 SendEvent(BluetoothChooser::Event::CANCELLED, ""); |
99 } | 100 } |
100 | 101 |
101 scoped_ptr<BluetoothChooser> | 102 scoped_ptr<BluetoothChooser> |
102 LayoutTestBluetoothChooserFactory::RunBluetoothChooser( | 103 LayoutTestBluetoothChooserFactory::RunBluetoothChooser( |
103 WebContents* web_contents, | 104 RenderFrameHost* frame, |
104 const BluetoothChooser::EventHandler& event_handler, | 105 const BluetoothChooser::EventHandler& event_handler) { |
105 const url::Origin& origin) { | 106 const url::Origin origin = frame->GetLastCommittedOrigin(); |
106 DCHECK(!origin.unique()); | 107 DCHECK(!origin.unique()); |
107 std::string event = "chooser-opened("; | 108 std::string event = "chooser-opened("; |
108 event += origin.Serialize(); | 109 event += origin.Serialize(); |
109 event += ")"; | 110 event += ")"; |
110 events_.push_back(event); | 111 events_.push_back(event); |
111 return make_scoped_ptr(new Chooser(weak_this_.GetWeakPtr(), event_handler)); | 112 return make_scoped_ptr(new Chooser(weak_this_.GetWeakPtr(), event_handler)); |
112 } | 113 } |
113 | 114 |
114 std::vector<std::string> | 115 std::vector<std::string> |
115 LayoutTestBluetoothChooserFactory::GetAndResetEvents() { | 116 LayoutTestBluetoothChooserFactory::GetAndResetEvents() { |
116 std::vector<std::string> result; | 117 std::vector<std::string> result; |
117 result.swap(events_); | 118 result.swap(events_); |
118 return result; | 119 return result; |
119 } | 120 } |
120 | 121 |
121 void LayoutTestBluetoothChooserFactory::SendEvent( | 122 void LayoutTestBluetoothChooserFactory::SendEvent( |
122 BluetoothChooser::Event event, | 123 BluetoothChooser::Event event, |
123 const std::string& device_id) { | 124 const std::string& device_id) { |
124 // Copy |choosers_| to make sure event handler executions that modify | 125 // Copy |choosers_| to make sure event handler executions that modify |
125 // |choosers_| don't invalidate iterators. | 126 // |choosers_| don't invalidate iterators. |
126 std::vector<Chooser*> choosers_copy(choosers_.begin(), choosers_.end()); | 127 std::vector<Chooser*> choosers_copy(choosers_.begin(), choosers_.end()); |
127 for (Chooser* chooser : choosers_copy) { | 128 for (Chooser* chooser : choosers_copy) { |
128 chooser->event_handler.Run(event, device_id); | 129 chooser->event_handler.Run(event, device_id); |
129 } | 130 } |
130 } | 131 } |
131 | 132 |
132 } // namespace content | 133 } // namespace content |
OLD | NEW |