webbrowser.c 28.5 KB
Newer Older
1
/*
2
 * Implementation of IWebBrowser interface for WebBrowser control
3 4
 *
 * Copyright 2001 John R. Sheets (for CodeWeavers)
5
 * Copyright 2005 Jacek Caban
6 7 8 9 10 11 12 13 14 15 16 17 18
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 21 22 23
 */

#include "wine/debug.h"
#include "shdocvw.h"
24
#include "exdispid.h"
25 26 27 28 29 30 31

WINE_DEFAULT_DEBUG_CHANNEL(shdocvw);

/**********************************************************************
 * Implement the IWebBrowser interface
 */

32
#define WEBBROWSER_THIS(iface) DEFINE_THIS(WebBrowser, WebBrowser2, iface)
33

34
static HRESULT WINAPI WebBrowser_QueryInterface(IWebBrowser2 *iface, REFIID riid, LPVOID *ppv)
35 36 37 38 39 40 41 42 43 44
{
    WebBrowser *This = WEBBROWSER_THIS(iface);

    if (ppv == NULL)
        return E_POINTER;
    *ppv = NULL;

    if(IsEqualGUID(&IID_IUnknown, riid)) {
        TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
        *ppv = WEBBROWSER(This);
45
    }else if(IsEqualGUID(&IID_IDispatch, riid)) {
46
        TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
47 48 49 50
        *ppv = WEBBROWSER(This);
    }else if(IsEqualGUID(&IID_IWebBrowser, riid)) {
        TRACE("(%p)->(IID_IWebBrowser %p)\n", This, ppv);
        *ppv = WEBBROWSER(This);
51 52 53 54 55 56
    }else if(IsEqualGUID(&IID_IWebBrowserApp, riid)) {
        TRACE("(%p)->(IID_IWebBrowserApp %p)\n", This, ppv);
        *ppv = WEBBROWSER(This);
    }else if(IsEqualGUID(&IID_IWebBrowser2, riid)) {
        TRACE("(%p)->(IID_IWebBrowser2 %p)\n", This, ppv);
        *ppv = WEBBROWSER(This);
57
    }else if(IsEqualGUID(&IID_IOleObject, riid)) {
58
        TRACE("(%p)->(IID_IOleObject %p)\n", This, ppv);
59
        *ppv = OLEOBJ(This);
60 61 62 63 64 65
    }else if(IsEqualGUID(&IID_IOleWindow, riid)) {
        TRACE("(%p)->(IID_IOleWindow %p)\n", This, ppv);
        *ppv = INPLACEOBJ(This);
    }else if(IsEqualGUID (&IID_IOleInPlaceObject, riid)) {
        TRACE("(%p)->(IID_IOleInPlaceObject %p)\n", This, ppv);
        *ppv = INPLACEOBJ(This);
66 67
    }else if(IsEqualGUID(&IID_IOleControl, riid)) {
        TRACE("(%p)->(IID_IOleControl %p)\n", This, ppv);
68
        *ppv = CONTROL(This);
69 70 71 72 73 74
    }else if(IsEqualGUID(&IID_IPersist, riid)) {
        TRACE("(%p)->(IID_IPersist %p)\n", This, ppv);
        *ppv = PERSTORAGE(This);
    }else if(IsEqualGUID(&IID_IPersistStorage, riid)) {
        TRACE("(%p)->(IID_IPersistStorage %p)\n", This, ppv);
        *ppv = PERSTORAGE(This);
75
    }else if(IsEqualGUID (&IID_IPersistStreamInit, riid)) {
76 77
        TRACE("(%p)->(IID_IPersistStreamInit %p)\n", This, ppv);
        *ppv = PERSTRINIT(This);
78
    }else if(IsEqualGUID(&IID_IProvideClassInfo, riid)) {
79 80
        TRACE("(%p)->(IID_IProvideClassInfo %p)\n", This, ppv);
        *ppv = CLASSINFO(This);
81
    }else if(IsEqualGUID(&IID_IProvideClassInfo2, riid)) {
82 83
        TRACE("(%p)->(IID_IProvideClassInfo2 %p)\n", This, ppv);
        *ppv = CLASSINFO(This);
84
    }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
85
        TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppv);
86
        *ppv = CONPTCONT(&This->doc_host.cps);
