browser_plugin_guest.h revision 03b57e008b61dfcb1fbad3aea950ae0e001748b0
15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// A BrowserPluginGuest is the browser side of a browser <--> embedder 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// renderer channel. A BrowserPlugin (a WebPlugin) is on the embedder 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// renderer side of browser <--> embedder renderer communication. 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 91e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// BrowserPluginGuest lives on the UI thread of the browser process. Any 101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// messages about the guest render process that the embedder might be interested 111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// in receiving should be listened for here. 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 13cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// BrowserPluginGuest is a WebContentsObserver for the guest WebContents. 14cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// BrowserPluginGuest operates under the assumption that the guest will be 15cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// accessible through only one RenderViewHost for the lifetime of 162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// the guest WebContents. Thus, cross-process navigation is not supported. 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <map> 22b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include <queue> 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/compiler_specific.h" 25f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "base/memory/linked_ptr.h" 262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "base/memory/weak_ptr.h" 27eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/values.h" 28868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "content/common/edit_command.h" 29010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "content/common/input/input_event_ack_state.h" 307dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "content/public/browser/browser_plugin_guest_delegate.h" 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_contents_observer.h" 325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "third_party/WebKit/public/web/WebCompositionUnderline.h" 337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "third_party/WebKit/public/web/WebDragOperation.h" 347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "third_party/WebKit/public/web/WebDragStatus.h" 357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "third_party/WebKit/public/web/WebInputEvent.h" 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/base/ime/text_input_mode.h" 375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/base/ime/text_input_type.h" 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/rect.h" 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 40cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class SkBitmap; 41c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)struct BrowserPluginHostMsg_Attach_Params; 425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct BrowserPluginHostMsg_ResizeGuest_Params; 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)struct FrameHostMsg_CompositorFrameSwappedACK_Params; 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)struct FrameHostMsg_ReclaimCompositorResources_Params; 452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_MACOSX) 462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)struct ViewHostMsg_ShowPopup_Params; 472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif 48f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)struct ViewHostMsg_TextInputState_Params; 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)struct ViewHostMsg_UpdateRect_Params; 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 51f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)namespace blink { 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebInputEvent; 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)namespace gfx { 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)class Range; 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content { 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 61010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)class BrowserPluginGuestManager; 62cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class RenderViewHostImpl; 632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class RenderWidgetHostView; 640f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)class SiteInstance; 6523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)class WebCursor; 66eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdochstruct DropData; 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// A browser plugin guest provides functionality for WebContents to operate in 692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// the guest role and implements guest-specific overrides for ViewHostMsg_* 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// messages. 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// 722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// When a guest is initially created, it is in an unattached state. That is, 732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// it is not visible anywhere and has no embedder WebContents assigned. 742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// A BrowserPluginGuest is said to be "attached" if it has an embedder. 752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// A BrowserPluginGuest can also create a new unattached guest via 762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// CreateNewWindow. The newly created guest will live in the same partition, 772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// which means it can share storage and can script this guest. 78cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class CONTENT_EXPORT BrowserPluginGuest : public WebContentsObserver { 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~BrowserPluginGuest(); 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 820f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // The WebContents passed into the factory method here has not been 830f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // initialized yet and so it does not yet hold a SiteInstance. 840f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // BrowserPluginGuest must be constructed and installed into a WebContents 850f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // prior to its initialization because WebContents needs to determine what 860f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // type of WebContentsView to construct on initialization. The content 870f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // embedder needs to be aware of |guest_site_instance| on the guest's 880f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) // construction and so we pass it in here. 8903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) static BrowserPluginGuest* Create(WebContentsImpl* web_contents, 9003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) BrowserPluginGuestDelegate* delegate); 91c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 92cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Returns whether the given WebContents is a BrowserPlugin guest. 93cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) static bool IsGuest(WebContentsImpl* web_contents); 94cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 95cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Returns whether the given RenderviewHost is a BrowserPlugin guest. 96cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) static bool IsGuest(RenderViewHostImpl* render_view_host); 97cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Returns a WeakPtr to this BrowserPluginGuest. 995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::WeakPtr<BrowserPluginGuest> AsWeakPtr(); 1005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 101cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Sets the lock state of the pointer. Returns true if |allowed| is true and 102cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // the mouse has been successfully locked. 103cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) bool LockMouse(bool allowed); 104d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 10503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) // Return true if the mouse is locked. 10603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) bool mouse_locked() const { return mouse_locked_; } 10703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) 1084e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Called when the embedder WebContents changes visibility. 1094e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) void EmbedderVisibilityChanged(bool visible); 1104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 1112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Destroys the guest WebContents and all its associated state, including 1122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // this BrowserPluginGuest, and its new unattached windows. 1132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void Destroy(); 1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 115116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // Creates a new guest WebContentsImpl with the provided |params| with |this| 116116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // as the |opener|. 117116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch WebContentsImpl* CreateNewGuestWindow( 118116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch const WebContents::CreateParams& params); 119116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch 1202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Returns the identifier that uniquely identifies a browser plugin guest 1212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // within an embedder. 12203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) int browser_plugin_instance_id() const { return browser_plugin_instance_id_; } 1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool OnMessageReceivedFromEmbedder(const IPC::Message& message); 1252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) WebContentsImpl* embedder_web_contents() const { 1272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) return embedder_web_contents_; 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Returns the embedder's RenderWidgetHostView if it is available. 1315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Returns NULL otherwise. 1322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) RenderWidgetHostView* GetEmbedderRenderWidgetHostView(); 1332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool focused() const { return focused_; } 1352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool visible() const { return guest_visible_; } 1363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) bool is_in_destruction() { return is_in_destruction_; } 1372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void UpdateVisibility(); 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 140a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) void CopyFromCompositingSurface( 141a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) gfx::Rect src_subrect, 142a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) gfx::Size dst_size, 143a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::Callback<void(bool, const SkBitmap&)>& callback); 144a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 145010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) BrowserPluginGuestManager* GetBrowserPluginGuestManager() const; 146010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // WebContentsObserver implementation. 1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void DidCommitProvisionalLoadForFrame( 149116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch RenderFrameHost* render_frame_host, 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const GURL& url, 151116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch PageTransition transition_type) OVERRIDE; 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void RenderViewReady() OVERRIDE; 1547dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE; 1552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 1562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Exposes the protected web_contents() from WebContentsObserver. 158010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) WebContentsImpl* GetWebContents() const; 1595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Point GetScreenCoordinates(const gfx::Point& relative_position) const; 1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Helper to send messages to embedder. This methods fills the message with 1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // the correct routing id. 16446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) void SendMessageToEmbedder(IPC::Message* msg); 1652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Returns whether the guest is attached to an embedder. 167f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) bool attached() const { return embedder_web_contents_ != NULL; } 1682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Attaches this BrowserPluginGuest to the provided |embedder_web_contents| 1702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // and initializes the guest with the provided |params|. Attaching a guest 1712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // to an embedder implies that this guest's lifetime is no longer managed 17203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) // by its opener, and it can begin loading resources. 17303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) void Attach(int browser_plugin_instance_id, 17403b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) WebContentsImpl* embedder_web_contents, 17503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) const BrowserPluginHostMsg_Attach_Params& params); 1762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Returns whether BrowserPluginGuest is interested in receiving the given 1782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // |message|. 1792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) static bool ShouldForwardToBrowserPluginGuest(const IPC::Message& message); 18090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) gfx::Rect ToGuestRect(const gfx::Rect& rect); 1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 182c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void DragSourceEndedAt(int client_x, int client_y, int screen_x, 183f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) int screen_y, blink::WebDragOperation operation); 184c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 185c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Called when the drag started by this guest ends at an OS-level. 186c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void EndSystemDrag(); 1872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 188c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch void RespondToPermissionRequest(int request_id, 189c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch bool should_allow, 190c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch const std::string& user_input); 191c2db58bd994c04d98e4ee2cd7565b71548655fe3Ben Murdoch 1920529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch void PointerLockPermissionResponse(bool allow); 1930529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch 194c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) private: 1954e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) class EmbedderWebContentsObserver; 1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 197f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // BrowserPluginGuest is a WebContentsObserver of |web_contents| and 198f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // |web_contents| has to stay valid for the lifetime of BrowserPluginGuest. 19903b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) BrowserPluginGuest(bool has_render_view, 200116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch WebContentsImpl* web_contents, 201116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch BrowserPluginGuestDelegate* delegate); 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 203cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) void WillDestroy(); 204d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 20503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) void Initialize(int browser_plugin_instance_id, 20603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) const BrowserPluginHostMsg_Attach_Params& params, 20703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) WebContentsImpl* embedder_web_contents); 208f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool InAutoSizeBounds(const gfx::Size& size) const; 2102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Message handlers for messages from embedder. 2122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void OnCompositorFrameSwappedACK( 2145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int instance_id, 2155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const FrameHostMsg_CompositorFrameSwappedACK_Params& params); 216a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) void OnCopyFromCompositingSurfaceAck(int instance_id, 217a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) int request_id, 218a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const SkBitmap& bitmap); 2192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Handles drag events from the embedder. 2202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // When dragging, the drag events go to the embedder first, and if the drag 2212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // happens on the browser plugin, then the plugin sends a corresponding 2222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // drag-message to the guest. This routes the drag-message to the guest 2232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // renderer. 2242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void OnDragStatusUpdate(int instance_id, 225f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) blink::WebDragStatus drag_status, 226eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch const DropData& drop_data, 227f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) blink::WebDragOperationsMask drag_mask, 2282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Point& location); 229c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Instructs the guest to execute an edit command decoded in the embedder. 230c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void OnExecuteEditCommand(int instance_id, 231c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) const std::string& command); 232f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 233f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) // Returns compositor resources reclaimed in the embedder to the guest. 2345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void OnReclaimCompositorResources( 2355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int instance_id, 2365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const FrameHostMsg_ReclaimCompositorResources_Params& params); 237f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) 23846d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) void OnHandleInputEvent(int instance_id, 2392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const gfx::Rect& guest_window_rect, 240f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) const blink::WebInputEvent* event); 2412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void OnLockMouse(bool user_gesture, 2422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool last_unlocked_by_target, 2432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool privileged); 2442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void OnLockMouseAck(int instance_id, bool succeeded); 2452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void OnPluginDestroyed(int instance_id); 2465c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu // Resizes the guest's web contents. 247cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) void OnResizeGuest( 2485c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu int instance_id, const BrowserPluginHostMsg_ResizeGuest_Params& params); 249cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) void OnSetFocus(int instance_id, bool focused); 2502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Sets the name of the guest so that other guests in the same partition can 2512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // access it. 2522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void OnSetName(int instance_id, const std::string& name); 2532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Updates the size state of the guest. 254868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) void OnSetEditCommandsForNextKeyEvent( 255868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) int instance_id, 256868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const std::vector<EditCommand>& edit_commands); 257f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) void OnSetContentsOpaque(int instance_id, bool opaque); 2582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // The guest WebContents is visible if both its embedder is visible and 2592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // the browser plugin element is visible. If either one is not then the 2602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // WebContents is marked as hidden. A hidden WebContents will consume 2612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // fewer GPU and CPU resources. 2622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // 2632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // When every WebContents in a RenderProcessHost is hidden, it will lower 2642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // the priority of the process (see RenderProcessHostImpl::WidgetHidden). 2652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // 2662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // It will also send a message to the guest renderer process to cleanup 2672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // resources such as dropping back buffers and adjusting memory limits (if in 2682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // compositing mode, see CCLayerTreeHost::setVisible). 2692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // 2702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Additionally, it will slow down Javascript execution and garbage 2712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // collection. See RenderThreadImpl::IdleHandler (executed when hidden) and 2722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // RenderThreadImpl::IdleHandlerInForegroundTab (executed when visible). 2732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void OnSetVisibility(int instance_id, bool visible); 2742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void OnUnlockMouse(); 2752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void OnUnlockMouseAck(int instance_id); 27690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) void OnUpdateGeometry(int instance_id, const gfx::Rect& view_rect); 2772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 278f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) void OnTextInputStateChanged( 279f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) const ViewHostMsg_TextInputState_Params& params); 280f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 2815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void OnImeSetComposition( 2825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int instance_id, 2835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& text, 2845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::vector<blink::WebCompositionUnderline>& underlines, 2855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int selection_start, 2865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int selection_end); 2875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void OnImeConfirmComposition( 2885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int instance_id, 2895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& text, 2905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool keep_selection); 2915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void OnExtendSelectionAndDelete(int instance_id, int before, int after); 29246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles) void OnImeCancelComposition(); 293a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch#if defined(OS_MACOSX) || defined(USE_AURA) 2945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void OnImeCompositionRangeChanged( 2955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const gfx::Range& range, 2965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::vector<gfx::Rect>& character_bounds); 2975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#endif 2982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 2992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Message handlers for messages from guest. 3002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 301c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) void OnDragStopped(); 3022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void OnHandleInputEventAck( 303f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) blink::WebInputEvent::Type event_type, 3042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) InputEventAckState ack_result); 3052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void OnHasTouchEventHandlers(bool accept); 3062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void OnSetCursor(const WebCursor& cursor); 3072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // On MacOSX popups are painted by the browser process. We handle them here 3082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // so that they are positioned correctly. 3092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_MACOSX) 3102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void OnShowPopup(const ViewHostMsg_ShowPopup_Params& params); 3112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif 3122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void OnShowWidget(int route_id, const gfx::Rect& initial_pos); 313cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) void OnTakeFocus(bool reverse); 3142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void OnUpdateFrameName(int frame_id, 3152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool is_top_level, 3162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) const std::string& name); 3172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void OnUpdateRect(const ViewHostMsg_UpdateRect_Params& params); 3182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 319b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // Forwards all messages from the |pending_messages_| queue to the embedder. 320b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) void SendQueuedMessages(); 321b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 3224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) scoped_ptr<EmbedderWebContentsObserver> embedder_web_contents_observer_; 3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WebContentsImpl* embedder_web_contents_; 324c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 32503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) // An identifier that uniquely identifies a browser plugin within an embedder. 32603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) int browser_plugin_instance_id_; 327c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) float guest_device_scale_factor_; 3282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect guest_window_rect_; 3292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gfx::Rect guest_screen_rect_; 3305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) bool focused_; 3312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool mouse_locked_; 3322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool pending_lock_request_; 3332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool guest_visible_; 334f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) bool guest_opaque_; 3352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) bool embedder_visible_; 3365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 337a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // Each copy-request is identified by a unique number. The unique number is 338a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) // used to keep track of the right callback. 339a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) int copy_request_id_; 340a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) typedef base::Callback<void(bool, const SkBitmap&)> CopyRequestCallback; 341a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) typedef std::map<int, const CopyRequestCallback> CopyRequestMap; 342a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) CopyRequestMap copy_request_callbacks_; 343a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) 344c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // Indicates that this BrowserPluginGuest has associated renderer-side state. 345c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) // This is used to determine whether or not to create a new RenderView when 3466d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) // this guest is attached. A BrowserPluginGuest would have renderer-side state 3476d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) // prior to attachment if it is created via a call to window.open and 3486d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles) // maintains a JavaScript reference to its opener. 349c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) bool has_render_view_; 3502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3513551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Last seen size of guest contents (by OnUpdateRect). 3523551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) gfx::Size last_seen_view_size_; 3535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Last seen size of BrowserPlugin (by OnResizeGuest). 3545f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) gfx::Size last_seen_browser_plugin_size_; 3553551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 3563551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) bool is_in_destruction_; 3573551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 3585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Text input type states. 3595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::TextInputType last_text_input_type_; 3605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ui::TextInputMode last_input_mode_; 3615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool last_can_compose_inline_; 3625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 363b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // This is a queue of messages that are destined to be sent to the embedder 364b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // once the guest is attached to a particular embedder. 365f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) std::deque<linked_ptr<IPC::Message> > pending_messages_; 366b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 367116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch BrowserPluginGuestDelegate* const delegate_; 368d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 3695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Weak pointer used to ask GeolocationPermissionContext about geolocation 3705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // permission. 3715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::WeakPtrFactory<BrowserPluginGuest> weak_ptr_factory_; 3725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(BrowserPluginGuest); 3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace content 3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_GUEST_H_ 379