| 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/browser/browser_plugin/browser_plugin_embedder.h" | 5 #include "content/browser/browser_plugin/browser_plugin_embedder.h" |
| 6 | 6 |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "content/browser/browser_plugin/browser_plugin_guest.h" | 8 #include "content/browser/browser_plugin/browser_plugin_guest.h" |
| 9 #include "content/browser/browser_plugin/browser_plugin_guest_manager.h" | 9 #include "content/browser/browser_plugin/browser_plugin_guest_manager.h" |
| 10 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" | 10 #include "content/browser/browser_plugin/browser_plugin_host_factory.h" |
| 11 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 11 #include "content/browser/web_contents/web_contents_impl.h" | 12 #include "content/browser/web_contents/web_contents_impl.h" |
| 12 #include "content/common/browser_plugin/browser_plugin_constants.h" | 13 #include "content/common/browser_plugin/browser_plugin_constants.h" |
| 13 #include "content/common/browser_plugin/browser_plugin_messages.h" | 14 #include "content/common/browser_plugin/browser_plugin_messages.h" |
| 14 #include "content/common/drag_messages.h" | 15 #include "content/common/drag_messages.h" |
| 15 #include "content/common/gpu/gpu_messages.h" | 16 #include "content/common/gpu/gpu_messages.h" |
| 16 #include "content/public/browser/browser_context.h" | 17 #include "content/public/browser/browser_context.h" |
| 17 #include "content/public/browser/content_browser_client.h" | 18 #include "content/public/browser/content_browser_client.h" |
| 18 #include "content/public/browser/native_web_keyboard_event.h" | 19 #include "content/public/browser/native_web_keyboard_event.h" |
| 19 #include "content/public/browser/render_view_host.h" | 20 #include "content/public/browser/render_view_host.h" |
| 20 #include "content/public/browser/user_metrics.h" | 21 #include "content/public/browser/user_metrics.h" |
| 21 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
| 22 #include "content/public/common/result_codes.h" | 23 #include "content/public/common/result_codes.h" |
| 23 #include "content/public/common/url_constants.h" | 24 #include "content/public/common/url_constants.h" |
| 24 #include "net/base/escape.h" | 25 #include "net/base/escape.h" |
| 26 #include "ui/events/keycodes/keyboard_codes.h" |
| 25 | 27 |
| 26 namespace content { | 28 namespace content { |
| 27 | 29 |
| 28 // static | 30 // static |
| 29 BrowserPluginHostFactory* BrowserPluginEmbedder::factory_ = NULL; | 31 BrowserPluginHostFactory* BrowserPluginEmbedder::factory_ = NULL; |
| 30 | 32 |
| 31 BrowserPluginEmbedder::BrowserPluginEmbedder(WebContentsImpl* web_contents) | 33 BrowserPluginEmbedder::BrowserPluginEmbedder(WebContentsImpl* web_contents) |
| 32 : WebContentsObserver(web_contents), | 34 : WebContentsObserver(web_contents), |
| 33 next_get_render_view_request_id_(0) { | 35 next_get_render_view_request_id_(0) { |
| 34 } | 36 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 // Store the callback so we can call it later when we have the response. | 74 // Store the callback so we can call it later when we have the response. |
| 73 pending_get_render_view_callbacks_.insert( | 75 pending_get_render_view_callbacks_.insert( |
| 74 std::make_pair(next_get_render_view_request_id_, callback)); | 76 std::make_pair(next_get_render_view_request_id_, callback)); |
| 75 Send(new BrowserPluginMsg_PluginAtPositionRequest( | 77 Send(new BrowserPluginMsg_PluginAtPositionRequest( |
| 76 routing_id(), | 78 routing_id(), |
| 77 next_get_render_view_request_id_, | 79 next_get_render_view_request_id_, |
| 78 gfx::Point(x, y))); | 80 gfx::Point(x, y))); |
| 79 ++next_get_render_view_request_id_; | 81 ++next_get_render_view_request_id_; |
| 80 } | 82 } |
| 81 | 83 |
| 84 bool BrowserPluginEmbedder::DidSendScreenRectsCallback( |
| 85 BrowserPluginGuest* guest) { |
| 86 static_cast<RenderViewHostImpl*>( |
| 87 guest->GetWebContents()->GetRenderViewHost())->SendScreenRects(); |
| 88 // Not handled => Iterate over all guests. |
| 89 return false; |
| 90 } |
| 91 |
| 82 void BrowserPluginEmbedder::DidSendScreenRects() { | 92 void BrowserPluginEmbedder::DidSendScreenRects() { |
| 83 GetBrowserPluginGuestManager()->DidSendScreenRects( | 93 WebContentsImpl* embedder = |
| 84 static_cast<WebContentsImpl*>(web_contents())); | 94 static_cast<WebContentsImpl*>(web_contents()); |
| 95 GetBrowserPluginGuestManager()->ForEachGuest(embedder, base::Bind( |
| 96 &BrowserPluginEmbedder::DidSendScreenRectsCallback, |
| 97 base::Unretained(this))); |
| 98 } |
| 99 |
| 100 bool BrowserPluginEmbedder::UnlockMouseIfNecessaryCallback( |
| 101 const NativeWebKeyboardEvent& event, |
| 102 BrowserPluginGuest* guest) { |
| 103 return guest->UnlockMouseIfNecessary(event); |
| 85 } | 104 } |
| 86 | 105 |
| 87 bool BrowserPluginEmbedder::HandleKeyboardEvent( | 106 bool BrowserPluginEmbedder::HandleKeyboardEvent( |
| 88 const NativeWebKeyboardEvent& event) { | 107 const NativeWebKeyboardEvent& event) { |
| 89 return GetBrowserPluginGuestManager()->UnlockMouseIfNecessary( | 108 if ((event.type != blink::WebInputEvent::RawKeyDown) || |
| 90 static_cast<WebContentsImpl*>(web_contents()), event); | 109 (event.windowsKeyCode != ui::VKEY_ESCAPE) || |
| 110 (event.modifiers & blink::WebInputEvent::InputModifiers)) { |
| 111 return false; |
| 112 } |
| 113 |
| 114 WebContentsImpl* embedder = |
| 115 static_cast<WebContentsImpl*>(web_contents()); |
| 116 return GetBrowserPluginGuestManager()->ForEachGuest(embedder, base::Bind( |
| 117 &BrowserPluginEmbedder::UnlockMouseIfNecessaryCallback, |
| 118 base::Unretained(this), |
| 119 event)); |
| 91 } | 120 } |
| 92 | 121 |
| 93 void BrowserPluginEmbedder::RenderProcessGone(base::TerminationStatus status) { | 122 void BrowserPluginEmbedder::RenderProcessGone(base::TerminationStatus status) { |
| 94 CleanUp(); | 123 CleanUp(); |
| 95 } | 124 } |
| 96 | 125 |
| 97 bool BrowserPluginEmbedder::OnMessageReceived(const IPC::Message& message) { | 126 bool BrowserPluginEmbedder::OnMessageReceived(const IPC::Message& message) { |
| 98 bool handled = true; | 127 bool handled = true; |
| 99 IPC_BEGIN_MESSAGE_MAP(BrowserPluginEmbedder, message) | 128 IPC_BEGIN_MESSAGE_MAP(BrowserPluginEmbedder, message) |
| 100 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_AllocateInstanceID, | 129 IPC_MESSAGE_HANDLER(BrowserPluginHostMsg_AllocateInstanceID, |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 if (guest) | 253 if (guest) |
| 225 render_view_host = guest->GetWebContents()->GetRenderViewHost(); | 254 render_view_host = guest->GetWebContents()->GetRenderViewHost(); |
| 226 else // No plugin, use embedder's RenderViewHost. | 255 else // No plugin, use embedder's RenderViewHost. |
| 227 render_view_host = web_contents()->GetRenderViewHost(); | 256 render_view_host = web_contents()->GetRenderViewHost(); |
| 228 | 257 |
| 229 callback_iter->second.Run(render_view_host, position.x(), position.y()); | 258 callback_iter->second.Run(render_view_host, position.x(), position.y()); |
| 230 pending_get_render_view_callbacks_.erase(callback_iter); | 259 pending_get_render_view_callbacks_.erase(callback_iter); |
| 231 } | 260 } |
| 232 | 261 |
| 233 } // namespace content | 262 } // namespace content |
| OLD | NEW |