2 * Copyright (C) 2009 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "HistoryDelegate.h"
29 #include "DumpRenderTree.h"
30 #include "DumpRenderTreeWin.h"
31 #include "TestRunner.h"
33 #include <WebKit/WebKit.h>
37 static inline wstring wstringFromBSTR(BSTR str)
39 return wstring(str, ::SysStringLen(str));
42 HistoryDelegate::HistoryDelegate()
47 HistoryDelegate::~HistoryDelegate()
52 HRESULT HistoryDelegate::QueryInterface(REFIID riid, void** ppvObject)
55 if (IsEqualGUID(riid, IID_IUnknown))
56 *ppvObject = static_cast<IWebHistoryDelegate*>(this);
57 else if (IsEqualGUID(riid, IID_IWebHistoryDelegate))
58 *ppvObject = static_cast<IWebHistoryDelegate*>(this);
66 ULONG HistoryDelegate::AddRef(void)
71 ULONG HistoryDelegate::Release(void)
73 ULONG newRef = --m_refCount;
80 // IWebHistoryDelegate
81 HRESULT HistoryDelegate::didNavigateWithNavigationData(IWebView* webView, IWebNavigationData* navigationData, IWebFrame* webFrame)
83 if (!gTestRunner->dumpHistoryDelegateCallbacks())
87 if (FAILED(navigationData->url(&urlBSTR)))
91 url = urlSuitableForTestResult(wstringFromBSTR(urlBSTR));
92 SysFreeString(urlBSTR);
95 if (FAILED(navigationData->title(&titleBSTR)))
99 title = wstringFromBSTR(titleBSTR);
100 SysFreeString(titleBSTR);
102 COMPtr<IWebURLRequest> request;
103 if (FAILED(navigationData->originalRequest(&request)))
107 if (FAILED(request->HTTPMethod(&httpMethodBSTR)))
111 httpMethod = wstringFromBSTR(httpMethodBSTR);
112 SysFreeString(httpMethodBSTR);
114 COMPtr<IWebURLResponse> response;
115 if (FAILED(navigationData->response(&response)))
118 COMPtr<IWebHTTPURLResponse> httpResponse;
119 if (FAILED(response->QueryInterface(&httpResponse)))
123 if (FAILED(httpResponse->statusCode(&statusCode)))
126 BOOL hasSubstituteData;
127 if (FAILED(navigationData->hasSubstituteData(&hasSubstituteData)))
130 BSTR clientRedirectSourceBSTR;
131 if (FAILED(navigationData->clientRedirectSource(&clientRedirectSourceBSTR)))
133 bool hasClientRedirect = clientRedirectSourceBSTR && SysStringLen(clientRedirectSourceBSTR);
134 wstring redirectSource;
135 if (clientRedirectSourceBSTR)
136 redirectSource = urlSuitableForTestResult(wstringFromBSTR(clientRedirectSourceBSTR));
137 SysFreeString(clientRedirectSourceBSTR);
139 bool wasFailure = hasSubstituteData || (httpResponse && statusCode >= 400);
141 printf("WebView navigated to url \"%S\" with title \"%S\" with HTTP equivalent method \"%S\". The navigation was %s and was %s%S.\n",
145 wasFailure ? "a failure" : "successful",
146 hasClientRedirect ? "a client redirect from " : "not a client redirect",
147 redirectSource.c_str());
152 HRESULT HistoryDelegate::didPerformClientRedirectFromURL(IWebView*, BSTR sourceURL, BSTR destinationURL, IWebFrame*)
154 if (!gTestRunner->dumpHistoryDelegateCallbacks())
159 source = urlSuitableForTestResult(wstringFromBSTR(sourceURL));
163 destination = urlSuitableForTestResult(wstringFromBSTR(destinationURL));
165 printf("WebView performed a client redirect from \"%S\" to \"%S\".\n", source.c_str(), destination.c_str());
169 HRESULT HistoryDelegate::didPerformServerRedirectFromURL(IWebView* webView, BSTR sourceURL, BSTR destinationURL, IWebFrame* webFrame)
171 if (!gTestRunner->dumpHistoryDelegateCallbacks())
176 source = urlSuitableForTestResult(wstringFromBSTR(sourceURL));
180 destination = urlSuitableForTestResult(wstringFromBSTR(destinationURL));
182 printf("WebView performed a server redirect from \"%S\" to \"%S\".\n", source.c_str(), destination.c_str());
186 HRESULT HistoryDelegate::updateHistoryTitle(IWebView* webView, BSTR titleBSTR, BSTR urlBSTR)
188 if (!gTestRunner->dumpHistoryDelegateCallbacks())
193 url = urlSuitableForTestResult(wstringFromBSTR(urlBSTR));
197 title = wstringFromBSTR(titleBSTR);
199 printf("WebView updated the title for history URL \"%S\" to \"%S\".\n", url.c_str(), title.c_str());
203 HRESULT HistoryDelegate::populateVisitedLinksForWebView(IWebView* webView)
205 if (!gTestRunner->dumpHistoryDelegateCallbacks())
209 if (FAILED(webView->mainFrameURL(&urlBSTR)))
214 url = urlSuitableForTestResult(wstringFromBSTR(urlBSTR));
215 SysFreeString(urlBSTR);
217 if (gTestRunner->dumpVisitedLinksCallback())
218 printf("Asked to populate visited links for WebView \"%S\"\n", url.c_str());