~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Tools/DumpRenderTree/mac/UIDelegate.mm

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "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>
 
46
 
 
47
DumpRenderTreeDraggingInfo *draggingInfo = nil;
 
48
 
 
49
@implementation UIDelegate
 
50
 
 
51
- (void)webView:(WebView *)sender setFrame:(NSRect)frame
 
52
{
 
53
    m_frame = frame;
 
54
}
 
55
 
 
56
- (NSRect)webViewFrame:(WebView *)sender
 
57
{
 
58
    return m_frame;
 
59
}
 
60
 
 
61
- (void)webView:(WebView *)sender addMessageToConsole:(NSDictionary *)dictionary withSource:(NSString *)source
 
62
{
 
63
    NSString *message = [dictionary objectForKey:@"message"];
 
64
    NSNumber *lineNumber = [dictionary objectForKey:@"lineNumber"];
 
65
 
 
66
    NSRange range = [message rangeOfString:@"file://"];
 
67
    if (range.location != NSNotFound)
 
68
        message = [[message substringToIndex:range.location] stringByAppendingString:[[message substringFromIndex:NSMaxRange(range)] lastPathComponent]];
 
69
 
 
70
    printf ("CONSOLE MESSAGE: ");
 
71
    if ([lineNumber intValue])
 
72
        printf ("line %d: ", [lineNumber intValue]);
 
73
    printf ("%s\n", [message UTF8String]);
 
74
}
 
75
 
 
76
- (void)modalWindowWillClose:(NSNotification *)notification
 
77
{
 
78
    [[NSNotificationCenter defaultCenter] removeObserver:self name:NSWindowWillCloseNotification object:nil];
 
79
    [NSApp abortModal];
 
80
}
 
81
 
 
82
- (void)webViewRunModal:(WebView *)sender
 
83
{
 
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);
 
88
}
 
89
 
 
90
- (void)webView:(WebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame
 
91
{
 
92
    if (!done) {
 
93
        printf("ALERT: %s\n", [message UTF8String]);
 
94
        fflush(stdout);
 
95
    }
 
96
}
 
97
 
 
98
- (BOOL)webView:(WebView *)sender runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame
 
99
{
 
100
    if (!done)
 
101
        printf("CONFIRM: %s\n", [message UTF8String]);
 
102
    return YES;
 
103
}
 
104
 
 
105
- (NSString *)webView:(WebView *)sender runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)defaultText initiatedByFrame:(WebFrame *)frame
 
106
{
 
107
    if (!done)
 
108
        printf("PROMPT: %s, default text: %s\n", [prompt UTF8String], [defaultText UTF8String]);
 
109
    return defaultText;
 
110
}
 
111
 
 
112
- (BOOL)webView:(WebView *)c runBeforeUnloadConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WebFrame *)frame
 
113
{
 
114
    if (!done)
 
115
        printf("CONFIRM NAVIGATION: %s\n", [message UTF8String]);
 
116
    
 
117
    return !gTestRunner->shouldStayOnPageAfterHandlingBeforeUnload();
 
118
}
 
119
 
 
120
 
 
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
 
122
{
 
123
     assert(!draggingInfo);
 
124
     draggingInfo = [[DumpRenderTreeDraggingInfo alloc] initWithImage:anImage offset:initialOffset pasteboard:pboard source:sourceObj];
 
125
     [sender draggingUpdated:draggingInfo];
 
126
     [EventSendingController replaySavedEvents];
 
127
}
 
128
 
 
129
- (void)webViewFocus:(WebView *)webView
 
130
{
 
131
    gTestRunner->setWindowIsKey(true);
 
132
}
 
133
 
 
134
- (void)webViewUnfocus:(WebView *)webView
 
135
{
 
136
    gTestRunner->setWindowIsKey(false);
 
137
}
 
138
 
 
139
- (WebView *)webView:(WebView *)sender createWebViewWithRequest:(NSURLRequest *)request
 
