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 "DOMNodeInternal.h"
33 #import "WebDefaultUIDelegate.h"
34 #import "WebDelegateImplementationCaching.h"
35 #import "WebElementDictionary.h"
36 #import "WebFrameInternal.h"
37 #import "WebFrameView.h"
38 #import "WebHTMLViewInternal.h"
39 #import "WebHistoryInternal.h"
40 #import "WebKitPrefix.h"
41 #import "WebKitSystemInterface.h"
42 #import "WebNSURLRequestExtras.h"
44 #import "WebQuotaManager.h"
45 #import "WebSecurityOriginInternal.h"
46 #import "WebUIDelegatePrivate.h"
48 #import "WebViewInternal.h"
49 #import <Foundation/Foundation.h>
50 #import <WebCore/BlockExceptions.h>
51 #import <WebCore/Console.h>
52 #import <WebCore/Cursor.h>
53 #import <WebCore/Element.h>
54 #import <WebCore/FileChooser.h>
55 #import <WebCore/FloatRect.h>
56 #import <WebCore/Frame.h>
57 #import <WebCore/FrameLoadRequest.h>
58 #import <WebCore/Geolocation.h>
59 #import <WebCore/HTMLNames.h>
60 #import <WebCore/HitTestResult.h>
61 #import <WebCore/Icon.h>
62 #import <WebCore/IntRect.h>
63 #import <WebCore/NavigationAction.h>
64 #import <WebCore/Page.h>
65 #import <WebCore/PlatformScreen.h>
66 #import <WebCore/PlatformString.h>
67 #import <WebCore/PopupMenuMac.h>
68 #import <WebCore/ResourceRequest.h>
69 #import <WebCore/SearchPopupMenuMac.h>
70 #import <WebCore/Widget.h>
71 #import <WebCore/WindowFeatures.h>
72 #import <wtf/PassRefPtr.h>
73 #import <wtf/Vector.h>
75 #if USE(ACCELERATED_COMPOSITING)
76 #import <WebCore/GraphicsLayer.h>
79 #if USE(PLUGIN_HOST_PROCESS) && ENABLE(NETSCAPE_PLUGIN_API)
80 #import "NetscapePluginHostManager.h"
83 @interface NSView (WebNSViewDetails)
84 - (NSView *)_findLastViewInKeyViewLoop;
87 // For compatibility with old SPI.
88 @interface NSView (WebOldWebKitPlugInDetails)
89 - (void)setIsSelected:(BOOL)isSelected;
92 @interface NSWindow (AppKitSecretsIKnowAbout)
93 - (NSRect)_growBoxRect;
96 using namespace WebCore;
98 @interface WebOpenPanelResultListener : NSObject <WebOpenPanelResultListener>
100 FileChooser* _chooser;
102 - (id)initWithChooser:(PassRefPtr<FileChooser>)chooser;
105 @interface WebGeolocationPolicyListener : NSObject <WebGeolocationPolicyListener>
107 RefPtr<Geolocation> _geolocation;
109 - (id)initWithGeolocation:(Geolocation*)geolocation;
112 #if ENABLE(FULLSCREEN_API)
114 @interface WebKitFullScreenListener : NSObject <WebKitFullScreenListener>
116 RefPtr<Element> _element;
119 - (id)initWithElement:(Element*)element;
124 WebChromeClient::WebChromeClient(WebView *webView)
129 void WebChromeClient::chromeDestroyed()
134 // These functions scale between window and WebView coordinates because JavaScript/DOM operations
135 // assume that the WebView and the window share the same coordinate system.
137 void WebChromeClient::setWindowRect(const FloatRect& rect)
139 NSRect windowRect = toDeviceSpace(rect, [m_webView window]);
140 [[m_webView _UIDelegateForwarder] webView:m_webView setFrame:windowRect];
143 FloatRect WebChromeClient::windowRect()
145 NSRect windowRect = [[m_webView _UIDelegateForwarder] webViewFrame:m_webView];
146 return toUserSpace(windowRect, [m_webView window]);
149 // FIXME: We need to add API for setting and getting this.
150 FloatRect WebChromeClient::pageRect()
152 return [m_webView frame];
155 float WebChromeClient::scaleFactor()
157 if (NSWindow *window = [m_webView window])
158 return [window userSpaceScaleFactor];
159 return [[NSScreen mainScreen] userSpaceScaleFactor];
162 void WebChromeClient::focus()
164 [[m_webView _UIDelegateForwarder] webViewFocus:m_webView];
167 void WebChromeClient::unfocus()
169 [[m_webView _UIDelegateForwarder] webViewUnfocus:m_webView];
172 bool WebChromeClient::canTakeFocus(FocusDirection)
174 // There's unfortunately no way to determine if we will become first responder again
175 // once we give it up, so we just have to guess that we won't.
179 void WebChromeClient::takeFocus(FocusDirection direction)
181 if (direction == FocusDirectionForward) {
182 // Since we're trying to move focus out of m_webView, and because
183 // m_webView may contain subviews within it, we ask it for the next key
184 // view of the last view in its key view loop. This makes m_webView
185 // behave as if it had no subviews, which is the behavior we want.
186 NSView *lastView = [m_webView _findLastViewInKeyViewLoop];
187 // avoid triggering assertions if the WebView is the only thing in the key loop
188 if ([m_webView _becomingFirstResponderFromOutside] && m_webView == [lastView nextValidKeyView])
190 [[m_webView window] selectKeyViewFollowingView:lastView];
192 // avoid triggering assertions if the WebView is the only thing in the key loop
193 if ([m_webView _becomingFirstResponderFromOutside] && m_webView == [m_webView previousValidKeyView])
195 [[m_webView window] selectKeyViewPrecedingView:m_webView];
199 void WebChromeClient::focusedNodeChanged(Node*)
203 Page* WebChromeClient::createWindow(Frame* frame, const FrameLoadRequest& request, const WindowFeatures& features, const NavigationAction&)
205 NSURLRequest *URLRequest = nil;
206 if (!request.isEmpty())
207 URLRequest = request.resourceRequest().nsURLRequest();
209 id delegate = [m_webView UIDelegate];
212 if ([delegate respondsToSelector:@selector(webView:createWebViewWithRequest:windowFeatures:)]) {
213 NSNumber *x = features.xSet ? [[NSNumber alloc] initWithFloat:features.x] : nil;
214 NSNumber *y = features.ySet ? [[NSNumber alloc] initWithFloat:features.y] : nil;
215 NSNumber *width = features.widthSet ? [[NSNumber alloc] initWithFloat:features.width] : nil;
216 NSNumber *height = features.heightSet ? [[NSNumber alloc] initWithFloat:features.height] : nil;
217 NSNumber *menuBarVisible = [[NSNumber alloc] initWithBool:features.menuBarVisible];
218 NSNumber *statusBarVisible = [[NSNumber alloc] initWithBool:features.statusBarVisible];
219 NSNumber *toolBarVisible = [[NSNumber alloc] initWithBool:features.toolBarVisible];
220 NSNumber *scrollbarsVisible = [[NSNumber alloc] initWithBool:features.scrollbarsVisible];
221 NSNumber *resizable = [[NSNumber alloc] initWithBool:features.resizable];
222 NSNumber *fullscreen = [[NSNumber alloc] initWithBool:features.fullscreen];
223 NSNumber *dialog = [[NSNumber alloc] initWithBool:features.dialog];
225 NSMutableDictionary *dictFeatures = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
226 menuBarVisible, @"menuBarVisible",
227 statusBarVisible, @"statusBarVisible",
228 toolBarVisible, @"toolBarVisible",
229 scrollbarsVisible, @"scrollbarsVisible",
230 resizable, @"resizable",
231 fullscreen, @"fullscreen",
236 [dictFeatures setObject:x forKey:@"x"];
238 [dictFeatures setObject:y forKey:@"y"];
240 [dictFeatures setObject:width forKey:@"width"];
242 [dictFeatures setObject:height forKey:@"height"];
244 newWebView = CallUIDelegate(m_webView, @selector(webView:createWebViewWithRequest:windowFeatures:), URLRequest, dictFeatures);
246 [dictFeatures release];
251 [menuBarVisible release];
252 [statusBarVisible release];
253 [toolBarVisible release];
254 [scrollbarsVisible release];
256 [fullscreen release];
258 } else if (features.dialog && [delegate respondsToSelector:@selector(webView:createWebViewModalDialogWithRequest:)]) {
259 newWebView = CallUIDelegate(m_webView, @selector(webView:createWebViewModalDialogWithRequest:), URLRequest);
261 newWebView = CallUIDelegate(m_webView, @selector(webView:createWebViewWithRequest:), URLRequest);
264 #if USE(PLUGIN_HOST_PROCESS) && ENABLE(NETSCAPE_PLUGIN_API)
266 WebKit::NetscapePluginHostManager::shared().didCreateWindow();
269 return core(newWebView);
272 void WebChromeClient::show()
274 [[m_webView _UIDelegateForwarder] webViewShow:m_webView];
277 bool WebChromeClient::canRunModal()
279 return [[m_webView UIDelegate] respondsToSelector:@selector(webViewRunModal:)];
282 void WebChromeClient::runModal()
284 CallUIDelegate(m_webView, @selector(webViewRunModal:));
287 void WebChromeClient::setToolbarsVisible(bool b)
289 [[m_webView _UIDelegateForwarder] webView:m_webView setToolbarsVisible:b];
292 bool WebChromeClient::toolbarsVisible()
294 return CallUIDelegateReturningBoolean(NO, m_webView, @selector(webViewAreToolbarsVisible:));
297 void WebChromeClient::setStatusbarVisible(bool b)
299 [[m_webView _UIDelegateForwarder] webView:m_webView setStatusBarVisible:b];
302 bool WebChromeClient::statusbarVisible()
304 return CallUIDelegateReturningBoolean(NO, m_webView, @selector(webViewIsStatusBarVisible:));
307 void WebChromeClient::setScrollbarsVisible(bool b)
309 [[[m_webView mainFrame] frameView] setAllowsScrolling:b];
312 bool WebChromeClient::scrollbarsVisible()
314 return [[[m_webView mainFrame] frameView] allowsScrolling];
317 void WebChromeClient::setMenubarVisible(bool)
319 // The menubar is always visible in Mac OS X.
323 bool WebChromeClient::menubarVisible()
325 // The menubar is always visible in Mac OS X.
329 void WebChromeClient::setResizable(bool b)
331 [[m_webView _UIDelegateForwarder] webView:m_webView setResizable:b];
334 void WebChromeClient::addMessageToConsole(MessageSource source, MessageType type, MessageLevel level, const String& message, unsigned int lineNumber, const String& sourceURL)
336 id delegate = [m_webView UIDelegate];
337 SEL selector = @selector(webView:addMessageToConsole:);
338 if (![delegate respondsToSelector:selector])
341 NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:
342 (NSString *)message, @"message", [NSNumber numberWithUnsignedInt:lineNumber], @"lineNumber",
343 (NSString *)sourceURL, @"sourceURL", NULL];
345 CallUIDelegate(m_webView, selector, dictionary);
347 [dictionary release];
350 bool WebChromeClient::canRunBeforeUnloadConfirmPanel()
352 return [[m_webView UIDelegate] respondsToSelector:@selector(webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:)];
355 bool WebChromeClient::runBeforeUnloadConfirmPanel(const String& message, Frame* frame)
357 return CallUIDelegateReturningBoolean(true, m_webView, @selector(webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:), message, kit(frame));
360 void WebChromeClient::closeWindowSoon()
362 // We need to remove the parent WebView from WebViewSets here, before it actually
363 // closes, to make sure that JavaScript code that executes before it closes
364 // can't find it. Otherwise, window.open will select a closed WebView instead of
365 // opening a new one <rdar://problem/3572585>.
367 // We also need to stop the load to prevent further parsing or JavaScript execution
368 // after the window has torn down <rdar://problem/4161660>.
370 // FIXME: This code assumes that the UI delegate will respond to a webViewClose
371 // message by actually closing the WebView. Safari guarantees this behavior, but other apps might not.
372 // This approach is an inherent limitation of not making a close execute immediately
373 // after a call to window.close.
375 [m_webView setGroupName:nil];
376 [m_webView stopLoading:nil];
377 [m_webView performSelector:@selector(_closeWindow) withObject:nil afterDelay:0.0];
380 void WebChromeClient::runJavaScriptAlert(Frame* frame, const String& message)
382 id delegate = [m_webView UIDelegate];
383 SEL selector = @selector(webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:);
384 if ([delegate respondsToSelector:selector]) {
385 CallUIDelegate(m_webView, selector, message, kit(frame));
389 // Call the old version of the delegate method if it is implemented.
390 selector = @selector(webView:runJavaScriptAlertPanelWithMessage:);
391 if ([delegate respondsToSelector:selector]) {
392 CallUIDelegate(m_webView, selector, message);
397 bool WebChromeClient::runJavaScriptConfirm(Frame* frame, const String& message)
399 id delegate = [m_webView UIDelegate];
400 SEL selector = @selector(webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame:);
401 if ([delegate respondsToSelector:selector])
402 return CallUIDelegateReturningBoolean(NO, m_webView, selector, message, kit(frame));
404 // Call the old version of the delegate method if it is implemented.
405 selector = @selector(webView:runJavaScriptConfirmPanelWithMessage:);
406 if ([delegate respondsToSelector:selector])
407 return CallUIDelegateReturningBoolean(NO, m_webView, selector, message);
412 bool WebChromeClient::runJavaScriptPrompt(Frame* frame, const String& prompt, const String& defaultText, String& result)
414 id delegate = [m_webView UIDelegate];
415 SEL selector = @selector(webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:);
416 if ([delegate respondsToSelector:selector]) {
417 result = (NSString *)CallUIDelegate(m_webView, selector, prompt, defaultText, kit(frame));
418 return !result.isNull();
421 // Call the old version of the delegate method if it is implemented.
422 selector = @selector(webView:runJavaScriptTextInputPanelWithPrompt:defaultText:);
423 if ([delegate respondsToSelector:selector]) {
424 result = (NSString *)CallUIDelegate(m_webView, selector, prompt, defaultText);
425 return !result.isNull();
428 result = [[WebDefaultUIDelegate sharedUIDelegate] webView:m_webView runJavaScriptTextInputPanelWithPrompt:prompt defaultText:defaultText initiatedByFrame:kit(frame)];
429 return !result.isNull();
432 bool WebChromeClient::shouldInterruptJavaScript()
434 return CallUIDelegate(m_webView, @selector(webViewShouldInterruptJavaScript:));
437 void WebChromeClient::setStatusbarText(const String& status)
439 // We want the temporaries allocated here to be released even before returning to the
440 // event loop; see <http://bugs.webkit.org/show_bug.cgi?id=9880>.
441 NSAutoreleasePool* localPool = [[NSAutoreleasePool alloc] init];
442 CallUIDelegate(m_webView, @selector(webView:setStatusText:), (NSString *)status);
446 bool WebChromeClient::tabsToLinks() const
448 return [[m_webView preferences] tabsToLinks];
451 IntRect WebChromeClient::windowResizerRect() const
453 NSRect rect = [[m_webView window] _growBoxRect];
454 if ([m_webView _usesDocumentViews])
455 return enclosingIntRect(rect);
456 return enclosingIntRect([m_webView convertRect:rect fromView:nil]);
459 void WebChromeClient::invalidateWindow(const IntRect&, bool immediate)
462 [[m_webView window] displayIfNeeded];
463 [[m_webView window] flushWindowIfNeeded];
467 void WebChromeClient::invalidateContentsAndWindow(const IntRect& rect, bool immediate)
469 if ([m_webView _usesDocumentViews])
472 [m_webView setNeedsDisplayInRect:rect];
475 [[m_webView window] displayIfNeeded];
476 [[m_webView window] flushWindowIfNeeded];
480 void WebChromeClient::invalidateContentsForSlowScroll(const IntRect& rect, bool immediate)
482 invalidateContentsAndWindow(rect, immediate);
485 void WebChromeClient::scroll(const IntSize&, const IntRect&, const IntRect&)
489 IntPoint WebChromeClient::screenToWindow(const IntPoint& p) const
491 if ([m_webView _usesDocumentViews])
493 NSPoint windowCoord = [[m_webView window] convertScreenToBase:p];
494 return IntPoint([m_webView convertPoint:windowCoord fromView:nil]);
497 IntRect WebChromeClient::windowToScreen(const IntRect& r) const
499 if ([m_webView _usesDocumentViews])
502 tempRect = [m_webView convertRect:tempRect toView:nil];
503 tempRect.origin = [[m_webView window] convertBaseToScreen:tempRect.origin];
504 return enclosingIntRect(tempRect);
507 PlatformPageClient WebChromeClient::platformPageClient() const
509 if ([m_webView _usesDocumentViews])
514 void WebChromeClient::contentsSizeChanged(Frame*, const IntSize&) const
518 void WebChromeClient::scrollRectIntoView(const IntRect& r, const ScrollView*) const
520 // FIXME: This scrolling behavior should be under the control of the embedding client,
521 // perhaps in a delegate method, rather than something WebKit does unconditionally.
522 NSView *coordinateView = [m_webView _usesDocumentViews]
523 ? [[[m_webView mainFrame] frameView] documentView] : m_webView;
525 for (NSView *view = m_webView; view; view = [view superview]) {
526 if ([view isKindOfClass:[NSClipView class]]) {
527 NSClipView *clipView = (NSClipView *)view;
528 NSView *documentView = [clipView documentView];
529 [documentView scrollRectToVisible:[documentView convertRect:rect fromView:coordinateView]];
534 // End host window methods.
536 bool WebChromeClient::shouldMissingPluginMessageBeButton() const
538 return [[m_webView UIDelegate] respondsToSelector:@selector(webView:didPressMissingPluginButton:)];
541 void WebChromeClient::missingPluginButtonClicked(Element* element) const
543 CallUIDelegate(m_webView, @selector(webView:didPressMissingPluginButton:), kit(element));
546 void WebChromeClient::mouseDidMoveOverElement(const HitTestResult& result, unsigned modifierFlags)
548 WebElementDictionary *element = [[WebElementDictionary alloc] initWithHitTestResult:result];
549 [m_webView _mouseDidMoveOverElement:element modifierFlags:modifierFlags];
553 void WebChromeClient::setToolTip(const String& toolTip, TextDirection)
555 [m_webView _setToolTip:toolTip];
558 void WebChromeClient::print(Frame* frame)
560 WebFrame *webFrame = kit(frame);
561 if ([[m_webView UIDelegate] respondsToSelector:@selector(webView:printFrame:)])
562 CallUIDelegate(m_webView, @selector(webView:printFrame:), webFrame);
563 else if ([m_webView _usesDocumentViews])
564 CallUIDelegate(m_webView, @selector(webView:printFrameView:), [webFrame frameView]);
569 void WebChromeClient::exceededDatabaseQuota(Frame* frame, const String& databaseName)
571 BEGIN_BLOCK_OBJC_EXCEPTIONS;
573 WebSecurityOrigin *webOrigin = [[WebSecurityOrigin alloc] _initWithWebCoreSecurityOrigin:frame->document()->securityOrigin()];
574 // FIXME: remove this workaround once shipping Safari has the necessary delegate implemented.
575 if (WKAppVersionCheckLessThan(@"com.apple.Safari", -1, 3.1)) {
576 const unsigned long long defaultQuota = 5 * 1024 * 1024; // 5 megabytes should hopefully be enough to test storage support.
577 [[webOrigin databaseQuotaManager] setQuota:defaultQuota];
579 CallUIDelegate(m_webView, @selector(webView:frame:exceededDatabaseQuotaForSecurityOrigin:database:), kit(frame), webOrigin, (NSString *)databaseName);
582 END_BLOCK_OBJC_EXCEPTIONS;
587 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
589 void WebChromeClient::reachedMaxAppCacheSize(int64_t spaceNeeded)
591 // FIXME: Free some space.
594 void WebChromeClient::reachedApplicationCacheOriginQuota(SecurityOrigin* origin)
596 BEGIN_BLOCK_OBJC_EXCEPTIONS;
598 WebSecurityOrigin *webOrigin = [[WebSecurityOrigin alloc] _initWithWebCoreSecurityOrigin:origin];
599 CallUIDelegate(m_webView, @selector(webView:exceededApplicationCacheOriginQuotaForSecurityOrigin:), webOrigin);
602 END_BLOCK_OBJC_EXCEPTIONS;
607 void WebChromeClient::populateVisitedLinks()
609 if ([m_webView historyDelegate]) {
610 WebHistoryDelegateImplementationCache* implementations = WebViewGetHistoryDelegateImplementations(m_webView);
612 if (implementations->populateVisitedLinksFunc)
613 CallHistoryDelegate(implementations->populateVisitedLinksFunc, m_webView, @selector(populateVisitedLinksForWebView:));
618 BEGIN_BLOCK_OBJC_EXCEPTIONS;
619 [[WebHistory optionalSharedHistory] _addVisitedLinksToPageGroup:[m_webView page]->group()];
620 END_BLOCK_OBJC_EXCEPTIONS;
623 #if ENABLE(DASHBOARD_SUPPORT)
625 void WebChromeClient::dashboardRegionsChanged()
627 BEGIN_BLOCK_OBJC_EXCEPTIONS;
628 CallUIDelegate(m_webView, @selector(webView:dashboardRegionsChanged:), [m_webView _dashboardRegions]);
629 END_BLOCK_OBJC_EXCEPTIONS;
634 FloatRect WebChromeClient::customHighlightRect(Node* node, const AtomicString& type, const FloatRect& lineRect)
636 BEGIN_BLOCK_OBJC_EXCEPTIONS;
638 NSView *documentView = [[kit(node->document()->frame()) frameView] documentView];
639 if (![documentView isKindOfClass:[WebHTMLView class]])
642 WebHTMLView *webHTMLView = (WebHTMLView *)documentView;
643 id<WebHTMLHighlighter> highlighter = [webHTMLView _highlighterForType:type];
644 return [highlighter highlightRectForLine:lineRect representedNode:kit(node)];
646 END_BLOCK_OBJC_EXCEPTIONS;
651 void WebChromeClient::paintCustomHighlight(Node* node, const AtomicString& type, const FloatRect& boxRect, const FloatRect& lineRect,
652 bool behindText, bool entireLine)
654 BEGIN_BLOCK_OBJC_EXCEPTIONS;
656 NSView *documentView = [[kit(node->document()->frame()) frameView] documentView];
657 if (![documentView isKindOfClass:[WebHTMLView class]])
660 WebHTMLView *webHTMLView = (WebHTMLView *)documentView;
661 id<WebHTMLHighlighter> highlighter = [webHTMLView _highlighterForType:type];
662 [highlighter paintHighlightForBox:boxRect onLine:lineRect behindText:behindText entireLine:entireLine representedNode:kit(node)];
664 END_BLOCK_OBJC_EXCEPTIONS;
667 void WebChromeClient::runOpenPanel(Frame*, PassRefPtr<FileChooser> chooser)
669 BEGIN_BLOCK_OBJC_EXCEPTIONS;
670 BOOL allowMultipleFiles = chooser->allowsMultipleFiles();
671 WebOpenPanelResultListener *listener = [[WebOpenPanelResultListener alloc] initWithChooser:chooser];
672 id delegate = [m_webView UIDelegate];
673 if ([delegate respondsToSelector:@selector(webView:runOpenPanelForFileButtonWithResultListener:allowMultipleFiles:)])
674 CallUIDelegate(m_webView, @selector(webView:runOpenPanelForFileButtonWithResultListener:allowMultipleFiles:), listener, allowMultipleFiles);
676 CallUIDelegate(m_webView, @selector(webView:runOpenPanelForFileButtonWithResultListener:), listener);
678 END_BLOCK_OBJC_EXCEPTIONS;
681 void WebChromeClient::chooseIconForFiles(const Vector<String>& filenames, FileChooser* chooser)
683 chooser->iconLoaded(Icon::createIconForFiles(filenames));
686 void WebChromeClient::setCursor(const WebCore::Cursor& cursor)
688 NSCursor *platformCursor = cursor.platformCursor();
689 if ([NSCursor currentCursor] == platformCursor)
691 [platformCursor set];
694 KeyboardUIMode WebChromeClient::keyboardUIMode()
696 BEGIN_BLOCK_OBJC_EXCEPTIONS;
697 return [m_webView _keyboardUIMode];
698 END_BLOCK_OBJC_EXCEPTIONS;
699 return KeyboardAccessDefault;
702 NSResponder *WebChromeClient::firstResponder()
704 BEGIN_BLOCK_OBJC_EXCEPTIONS;
705 return [[m_webView _UIDelegateForwarder] webViewFirstResponder:m_webView];
706 END_BLOCK_OBJC_EXCEPTIONS;
710 void WebChromeClient::makeFirstResponder(NSResponder *responder)
712 BEGIN_BLOCK_OBJC_EXCEPTIONS;
713 [m_webView _pushPerformingProgrammaticFocus];
714 [[m_webView _UIDelegateForwarder] webView:m_webView makeFirstResponder:responder];
715 [m_webView _popPerformingProgrammaticFocus];
716 END_BLOCK_OBJC_EXCEPTIONS;
719 void WebChromeClient::willPopUpMenu(NSMenu *menu)
721 BEGIN_BLOCK_OBJC_EXCEPTIONS;
722 CallUIDelegate(m_webView, @selector(webView:willPopupMenu:), menu);
723 END_BLOCK_OBJC_EXCEPTIONS;
726 bool WebChromeClient::shouldReplaceWithGeneratedFileForUpload(const String& path, String& generatedFilename)
729 if (![[m_webView _UIDelegateForwarder] webView:m_webView shouldReplaceUploadFile:path usingGeneratedFilename:&filename])
731 generatedFilename = filename;
735 String WebChromeClient::generateReplacementFile(const String& path)
737 return [[m_webView _UIDelegateForwarder] webView:m_webView generateReplacementFile:path];
740 void WebChromeClient::formDidFocus(const WebCore::Node* node)
742 CallUIDelegate(m_webView, @selector(webView:formDidFocusNode:), kit(const_cast<WebCore::Node*>(node)));
745 void WebChromeClient::formDidBlur(const WebCore::Node* node)
747 CallUIDelegate(m_webView, @selector(webView:formDidBlurNode:), kit(const_cast<WebCore::Node*>(node)));
750 bool WebChromeClient::selectItemWritingDirectionIsNatural()
755 PassRefPtr<WebCore::PopupMenu> WebChromeClient::createPopupMenu(WebCore::PopupMenuClient* client) const
757 return adoptRef(new PopupMenuMac(client));
760 PassRefPtr<WebCore::SearchPopupMenu> WebChromeClient::createSearchPopupMenu(WebCore::PopupMenuClient* client) const
762 return adoptRef(new SearchPopupMenuMac(client));
765 #if USE(ACCELERATED_COMPOSITING)
767 void WebChromeClient::attachRootGraphicsLayer(Frame* frame, GraphicsLayer* graphicsLayer)
769 BEGIN_BLOCK_OBJC_EXCEPTIONS;
771 NSView *documentView = [[kit(frame) frameView] documentView];
772 if (![documentView isKindOfClass:[WebHTMLView class]]) {
773 // We should never be attaching when we don't have a WebHTMLView.
774 ASSERT(!graphicsLayer);
778 WebHTMLView *webHTMLView = (WebHTMLView *)documentView;
780 [webHTMLView attachRootLayer:graphicsLayer->nativeLayer()];
782 [webHTMLView detachRootLayer];
783 END_BLOCK_OBJC_EXCEPTIONS;
786 void WebChromeClient::setNeedsOneShotDrawingSynchronization()
788 BEGIN_BLOCK_OBJC_EXCEPTIONS;
789 [m_webView _setNeedsOneShotDrawingSynchronization:YES];
790 END_BLOCK_OBJC_EXCEPTIONS;
793 void WebChromeClient::scheduleCompositingLayerSync()
795 BEGIN_BLOCK_OBJC_EXCEPTIONS;
796 [m_webView _scheduleCompositingLayerSync];
797 END_BLOCK_OBJC_EXCEPTIONS;
804 bool WebChromeClient::supportsFullscreenForNode(const Node* node)
806 return node->hasTagName(WebCore::HTMLNames::videoTag);
809 void WebChromeClient::enterFullscreenForNode(Node* node)
811 BEGIN_BLOCK_OBJC_EXCEPTIONS;
812 [m_webView _enterFullscreenForNode:node];
813 END_BLOCK_OBJC_EXCEPTIONS;
816 void WebChromeClient::exitFullscreenForNode(Node*)
818 BEGIN_BLOCK_OBJC_EXCEPTIONS;
819 [m_webView _exitFullscreen];
820 END_BLOCK_OBJC_EXCEPTIONS;
825 #if ENABLE(FULLSCREEN_API)
827 bool WebChromeClient::supportsFullScreenForElement(const Element* element)
829 return CallUIDelegateReturningBoolean(false, m_webView, @selector(webView:supportsFullScreenForElement:), kit(const_cast<WebCore::Element*>(element)));
832 void WebChromeClient::enterFullScreenForElement(Element* element)
834 WebKitFullScreenListener* listener = [[WebKitFullScreenListener alloc] initWithElement:element];
835 CallUIDelegate(m_webView, @selector(webView:enterFullScreenForElement:listener:), kit(element), listener);
839 void WebChromeClient::exitFullScreenForElement(Element* element)
841 WebKitFullScreenListener* listener = [[WebKitFullScreenListener alloc] initWithElement:element];
842 CallUIDelegate(m_webView, @selector(webView:exitFullScreenForElement:listener:), kit(element), listener);
848 void WebChromeClient::requestGeolocationPermissionForFrame(Frame* frame, Geolocation* geolocation)
850 BEGIN_BLOCK_OBJC_EXCEPTIONS;
852 SEL selector = @selector(webView:decidePolicyForGeolocationRequestFromOrigin:frame:listener:);
853 if (![[m_webView UIDelegate] respondsToSelector:selector]) {
854 geolocation->setIsAllowed(false);
858 WebSecurityOrigin *webOrigin = [[WebSecurityOrigin alloc] _initWithWebCoreSecurityOrigin:frame->document()->securityOrigin()];
859 WebGeolocationPolicyListener* listener = [[WebGeolocationPolicyListener alloc] initWithGeolocation:geolocation];
861 CallUIDelegate(m_webView, selector, webOrigin, kit(frame), listener);
866 END_BLOCK_OBJC_EXCEPTIONS;
869 @implementation WebOpenPanelResultListener
871 - (id)initWithChooser:(PassRefPtr<FileChooser>)chooser
876 _chooser = chooser.releaseRef();
905 - (void)chooseFilename:(NSString *)filename
910 _chooser->chooseFile(filename);
915 - (void)chooseFilenames:(NSArray *)filenames
920 int count = [filenames count];
921 Vector<String> names(count);
922 for (int i = 0; i < count; i++)
923 names[i] = [filenames objectAtIndex:i];
924 _chooser->chooseFiles(names);
931 @implementation WebGeolocationPolicyListener
933 - (id)initWithGeolocation:(Geolocation*)geolocation
935 if (!(self = [super init]))
937 _geolocation = geolocation;
943 _geolocation->setIsAllowed(true);
948 _geolocation->setIsAllowed(false);
953 #if ENABLE(FULLSCREEN_API)
955 @implementation WebKitFullScreenListener
957 - (id)initWithElement:(Element*)element
959 if (!(self = [super init]))
966 - (void)webkitWillEnterFullScreen
969 _element->document()->webkitWillEnterFullScreenForElement(_element.get());
972 - (void)webkitDidEnterFullScreen
975 _element->document()->webkitDidEnterFullScreenForElement(_element.get());
978 - (void)webkitWillExitFullScreen
981 _element->document()->webkitWillExitFullScreenForElement(_element.get());
984 - (void)webkitDidExitFullScreen
987 _element->document()->webkitDidExitFullScreenForElement(_element.get());