IndexedDBFactory now ForceCloses databases.
[chromium-blink-merge.git] / content / browser / browser_plugin / browser_plugin_embedder.h
bloba1633605d9f6bd97cd827cb65e5cc619bb5e5d2f
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 <map>
19 #include "base/memory/weak_ptr.h"
20 #include "base/values.h"
21 #include "content/public/browser/web_contents.h"
22 #include "content/public/browser/web_contents_observer.h"
23 #include "third_party/WebKit/public/web/WebDragOperation.h"
25 struct BrowserPluginHostMsg_Attach_Params;
26 struct BrowserPluginHostMsg_ResizeGuest_Params;
28 namespace gfx {
29 class Point;
32 namespace content {
34 class BrowserPluginGuest;
35 class BrowserPluginGuestManager;
36 class BrowserPluginHostFactory;
37 class RenderWidgetHostImpl;
38 class WebContentsImpl;
39 struct NativeWebKeyboardEvent;
41 class CONTENT_EXPORT BrowserPluginEmbedder : public WebContentsObserver {
42 public:
43 virtual ~BrowserPluginEmbedder();
45 static BrowserPluginEmbedder* Create(WebContentsImpl* web_contents);
47 // Returns the RenderViewHost at a point (|x|, |y|) asynchronously via
48 // |callback|. We need a roundtrip to renderer process to get this
49 // information.
50 void GetRenderViewHostAtPosition(
51 int x,
52 int y,
53 const WebContents::GetRenderViewHostCallback& callback);
55 // Returns this embedder's WebContentsImpl.
56 WebContentsImpl* GetWebContents();
58 // Called when embedder's |rwh| has sent screen rects to renderer.
59 void DidSendScreenRects();
61 // Called when embedder's WebContentsImpl has unhandled keyboard input.
62 // Returns whether the BrowserPlugin has handled the keyboard event.
63 // Currently we are only interested in checking for the escape key to
64 // unlock hte guest's pointer lock.
65 bool HandleKeyboardEvent(const NativeWebKeyboardEvent& event);
67 // Overrides factory for testing. Default (NULL) value indicates regular
68 // (non-test) environment.
69 static void set_factory_for_testing(BrowserPluginHostFactory* factory) {
70 factory_ = factory;
73 // Sets the zoom level for all guests within this embedder.
74 void SetZoomLevel(double level);
76 // WebContentsObserver implementation.
77 virtual void RenderProcessGone(base::TerminationStatus status) OVERRIDE;
78 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
80 void DragSourceEndedAt(int client_x, int client_y, int screen_x,
81 int screen_y, blink::WebDragOperation operation);
83 void DragSourceMovedTo(int client_x, int client_y,
84 int screen_x, int screen_y);
86 void OnUpdateDragCursor(bool* handled);
88 void DragEnteredGuest(BrowserPluginGuest* guest);
90 void DragLeftGuest(BrowserPluginGuest* guest);
92 void StartDrag(BrowserPluginGuest* guest);
94 void StopDrag(BrowserPluginGuest* guest);
96 void SystemDragEnded();
98 private:
99 friend class TestBrowserPluginEmbedder;
101 BrowserPluginEmbedder(WebContentsImpl* web_contents);
103 void CleanUp();
105 BrowserPluginGuestManager* GetBrowserPluginGuestManager();
107 bool DidSendScreenRectsCallback(BrowserPluginGuest* guest);
109 bool SetZoomLevelCallback(double level, BrowserPluginGuest* guest);
111 bool UnlockMouseIfNecessaryCallback(const NativeWebKeyboardEvent& event,
112 BrowserPluginGuest* guest);
114 // Message handlers.
116 void OnAllocateInstanceID(int request_id);
117 void OnAttach(int instance_id,
118 const BrowserPluginHostMsg_Attach_Params& params,
119 const base::DictionaryValue& extra_params);
120 void OnPluginAtPositionResponse(int instance_id,
121 int request_id,
122 const gfx::Point& position);
124 // Static factory instance (always NULL for non-test).
125 static BrowserPluginHostFactory* factory_;
127 // Map that contains outstanding queries to |GetRenderViewHostAtPosition|.
128 // We need a roundtrip to the renderer process to retrieve the answer,
129 // so we store these callbacks until we hear back from the renderer.
130 typedef std::map<int, WebContents::GetRenderViewHostCallback>
131 GetRenderViewHostCallbackMap;
132 GetRenderViewHostCallbackMap pending_get_render_view_callbacks_;
133 // Next request id for BrowserPluginMsg_PluginAtPositionRequest query.
134 int next_get_render_view_request_id_;
136 // Used to correctly update the cursor when dragging over a guest, and to
137 // handle a race condition when dropping onto the guest that started the drag
138 // (the race is that the dragend message arrives before the drop message so
139 // the drop never takes place).
140 // crbug.com/233571
141 base::WeakPtr<BrowserPluginGuest> guest_dragging_over_;
143 // Pointer to the guest that started the drag, used to forward necessary drag
144 // status messages to the correct guest.
145 base::WeakPtr<BrowserPluginGuest> guest_started_drag_;
147 DISALLOW_COPY_AND_ASSIGN(BrowserPluginEmbedder);
150 } // namespace content
152 #endif // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_EMBEDDER_H_