140
{
 
141
    if (!gTestRunner->canOpenWindows())
 
142
        return nil;
 
143
    
 
144
    // Make sure that waitUntilDone has been called.
 
145
    ASSERT(gTestRunner->waitToDump());
 
146
 
 
147
    WebView *webView = createWebViewAndOffscreenWindow();
 
148
    
 
149
    if (gTestRunner->newWindowsCopyBackForwardList())
 
150
        [webView _loadBackForwardListFromOtherView:sender];
 
151
    
 
152
    return [webView autorelease];
 
153
}
 
154
 
 
155
- (void)webViewClose:(WebView *)sender
 
156
{
 
157
    NSWindow* window = [sender window];
 
158
 
 
159
    if (gTestRunner->callCloseOnWebViews())
 
160
        [sender close];
 
161
    
 
162
    [window close];
 
163
}
 
164
 
 
165
- (void)webView:(WebView *)sender frame:(WebFrame *)frame exceededDatabaseQuotaForSecurityOrigin:(WebSecurityOrigin *)origin database:(NSString *)databaseIdentifier
 
166
{
 
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]);
 
170
    }
 
171
 
 
172
    static const unsigned long long defaultQuota = 5 * 1024 * 1024;    
 
173
    [[origin databaseQuotaManager] setQuota:defaultQuota];
 
174
}
 
175
 
 
176
- (void)webView:(WebView *)sender exceededApplicationCacheOriginQuotaForSecurityOrigin:(WebSecurityOrigin *)origin totalSpaceNeeded:(NSUInteger)totalSpaceNeeded
 
177
{
 
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);
 
186
    }
 
187
 
 
188
    if (gTestRunner->disallowIncreaseForApplicationCacheQuota())
 
189
        return;
 
190
 
 
191
    static const unsigned long long defaultOriginQuota = [WebApplicationCache defaultOriginQuota];
 
192
    [[origin applicationCacheQuotaManager] setQuota:defaultOriginQuota];
 
193
}
 
194
 
 
195
- (void)webView:(WebView *)sender setStatusText:(NSString *)text
 
196
{
 
197
    if (gTestRunner->dumpStatusCallbacks())
 
198
        printf("UI DELEGATE STATUS CALLBACK: setStatusText:%s\n", [text UTF8String]);
 
199
}
 
200
 
 
201
- (void)webView:(WebView *)webView decidePolicyForGeolocationRequestFromOrigin:(WebSecurityOrigin *)origin frame:(WebFrame *)frame listener:(id<WebAllowDenyPolicyListener>)listener
 
202
{
 
203
    if (!gTestRunner->isGeolocationPermissionSet()) {
 
204
        if (!m_pendingGeolocationPermissionListeners)
 
205
            m_pendingGeolocationPermissionListeners = [[NSMutableSet set] retain];
 
206
        [m_pendingGeolocationPermissionListeners addObject:listener];
 
207
        return;
 
208
    }
 
209
 
 
210
    if (gTestRunner->geolocationPermission())
 
211
        [listener allow];
 
212
    else
 
213
        [listener deny];
 
214
}
 
215
 
 
216
- (void)didSetMockGeolocationPermission
 
217
{
 
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];
 
221
}
 
222
 
 
223
- (int)numberOfPendingGeolocationPermissionRequests
 
224
{
 
225
    if (!m_pendingGeolocationPermissionListeners)
 
226
        return 0;
 
227
    return [m_pendingGeolocationPermissionListeners count];
 
228
}
 
229
 
 
230
 
 
231
- (void)timerFired
 
