1231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block/*
2231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * Copyright (C) 2009 Apple Inc. All rights reserved.
3231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block *
4231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * Redistribution and use in source and binary forms, with or without
5231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * modification, are permitted provided that the following conditions
6231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * are met:
7231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * 1. Redistributions of source code must retain the above copyright
8231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block *    notice, this list of conditions and the following disclaimer.
9231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * 2. Redistributions in binary form must reproduce the above copyright
10231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block *    notice, this list of conditions and the following disclaimer in the
11231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block *    documentation and/or other materials provided with the distribution.
12231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block *
13231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block */
25231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#import "config.h"
26231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#import "HistoryDelegate.h"
27231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
28231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#import "DumpRenderTree.h"
29231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#import "LayoutTestController.h"
30231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
31231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block#import <WebKit/WebNavigationData.h>
32cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block#import <WebKit/WebView.h>
33231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
34231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block@interface NSURL (DRTExtras)
35231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block- (NSString *)_drt_descriptionSuitableForTestResult;
36231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block@end
37231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
38231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block@implementation HistoryDelegate
39231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
40231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block- (void)webView:(WebView *)webView didNavigateWithNavigationData:(WebNavigationData *)navigationData inFrame:(WebFrame *)webFrame
41231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block{
42231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    NSURL *url = [navigationData url] ? [NSURL URLWithString:[navigationData url]] : nil;
43231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    bool hasClientRedirect = [[navigationData clientRedirectSource] length];
44231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    NSHTTPURLResponse *httpResponse = [[navigationData response] isKindOfClass:[NSHTTPURLResponse class]] ? (NSHTTPURLResponse *)[navigationData response] : nil;
45231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    bool wasFailure = [navigationData hasSubstituteData] || (httpResponse && [httpResponse statusCode] >= 400);
46231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
47231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    printf("WebView navigated to url \"%s\" with title \"%s\" with HTTP equivalent method \"%s\".  The navigation was %s and was %s%s.\n",
48231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        url ? [[url _drt_descriptionSuitableForTestResult] UTF8String] : "<none>",
49231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        [navigationData title] ? [[navigationData title] UTF8String] : "",
50231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        [navigationData originalRequest] ? [[[navigationData originalRequest] HTTPMethod] UTF8String] : "",
51231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        wasFailure ? "a failure" : "successful",
52231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        hasClientRedirect ? "a client redirect from " : "not a client redirect",
53231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block        hasClientRedirect ? [[navigationData clientRedirectSource] UTF8String] : "");
54231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block}
55231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
56231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block- (void)webView:(WebView *)webView didPerformClientRedirectFromURL:(NSString *)sourceURL toURL:(NSString *)destinationURL inFrame:(WebFrame *)webFrame
57231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block{
58231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    NSURL *source = [NSURL URLWithString:sourceURL];
59231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    NSURL *dest = [NSURL URLWithString:destinationURL];
60231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    printf("WebView performed a client redirect from \"%s\" to \"%s\".\n", [[source _drt_descriptionSuitableForTestResult] UTF8String], [[dest _drt_descriptionSuitableForTestResult] UTF8String]);
61231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block}
62231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
63231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block- (void)webView:(WebView *)webView didPerformServerRedirectFromURL:(NSString *)sourceURL toURL:(NSString *)destinationURL inFrame:(WebFrame *)webFrame
64231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block{
65231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    NSURL *source = [NSURL URLWithString:sourceURL];
66231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    NSURL *dest = [NSURL URLWithString:destinationURL];
67231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    printf("WebView performed a server redirect from \"%s\" to \"%s\".\n", [[source _drt_descriptionSuitableForTestResult] UTF8String], [[dest _drt_descriptionSuitableForTestResult] UTF8String]);
68231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block}
69231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
70231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block- (void)webView:(WebView *)webView updateHistoryTitle:(NSString *)title forURL:(NSString *)url
71231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block{
72231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block    printf("WebView updated the title for history URL \"%s\" to \"%s\".\n", [[[NSURL URLWithString:url]_drt_descriptionSuitableForTestResult] UTF8String], [title UTF8String]);
73231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block}
74231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block
75cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block- (void)populateVisitedLinksForWebView:(WebView *)webView
76cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block{
77cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block    if (gLayoutTestController->dumpVisitedLinksCallback())
78cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block        printf("Asked to populate visited links for WebView \"%s\"\n", [[[NSURL URLWithString:[webView mainFrameURL]] _drt_descriptionSuitableForTestResult] UTF8String]);
79cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block}
80cac0f67c402d107cdb10971b95719e2ff9c7c76bSteve Block
81231d4e3152a9c27a73b6ac7badbe6be673aa3ddfSteve Block@end
82