2 * Copyright 2006 Jacek Caban for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
32 #include "wine/debug.h"
34 #include "mshtml_private.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
38 #define WM_PROCESSTASK 0x8008
40 void push_task(task_t
*task
)
42 thread_data_t
*thread_data
= get_thread_data(TRUE
);
44 if(thread_data
->task_queue_tail
)
45 thread_data
->task_queue_tail
->next
= task
;
47 thread_data
->task_queue_head
= task
;
49 thread_data
->task_queue_tail
= task
;
51 PostMessageW(thread_data
->thread_hwnd
, WM_PROCESSTASK
, 0, 0);
54 static task_t
*pop_task(void)
56 thread_data_t
*thread_data
= get_thread_data(TRUE
);
57 task_t
*task
= thread_data
->task_queue_head
;
62 thread_data
->task_queue_head
= task
->next
;
63 if(!thread_data
->task_queue_head
)
64 thread_data
->task_queue_tail
= NULL
;
69 void remove_doc_tasks(HTMLDocument
*doc
)
71 thread_data_t
*thread_data
= get_thread_data(FALSE
);
77 while(thread_data
->task_queue_head
78 && thread_data
->task_queue_head
->doc
== doc
)
81 for(iter
= thread_data
->task_queue_head
; iter
; iter
= iter
->next
) {
82 while(iter
->next
&& iter
->next
->doc
== doc
) {
84 iter
->next
= tmp
->next
;
89 thread_data
->task_queue_tail
= iter
;
93 static void set_downloading(HTMLDocument
*doc
)
95 IOleCommandTarget
*olecmd
;
101 IOleInPlaceFrame_SetStatusText(doc
->frame
, NULL
/* FIXME */);
106 hres
= IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&olecmd
);
107 if(SUCCEEDED(hres
)) {
113 IOleCommandTarget_Exec(olecmd
, NULL
, OLECMDID_SETDOWNLOADSTATE
, OLECMDEXECOPT_DONTPROMPTUSER
,
115 IOleCommandTarget_Release(olecmd
);
119 IDropTarget
*drop_target
= NULL
;
121 hres
= IDocHostUIHandler_GetDropTarget(doc
->hostui
, NULL
/* FIXME */, &drop_target
);
123 FIXME("Use IDropTarget\n");
124 IDropTarget_Release(drop_target
);
129 static void set_parsecomplete(HTMLDocument
*doc
)
131 IOleCommandTarget
*olecmd
= NULL
;
133 TRACE("(%p)\n", doc
);
135 call_property_onchanged(doc
->cp_propnotif
, 1005);
137 doc
->readystate
= READYSTATE_INTERACTIVE
;
138 call_property_onchanged(doc
->cp_propnotif
, DISPID_READYSTATE
);
141 IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&olecmd
);
144 VARIANT state
, progress
;
146 V_VT(&progress
) = VT_I4
;
148 IOleCommandTarget_Exec(olecmd
, NULL
, OLECMDID_SETPROGRESSPOS
, OLECMDEXECOPT_DONTPROMPTUSER
,
151 V_VT(&state
) = VT_I4
;
153 IOleCommandTarget_Exec(olecmd
, NULL
, OLECMDID_SETDOWNLOADSTATE
, OLECMDEXECOPT_DONTPROMPTUSER
,
156 IOleCommandTarget_Exec(olecmd
, &CGID_MSHTML
, IDM_PARSECOMPLETE
, 0, NULL
, NULL
);
157 IOleCommandTarget_Exec(olecmd
, NULL
, OLECMDID_HTTPEQUIV_DONE
, 0, NULL
, NULL
);
160 doc
->readystate
= READYSTATE_COMPLETE
;
161 call_property_onchanged(doc
->cp_propnotif
, DISPID_READYSTATE
);
164 static const WCHAR wszDone
[] = {'D','o','n','e',0};
165 IOleInPlaceFrame_SetStatusText(doc
->frame
, wszDone
);
172 V_VT(&title
) = VT_BSTR
;
173 V_BSTR(&title
) = SysAllocString(empty
);
174 IOleCommandTarget_Exec(olecmd
, NULL
, OLECMDID_SETTITLE
, OLECMDEXECOPT_DONTPROMPTUSER
,
176 SysFreeString(V_BSTR(&title
));
178 IOleCommandTarget_Release(olecmd
);
182 static void set_progress(HTMLDocument
*doc
)
184 IOleCommandTarget
*olecmd
= NULL
;
187 TRACE("(%p)\n", doc
);
190 IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&olecmd
);
193 VARIANT progress_max
, progress
;
195 V_VT(&progress_max
) = VT_I4
;
196 V_I4(&progress_max
) = 0; /* FIXME */
197 IOleCommandTarget_Exec(olecmd
, NULL
, OLECMDID_SETPROGRESSMAX
, OLECMDEXECOPT_DONTPROMPTUSER
,
198 &progress_max
, NULL
);
200 V_VT(&progress
) = VT_I4
;
201 V_I4(&progress
) = 0; /* FIXME */
202 IOleCommandTarget_Exec(olecmd
, NULL
, OLECMDID_SETPROGRESSPOS
, OLECMDEXECOPT_DONTPROMPTUSER
,
206 if(doc
->usermode
== EDITMODE
&& doc
->hostui
) {
207 DOCHOSTUIINFO hostinfo
;
209 memset(&hostinfo
, 0, sizeof(DOCHOSTUIINFO
));
210 hostinfo
.cbSize
= sizeof(DOCHOSTUIINFO
);
211 hres
= IDocHostUIHandler_GetHostInfo(doc
->hostui
, &hostinfo
);
213 /* FIXME: use hostinfo */
214 TRACE("hostinfo = {%u %08x %08x %s %s}\n",
215 hostinfo
.cbSize
, hostinfo
.dwFlags
, hostinfo
.dwDoubleClick
,
216 debugstr_w(hostinfo
.pchHostCss
), debugstr_w(hostinfo
.pchHostNS
));
220 static void task_start_binding(BSCallback
*bscallback
)
222 start_binding(bscallback
);
223 IBindStatusCallback_Release(STATUSCLB(bscallback
));
226 static void process_task(task_t
*task
)
228 switch(task
->task_id
) {
229 case TASK_SETDOWNLOADSTATE
:
230 return set_downloading(task
->doc
);
231 case TASK_PARSECOMPLETE
:
232 return set_parsecomplete(task
->doc
);
233 case TASK_SETPROGRESS
:
234 return set_progress(task
->doc
);
235 case TASK_START_BINDING
:
236 return task_start_binding(task
->bscallback
);
238 ERR("Wrong task_id %d\n", task
->task_id
);
242 static LRESULT WINAPI
hidden_proc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
247 task_t
*task
= pop_task();
259 FIXME("(%p %d %x %lx)\n", hwnd
, msg
, wParam
, lParam
);
261 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
264 static HWND
create_thread_hwnd(void)
266 static ATOM hidden_wnd_class
= 0;
267 static const WCHAR wszInternetExplorer_Hidden
[] = {'I','n','t','e','r','n','e','t',
268 ' ','E','x','p','l','o','r','e','r','_','H','i','d','d','e','n',0};
270 if(!hidden_wnd_class
) {
271 WNDCLASSEXW wndclass
= {
272 sizeof(WNDCLASSEXW
), 0,
274 0, 0, hInst
, NULL
, NULL
, NULL
, NULL
,
275 wszInternetExplorer_Hidden
,
279 hidden_wnd_class
= RegisterClassExW(&wndclass
);
282 return CreateWindowExW(0, wszInternetExplorer_Hidden
, NULL
, WS_POPUP
,
283 0, 0, 0, 0, NULL
, NULL
, hInst
, NULL
);
286 HWND
get_thread_hwnd(void)
288 thread_data_t
*thread_data
= get_thread_data(TRUE
);
290 if(!thread_data
->thread_hwnd
)
291 thread_data
->thread_hwnd
= create_thread_hwnd();
293 return thread_data
->thread_hwnd
;
296 thread_data_t
*get_thread_data(BOOL create
)
298 thread_data_t
*thread_data
;
302 mshtml_tls
= TlsAlloc();
307 thread_data
= TlsGetValue(mshtml_tls
);
308 if(!thread_data
&& create
) {
309 thread_data
= mshtml_alloc_zero(sizeof(thread_data_t
));
310 TlsSetValue(mshtml_tls
, thread_data
);