87 88 89 90 91 92
    }else if(IsEqualGUID(&IID_IViewObject, riid)) {
        TRACE("(%p)->(IID_IViewObject %p)\n", This, ppv);
        *ppv = VIEWOBJ(This);
    }else if(IsEqualGUID(&IID_IViewObject2, riid)) {
        TRACE("(%p)->(IID_IViewObject2 %p)\n", This, ppv);
        *ppv = VIEWOBJ2(This);
93 94 95
    }else if(IsEqualGUID(&IID_IOleInPlaceActiveObject, riid)) {
        TRACE("(%p)->(IID_IOleInPlaceActiveObject %p)\n", This, ppv);
        *ppv = ACTIVEOBJ(This);
96 97
    }else if(IsEqualGUID(&IID_IOleCommandTarget, riid)) {
        TRACE("(%p)->(IID_IOleCommandTarget %p)\n", This, ppv);
Jacek Caban's avatar
Jacek Caban committed
98
        *ppv = OLECMD(This);
99 100 101
    }else if(IsEqualGUID(&IID_IHlinkFrame, riid)) {
        TRACE("(%p)->(IID_IHlinkFrame %p)\n", This, ppv);
        *ppv = HLINKFRAME(This);
102 103 104 105 106 107
    }else if(IsEqualGUID(&IID_IQuickActivate, riid)) {
        TRACE("(%p)->(IID_IQuickActivate %p) returning NULL\n", This, ppv);
        return E_NOINTERFACE;
    }else if(IsEqualGUID(&IID_IRunnableObject, riid)) {
        TRACE("(%p)->(IID_IRunnableObject %p) returning NULL\n", This, ppv);
        return E_NOINTERFACE;
108 109 110 111 112 113 114 115
    }

    if(*ppv) {
        IUnknown_AddRef((IUnknown*)*ppv);
        return S_OK;
    }

    FIXME("(%p)->(%s %p) interface not supported\n", This, debugstr_guid(riid), ppv);
116 117 118
    return E_NOINTERFACE;
}

119
static ULONG WINAPI WebBrowser_AddRef(IWebBrowser2 *iface)
120
{
121 122 123 124
    WebBrowser *This = WEBBROWSER_THIS(iface);
    LONG ref = InterlockedIncrement(&This->ref);
    TRACE("(%p) ref=%ld\n", This, ref);
    return ref;
125 126
}

127
static ULONG WINAPI WebBrowser_Release(IWebBrowser2 *iface)
128
{
129 130 131 132
    WebBrowser *This = WEBBROWSER_THIS(iface);
    LONG ref = InterlockedDecrement(&This->ref);

    TRACE("(%p) ref=%ld\n", This, ref);
133

134
    if(!ref) {
135 136
        if(This->doc_host.document)
            IUnknown_Release(This->doc_host.document);
137

138 139
        DocHost_Release(&This->doc_host);

140 141
        WebBrowser_OleObject_Destroy(This);

142
        shdocvw_free(This);
143 144 145 146
        SHDOCVW_UnlockModule();
    }

    return ref;
147 148 149
}

/* IDispatch methods */
150
static HRESULT WINAPI WebBrowser_GetTypeInfoCount(IWebBrowser2 *iface, UINT *pctinfo)
151
{
152 153 154
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%p)\n", This, pctinfo);
    return E_NOTIMPL;
155 156
}

157
static HRESULT WINAPI WebBrowser_GetTypeInfo(IWebBrowser2 *iface, UINT iTInfo, LCID lcid,
158 159
                                     LPTYPEINFO *ppTInfo)
{
160 161 162
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%d %ld %p)\n", This, iTInfo, lcid, ppTInfo);
    return E_NOTIMPL;
163 164
}

165
static HRESULT WINAPI WebBrowser_GetIDsOfNames(IWebBrowser2 *iface, REFIID riid,
166 167 168
                                       LPOLESTR *rgszNames, UINT cNames,
                                       LCID lcid, DISPID *rgDispId)
{
169 170 171 172
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%s %p %d %ld %p)\n", This, debugstr_guid(riid), rgszNames, cNames,
            lcid, rgDispId);
    return E_NOTIMPL;
173 174
}

175
static HRESULT WINAPI WebBrowser_Invoke(IWebBrowser2 *iface, DISPID dispIdMember,
176 177 178 179
                                REFIID riid, LCID lcid, WORD wFlags,
                                DISPPARAMS *pDispParams, VARIANT *pVarResult,
                                EXCEPINFO *pExepInfo, UINT *puArgErr)
{
180
    WebBrowser *This = WEBBROWSER_THIS(iface);
181 182 183 184
    ITypeInfo *typeinfo;
    HRESULT hres;

    TRACE("(%p)->(%ld %s %ld %08x %p %p %p %p)\n", This, dispIdMember, debugstr_guid(riid),
185
            lcid, wFlags, pDispParams, pVarResult, pExepInfo, puArgErr);
186 187 188 189 190 191 192

    hres = get_typeinfo(&typeinfo);
    if(FAILED(hres))
        return hres;

    return ITypeInfo_Invoke(typeinfo, WEBBROWSER2(This), dispIdMember, wFlags, pDispParams,
                            pVarResult, pExepInfo, puArgErr);
193 194 195
}

