1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
// Copyright (c) 2012 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/renderer/browser_plugin/browser_plugin_manager.h"
#include "base/memory/scoped_ptr.h"
#include "content/common/browser_plugin/browser_plugin_constants.h"
#include "content/common/browser_plugin/browser_plugin_messages.h"
#include "content/common/frame_messages.h"
#include "content/public/renderer/browser_plugin_delegate.h"
#include "content/public/renderer/content_renderer_client.h"
#include "content/renderer/browser_plugin/browser_plugin.h"
#include "content/renderer/render_thread_impl.h"
#include "ipc/ipc_message_macros.h"
namespace content {
// static
BrowserPluginManager* BrowserPluginManager::Get() {
if (!RenderThreadImpl::current())
return nullptr;
return RenderThreadImpl::current()->browser_plugin_manager();
}
BrowserPluginManager::BrowserPluginManager() {
}
BrowserPluginManager::~BrowserPluginManager() {
}
void BrowserPluginManager::AddBrowserPlugin(
int browser_plugin_instance_id,
BrowserPlugin* browser_plugin) {
instances_.AddWithID(browser_plugin, browser_plugin_instance_id);
}
void BrowserPluginManager::RemoveBrowserPlugin(int browser_plugin_instance_id) {
instances_.Remove(browser_plugin_instance_id);
}
BrowserPlugin* BrowserPluginManager::GetBrowserPlugin(
int browser_plugin_instance_id) const {
return instances_.Lookup(browser_plugin_instance_id);
}
int BrowserPluginManager::GetNextInstanceID() {
return RenderThreadImpl::current()->GenerateRoutingID();
}
void BrowserPluginManager::UpdateDeviceScaleFactor() {
IDMap<BrowserPlugin>::iterator iter(&instances_);
while (!iter.IsAtEnd()) {
iter.GetCurrentValue()->UpdateDeviceScaleFactor();
iter.Advance();
}
}
void BrowserPluginManager::UpdateFocusState() {
IDMap<BrowserPlugin>::iterator iter(&instances_);
while (!iter.IsAtEnd()) {
iter.GetCurrentValue()->UpdateGuestFocusState();
iter.Advance();
}
}
void BrowserPluginManager::Attach(int browser_plugin_instance_id) {
BrowserPlugin* plugin = GetBrowserPlugin(browser_plugin_instance_id);
if (plugin)
plugin->Attach();
}
void BrowserPluginManager::Detach(int browser_plugin_instance_id) {
BrowserPlugin* plugin = GetBrowserPlugin(browser_plugin_instance_id);
if (plugin)
plugin->Detach();
}
BrowserPlugin* BrowserPluginManager::CreateBrowserPlugin(
RenderFrame* render_frame,
scoped_ptr<BrowserPluginDelegate> delegate) {
return new BrowserPlugin(render_frame, delegate.Pass());
}
void BrowserPluginManager::DidCommitCompositorFrame(
int render_view_routing_id) {
IDMap<BrowserPlugin>::iterator iter(&instances_);
while (!iter.IsAtEnd()) {
if (iter.GetCurrentValue()->render_view_routing_id() ==
render_view_routing_id) {
iter.GetCurrentValue()->DidCommitCompositorFrame();
}
iter.Advance();
}
}
bool BrowserPluginManager::OnControlMessageReceived(
const IPC::Message& message) {
if (!BrowserPlugin::ShouldForwardToBrowserPlugin(message) &&
!content::GetContentClient()->renderer()->
ShouldForwardToGuestContainer(message)) {
return false;
}
int browser_plugin_instance_id = browser_plugin::kInstanceIDNone;
// All allowed messages must have |browser_plugin_instance_id| as their
// first parameter.
PickleIterator iter(message);
bool success = iter.ReadInt(&browser_plugin_instance_id);
DCHECK(success);
BrowserPlugin* plugin = GetBrowserPlugin(browser_plugin_instance_id);
if (plugin && plugin->OnMessageReceived(message))
return true;
// TODO(fsamuel): This is probably forcing the compositor to continue working
// even on display:none. We should optimize this.
if (message.type() == BrowserPluginMsg_CompositorFrameSwapped::ID) {
OnCompositorFrameSwappedPluginUnavailable(message);
return true;
}
return false;
}
bool BrowserPluginManager::Send(IPC::Message* msg) {
return RenderThreadImpl::current()->Send(msg);
}
void BrowserPluginManager::OnCompositorFrameSwappedPluginUnavailable(
const IPC::Message& message) {
BrowserPluginMsg_CompositorFrameSwapped::Param param;
if (!BrowserPluginMsg_CompositorFrameSwapped::Read(&message, ¶m))
return;
FrameHostMsg_CompositorFrameSwappedACK_Params params;
params.producing_host_id = get<1>(param).producing_host_id;
params.producing_route_id = get<1>(param).producing_route_id;
params.output_surface_id = get<1>(param).output_surface_id;
Send(new BrowserPluginHostMsg_CompositorFrameSwappedACK(
message.routing_id(), get<0>(param), params));
}
} // namespace content
|