232
{
 
233
    ASSERT(gTestRunner->isGeolocationPermissionSet());
 
234
    m_timer = 0;
 
235
    NSEnumerator* enumerator = [m_pendingGeolocationPermissionListeners objectEnumerator];
 
236
    id<WebAllowDenyPolicyListener> listener;
 
237
    while ((listener = [enumerator nextObject])) {
 
238
        if (gTestRunner->geolocationPermission())
 
239
            [listener allow];
 
240
        else
 
241
            [listener deny];
 
242
    }
 
243
    [m_pendingGeolocationPermissionListeners removeAllObjects];
 
244
    [m_pendingGeolocationPermissionListeners release];
 
245
    m_pendingGeolocationPermissionListeners = nil;
 
246
}
 
247
 
 
248
- (BOOL)webView:(WebView *)sender shouldHaltPlugin:(DOMNode *)pluginNode
 
249
{
 
250
    return NO;
 
251
}
 
252
 
 
253
- (BOOL)webView:(WebView *)webView supportsFullScreenForElement:(DOMElement*)element withKeyboard:(BOOL)withKeyboard
 
254
{
 
255
    return YES;
 
256
}
 
257
 
 
258
- (void)enterFullScreenWithListener:(NSObject<WebKitFullScreenListener>*)listener
 
259
{
 
260
    [listener webkitWillEnterFullScreen];
 
261
    [listener webkitDidEnterFullScreen];
 
262
}
 
263
 
 
264
- (void)webView:(WebView *)webView enterFullScreenForElement:(DOMElement*)element listener:(NSObject<WebKitFullScreenListener>*)listener
 
265
{
 
266
    if (!gTestRunner->hasCustomFullScreenBehavior())
 
267
        [self performSelector:@selector(enterFullScreenWithListener:) withObject:listener afterDelay:0];
 
268
}
 
269
 
 
270
- (void)exitFullScreenWithListener:(NSObject<WebKitFullScreenListener>*)listener
 
271
{
 
272
    [listener webkitWillExitFullScreen];
 
273
    [listener webkitDidExitFullScreen];
 
274
}
 
275
 
 
276
- (void)webView:(WebView *)webView exitFullScreenForElement:(DOMElement*)element listener:(NSObject<WebKitFullScreenListener>*)listener
 
277
{
 
278
    if (!gTestRunner->hasCustomFullScreenBehavior())
 
279
        [self performSelector:@selector(exitFullScreenWithListener:) withObject:listener afterDelay:0];
 
280
}
 
281
 
 
282
- (void)webView:(WebView *)sender closeFullScreenWithListener:(NSObject<WebKitFullScreenListener>*)listener
 
283
{
 
284
    [listener webkitWillExitFullScreen];
 
285
    [listener webkitDidExitFullScreen];
 
286
}
 
287
 
 
288
- (BOOL)webView:(WebView *)webView didPressMissingPluginButton:(DOMElement *)element
 
289
{
 
290
    printf("MISSING PLUGIN BUTTON PRESSED\n");
 
291
    return TRUE;
 
292
}
 
293
 
 
294
- (void)webView:(WebView *)webView decidePolicyForNotificationRequestFromOrigin:(WebSecurityOrigin *)origin listener:(id<WebAllowDenyPolicyListener>)listener
 
295
{
 
296
    MockWebNotificationProvider *provider = (MockWebNotificationProvider *)[webView _notificationProvider];
 
297
    switch ([provider policyForOrigin:origin]) {
 
298
    case WebNotificationPermissionAllowed:
 
299
        [listener allow];
 
300
        break;
 
301
    case WebNotificationPermissionDenied:
 
302
        [listener deny];
 
303
        break;
 
304
    case WebNotificationPermissionNotAllowed:
 
305
        [provider setWebNotificationOrigin:[origin stringValue] permission:YES];
 
306
        [listener allow];
 
307
        break;
 
308
    }
 
309
}
 
310
 
 
311
- (void)dealloc
 
312
{
 
313
    [draggingInfo release];
 
314
    draggingInfo = nil;
 
315
    [m_pendingGeolocationPermissionListeners release];
 
316
    m_pendingGeolocationPermissionListeners = nil;
 
317
 
 
318
    [super dealloc];
 
319
}
 
320
 
 
321
@end