/* IWebBrowser methods */
196
static HRESULT WINAPI WebBrowser_GoBack(IWebBrowser2 *iface)
197
{
198 199 200
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)\n", This);
    return E_NOTIMPL;
201 202
}

203
static HRESULT WINAPI WebBrowser_GoForward(IWebBrowser2 *iface)
204
{
205 206 207
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)\n", This);
    return E_NOTIMPL;
208 209
}

210
static HRESULT WINAPI WebBrowser_GoHome(IWebBrowser2 *iface)
211
{
212 213 214
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)\n", This);
    return E_NOTIMPL;
215 216
}

217
static HRESULT WINAPI WebBrowser_GoSearch(IWebBrowser2 *iface)
218
{
219 220 221
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)\n", This);
    return E_NOTIMPL;
222 223
}

224
static HRESULT WINAPI WebBrowser_Navigate(IWebBrowser2 *iface, BSTR szUrl,
225 226 227
                                  VARIANT *Flags, VARIANT *TargetFrameName,
                                  VARIANT *PostData, VARIANT *Headers)
{
228
    WebBrowser *This = WEBBROWSER_THIS(iface);
229 230 231 232
    VARIANT url;
    HRESULT r;

    FIXME("(%p)->(%s %p %p %p %p)\n", This, debugstr_w(szUrl), Flags, TargetFrameName,
233
          PostData, Headers);
234 235 236 237 238 239 240

    V_VT(&url) = VT_BSTR;
    V_BSTR(&url) = szUrl;
    r = IWebBrowser2_Navigate2(iface, &url, Flags,
                               TargetFrameName, PostData, Headers);

    return r;
241 242
}

243
static HRESULT WINAPI WebBrowser_Refresh(IWebBrowser2 *iface)
244
{
245 246 247
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)\n", This);
    return E_NOTIMPL;
248 249
}

250
static HRESULT WINAPI WebBrowser_Refresh2(IWebBrowser2 *iface, VARIANT *Level)
251
{
252 253 254
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%p)\n", This, Level);
    return E_NOTIMPL;
255 256
}

257
static HRESULT WINAPI WebBrowser_Stop(IWebBrowser2 *iface)
258
{
259 260 261
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)\n", This);
    return E_NOTIMPL;
262 263
}

264
static HRESULT WINAPI WebBrowser_get_Application(IWebBrowser2 *iface, IDispatch **ppDisp)
265
{
266 267 268
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%p)\n", This, ppDisp);
    return E_NOTIMPL;
269 270
}

271
static HRESULT WINAPI WebBrowser_get_Parent(IWebBrowser2 *iface, IDispatch **ppDisp)
272
{
273 274 275
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%p)\n", This, ppDisp);
    return E_NOTIMPL;
276 277
}

278
static HRESULT WINAPI WebBrowser_get_Container(IWebBrowser2 *iface, IDispatch **ppDisp)
279
{
280 281 282
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%p)\n", This, ppDisp);
    return E_NOTIMPL;
283 284
}

285
static HRESULT WINAPI WebBrowser_get_Document(IWebBrowser2 *iface, IDispatch **ppDisp)
286
{
287
    WebBrowser *This = WEBBROWSER_THIS(iface);
288 289 290 291

    TRACE("(%p)->(%p)\n", This, ppDisp);

    *ppDisp = NULL;
292 293
    if(This->doc_host.document)
        IUnknown_QueryInterface(This->doc_host.document, &IID_IDispatch, (void**)ppDisp);
294 295

    return S_OK;
296 297
}

298
static HRESULT WINAPI WebBrowser_get_TopLevelContainer(IWebBrowser2 *iface, VARIANT_BOOL *pBool)
299
{
300 301 302
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%p)\n", This, pBool);
    return E_NOTIMPL;
303 304
}

305
static HRESULT WINAPI WebBrowser_get_Type(IWebBrowser2 *iface, BSTR *Type)
306
{
307 308 309
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%p)\n", This, Type);
    return E_NOTIMPL;
310 311
}

312
static HRESULT WINAPI WebBrowser_get_Left(IWebBrowser2 *iface, long *pl)
313
{
314
    WebBrowser *This = WEBBROWSER_THIS(iface);
315 316 317 318 319

    TRACE("(%p)->(%p)\n", This, pl);

    *pl = This->pos_rect.left;
    return S_OK;
320 321
}

322
static HRESULT WINAPI WebBrowser_put_Left(IWebBrowser2 *iface, long Left)
323
{
324
    WebBrowser *This = WEBBROWSER_THIS(iface);
325 326 327 328 329 330 331 332 333 334
    RECT rect;

    TRACE("(%p)->(%ld)\n", This, Left);

    if(!This->inplace)
        return E_UNEXPECTED;

    memcpy(&rect, &This->pos_rect, sizeof(RECT));
    rect.left = Left;

335 336
    /* We don't really change the window position here.
     * We just notify the embedder that he should do so. */
337
    return IOleInPlaceSite_OnPosRectChange(This->inplace, &rect);
338 339
}

