2
* Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
3
* Copyright (C) 2008, 2010 Nokia Corporation and/or its subsidiary(-ies)
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
9
* 1. Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* 2. Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15
* its contributors may be used to endorse or promote products derived
16
* from this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
#import "WebChromeClient.h"
32
#import "DOMElementInternal.h"
33
#import "DOMNodeInternal.h"
34
#import "WebBasePluginPackage.h"
35
#import "WebDefaultUIDelegate.h"
36
#import "WebDelegateImplementationCaching.h"
37
#import "WebElementDictionary.h"
38
#import "WebFrameInternal.h"
39
#import "WebFrameView.h"
40
#import "WebHTMLViewInternal.h"
41
#import "WebHistoryInternal.h"
42
#import "WebKitFullScreenListener.h"
43
#import "WebKitPrefix.h"
44
#import "WebKitSystemInterface.h"
45
#import "WebNSURLRequestExtras.h"
46
#import "WebOpenPanelResultListener.h"
48
#import "WebQuotaManager.h"
49
#import "WebSecurityOriginInternal.h"
50
#import "WebUIDelegatePrivate.h"
52
#import "WebViewInternal.h"
53
#import <Foundation/Foundation.h>
54
#import <WebCore/BlockExceptions.h>
55
#import <WebCore/Console.h>
56
#import <WebCore/ContextMenu.h>
57
#import <WebCore/ContextMenuController.h>
58
#import <WebCore/Cursor.h>
59
#import <WebCore/Element.h>
60
#import <WebCore/FileChooser.h>
61
#import <WebCore/FileIconLoader.h>
62
#import <WebCore/FloatRect.h>
63
#import <WebCore/Frame.h>
64
#import <WebCore/FrameLoadRequest.h>
65
#import <WebCore/FrameView.h>
66
#import <WebCore/HTMLNames.h>
67
#import <WebCore/HTMLPlugInImageElement.h>
68
#import <WebCore/HitTestResult.h>
69
#import <WebCore/Icon.h>
70
#import <WebCore/IntPoint.h>
71
#import <WebCore/IntRect.h>
72
#import <WebCore/NavigationAction.h>
73
#import <WebCore/NotImplemented.h>
74
#import <WebCore/Page.h>
75
#import <WebCore/PlatformScreen.h>
76
#import <WebCore/PopupMenuMac.h>
77
#import <WebCore/ResourceRequest.h>
78
#import <WebCore/SearchPopupMenuMac.h>
79
#import <WebCore/Widget.h>
80
#import <WebCore/WindowFeatures.h>
81
#import <wtf/PassRefPtr.h>
82
#import <wtf/Vector.h>
83
#import <wtf/text/WTFString.h>
85
#if USE(ACCELERATED_COMPOSITING)
86
#import <WebCore/GraphicsLayer.h>
89
#if USE(PLUGIN_HOST_PROCESS) && ENABLE(NETSCAPE_PLUGIN_API)
90
#import "NetscapePluginHostManager.h"
93
NSString *WebConsoleMessageHTMLMessageSource = @"HTMLMessageSource";
94
NSString *WebConsoleMessageXMLMessageSource = @"XMLMessageSource";
95
NSString *WebConsoleMessageJSMessageSource = @"JSMessageSource";
96
NSString *WebConsoleMessageNetworkMessageSource = @"NetworkMessageSource";
97
NSString *WebConsoleMessageConsoleAPIMessageSource = @"ConsoleAPIMessageSource";
98
NSString *WebConsoleMessageOtherMessageSource = @"OtherMessageSource";
100
NSString *WebConsoleMessageLogMessageType = @"LogMessageType";
101
NSString *WebConsoleMessageDirMessageType = @"DirMessageType";
102
NSString *WebConsoleMessageClearMessageType = @"ClearMessageType";
103
NSString *WebConsoleMessageDirXMLMessageType = @"DirXMLMessageType";
104
NSString *WebConsoleMessageTraceMessageType = @"TraceMessageType";
105
NSString *WebConsoleMessageStartGroupMessageType = @"StartGroupMessageType";
106
NSString *WebConsoleMessageStartGroupCollapsedMessageType = @"StartGroupCollapsedMessageType";
107
NSString *WebConsoleMessageEndGroupMessageType = @"EndGroupMessageType";
108
NSString *WebConsoleMessageAssertMessageType = @"AssertMessageType";
110
NSString *WebConsoleMessageTipMessageLevel = @"TipMessageLevel";
111
NSString *WebConsoleMessageLogMessageLevel = @"LogMessageLevel";
112
NSString *WebConsoleMessageWarningMessageLevel = @"WarningMessageLevel";
113
NSString *WebConsoleMessageErrorMessageLevel = @"ErrorMessageLevel";
114
NSString *WebConsoleMessageDebugMessageLevel = @"DebugMessageLevel";
116
@interface NSApplication (WebNSApplicationDetails)
117
- (NSCursor *)_cursorRectCursor;
120
@interface NSView (WebNSViewDetails)
121
- (NSView *)_findLastViewInKeyViewLoop;
124
// For compatibility with old SPI.
125
@interface NSView (WebOldWebKitPlugInDetails)
126
- (void)setIsSelected:(BOOL)isSelected;
129
@interface NSWindow (AppKitSecretsIKnowAbout)
130
- (NSRect)_growBoxRect;
133
using namespace WebCore;
134
using namespace HTMLNames;
136
WebChromeClient::WebChromeClient(WebView *webView)
141
void WebChromeClient::chromeDestroyed()
146
// These functions scale between window and WebView coordinates because JavaScript/DOM operations
147
// assume that the WebView and the window share the same coordinate system.
149
void WebChromeClient::setWindowRect(const FloatRect& rect)
151
NSRect windowRect = toDeviceSpace(rect, [m_webView window]);
152
[[m_webView _UIDelegateForwarder] webView:m_webView setFrame:windowRect];
155
FloatRect WebChromeClient::windowRect()
157
NSRect windowRect = [[m_webView _UIDelegateForwarder] webViewFrame:m_webView];
158
return toUserSpace(windowRect, [m_webView window]);
161
// FIXME: We need to add API for setting and getting this.
162
FloatRect WebChromeClient::pageRect()
164
return [m_webView frame];
167
void WebChromeClient::focus()
169
[[m_webView _UIDelegateForwarder] webViewFocus:m_webView];
172
void WebChromeClient::unfocus()
174
[[m_webView _UIDelegateForwarder] webViewUnfocus:m_webView];
177
bool WebChromeClient::canTakeFocus(FocusDirection)
179
// There's unfortunately no way to determine if we will become first responder again
180
// once we give it up, so we just have to guess that we won't.
184
void WebChromeClient::takeFocus(FocusDirection direction)
186
if (direction == FocusDirectionForward) {
187
// Since we're trying to move focus out of m_webView, and because
188
// m_webView may contain subviews within it, we ask it for the next key
189
// view of the last view in its key view loop. This makes m_webView
190
// behave as if it had no subviews, which is the behavior we want.
191
NSView *lastView = [m_webView _findLastViewInKeyViewLoop];
192
// avoid triggering assertions if the WebView is the only thing in the key loop
193
if ([m_webView _becomingFirstResponderFromOutside] && m_webView == [lastView nextValidKeyView])
195
[[m_webView window] selectKeyViewFollowingView:lastView];
197
// avoid triggering assertions if the WebView is the only thing in the key loop
198
if ([m_webView _becomingFirstResponderFromOutside] && m_webView == [m_webView previousValidKeyView])
200
[[m_webView window] selectKeyViewPrecedingView:m_webView];
204
void WebChromeClient::focusedNodeChanged(Node*)
208
void WebChromeClient::focusedFrameChanged(Frame*)
212
Page* WebChromeClient::createWindow(Frame* frame, const FrameLoadRequest&, const WindowFeatures& features, const NavigationAction&)
214
id delegate = [m_webView UIDelegate];
217
if ([delegate respondsToSelector:@selector(webView:createWebViewWithRequest:windowFeatures:)]) {
218
NSNumber *x = features.xSet ? [[NSNumber alloc] initWithFloat:features.x] : nil;
219
NSNumber *y = features.ySet ? [[NSNumber alloc] initWithFloat:features.y] : nil;
220
NSNumber *width = features.widthSet ? [[NSNumber alloc] initWithFloat:features.width] : nil;
221
NSNumber *height = features.heightSet ? [[NSNumber alloc] initWithFloat:features.height] : nil;
222
NSNumber *menuBarVisible = [[NSNumber alloc] initWithBool:features.menuBarVisible];
223
NSNumber *statusBarVisible = [[NSNumber alloc] initWithBool:features.statusBarVisible];
224
NSNumber *toolBarVisible = [[NSNumber alloc] initWithBool:features.toolBarVisible];
225
NSNumber *scrollbarsVisible = [[NSNumber alloc] initWithBool:features.scrollbarsVisible];
226
NSNumber *resizable = [[NSNumber alloc] initWithBool:features.resizable];
227
NSNumber *fullscreen = [[NSNumber alloc] initWithBool:features.fullscreen];
228
NSNumber *dialog = [[NSNumber alloc] initWithBool:features.dialog];
230
NSMutableDictionary *dictFeatures = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
231
menuBarVisible, @"menuBarVisible",
232
statusBarVisible, @"statusBarVisible",
233
toolBarVisible, @"toolBarVisible",
234
scrollbarsVisible, @"scrollbarsVisible",
235
resizable, @"resizable",
236
fullscreen, @"fullscreen",
241
[dictFeatures setObject:x forKey:@"x"];
243
[dictFeatures setObject:y forKey:@"y"];
245
[dictFeatures setObject:width forKey:@"width"];
247
[dictFeatures setObject:height forKey:@"height"];
249
newWebView = CallUIDelegate(m_webView, @selector(webView:createWebViewWithRequest:windowFeatures:), nil, dictFeatures);
251
[dictFeatures release];
256
[menuBarVisible release];
257
[statusBarVisible release];
258
[toolBarVisible release];
259
[scrollbarsVisible release];
261
[fullscreen release];
263
} else if (features.dialog && [delegate respondsToSelector:@selector(webView:createWebViewModalDialogWithRequest:)]) {
264
newWebView = CallUIDelegate(m_webView, @selector(webView:createWebViewModalDialogWithRequest:), nil);
266
newWebView = CallUIDelegate(m_webView, @selector(webView:createWebViewWithRequest:), nil);
269
#if USE(PLUGIN_HOST_PROCESS) && ENABLE(NETSCAPE_PLUGIN_API)
271
WebKit::NetscapePluginHostManager::shared().didCreateWindow();
274
return core(newWebView);
277
void WebChromeClient::show()
279
[[m_webView _UIDelegateForwarder] webViewShow:m_webView];
282
bool WebChromeClient::canRunModal()
284
return [[m_webView UIDelegate] respondsToSelector:@selector(webViewRunModal:)];
287
void WebChromeClient::runModal()
289
CallUIDelegate(m_webView, @selector(webViewRunModal:));
292
void WebChromeClient::setToolbarsVisible(bool b)
294
[[m_webView _UIDelegateForwarder] webView:m_webView setToolbarsVisible:b];
297
bool WebChromeClient::toolbarsVisible()
299
return CallUIDelegateReturningBoolean(NO, m_webView, @selector(webViewAreToolbarsVisible:));
302
void WebChromeClient::setStatusbarVisible(bool b)
304
[[m_webView _UIDelegateForwarder] webView:m_webView setStatusBarVisible:b];
307
bool WebChromeClient::statusbarVisible()
309
return CallUIDelegateReturningBoolean(NO, m_webView, @selector(webViewIsStatusBarVisible:));
312
void WebChromeClient::setScrollbarsVisible(bool b)
314
[[[m_webView mainFrame] frameView] setAllowsScrolling:b];
317
bool WebChromeClient::scrollbarsVisible()
319
return [[[m_webView mainFrame] frameView] allowsScrolling];
322
void WebChromeClient::setMenubarVisible(bool)
324
// The menubar is always visible in Mac OS X.
328
bool WebChromeClient::menubarVisible()
330
// The menubar is always visible in Mac OS X.
334
void WebChromeClient::setResizable(bool b)
336
[[m_webView _UIDelegateForwarder] webView:m_webView setResizable:b];
339
inline static NSString *stringForMessageSource(MessageSource source)
342
case HTMLMessageSource:
343
return WebConsoleMessageHTMLMessageSource;
344
case XMLMessageSource:
345
return WebConsoleMessageXMLMessageSource;
346
case JSMessageSource:
347
return WebConsoleMessageJSMessageSource;
348
case NetworkMessageSource:
349
return WebConsoleMessageNetworkMessageSource;
350
case ConsoleAPIMessageSource:
351
return WebConsoleMessageConsoleAPIMessageSource;
352
case OtherMessageSource:
353
return WebConsoleMessageOtherMessageSource;
355
ASSERT_NOT_REACHED();
359
inline static NSString *stringForMessageType(MessageType type)
363
return WebConsoleMessageLogMessageType;
364
case ClearMessageType:
365
return WebConsoleMessageClearMessageType;
367
return WebConsoleMessageDirMessageType;
368
case DirXMLMessageType:
369
return WebConsoleMessageDirXMLMessageType;
370
case TraceMessageType:
371
return WebConsoleMessageTraceMessageType;
372
case StartGroupMessageType:
373
return WebConsoleMessageStartGroupMessageType;
374
case StartGroupCollapsedMessageType:
375
return WebConsoleMessageStartGroupCollapsedMessageType;
376
case EndGroupMessageType:
377
return WebConsoleMessageEndGroupMessageType;
378
case AssertMessageType:
379
return WebConsoleMessageAssertMessageType;
381
ASSERT_NOT_REACHED();
385
inline static NSString *stringForMessageLevel(MessageLevel level)
388
case TipMessageLevel:
389
return WebConsoleMessageTipMessageLevel;
390
case LogMessageLevel:
391
return WebConsoleMessageLogMessageLevel;
392
case WarningMessageLevel:
393
return WebConsoleMessageWarningMessageLevel;
394
case ErrorMessageLevel:
395
return WebConsoleMessageErrorMessageLevel;
396
case DebugMessageLevel:
397
return WebConsoleMessageDebugMessageLevel;
399
ASSERT_NOT_REACHED();
403
void WebChromeClient::addMessageToConsole(MessageSource source, MessageType type, MessageLevel level, const String& message, unsigned int lineNumber, const String& sourceURL)
405
id delegate = [m_webView UIDelegate];
406
BOOL respondsToNewSelector = NO;
408
SEL selector = @selector(webView:addMessageToConsole:withSource:);
409
if ([delegate respondsToSelector:selector])
410
respondsToNewSelector = YES;
412
// The old selector only takes JSMessageSource messages.
413
if (source != JSMessageSource)
415
selector = @selector(webView:addMessageToConsole:);
416
if (![delegate respondsToSelector:selector])
420
NSString *messageSource = stringForMessageSource(source);
421
NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:
422
(NSString *)message, @"message",
423
[NSNumber numberWithUnsignedInt:lineNumber], @"lineNumber",
424
(NSString *)sourceURL, @"sourceURL",
425
messageSource, @"MessageSource",
426
stringForMessageType(type), @"MessageType",
427
stringForMessageLevel(level), @"MessageLevel",
430
if (respondsToNewSelector)
431
CallUIDelegate(m_webView, selector, dictionary, messageSource);
433
CallUIDelegate(m_webView, selector, dictionary);
435
[dictionary release];
438
bool WebChromeClient::canRunBeforeUnloadConfirmPanel()
440
return [[m_webView UIDelegate] respondsToSelector:@selector(webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:)];
443
bool WebChromeClient::runBeforeUnloadConfirmPanel(const String& message, Frame* frame)
445
return CallUIDelegateReturningBoolean(true, m_webView, @selector(webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:), message, kit(frame));
448
void WebChromeClient::closeWindowSoon()
450
// We need to remove the parent WebView from WebViewSets here, before it actually
451
// closes, to make sure that JavaScript code that executes before it closes
452
// can't find it. Otherwise, window.open will select a closed WebView instead of
453
// opening a new one <rdar://problem/3572585>.
455
// We also need to stop the load to prevent further parsing or JavaScript execution
456
// after the window has torn down <rdar://problem/4161660>.
458
// FIXME: This code assumes that the UI delegate will respond to a webViewClose
459
// message by actually closing the WebView. Safari guarantees this behavior, but other apps might not.
460
// This approach is an inherent limitation of not making a close execute immediately
461
// after a call to window.close.
463
[m_webView setGroupName:nil];
464
[m_webView stopLoading:nil];
465
[m_webView performSelector:@selector(_closeWindow) withObject:nil afterDelay:0.0];
468
void WebChromeClient::runJavaScriptAlert(Frame* frame, const String& message)
470
id delegate = [m_webView UIDelegate];
471
SEL selector = @selector(webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:);
472
if ([delegate respondsToSelector:selector]) {
473
CallUIDelegate(m_webView, selector, message, kit(frame));
477
// Call the old version of the delegate method if it is implemented.
478
selector = @selector(webView:runJavaScriptAlertPanelWithMessage:);
479
if ([delegate respondsToSelector:selector]) {
480
CallUIDelegate(m_webView, selector, message);
485
bool WebChromeClient::runJavaScriptConfirm(Frame* frame, const String& message)
487
id delegate = [m_webView UIDelegate];
488
SEL selector = @selector(webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame:);
489
if ([delegate respondsToSelector:selector])
490
return CallUIDelegateReturningBoolean(NO, m_webView, selector, message, kit(frame));
492
// Call the old version of the delegate method if it is implemented.
493
selector = @selector(webView:runJavaScriptConfirmPanelWithMessage:);
494
if ([delegate respondsToSelector:selector])
495
return CallUIDelegateReturningBoolean(NO, m_webView, selector, message);
500
bool WebChromeClient::runJavaScriptPrompt(Frame* frame, const String& prompt, const String& defaultText, String& result)
502
id delegate = [m_webView UIDelegate];
503
SEL selector = @selector(webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:);
504
NSString *defaultString = defaultText;
505
if ([delegate respondsToSelector:selector]) {
506
result = (NSString *)CallUIDelegate(m_webView, selector, prompt, defaultString, kit(frame));
507
return !result.isNull();
510
// Call the old version of the delegate method if it is implemented.
511
selector = @selector(webView:runJavaScriptTextInputPanelWithPrompt:defaultText:);
512
if ([delegate respondsToSelector:selector]) {
513
result = (NSString *)CallUIDelegate(m_webView, selector, prompt, defaultString);
514
return !result.isNull();
517
result = [[WebDefaultUIDelegate sharedUIDelegate] webView:m_webView runJavaScriptTextInputPanelWithPrompt:prompt defaultText:defaultString initiatedByFrame:kit(frame)];
518
return !result.isNull();
521
bool WebChromeClient::shouldInterruptJavaScript()
523
return CallUIDelegateReturningBoolean(NO, m_webView, @selector(webViewShouldInterruptJavaScript:));
526
void WebChromeClient::setStatusbarText(const String& status)
528
// We want the temporaries allocated here to be released even before returning to the
529
// event loop; see <http://bugs.webkit.org/show_bug.cgi?id=9880>.
530
NSAutoreleasePool* localPool = [[NSAutoreleasePool alloc] init];
531
CallUIDelegate(m_webView, @selector(webView:setStatusText:), (NSString *)status);
535
IntRect WebChromeClient::windowResizerRect() const
537
return enclosingIntRect([[m_webView window] _growBoxRect]);
540
void WebChromeClient::invalidateRootView(const IntRect&, bool immediate)
543
[[m_webView window] displayIfNeeded];
544
[[m_webView window] flushWindowIfNeeded];
548
void WebChromeClient::invalidateContentsAndRootView(const IntRect& rect, bool immediate)
552
void WebChromeClient::invalidateContentsForSlowScroll(const IntRect& rect, bool immediate)
554
invalidateContentsAndRootView(rect, immediate);
557
void WebChromeClient::scroll(const IntSize&, const IntRect&, const IntRect&)
561
IntPoint WebChromeClient::screenToRootView(const IntPoint& p) const
563
// FIXME: Implement this.
567
IntRect WebChromeClient::rootViewToScreen(const IntRect& r) const
569
// FIXME: Implement this.
573
PlatformPageClient WebChromeClient::platformPageClient() const
578
void WebChromeClient::contentsSizeChanged(Frame*, const IntSize&) const
582
void WebChromeClient::scrollRectIntoView(const IntRect& r) const
584
// FIXME: This scrolling behavior should be under the control of the embedding client,
585
// perhaps in a delegate method, rather than something WebKit does unconditionally.
586
NSView *coordinateView = [[[m_webView mainFrame] frameView] documentView];
588
for (NSView *view = m_webView; view; view = [view superview]) {
589
if ([view isKindOfClass:[NSClipView class]]) {
590
NSClipView *clipView = (NSClipView *)view;
591
NSView *documentView = [clipView documentView];
592
[documentView scrollRectToVisible:[documentView convertRect:rect fromView:coordinateView]];
597
// End host window methods.
599
bool WebChromeClient::shouldUnavailablePluginMessageBeButton(RenderEmbeddedObject::PluginUnavailabilityReason pluginUnavailabilityReason) const
601
if (pluginUnavailabilityReason == RenderEmbeddedObject::PluginInactive)
604
if (pluginUnavailabilityReason == RenderEmbeddedObject::PluginMissing)
605
return [[m_webView UIDelegate] respondsToSelector:@selector(webView:didPressMissingPluginButton:)];
610
void WebChromeClient::unavailablePluginButtonClicked(Element* element, RenderEmbeddedObject::PluginUnavailabilityReason pluginUnavailabilityReason) const
612
ASSERT(element->hasTagName(objectTag) || element->hasTagName(embedTag) || element->hasTagName(appletTag));
614
if (pluginUnavailabilityReason == RenderEmbeddedObject::PluginInactive) {
615
HTMLPlugInImageElement* pluginElement = static_cast<HTMLPlugInImageElement*>(element);
617
WebBasePluginPackage *pluginPackage = nil;
618
if (!pluginElement->serviceType().isEmpty())
619
pluginPackage = [m_webView _pluginForMIMEType:pluginElement->serviceType()];
621
NSURL *url = pluginElement->document()->completeURL(pluginElement->url());
622
NSString *extension = [[url path] pathExtension];
623
if (!pluginPackage && [extension length])
624
pluginPackage = [m_webView _pluginForExtension:extension];
626
if (pluginPackage && [pluginPackage bundleIdentifier] == "com.oracle.java.JavaAppletPlugin") {
627
// Reactivate the plug-in and reload the page so the plug-in will be instantiated correctly.
628
WKActivateJavaPlugIn();
629
[m_webView reload:nil];
635
ASSERT(pluginUnavailabilityReason == RenderEmbeddedObject::PluginMissing || pluginUnavailabilityReason == RenderEmbeddedObject::PluginInactive);
636
CallUIDelegate(m_webView, @selector(webView:didPressMissingPluginButton:), kit(element));
639
void WebChromeClient::mouseDidMoveOverElement(const HitTestResult& result, unsigned modifierFlags)
641
WebElementDictionary *element = [[WebElementDictionary alloc] initWithHitTestResult:result];
642
[m_webView _mouseDidMoveOverElement:element modifierFlags:modifierFlags];
646
void WebChromeClient::setToolTip(const String& toolTip, TextDirection)
648
NSView<WebDocumentView> *documentView = [[[m_webView _selectedOrMainFrame] frameView] documentView];
649
if ([documentView isKindOfClass:[WebHTMLView class]])
650
[(WebHTMLView *)documentView _setToolTip:toolTip];
653
void WebChromeClient::print(Frame* frame)
655
WebFrame *webFrame = kit(frame);
656
if ([[m_webView UIDelegate] respondsToSelector:@selector(webView:printFrame:)])
657
CallUIDelegate(m_webView, @selector(webView:printFrame:), webFrame);
659
CallUIDelegate(m_webView, @selector(webView:printFrameView:), [webFrame frameView]);
662
#if ENABLE(SQL_DATABASE)
664
void WebChromeClient::exceededDatabaseQuota(Frame* frame, const String& databaseName)
666
BEGIN_BLOCK_OBJC_EXCEPTIONS;
668
WebSecurityOrigin *webOrigin = [[WebSecurityOrigin alloc] _initWithWebCoreSecurityOrigin:frame->document()->securityOrigin()];
669
// FIXME: remove this workaround once shipping Safari has the necessary delegate implemented.
670
if (WKAppVersionCheckLessThan(@"com.apple.Safari", -1, 3.1)) {
671
const unsigned long long defaultQuota = 5 * 1024 * 1024; // 5 megabytes should hopefully be enough to test storage support.
672
[[webOrigin databaseQuotaManager] setQuota:defaultQuota];
674
CallUIDelegate(m_webView, @selector(webView:frame:exceededDatabaseQuotaForSecurityOrigin:database:), kit(frame), webOrigin, (NSString *)databaseName);
677
END_BLOCK_OBJC_EXCEPTIONS;
682
void WebChromeClient::reachedMaxAppCacheSize(int64_t spaceNeeded)
684
// FIXME: Free some space.
687
void WebChromeClient::reachedApplicationCacheOriginQuota(SecurityOrigin* origin, int64_t totalSpaceNeeded)
689
BEGIN_BLOCK_OBJC_EXCEPTIONS;
691
WebSecurityOrigin *webOrigin = [[WebSecurityOrigin alloc] _initWithWebCoreSecurityOrigin:origin];
692
CallUIDelegate(m_webView, @selector(webView:exceededApplicationCacheOriginQuotaForSecurityOrigin:totalSpaceNeeded:), webOrigin, static_cast<NSUInteger>(totalSpaceNeeded));
695
END_BLOCK_OBJC_EXCEPTIONS;
698
void WebChromeClient::populateVisitedLinks()
700
if ([m_webView historyDelegate]) {
701
WebHistoryDelegateImplementationCache* implementations = WebViewGetHistoryDelegateImplementations(m_webView);
703
if (implementations->populateVisitedLinksFunc)
704
CallHistoryDelegate(implementations->populateVisitedLinksFunc, m_webView, @selector(populateVisitedLinksForWebView:));
709
BEGIN_BLOCK_OBJC_EXCEPTIONS;
710
[[WebHistory optionalSharedHistory] _addVisitedLinksToPageGroup:[m_webView page]->group()];
711
END_BLOCK_OBJC_EXCEPTIONS;
714
#if ENABLE(DASHBOARD_SUPPORT)
716
void WebChromeClient::annotatedRegionsChanged()
718
BEGIN_BLOCK_OBJC_EXCEPTIONS;
719
CallUIDelegate(m_webView, @selector(webView:dashboardRegionsChanged:), [m_webView _dashboardRegions]);
720
END_BLOCK_OBJC_EXCEPTIONS;
725
FloatRect WebChromeClient::customHighlightRect(Node* node, const AtomicString& type, const FloatRect& lineRect)
727
BEGIN_BLOCK_OBJC_EXCEPTIONS;
729
NSView *documentView = [[kit(node->document()->frame()) frameView] documentView];
730
if (![documentView isKindOfClass:[WebHTMLView class]])
733
WebHTMLView *webHTMLView = (WebHTMLView *)documentView;
734
id<WebHTMLHighlighter> highlighter = [webHTMLView _highlighterForType:type];
735
return [highlighter highlightRectForLine:lineRect representedNode:kit(node)];
737
END_BLOCK_OBJC_EXCEPTIONS;
742
void WebChromeClient::paintCustomHighlight(Node* node, const AtomicString& type, const FloatRect& boxRect, const FloatRect& lineRect,
743
bool behindText, bool entireLine)
745
BEGIN_BLOCK_OBJC_EXCEPTIONS;
747
NSView *documentView = [[kit(node->document()->frame()) frameView] documentView];
748
if (![documentView isKindOfClass:[WebHTMLView class]])
751
WebHTMLView *webHTMLView = (WebHTMLView *)documentView;
752
id<WebHTMLHighlighter> highlighter = [webHTMLView _highlighterForType:type];
753
[highlighter paintHighlightForBox:boxRect onLine:lineRect behindText:behindText entireLine:entireLine representedNode:kit(node)];
755
END_BLOCK_OBJC_EXCEPTIONS;
758
void WebChromeClient::runOpenPanel(Frame*, PassRefPtr<FileChooser> chooser)
760
BEGIN_BLOCK_OBJC_EXCEPTIONS;
761
BOOL allowMultipleFiles = chooser->settings().allowsMultipleFiles;
762
WebOpenPanelResultListener *listener = [[WebOpenPanelResultListener alloc] initWithChooser:chooser];
763
id delegate = [m_webView UIDelegate];
764
if ([delegate respondsToSelector:@selector(webView:runOpenPanelForFileButtonWithResultListener:allowMultipleFiles:)])
765
CallUIDelegate(m_webView, @selector(webView:runOpenPanelForFileButtonWithResultListener:allowMultipleFiles:), listener, allowMultipleFiles);
766
else if ([delegate respondsToSelector:@selector(webView:runOpenPanelForFileButtonWithResultListener:)])
767
CallUIDelegate(m_webView, @selector(webView:runOpenPanelForFileButtonWithResultListener:), listener);
771
END_BLOCK_OBJC_EXCEPTIONS;
774
void WebChromeClient::loadIconForFiles(const Vector<String>& filenames, FileIconLoader* iconLoader)
776
iconLoader->notifyFinished(Icon::createIconForFiles(filenames));
779
void WebChromeClient::setCursor(const WebCore::Cursor& cursor)
781
if ([NSApp _cursorRectCursor])
784
NSCursor *platformCursor = cursor.platformCursor();
785
if ([NSCursor currentCursor] == platformCursor)
787
[platformCursor set];
790
void WebChromeClient::setCursorHiddenUntilMouseMoves(bool hiddenUntilMouseMoves)
792
[NSCursor setHiddenUntilMouseMoves:hiddenUntilMouseMoves];
795
KeyboardUIMode WebChromeClient::keyboardUIMode()
797
BEGIN_BLOCK_OBJC_EXCEPTIONS;
798
return [m_webView _keyboardUIMode];
799
END_BLOCK_OBJC_EXCEPTIONS;
800
return KeyboardAccessDefault;
803
NSResponder *WebChromeClient::firstResponder()
805
BEGIN_BLOCK_OBJC_EXCEPTIONS;
806
return [[m_webView _UIDelegateForwarder] webViewFirstResponder:m_webView];
807
END_BLOCK_OBJC_EXCEPTIONS;
811
void WebChromeClient::makeFirstResponder(NSResponder *responder)
813
BEGIN_BLOCK_OBJC_EXCEPTIONS;
814
[m_webView _pushPerformingProgrammaticFocus];
815
[[m_webView _UIDelegateForwarder] webView:m_webView makeFirstResponder:responder];
816
[m_webView _popPerformingProgrammaticFocus];
817
END_BLOCK_OBJC_EXCEPTIONS;
820
void WebChromeClient::willPopUpMenu(NSMenu *menu)
822
BEGIN_BLOCK_OBJC_EXCEPTIONS;
823
CallUIDelegate(m_webView, @selector(webView:willPopupMenu:), menu);
824
END_BLOCK_OBJC_EXCEPTIONS;
827
bool WebChromeClient::shouldReplaceWithGeneratedFileForUpload(const String& path, String& generatedFilename)
830
if (![[m_webView _UIDelegateForwarder] webView:m_webView shouldReplaceUploadFile:path usingGeneratedFilename:&filename])
832
generatedFilename = filename;
836
String WebChromeClient::generateReplacementFile(const String& path)
838
return [[m_webView _UIDelegateForwarder] webView:m_webView generateReplacementFile:path];
841
void WebChromeClient::elementDidFocus(const WebCore::Node* node)
843
CallUIDelegate(m_webView, @selector(webView:formDidFocusNode:), kit(const_cast<WebCore::Node*>(node)));
846
void WebChromeClient::elementDidBlur(const WebCore::Node* node)
848
CallUIDelegate(m_webView, @selector(webView:formDidBlurNode:), kit(const_cast<WebCore::Node*>(node)));
851
bool WebChromeClient::selectItemWritingDirectionIsNatural()
853
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
860
bool WebChromeClient::selectItemAlignmentFollowsMenuWritingDirection()
862
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
869
bool WebChromeClient::hasOpenedPopup() const
875
PassRefPtr<WebCore::PopupMenu> WebChromeClient::createPopupMenu(WebCore::PopupMenuClient* client) const
877
return adoptRef(new PopupMenuMac(client));
880
PassRefPtr<WebCore::SearchPopupMenu> WebChromeClient::createSearchPopupMenu(WebCore::PopupMenuClient* client) const
882
return adoptRef(new SearchPopupMenuMac(client));
885
#if USE(ACCELERATED_COMPOSITING)
887
void WebChromeClient::attachRootGraphicsLayer(Frame* frame, GraphicsLayer* graphicsLayer)
889
BEGIN_BLOCK_OBJC_EXCEPTIONS;
891
NSView *documentView = [[kit(frame) frameView] documentView];
892
if (![documentView isKindOfClass:[WebHTMLView class]]) {
893
// We should never be attaching when we don't have a WebHTMLView.
894
ASSERT(!graphicsLayer);
898
WebHTMLView *webHTMLView = (WebHTMLView *)documentView;
900
[webHTMLView attachRootLayer:graphicsLayer->platformLayer()];
902
[webHTMLView detachRootLayer];
903
END_BLOCK_OBJC_EXCEPTIONS;
906
void WebChromeClient::setNeedsOneShotDrawingSynchronization()
908
BEGIN_BLOCK_OBJC_EXCEPTIONS;
909
[m_webView _setNeedsOneShotDrawingSynchronization:YES];
910
END_BLOCK_OBJC_EXCEPTIONS;
913
void WebChromeClient::scheduleCompositingLayerFlush()
915
BEGIN_BLOCK_OBJC_EXCEPTIONS;
916
[m_webView _scheduleCompositingLayerFlush];
917
END_BLOCK_OBJC_EXCEPTIONS;
924
bool WebChromeClient::supportsFullscreenForNode(const Node* node)
926
return node->hasTagName(WebCore::HTMLNames::videoTag);
929
void WebChromeClient::enterFullscreenForNode(Node* node)
931
BEGIN_BLOCK_OBJC_EXCEPTIONS;
932
[m_webView _enterFullscreenForNode:node];
933
END_BLOCK_OBJC_EXCEPTIONS;
936
void WebChromeClient::exitFullscreenForNode(Node*)
938
BEGIN_BLOCK_OBJC_EXCEPTIONS;
939
[m_webView _exitFullscreen];
940
END_BLOCK_OBJC_EXCEPTIONS;
945
#if ENABLE(FULLSCREEN_API)
947
bool WebChromeClient::supportsFullScreenForElement(const Element* element, bool withKeyboard)
949
SEL selector = @selector(webView:supportsFullScreenForElement:withKeyboard:);
950
if ([[m_webView UIDelegate] respondsToSelector:selector])
951
return CallUIDelegateReturningBoolean(false, m_webView, selector, kit(const_cast<WebCore::Element*>(element)), withKeyboard);
952
return [m_webView _supportsFullScreenForElement:const_cast<WebCore::Element*>(element) withKeyboard:withKeyboard];
955
void WebChromeClient::enterFullScreenForElement(Element* element)
957
SEL selector = @selector(webView:enterFullScreenForElement:listener:);
958
if ([[m_webView UIDelegate] respondsToSelector:selector]) {
959
WebKitFullScreenListener* listener = [[WebKitFullScreenListener alloc] initWithElement:element];
960
CallUIDelegate(m_webView, selector, kit(element), listener);
963
[m_webView _enterFullScreenForElement:element];
966
void WebChromeClient::exitFullScreenForElement(Element* element)
968
SEL selector = @selector(webView:exitFullScreenForElement:listener:);
969
if ([[m_webView UIDelegate] respondsToSelector:selector]) {
970
WebKitFullScreenListener* listener = [[WebKitFullScreenListener alloc] initWithElement:element];
971
CallUIDelegate(m_webView, selector, kit(element), listener);
974
[m_webView _exitFullScreenForElement:element];
977
void WebChromeClient::fullScreenRendererChanged(RenderBox* renderer)
979
SEL selector = @selector(webView:fullScreenRendererChanged:);
980
if ([[m_webView UIDelegate] respondsToSelector:selector])
981
CallUIDelegate(m_webView, selector, (id)renderer);