コード例 #1
0
// IWebHistoryDelegate
HRESULT HistoryDelegate::didNavigateWithNavigationData(IWebView* webView, IWebNavigationData* navigationData, IWebFrame* webFrame)
{
    if (!gLayoutTestController->dumpHistoryDelegateCallbacks())
        return S_OK;

    BSTR urlBSTR;
    if (FAILED(navigationData->url(&urlBSTR)))
        return E_FAIL;
    wstring url;
    if (urlBSTR)
        url = urlSuitableForTestResult(wstringFromBSTR(urlBSTR));
    SysFreeString(urlBSTR);

    BSTR titleBSTR;
    if (FAILED(navigationData->title(&titleBSTR)))
        return E_FAIL;
    wstring title;
    if (titleBSTR)
        title = wstringFromBSTR(titleBSTR);
    SysFreeString(titleBSTR);

    COMPtr<IWebURLRequest> request;
    if (FAILED(navigationData->originalRequest(&request)))
        return E_FAIL;

    BSTR httpMethodBSTR;
    if (FAILED(request->HTTPMethod(&httpMethodBSTR)))
        return E_FAIL;
    wstring httpMethod;
    if (httpMethodBSTR)
        httpMethod = wstringFromBSTR(httpMethodBSTR);
    SysFreeString(httpMethodBSTR);

    COMPtr<IWebURLResponse> response;
    if (FAILED(navigationData->response(&response)))
        return E_FAIL;

    COMPtr<IWebHTTPURLResponse> httpResponse;
    if (FAILED(response->QueryInterface(&httpResponse)))
        return E_FAIL;

    int statusCode = 0;
    if (FAILED(httpResponse->statusCode(&statusCode)))
        return E_FAIL;

    BOOL hasSubstituteData;
    if (FAILED(navigationData->hasSubstituteData(&hasSubstituteData)))
        return E_FAIL;

    BSTR clientRedirectSourceBSTR;
    if (FAILED(navigationData->clientRedirectSource(&clientRedirectSourceBSTR)))
        return E_FAIL;
    bool hasClientRedirect = clientRedirectSourceBSTR && SysStringLen(clientRedirectSourceBSTR);
    wstring redirectSource;
    if (clientRedirectSourceBSTR)
        redirectSource = urlSuitableForTestResult(wstringFromBSTR(clientRedirectSourceBSTR));
    SysFreeString(clientRedirectSourceBSTR);

    bool wasFailure = hasSubstituteData || (httpResponse && statusCode >= 400);
        
    printf("WebView navigated to url \"%S\" with title \"%S\" with HTTP equivalent method \"%S\".  The navigation was %s and was %s%S.\n", 
        url.c_str(), 
        title.c_str(), 
        httpMethod.c_str(),
        wasFailure ? "a failure" : "successful", 
        hasClientRedirect ? "a client redirect from " : "not a client redirect", 
        redirectSource.c_str());

    return S_OK;
}
コード例 #2
0
ファイル: HistoryDelegate.cpp プロジェクト: nickooms/webkit
// IWebHistoryDelegate
HRESULT HistoryDelegate::didNavigateWithNavigationData(_In_opt_ IWebView* webView, _In_opt_ IWebNavigationData* navigationData, _In_opt_ IWebFrame* webFrame)
{
    if (!gTestRunner->dumpHistoryDelegateCallbacks())
        return S_OK;

    _bstr_t urlBSTR;
    if (FAILED(navigationData->url(&urlBSTR.GetBSTR())))
        return E_FAIL;
    wstring url;
    if (urlBSTR.length())
        url = urlSuitableForTestResult(wstringFromBSTR(urlBSTR));

    _bstr_t titleBSTR;
    if (FAILED(navigationData->title(&titleBSTR.GetBSTR())))
        return E_FAIL;

    if (!static_cast<char*>(titleBSTR))
        titleBSTR = L"";

    COMPtr<IWebURLRequest> request;
    if (FAILED(navigationData->originalRequest(&request)))
        return E_FAIL;

    _bstr_t httpMethodBSTR;
    if (FAILED(request->HTTPMethod(&httpMethodBSTR.GetBSTR())))
        return E_FAIL;

    if (!static_cast<char*>(httpMethodBSTR))
        httpMethodBSTR = L"";

    COMPtr<IWebURLResponse> response;
    if (FAILED(navigationData->response(&response)))
        return E_FAIL;

    COMPtr<IWebHTTPURLResponse> httpResponse;
    if (FAILED(response->QueryInterface(&httpResponse)))
        return E_FAIL;

    int statusCode = 0;
    if (FAILED(httpResponse->statusCode(&statusCode)))
        return E_FAIL;

    BOOL hasSubstituteData;
    if (FAILED(navigationData->hasSubstituteData(&hasSubstituteData)))
        return E_FAIL;

    _bstr_t clientRedirectSourceBSTR;
    if (FAILED(navigationData->clientRedirectSource(&clientRedirectSourceBSTR.GetBSTR())))
        return E_FAIL;

    if (!static_cast<char*>(clientRedirectSourceBSTR))
        clientRedirectSourceBSTR = L"";

    bool hasClientRedirect = clientRedirectSourceBSTR.length();
    wstring redirectSource;
    if (clientRedirectSourceBSTR.length())
        redirectSource = urlSuitableForTestResult(wstringFromBSTR(clientRedirectSourceBSTR));

    bool wasFailure = hasSubstituteData || (httpResponse && statusCode >= 400);

    printf("WebView navigated to url \"%S\" with title \"%s\" with HTTP equivalent method \"%s\".  The navigation was %s and was %s%S.\n",
           url.c_str(),
           static_cast<char*>(titleBSTR),
           static_cast<char*>(httpMethodBSTR),
           wasFailure ? "a failure" : "successful",
           hasClientRedirect ? "a client redirect from " : "not a client redirect",
           redirectSource.c_str());

    return S_OK;
}