340
static HRESULT WINAPI WebBrowser_get_Top(IWebBrowser2 *iface, long *pl)
341
{
342
    WebBrowser *This = WEBBROWSER_THIS(iface);
343 344 345 346 347

    TRACE("(%p)->(%p)\n", This, pl);

    *pl = This->pos_rect.top;
    return S_OK;
348 349
}

350
static HRESULT WINAPI WebBrowser_put_Top(IWebBrowser2 *iface, long Top)
351
{
352
    WebBrowser *This = WEBBROWSER_THIS(iface);
353 354 355 356 357 358 359 360 361 362
    RECT rect;

    TRACE("(%p)->(%ld)\n", This, Top);

    if(!This->inplace)
        return E_UNEXPECTED;

    memcpy(&rect, &This->pos_rect, sizeof(RECT));
    rect.top = Top;

363 364
    /* We don't really change the window position here.
     * We just notify the embedder that he should do so. */
365
    return IOleInPlaceSite_OnPosRectChange(This->inplace, &rect);
366 367
}

368
static HRESULT WINAPI WebBrowser_get_Width(IWebBrowser2 *iface, long *pl)
369
{
370
    WebBrowser *This = WEBBROWSER_THIS(iface);
371 372 373 374 375

    TRACE("(%p)->(%p)\n", This, pl);

    *pl = This->pos_rect.right - This->pos_rect.left;
    return S_OK;
376 377
}

378
static HRESULT WINAPI WebBrowser_put_Width(IWebBrowser2 *iface, long Width)
379
{
380
    WebBrowser *This = WEBBROWSER_THIS(iface);
381 382 383 384 385 386 387 388 389
    RECT rect;

    TRACE("(%p)->(%ld)\n", This, Width);

    if(!This->inplace)
        return E_UNEXPECTED;

    memcpy(&rect, &This->pos_rect, sizeof(RECT));
    rect.right = rect.left+Width;
390 391 392 393
 
    /* We don't really change the window size here.
     * We just notify the embedder that he should do so. */
   return IOleInPlaceSite_OnPosRectChange(This->inplace, &rect);
394 395
}

396
static HRESULT WINAPI WebBrowser_get_Height(IWebBrowser2 *iface, long *pl)
397
{
398
    WebBrowser *This = WEBBROWSER_THIS(iface);
399 400 401 402 403

    TRACE("(%p)->(%p)\n", This, pl);

    *pl = This->pos_rect.bottom - This->pos_rect.top;
    return S_OK;
404 405
}

406
static HRESULT WINAPI WebBrowser_put_Height(IWebBrowser2 *iface, long Height)
407
{
408
    WebBrowser *This = WEBBROWSER_THIS(iface);
409 410 411 412 413 414 415 416 417 418
    RECT rect;

    TRACE("(%p)->(%ld)\n", This, Height);

    if(!This->inplace)
        return E_UNEXPECTED;

    memcpy(&rect, &This->pos_rect, sizeof(RECT));
    rect.bottom = rect.top+Height;

419 420
    /* We don't really change the window size here.
     * We just notify the embedder that he should do so. */
421
    return IOleInPlaceSite_OnPosRectChange(This->inplace, &rect);
422 423
}

424
static HRESULT WINAPI WebBrowser_get_LocationName(IWebBrowser2 *iface, BSTR *LocationName)
425
{
426 427 428
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%p)\n", This, LocationName);
    return E_NOTIMPL;
429 430
}

431
static HRESULT WINAPI WebBrowser_get_LocationURL(IWebBrowser2 *iface, BSTR *LocationURL)
432
{
433
    WebBrowser *This = WEBBROWSER_THIS(iface);
434

435
    FIXME("(%p)->(%p)\n", This, LocationURL);
436

437
    if(!This->doc_host.url) {
438 439 440 441 442
        static const WCHAR null_char = 0;
        *LocationURL = SysAllocString(&null_char);
        return S_FALSE;
    }

443
    *LocationURL = SysAllocString(This->doc_host.url);
444
    return S_OK;
445 446
}

447
static HRESULT WINAPI WebBrowser_get_Busy(IWebBrowser2 *iface, VARIANT_BOOL *pBool)
448
{
449 450 451
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%p)\n", This, pBool);
    return E_NOTIMPL;
452 453
}

454 455 456 457 458 459
static HRESULT WINAPI WebBrowser_Quit(IWebBrowser2 *iface)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)\n", This);
    return E_NOTIMPL;
}
460

