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