OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/renderer/browser_plugin/browser_plugin_manager.h" | 5 #include "content/renderer/browser_plugin/browser_plugin_manager.h" |
| 6 |
6 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/threading/thread.h" |
| 9 #include "cc/base/completion_event.h" |
7 #include "content/common/browser_plugin/browser_plugin_constants.h" | 10 #include "content/common/browser_plugin/browser_plugin_constants.h" |
8 #include "content/common/browser_plugin/browser_plugin_messages.h" | 11 #include "content/common/browser_plugin/browser_plugin_messages.h" |
9 #include "content/common/frame_messages.h" | 12 #include "content/common/frame_messages.h" |
10 #include "content/public/renderer/browser_plugin_delegate.h" | 13 #include "content/public/renderer/browser_plugin_delegate.h" |
11 #include "content/renderer/browser_plugin/browser_plugin.h" | 14 #include "content/renderer/browser_plugin/browser_plugin.h" |
12 #include "content/renderer/render_thread_impl.h" | 15 #include "content/renderer/render_thread_impl.h" |
13 #include "ipc/ipc_message_macros.h" | 16 #include "ipc/ipc_message_macros.h" |
| 17 #include "ipc/ipc_sync_channel.h" |
| 18 #include "ipc/message_filter.h" |
14 | 19 |
15 namespace content { | 20 namespace content { |
16 | 21 |
| 22 class GuestScrollCompletionFilter : public IPC::MessageFilter { |
| 23 public: |
| 24 explicit GuestScrollCompletionFilter( |
| 25 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) |
| 26 : io_task_runner_(io_task_runner), |
| 27 guest_handled_scroll_event_(true), |
| 28 scroll_completion_event_(nullptr) {} |
| 29 |
| 30 // IPC::MessageFilter implementation. |
| 31 bool OnMessageReceived(const IPC::Message& message) override { |
| 32 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 33 // If we see the as-yet-to-be determined ack from the browser, |
| 34 // set |guest_handled_scroll_event_| and call |
| 35 // scroll_completion_event_->Signal(). |
| 36 bool handled = true; |
| 37 IPC_BEGIN_MESSAGE_MAP(GuestScrollCompletionFilter, message) |
| 38 IPC_MESSAGE_HANDLER(BrowserPluginMsg_SignalScrollCompletionEvent, |
| 39 OnSignalScrollCompletionEvent) |
| 40 IPC_MESSAGE_UNHANDLED(handled = false) |
| 41 IPC_END_MESSAGE_MAP() |
| 42 return handled; |
| 43 } |
| 44 |
| 45 void set_scroll_completion_event( |
| 46 cc::CompletionEvent* scroll_completion_event) { |
| 47 scroll_completion_event_ = scroll_completion_event; |
| 48 } |
| 49 bool guest_handled_scroll_event() const { |
| 50 return guest_handled_scroll_event_; |
| 51 } |
| 52 |
| 53 private: |
| 54 ~GuestScrollCompletionFilter() override {} |
| 55 |
| 56 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 57 bool guest_handled_scroll_event_; |
| 58 cc::CompletionEvent* scroll_completion_event_; |
| 59 |
| 60 void OnSignalScrollCompletionEvent(bool handled) { |
| 61 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 62 guest_handled_scroll_event_ = handled; |
| 63 scroll_completion_event_->Signal(); |
| 64 scroll_completion_event_ = nullptr; |
| 65 } |
| 66 |
| 67 DISALLOW_COPY_AND_ASSIGN(GuestScrollCompletionFilter); |
| 68 }; |
| 69 |
17 // static | 70 // static |
18 BrowserPluginManager* BrowserPluginManager::Get() { | 71 BrowserPluginManager* BrowserPluginManager::Get() { |
19 if (!RenderThreadImpl::current()) | 72 if (!RenderThreadImpl::current()) |
20 return nullptr; | 73 return nullptr; |
21 return RenderThreadImpl::current()->browser_plugin_manager(); | 74 return RenderThreadImpl::current()->browser_plugin_manager(); |
22 } | 75 } |
23 | 76 |
24 BrowserPluginManager::BrowserPluginManager() { | 77 BrowserPluginManager::BrowserPluginManager() { |
25 } | 78 } |
26 | 79 |
27 BrowserPluginManager::~BrowserPluginManager() { | 80 BrowserPluginManager::~BrowserPluginManager() { |
28 } | 81 } |
29 | 82 |
| 83 void BrowserPluginManager::Init( |
| 84 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
| 85 IPC::SyncChannel* channel) { |
| 86 scroll_completion_filter_ = new GuestScrollCompletionFilter(io_task_runner); |
| 87 channel->AddFilter(scroll_completion_filter_.get()); |
| 88 } |
| 89 |
30 void BrowserPluginManager::AddBrowserPlugin( | 90 void BrowserPluginManager::AddBrowserPlugin( |
31 int browser_plugin_instance_id, | 91 int browser_plugin_instance_id, |
32 BrowserPlugin* browser_plugin) { | 92 BrowserPlugin* browser_plugin) { |
33 instances_.AddWithID(browser_plugin, browser_plugin_instance_id); | 93 instances_.AddWithID(browser_plugin, browser_plugin_instance_id); |
34 } | 94 } |
35 | 95 |
36 void BrowserPluginManager::RemoveBrowserPlugin(int browser_plugin_instance_id) { | 96 void BrowserPluginManager::RemoveBrowserPlugin(int browser_plugin_instance_id) { |
37 instances_.Remove(browser_plugin_instance_id); | 97 instances_.Remove(browser_plugin_instance_id); |
38 } | 98 } |
39 | 99 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 return true; | 166 return true; |
107 } | 167 } |
108 | 168 |
109 return false; | 169 return false; |
110 } | 170 } |
111 | 171 |
112 bool BrowserPluginManager::Send(IPC::Message* msg) { | 172 bool BrowserPluginManager::Send(IPC::Message* msg) { |
113 return RenderThreadImpl::current()->Send(msg); | 173 return RenderThreadImpl::current()->Send(msg); |
114 } | 174 } |
115 | 175 |
| 176 bool BrowserPluginManager::GetScrollHandledStatus() { |
| 177 cc::CompletionEvent scroll_completion_event; |
| 178 |
| 179 scroll_completion_filter_->set_scroll_completion_event( |
| 180 &scroll_completion_event); |
| 181 scroll_completion_event.Wait(); |
| 182 return scroll_completion_filter_->guest_handled_scroll_event(); |
| 183 } |
| 184 |
116 void BrowserPluginManager::OnCompositorFrameSwappedPluginUnavailable( | 185 void BrowserPluginManager::OnCompositorFrameSwappedPluginUnavailable( |
117 const IPC::Message& message) { | 186 const IPC::Message& message) { |
118 BrowserPluginMsg_CompositorFrameSwapped::Param param; | 187 BrowserPluginMsg_CompositorFrameSwapped::Param param; |
119 if (!BrowserPluginMsg_CompositorFrameSwapped::Read(&message, ¶m)) | 188 if (!BrowserPluginMsg_CompositorFrameSwapped::Read(&message, ¶m)) |
120 return; | 189 return; |
121 | 190 |
122 FrameHostMsg_CompositorFrameSwappedACK_Params params; | 191 FrameHostMsg_CompositorFrameSwappedACK_Params params; |
123 params.producing_host_id = base::get<1>(param).producing_host_id; | 192 params.producing_host_id = base::get<1>(param).producing_host_id; |
124 params.producing_route_id = base::get<1>(param).producing_route_id; | 193 params.producing_route_id = base::get<1>(param).producing_route_id; |
125 params.output_surface_id = base::get<1>(param).output_surface_id; | 194 params.output_surface_id = base::get<1>(param).output_surface_id; |
126 Send(new BrowserPluginHostMsg_CompositorFrameSwappedACK( | 195 Send(new BrowserPluginHostMsg_CompositorFrameSwappedACK( |
127 base::get<0>(param), params)); | 196 base::get<0>(param), params)); |
128 } | 197 } |
129 | 198 |
130 } // namespace content | 199 } // namespace content |
OLD | NEW |