• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2006. 2007 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1.  Redistributions of source code must retain the above copyright
9 *     notice, this list of conditions and the following disclaimer.
10 * 2.  Redistributions in binary form must reproduce the above copyright
11 *     notice, this list of conditions and the following disclaimer in the
12 *     documentation and/or other materials provided with the distribution.
13 * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 *     its contributors may be used to endorse or promote products derived
15 *     from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#import "config.h"
30#import "UIDelegate.h"
31
32#import "DumpRenderTree.h"
33#import "DumpRenderTreeDraggingInfo.h"
34#import "EventSendingController.h"
35#import "LayoutTestController.h"
36#import <WebKit/WebFramePrivate.h>
37#import <WebKit/WebHTMLViewPrivate.h>
38#import <WebKit/WebSecurityOriginPrivate.h>
39#import <WebKit/WebView.h>
40#import <wtf/Assertions.h>
41
42DumpRenderTreeDraggingInfo *draggingInfo = nil;
43
44@implementation UIDelegate
45
46- (void)webView:(WebView *)sender setFrame:(NSRect)frame
47{
48    m_frame = frame;
49}
50
51- (NSRect)webViewFrame:(WebView *)sender
52{
53    return m_frame;
54}
55
56- (void)webView:(WebView *)sender addMessageToConsole:(NSDictionary *)dictionary
57{
58    NSString *message = [dictionary objectForKey:@"message"];
59    NSNumber *lineNumber = [dictionary objectForKey:@"lineNumber"];
60
61    NSRange range = [message rangeOfString:@"file://"];
62    if (range.location != NSNotFound)
63        message = [[message substringToIndex:range.location] stringByAppendingString:[[message substringFromIndex:NSMaxRange(range)] lastPathComponent]];
64
65    printf ("CONSOLE MESSAGE: line %d: %s\n", [lineNumber intValue], [message UTF8String]);
66}
67
68- (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame
69{
70    if (!done)
71        printf("ALERT: %s\n", [message UTF8String]);
72}
73
74- (BOOL)webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame
75{
76    if (!done)
77        printf("CONFIRM: %s\n", [message UTF8String]);
78    return YES;
79}
80
81- (NSString *)webView:(WebView *)sender runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)defaultText initiatedByFrame:(WebFrame *)frame
82{
83    if (!done)
84        printf("PROMPT: %s, default text: %s\n", [prompt UTF8String], [defaultText UTF8String]);
85    return defaultText;
86}
87
88- (BOOL)webView:(WebView *)c runBeforeUnloadConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame
89{
90    if (!done)
91        printf("CONFIRM NAVIGATION: %s\n", [message UTF8String]);
92    return YES;
93}
94
95
96- (void)webView:(WebView *)sender dragImage:(NSImage *)anImage at:(NSPoint)viewLocation offset:(NSSize)initialOffset event:(NSEvent *)event pasteboard:(NSPasteboard *)pboard source:(id)sourceObj slideBack:(BOOL)slideFlag forView:(NSView *)view
97{
98     assert(!draggingInfo);
99     draggingInfo = [[DumpRenderTreeDraggingInfo alloc] initWithImage:anImage offset:initialOffset pasteboard:pboard source:sourceObj];
100     [sender draggingUpdated:draggingInfo];
101     [EventSendingController replaySavedEvents];
102}
103
104- (void)webViewFocus:(WebView *)webView
105{
106    gLayoutTestController->setWindowIsKey(true);
107}
108
109- (void)webViewUnfocus:(WebView *)webView
110{
111    gLayoutTestController->setWindowIsKey(false);
112}
113
114- (WebView *)webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request
115{
116    if (!gLayoutTestController->canOpenWindows())
117        return nil;
118
119    // Make sure that waitUntilDone has been called.
120    ASSERT(gLayoutTestController->waitToDump());
121
122    WebView *webView = createWebViewAndOffscreenWindow();
123
124    return [webView autorelease];
125}
126
127- (void)webViewClose:(WebView *)sender
128{
129    NSWindow* window = [sender window];
130
131    if (gLayoutTestController->callCloseOnWebViews())
132        [sender close];
133
134    [window close];
135}
136
137- (void)webView:(WebView *)sender frame:(WebFrame *)frame exceededDatabaseQuotaForSecurityOrigin:(WebSecurityOrigin *)origin database:(NSString *)databaseIdentifier
138{
139    if (!done && gLayoutTestController->dumpDatabaseCallbacks())
140        printf("UI DELEGATE DATABASE CALLBACK: exceededDatabaseQuotaForSecurityOrigin:{%s, %s, %i} database:%s\n", [[origin protocol] UTF8String], [[origin host] UTF8String],
141            [origin port], [databaseIdentifier UTF8String]);
142
143    static const unsigned long long defaultQuota = 5 * 1024 * 1024;
144    [origin setQuota:defaultQuota];
145}
146
147- (void)webView:(WebView *)sender setStatusText:(NSString *)text
148{
149    if (gLayoutTestController->dumpStatusCallbacks())
150        printf("UI DELEGATE STATUS CALLBACK: setStatusText:%s\n", [text UTF8String]);
151}
152
153- (void)dealloc
154{
155    [draggingInfo release];
156    draggingInfo = nil;
157
158    [super dealloc];
159}
160
161@end
162