rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "content/public/browser/web_contents_binding_set.h" |
| 6 | |
| 7 | #include <utility> |
| 8 | |
| 9 | #include "base/logging.h" |
| 10 | #include "content/browser/web_contents/web_contents_impl.h" |
| 11 | |
| 12 | namespace content { |
| 13 | |
| 14 | void WebContentsBindingSet::Binder::OnRequestForFrame( |
| 15 | RenderFrameHost* render_frame_host, |
| 16 | mojo::ScopedInterfaceEndpointHandle handle) { |
| 17 | NOTREACHED(); |
| 18 | } |
| 19 | |
Ken Rockot | 3b799c6 | 2019-04-25 17:38:10 | [diff] [blame] | 20 | void WebContentsBindingSet::Binder::CloseAllBindings() { |
| 21 | NOTREACHED(); |
| 22 | } |
| 23 | |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 24 | WebContentsBindingSet::WebContentsBindingSet(WebContents* web_contents, |
Ken Rockot | 3b799c6 | 2019-04-25 17:38:10 | [diff] [blame] | 25 | const std::string& interface_name) |
rockot | 96c63e3 | 2017-03-20 23:23:03 | [diff] [blame] | 26 | : remove_callback_(static_cast<WebContentsImpl*>(web_contents) |
Ken Rockot | 3b799c6 | 2019-04-25 17:38:10 | [diff] [blame] | 27 | ->AddBindingSet(interface_name, this)) {} |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 28 | |
| 29 | WebContentsBindingSet::~WebContentsBindingSet() { |
danakj | f4b9e94 | 2019-11-29 15:43:04 | [diff] [blame^] | 30 | std::move(remove_callback_).Run(); |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 31 | } |
| 32 | |
rockot | 8bbad22 | 2017-03-22 04:34:05 | [diff] [blame] | 33 | // static |
| 34 | WebContentsBindingSet* WebContentsBindingSet::GetForWebContents( |
| 35 | WebContents* web_contents, |
| 36 | const char* interface_name) { |
| 37 | return static_cast<WebContentsImpl*>(web_contents) |
| 38 | ->GetBindingSet(interface_name); |
| 39 | } |
| 40 | |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 41 | void WebContentsBindingSet::CloseAllBindings() { |
Ken Rockot | 3b799c6 | 2019-04-25 17:38:10 | [diff] [blame] | 42 | binder_->CloseAllBindings(); |
| 43 | binder_ = nullptr; |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | void WebContentsBindingSet::OnRequestForFrame( |
| 47 | RenderFrameHost* render_frame_host, |
| 48 | mojo::ScopedInterfaceEndpointHandle handle) { |
Ken Rockot | 3b799c6 | 2019-04-25 17:38:10 | [diff] [blame] | 49 | if (binder_) |
| 50 | binder_->OnRequestForFrame(render_frame_host, std::move(handle)); |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | } // namespace content |