461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491
static HRESULT WINAPI WebBrowser_ClientToWindow(IWebBrowser2 *iface, int *pcx, int *pcy)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%p %p)\n", This, pcx, pcy);
    return E_NOTIMPL;
}

static HRESULT WINAPI WebBrowser_PutProperty(IWebBrowser2 *iface, BSTR szProperty, VARIANT vtValue)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_w(szProperty));
    return E_NOTIMPL;
}

static HRESULT WINAPI WebBrowser_GetProperty(IWebBrowser2 *iface, BSTR szProperty, VARIANT *pvtValue)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%s %p)\n", This, debugstr_w(szProperty), pvtValue);
    return E_NOTIMPL;
}

static HRESULT WINAPI WebBrowser_get_Name(IWebBrowser2 *iface, BSTR *Name)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%p)\n", This, Name);
    return E_NOTIMPL;
}

static HRESULT WINAPI WebBrowser_get_HWND(IWebBrowser2 *iface, long *pHWND)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
492 493 494

    TRACE("(%p)->(%p)\n", This, pHWND);

495
    /* WebBrowser control never has a frame window (in opposition to InternetExplorer) */
496 497
    *pHWND = 0;
    return E_FAIL;
498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
}

static HRESULT WINAPI WebBrowser_get_FullName(IWebBrowser2 *iface, BSTR *FullName)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%p)\n", This, FullName);
    return E_NOTIMPL;
}

static HRESULT WINAPI WebBrowser_get_Path(IWebBrowser2 *iface, BSTR *Path)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%p)\n", This, Path);
    return E_NOTIMPL;
}

static HRESULT WINAPI WebBrowser_get_Visible(IWebBrowser2 *iface, VARIANT_BOOL *pBool)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
517 518 519 520 521

    TRACE("(%p)->(%p)\n", This, pBool);

    *pBool = This->visible;
    return S_OK;
522 523 524 525 526
}

static HRESULT WINAPI WebBrowser_put_Visible(IWebBrowser2 *iface, VARIANT_BOOL Value)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
527 528 529 530 531 532 533 534 535
    VARIANTARG arg;
    DISPPARAMS dispparams = {&arg, NULL, 1, 0};

    TRACE("(%p)->(%x)\n", This, Value);

    This->visible = Value;

    V_VT(&arg) = VT_BOOL;
    V_BOOL(&arg) = Value;
536
    call_sink(This->doc_host.cps.wbe2, DISPID_ONVISIBLE, &dispparams);
537 538

    return S_OK;
539 540 541 542 543
}

static HRESULT WINAPI WebBrowser_get_StatusBar(IWebBrowser2 *iface, VARIANT_BOOL *pBool)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
544 545 546 547 548

    TRACE("(%p)->(%p)\n", This, pBool);

    *pBool = This->status_bar;
    return S_OK;
549 550 551 552 553
}

static HRESULT WINAPI WebBrowser_put_StatusBar(IWebBrowser2 *iface, VARIANT_BOOL Value)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
554 555 556 557 558
    VARIANTARG arg;
    DISPPARAMS dispparams = {&arg, NULL, 1, 0};

    TRACE("(%p)->(%x)\n", This, Value);

559
    This->status_bar = Value ? VARIANT_TRUE : VARIANT_FALSE;
560

561 562 563
    /* In opposition to InternetExplorer, all we should do here is
     * inform the embedder about the status bar change. */

564 565
    V_VT(&arg) = VT_BOOL;
    V_BOOL(&arg) = Value;
566
    call_sink(This->doc_host.cps.wbe2, DISPID_ONSTATUSBAR, &dispparams);
567 568

    return S_OK;
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587
}

static HRESULT WINAPI WebBrowser_get_StatusText(IWebBrowser2 *iface, BSTR *StatusText)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%p)\n", This, StatusText);
    return E_NOTIMPL;
}

static HRESULT WINAPI WebBrowser_put_StatusText(IWebBrowser2 *iface, BSTR StatusText)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%s)\n", This, debugstr_w(StatusText));
    return E_NOTIMPL;
}

static HRESULT WINAPI WebBrowser_get_ToolBar(IWebBrowser2 *iface, int *Value)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
588 589 590 591 592

    TRACE("(%p)->(%p)\n", This, Value);

    *Value = This->tool_bar;
    return S_OK;
593 594 595 596 597
}

static HRESULT WINAPI WebBrowser_put_ToolBar(IWebBrowser2 *iface, int Value)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
598 599 600 601 602 603 604
    VARIANTARG arg;
    DISPPARAMS dispparams = {&arg, NULL, 1, 0};

    TRACE("(%p)->(%x)\n", This, Value);

    This->tool_bar = Value ? VARIANT_TRUE : VARIANT_FALSE;

605 606 607
    /* In opposition to InternetExplorer, all we should do here is
     * inform the embedder about the tool bar change. */

