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
3 // found in the LICENSE file.
5 // A BrowserPluginEmbedder handles messages coming from a BrowserPlugin's
6 // embedder that are not directed at any particular existing guest process.
7 // In the beginning, when a BrowserPlugin instance in the embedder renderer
8 // process requests an initial navigation, the WebContents for that renderer
9 // renderer creates a BrowserPluginEmbedder for itself. The
10 // BrowserPluginEmbedder, in turn, forwards the requests to a
11 // BrowserPluginGuestManager, which creates and manages the lifetime of the new
14 #ifndef CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_EMBEDDER_H_
15 #define CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_EMBEDDER_H_
17 #include "base/memory/weak_ptr.h"
18 #include "content/public/browser/web_contents.h"
19 #include "content/public/browser/web_contents_observer.h"
20 #include "third_party/WebKit/public/web/WebDragOperation.h"
22 struct BrowserPluginHostMsg_Attach_Params
;
26 class BrowserPluginGuest
;
27 class BrowserPluginGuestManager
;
28 class RenderWidgetHostImpl
;
29 struct NativeWebKeyboardEvent
;
31 class CONTENT_EXPORT BrowserPluginEmbedder
: public WebContentsObserver
{
33 ~BrowserPluginEmbedder() override
;
35 static BrowserPluginEmbedder
* Create(WebContentsImpl
* web_contents
);
37 // Called when embedder's |rwh| has sent screen rects to renderer.
38 void DidSendScreenRects();
40 // WebContentsObserver implementation.
41 bool OnMessageReceived(const IPC::Message
& message
) override
;
42 bool OnMessageReceived(const IPC::Message
& message
,
43 RenderFrameHost
* render_frame_host
) override
;
45 // Sends a 'dragend' message to the guest that started the drag.
46 void DragSourceEndedAt(int client_x
, int client_y
, int screen_x
,
47 int screen_y
, blink::WebDragOperation operation
);
49 // Indicates that a drag operation has entered into the bounds of a given
50 // |guest|. Returns whether the |guest| also started the operation.
51 bool DragEnteredGuest(BrowserPluginGuest
* guest
);
53 // Indicates that a drag operation has left the bounds of a given |guest|.
54 void DragLeftGuest(BrowserPluginGuest
* guest
);
56 // Called when the screen info has changed.
57 void ScreenInfoChanged();
59 // Called by WebContentsViewGuest when a drag operation is started within
60 // |guest|. This |guest| will be signaled at the end of the drag operation.
61 void StartDrag(BrowserPluginGuest
* guest
);
63 // Sends EndSystemDrag message to the guest that initiated the last drag/drop
64 // operation, if there's any.
65 void SystemDragEnded();
67 // Used to handle special keyboard events.
68 bool HandleKeyboardEvent(const NativeWebKeyboardEvent
& event
);
70 // Find the given |search_text| in the page. Returns true if the find request
71 // is handled by this browser plugin embedder.
72 bool Find(int request_id
,
73 const base::string16
& search_text
,
74 const blink::WebFindOptions
& options
);
75 bool StopFinding(StopFindAction action
);
78 explicit BrowserPluginEmbedder(WebContentsImpl
* web_contents
);
80 BrowserPluginGuestManager
* GetBrowserPluginGuestManager() const;
82 void ClearGuestDragStateIfApplicable();
84 static bool DidSendScreenRectsCallback(WebContents
* guest_web_contents
);
86 // Notifies a guest that the embedder's screen info has changed.
87 static bool NotifyScreenInfoChanged(WebContents
* guest_web_contents
);
89 static bool UnlockMouseIfNecessaryCallback(bool* mouse_unlocked
,
92 static bool FindInGuest(int request_id
,
93 const base::string16
& search_text
,
94 const blink::WebFindOptions
& options
,
96 static bool StopFindingInGuest(StopFindAction action
, WebContents
* guest
);
100 void OnAttach(RenderFrameHost
* render_frame_host
,
102 const BrowserPluginHostMsg_Attach_Params
& params
);
103 void OnUpdateDragCursor(bool* handled
);
105 // Used to correctly update the cursor when dragging over a guest, and to
106 // handle a race condition when dropping onto the guest that started the drag
107 // (the race is that the dragend message arrives before the drop message so
108 // the drop never takes place).
110 base::WeakPtr
<BrowserPluginGuest
> guest_dragging_over_
;
112 // Pointer to the guest that started the drag, used to forward necessary drag
113 // status messages to the correct guest.
114 base::WeakPtr
<BrowserPluginGuest
> guest_started_drag_
;
116 // Keeps track of "dragend" state.
117 bool guest_drag_ending_
;
119 base::WeakPtrFactory
<BrowserPluginEmbedder
> weak_ptr_factory_
;
121 DISALLOW_COPY_AND_ASSIGN(BrowserPluginEmbedder
);
124 } // namespace content
126 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_EMBEDDER_H_