| Index: content/browser/web_contents/web_contents_interface_registry_impl.cc
|
| diff --git a/content/browser/web_contents/web_contents_interface_registry_impl.cc b/content/browser/web_contents/web_contents_interface_registry_impl.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..4b056b1ed2ecf972aa034af62c128b16f1c37140
|
| --- /dev/null
|
| +++ b/content/browser/web_contents/web_contents_interface_registry_impl.cc
|
| @@ -0,0 +1,100 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "content/browser/web_contents/web_contents_interface_registry_impl.h"
|
| +
|
| +#include "base/bind.h"
|
| +#include "base/memory/ptr_util.h"
|
| +#include "content/public/browser/render_frame_host.h"
|
| +#include "content/public/browser/web_contents.h"
|
| +#include "content/public/common/associated_interface_registry.h"
|
| +
|
| +namespace content {
|
| +
|
| +WebContentsInterfaceRegistryImpl::WebContentsInterfaceRegistryImpl(
|
| + WebContents* web_contents)
|
| + : WebContentsObserver(web_contents), weak_factory_(this) {
|
| +}
|
| +
|
| +WebContentsInterfaceRegistryImpl::~WebContentsInterfaceRegistryImpl() {
|
| +}
|
| +
|
| +RenderFrameHost* WebContentsInterfaceRegistryImpl::GetCurrentTargetFrame() {
|
| + DCHECK(current_target_frame_host_);
|
| + return current_target_frame_host_;
|
| +}
|
| +
|
| +base::WeakPtr<WebContentsInterfaceRegistry>
|
| +WebContentsInterfaceRegistryImpl::GetWeakPtr() {
|
| + return weak_factory_.GetWeakPtr();
|
| +}
|
| +
|
| +void WebContentsInterfaceRegistryImpl::SetCurrentTargetFrameForTesting(
|
| + RenderFrameHost* render_frame_host) {
|
| + current_target_frame_host_ = render_frame_host;
|
| +}
|
| +
|
| +void WebContentsInterfaceRegistryImpl::RenderFrameCreated(
|
| + RenderFrameHost* render_frame_host) {
|
| + for (auto& entry : frame_interfaces_)
|
| + AddInterfaceToFrame(entry.first, entry.second.get(), render_frame_host);
|
| +
|
| + auto result = frames_.insert(render_frame_host);
|
| + DCHECK(result.second);
|
| +}
|
| +
|
| +void WebContentsInterfaceRegistryImpl::RenderFrameDeleted(
|
| + RenderFrameHost* render_frame_host) {
|
| + auto it = frames_.find(render_frame_host);
|
| + if (it == frames_.end())
|
| + return;
|
| +
|
| + frames_.erase(it);
|
| + for (auto& entry : frame_interfaces_) {
|
| + render_frame_host->GetAssociatedInterfaceRegistry()->RemoveInterface(
|
| + entry.first);
|
| + }
|
| +}
|
| +
|
| +void WebContentsInterfaceRegistryImpl::WebContentsDestroyed() {
|
| + frames_.clear();
|
| +}
|
| +
|
| +void WebContentsInterfaceRegistryImpl::AddFrameInterface(
|
| + const std::string& name,
|
| + std::unique_ptr<FrameInterfaceBase> iface) {
|
| + for (auto* frame : frames_)
|
| + AddInterfaceToFrame(name, iface.get(), frame);
|
| +
|
| + auto result =
|
| + frame_interfaces_.insert(std::make_pair(name, std::move(iface)));
|
| + DCHECK(result.second);
|
| +}
|
| +
|
| +void WebContentsInterfaceRegistryImpl::RemoveFrameInterface(
|
| + const std::string& name) {
|
| + for (auto* frame : frames_)
|
| + frame->GetAssociatedInterfaceRegistry()->RemoveInterface(name);
|
| +
|
| + auto it = frame_interfaces_.find(name);
|
| + DCHECK(it != frame_interfaces_.end());
|
| + frame_interfaces_.erase(it);
|
| +}
|
| +
|
| +void WebContentsInterfaceRegistryImpl::WillDispatchForFrame(
|
| + RenderFrameHost* render_frame_host) {
|
| + current_target_frame_host_ = render_frame_host;
|
| +}
|
| +
|
| +// static
|
| +void WebContentsInterfaceRegistryImpl::AddInterfaceToFrame(
|
| + const std::string& name,
|
| + FrameInterfaceBase* iface,
|
| + RenderFrameHost* render_frame_host) {
|
| + render_frame_host->GetAssociatedInterfaceRegistry()->AddInterface(
|
| + name, base::Bind(&FrameInterfaceBase::AddBinding,
|
| + base::Unretained(iface), render_frame_host));
|
| +}
|
| +
|
| +} // namespace content
|
|
|