608 609
    V_VT(&arg) = VT_BOOL;
    V_BOOL(&arg) = Value;
610
    call_sink(This->doc_host.cps.wbe2, DISPID_ONTOOLBAR, &dispparams);
611 612

    return S_OK;
613 614 615 616 617
}

static HRESULT WINAPI WebBrowser_get_MenuBar(IWebBrowser2 *iface, VARIANT_BOOL *Value)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
618 619 620 621 622

    TRACE("(%p)->(%p)\n", This, Value);

    *Value = This->menu_bar;
    return S_OK;
623 624 625 626 627
}

static HRESULT WINAPI WebBrowser_put_MenuBar(IWebBrowser2 *iface, VARIANT_BOOL Value)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
628 629 630 631 632
    VARIANTARG arg;
    DISPPARAMS dispparams = {&arg, NULL, 1, 0};

    TRACE("(%p)->(%x)\n", This, Value);

633
    This->menu_bar = Value ? VARIANT_TRUE : VARIANT_FALSE;
634

635 636 637
    /* In opposition to InternetExplorer, all we should do here is
     * inform the embedder about the menu bar change. */

638 639
    V_VT(&arg) = VT_BOOL;
    V_BOOL(&arg) = Value;
640
    call_sink(This->doc_host.cps.wbe2, DISPID_ONMENUBAR, &dispparams);
641 642

    return S_OK;
643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662
}

static HRESULT WINAPI WebBrowser_get_FullScreen(IWebBrowser2 *iface, VARIANT_BOOL *pbFullScreen)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%p)\n", This, pbFullScreen);
    return E_NOTIMPL;
}

static HRESULT WINAPI WebBrowser_put_FullScreen(IWebBrowser2 *iface, VARIANT_BOOL bFullScreen)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%x)\n", This, bFullScreen);
    return E_NOTIMPL;
}

static HRESULT WINAPI WebBrowser_Navigate2(IWebBrowser2 *iface, VARIANT *URL, VARIANT *Flags,
        VARIANT *TargetFrameName, VARIANT *PostData, VARIANT *Headers)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
663 664 665
    PBYTE post_data = NULL;
    ULONG post_data_len = 0;
    LPWSTR headers = NULL;
666 667 668 669 670 671 672
    HRESULT hres;

    TRACE("(%p)->(%p %p %p %p %p)\n", This, URL, Flags, TargetFrameName, PostData, Headers);

    if(!This->client)
        return E_FAIL;

673
    if((Flags && V_VT(Flags) != VT_EMPTY) 
674
       || (TargetFrameName && V_VT(TargetFrameName) != VT_EMPTY))
675 676
        FIXME("Unsupported arguments\n");

677

678 679
    if(!URL)
        return S_OK;
680

681
    if(V_VT(URL) != VT_BSTR)
682
        return E_INVALIDARG;
683

684
    if(PostData && V_VT(PostData) != VT_EMPTY && V_VT(PostData) != VT_ERROR) {
685 686 687 688 689
        if(V_VT(PostData) != (VT_ARRAY | VT_UI1)
           || V_ARRAY(PostData)->cDims != 1) {
            WARN("Invalid PostData\n");
            return E_INVALIDARG;
        }
Jacek Caban's avatar
Jacek Caban committed
690

691 692
        SafeArrayAccessData(V_ARRAY(PostData), (void**)&post_data);
        post_data_len = V_ARRAY(PostData)->rgsabound[0].cElements;
693 694
    }

695
    if(Headers && V_VT(Headers) != VT_EMPTY && V_VT(Headers) != VT_ERROR) {
696 697
        if(V_VT(Headers) != VT_BSTR)
            return E_INVALIDARG;
698

699
        headers = V_BSTR(Headers);
700
        TRACE("Headers: %s\n", debugstr_w(headers));
701 702
    }

703
    hres = navigate_url(&This->doc_host, V_BSTR(URL), post_data, post_data_len, headers);
704

705 706
    if(post_data)
        SafeArrayUnaccessData(V_ARRAY(PostData));
Jacek Caban's avatar
Jacek Caban committed
707

708
    return hres;
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757
}

static HRESULT WINAPI WebBrowser_QueryStatusWB(IWebBrowser2 *iface, OLECMDID cmdID, OLECMDF *pcmdf)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%d %p)\n", This, cmdID, pcmdf);
    return E_NOTIMPL;
}

static HRESULT WINAPI WebBrowser_ExecWB(IWebBrowser2 *iface, OLECMDID cmdID,
        OLECMDEXECOPT cmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%d %d %p %p)\n", This, cmdID, cmdexecopt, pvaIn, pvaOut);
    return E_NOTIMPL;
}

