OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/public/browser/web_contents_binding_set.h" | 5 #include "content/public/browser/web_contents_binding_set.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "content/browser/web_contents/web_contents_impl.h" | 10 #include "content/browser/web_contents/web_contents_impl.h" |
11 | 11 |
12 namespace content { | 12 namespace content { |
13 | 13 |
14 void WebContentsBindingSet::Binder::OnRequestForFrame( | 14 void WebContentsBindingSet::Binder::OnRequestForFrame( |
15 RenderFrameHost* render_frame_host, | 15 RenderFrameHost* render_frame_host, |
16 mojo::ScopedInterfaceEndpointHandle handle) { | 16 mojo::ScopedInterfaceEndpointHandle handle) { |
17 NOTREACHED(); | 17 NOTREACHED(); |
18 } | 18 } |
19 | 19 |
20 WebContentsBindingSet::WebContentsBindingSet(WebContents* web_contents, | 20 WebContentsBindingSet::WebContentsBindingSet(WebContents* web_contents, |
21 const std::string& interface_name, | 21 const std::string& interface_name, |
22 std::unique_ptr<Binder> binder) | 22 std::unique_ptr<Binder> binder) |
23 : remove_callback_( | 23 : remove_callback_(static_cast<WebContentsImpl*>(web_contents) |
24 static_cast<WebContentsImpl*>(web_contents)->AddBindingSet( | 24 ->AddBindingSet(interface_name, this)), |
25 interface_name, this)), | |
26 binder_(std::move(binder)) {} | 25 binder_(std::move(binder)) {} |
27 | 26 |
28 WebContentsBindingSet::~WebContentsBindingSet() { | 27 WebContentsBindingSet::~WebContentsBindingSet() { |
29 remove_callback_.Run(); | 28 remove_callback_.Run(); |
30 } | 29 } |
31 | 30 |
32 void WebContentsBindingSet::CloseAllBindings() { | 31 void WebContentsBindingSet::CloseAllBindings() { |
| 32 binder_for_testing_.reset(); |
33 binder_.reset(); | 33 binder_.reset(); |
34 } | 34 } |
35 | 35 |
36 void WebContentsBindingSet::OnRequestForFrame( | 36 void WebContentsBindingSet::OnRequestForFrame( |
37 RenderFrameHost* render_frame_host, | 37 RenderFrameHost* render_frame_host, |
38 mojo::ScopedInterfaceEndpointHandle handle) { | 38 mojo::ScopedInterfaceEndpointHandle handle) { |
| 39 if (binder_for_testing_) { |
| 40 binder_for_testing_->OnRequestForFrame(render_frame_host, |
| 41 std::move(handle)); |
| 42 return; |
| 43 } |
39 DCHECK(binder_); | 44 DCHECK(binder_); |
40 binder_->OnRequestForFrame(render_frame_host, std::move(handle)); | 45 binder_->OnRequestForFrame(render_frame_host, std::move(handle)); |
41 } | 46 } |
42 | 47 |
43 } // namespace content | 48 } // namespace content |
OLD | NEW |