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
/*
 * ReactOS Explorer
 *
 * Copyright 2009 Andrew Hill <ash77 at domain reactos.org>
 *
 * 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
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/*
Used by the address band to dispatch navigation changes to the main browser object.

TODO:

*/

#include "precomp.h"

CBandProxy::CBandProxy()
{
}

CBandProxy::~CBandProxy()
{
}

HRESULT CBandProxy::FindBrowserWindow(IUnknown **browser)
{
    IWebBrowser2* webBrowser;
    HRESULT hResult;

    if (browser == NULL)
        return E_POINTER;
    hResult = IUnknown_QueryService(fSite, SID_IWebBrowserApp, IID_PPV_ARG(IWebBrowser2, &webBrowser));
    if (FAILED_UNEXPECTEDLY(hResult))
        return hResult;
    *browser = webBrowser;
    return S_OK;
}

HRESULT STDMETHODCALLTYPE CBandProxy::SetSite(IUnknown *paramC)
{
    fSite = paramC;
    return S_OK;
}

HRESULT STDMETHODCALLTYPE CBandProxy::CreateNewWindow(long paramC)
{
    return E_NOTIMPL;
}

HRESULT STDMETHODCALLTYPE CBandProxy::GetBrowserWindow(IUnknown **paramC)
{
    if (paramC == NULL)
        return E_POINTER;
    return FindBrowserWindow(paramC);
}

HRESULT STDMETHODCALLTYPE CBandProxy::IsConnected()
{
    CComPtr<IUnknown>                       webBrowser;
    HRESULT                                 hResult;

    hResult = FindBrowserWindow(&webBrowser);
    if (FAILED_UNEXPECTEDLY(hResult) || webBrowser.p == NULL)
        return S_FALSE;
    return S_OK;
}

HRESULT STDMETHODCALLTYPE CBandProxy::NavigateToPIDL(LPCITEMIDLIST pidl)
{
    CComPtr<IOleWindow>                     oleWindow;
    CComPtr<IServiceProvider>               serviceProvider;
    CComPtr<IUnknown>                       webBrowserUnknown;
    CComPtr<IWebBrowser2>                   webBrowser;
    HWND                                    browserWindow;
    CComVariant                             args;
    CComVariant                             emptyVariant;
    unsigned int                            arraySize;
    HRESULT                                 hResult;

    hResult = FindBrowserWindow(&webBrowserUnknown);
    if (FAILED_UNEXPECTEDLY(hResult))
        return hResult;
    hResult = webBrowserUnknown->QueryInterface(IID_PPV_ARG(IWebBrowser2, &webBrowser));
    if (FAILED_UNEXPECTEDLY(hResult))
        return hResult;
    hResult = webBrowser->put_Visible(TRUE);<--- hResult is assigned
    hResult = webBrowser->QueryInterface(IID_PPV_ARG(IServiceProvider, &serviceProvider));<--- hResult is overwritten
    if (SUCCEEDED(hResult))
    {
        hResult = serviceProvider->QueryService(SID_STopLevelBrowser,
            IID_PPV_ARG(IOleWindow, &oleWindow));
        if (SUCCEEDED(hResult))
        {
            hResult = oleWindow->GetWindow(&browserWindow);<--- hResult is assigned
            if (IsIconic(browserWindow))
                ShowWindow(browserWindow, SW_RESTORE);
        }
    }
    arraySize = ILGetSize(pidl);
    V_VT(&args) = VT_ARRAY | VT_UI1;
    V_ARRAY(&args) = SafeArrayCreateVector(VT_UI1, 0, arraySize);
    if (V_ARRAY(&args) == NULL)
        return E_OUTOFMEMORY;
    memcpy(V_ARRAY(&args)->pvData, pidl, arraySize);
    hResult = webBrowser->Navigate2(&args, &emptyVariant, &emptyVariant, &emptyVariant, &emptyVariant);<--- hResult is overwritten
    if (FAILED_UNEXPECTEDLY(hResult))
        return hResult;
    return S_OK;
}

HRESULT STDMETHODCALLTYPE CBandProxy::NavigateToURL(long paramC, long param10)
{
    return E_NOTIMPL;
}