static HRESULT WINAPI WebBrowser_ShowBrowserBar(IWebBrowser2 *iface, VARIANT *pvaClsid,
        VARIANT *pvarShow, VARIANT *pvarSize)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%p %p %p)\n", This, pvaClsid, pvarShow, pvarSize);
    return E_NOTIMPL;
}

static HRESULT WINAPI WebBrowser_get_ReadyState(IWebBrowser2 *iface, READYSTATE *lpReadyState)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%p)\n", This, lpReadyState);
    return E_NOTIMPL;
}

static HRESULT WINAPI WebBrowser_get_Offline(IWebBrowser2 *iface, VARIANT_BOOL *pbOffline)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%p)\n", This, pbOffline);
    return E_NOTIMPL;
}

static HRESULT WINAPI WebBrowser_put_Offline(IWebBrowser2 *iface, VARIANT_BOOL bOffline)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%x)\n", This, bOffline);
    return E_NOTIMPL;
}

static HRESULT WINAPI WebBrowser_get_Silent(IWebBrowser2 *iface, VARIANT_BOOL *pbSilent)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
758 759 760 761 762

    TRACE("(%p)->(%p)\n", This, pbSilent);

    *pbSilent = This->silent;
    return S_OK;
763 764 765 766 767
}

static HRESULT WINAPI WebBrowser_put_Silent(IWebBrowser2 *iface, VARIANT_BOOL bSilent)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
768 769 770 771 772

    TRACE("(%p)->(%x)\n", This, bSilent);

    This->silent = bSilent ? VARIANT_TRUE : VARIANT_FALSE;
    return S_OK;
773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803
}

static HRESULT WINAPI WebBrowser_get_RegisterAsBrowser(IWebBrowser2 *iface,
        VARIANT_BOOL *pbRegister)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%p)\n", This, pbRegister);
    return E_NOTIMPL;
}

static HRESULT WINAPI WebBrowser_put_RegisterAsBrowser(IWebBrowser2 *iface,
        VARIANT_BOOL bRegister)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%x)\n", This, bRegister);
    return E_NOTIMPL;
}

static HRESULT WINAPI WebBrowser_get_RegisterAsDropTarget(IWebBrowser2 *iface,
        VARIANT_BOOL *pbRegister)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%p)\n", This, pbRegister);
    return E_NOTIMPL;
}

static HRESULT WINAPI WebBrowser_put_RegisterAsDropTarget(IWebBrowser2 *iface,
        VARIANT_BOOL bRegister)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%x)\n", This, bRegister);
804
    return S_OK;
805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823
}

static HRESULT WINAPI WebBrowser_get_TheaterMode(IWebBrowser2 *iface, VARIANT_BOOL *pbRegister)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%p)\n", This, pbRegister);
    return E_NOTIMPL;
}

static HRESULT WINAPI WebBrowser_put_TheaterMode(IWebBrowser2 *iface, VARIANT_BOOL bRegister)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%x)\n", This, bRegister);
    return E_NOTIMPL;
}

static HRESULT WINAPI WebBrowser_get_AddressBar(IWebBrowser2 *iface, VARIANT_BOOL *Value)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
824 825 826 827 828

    TRACE("(%p)->(%p)\n", This, Value);

    *Value = This->address_bar;
    return S_OK;
829 830 831 832 833
}

static HRESULT WINAPI WebBrowser_put_AddressBar(IWebBrowser2 *iface, VARIANT_BOOL Value)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
834 835 836 837 838
    VARIANTARG arg;
    DISPPARAMS dispparams = {&arg, NULL, 1, 0};

    TRACE("(%p)->(%x)\n", This, Value);

839
    This->address_bar = Value ? VARIANT_TRUE : VARIANT_FALSE;
840

841 842 843
    /* In opposition to InternetExplorer, all we should do here is
     * inform the embedder about the address bar change. */

844 845
    V_VT(&arg) = VT_BOOL;
    V_BOOL(&arg) = Value;
846
    call_sink(This->doc_host.cps.wbe2, DISPID_ONADDRESSBAR, &dispparams);
847 848

    return S_OK;
849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865
}

static HRESULT WINAPI WebBrowser_get_Resizable(IWebBrowser2 *iface, VARIANT_BOOL *Value)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%p)\n", This, Value);
    return E_NOTIMPL;
}

static HRESULT WINAPI WebBrowser_put_Resizable(IWebBrowser2 *iface, VARIANT_BOOL Value)
{
    WebBrowser *This = WEBBROWSER_THIS(iface);
    FIXME("(%p)->(%x)\n", This, Value);
    return E_NOTIMPL;
}

#undef WEBBROWSER_THIS
866

