Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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/browser/web_contents/web_contents_interface_registry_impl.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/memory/ptr_util.h" | |
| 9 #include "content/public/browser/render_frame_host.h" | |
| 10 #include "content/public/browser/web_contents.h" | |
| 11 #include "content/public/common/associated_interface_registry.h" | |
| 12 | |
| 13 namespace content { | |
| 14 | |
| 15 WebContentsInterfaceRegistryImpl::WebContentsInterfaceRegistryImpl( | |
| 16 WebContents* web_contents) | |
| 17 : WebContentsObserver(web_contents), weak_factory_(this) { | |
| 18 } | |
| 19 | |
| 20 WebContentsInterfaceRegistryImpl::~WebContentsInterfaceRegistryImpl() { | |
| 21 for (auto* frame : frames_) | |
| 22 RemoveInterfacesFromFrame(frame); | |
|
Sam McNally
2016/09/09 05:33:14
Is this necessary after WebContentsDestroyed() is
Ken Rockot(use gerrit already)
2016/09/09 16:01:50
Removed. This was added before WebContentsImpl own
| |
| 23 } | |
| 24 | |
| 25 RenderFrameHost* WebContentsInterfaceRegistryImpl::GetCurrentTargetFrame() { | |
| 26 DCHECK(current_target_frame_host_); | |
| 27 return current_target_frame_host_; | |
| 28 } | |
| 29 | |
| 30 base::WeakPtr<WebContentsInterfaceRegistry> | |
| 31 WebContentsInterfaceRegistryImpl::GetWeakPtr() { | |
| 32 return weak_factory_.GetWeakPtr(); | |
| 33 } | |
| 34 | |
| 35 void WebContentsInterfaceRegistryImpl::SetCurrentTargetFrameForTesting( | |
| 36 RenderFrameHost* render_frame_host) { | |
| 37 current_target_frame_host_ = render_frame_host; | |
| 38 } | |
| 39 | |
| 40 void WebContentsInterfaceRegistryImpl::RenderFrameCreated( | |
| 41 RenderFrameHost* render_frame_host) { | |
| 42 AddInterfacesToFrame(render_frame_host); | |
| 43 | |
| 44 auto result = frames_.insert(render_frame_host); | |
| 45 DCHECK(result.second); | |
| 46 } | |
| 47 | |
| 48 void WebContentsInterfaceRegistryImpl::RenderFrameDeleted( | |
| 49 RenderFrameHost* render_frame_host) { | |
| 50 auto it = frames_.find(render_frame_host); | |
| 51 if (it == frames_.end()) | |
| 52 return; | |
| 53 | |
| 54 frames_.erase(it); | |
| 55 RemoveInterfacesFromFrame(render_frame_host); | |
| 56 } | |
| 57 | |
| 58 void WebContentsInterfaceRegistryImpl::WebContentsDestroyed() { | |
| 59 frames_.clear(); | |
| 60 } | |
| 61 | |
| 62 void WebContentsInterfaceRegistryImpl::AddFrameInterface( | |
| 63 const std::string& name, | |
| 64 std::unique_ptr<FrameInterfaceBase> iface) { | |
| 65 for (auto* frame : frames_) | |
| 66 AddInterfaceToFrame(name, iface.get(), frame); | |
| 67 | |
| 68 auto result = | |
| 69 frame_interfaces_.insert(std::make_pair(name, std::move(iface))); | |
| 70 DCHECK(result.second); | |
| 71 } | |
| 72 | |
| 73 void WebContentsInterfaceRegistryImpl::RemoveFrameInterface( | |
| 74 const std::string& name) { | |
| 75 for (auto* frame : frames_) | |
| 76 frame->GetAssociatedInterfaceRegistry()->RemoveInterface(name); | |
| 77 | |
| 78 auto it = frame_interfaces_.find(name); | |
| 79 DCHECK(it != frame_interfaces_.end()); | |
| 80 frame_interfaces_.erase(it); | |
| 81 } | |
| 82 | |
| 83 void WebContentsInterfaceRegistryImpl::WillDispatchForFrame( | |
| 84 RenderFrameHost* render_frame_host) { | |
| 85 current_target_frame_host_ = render_frame_host; | |
| 86 } | |
| 87 | |
| 88 void WebContentsInterfaceRegistryImpl::AddInterfacesToFrame( | |
| 89 RenderFrameHost* render_frame_host) { | |
| 90 for (auto& entry : frame_interfaces_) | |
| 91 AddInterfaceToFrame(entry.first, entry.second.get(), render_frame_host); | |
| 92 } | |
| 93 | |
| 94 void WebContentsInterfaceRegistryImpl::RemoveInterfacesFromFrame( | |
| 95 RenderFrameHost* render_frame_host) { | |
| 96 for (auto& entry : frame_interfaces_) { | |
| 97 render_frame_host->GetAssociatedInterfaceRegistry()->RemoveInterface( | |
| 98 entry.first); | |
| 99 } | |
| 100 } | |
| 101 | |
| 102 // static | |
| 103 void WebContentsInterfaceRegistryImpl::AddInterfaceToFrame( | |
| 104 const std::string& name, | |
| 105 FrameInterfaceBase* iface, | |
| 106 RenderFrameHost* render_frame_host) { | |
| 107 render_frame_host->GetAssociatedInterfaceRegistry()->AddInterface( | |
| 108 name, base::Bind(&FrameInterfaceBase::AddBinding, | |
| 109 base::Unretained(iface), render_frame_host)); | |
| 110 } | |
| 111 | |
| 112 } // namespace content | |
| OLD | NEW |