Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / content / browser / browser_plugin / browser_plugin_embedder.h
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.
4
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.
13
14 #ifndef CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_EMBEDDER_H_
15 #define CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_EMBEDDER_H_
16
17 #include <map>
18
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"
24
25 struct BrowserPluginHostMsg_Attach_Params;
26 struct BrowserPluginHostMsg_ResizeGuest_Params;
27
28 namespace gfx {
29 class Point;
30 }
31
32 namespace content {
33
34 class BrowserPluginGuest;
35 class BrowserPluginGuestManager;
36 class BrowserPluginHostFactory;
37 class RenderWidgetHostImpl;
38 class WebContentsImpl;
39 struct NativeWebKeyboardEvent;
40
41 class CONTENT_EXPORT BrowserPluginEmbedder : public WebContentsObserver {
42  public:
43   virtual ~BrowserPluginEmbedder();
44
45   static BrowserPluginEmbedder* Create(WebContentsImpl* web_contents);
46
47   // Returns this embedder's WebContentsImpl.
48   WebContentsImpl* GetWebContents() const;
49
50   // Called when embedder's |rwh| has sent screen rects to renderer.
51   void DidSendScreenRects();
52
53   // Called when embedder's WebContentsImpl has unhandled keyboard input.
54   // Returns whether the BrowserPlugin has handled the keyboard event.
55   // Currently we are only interested in checking for the escape key to
56   // unlock hte guest's pointer lock.
57   bool HandleKeyboardEvent(const NativeWebKeyboardEvent& event);
58
59   // Overrides factory for testing. Default (NULL) value indicates regular
60   // (non-test) environment.
61   static void set_factory_for_testing(BrowserPluginHostFactory* factory) {
62     factory_ = factory;
63   }
64
65   // Sets the zoom level for all guests within this embedder.
66   void SetZoomLevel(double level);
67
68   // WebContentsObserver implementation.
69   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
70
71   void DragSourceEndedAt(int client_x, int client_y, int screen_x,
72       int screen_y, blink::WebDragOperation operation);
73
74   void OnUpdateDragCursor(bool* handled);
75
76   void DragEnteredGuest(BrowserPluginGuest* guest);
77
78   void DragLeftGuest(BrowserPluginGuest* guest);
79
80   void StartDrag(BrowserPluginGuest* guest);
81
82   // Sends EndSystemDrag message to the guest that initiated the last drag/drop
83   // operation, if there's any.
84   void SystemDragEnded();
85
86  private:
87   friend class TestBrowserPluginEmbedder;
88
89   explicit BrowserPluginEmbedder(WebContentsImpl* web_contents);
90
91   BrowserPluginGuestManager* GetBrowserPluginGuestManager() const;
92
93   bool DidSendScreenRectsCallback(BrowserPluginGuest* guest);
94
95   bool SetZoomLevelCallback(double level, BrowserPluginGuest* guest);
96
97   bool UnlockMouseIfNecessaryCallback(const NativeWebKeyboardEvent& event,
98                                       BrowserPluginGuest* guest);
99
100   // Called by the content embedder when a guest exists with the provided
101   // |instance_id|.
102   void OnGuestCallback(int instance_id,
103                        const BrowserPluginHostMsg_Attach_Params& params,
104                        const base::DictionaryValue* extra_params,
105                        BrowserPluginGuest* guest);
106
107   // Message handlers.
108
109   void OnAllocateInstanceID(int request_id);
110   void OnAttach(int instance_id,
111                 const BrowserPluginHostMsg_Attach_Params& params,
112                 const base::DictionaryValue& extra_params);
113   void OnPluginAtPositionResponse(int instance_id,
114                                   int request_id,
115                                   const gfx::Point& position);
116
117   // Static factory instance (always NULL for non-test).
118   static BrowserPluginHostFactory* factory_;
119
120   // Used to correctly update the cursor when dragging over a guest, and to
121   // handle a race condition when dropping onto the guest that started the drag
122   // (the race is that the dragend message arrives before the drop message so
123   // the drop never takes place).
124   // crbug.com/233571
125   base::WeakPtr<BrowserPluginGuest> guest_dragging_over_;
126
127   // Pointer to the guest that started the drag, used to forward necessary drag
128   // status messages to the correct guest.
129   base::WeakPtr<BrowserPluginGuest> guest_started_drag_;
130
131   base::WeakPtrFactory<BrowserPluginEmbedder> weak_ptr_factory_;
132
133   DISALLOW_COPY_AND_ASSIGN(BrowserPluginEmbedder);
134 };
135
136 }  // namespace content
137
138 #endif  // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_EMBEDDER_H_