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
|
// Copyright 2009, Google Inc. All rights reserved.
// Portions of this file were adapted from the Mozilla project.
// See https://developer.mozilla.org/en/ActiveX_Control_for_Hosting_Netscape_Plug-ins_in_IE
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Netscape security libraries.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1994-2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Adam Lock <adamlock@eircom.net>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// File declaring StreamOperation class encapsulating basic support
// for the NPAPI GetURL streaming interface.
#ifndef O3D_PLUGIN_NPAPI_HOST_CONTROL_WIN_STREAM_OPERATION_H_
#define O3D_PLUGIN_NPAPI_HOST_CONTROL_WIN_STREAM_OPERATION_H_
#include <atlwin.h>
#include <atlstr.h>
#include <urlmon.h>
#include "third_party/npapi/files/include/npupp.h"
class NPPluginProxy;
#define WM_NPP_NEWSTREAM WM_USER
#define WM_NPP_ASFILE WM_USER + 1
#define WM_NPP_DESTROYSTREAM WM_USER + 2
#define WM_NPP_URLNOTIFY WM_USER + 3
#define WM_NPP_WRITEREADY WM_USER + 4
#define WM_NPP_WRITE WM_USER + 5
#define WM_TEAR_DOWN WM_USER + 10
// StreamOperation class used to provide a subset of the NPAPI GetURL* API.
// Class makes use of urlmon's IBindStatusCallback to receive notifications
// from urlmon as data is transferred. Refer to the MSDN documentation
// for information on the usage model of IBindStatusCallback.
class ATL_NO_VTABLE StreamOperation :
public CComObjectRootEx<CComMultiThreadModel>,
public CWindowImpl<StreamOperation, CWindow, CNullTraits>,
public CComCoClass<StreamOperation, &CLSID_NULL>,
public IBindStatusCallback {
public:
typedef CWindowImpl<StreamOperation, CWindow, CNullTraits> CWindowImplBase;
StreamOperation();
~StreamOperation();
// Assign/Retrieve the url from which to stream the data.
void SetURL(const wchar_t* url) {
url_ = url;
}
const ATL::CStringW& GetURL() const {
return url_;
}
void SetFullURL(const wchar_t* url) {
full_url_ = url;
}
const ATL::CStringW& GetFullURL() const {
return full_url_;
}
// Returns the MIME-type of the data stream.
const ATL::CStringW& GetContentType() const {
return content_type_;
}
NPStream* GetNPStream() {
return &np_stream_;
}
HANDLE GetThreadHandle() const {
return thread_handle_;
}
// Assign the owning plugin pointer that spawned this operation.
void SetOwner(NPPluginProxy* plugin) {
owner_ = plugin;
}
// Assign/Retrieve the opaque NPAPI-provided callback data for the
// stream-operation.
void SetNotifyData(void *notify_data) {
notify_data_ = notify_data;
}
void* GetNotifyData() {
return notify_data_;
}
// Call to request that the streaming operation terminate early. As soon as
// the streaming thread sees the request has been cancelled, it aborts its
// binding.
HRESULT RequestCancellation();
BEGIN_COM_MAP(StreamOperation)
COM_INTERFACE_ENTRY(IBindStatusCallback)
END_COM_MAP()
// To allow interaction with non-thread-safe NPAPI plug-in modules, the
// streaming code uses Windows message pumps to serialize the interactions
// calling back into the plug-in on the thread in which the plug-in resides.
// When information about the state of the streaming request is provided
// through a IBindStatusCallback routine, the thread will post a message
// to the window created by the StreamOperation instance. Because this
// window will reside in the same thread as the calling plug-in, we are
// guaranteed serialization and mutual exclusion of the handling of the
// routines below.
BEGIN_MSG_MAP(StreamOperation)
MESSAGE_HANDLER(WM_NPP_NEWSTREAM, OnNPPNewStream)
MESSAGE_HANDLER(WM_NPP_ASFILE, OnNPPAsFile)
MESSAGE_HANDLER(WM_NPP_DESTROYSTREAM, OnNPPDestroyStream)
MESSAGE_HANDLER(WM_NPP_URLNOTIFY, OnNPPUrlNotify)
MESSAGE_HANDLER(WM_NPP_WRITEREADY, OnNPPWriteReady)
MESSAGE_HANDLER(WM_NPP_WRITE, OnNPPWrite)
MESSAGE_HANDLER(WM_TEAR_DOWN, OnTearDown);
END_MSG_MAP()
// Helper function called in response to WM_TEAR_DOWN to destroy class
// resources on the appropriate thread.
LRESULT OnTearDown(UINT uMsg,
WPARAM wParam,
LPARAM lParam,
BOOL& bHandled);
// The following OnNPP... routines forward the respective notification to
// the plugin that spawned the data transmission.
LRESULT OnNPPNewStream(UINT uMsg,
WPARAM wParam,
LPARAM lParam,
BOOL& bHandled);
LRESULT OnNPPDestroyStream(UINT uMsg,
WPARAM wParam,
LPARAM lParam,
BOOL& bHandled);
LRESULT OnNPPAsFile(UINT uMsg,
WPARAM wParam,
LPARAM lParam,
BOOL& bHandled);
LRESULT OnNPPUrlNotify(UINT uMsg,
WPARAM wParam,
LPARAM lParam,
BOOL& bHandled);
LRESULT OnNPPWriteReady(UINT uMsg,
WPARAM wParam,
LPARAM lParam,
BOOL& bHandled);
LRESULT OnNPPWrite(UINT uMsg,
WPARAM wParam,
LPARAM lParam,
BOOL& bHandled);
// Methods implementing the IBindStatusCallback interface. Refer to
// the MSDN documentation for the expected behaviour of these routines.
virtual HRESULT STDMETHODCALLTYPE OnStartBinding(DWORD dwReserved,
IBinding *pib);
virtual HRESULT STDMETHODCALLTYPE GetPriority(LONG *pnPriority);
virtual HRESULT STDMETHODCALLTYPE OnLowResource(DWORD reserved);
virtual HRESULT STDMETHODCALLTYPE OnProgress(ULONG ulProgress,
ULONG ulProgressMax,
ULONG ulStatusCode,
LPCWSTR szStatusText);
virtual HRESULT STDMETHODCALLTYPE OnStopBinding(HRESULT hresult,
LPCWSTR szError);
virtual HRESULT STDMETHODCALLTYPE GetBindInfo(DWORD *grfBINDF,
BINDINFO *pbindinfo);
virtual HRESULT STDMETHODCALLTYPE OnDataAvailable(DWORD grfBSCF,
DWORD dwSize,
FORMATETC *pformatetc,
STGMEDIUM *pstgmed);
virtual HRESULT STDMETHODCALLTYPE OnObjectAvailable(REFIID riid,
IUnknown *punk);
static HRESULT OpenURL(NPPluginProxy *owning_plugin, const wchar_t* url,
void *notify_data);
virtual void OnFinalMessage(HWND hWnd);
DECLARE_PROTECT_FINAL_CONSTRUCT();
private:
// Callback object for interacting with the urlmon streaming manager.
ATL::CComPtr<IBinding> binding_;
// The url from which the data is fetched, and the associated MIME-type.
ATL::CStringW url_;
ATL::CStringW full_url_;
ATL::CStringW content_type_;
// Back-pointer to the plug-in instance requesting the data transfer.
NPPluginProxy *owner_;
// Opaque data specified at request initiation that is passed back to the
// plug-in during call-back invocation.
void *notify_data_;
NPStream np_stream_;
int stream_size_;
int stream_received_;
// Cache of the type of stream requested by the plug-in. May be one of:
// NP_NORMAL, NP_ASFILE, NP_ASFILEONLY.
int stream_type_;
// Pointer to file handle used to save incoming data if the stream type is
// NP_ASFILE or NP_ASFILEONLY.
FILE* temp_file_;
// Temporary file name.
CStringW temp_file_name_;
// Handle to the worker-thread where the streaming notifications are received.
HANDLE thread_handle_;
// Value used to indicate the streaming operation should stop processing
// input data.
bool cancel_requested_;
static unsigned int __stdcall WorkerProc(void *worker_arguments);
DISALLOW_COPY_AND_ASSIGN(StreamOperation);
};
#endif // O3D_PLUGIN_NPAPI_HOST_CONTROL_WIN_STREAM_OPERATION_H_
|