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
39 #define TIMER_ID 0x3000
50 void push_task(task_t
*task
)
52 thread_data_t
*thread_data
= get_thread_data(TRUE
);
54 if(thread_data
->task_queue_tail
)
55 thread_data
->task_queue_tail
->next
= task
;
57 thread_data
->task_queue_head
= task
;
59 thread_data
->task_queue_tail
= task
;
61 PostMessageW(thread_data
->thread_hwnd
, WM_PROCESSTASK
, 0, 0);
64 static task_t
*pop_task(void)
66 thread_data_t
*thread_data
= get_thread_data(TRUE
);
67 task_t
*task
= thread_data
->task_queue_head
;
72 thread_data
->task_queue_head
= task
->next
;
73 if(!thread_data
->task_queue_head
)
74 thread_data
->task_queue_tail
= NULL
;
79 static void release_task_timer(HWND thread_hwnd
, task_timer_t
*timer
)
81 list_remove(&timer
->entry
);
83 KillTimer(thread_hwnd
, timer
->id
);
84 IDispatch_Release(timer
->disp
);
89 void remove_doc_tasks(const HTMLDocument
*doc
)
91 thread_data_t
*thread_data
= get_thread_data(FALSE
);
92 struct list
*liter
, *ltmp
;
96 LIST_FOR_EACH_SAFE(liter
, ltmp
, &thread_data
->timer_list
) {
97 timer
= LIST_ENTRY(liter
, task_timer_t
, entry
);
99 release_task_timer(thread_data
->thread_hwnd
, timer
);
102 if(!list_empty(&thread_data
->timer_list
)) {
103 timer
= LIST_ENTRY(list_head(&thread_data
->timer_list
), task_timer_t
, entry
);
104 SetTimer(thread_data
->thread_hwnd
, TIMER_ID
, timer
->time
- GetTickCount(), NULL
);
110 while(thread_data
->task_queue_head
111 && thread_data
->task_queue_head
->doc
== doc
)
114 for(iter
= thread_data
->task_queue_head
; iter
; iter
= iter
->next
) {
115 while(iter
->next
&& iter
->next
->doc
== doc
) {
117 iter
->next
= tmp
->next
;
122 thread_data
->task_queue_tail
= iter
;
126 DWORD
set_task_timer(HTMLDocument
*doc
, DWORD msec
, IDispatch
*disp
)
128 thread_data_t
*thread_data
= get_thread_data(TRUE
);
130 DWORD tc
= GetTickCount();
132 static DWORD id_cnt
= 0x20000000;
134 timer
= heap_alloc(sizeof(task_timer_t
));
135 timer
->id
= id_cnt
++;
137 timer
->time
= tc
+ msec
;
139 IDispatch_AddRef(disp
);
142 if(list_empty(&thread_data
->timer_list
)
143 || LIST_ENTRY(list_head(&thread_data
->timer_list
), task_timer_t
, entry
)->time
> timer
->time
) {
145 list_add_head(&thread_data
->timer_list
, &timer
->entry
);
146 SetTimer(thread_data
->thread_hwnd
, TIMER_ID
, msec
, NULL
);
150 LIST_FOR_EACH_ENTRY(iter
, &thread_data
->timer_list
, task_timer_t
, entry
) {
151 if(iter
->time
> timer
->time
) {
152 list_add_tail(&iter
->entry
, &timer
->entry
);
157 list_add_tail(&thread_data
->timer_list
, &timer
->entry
);
163 static void set_downloading(HTMLDocument
*doc
)
165 IOleCommandTarget
*olecmd
;
168 TRACE("(%p)\n", doc
);
171 IOleInPlaceFrame_SetStatusText(doc
->frame
, NULL
/* FIXME */);
176 hres
= IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&olecmd
);
177 if(SUCCEEDED(hres
)) {
183 IOleCommandTarget_Exec(olecmd
, NULL
, OLECMDID_SETDOWNLOADSTATE
, OLECMDEXECOPT_DONTPROMPTUSER
,
185 IOleCommandTarget_Release(olecmd
);
189 IDropTarget
*drop_target
= NULL
;
191 hres
= IDocHostUIHandler_GetDropTarget(doc
->hostui
, NULL
/* FIXME */, &drop_target
);
193 FIXME("Use IDropTarget\n");
194 IDropTarget_Release(drop_target
);
199 static void set_parsecomplete(HTMLDocument
*doc
)
201 IOleCommandTarget
*olecmd
= NULL
;
203 TRACE("(%p)\n", doc
);
205 if(doc
->usermode
== EDITMODE
)
208 call_property_onchanged(&doc
->cp_propnotif
, 1005);
210 doc
->readystate
= READYSTATE_INTERACTIVE
;
211 call_property_onchanged(&doc
->cp_propnotif
, DISPID_READYSTATE
);
214 IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&olecmd
);
217 VARIANT state
, progress
;
219 V_VT(&progress
) = VT_I4
;
221 IOleCommandTarget_Exec(olecmd
, NULL
, OLECMDID_SETPROGRESSPOS
, OLECMDEXECOPT_DONTPROMPTUSER
,
224 V_VT(&state
) = VT_I4
;
226 IOleCommandTarget_Exec(olecmd
, NULL
, OLECMDID_SETDOWNLOADSTATE
, OLECMDEXECOPT_DONTPROMPTUSER
,
229 IOleCommandTarget_Exec(olecmd
, &CGID_MSHTML
, IDM_PARSECOMPLETE
, 0, NULL
, NULL
);
230 IOleCommandTarget_Exec(olecmd
, NULL
, OLECMDID_HTTPEQUIV_DONE
, 0, NULL
, NULL
);
232 IOleCommandTarget_Release(olecmd
);
235 doc
->readystate
= READYSTATE_COMPLETE
;
236 call_property_onchanged(&doc
->cp_propnotif
, DISPID_READYSTATE
);
239 static const WCHAR wszDone
[] = {'D','o','n','e',0};
240 IOleInPlaceFrame_SetStatusText(doc
->frame
, wszDone
);
246 static void set_progress(HTMLDocument
*doc
)
248 IOleCommandTarget
*olecmd
= NULL
;
251 TRACE("(%p)\n", doc
);
254 IOleClientSite_QueryInterface(doc
->client
, &IID_IOleCommandTarget
, (void**)&olecmd
);
257 VARIANT progress_max
, progress
;
259 V_VT(&progress_max
) = VT_I4
;
260 V_I4(&progress_max
) = 0; /* FIXME */
261 IOleCommandTarget_Exec(olecmd
, NULL
, OLECMDID_SETPROGRESSMAX
, OLECMDEXECOPT_DONTPROMPTUSER
,
262 &progress_max
, NULL
);
264 V_VT(&progress
) = VT_I4
;
265 V_I4(&progress
) = 0; /* FIXME */
266 IOleCommandTarget_Exec(olecmd
, NULL
, OLECMDID_SETPROGRESSPOS
, OLECMDEXECOPT_DONTPROMPTUSER
,
270 if(doc
->usermode
== EDITMODE
&& doc
->hostui
) {
271 DOCHOSTUIINFO hostinfo
;
273 memset(&hostinfo
, 0, sizeof(DOCHOSTUIINFO
));
274 hostinfo
.cbSize
= sizeof(DOCHOSTUIINFO
);
275 hres
= IDocHostUIHandler_GetHostInfo(doc
->hostui
, &hostinfo
);
277 /* FIXME: use hostinfo */
278 TRACE("hostinfo = {%u %08x %08x %s %s}\n",
279 hostinfo
.cbSize
, hostinfo
.dwFlags
, hostinfo
.dwDoubleClick
,
280 debugstr_w(hostinfo
.pchHostCss
), debugstr_w(hostinfo
.pchHostNS
));
284 static void task_start_binding(HTMLDocument
*doc
, BSCallback
*bscallback
)
287 start_binding(doc
, bscallback
, NULL
);
288 IUnknown_Release((IUnknown
*)bscallback
);
291 static void process_task(task_t
*task
)
293 switch(task
->task_id
) {
294 case TASK_SETDOWNLOADSTATE
:
295 set_downloading(task
->doc
);
297 case TASK_PARSECOMPLETE
:
298 set_parsecomplete(task
->doc
);
300 case TASK_SETPROGRESS
:
301 set_progress(task
->doc
);
303 case TASK_START_BINDING
:
304 task_start_binding(task
->doc
, (BSCallback
*)task
->bscallback
);
307 ERR("Wrong task_id %d\n", task
->task_id
);
311 static LRESULT
process_timer(void)
313 thread_data_t
*thread_data
= get_thread_data(TRUE
);
314 DWORD tc
= GetTickCount();
317 while(!list_empty(&thread_data
->timer_list
)) {
318 timer
= LIST_ENTRY(list_head(&thread_data
->timer_list
), task_timer_t
, entry
);
319 if(timer
->time
> tc
) {
320 SetTimer(thread_data
->thread_hwnd
, TIMER_ID
, timer
->time
-tc
, NULL
);
324 list_remove(&timer
->entry
);
325 call_disp_func(timer
->doc
, timer
->disp
);
326 release_task_timer(thread_data
->thread_hwnd
, timer
);
329 KillTimer(thread_data
->thread_hwnd
, TIMER_ID
);
333 static LRESULT WINAPI
hidden_proc(HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
338 task_t
*task
= pop_task();
348 return process_timer();
352 FIXME("(%p %d %lx %lx)\n", hwnd
, msg
, wParam
, lParam
);
354 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
357 static HWND
create_thread_hwnd(void)
359 static ATOM hidden_wnd_class
= 0;
360 static const WCHAR wszInternetExplorer_Hidden
[] = {'I','n','t','e','r','n','e','t',
361 ' ','E','x','p','l','o','r','e','r','_','H','i','d','d','e','n',0};
363 if(!hidden_wnd_class
) {
364 WNDCLASSEXW wndclass
= {
365 sizeof(WNDCLASSEXW
), 0,
367 0, 0, hInst
, NULL
, NULL
, NULL
, NULL
,
368 wszInternetExplorer_Hidden
,
372 hidden_wnd_class
= RegisterClassExW(&wndclass
);
375 return CreateWindowExW(0, wszInternetExplorer_Hidden
, NULL
, WS_POPUP
,
376 0, 0, 0, 0, NULL
, NULL
, hInst
, NULL
);
379 HWND
get_thread_hwnd(void)
381 thread_data_t
*thread_data
= get_thread_data(TRUE
);
383 if(!thread_data
->thread_hwnd
)
384 thread_data
->thread_hwnd
= create_thread_hwnd();
386 return thread_data
->thread_hwnd
;
389 thread_data_t
*get_thread_data(BOOL create
)
391 thread_data_t
*thread_data
;
395 mshtml_tls
= TlsAlloc();
400 thread_data
= TlsGetValue(mshtml_tls
);
401 if(!thread_data
&& create
) {
402 thread_data
= heap_alloc_zero(sizeof(thread_data_t
));
403 TlsSetValue(mshtml_tls
, thread_data
);
404 list_init(&thread_data
->timer_list
);