867
static const IWebBrowser2Vtbl WebBrowser2Vtbl =
868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899
{
    WebBrowser_QueryInterface,
    WebBrowser_AddRef,
    WebBrowser_Release,
    WebBrowser_GetTypeInfoCount,
    WebBrowser_GetTypeInfo,
    WebBrowser_GetIDsOfNames,
    WebBrowser_Invoke,
    WebBrowser_GoBack,
    WebBrowser_GoForward,
    WebBrowser_GoHome,
    WebBrowser_GoSearch,
    WebBrowser_Navigate,
    WebBrowser_Refresh,
    WebBrowser_Refresh2,
    WebBrowser_Stop,
    WebBrowser_get_Application,
    WebBrowser_get_Parent,
    WebBrowser_get_Container,
    WebBrowser_get_Document,
    WebBrowser_get_TopLevelContainer,
    WebBrowser_get_Type,
    WebBrowser_get_Left,
    WebBrowser_put_Left,
    WebBrowser_get_Top,
    WebBrowser_put_Top,
    WebBrowser_get_Width,
    WebBrowser_put_Width,
    WebBrowser_get_Height,
    WebBrowser_put_Height,
    WebBrowser_get_LocationName,
    WebBrowser_get_LocationURL,
900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939
    WebBrowser_get_Busy,
    WebBrowser_Quit,
    WebBrowser_ClientToWindow,
    WebBrowser_PutProperty,
    WebBrowser_GetProperty,
    WebBrowser_get_Name,
    WebBrowser_get_HWND,
    WebBrowser_get_FullName,
    WebBrowser_get_Path,
    WebBrowser_get_Visible,
    WebBrowser_put_Visible,
    WebBrowser_get_StatusBar,
    WebBrowser_put_StatusBar,
    WebBrowser_get_StatusText,
    WebBrowser_put_StatusText,
    WebBrowser_get_ToolBar,
    WebBrowser_put_ToolBar,
    WebBrowser_get_MenuBar,
    WebBrowser_put_MenuBar,
    WebBrowser_get_FullScreen,
    WebBrowser_put_FullScreen,
    WebBrowser_Navigate2,
    WebBrowser_QueryStatusWB,
    WebBrowser_ExecWB,
    WebBrowser_ShowBrowserBar,
    WebBrowser_get_ReadyState,
    WebBrowser_get_Offline,
    WebBrowser_put_Offline,
    WebBrowser_get_Silent,
    WebBrowser_put_Silent,
    WebBrowser_get_RegisterAsBrowser,
    WebBrowser_put_RegisterAsBrowser,
    WebBrowser_get_RegisterAsDropTarget,
    WebBrowser_put_RegisterAsDropTarget,
    WebBrowser_get_TheaterMode,
    WebBrowser_put_TheaterMode,
    WebBrowser_get_AddressBar,
    WebBrowser_put_AddressBar,
    WebBrowser_get_Resizable,
    WebBrowser_put_Resizable
940 941
};

942
static HRESULT WebBrowser_Create(INT version, IUnknown *pOuter, REFIID riid, void **ppv)
943 944 945 946
{
    WebBrowser *ret;
    HRESULT hres;

947
    TRACE("(%p %s %p) version=%d\n", pOuter, debugstr_guid(riid), ppv, version);
948

949
    ret = shdocvw_alloc(sizeof(WebBrowser));
950

951
    ret->lpWebBrowser2Vtbl = &WebBrowser2Vtbl;
952
    ret->ref = 0;
953
    ret->version = version;
954

955
    DocHost_Init(&ret->doc_host, (IDispatch*)WEBBROWSER2(ret));
956

957
    ret->visible = VARIANT_TRUE;
958
    ret->menu_bar = VARIANT_TRUE;
959
    ret->address_bar = VARIANT_TRUE;
960
    ret->status_bar = VARIANT_TRUE;
961
    ret->tool_bar = VARIANT_TRUE;
962
    ret->silent = VARIANT_FALSE;
963

964
    WebBrowser_OleObject_Init(ret);
965
    WebBrowser_ViewObject_Init(ret);
966
    WebBrowser_Persist_Init(ret);
967
    WebBrowser_ClassInfo_Init(ret);
968
    WebBrowser_HlinkFrame_Init(ret);
969 970 971 972 973

    hres = IWebBrowser_QueryInterface(WEBBROWSER(ret), riid, ppv);
    if(SUCCEEDED(hres)) {
        SHDOCVW_LockModule();
    }else {
974
        shdocvw_free(ret);
975 976 977 978 979
        return hres;
    }

    return hres;
}
980 981 982 983 984 985 986 987 988 989

HRESULT WebBrowserV1_Create(IUnknown *pOuter, REFIID riid, void **ppv)
{
    return WebBrowser_Create(1, pOuter, riid, ppv);
}

HRESULT WebBrowserV2_Create(IUnknown *pOuter, REFIID riid, void **ppv)
{
    return WebBrowser_Create(2, pOuter, riid, ppv);
}