2
* Copyright (C) 2006. 2007 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
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.
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.
30
#import "UIDelegate.h"
32
#import "DumpRenderTree.h"
33
#import "DumpRenderTreeDraggingInfo.h"
34
#import "EventSendingController.h"
35
#import "MockWebNotificationProvider.h"
36
#import "TestRunner.h"
37
#import <WebKit/WebApplicationCache.h>
38
#import <WebKit/WebFramePrivate.h>
39
#import <WebKit/WebHTMLViewPrivate.h>
40
#import <WebKit/WebQuotaManager.h>
41
#import <WebKit/WebSecurityOriginPrivate.h>
42
#import <WebKit/WebUIDelegatePrivate.h>
43
#import <WebKit/WebView.h>
44
#import <WebKit/WebViewPrivate.h>
45
#import <wtf/Assertions.h>
47
DumpRenderTreeDraggingInfo *draggingInfo = nil;
49
@implementation UIDelegate
51
- (void)webView:(WebView *)sender setFrame:(NSRect)frame
56
- (NSRect)webViewFrame:(WebView *)sender
61
- (void)webView:(WebView *)sender addMessageToConsole:(NSDictionary *)dictionary withSource:(NSString *)source
63
NSString *message = [dictionary objectForKey:@"message"];
64
NSNumber *lineNumber = [dictionary objectForKey:@"lineNumber"];
66
NSRange range = [message rangeOfString:@"file://"];
67
if (range.location != NSNotFound)
68
message = [[message substringToIndex:range.location] stringByAppendingString:[[message substringFromIndex:NSMaxRange(range)] lastPathComponent]];
70
printf ("CONSOLE MESSAGE: ");
71
if ([lineNumber intValue])
72
printf ("line %d: ", [lineNumber intValue]);
73
printf ("%s\n", [message UTF8String]);
76
- (void)modalWindowWillClose:(NSNotification *)notification
78
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowWillCloseNotification object:nil];
82
- (void)webViewRunModal:(WebView *)sender
84
gTestRunner->setWindowIsKey(false);
85
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(modalWindowWillClose:) name:NSWindowWillCloseNotification object:nil];
86
[NSApp runModalForWindow:[sender window]];
87
gTestRunner->setWindowIsKey(true);
90
- (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame
93
printf("ALERT: %s\n", [message UTF8String]);
98
- (BOOL)webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame
101
printf("CONFIRM: %s\n", [message UTF8String]);
105
- (NSString *)webView:(WebView *)sender runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)defaultText initiatedByFrame:(WebFrame *)frame
108
printf("PROMPT: %s, default text: %s\n", [prompt UTF8String], [defaultText UTF8String]);
112
- (BOOL)webView:(WebView *)c runBeforeUnloadConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame
115
printf("CONFIRM NAVIGATION: %s\n", [message UTF8String]);
117
return !gTestRunner->shouldStayOnPageAfterHandlingBeforeUnload();
121
- (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
123
assert(!draggingInfo);
124
draggingInfo = [[DumpRenderTreeDraggingInfo alloc] initWithImage:anImage offset:initialOffset pasteboard:pboard source:sourceObj];
125
[sender draggingUpdated:draggingInfo];
126
[EventSendingController replaySavedEvents];
129
- (void)webViewFocus:(WebView *)webView
131
gTestRunner->setWindowIsKey(true);
134
- (void)webViewUnfocus:(WebView *)webView
136
gTestRunner->setWindowIsKey(false);
139
- (WebView *)webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request
141
if (!gTestRunner->canOpenWindows())
144
// Make sure that waitUntilDone has been called.
145
ASSERT(gTestRunner->waitToDump());
147
WebView *webView = createWebViewAndOffscreenWindow();
149
if (gTestRunner->newWindowsCopyBackForwardList())
150
[webView _loadBackForwardListFromOtherView:sender];
152
return [webView autorelease];
155
- (void)webViewClose:(WebView *)sender
157
NSWindow* window = [sender window];
159
if (gTestRunner->callCloseOnWebViews())
165
- (void)webView:(WebView *)sender frame:(WebFrame *)frame exceededDatabaseQuotaForSecurityOrigin:(WebSecurityOrigin *)origin database:(NSString *)databaseIdentifier
167
if (!done && gTestRunner->dumpDatabaseCallbacks()) {
168
printf("UI DELEGATE DATABASE CALLBACK: exceededDatabaseQuotaForSecurityOrigin:{%s, %s, %i} database:%s\n", [[origin protocol] UTF8String], [[origin host] UTF8String],
169
[origin port], [databaseIdentifier UTF8String]);
172
static const unsigned long long defaultQuota = 5 * 1024 * 1024;
173
[[origin databaseQuotaManager] setQuota:defaultQuota];
176
- (void)webView:(WebView *)sender exceededApplicationCacheOriginQuotaForSecurityOrigin:(WebSecurityOrigin *)origin totalSpaceNeeded:(NSUInteger)totalSpaceNeeded
178
if (!done && gTestRunner->dumpApplicationCacheDelegateCallbacks()) {
179
// For example, numbers from 30000 - 39999 will output as 30000.
180
// Rounding up or down not really matter for these tests. It's
181
// sufficient to just get a range of 10000 to determine if we were
182
// above or below a threshold.
183
unsigned long truncatedSpaceNeeded = static_cast<unsigned long>((totalSpaceNeeded / 10000) * 10000);
184
printf("UI DELEGATE APPLICATION CACHE CALLBACK: exceededApplicationCacheOriginQuotaForSecurityOrigin:{%s, %s, %i} totalSpaceNeeded:~%lu\n",
185
[[origin protocol] UTF8String], [[origin host] UTF8String], [origin port], truncatedSpaceNeeded);
188
if (gTestRunner->disallowIncreaseForApplicationCacheQuota())
191
static const unsigned long long defaultOriginQuota = [WebApplicationCache defaultOriginQuota];
192
[[origin applicationCacheQuotaManager] setQuota:defaultOriginQuota];
195
- (void)webView:(WebView *)sender setStatusText:(NSString *)text
197
if (gTestRunner->dumpStatusCallbacks())
198
printf("UI DELEGATE STATUS CALLBACK: setStatusText:%s\n", [text UTF8String]);
201
- (void)webView:(WebView *)webView decidePolicyForGeolocationRequestFromOrigin:(WebSecurityOrigin *)origin frame:(WebFrame *)frame listener:(id<WebAllowDenyPolicyListener>)listener
203
if (!gTestRunner->isGeolocationPermissionSet()) {
204
if (!m_pendingGeolocationPermissionListeners)
205
m_pendingGeolocationPermissionListeners = [[NSMutableSet set] retain];
206
[m_pendingGeolocationPermissionListeners addObject:listener];
210
if (gTestRunner->geolocationPermission())
216
- (void)didSetMockGeolocationPermission
218
ASSERT(gTestRunner->isGeolocationPermissionSet());
219
if (m_pendingGeolocationPermissionListeners && !m_timer)
220
m_timer = [NSTimer scheduledTimerWithTimeInterval:0 target:self selector:@selector(timerFired) userInfo:0 repeats:NO];
223
- (int)numberOfPendingGeolocationPermissionRequests
225
if (!m_pendingGeolocationPermissionListeners)
227
return [m_pendingGeolocationPermissionListeners count];
233
ASSERT(gTestRunner->isGeolocationPermissionSet());
235
NSEnumerator* enumerator = [m_pendingGeolocationPermissionListeners objectEnumerator];
236
id<WebAllowDenyPolicyListener> listener;
237
while ((listener = [enumerator nextObject])) {
238
if (gTestRunner->geolocationPermission())
243
[m_pendingGeolocationPermissionListeners removeAllObjects];
244
[m_pendingGeolocationPermissionListeners release];
245
m_pendingGeolocationPermissionListeners = nil;
248
- (BOOL)webView:(WebView *)sender shouldHaltPlugin:(DOMNode *)pluginNode
253
- (BOOL)webView:(WebView *)webView supportsFullScreenForElement:(DOMElement*)element withKeyboard:(BOOL)withKeyboard
258
- (void)enterFullScreenWithListener:(NSObject<WebKitFullScreenListener>*)listener
260
[listener webkitWillEnterFullScreen];
261
[listener webkitDidEnterFullScreen];
264
- (void)webView:(WebView *)webView enterFullScreenForElement:(DOMElement*)element listener:(NSObject<WebKitFullScreenListener>*)listener
266
if (!gTestRunner->hasCustomFullScreenBehavior())
267
[self performSelector:@selector(enterFullScreenWithListener:) withObject:listener afterDelay:0];
270
- (void)exitFullScreenWithListener:(NSObject<WebKitFullScreenListener>*)listener
272
[listener webkitWillExitFullScreen];
273
[listener webkitDidExitFullScreen];
276
- (void)webView:(WebView *)webView exitFullScreenForElement:(DOMElement*)element listener:(NSObject<WebKitFullScreenListener>*)listener
278
if (!gTestRunner->hasCustomFullScreenBehavior())
279
[self performSelector:@selector(exitFullScreenWithListener:) withObject:listener afterDelay:0];
282
- (void)webView:(WebView *)sender closeFullScreenWithListener:(NSObject<WebKitFullScreenListener>*)listener
284
[listener webkitWillExitFullScreen];
285
[listener webkitDidExitFullScreen];
288
- (BOOL)webView:(WebView *)webView didPressMissingPluginButton:(DOMElement *)element
290
printf("MISSING PLUGIN BUTTON PRESSED\n");
294
- (void)webView:(WebView *)webView decidePolicyForNotificationRequestFromOrigin:(WebSecurityOrigin *)origin listener:(id<WebAllowDenyPolicyListener>)listener
296
MockWebNotificationProvider *provider = (MockWebNotificationProvider *)[webView _notificationProvider];
297
switch ([provider policyForOrigin:origin]) {
298
case WebNotificationPermissionAllowed:
301
case WebNotificationPermissionDenied:
304
case WebNotificationPermissionNotAllowed:
305
[provider setWebNotificationOrigin:[origin stringValue] permission:YES];
313
[draggingInfo release];
315
[m_pendingGeolocationPermissionListeners release];
316
m_pendingGeolocationPermissionListeners = nil;