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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
|
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "webkit/activex_shim/web_activex_container.h"
#include "webkit/activex_shim/activex_plugin.h"
#include "webkit/activex_shim/activex_util.h"
#include "webkit/activex_shim/npn_scripting.h"
#include "webkit/activex_shim/npp_impl.h"
#include "webkit/activex_shim/web_activex_site.h"
namespace activex_shim {
// WebActiveXContainer
WebActiveXContainer::WebActiveXContainer()
: plugin_(NULL),
container_wnd_(NULL) {
}
WebActiveXContainer::~WebActiveXContainer() {
// Don't do anything here. Do everything in FinalRelease.
}
void WebActiveXContainer::Init(ActiveXPlugin* plugin) {
plugin_ = plugin;
}
void WebActiveXContainer::FinalRelease() {
container_wnd_ = NULL;
for (unsigned int i = 0; i < sites_.size(); i++) {
delete sites_[i];
}
sites_.clear();
}
// IUnknown
HRESULT STDMETHODCALLTYPE WebActiveXContainer::QueryInterface(
REFIID iid,
void** object) {
*object = NULL;
if (iid == IID_IUnknown) {
*object = static_cast<IUnknown*>(static_cast<IOleContainer*>(this));
} else if (iid == IID_IDispatch) {
*object = static_cast<IDispatch*>(static_cast<IHTMLDocument2Impl*>(this));
} else if (iid == IID_IParseDisplayName) {
*object = static_cast<IParseDisplayName*>(this);
} else if (iid == IID_IOleContainer) {
*object = static_cast<IOleContainer*>(this);
} else if (iid == IID_IOleWindow) {
*object = static_cast<IOleWindow*>(this);
} else if (iid == IID_IOleInPlaceUIWindow) {
*object = static_cast<IOleInPlaceUIWindow*>(this);
} else if (iid == IID_IOleInPlaceFrame) {
*object = static_cast<IOleInPlaceFrame*>(this);
} else if (iid == IID_IHTMLDocument) {
*object = static_cast<IHTMLDocument*>(this);
} else if (iid == IID_IHTMLDocument2) {
*object = static_cast<IHTMLDocument2*>(this);
} else if (iid == IID_IWebBrowser) {
*object = static_cast<IWebBrowser*>(this);
} else if (iid == IID_IWebBrowserApp) {
*object = static_cast<IWebBrowserApp*>(this);
} else if (iid == IID_IWebBrowser2) {
*object = static_cast<IWebBrowser2*>(this);
} else if (iid == IID_IBindHost) {
*object = static_cast<IBindHost*>(this);
}
TRACK_QUERY_INTERFACE(iid, *object != NULL);
return (*object != NULL) ? S_OK : E_NOINTERFACE;
}
// IParseDisplayName
HRESULT STDMETHODCALLTYPE WebActiveXContainer::ParseDisplayName(
IBindCtx* bc,
LPOLESTR display_name,
ULONG* cheaten,
IMoniker** moniker) {
TRACK_METHOD();
// Do not support this.
return E_NOTIMPL;
}
// IOleContainer
HRESULT STDMETHODCALLTYPE WebActiveXContainer::EnumObjects(DWORD flags,
IEnumUnknown** ppenum) {
TRACK_METHOD();
// Do not support enumeration.
return E_NOTIMPL;
};
HRESULT STDMETHODCALLTYPE WebActiveXContainer::LockContainer(BOOL lock) {
TRACK_METHOD();
// Do not allow locking container.
return E_NOTIMPL;
};
// IOleWindow
HRESULT STDMETHODCALLTYPE WebActiveXContainer::GetWindow(HWND* wnd) {
TRACK_METHOD();
*wnd = container_wnd();
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebActiveXContainer::ContextSensitiveHelp(
BOOL enter_mode) {
TRACK_METHOD();
return E_NOTIMPL;
}
// IOleInPlaceUIWindow
HRESULT STDMETHODCALLTYPE WebActiveXContainer::GetBorder(LPRECT border) {
TRACK_METHOD();
// Does not allow tool bar etc.
return INPLACE_E_NOTOOLSPACE;
}
HRESULT STDMETHODCALLTYPE WebActiveXContainer::RequestBorderSpace(
LPCBORDERWIDTHS border_widths) {
TRACK_METHOD();
return INPLACE_E_NOTOOLSPACE;
}
HRESULT STDMETHODCALLTYPE WebActiveXContainer::SetBorderSpace(
LPCBORDERWIDTHS border_widths) {
TRACK_METHOD();
return E_UNEXPECTED;
}
HRESULT STDMETHODCALLTYPE WebActiveXContainer::SetActiveObject(
IOleInPlaceActiveObject* active_object,
LPCOLESTR obj_name) {
TRACK_METHOD();
// Ignore whatever.
return S_OK;
}
// IOleInPlaceFrame
HRESULT STDMETHODCALLTYPE WebActiveXContainer::InsertMenus(
HMENU hmenu_shared,
LPOLEMENUGROUPWIDTHS menu_widths) {
TRACK_METHOD();
// No menu is allowed.
return E_UNEXPECTED;
}
HRESULT STDMETHODCALLTYPE WebActiveXContainer::SetMenu(
HMENU hmenu_shared,
HOLEMENU hole_menu,
HWND active_object) {
TRACK_METHOD();
return E_UNEXPECTED;
}
HRESULT STDMETHODCALLTYPE WebActiveXContainer::RemoveMenus(
HMENU hmenu_shared) {
TRACK_METHOD();
return E_UNEXPECTED;
}
HRESULT STDMETHODCALLTYPE WebActiveXContainer::SetStatusText(
LPCOLESTR status_text) {
TRACK_METHOD();
return E_UNEXPECTED;
}
HRESULT STDMETHODCALLTYPE WebActiveXContainer::EnableModeless(BOOL enable) {
TRACK_METHOD();
return E_UNEXPECTED;
}
HRESULT STDMETHODCALLTYPE WebActiveXContainer::TranslateAccelerator(
LPMSG msg,
WORD id) {
TRACK_METHOD();
// TODO(ruijiang): Link it with browser message processing.
// Returning S_FALSE means: The keystroke was not used.
return S_FALSE;
}
// IHTMLDocument2
HRESULT STDMETHODCALLTYPE WebActiveXContainer::get_URL(BSTR* p) {
TRACK_METHOD();
std::wstring url = plugin_->GetCurrentURL();
*p = SysAllocString(url.c_str());
return S_OK;
}
HRESULT STDMETHODCALLTYPE WebActiveXContainer::get_cookie(BSTR* p) {
TRACK_METHOD();
*p = SysAllocString(plugin_->GetWindow().
GetObjectProperty("document").GetStringProperty("cookie").c_str());
return S_OK;
}
// IWebBrowser
HRESULT STDMETHODCALLTYPE WebActiveXContainer::Navigate(
BSTR url,
VARIANT* flags,
VARIANT* target_frame_name,
VARIANT* post_data,
VARIANT* headers) {
TRACK_METHOD();
// TODO(ruijiang): See if we need to handle the optional params.
plugin_->GetWindow().Invoke("open", "%s%s", url, L"_blank");
return S_OK;
}
// IWebBrowserApp
HRESULT STDMETHODCALLTYPE WebActiveXContainer::get_LocationURL(
BSTR* location_url) {
return get_URL(location_url);
}
// IBindHost
// Flash uses CreateMoniker to get the url of the movie its "movie" parameter
// points to. We must implement this otherwise Flash will not work.
HRESULT STDMETHODCALLTYPE WebActiveXContainer::CreateMoniker(
LPOLESTR szName,
IBindCtx* bc,
IMoniker** mk,
DWORD reserved) {
TRACK_METHOD();
std::wstring url = plugin_->ResolveURL(szName);
HRESULT hr = CreateURLMoniker(NULL, url.c_str(), mk);
return hr;
}
HRESULT STDMETHODCALLTYPE WebActiveXContainer::MonikerBindToStorage(
IMoniker* mk,
IBindCtx* bc,
IBindStatusCallback* bsc,
REFIID riid,
void** obj) {
// QuickTime uses this function to get the movie data from the container.
TRACK_METHOD();
IBindCtx* new_bc = NULL;
// Logic is a little tricky here. When bc is passed in, we should use that;
// otherwise we need to create a new one and release it after done.
IBindCtx* bc_to_use = bc;
if (bc == NULL) {
CreateBindCtx(0, &new_bc);
if (!new_bc)
return E_FAIL;
bc_to_use = new_bc;
}
// We must register the callback otherwise control will not know when new
// data arrive.
if (bsc)
RegisterBindStatusCallback(bc_to_use, bsc, NULL, 0);
HRESULT hr = mk->BindToStorage(bc_to_use, NULL, riid, obj);
if (new_bc)
new_bc->Release();
return hr;
}
HRESULT STDMETHODCALLTYPE WebActiveXContainer::MonikerBindToObject(
IMoniker* mk,
IBindCtx* bc,
IBindStatusCallback* bsc,
REFIID riid,
void** obj) {
TRACK_METHOD();
return E_NOTIMPL;
}
HRESULT WebActiveXContainer::CreateControlWithSite(const wchar_t* clsid) {
HRESULT hr;
CLSID id;
hr = CLSIDFromString(const_cast<LPOLESTR>(clsid), &id);
if (FAILED(hr))
return hr;
IUnknown* control;
hr = CoCreateInstance(id, NULL, CLSCTX_INPROC_SERVER, __uuidof(IUnknown),
(LPVOID*)&control);
if (FAILED(hr))
return hr;
// First try to get the IObjectSafety interface and get/set options.
// If failed then see if the object has registered itself as safe.
unsigned long safety_flag = GetAndSetObjectSafetyOptions(control);
if (!(safety_flag & SAFE_FOR_INITIALIZING) ||
!(safety_flag & SAFE_FOR_SCRIPTING)) {
safety_flag = GetRegisteredObjectSafetyOptions(id);
if (!(safety_flag & SAFE_FOR_INITIALIZING) ||
!(safety_flag & SAFE_FOR_SCRIPTING))
return E_FAIL;
}
// Create client site and pass it to the control.
WebActiveXSite* site = new NoRefIUnknownImpl<WebActiveXSite>;
// From now on, we should assume site will take care of the lifecycle
// of control.
site->Init(this, control);
control = NULL;
sites_.push_back(site);
return S_OK;
}
bool WebActiveXContainer::OnWindowMessage(UINT msg, WPARAM wparam,
LPARAM lparam, LRESULT* result) {
HRESULT hr;
for (unsigned int i = 0; i < sites_.size(); i++) {
WebActiveXSite* site = sites_[i];
CComQIPtr<IOleInPlaceObjectWindowless> windowless = site->control_;
if (windowless == NULL)
continue;
if (msg == WM_MOUSEMOVE || msg == WM_LBUTTONDOWN || msg == WM_LBUTTONUP) {
POINT pt;
pt.x = LOWORD(lparam);
pt.y = HIWORD(lparam);
if (PtInRect(&site->rect_, pt)) {
hr = windowless->OnWindowMessage(msg, wparam, lparam, result);
if (hr == S_OK)
return true;
}
}
}
// We did not consume the message. The caller can now process it.
return false;
}
IUnknown* WebActiveXContainer::GetFirstControl() {
if (sites_.size()) {
return sites_[0]->control_;
} else {
return NULL;
}
}
WebActiveXSite* WebActiveXContainer::GetFirstSite() {
if (sites_.size()) {
return sites_[0];
} else {
return NULL;
}
}
} // namespace activex_shim
|