2 * Copyright (C) 2005, 2006 Apple Computer, 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.
29 #import "WebFrameBridge.h"
31 #import <JavaScriptCore/Assertions.h>
32 #import "WebBackForwardList.h"
33 #import "WebBaseNetscapePluginView.h"
34 #import "WebBasePluginPackage.h"
35 #import "WebDataSourceInternal.h"
36 #import "WebDefaultUIDelegate.h"
37 #import "WebDocumentLoader.h"
38 #import "WebEditingDelegate.h"
39 #import "WebFormDataStream.h"
40 #import "WebFormDelegate.h"
41 #import "WebFrameInternal.h"
42 #import "WebFrameLoadDelegate.h"
43 #import "WebFrameLoader.h"
44 #import "WebFrameViewInternal.h"
45 #import "WebHTMLRepresentationPrivate.h"
46 #import "WebHTMLViewInternal.h"
47 #import "WebHistoryItemPrivate.h"
48 #import "WebIconDatabase.h"
49 #import <WebKit/WebIconDatabasePrivate.h>
50 #import "WebJavaPlugIn.h"
51 #import "WebJavaScriptTextInputPanel.h"
52 #import "WebKitErrorsPrivate.h"
53 #import "WebKitLogging.h"
54 #import "WebKitNSStringExtras.h"
55 #import "WebKitStatisticsPrivate.h"
56 #import "WebKitSystemBits.h"
58 #import "WebLocalizableStrings.h"
59 #import "WebNSObjectExtras.h"
60 #import "WebNSURLExtras.h"
61 #import "WebNSURLRequestExtras.h"
62 #import "WebNSViewExtras.h"
63 #import "WebNetscapePluginEmbeddedView.h"
64 #import "WebNetscapePluginPackage.h"
65 #import "WebNullPluginView.h"
66 #import "WebPageBridge.h"
68 #import "WebPluginController.h"
69 #import "WebPluginDatabase.h"
70 #import "WebPluginPackage.h"
71 #import "WebPluginViewFactoryPrivate.h"
72 #import "WebPreferencesPrivate.h"
73 #import "WebResourcePrivate.h"
74 #import "WebScriptDebugServerPrivate.h"
75 #import "WebSubresourceLoader.h"
76 #import "WebUIDelegatePrivate.h"
77 #import "WebViewInternal.h"
78 #import <Foundation/NSURLConnection.h>
79 #import <Foundation/NSURLRequest.h>
80 #import <Foundation/NSURLResponse.h>
81 #import <JavaVM/jni.h>
82 #import <WebCore/WebCoreFrameNamespaces.h>
83 #import <WebKitSystemInterface.h>
85 // For compatibility only with old SPI.
86 @interface NSObject (OldWebPlugin)
87 - (void)setIsSelected:(BOOL)f;
90 @interface NSApplication (DeclarationStolenFromAppKit)
91 - (void)_cycleWindowsReversed:(BOOL)reversed;
94 @interface NSView (AppKitSecretsWebBridgeKnowsAbout)
95 - (NSView *)_findLastViewInKeyViewLoop;
98 @interface NSURLResponse (FoundationSecretsWebBridgeKnowsAbout)
99 - (NSTimeInterval)_calculatedExpiration;
102 @interface NSView (JavaPluginSecrets)
103 - (jobject)pollForAppletInWindow:(NSWindow *)window;
106 NSString *WebPluginBaseURLKey = @"WebPluginBaseURL";
107 NSString *WebPluginAttributesKey = @"WebPluginAttributes";
108 NSString *WebPluginContainerKey = @"WebPluginContainer";
110 @implementation WebFrameBridge
114 ASSERT([[self page] isKindOfClass:[WebPageBridge class]]);
115 return [(WebPageBridge *)[self page] webView];
118 - (id)initMainFrameWithPage:(WebPageBridge *)page frameName:(NSString *)name view:(WebFrameView *)view
120 self = [super initMainFrameWithPage:page];
124 _frame = [[WebFrame alloc] _initWithWebFrameView:view webView:[self webView] bridge:self];
125 _loader = [[WebFrameLoader alloc] initWithClient:_frame];
128 [self initializeSettings:[[self webView] _settings]];
129 [self setTextSizeMultiplier:[[self webView] textSizeMultiplier]];
134 - (id)initSubframeWithOwnerElement:(WebCoreElement *)ownerElement frameName:(NSString *)name view:(WebFrameView *)view
136 self = [super initSubframeWithOwnerElement:ownerElement];
140 _frame = [[WebFrame alloc] _initWithWebFrameView:view webView:[self webView] bridge:self];
141 _loader = [[WebFrameLoader alloc] initWithClient:_frame];
144 [self initializeSettings:[[self webView] _settings]];
145 [self setTextSizeMultiplier:[[self webView] textSizeMultiplier]];
150 #define KeyboardUIModeDidChangeNotification @"com.apple.KeyboardUIModeDidChange"
151 #define AppleKeyboardUIMode CFSTR("AppleKeyboardUIMode")
152 #define UniversalAccessDomain CFSTR("com.apple.universalaccess")
156 if (_keyboardUIModeAccessed) {
157 [[NSDistributedNotificationCenter defaultCenter]
158 removeObserver:self name:KeyboardUIModeDidChangeNotification object:nil];
159 [[NSNotificationCenter defaultCenter]
160 removeObserver:self name:WebPreferencesChangedNotification object:nil];
162 ASSERT(_frame == nil);
168 [lastDashboardRegions release];
182 - (WebPreferences *)_preferences
184 return [[self webView] preferences];
187 - (void)_retrieveKeyboardUIModeFromPreferences:(NSNotification *)notification
189 CFPreferencesAppSynchronize(UniversalAccessDomain);
191 Boolean keyExistsAndHasValidFormat;
192 int mode = CFPreferencesGetAppIntegerValue(AppleKeyboardUIMode, UniversalAccessDomain, &keyExistsAndHasValidFormat);
194 // The keyboard access mode is reported by two bits:
195 // Bit 0 is set if feature is on
196 // Bit 1 is set if full keyboard access works for any control, not just text boxes and lists
197 // We require both bits to be on.
198 // I do not know that we would ever get one bit on and the other off since
199 // checking the checkbox in system preferences which is marked as "Turn on full keyboard access"
200 // turns on both bits.
201 _keyboardUIMode = (mode & 0x2) ? WebCoreKeyboardAccessFull : WebCoreKeyboardAccessDefault;
203 // check for tabbing to links
204 if ([[self _preferences] tabsToLinks]) {
205 _keyboardUIMode |= WebCoreKeyboardAccessTabsToLinks;
209 - (WebCoreKeyboardUIMode)keyboardUIMode
211 if (!_keyboardUIModeAccessed) {
212 _keyboardUIModeAccessed = YES;
213 [self _retrieveKeyboardUIModeFromPreferences:nil];
215 [[NSDistributedNotificationCenter defaultCenter]
216 addObserver:self selector:@selector(_retrieveKeyboardUIModeFromPreferences:)
217 name:KeyboardUIModeDidChangeNotification object:nil];
219 [[NSNotificationCenter defaultCenter]
220 addObserver:self selector:@selector(_retrieveKeyboardUIModeFromPreferences:)
221 name:WebPreferencesChangedNotification object:nil];
223 return _keyboardUIMode;
226 - (WebFrame *)webFrame
231 - (WebFrameLoader *)loader
236 - (WebCoreFrameBridge *)mainFrame
238 ASSERT(_frame != nil);
239 return [[[self webView] mainFrame] _bridge];
242 - (NSView *)documentView
244 ASSERT(_frame != nil);
245 return [[_frame frameView] documentView];
248 - (WebCorePageBridge *)createWindowWithURL:(NSURL *)URL
250 ASSERT(_frame != nil);
252 NSMutableURLRequest *request = nil;
253 if (URL != nil && ![URL _web_isEmpty]) {
254 request = [NSMutableURLRequest requestWithURL:URL];
255 [request _web_setHTTPReferrer:[self referrer]];
258 WebView *currentWebView = [self webView];
259 id wd = [currentWebView UIDelegate];
261 if ([wd respondsToSelector:@selector(webView:createWebViewWithRequest:)])
262 newWebView = [wd webView:currentWebView createWebViewWithRequest:request];
264 newWebView = [[WebDefaultUIDelegate sharedUIDelegate] webView:currentWebView createWebViewWithRequest:request];
265 return [newWebView _pageBridge];
270 WebView *wv = [self webView];
271 [[wv _UIDelegateForwarder] webViewShow:wv];
274 - (BOOL)areToolbarsVisible
276 ASSERT(_frame != nil);
277 WebView *wv = [self webView];
278 id wd = [wv UIDelegate];
279 if ([wd respondsToSelector:@selector(webViewAreToolbarsVisible:)])
280 return [wd webViewAreToolbarsVisible:wv];
281 return [[WebDefaultUIDelegate sharedUIDelegate] webViewAreToolbarsVisible:wv];
284 - (void)setToolbarsVisible:(BOOL)visible
286 ASSERT(_frame != nil);
287 WebView *wv = [self webView];
288 [[wv _UIDelegateForwarder] webView:wv setToolbarsVisible:visible];
291 - (BOOL)areScrollbarsVisible
293 ASSERT(_frame != nil);
294 return [[_frame frameView] allowsScrolling];
297 - (void)setScrollbarsVisible:(BOOL)visible
299 ASSERT(_frame != nil);
300 [[_frame frameView] setAllowsScrolling:visible];
303 - (BOOL)isStatusbarVisible
305 ASSERT(_frame != nil);
306 WebView *wv = [self webView];
307 id wd = [wv UIDelegate];
308 if ([wd respondsToSelector:@selector(webViewIsStatusBarVisible:)])
309 return [wd webViewIsStatusBarVisible:wv];
310 return [[WebDefaultUIDelegate sharedUIDelegate] webViewIsStatusBarVisible:wv];
313 - (void)setStatusbarVisible:(BOOL)visible
315 ASSERT(_frame != nil);
316 WebView *wv = [self webView];
317 [[wv _UIDelegateForwarder] webView:wv setStatusBarVisible:visible];
320 - (void)setWindowIsResizable:(BOOL)resizable
322 ASSERT(_frame != nil);
323 WebView *webView = [self webView];
324 [[webView _UIDelegateForwarder] webView:webView setResizable:resizable];
327 - (BOOL)windowIsResizable
329 ASSERT(_frame != nil);
330 WebView *webView = [self webView];
331 return [[webView _UIDelegateForwarder] webViewIsResizable:webView];
334 - (NSResponder *)firstResponder
336 ASSERT(_frame != nil);
337 WebView *webView = [self webView];
338 return [[webView _UIDelegateForwarder] webViewFirstResponder:webView];
341 - (void)makeFirstResponder:(NSResponder *)view
343 ASSERT(_frame != nil);
344 WebView *webView = [self webView];
345 [webView _pushPerformingProgrammaticFocus];
346 [[webView _UIDelegateForwarder] webView:webView makeFirstResponder:view];
347 [webView _popPerformingProgrammaticFocus];
350 - (void)willMakeFirstResponderForNodeFocus
352 ASSERT([[[_frame frameView] documentView] isKindOfClass:[WebHTMLView class]]);
353 [(WebHTMLView *)[[_frame frameView] documentView] _willMakeFirstResponderForNodeFocus];
357 - (BOOL)textViewWasFirstResponderAtMouseDownTime:(NSTextView *)textView;
359 ASSERT(_frame != nil);
360 NSView *documentView = [[_frame frameView] documentView];
361 if (![documentView isKindOfClass:[WebHTMLView class]]) {
364 WebHTMLView *webHTMLView = (WebHTMLView *)documentView;
365 return [webHTMLView _textViewWasFirstResponderAtMouseDownTime:textView];
368 - (void)closeWindowSoon
370 WebView *parentWebView = [self webView];
372 // We need to remove the parent WebView from WebViewSets here, before it actually
373 // closes, to make sure that JavaScript code that executes before it closes
374 // can't find it. Otherwise, window.open will select a closed WebView instead of
375 // opening a new one <rdar://problem/3572585>.
377 // We also need to stop the load to prevent further parsing or JavaScript execution
378 // after the window has torn down <rdar://problem/4161660>.
380 // FIXME: This code assumes that the UI delegate will respond to a webViewClose
381 // message by actually closing the WebView. Safari guarantees this behavior, but other apps might not.
382 // This approach is an inherent limitation of not making a close execute immediately
383 // after a call to window.close.
385 [parentWebView setGroupName:nil];
386 [parentWebView stopLoading:self];
387 [parentWebView performSelector:@selector(_closeWindow) withObject:nil afterDelay:0.0];
392 ASSERT(_frame != nil);
393 return [[_frame frameView] window];
396 - (void)runJavaScriptAlertPanelWithMessage:(NSString *)message
398 WebView *wv = [self webView];
399 id wd = [wv UIDelegate];
400 // Check whether delegate implements new version, then whether delegate implements old version. If neither,
401 // fall back to shared delegate's implementation of new version.
402 if ([wd respondsToSelector:@selector(webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:)])
403 [wd webView:wv runJavaScriptAlertPanelWithMessage:message initiatedByFrame:_frame];
404 else if ([wd respondsToSelector:@selector(webView:runJavaScriptAlertPanelWithMessage:)])
405 [wd webView:wv runJavaScriptAlertPanelWithMessage:message];
407 [[WebDefaultUIDelegate sharedUIDelegate] webView:wv runJavaScriptAlertPanelWithMessage:message initiatedByFrame:_frame];
410 - (BOOL)runJavaScriptConfirmPanelWithMessage:(NSString *)message
412 WebView *wv = [self webView];
413 id wd = [wv UIDelegate];
414 // Check whether delegate implements new version, then whether delegate implements old version. If neither,
415 // fall back to shared delegate's implementation of new version.
416 if ([wd respondsToSelector:@selector(webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame:)])
417 return [wd webView:wv runJavaScriptConfirmPanelWithMessage:message initiatedByFrame:_frame];
418 if ([wd respondsToSelector:@selector(webView:runJavaScriptConfirmPanelWithMessage:)])
419 return [wd webView:wv runJavaScriptConfirmPanelWithMessage:message];
420 return [[WebDefaultUIDelegate sharedUIDelegate] webView:wv runJavaScriptConfirmPanelWithMessage:message initiatedByFrame:_frame];
423 - (BOOL)shouldInterruptJavaScript
425 WebView *wv = [self webView];
426 id wd = [wv UIDelegate];
428 if ([wd respondsToSelector:@selector(webViewShouldInterruptJavaScript:)])
429 return [wd webViewShouldInterruptJavaScript:wv];
433 - (BOOL)canRunBeforeUnloadConfirmPanel
435 WebView *wv = [self webView];
436 id wd = [wv UIDelegate];
437 return [wd respondsToSelector:@selector(webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:)];
440 - (BOOL)runBeforeUnloadConfirmPanelWithMessage:(NSString *)message
442 WebView *wv = [self webView];
443 id wd = [wv UIDelegate];
444 if ([wd respondsToSelector:@selector(webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:)])
445 return [wd webView:wv runBeforeUnloadConfirmPanelWithMessage:message initiatedByFrame:_frame];
449 - (BOOL)runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)defaultText returningText:(NSString **)result
451 WebView *wv = [self webView];
452 id wd = [wv UIDelegate];
453 // Check whether delegate implements new version, then whether delegate implements old version. If neither,
454 // fall back to shared delegate's implementation of new version.
455 if ([wd respondsToSelector:@selector(webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:)])
456 *result = [wd webView:wv runJavaScriptTextInputPanelWithPrompt:prompt defaultText:defaultText initiatedByFrame:_frame];
457 else if ([wd respondsToSelector:@selector(webView:runJavaScriptTextInputPanelWithPrompt:defaultText:)])
458 *result = [wd webView:wv runJavaScriptTextInputPanelWithPrompt:prompt defaultText:defaultText];
460 *result = [[WebDefaultUIDelegate sharedUIDelegate] webView:wv runJavaScriptTextInputPanelWithPrompt:prompt defaultText:defaultText initiatedByFrame:_frame];
461 return *result != nil;
464 - (void)addMessageToConsole:(NSDictionary *)message
466 WebView *wv = [self webView];
467 id wd = [wv UIDelegate];
468 if ([wd respondsToSelector:@selector(webView:addMessageToConsole:)])
469 [wd webView:wv addMessageToConsole:message];
472 - (void)runOpenPanelForFileButtonWithResultListener:(id<WebCoreOpenPanelResultListener>)resultListener
474 WebView *wv = [self webView];
475 [[wv _UIDelegateForwarder] webView:wv runOpenPanelForFileButtonWithResultListener:(id<WebOpenPanelResultListener>)resultListener];
478 - (WebDataSource *)dataSource
480 ASSERT(_frame != nil);
481 WebDataSource *dataSource = [_frame dataSource];
483 ASSERT(dataSource != nil);
488 - (void)setTitle:(NSString *)title
490 [[_loader documentLoader] setTitle:[title _webkit_stringByCollapsingNonPrintingCharacters]];
493 - (void)setStatusText:(NSString *)status
495 ASSERT(_frame != nil);
496 WebView *wv = [self webView];
497 [[wv _UIDelegateForwarder] webView:wv setStatusText:status];
500 - (void)receivedData:(NSData *)data textEncodingName:(NSString *)textEncodingName
502 // Set the encoding. This only needs to be done once, but it's harmless to do it again later.
503 NSString *encoding = [[_loader documentLoader] overrideEncoding];
504 BOOL userChosen = encoding != nil;
505 if (encoding == nil) {
506 encoding = textEncodingName;
508 [self setEncoding:encoding userChosen:userChosen];
513 - (id <WebCoreResourceHandle>)startLoadingResource:(id <WebCoreResourceLoader>)resourceLoader withMethod:(NSString *)method URL:(NSURL *)URL customHeaders:(NSDictionary *)customHeaders
515 // If we are no longer attached to a WebView, this must be an attempted load from an
516 // onUnload handler, so let's just block it.
517 if ([[self webFrame] webView] == nil)
520 // Since this is a subresource, we can load any URL (we ignore the return value).
521 // But we still want to know whether we should hide the referrer or not, so we call the canLoadURL method.
523 [self canLoadURL:URL fromReferrer:[self referrer] hideReferrer:&hideReferrer];
525 return [WebSubresourceLoader startLoadingResource:resourceLoader
528 customHeaders:customHeaders
529 referrer:(hideReferrer ? nil : [self referrer])
530 forFrameLoader:_loader];
533 - (id <WebCoreResourceHandle>)startLoadingResource:(id <WebCoreResourceLoader>)resourceLoader withMethod:(NSString *)method URL:(NSURL *)URL customHeaders:(NSDictionary *)customHeaders postData:(NSArray *)postData
535 // If we are no longer attached to a WebView, this must be an attempted load from an
536 // onUnload handler, so let's just block it.
537 if ([[self webFrame] webView] == nil)
540 // Since this is a subresource, we can load any URL (we ignore the return value).
541 // But we still want to know whether we should hide the referrer or not, so we call the canLoadURL method.
543 [self canLoadURL:URL fromReferrer:[self referrer] hideReferrer:&hideReferrer];
545 return [WebSubresourceLoader startLoadingResource:resourceLoader
548 customHeaders:customHeaders
550 referrer:(hideReferrer ? nil : [self referrer])
551 forFrameLoader:_loader];
554 - (void)objectLoadedFromCacheWithURL:(NSURL *)URL response:(NSURLResponse *)response data:(NSData *)data
556 // FIXME: If the WebKit client changes or cancels the request, WebCore does not respect this and continues the load.
559 NSURLRequest *request = [[NSURLRequest alloc] initWithURL:URL];
560 [_frame _requestFromDelegateForRequest:request identifier:&identifier error:&error];
561 [_frame _sendRemainingDelegateMessagesWithIdentifier:identifier response:response length:[data length] error:error];
565 - (NSData *)syncLoadResourceWithMethod:(NSString *)method URL:(NSURL *)URL customHeaders:(NSDictionary *)requestHeaders postData:(NSArray *)postData finalURL:(NSURL **)finalURL responseHeaders:(NSDictionary **)responseHeaderDict statusCode:(int *)statusCode
567 // Since this is a subresource, we can load any URL (we ignore the return value).
568 // But we still want to know whether we should hide the referrer or not, so we call the canLoadURL method.
570 [self canLoadURL:URL fromReferrer:[self referrer] hideReferrer:&hideReferrer];
572 NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:URL];
573 [request setTimeoutInterval:10];
575 // setHTTPMethod is not called for GET requests to work around <rdar://4464032>.
576 if (![method isEqualToString:@"GET"])
577 [request setHTTPMethod:method];
580 webSetHTTPBody(request, postData);
582 NSEnumerator *e = [requestHeaders keyEnumerator];
584 while ((key = (NSString *)[e nextObject]) != nil) {
585 [request addValue:[requestHeaders objectForKey:key] forHTTPHeaderField:key];
588 if ([request _web_isConditionalRequest])
589 [request setCachePolicy:NSURLRequestReloadIgnoringCacheData];
591 [request setCachePolicy:[[[self dataSource] request] cachePolicy]];
593 [request _web_setHTTPReferrer:[self referrer]];
595 WebView *webView = [self webView];
596 [request setMainDocumentURL:[[[[webView mainFrame] dataSource] request] URL]];
597 [request _web_setHTTPUserAgent:[webView userAgentForURL:[request URL]]];
599 NSError *error = nil;
601 NSURLRequest *newRequest = [_frame _requestFromDelegateForRequest:request identifier:&identifier error:&error];
603 NSURLResponse *response = nil;
604 NSData *result = nil;
606 ASSERT(newRequest != nil);
607 result = [NSURLConnection sendSynchronousRequest:newRequest returningResponse:&response error:&error];
611 *finalURL = [response URL];
612 if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
613 NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
614 *responseHeaderDict = [httpResponse allHeaderFields];
615 *statusCode = [httpResponse statusCode];
617 *responseHeaderDict = [NSDictionary dictionary];
622 *responseHeaderDict = [NSDictionary dictionary];
623 if ([error domain] == NSURLErrorDomain) {
624 *statusCode = [error code];
630 [_frame _sendRemainingDelegateMessagesWithIdentifier:identifier response:response length:[result length] error:error];
638 return [[[self dataSource] request] cachePolicy] == NSURLRequestReloadIgnoringCacheData;
641 // We would like a better value for a maximum time_t,
642 // but there is no way to do that in C with any certainty.
643 // INT_MAX should work well enough for our purposes.
644 #define MAX_TIME_T ((time_t)INT_MAX)
646 - (time_t)expiresTimeForResponse:(NSURLResponse *)response
648 // This check can be removed when the new Foundation method
649 // has been around long enough for everyone to have it.
650 ASSERT([response respondsToSelector:@selector(_calculatedExpiration)]);
652 NSTimeInterval expiration = [response _calculatedExpiration];
653 expiration += kCFAbsoluteTimeIntervalSince1970;
655 return expiration > MAX_TIME_T ? MAX_TIME_T : (time_t)expiration;
658 - (void)reportClientRedirectToURL:(NSURL *)URL delay:(NSTimeInterval)seconds fireDate:(NSDate *)date lockHistory:(BOOL)lockHistory isJavaScriptFormAction:(BOOL)isJavaScriptFormAction
660 [_loader clientRedirectedTo:URL delay:seconds fireDate:date lockHistory:lockHistory isJavaScriptFormAction:(BOOL)isJavaScriptFormAction];
663 - (void)reportClientRedirectCancelled:(BOOL)cancelWithLoadInProgress
665 [_loader clientRedirectCancelledOrFinished:cancelWithLoadInProgress];
675 - (void)activateWindow
677 [[[self webView] _UIDelegateForwarder] webViewFocus:[self webView]];
680 - (void)deactivateWindow
682 [[[self webView] _UIDelegateForwarder] webViewUnfocus:[self webView]];
685 - (void)formControlIsBecomingFirstResponder:(NSView *)formControl
687 // When a form element becomes first responder, its enclosing WebHTMLView might need to
688 // change its focus-displaying state, but isn't otherwise notified.
689 [(WebHTMLView *)[[_frame frameView] documentView] _formControlIsBecomingFirstResponder:formControl];
692 - (void)formControlIsResigningFirstResponder:(NSView *)formControl
694 // When a form element resigns first responder, its enclosing WebHTMLView might need to
695 // change its focus-displaying state, but isn't otherwise notified.
696 [(WebHTMLView *)[[_frame frameView] documentView] _formControlIsResigningFirstResponder:formControl];
699 - (void)loadURL:(NSURL *)URL referrer:(NSString *)referrer reload:(BOOL)reload userGesture:(BOOL)forUser target:(NSString *)target triggeringEvent:(NSEvent *)event form:(DOMElement *)form formValues:(NSDictionary *)values
702 if (![self canLoadURL:URL fromReferrer:referrer hideReferrer:&hideReferrer])
705 if ([target length] == 0) {
709 WebFrame *targetFrame = [_frame findFrameNamed:target];
710 if (![self canTargetLoadInFrame:[targetFrame _bridge]]) {
714 WebFrameLoadType loadType;
717 loadType = WebFrameLoadTypeReload;
719 loadType = WebFrameLoadTypeInternal;
721 loadType = WebFrameLoadTypeStandard;
722 [_loader loadURL:URL referrer:(hideReferrer ? nil : referrer) loadType:loadType target:target triggeringEvent:event form:form formValues:values];
724 if (targetFrame != nil && _frame != targetFrame) {
725 [[targetFrame _bridge] activateWindow];
729 - (void)postWithURL:(NSURL *)URL referrer:(NSString *)referrer target:(NSString *)target data:(NSArray *)postData contentType:(NSString *)contentType triggeringEvent:(NSEvent *)event form:(DOMElement *)form formValues:(NSDictionary *)values
732 if (![self canLoadURL:URL fromReferrer:referrer hideReferrer:&hideReferrer])
735 if ([target length] == 0) {
739 WebFrame *targetFrame = [_frame findFrameNamed:target];
740 if (![self canTargetLoadInFrame:[targetFrame _bridge]]) {
744 [_frame _postWithURL:URL referrer:(hideReferrer ? nil : referrer) target:target data:postData contentType:contentType triggeringEvent:event form:form formValues:values];
746 if (targetFrame != nil && _frame != targetFrame) {
747 [[targetFrame _bridge] activateWindow];
751 - (WebCoreFrameBridge *)createChildFrameNamed:(NSString *)frameName
753 referrer:(NSString *)referrer
754 ownerElement:(WebCoreElement *)ownerElement
755 allowsScrolling:(BOOL)allowsScrolling
756 marginWidth:(int)width
757 marginHeight:(int)height
760 if (![self canLoadURL:URL fromReferrer:referrer hideReferrer:&hideReferrer])
765 WebFrameView *childView = [[WebFrameView alloc] initWithFrame:NSMakeRect(0,0,0,0)];
766 [childView setAllowsScrolling:allowsScrolling];
767 WebFrameBridge *newBridge = [[WebFrameBridge alloc] initSubframeWithOwnerElement:ownerElement frameName:frameName view:childView];
768 [_frame _addChild:[newBridge webFrame]];
771 [childView _setMarginWidth:width];
772 [childView _setMarginHeight:height];
779 [_frame _loadURL:URL referrer:(hideReferrer ? nil : referrer) intoChild:[newBridge webFrame]];
784 - (void)saveDocumentState:(NSArray *)documentState
786 WebHistoryItem *item = [_frame _itemForSavingDocState];
787 LOG(Loading, "%@: saving form state from to 0x%x", [_frame name], item);
789 [item setDocumentState:documentState];
790 // You might think we could save the scroll state here too, but unfortunately this
791 // often gets called after WebFrame::_transitionToCommitted has restored the scroll
792 // position of the next document.
796 - (NSArray *)documentState
798 LOG(Loading, "%@: restoring form state from item 0x%x", [_frame name], [_frame _itemForRestoringDocState]);
799 return [[_frame _itemForRestoringDocState] documentState];
802 - (BOOL)saveDocumentToPageCache:(id)documentInfo
804 WebHistoryItem *item = [_frame _itemForSavingDocState];
805 if (![item hasPageCache]) {
808 [[item pageCache] setObject:documentInfo forKey:WebCorePageCacheStateKey];
812 - (NSString *)userAgentForURL:(NSURL *)URL
814 return [[self webView] userAgentForURL:URL];
817 - (BOOL)inNextKeyViewOutsideWebFrameViews
819 return _inNextKeyViewOutsideWebFrameViews;
822 - (NSView *)_nextKeyViewOutsideWebFrameViewsWithValidityCheck:(BOOL)mustBeValid
824 // We can get here in unusual situations such as the one listed in 4451831, so we
825 // return nil to avoid an infinite recursion.
826 if (_inNextKeyViewOutsideWebFrameViews)
829 _inNextKeyViewOutsideWebFrameViews = YES;
830 WebView *webView = [self webView];
831 // Do not ask webView for its next key view, but rather, ask it for
832 // the next key view of the last view in its key view loop.
833 // Doing so gives us the correct answer as calculated by AppKit,
834 // and makes HTML views behave like other views.
835 NSView *lastViewInLoop = [webView _findLastViewInKeyViewLoop];
836 NSView *nextKeyView = mustBeValid ? [lastViewInLoop nextValidKeyView] : [lastViewInLoop nextKeyView];
837 _inNextKeyViewOutsideWebFrameViews = NO;
841 - (NSView *)nextKeyViewOutsideWebFrameViews
843 return [self _nextKeyViewOutsideWebFrameViewsWithValidityCheck:NO];
846 - (NSView *)nextValidKeyViewOutsideWebFrameViews
848 return [self _nextKeyViewOutsideWebFrameViewsWithValidityCheck:YES];
851 - (NSView *)previousKeyViewOutsideWebFrameViews
853 WebView *webView = [self webView];
854 NSView *previousKeyView = [webView previousKeyView];
855 return previousKeyView;
858 - (BOOL)defersLoading
860 return [[self webView] defersCallbacks];
863 - (void)setDefersLoading:(BOOL)defers
865 [[self webView] setDefersCallbacks:defers];
868 - (void)setNeedsReapplyStyles
870 NSView <WebDocumentView> *view = [[_frame frameView] documentView];
871 if ([view isKindOfClass:[WebHTMLView class]]) {
872 [(WebHTMLView *)view setNeedsToApplyStyles:YES];
873 [view setNeedsLayout:YES];
874 [view setNeedsDisplay:YES];
878 - (void)tokenizerProcessedData
880 [_frame _checkLoadComplete];
883 - (NSString *)incomingReferrer
885 return [[[self dataSource] request] _web_HTTPReferrer];
888 - (NSView *)pluginViewWithPackage:(WebPluginPackage *)pluginPackage
889 attributeNames:(NSArray *)attributeNames
890 attributeValues:(NSArray *)attributeValues
891 baseURL:(NSURL *)baseURL
892 DOMElement:(DOMElement *)element
893 loadManually:(BOOL)loadManually
895 WebHTMLView *docView = (WebHTMLView *)[[_frame frameView] documentView];
896 ASSERT([docView isKindOfClass:[WebHTMLView class]]);
898 WebPluginController *pluginController = [docView _pluginController];
900 // Store attributes in a dictionary so they can be passed to WebPlugins.
901 NSMutableDictionary *attributes = [[NSMutableDictionary alloc] initWithObjects:attributeValues forKeys:attributeNames];
903 [pluginPackage load];
904 Class viewFactory = [pluginPackage viewFactory];
907 NSDictionary *arguments = nil;
909 if ([viewFactory respondsToSelector:@selector(plugInViewWithArguments:)]) {
910 arguments = [NSDictionary dictionaryWithObjectsAndKeys:
911 baseURL, WebPlugInBaseURLKey,
912 attributes, WebPlugInAttributesKey,
913 pluginController, WebPlugInContainerKey,
914 [NSNumber numberWithInt:loadManually ? WebPlugInModeFull : WebPlugInModeEmbed], WebPlugInModeKey,
915 [NSNumber numberWithBool:!loadManually], WebPlugInShouldLoadMainResourceKey,
916 element, WebPlugInContainingElementKey,
918 LOG(Plugins, "arguments:\n%@", arguments);
919 } else if ([viewFactory respondsToSelector:@selector(pluginViewWithArguments:)]) {
920 arguments = [NSDictionary dictionaryWithObjectsAndKeys:
921 baseURL, WebPluginBaseURLKey,
922 attributes, WebPluginAttributesKey,
923 pluginController, WebPluginContainerKey,
924 element, WebPlugInContainingElementKey,
926 LOG(Plugins, "arguments:\n%@", arguments);
929 view = [WebPluginController plugInViewWithArguments:arguments fromPluginPackage:pluginPackage];
931 [attributes release];
935 - (NSString *)valueForKey:(NSString *)key keys:(NSArray *)keys values:(NSArray *)values
937 unsigned count = [keys count];
939 for (i = 0; i < count; i++) {
940 if ([[keys objectAtIndex:i] _webkit_isCaseInsensitiveEqualToString:key])
941 return [values objectAtIndex:i];
946 - (NSView *)viewForPluginWithURL:(NSURL *)URL
947 attributeNames:(NSArray *)attributeNames
948 attributeValues:(NSArray *)attributeValues
949 MIMEType:(NSString *)MIMEType
950 DOMElement:(DOMElement *)element
951 loadManually:(BOOL)loadManually
954 if (![self canLoadURL:URL fromReferrer:[self referrer] hideReferrer:&hideReferrer])
957 ASSERT([attributeNames count] == [attributeValues count]);
959 WebBasePluginPackage *pluginPackage = nil;
963 WebView *wv = [self webView];
964 id wd = [wv UIDelegate];
966 if ([wd respondsToSelector:@selector(webView:plugInViewWithArguments:)]) {
967 NSMutableDictionary *attributes = [[NSMutableDictionary alloc] initWithObjects:attributeValues forKeys:attributeNames];
968 NSDictionary *arguments = [NSDictionary dictionaryWithObjectsAndKeys:
969 attributes, WebPlugInAttributesKey,
970 [NSNumber numberWithInt:loadManually ? WebPlugInModeFull : WebPlugInModeEmbed], WebPlugInModeKey,
971 URL, WebPlugInBaseURLKey, // URL might be nil, so add it last
972 [NSNumber numberWithBool:!loadManually], WebPlugInShouldLoadMainResourceKey,
973 element, WebPlugInContainingElementKey,
975 [attributes release];
976 view = [wd webView:wv plugInViewWithArguments:arguments];
981 if ([MIMEType length] != 0)
982 pluginPackage = [[self webView] _pluginForMIMEType:MIMEType];
986 NSString *extension = [[URL path] pathExtension];
987 if (!pluginPackage && [extension length] != 0) {
988 pluginPackage = [[self webView] _pluginForExtension:extension];
990 NSString *newMIMEType = [pluginPackage MIMETypeForExtension:extension];
991 if ([newMIMEType length] != 0)
992 MIMEType = newMIMEType;
996 NSURL *baseURL = [self baseURL];
998 if ([pluginPackage isKindOfClass:[WebPluginPackage class]]) {
999 view = [self pluginViewWithPackage:(WebPluginPackage *)pluginPackage
1000 attributeNames:attributeNames
1001 attributeValues:attributeValues
1004 loadManually:loadManually];
1005 } else if ([pluginPackage isKindOfClass:[WebNetscapePluginPackage class]]) {
1006 WebNetscapePluginEmbeddedView *embeddedView = [[[WebNetscapePluginEmbeddedView alloc] initWithFrame:NSZeroRect
1007 plugin:(WebNetscapePluginPackage *)pluginPackage
1011 attributeKeys:attributeNames
1012 attributeValues:attributeValues
1013 loadManually:loadManually
1014 DOMElement:element] autorelease];
1015 view = embeddedView;
1016 [_frame _addPlugInView:embeddedView];
1018 ASSERT_NOT_REACHED();
1020 errorCode = WebKitErrorCannotFindPlugIn;
1022 if (!errorCode && !view)
1023 errorCode = WebKitErrorCannotLoadPlugIn;
1026 NSString *pluginPage = [self valueForKey:@"pluginspage" keys:attributeNames values:attributeValues];
1027 NSURL *pluginPageURL = pluginPage != nil ? [self URLWithAttributeString:pluginPage] : nil;
1028 NSError *error = [[NSError alloc] _initWithPluginErrorCode:errorCode
1030 pluginPageURL:pluginPageURL
1031 pluginName:[pluginPackage name]
1033 WebNullPluginView *nullView = [[[WebNullPluginView alloc] initWithFrame:NSZeroRect error:error] autorelease];
1034 [_frame _addPlugInView:nullView];
1043 - (void)redirectDataToPlugin:(NSView *)pluginView
1045 WebHTMLRepresentation *representation = (WebHTMLRepresentation *)[[_frame dataSource] representation];
1047 if ([pluginView isKindOfClass:[WebNetscapePluginEmbeddedView class]])
1048 [representation _redirectDataToManualLoader:(WebNetscapePluginEmbeddedView *)pluginView forPluginView:pluginView];
1050 WebHTMLView *docView = (WebHTMLView *)[[_frame frameView] documentView];
1051 ASSERT([docView isKindOfClass:[WebHTMLView class]]);
1053 WebPluginController *pluginController = [docView _pluginController];
1054 [representation _redirectDataToManualLoader:pluginController forPluginView:pluginView];
1058 - (NSView *)viewForJavaAppletWithFrame:(NSRect)theFrame
1059 attributeNames:(NSArray *)attributeNames
1060 attributeValues:(NSArray *)attributeValues
1061 baseURL:(NSURL *)baseURL
1062 DOMElement:(DOMElement *)element
1064 NSString *MIMEType = @"application/x-java-applet";
1065 WebBasePluginPackage *pluginPackage;
1068 pluginPackage = [[self webView] _pluginForMIMEType:MIMEType];
1070 if (pluginPackage) {
1071 if ([pluginPackage isKindOfClass:[WebPluginPackage class]]) {
1072 // For some reason, the Java plug-in requires that we pass the dimension of the plug-in as attributes.
1073 NSMutableArray *names = [attributeNames mutableCopy];
1074 NSMutableArray *values = [attributeValues mutableCopy];
1075 if ([self valueForKey:@"width" keys:attributeNames values:attributeValues] == nil) {
1076 [names addObject:@"width"];
1077 [values addObject:[NSString stringWithFormat:@"%d", (int)theFrame.size.width]];
1079 if ([self valueForKey:@"height" keys:attributeNames values:attributeValues] == nil) {
1080 [names addObject:@"height"];
1081 [values addObject:[NSString stringWithFormat:@"%d", (int)theFrame.size.height]];
1083 view = [self pluginViewWithPackage:(WebPluginPackage *)pluginPackage
1084 attributeNames:names
1085 attributeValues:values
1091 } else if ([pluginPackage isKindOfClass:[WebNetscapePluginPackage class]]) {
1092 view = [[[WebNetscapePluginEmbeddedView alloc] initWithFrame:theFrame
1093 plugin:(WebNetscapePluginPackage *)pluginPackage
1097 attributeKeys:attributeNames
1098 attributeValues:attributeValues
1100 DOMElement:element] autorelease];
1102 ASSERT_NOT_REACHED();
1107 NSError *error = [[NSError alloc] _initWithPluginErrorCode:WebKitErrorJavaUnavailable
1110 pluginName:[pluginPackage name]
1112 view = [[[WebNullPluginView alloc] initWithFrame:theFrame error:error] autorelease];
1122 static BOOL loggedObjectCacheSize = NO;
1125 -(int)getObjectCacheSize
1127 vm_size_t memSize = WebSystemMainMemory();
1128 int cacheSize = [[self _preferences] _objectCacheSize];
1130 if (memSize >= 1024 * 1024 * 1024)
1132 else if (memSize >= 512 * 1024 * 1024)
1136 if (!loggedObjectCacheSize){
1137 LOG (CacheSizes, "Object cache size set to %d bytes.", cacheSize * multiplier);
1138 loggedObjectCacheSize = YES;
1142 return cacheSize * multiplier;
1145 - (ObjectElementType)determineObjectFromMIMEType:(NSString*)MIMEType URL:(NSURL*)URL
1147 if ([MIMEType length] == 0) {
1148 // Try to guess the MIME type based off the extension.
1149 NSString *extension = [[URL path] pathExtension];
1150 if ([extension length] > 0) {
1151 MIMEType = WKGetMIMETypeForExtension(extension);
1152 if ([MIMEType length] == 0 && [[self webView] _pluginForExtension:extension])
1153 // If no MIME type is specified, use a plug-in if we have one that can handle the extension.
1154 return ObjectElementPlugin;
1158 if ([MIMEType length] == 0)
1159 return ObjectElementFrame; // Go ahead and hope that we can display the content.
1161 if ([[self webView] _isMIMETypeRegisteredAsPlugin:MIMEType])
1162 return ObjectElementPlugin;
1164 if ([WebFrameView _viewClassForMIMEType:MIMEType])
1165 return ObjectElementFrame;
1167 return ObjectElementNone;
1170 - (void)loadEmptyDocumentSynchronously
1172 NSURL *url = [[NSURL alloc] initWithString:@""];
1173 NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
1174 [_frame loadRequest:request];
1179 - (NSString *)MIMETypeForPath:(NSString *)path
1182 NSString *extension = [path pathExtension];
1183 NSString *type = WKGetMIMETypeForExtension(extension);
1184 return [type length] == 0 ? (NSString *)@"application/octet-stream" : type;
1187 - (void)allowDHTMLDrag:(BOOL *)flagDHTML UADrag:(BOOL *)flagUA
1189 WebHTMLView *docView = (WebHTMLView *)[[_frame frameView] documentView];
1190 ASSERT([docView isKindOfClass:[WebHTMLView class]]);
1191 unsigned int mask = [docView _delegateDragSourceActionMask];
1192 *flagDHTML = (mask & WebDragSourceActionDHTML) != 0;
1193 *flagUA = ((mask & WebDragSourceActionImage) || (mask & WebDragSourceActionLink) || (mask & WebDragSourceActionSelection));
1196 - (BOOL)startDraggingImage:(NSImage *)dragImage at:(NSPoint)dragLoc operation:(NSDragOperation)op event:(NSEvent *)event sourceIsDHTML:(BOOL)flag DHTMLWroteData:(BOOL)dhtmlWroteData
1198 WebHTMLView *docView = (WebHTMLView *)[[_frame frameView] documentView];
1199 ASSERT([docView isKindOfClass:[WebHTMLView class]]);
1200 [docView _setInitiatedDrag:YES];
1201 return [docView _startDraggingImage:dragImage at:dragLoc operation:op event:event sourceIsDHTML:flag DHTMLWroteData:dhtmlWroteData];
1204 - (void)handleAutoscrollForMouseDragged:(NSEvent *)event;
1206 WebHTMLView *docView = (WebHTMLView *)[[_frame frameView] documentView];
1208 ASSERT([docView isKindOfClass:[WebHTMLView class]]);
1210 [docView _handleAutoscrollForMouseDragged:event];
1213 - (BOOL)mayStartDragAtEventLocation:(NSPoint)location
1215 WebHTMLView *docView = (WebHTMLView *)[[_frame frameView] documentView];
1217 ASSERT([docView isKindOfClass:[WebHTMLView class]]);
1219 return [docView _mayStartDragAtEventLocation:location];
1222 - (BOOL)selectWordBeforeMenuEvent
1224 return [[self webView] _selectWordBeforeMenuEvent];
1227 - (int)historyLength
1229 return [[[self webView] backForwardList] backListCount] + 1;
1232 - (BOOL)canGoBackOrForward:(int)distance
1237 if (distance > 0 && distance <= [[[self webView] backForwardList] forwardListCount])
1240 if (distance < 0 && -distance <= [[[self webView] backForwardList] backListCount])
1246 - (void)goBackOrForward:(int)distance
1248 if (distance == 0) {
1251 WebView *webView = [self webView];
1252 WebBackForwardList *list = [webView backForwardList];
1253 WebHistoryItem *item = [list itemAtIndex:distance];
1256 int forwardListCount = [list forwardListCount];
1257 if (forwardListCount > 0) {
1258 item = [list itemAtIndex:forwardListCount];
1261 int backListCount = [list forwardListCount];
1262 if (backListCount > 0) {
1263 item = [list itemAtIndex:-backListCount];
1268 [webView goToBackForwardItem:item];
1272 - (NSURL*)historyURL:(int)distance
1274 WebView *webView = [self webView];
1275 WebBackForwardList *list = [webView backForwardList];
1276 WebHistoryItem *item = [list itemAtIndex:distance];
1279 int forwardListCount = [list forwardListCount];
1280 if (forwardListCount > 0)
1281 item = [list itemAtIndex:forwardListCount];
1283 int backListCount = [list forwardListCount];
1284 if (backListCount > 0)
1285 item = [list itemAtIndex:-backListCount];
1294 static id <WebFormDelegate> formDelegate(WebFrameBridge *self)
1296 ASSERT(self->_frame != nil);
1297 return [[self->_frame webView] _formDelegate];
1300 #define FormDelegateLog(ctrl) LOG(FormDelegate, "control=%@", ctrl)
1302 - (void)textFieldDidBeginEditing:(DOMHTMLInputElement *)element
1304 FormDelegateLog(element);
1305 [formDelegate(self) textFieldDidBeginEditing:element inFrame:_frame];
1308 - (void)textFieldDidEndEditing:(DOMHTMLInputElement *)element
1310 FormDelegateLog(element);
1311 [formDelegate(self) textFieldDidEndEditing:element inFrame:_frame];
1314 - (void)textDidChangeInTextField:(DOMHTMLInputElement *)element
1316 FormDelegateLog(element);
1317 [formDelegate(self) textDidChangeInTextField:(DOMHTMLInputElement *)element inFrame:_frame];
1320 - (void)textDidChangeInTextArea:(DOMHTMLTextAreaElement *)element
1322 FormDelegateLog(element);
1323 [formDelegate(self) textDidChangeInTextArea:element inFrame:_frame];
1326 - (BOOL)textField:(DOMHTMLInputElement *)element doCommandBySelector:(SEL)commandSelector
1328 FormDelegateLog(element);
1329 return [formDelegate(self) textField:element doCommandBySelector:commandSelector inFrame:_frame];
1332 - (BOOL)textField:(DOMHTMLInputElement *)element shouldHandleEvent:(NSEvent *)event
1334 FormDelegateLog(element);
1335 return [formDelegate(self) textField:element shouldHandleEvent:event inFrame:_frame];
1338 - (void)frameDetached
1340 [_frame stopLoading];
1341 [_frame _detachFromParent];
1344 - (void)setHasBorder:(BOOL)hasBorder
1346 [[_frame frameView] _setHasBorder:hasBorder];
1349 - (NSFileWrapper *)fileWrapperForURL:(NSURL *)URL
1351 return [[_frame dataSource] _fileWrapperForURL:URL];
1356 id wd = [[self webView] UIDelegate];
1358 if ([wd respondsToSelector:@selector(webView:printFrameView:)]) {
1359 [wd webView:[self webView] printFrameView:[_frame frameView]];
1361 [[WebDefaultUIDelegate sharedUIDelegate] webView:[self webView] printFrameView:[_frame frameView]];
1365 - (jobject)getAppletInView:(NSView *)view
1369 if ([view respondsToSelector:@selector(webPlugInGetApplet)])
1370 applet = [view webPlugInGetApplet];
1372 applet = [self pollForAppletInView:view];
1377 // NOTE: pollForAppletInView: will block until the block is ready to use, or
1378 // until a timeout is exceeded. It will return nil if the timeour is
1380 // Deprecated, use getAppletInView:.
1381 - (jobject)pollForAppletInView:(NSView *)view
1385 if ([view respondsToSelector:@selector(pollForAppletInWindow:)]) {
1386 // The Java VM needs the containing window of the view to
1387 // initialize. The view may not yet be in the window's view
1388 // hierarchy, so we have to pass the window when requesting
1390 applet = [view pollForAppletInWindow:[[self webView] window]];
1396 - (void)respondToChangedContents
1398 NSView <WebDocumentView> *view = [[_frame frameView] documentView];
1399 if ([view isKindOfClass:[WebHTMLView class]]) {
1400 [(WebHTMLView *)view _updateFontPanel];
1402 [[NSNotificationCenter defaultCenter] postNotificationName:WebViewDidChangeNotification object:[self webView]];
1405 - (void)respondToChangedSelection
1407 NSView <WebDocumentView> *view = [[_frame frameView] documentView];
1408 if ([view isKindOfClass:[WebHTMLView class]]) {
1409 [(WebHTMLView *)view _selectionChanged];
1411 [[NSNotificationCenter defaultCenter] postNotificationName:WebViewDidChangeSelectionNotification object:[self webView]];
1414 - (NSUndoManager *)undoManager
1416 return [[self webView] undoManager];
1419 - (void)issueCutCommand
1421 NSView* documentView = [[_frame frameView] documentView];
1422 if ([documentView isKindOfClass:[WebHTMLView class]])
1423 [(WebHTMLView*)documentView cut:nil];
1426 - (void)issueCopyCommand
1428 NSView* documentView = [[_frame frameView] documentView];
1429 if ([documentView isKindOfClass:[WebHTMLView class]])
1430 [(WebHTMLView*)documentView copy:nil];
1433 - (void)issuePasteCommand
1435 NSView* documentView = [[_frame frameView] documentView];
1436 if ([documentView isKindOfClass:[WebHTMLView class]])
1437 [(WebHTMLView*)documentView paste:nil];
1440 - (void)issuePasteAndMatchStyleCommand
1442 NSView <WebDocumentView> *documentView = [[_frame frameView] documentView];
1443 if ([documentView isKindOfClass:[WebHTMLView class]])
1444 [(WebHTMLView*)documentView pasteAsPlainText:nil];
1447 - (void)issueTransposeCommand
1449 NSView <WebDocumentView> *view = [[_frame frameView] documentView];
1450 if ([view isKindOfClass:[WebHTMLView class]])
1451 [(WebHTMLView *)view transpose:nil];
1456 NSView* documentView = [[_frame frameView] documentView];
1457 return [documentView isKindOfClass:[WebHTMLView class]] && [(WebHTMLView*)documentView _canPaste];
1460 - (void)setIsSelected:(BOOL)isSelected forView:(NSView *)view
1462 if ([view respondsToSelector:@selector(webPlugInSetIsSelected:)]) {
1463 [view webPlugInSetIsSelected:isSelected];
1465 else if ([view respondsToSelector:@selector(setIsSelected:)]) {
1466 [view setIsSelected:isSelected];
1470 - (NSString *)overrideMediaType
1472 return [[self webView] mediaStyle];
1477 return [[self webView] isEditable];
1480 - (BOOL)shouldChangeSelectedDOMRange:(DOMRange *)currentRange toDOMRange:(DOMRange *)proposedRange affinity:(NSSelectionAffinity)selectionAffinity stillSelecting:(BOOL)flag
1482 return [[self webView] _shouldChangeSelectedDOMRange:currentRange toDOMRange:proposedRange affinity:selectionAffinity stillSelecting:flag];
1485 - (BOOL)shouldDeleteSelectedDOMRange:(DOMRange *)range
1487 WebView *webView = [self webView];
1488 return [[webView _editingDelegateForwarder] webView:webView shouldDeleteDOMRange:range];
1491 - (BOOL)shouldBeginEditing:(DOMRange *)range
1493 return [[self webView] _shouldBeginEditingInDOMRange:range];
1496 - (BOOL)shouldEndEditing:(DOMRange *)range
1498 return [[self webView] _shouldEndEditingInDOMRange:range];
1501 - (void)didBeginEditing
1503 [[NSNotificationCenter defaultCenter] postNotificationName:WebViewDidBeginEditingNotification object:[_frame webView]];
1506 - (void)didEndEditing
1508 [[NSNotificationCenter defaultCenter] postNotificationName:WebViewDidEndEditingNotification object:[_frame webView]];
1511 - (void)windowObjectCleared
1513 WebView *wv = [self webView];
1514 [[wv _frameLoadDelegateForwarder] webView:wv windowScriptObjectAvailable:[self windowScriptObject]];
1515 if ([wv scriptDebugDelegate] || [WebScriptDebugServer listenerCount]) {
1516 [_frame _detachScriptDebugger]; // FIXME: remove this once <rdar://problem/4608404> is fixed
1517 [_frame _attachScriptDebugger];
1521 - (int)spellCheckerDocumentTag
1523 return [[self webView] spellCheckerDocumentTag];
1526 - (BOOL)isContinuousSpellCheckingEnabled
1528 return [[self webView] isContinuousSpellCheckingEnabled];
1531 - (void)didFirstLayout
1533 [_loader didFirstLayout];
1536 - (BOOL)_compareDashboardRegions:(NSDictionary *)regions
1538 return [lastDashboardRegions isEqualToDictionary:regions];
1541 - (void)dashboardRegionsChanged:(NSMutableDictionary *)regions
1543 WebView *wv = [self webView];
1544 id wd = [wv UIDelegate];
1546 [wv _addScrollerDashboardRegions:regions];
1548 if (![self _compareDashboardRegions:regions]) {
1549 if ([wd respondsToSelector:@selector(webView:dashboardRegionsChanged:)]) {
1550 [wd webView:wv dashboardRegionsChanged:regions];
1551 [lastDashboardRegions release];
1552 lastDashboardRegions = [regions retain];
1557 - (NSRect)customHighlightRect:(NSString*)type forLine:(NSRect)lineRect
1559 ASSERT(_frame != nil);
1560 NSView *documentView = [[_frame frameView] documentView];
1561 if (![documentView isKindOfClass:[WebHTMLView class]])
1564 WebHTMLView *webHTMLView = (WebHTMLView *)documentView;
1565 id<WebHTMLHighlighter> highlighter = [webHTMLView _highlighterForType:type];
1566 return [highlighter highlightRectForLine:lineRect];
1569 - (void)paintCustomHighlight:(NSString*)type forBox:(NSRect)boxRect onLine:(NSRect)lineRect behindText:(BOOL)text
1570 entireLine:(BOOL)line
1572 ASSERT(_frame != nil);
1573 NSView *documentView = [[_frame frameView] documentView];
1574 if (![documentView isKindOfClass:[WebHTMLView class]])
1577 WebHTMLView *webHTMLView = (WebHTMLView *)documentView;
1578 id<WebHTMLHighlighter> highlighter = [webHTMLView _highlighterForType:type];
1579 [highlighter paintHighlightForBox:boxRect onLine:lineRect behindText:text entireLine:line];
1582 - (NSString *)nameForUndoAction:(WebUndoAction)undoAction
1584 switch (undoAction) {
1585 case WebUndoActionUnspecified: return nil;
1586 case WebUndoActionSetColor: return UI_STRING_KEY("Set Color", "Set Color (Undo action name)", "Undo action name");
1587 case WebUndoActionSetBackgroundColor: return UI_STRING_KEY("Set Background Color", "Set Background Color (Undo action name)", "Undo action name");
1588 case WebUndoActionTurnOffKerning: return UI_STRING_KEY("Turn Off Kerning", "Turn Off Kerning (Undo action name)", "Undo action name");
1589 case WebUndoActionTightenKerning: return UI_STRING_KEY("Tighten Kerning", "Tighten Kerning (Undo action name)", "Undo action name");
1590 case WebUndoActionLoosenKerning: return UI_STRING_KEY("Loosen Kerning", "Loosen Kerning (Undo action name)", "Undo action name");
1591 case WebUndoActionUseStandardKerning: return UI_STRING_KEY("Use Standard Kerning", "Use Standard Kerning (Undo action name)", "Undo action name");
1592 case WebUndoActionTurnOffLigatures: return UI_STRING_KEY("Turn Off Ligatures", "Turn Off Ligatures (Undo action name)", "Undo action name");
1593 case WebUndoActionUseStandardLigatures: return UI_STRING_KEY("Use Standard Ligatures", "Use Standard Ligatures (Undo action name)", "Undo action name");
1594 case WebUndoActionUseAllLigatures: return UI_STRING_KEY("Use All Ligatures", "Use All Ligatures (Undo action name)", "Undo action name");
1595 case WebUndoActionRaiseBaseline: return UI_STRING_KEY("Raise Baseline", "Raise Baseline (Undo action name)", "Undo action name");
1596 case WebUndoActionLowerBaseline: return UI_STRING_KEY("Lower Baseline", "Lower Baseline (Undo action name)", "Undo action name");
1597 case WebUndoActionSetTraditionalCharacterShape: return UI_STRING_KEY("Set Traditional Character Shape", "Set Traditional Character Shape (Undo action name)", "Undo action name");
1598 case WebUndoActionSetFont: return UI_STRING_KEY("Set Font", "Set Font (Undo action name)", "Undo action name");
1599 case WebUndoActionChangeAttributes: return UI_STRING_KEY("Change Attributes", "Change Attributes (Undo action name)", "Undo action name");
1600 case WebUndoActionAlignLeft: return UI_STRING_KEY("Align Left", "Align Left (Undo action name)", "Undo action name");
1601 case WebUndoActionAlignRight: return UI_STRING_KEY("Align Right", "Align Right (Undo action name)", "Undo action name");
1602 case WebUndoActionCenter: return UI_STRING_KEY("Center", "Center (Undo action name)", "Undo action name");
1603 case WebUndoActionJustify: return UI_STRING_KEY("Justify", "Justify (Undo action name)", "Undo action name");
1604 case WebUndoActionSetWritingDirection: return UI_STRING_KEY("Set Writing Direction", "Set Writing Direction (Undo action name)", "Undo action name");
1605 case WebUndoActionSubscript: return UI_STRING_KEY("Subscript", "Subscript (Undo action name)", "Undo action name");
1606 case WebUndoActionSuperscript: return UI_STRING_KEY("Superscript", "Superscript (Undo action name)", "Undo action name");
1607 case WebUndoActionUnderline: return UI_STRING_KEY("Underline", "Underline (Undo action name)", "Undo action name");
1608 case WebUndoActionOutline: return UI_STRING_KEY("Outline", "Outline (Undo action name)", "Undo action name");
1609 case WebUndoActionUnscript: return UI_STRING_KEY("Unscript", "Unscript (Undo action name)", "Undo action name");
1610 case WebUndoActionDrag: return UI_STRING_KEY("Drag", "Drag (Undo action name)", "Undo action name");
1611 case WebUndoActionCut: return UI_STRING_KEY("Cut", "Cut (Undo action name)", "Undo action name");
1612 case WebUndoActionPaste: return UI_STRING_KEY("Paste", "Paste (Undo action name)", "Undo action name");
1613 case WebUndoActionPasteFont: return UI_STRING_KEY("Paste Font", "Paste Font (Undo action name)", "Undo action name");
1614 case WebUndoActionPasteRuler: return UI_STRING_KEY("Paste Ruler", "Paste Ruler (Undo action name)", "Undo action name");
1615 case WebUndoActionTyping: return UI_STRING_KEY("Typing", "Typing (Undo action name)", "Undo action name");
1616 case WebUndoActionCreateLink: return UI_STRING_KEY("Create Link", "Create Link (Undo action name)", "Undo action name");
1617 case WebUndoActionUnlink: return UI_STRING_KEY("Unlink", "Unlink (Undo action name)", "Undo action name");
1618 case WebUndoActionInsertList: return UI_STRING_KEY("Insert List", "Insert List (Undo action name)", "Undo action name");
1619 case WebUndoActionFormatBlock: return UI_STRING_KEY("Formatting", "Format Block (Undo action name)", "Undo action name");
1620 case WebUndoActionIndent: return UI_STRING_KEY("Indent", "Indent (Undo action name)", "Undo action name");
1621 case WebUndoActionOutdent: return UI_STRING_KEY("Outdent", "Outdent (Undo action name)", "Undo action name");
1626 - (WebCorePageBridge *)createModalDialogWithURL:(NSURL *)URL
1628 ASSERT(_frame != nil);
1630 NSMutableURLRequest *request = nil;
1632 if (URL != nil && ![URL _web_isEmpty]) {
1633 request = [NSMutableURLRequest requestWithURL:URL];
1634 [request _web_setHTTPReferrer:[self referrer]];
1637 WebView *currentWebView = [self webView];
1638 id UIDelegate = [currentWebView UIDelegate];
1640 WebView *newWebView = nil;
1641 if ([UIDelegate respondsToSelector:@selector(webView:createWebViewModalDialogWithRequest:)])
1642 newWebView = [UIDelegate webView:currentWebView createWebViewModalDialogWithRequest:request];
1643 else if ([UIDelegate respondsToSelector:@selector(webView:createWebViewWithRequest:)])
1644 newWebView = [UIDelegate webView:currentWebView createWebViewWithRequest:request];
1646 newWebView = [[WebDefaultUIDelegate sharedUIDelegate] webView:currentWebView createWebViewWithRequest:request];
1648 return [newWebView _pageBridge];
1653 WebView *webView = [self webView];
1654 id UIDelegate = [webView UIDelegate];
1655 return [UIDelegate respondsToSelector:@selector(webViewRunModal:)];
1658 - (BOOL)canRunModalNow
1660 return [self canRunModal] && ![WebLoader inConnectionCallback];
1665 if (![self canRunModal])
1668 WebView *webView = [self webView];
1669 if ([webView defersCallbacks]) {
1670 LOG_ERROR("tried to run modal in a view when it was deferring callbacks -- should never happen");
1674 // Defer callbacks in all the other views in this group, so we don't try to run JavaScript
1675 // in a way that could interact with this view.
1676 NSMutableArray *deferredWebViews = [NSMutableArray array];
1677 NSString *namespace = [webView groupName];
1679 NSEnumerator *enumerator = [WebCoreFrameNamespaces framesInNamespace:namespace];
1680 WebView *otherWebView;
1681 while ((otherWebView = [[enumerator nextObject] webView]) != nil) {
1682 if (otherWebView != webView && ![otherWebView defersCallbacks]) {
1683 [otherWebView setDefersCallbacks:YES];
1684 [deferredWebViews addObject:otherWebView];
1689 // Go run the modal event loop.
1690 [[webView UIDelegate] webViewRunModal:webView];
1692 // Restore the callbacks for any views that we deferred them for.
1693 unsigned count = [deferredWebViews count];
1695 for (i = 0; i < count; ++i) {
1696 WebView *otherWebView = [deferredWebViews objectAtIndex:i];
1697 [otherWebView setDefersCallbacks:NO];
1701 - (void)handledOnloadEvents
1703 [_frame _handledOnloadEvents];
1708 [_frame _willCloseURL];
1712 - (NSURLResponse*)mainResourceURLResponse
1714 return [[_frame dataSource] response];
1717 - (NSString*)imageTitleForFilename:(NSString*)filename size:(NSSize)size
1719 return [NSString stringWithFormat:UI_STRING("%@ %.0f√ó%.0f pixels", "window title for a standalone image (uses multiplication symbol, not x)"), filename, size.width, size.height];
1722 - (void)notifyIconChanged:(NSURL*)iconURL
1724 [_loader _notifyIconChanged:iconURL];
1727 - (NSURL*)originalRequestURL
1729 return [[[_loader activeDataSource] initialRequest] URL];
1732 - (BOOL)isLoadTypeReload
1734 return [_loader loadType] == WebFrameLoadTypeReload;