Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / browser / browser_plugin / browser_plugin_embedder.h
blob4c3731837ac2da56467efe8a2a6dd5d92c964961
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
12 // guest.
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;
24 namespace content {
26 class BrowserPluginGuest;
27 class BrowserPluginGuestManager;
28 class RenderWidgetHostImpl;
29 struct NativeWebKeyboardEvent;
31 class CONTENT_EXPORT BrowserPluginEmbedder : public WebContentsObserver {
32 public:
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 // Closes modal dialogs in all of the guests.
60 void CancelGuestDialogs();
62 // Called by WebContentsViewGuest when a drag operation is started within
63 // |guest|. This |guest| will be signaled at the end of the drag operation.
64 void StartDrag(BrowserPluginGuest* guest);
66 // Sends EndSystemDrag message to the guest that initiated the last drag/drop
67 // operation, if there's any.
68 void SystemDragEnded();
70 // Used to handle special keyboard events.
71 bool HandleKeyboardEvent(const NativeWebKeyboardEvent& event);
73 // Find the given |search_text| in the page. Returns true if the find request
74 // is handled by this browser plugin embedder.
75 bool Find(int request_id,
76 const base::string16& search_text,
77 const blink::WebFindOptions& options);
78 bool StopFinding(StopFindAction action);
80 // Returns the "full page" guest if there is one. That is, if there is a
81 // single BrowserPlugin in the embedder which takes up the full page, then it
82 // is returned.
83 BrowserPluginGuest* GetFullPageGuest();
85 private:
86 explicit BrowserPluginEmbedder(WebContentsImpl* web_contents);
88 BrowserPluginGuestManager* GetBrowserPluginGuestManager() const;
90 void ClearGuestDragStateIfApplicable();
92 static bool DidSendScreenRectsCallback(WebContents* guest_web_contents);
94 // Notifies a guest that the embedder's screen info has changed.
95 static bool NotifyScreenInfoChanged(WebContents* guest_web_contents);
97 // Closes modal dialogs in |guest_web_contents|.
98 static bool CancelDialogs(WebContents* guest_web_contents);
100 static bool UnlockMouseIfNecessaryCallback(bool* mouse_unlocked,
101 WebContents* guest);
103 static bool FindInGuest(int request_id,
104 const base::string16& search_text,
105 const blink::WebFindOptions& options,
106 WebContents* guest);
107 static bool StopFindingInGuest(StopFindAction action, WebContents* guest);
109 // Message handlers.
111 void OnAttach(RenderFrameHost* render_frame_host,
112 int instance_id,
113 const BrowserPluginHostMsg_Attach_Params& params);
114 void OnUpdateDragCursor(bool* handled);
116 // Used to correctly update the cursor when dragging over a guest, and to
117 // handle a race condition when dropping onto the guest that started the drag
118 // (the race is that the dragend message arrives before the drop message so
119 // the drop never takes place).
120 // crbug.com/233571
121 base::WeakPtr<BrowserPluginGuest> guest_dragging_over_;
123 // Pointer to the guest that started the drag, used to forward necessary drag
124 // status messages to the correct guest.
125 base::WeakPtr<BrowserPluginGuest> guest_started_drag_;
127 // Keeps track of "dragend" state.
128 bool guest_drag_ending_;
130 base::WeakPtrFactory<BrowserPluginEmbedder> weak_ptr_factory_;
132 DISALLOW_COPY_AND_ASSIGN(BrowserPluginEmbedder);
135 } // namespace content
137 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_EMBEDDER_H_