summaryrefslogtreecommitdiffstats
path: root/webkit/activex_shim/web_activex_container.h
blob: 6b0e2b0dbcf19b35ffed0b936a017c1d976124b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// Copyright 2008, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//    * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//    * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//    * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#ifndef WEBKIT_ACTIVEX_SHIM_WEB_ACTIVEX_CONTAINER_H__
#define WEBKIT_ACTIVEX_SHIM_WEB_ACTIVEX_CONTAINER_H__

#include <atlbase.h>
#include <atlcom.h>
#include <string>
#include <vector>
#include "webkit/activex_shim/activex_util.h"
#include "webkit/activex_shim/ihtmldocument_impl.h"
#include "webkit/activex_shim/iwebbrowser_impl.h"

namespace activex_shim {

class ActiveXPlugin;
class WebActiveXSite;

// WebActiveXContainer, as the container of the ActiveX control,
// implements the basic interfaces need to manage and interact with ActiveX
// controls.
// Theoretically this container can hold multiple sites/controls. However,
// in our case we only use 1 container per control for now.
//
// IOleContainer:
//   Required interface.
// IOleInPlaceFrame
//   Required interface.
// IHTMLDocument2:
//   WMP will query this interface to get URL.
// IWebBrowser2:
//   Flash will use IWebBrowser::Navigate to open a URL.
// IBindHost:
//   Flash will use this interface to resolve URL.
class WebActiveXContainer : public IOleContainer,
                            public IOleInPlaceFrame,
                            public IHTMLDocument2Impl,
                            public IWebBrowser2Impl,
                            public IBindHost {
 public:
  WebActiveXContainer();
  virtual ~WebActiveXContainer();

  // Initialize container with related ActiveXPlugin.
  void Init(ActiveXPlugin* plugin);
  // Deactivate and release contained controls. called by outer
  // NoRefIUnknownImpl's destructor.
  void FinalRelease();

  // Create ActiveX control together with its site. Do not do any initialization
  // now but we will query the interface that the control can support,
  // to decide whether it is viewable, supports windowless etc.
  HRESULT CreateControlWithSite(const wchar_t* clsid);
  // Called by ActiveXPlugin when it gets browser window first time.
  void set_container_wnd(HWND hwnd) { container_wnd_ = hwnd; }
  HWND container_wnd() { return container_wnd_; }
  // Returns the IUnknown of the first control. NULL if it doesn't have any.
  IUnknown* GetFirstControl();
  // Returns the first site. NULL if it doesn't have any.
  WebActiveXSite* GetFirstSite();
  ActiveXPlugin* plugin() { return plugin_; }

  // The containing Window should call this upon messages. Return true if we
  // consumed the message
  bool OnWindowMessage(UINT msg, WPARAM wparam, LPARAM lparam,
                       LRESULT* result);

  // IUnknown
  virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid,
                                                   void** object);

  // IDispatch
  virtual HRESULT STDMETHODCALLTYPE GetTypeInfoCount(UINT* ctinfo) {
    TRACK_METHOD();
    *ctinfo = 0;
    return S_OK;
  }
  virtual HRESULT STDMETHODCALLTYPE GetTypeInfo(UINT itinfo, LCID lcid,
                                                ITypeInfo** tinfo) {
    TRACK_METHOD();
    return E_NOTIMPL;
  }
  virtual HRESULT STDMETHODCALLTYPE GetIDsOfNames(
      REFIID riid,
      LPOLESTR* names,
      UINT cnames,
      LCID lcid,
      DISPID* dispids) {
    TRACK_METHOD();
    return E_NOTIMPL;
  }
  virtual HRESULT STDMETHODCALLTYPE Invoke(
      DISPID dispid,
      REFIID riid,
      LCID lcid,
      WORD flags,
      DISPPARAMS* params,
      VARIANT* result,
      EXCEPINFO* except_info,
      UINT* arg_error) {
    TRACK_METHOD();
    return E_NOTIMPL;
  }

  // IParseDisplayName
  virtual HRESULT STDMETHODCALLTYPE ParseDisplayName(
      IBindCtx* bc,
      LPOLESTR display_name,
      ULONG* cheaten,
      IMoniker** moniker);

  // IOleContainer
  virtual HRESULT STDMETHODCALLTYPE EnumObjects(DWORD flags,
      IEnumUnknown** ppenum);
  virtual HRESULT STDMETHODCALLTYPE LockContainer(BOOL lock);

  // IOleWindow
  virtual HRESULT STDMETHODCALLTYPE GetWindow(HWND* wnd);
  virtual HRESULT STDMETHODCALLTYPE ContextSensitiveHelp(BOOL enter_mode);

  // IOleInPlaceUIWindow
  virtual HRESULT STDMETHODCALLTYPE GetBorder(LPRECT border);
  virtual HRESULT STDMETHODCALLTYPE RequestBorderSpace(
      LPCBORDERWIDTHS border_widths);
  virtual HRESULT STDMETHODCALLTYPE SetBorderSpace(
      LPCBORDERWIDTHS border_widths);
  virtual HRESULT STDMETHODCALLTYPE SetActiveObject(
      IOleInPlaceActiveObject* active_object,
      LPCOLESTR obj_name);

  // IOleInPlaceFrame
  virtual HRESULT STDMETHODCALLTYPE InsertMenus(
      HMENU hmenu_shared,
      LPOLEMENUGROUPWIDTHS menu_widths);
  virtual HRESULT STDMETHODCALLTYPE SetMenu(
      HMENU hmenu_shared,
      HOLEMENU hole_menu,
      HWND active_object);
  virtual HRESULT STDMETHODCALLTYPE RemoveMenus(HMENU hmenu_shared);
  virtual HRESULT STDMETHODCALLTYPE SetStatusText(LPCOLESTR status_text);
  virtual HRESULT STDMETHODCALLTYPE EnableModeless(BOOL enable);
  virtual HRESULT STDMETHODCALLTYPE TranslateAccelerator(
      LPMSG msg,
      WORD id);

  // IHTMLDocument2
  virtual HRESULT STDMETHODCALLTYPE get_URL(BSTR* p);
  virtual HRESULT STDMETHODCALLTYPE get_cookie(BSTR* p);

  // IWebBrowser
  virtual HRESULT STDMETHODCALLTYPE Navigate(BSTR url,
                                             VARIANT* flags,
                                             VARIANT* target_frame_name,
                                             VARIANT* post_data,
                                             VARIANT* headers);

  // IWebBrowserApp
  virtual HRESULT STDMETHODCALLTYPE get_LocationURL(BSTR* location_url);

  // IBindHost
  virtual HRESULT STDMETHODCALLTYPE CreateMoniker(
      LPOLESTR szName,
      IBindCtx* bc,
      IMoniker** mk,
      DWORD reserved);
  virtual HRESULT STDMETHODCALLTYPE MonikerBindToStorage(
      IMoniker* mk,
      IBindCtx* bc,
      IBindStatusCallback* bsc,
      REFIID riid,
      void** obj);
  virtual HRESULT STDMETHODCALLTYPE MonikerBindToObject(
      IMoniker* mk,
      IBindCtx* bc,
      IBindStatusCallback* bsc,
      REFIID riid,
      void** obj);

 private:
  ActiveXPlugin* plugin_;
  HWND container_wnd_;
  std::vector<WebActiveXSite*> sites_;

  DISALLOW_EVIL_CONSTRUCTORS(WebActiveXContainer);
};

}  // namespace activex_shim

#endif // #ifndef WEBKIT_ACTIVEX_SHIM_WEB_ACTIVEX_CONTAINER_H__