Home | History | Annotate | Download | only in 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 #ifndef CONTENT_PLUGIN_WEBPLUGIN_DELEGATE_STUB_H_
      6 #define CONTENT_PLUGIN_WEBPLUGIN_DELEGATE_STUB_H_
      7 
      8 #include <string>
      9 #include <vector>
     10 
     11 #include "base/memory/ref_counted.h"
     12 #include "content/child/npapi/npobject_stub.h"
     13 #include "ipc/ipc_listener.h"
     14 #include "ipc/ipc_sender.h"
     15 #include "third_party/npapi/bindings/npapi.h"
     16 #include "ui/gfx/native_widget_types.h"
     17 #include "ui/gfx/rect.h"
     18 #include "url/gurl.h"
     19 
     20 struct PluginMsg_Init_Params;
     21 struct PluginMsg_DidReceiveResponseParams;
     22 struct PluginMsg_UpdateGeometry_Param;
     23 class WebCursor;
     24 
     25 namespace WebKit {
     26 class WebInputEvent;
     27 }
     28 
     29 namespace content {
     30 class PluginChannel;
     31 class WebPluginDelegateImpl;
     32 class WebPluginProxy;
     33 
     34 // Converts the IPC messages from WebPluginDelegateProxy into calls to the
     35 // actual WebPluginDelegateImpl object.
     36 class WebPluginDelegateStub : public IPC::Listener,
     37                               public IPC::Sender,
     38                               public base::RefCounted<WebPluginDelegateStub> {
     39  public:
     40   WebPluginDelegateStub(const std::string& mime_type, int instance_id,
     41                         PluginChannel* channel);
     42 
     43   // IPC::Listener implementation:
     44   virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE;
     45 
     46   // IPC::Sender implementation:
     47   virtual bool Send(IPC::Message* msg) OVERRIDE;
     48 
     49   int instance_id() { return instance_id_; }
     50   WebPluginProxy* webplugin() { return webplugin_; }
     51 
     52  private:
     53   friend class base::RefCounted<WebPluginDelegateStub>;
     54 
     55   virtual ~WebPluginDelegateStub();
     56 
     57   // Message handlers for the WebPluginDelegate calls that are proxied from the
     58   // renderer over the IPC channel.
     59   void OnInit(const PluginMsg_Init_Params& params,
     60               bool* transparent,
     61               bool* result);
     62   void OnWillSendRequest(int id, const GURL& url, int http_status_code);
     63   void OnDidReceiveResponse(const PluginMsg_DidReceiveResponseParams& params);
     64   void OnDidReceiveData(int id, const std::vector<char>& buffer,
     65                         int data_offset);
     66   void OnDidFinishLoading(int id);
     67   void OnDidFail(int id);
     68   void OnDidFinishLoadWithReason(const GURL& url, int reason, int notify_id);
     69   void OnSetFocus(bool focused);
     70   void OnHandleInputEvent(const WebKit::WebInputEvent* event,
     71                           bool* handled, WebCursor* cursor);
     72   void OnPaint(const gfx::Rect& damaged_rect);
     73   void OnDidPaint();
     74   void OnUpdateGeometry(const PluginMsg_UpdateGeometry_Param& param);
     75   void OnGetPluginScriptableObject(int* route_id);
     76   void OnSendJavaScriptStream(const GURL& url,
     77                               const std::string& result,
     78                               bool success,
     79                               int notify_id);
     80   void OnGetFormValue(string16* value, bool* success);
     81 
     82   void OnSetContentAreaFocus(bool has_focus);
     83 #if defined(OS_WIN) && !defined(USE_AURA)
     84   void OnImeCompositionUpdated(const string16& text,
     85                                const std::vector<int>& clauses,
     86                                const std::vector<int>& target,
     87                                int cursor_position);
     88   void OnImeCompositionCompleted(const string16& text);
     89 #endif
     90 #if defined(OS_MACOSX)
     91   void OnSetWindowFocus(bool has_focus);
     92   void OnContainerHidden();
     93   void OnContainerShown(gfx::Rect window_frame, gfx::Rect view_frame,
     94                         bool has_focus);
     95   void OnWindowFrameChanged(const gfx::Rect& window_frame,
     96                             const gfx::Rect& view_frame);
     97   void OnImeCompositionCompleted(const string16& text);
     98 #endif
     99 
    100   void OnDidReceiveManualResponse(
    101       const GURL& url,
    102       const PluginMsg_DidReceiveResponseParams& params);
    103   void OnDidReceiveManualData(const std::vector<char>& buffer);
    104   void OnDidFinishManualLoading();
    105   void OnDidManualLoadFail();
    106   void OnHandleURLRequestReply(unsigned long resource_id,
    107                                const GURL& url,
    108                                int notify_id);
    109   void OnHTTPRangeRequestReply(unsigned long resource_id, int range_request_id);
    110 
    111   std::string mime_type_;
    112   int instance_id_;
    113 
    114   scoped_refptr<PluginChannel> channel_;
    115 
    116   base::WeakPtr<NPObjectStub> plugin_scriptable_object_;
    117   WebPluginDelegateImpl* delegate_;
    118   WebPluginProxy* webplugin_;
    119   bool in_destructor_;
    120 
    121   // The url of the main frame hosting the plugin.
    122   GURL page_url_;
    123 
    124   DISALLOW_IMPLICIT_CONSTRUCTORS(WebPluginDelegateStub);
    125 };
    126 
    127 }  // namespace content
    128 
    129 #endif  // CONTENT_PLUGIN_WEBPLUGIN_DELEGATE_STUB_H_
    130