Home | History | Annotate | Download | only in browser_plugin
      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 RenderWidgetHostImpl;
     37 class WebContentsImpl;
     38 struct NativeWebKeyboardEvent;
     39 
     40 class CONTENT_EXPORT BrowserPluginEmbedder : public WebContentsObserver {
     41  public:
     42   virtual ~BrowserPluginEmbedder();
     43 
     44   static BrowserPluginEmbedder* Create(WebContentsImpl* web_contents);
     45 
     46   // Returns this embedder's WebContentsImpl.
     47   WebContentsImpl* GetWebContents() const;
     48 
     49   // Called when embedder's |rwh| has sent screen rects to renderer.
     50   void DidSendScreenRects();
     51 
     52   // WebContentsObserver implementation.
     53   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
     54 
     55   void DragSourceEndedAt(int client_x, int client_y, int screen_x,
     56       int screen_y, blink::WebDragOperation operation);
     57 
     58   void OnUpdateDragCursor(bool* handled);
     59 
     60   void DragEnteredGuest(BrowserPluginGuest* guest);
     61 
     62   void DragLeftGuest(BrowserPluginGuest* guest);
     63 
     64   void StartDrag(BrowserPluginGuest* guest);
     65 
     66   // Sends EndSystemDrag message to the guest that initiated the last drag/drop
     67   // operation, if there's any.
     68   void SystemDragEnded();
     69 
     70  private:
     71   explicit BrowserPluginEmbedder(WebContentsImpl* web_contents);
     72 
     73   BrowserPluginGuestManager* GetBrowserPluginGuestManager() const;
     74 
     75   bool DidSendScreenRectsCallback(WebContents* guest_web_contents);
     76 
     77   bool SetZoomLevelCallback(double level, WebContents* guest_web_contents);
     78 
     79   bool UnlockMouseIfNecessaryCallback(const NativeWebKeyboardEvent& event,
     80                                       WebContents* guest);
     81 
     82   // Called by the content embedder when a guest exists with the provided
     83   // |instance_id|.
     84   void OnGuestCallback(int instance_id,
     85                        const BrowserPluginHostMsg_Attach_Params& params,
     86                        const base::DictionaryValue* extra_params,
     87                        WebContents* guest_web_contents);
     88 
     89   // Message handlers.
     90 
     91   void OnAttach(int instance_id,
     92                 const BrowserPluginHostMsg_Attach_Params& params,
     93                 const base::DictionaryValue& extra_params);
     94   void OnPluginAtPositionResponse(int instance_id,
     95                                   int request_id,
     96                                   const gfx::Point& position);
     97 
     98   // Used to correctly update the cursor when dragging over a guest, and to
     99   // handle a race condition when dropping onto the guest that started the drag
    100   // (the race is that the dragend message arrives before the drop message so
    101   // the drop never takes place).
    102   // crbug.com/233571
    103   base::WeakPtr<BrowserPluginGuest> guest_dragging_over_;
    104 
    105   // Pointer to the guest that started the drag, used to forward necessary drag
    106   // status messages to the correct guest.
    107   base::WeakPtr<BrowserPluginGuest> guest_started_drag_;
    108 
    109   base::WeakPtrFactory<BrowserPluginEmbedder> weak_ptr_factory_;
    110 
    111   DISALLOW_COPY_AND_ASSIGN(BrowserPluginEmbedder);
    112 };
    113 
    114 }  // namespace content
    115 
    116 #endif  // CONTENT_BROWSER_BROWSER_PLUGIN_BROWSER_PLUGIN_EMBEDDER_H_
    117