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/WebUIDelegatePrivate.h> |
|
40 #import <WebKit/WebView.h> |
|
41 #import <WebKit/WebViewPrivate.h> |
|
42 #import <wtf/Assertions.h> |
|
43 |
|
44 DumpRenderTreeDraggingInfo *draggingInfo = nil; |
|
45 |
|
46 @implementation UIDelegate |
|
47 |
|
48 - (void)webView:(WebView *)sender setFrame:(NSRect)frame |
|
49 { |
|
50 m_frame = frame; |
|
51 } |
|
52 |
|
53 - (NSRect)webViewFrame:(WebView *)sender |
|
54 { |
|
55 return m_frame; |
|
56 } |
|
57 |
|
58 - (void)webView:(WebView *)sender addMessageToConsole:(NSDictionary *)dictionary |
|
59 { |
|
60 NSString *message = [dictionary objectForKey:@"message"]; |
|
61 NSNumber *lineNumber = [dictionary objectForKey:@"lineNumber"]; |
|
62 |
|
63 NSRange range = [message rangeOfString:@"file://"]; |
|
64 if (range.location != NSNotFound) |
|
65 message = [[message substringToIndex:range.location] stringByAppendingString:[[message substringFromIndex:NSMaxRange(range)] lastPathComponent]]; |
|
66 |
|
67 printf ("CONSOLE MESSAGE: line %d: %s\n", [lineNumber intValue], [message UTF8String]); |
|
68 } |
|
69 |
|
70 - (void)modalWindowWillClose:(NSNotification *)notification |
|
71 { |
|
72 [[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowWillCloseNotification object:nil]; |
|
73 [NSApp abortModal]; |
|
74 } |
|
75 |
|
76 - (void)webViewRunModal:(WebView *)sender |
|
77 { |
|
78 gLayoutTestController->setWindowIsKey(false); |
|
79 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(modalWindowWillClose:) name:NSWindowWillCloseNotification object:nil]; |
|
80 [NSApp runModalForWindow:[sender window]]; |
|
81 gLayoutTestController->setWindowIsKey(true); |
|
82 } |
|
83 |
|
84 - (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame |
|
85 { |
|
86 if (!done) |
|
87 printf("ALERT: %s\n", [message UTF8String]); |
|
88 } |
|
89 |
|
90 - (BOOL)webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame |
|
91 { |
|
92 if (!done) |
|
93 printf("CONFIRM: %s\n", [message UTF8String]); |
|
94 return YES; |
|
95 } |
|
96 |
|
97 - (NSString *)webView:(WebView *)sender runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)defaultText initiatedByFrame:(WebFrame *)frame |
|
98 { |
|
99 if (!done) |
|
100 printf("PROMPT: %s, default text: %s\n", [prompt UTF8String], [defaultText UTF8String]); |
|
101 return defaultText; |
|
102 } |
|
103 |
|
104 - (BOOL)webView:(WebView *)c runBeforeUnloadConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame |
|
105 { |
|
106 if (!done) |
|
107 printf("CONFIRM NAVIGATION: %s\n", [message UTF8String]); |
|
108 return YES; |
|
109 } |
|
110 |
|
111 |
|
112 - (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 |
|
113 { |
|
114 assert(!draggingInfo); |
|
115 draggingInfo = [[DumpRenderTreeDraggingInfo alloc] initWithImage:anImage offset:initialOffset pasteboard:pboard source:sourceObj]; |
|
116 [sender draggingUpdated:draggingInfo]; |
|
117 [EventSendingController replaySavedEvents]; |
|
118 } |
|
119 |
|
120 - (void)webViewFocus:(WebView *)webView |
|
121 { |
|
122 gLayoutTestController->setWindowIsKey(true); |
|
123 } |
|
124 |
|
125 - (void)webViewUnfocus:(WebView *)webView |
|
126 { |
|
127 gLayoutTestController->setWindowIsKey(false); |
|
128 } |
|
129 |
|
130 - (WebView *)webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request |
|
131 { |
|
132 if (!gLayoutTestController->canOpenWindows()) |
|
133 return nil; |
|
134 |
|
135 // Make sure that waitUntilDone has been called. |
|
136 ASSERT(gLayoutTestController->waitToDump()); |
|
137 |
|
138 WebView *webView = createWebViewAndOffscreenWindow(); |
|
139 |
|
140 if (gLayoutTestController->newWindowsCopyBackForwardList()) |
|
141 [webView _loadBackForwardListFromOtherView:sender]; |
|
142 |
|
143 return [webView autorelease]; |
|
144 } |
|
145 |
|
146 - (void)webViewClose:(WebView *)sender |
|
147 { |
|
148 NSWindow* window = [sender window]; |
|
149 |
|
150 if (gLayoutTestController->callCloseOnWebViews()) |
|
151 [sender close]; |
|
152 |
|
153 [window close]; |
|
154 } |
|
155 |
|
156 - (void)webView:(WebView *)sender frame:(WebFrame *)frame exceededDatabaseQuotaForSecurityOrigin:(WebSecurityOrigin *)origin database:(NSString *)databaseIdentifier |
|
157 { |
|
158 if (!done && gLayoutTestController->dumpDatabaseCallbacks()) |
|
159 printf("UI DELEGATE DATABASE CALLBACK: exceededDatabaseQuotaForSecurityOrigin:{%s, %s, %i} database:%s\n", [[origin protocol] UTF8String], [[origin host] UTF8String], |
|
160 [origin port], [databaseIdentifier UTF8String]); |
|
161 |
|
162 static const unsigned long long defaultQuota = 5 * 1024 * 1024; |
|
163 [origin setQuota:defaultQuota]; |
|
164 } |
|
165 |
|
166 - (void)webView:(WebView *)sender setStatusText:(NSString *)text |
|
167 { |
|
168 if (gLayoutTestController->dumpStatusCallbacks()) |
|
169 printf("UI DELEGATE STATUS CALLBACK: setStatusText:%s\n", [text UTF8String]); |
|
170 } |
|
171 |
|
172 - (void)webView:(WebView *)webView decidePolicyForGeolocationRequestFromOrigin:(WebSecurityOrigin *)origin frame:(WebFrame *)frame listener:(id<WebGeolocationPolicyListener>)listener |
|
173 { |
|
174 // FIXME: If mock permission isn't set yet, we should send the response asynchronously. |
|
175 if (gLayoutTestController->isGeolocationPermissionSet() && gLayoutTestController->geolocationPermission()) |
|
176 [listener allow]; |
|
177 else |
|
178 [listener deny]; |
|
179 } |
|
180 |
|
181 - (BOOL)webView:(WebView *)sender shouldHaltPlugin:(DOMNode *)pluginNode |
|
182 { |
|
183 return NO; |
|
184 } |
|
185 |
|
186 - (BOOL)webView:(WebView *)webView didPressMissingPluginButton:(DOMElement *)element |
|
187 { |
|
188 printf("MISSING PLUGIN BUTTON PRESSED\n"); |
|
189 return TRUE; |
|
190 } |
|
191 |
|
192 - (void)dealloc |
|
193 { |
|
194 [draggingInfo release]; |
|
195 draggingInfo = nil; |
|
196 |
|
197 [super dealloc]; |
|
198 } |
|
199 |
|
200 @end |
|