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 "WebEditingDelegate.h"
38 #import "WebFormDataStream.h"
39 #import "WebFormDelegate.h"
40 #import "WebFrameInternal.h"
41 #import "WebFrameLoadDelegate.h"
42 #import "WebFrameLoader.h"
43 #import "WebFrameViewInternal.h"
44 #import "WebHTMLRepresentationPrivate.h"
45 #import "WebHTMLViewInternal.h"
46 #import "WebHistoryItemPrivate.h"
47 #import "WebIconDatabase.h"
48 #import <WebKit/WebIconDatabasePrivate.h>
49 #import "WebJavaPlugIn.h"
50 #import "WebJavaScriptTextInputPanel.h"
51 #import "WebKitErrorsPrivate.h"
52 #import "WebKitLogging.h"
53 #import "WebKitNSStringExtras.h"
54 #import "WebKitStatisticsPrivate.h"
55 #import "WebKitSystemBits.h"
57 #import "WebLocalizableStrings.h"
58 #import "WebNSObjectExtras.h"
59 #import "WebNSURLExtras.h"
60 #import "WebNSURLRequestExtras.h"
61 #import "WebNSViewExtras.h"
62 #import "WebNetscapePluginEmbeddedView.h"
63 #import "WebNetscapePluginPackage.h"
64 #import "WebNullPluginView.h"
65 #import "WebPageBridge.h"
67 #import "WebPluginController.h"
68 #import "WebPluginDatabase.h"
69 #import "WebPluginPackage.h"
70 #import "WebPluginViewFactoryPrivate.h"
71 #import "WebPreferencesPrivate.h"
72 #import "WebResourcePrivate.h"
73 #import "WebScriptDebugServerPrivate.h"
74 #import "WebSubresourceLoader.h"
75 #import "WebUIDelegatePrivate.h"
76 #import "WebViewInternal.h"
77 #import <Foundation/NSURLConnection.h>
78 #import <Foundation/NSURLRequest.h>
79 #import <Foundation/NSURLResponse.h>
80 #import <JavaVM/jni.h>
81 #import <WebCore/WebCoreFrameNamespaces.h>
82 #import <WebKitSystemInterface.h>
84 // For compatibility only with old SPI.
85 @interface NSObject (OldWebPlugin)
86 - (void)setIsSelected:(BOOL)f;
89 @interface NSApplication (DeclarationStolenFromAppKit)
90 - (void)_cycleWindowsReversed:(BOOL)reversed;
93 @interface NSView (AppKitSecretsWebBridgeKnowsAbout)
94 - (NSView *)_findLastViewInKeyViewLoop;
97 @interface NSURLResponse (FoundationSecretsWebBridgeKnowsAbout)
98 - (NSTimeInterval)_calculatedExpiration;
101 @interface NSView (JavaPluginSecrets)
102 - (jobject)pollForAppletInWindow:(NSWindow *)window;
105 NSString *WebPluginBaseURLKey = @"WebPluginBaseURL";
106 NSString *WebPluginAttributesKey = @"WebPluginAttributes";
107 NSString *WebPluginContainerKey = @"WebPluginContainer";
109 @implementation WebFrameBridge
113 ASSERT([[self page] isKindOfClass:[WebPageBridge class]]);
114 return [(WebPageBridge *)[self page] webView];
117 - (id)initMainFrameWithPage:(WebPageBridge *)page frameName:(NSString *)name view:(WebFrameView *)view
119 self = [super initMainFrameWithPage:page];
123 _frame = [[WebFrame alloc] _initWithWebFrameView:view webView:[self webView] bridge:self];
126 [self initializeSettings:[[self webView] _settings]];
127 [self setTextSizeMultiplier:[[self webView] textSizeMultiplier]];
132 - (id)initSubframeWithOwnerElement:(WebCoreElement *)ownerElement frameName:(NSString *)name view:(WebFrameView *)view
134 self = [super initSubframeWithOwnerElement:ownerElement];
138 _frame = [[WebFrame alloc] _initWithWebFrameView:view webView:[self webView] bridge:self];
141 [self initializeSettings:[[self webView] _settings]];
142 [self setTextSizeMultiplier:[[self webView] textSizeMultiplier]];
147 #define KeyboardUIModeDidChangeNotification @"com.apple.KeyboardUIModeDidChange"
148 #define AppleKeyboardUIMode CFSTR("AppleKeyboardUIMode")
149 #define UniversalAccessDomain CFSTR("com.apple.universalaccess")
153 if (_keyboardUIModeAccessed) {
154 [[NSDistributedNotificationCenter defaultCenter]
155 removeObserver:self name:KeyboardUIModeDidChangeNotification object:nil];
156 [[NSNotificationCenter defaultCenter]
157 removeObserver:self name:WebPreferencesChangedNotification object:nil];
159 ASSERT(_frame == nil);
165 [lastDashboardRegions release];
178 - (WebPreferences *)_preferences
180 return [[self webView] preferences];
183 - (void)_retrieveKeyboardUIModeFromPreferences:(NSNotification *)notification
185 CFPreferencesAppSynchronize(UniversalAccessDomain);
187 Boolean keyExistsAndHasValidFormat;
188 int mode = CFPreferencesGetAppIntegerValue(AppleKeyboardUIMode, UniversalAccessDomain, &keyExistsAndHasValidFormat);
190 // The keyboard access mode is reported by two bits:
191 // Bit 0 is set if feature is on
192 // Bit 1 is set if full keyboard access works for any control, not just text boxes and lists
193 // We require both bits to be on.
194 // I do not know that we would ever get one bit on and the other off since
195 // checking the checkbox in system preferences which is marked as "Turn on full keyboard access"
196 // turns on both bits.
197 _keyboardUIMode = (mode & 0x2) ? WebCoreKeyboardAccessFull : WebCoreKeyboardAccessDefault;
199 // check for tabbing to links
200 if ([[self _preferences] tabsToLinks]) {
201 _keyboardUIMode |= WebCoreKeyboardAccessTabsToLinks;
205 - (WebCoreKeyboardUIMode)keyboardUIMode
207 if (!_keyboardUIModeAccessed) {
208 _keyboardUIModeAccessed = YES;
209 [self _retrieveKeyboardUIModeFromPreferences:nil];
211 [[NSDistributedNotificationCenter defaultCenter]
212 addObserver:self selector:@selector(_retrieveKeyboardUIModeFromPreferences:)
213 name:KeyboardUIModeDidChangeNotification object:nil];
215 [[NSNotificationCenter defaultCenter]
216 addObserver:self selector:@selector(_retrieveKeyboardUIModeFromPreferences:)
217 name:WebPreferencesChangedNotification object:nil];
219 return _keyboardUIMode;
222 - (WebFrame *)webFrame
227 - (WebCoreFrameBridge *)mainFrame
229 ASSERT(_frame != nil);
230 return [[[self webView] mainFrame] _bridge];
233 - (NSView *)documentView
235 ASSERT(_frame != nil);
236 return [[_frame frameView] documentView];
239 - (WebCorePageBridge *)createWindowWithURL:(NSURL *)URL
241 ASSERT(_frame != nil);
243 NSMutableURLRequest *request = nil;
244 if (URL != nil && ![URL _web_isEmpty]) {
245 request = [NSMutableURLRequest requestWithURL:URL];
246 [request _web_setHTTPReferrer:[self referrer]];
249 WebView *currentWebView = [self webView];
250 id wd = [currentWebView UIDelegate];
252 if ([wd respondsToSelector:@selector(webView:createWebViewWithRequest:)])
253 newWebView = [wd webView:currentWebView createWebViewWithRequest:request];
255 newWebView = [[WebDefaultUIDelegate sharedUIDelegate] webView:currentWebView createWebViewWithRequest:request];
256 return [newWebView _pageBridge];
261 WebView *wv = [self webView];
262 [[wv _UIDelegateForwarder] webViewShow:wv];
265 - (BOOL)areToolbarsVisible
267 ASSERT(_frame != nil);
268 WebView *wv = [self webView];
269 id wd = [wv UIDelegate];
270 if ([wd respondsToSelector:@selector(webViewAreToolbarsVisible:)])
271 return [wd webViewAreToolbarsVisible:wv];
272 return [[WebDefaultUIDelegate sharedUIDelegate] webViewAreToolbarsVisible:wv];
275 - (void)setToolbarsVisible:(BOOL)visible
277 ASSERT(_frame != nil);
278 WebView *wv = [self webView];
279 [[wv _UIDelegateForwarder] webView:wv setToolbarsVisible:visible];
282 - (BOOL)areScrollbarsVisible
284 ASSERT(_frame != nil);
285 return [[_frame frameView] allowsScrolling];
288 - (void)setScrollbarsVisible:(BOOL)visible
290 ASSERT(_frame != nil);
291 [[_frame frameView] setAllowsScrolling:visible];
294 - (BOOL)isStatusbarVisible
296 ASSERT(_frame != nil);
297 WebView *wv = [self webView];
298 id wd = [wv UIDelegate];
299 if ([wd respondsToSelector:@selector(webViewIsStatusBarVisible:)])
300 return [wd webViewIsStatusBarVisible:wv];
301 return [[WebDefaultUIDelegate sharedUIDelegate] webViewIsStatusBarVisible:wv];
304 - (void)setStatusbarVisible:(BOOL)visible
306 ASSERT(_frame != nil);
307 WebView *wv = [self webView];
308 [[wv _UIDelegateForwarder] webView:wv setStatusBarVisible:visible];
311 - (void)setWindowIsResizable:(BOOL)resizable
313 ASSERT(_frame != nil);
314 WebView *webView = [self webView];
315 [[webView _UIDelegateForwarder] webView:webView setResizable:resizable];
318 - (BOOL)windowIsResizable
320 ASSERT(_frame != nil);
321 WebView *webView = [self webView];
322 return [[webView _UIDelegateForwarder] webViewIsResizable:webView];
325 - (NSResponder *)firstResponder
327 ASSERT(_frame != nil);
328 WebView *webView = [self webView];
329 return [[webView _UIDelegateForwarder] webViewFirstResponder:webView];
332 - (void)makeFirstResponder:(NSResponder *)view
334 ASSERT(_frame != nil);
335 WebView *webView = [self webView];
336 [webView _pushPerformingProgrammaticFocus];
337 [[webView _UIDelegateForwarder] webView:webView makeFirstResponder:view];
338 [webView _popPerformingProgrammaticFocus];
341 - (void)willMakeFirstResponderForNodeFocus
343 ASSERT([[[_frame frameView] documentView] isKindOfClass:[WebHTMLView class]]);
344 [(WebHTMLView *)[[_frame frameView] documentView] _willMakeFirstResponderForNodeFocus];
348 - (BOOL)textViewWasFirstResponderAtMouseDownTime:(NSTextView *)textView;
350 ASSERT(_frame != nil);
351 NSView *documentView = [[_frame frameView] documentView];
352 if (![documentView isKindOfClass:[WebHTMLView class]]) {
355 WebHTMLView *webHTMLView = (WebHTMLView *)documentView;
356 return [webHTMLView _textViewWasFirstResponderAtMouseDownTime:textView];
359 - (void)closeWindowSoon
361 WebView *parentWebView = [self webView];
363 // We need to remove the parent WebView from WebViewSets here, before it actually
364 // closes, to make sure that JavaScript code that executes before it closes
365 // can't find it. Otherwise, window.open will select a closed WebView instead of
366 // opening a new one <rdar://problem/3572585>.
368 // We also need to stop the load to prevent further parsing or JavaScript execution
369 // after the window has torn down <rdar://problem/4161660>.
371 // FIXME: This code assumes that the UI delegate will respond to a webViewClose
372 // message by actually closing the WebView. Safari guarantees this behavior, but other apps might not.
373 // This approach is an inherent limitation of not making a close execute immediately
374 // after a call to window.close.
376 [parentWebView setGroupName:nil];
377 [parentWebView stopLoading:self];
378 [parentWebView performSelector:@selector(_closeWindow) withObject:nil afterDelay:0.0];
383 ASSERT(_frame != nil);
384 return [[_frame frameView] window];
387 - (void)runJavaScriptAlertPanelWithMessage:(NSString *)message
389 WebView *wv = [self webView];
390 id wd = [wv UIDelegate];
391 // Check whether delegate implements new version, then whether delegate implements old version. If neither,
392 // fall back to shared delegate's implementation of new version.
393 if ([wd respondsToSelector:@selector(webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:)])
394 [wd webView:wv runJavaScriptAlertPanelWithMessage:message initiatedByFrame:_frame];
395 else if ([wd respondsToSelector:@selector(webView:runJavaScriptAlertPanelWithMessage:)])
396 [wd webView:wv runJavaScriptAlertPanelWithMessage:message];
398 [[WebDefaultUIDelegate sharedUIDelegate] webView:wv runJavaScriptAlertPanelWithMessage:message initiatedByFrame:_frame];
401 - (BOOL)runJavaScriptConfirmPanelWithMessage:(NSString *)message
403 WebView *wv = [self webView];
404 id wd = [wv UIDelegate];
405 // Check whether delegate implements new version, then whether delegate implements old version. If neither,
406 // fall back to shared delegate's implementation of new version.
407 if ([wd respondsToSelector:@selector(webView:runJavaScriptConfirmPanelWithMessage:initiatedByFrame:)])
408 return [wd webView:wv runJavaScriptConfirmPanelWithMessage:message initiatedByFrame:_frame];
409 if ([wd respondsToSelector:@selector(webView:runJavaScriptConfirmPanelWithMessage:)])
410 return [wd webView:wv runJavaScriptConfirmPanelWithMessage:message];
411 return [[WebDefaultUIDelegate sharedUIDelegate] webView:wv runJavaScriptConfirmPanelWithMessage:message initiatedByFrame:_frame];
414 - (BOOL)shouldInterruptJavaScript
416 WebView *wv = [self webView];
417 id wd = [wv UIDelegate];
419 if ([wd respondsToSelector:@selector(webViewShouldInterruptJavaScript:)])
420 return [wd webViewShouldInterruptJavaScript:wv];
424 - (BOOL)canRunBeforeUnloadConfirmPanel
426 WebView *wv = [self webView];
427 id wd = [wv UIDelegate];
428 return [wd respondsToSelector:@selector(webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:)];
431 - (BOOL)runBeforeUnloadConfirmPanelWithMessage:(NSString *)message
433 WebView *wv = [self webView];
434 id wd = [wv UIDelegate];
435 if ([wd respondsToSelector:@selector(webView:runBeforeUnloadConfirmPanelWithMessage:initiatedByFrame:)])
436 return [wd webView:wv runBeforeUnloadConfirmPanelWithMessage:message initiatedByFrame:_frame];
440 - (BOOL)runJavaScriptTextInputPanelWithPrompt:(NSString *)prompt defaultText:(NSString *)defaultText returningText:(NSString **)result
442 WebView *wv = [self webView];
443 id wd = [wv UIDelegate];
444 // Check whether delegate implements new version, then whether delegate implements old version. If neither,
445 // fall back to shared delegate's implementation of new version.
446 if ([wd respondsToSelector:@selector(webView:runJavaScriptTextInputPanelWithPrompt:defaultText:initiatedByFrame:)])
447 *result = [wd webView:wv runJavaScriptTextInputPanelWithPrompt:prompt defaultText:defaultText initiatedByFrame:_frame];
448 else if ([wd respondsToSelector:@selector(webView:runJavaScriptTextInputPanelWithPrompt:defaultText:)])
449 *result = [wd webView:wv runJavaScriptTextInputPanelWithPrompt:prompt defaultText:defaultText];
451 *result = [[WebDefaultUIDelegate sharedUIDelegate] webView:wv runJavaScriptTextInputPanelWithPrompt:prompt defaultText:defaultText initiatedByFrame:_frame];
452 return *result != nil;
455 - (void)addMessageToConsole:(NSDictionary *)message
457 WebView *wv = [self webView];
458 id wd = [wv UIDelegate];
459 if ([wd respondsToSelector:@selector(webView:addMessageToConsole:)])
460 [wd webView:wv addMessageToConsole:message];
463 - (void)runOpenPanelForFileButtonWithResultListener:(id<WebCoreOpenPanelResultListener>)resultListener
465 WebView *wv = [self webView];
466 [[wv _UIDelegateForwarder] webView:wv runOpenPanelForFileButtonWithResultListener:(id<WebOpenPanelResultListener>)resultListener];
469 - (WebDataSource *)dataSource
471 ASSERT(_frame != nil);
472 WebDataSource *dataSource = [_frame dataSource];
474 ASSERT(dataSource != nil);
479 - (void)setTitle:(NSString *)title
481 [[[_frame _frameLoader] documentLoadState] setTitle:[title _webkit_stringByCollapsingNonPrintingCharacters]];
484 - (void)setStatusText:(NSString *)status
486 ASSERT(_frame != nil);
487 WebView *wv = [self webView];
488 [[wv _UIDelegateForwarder] webView:wv setStatusText:status];
491 - (void)receivedData:(NSData *)data textEncodingName:(NSString *)textEncodingName
493 // Set the encoding. This only needs to be done once, but it's harmless to do it again later.
494 NSString *encoding = [[[_frame _frameLoader] documentLoadState] overrideEncoding];
495 BOOL userChosen = encoding != nil;
496 if (encoding == nil) {
497 encoding = textEncodingName;
499 [self setEncoding:encoding userChosen:userChosen];
504 - (id <WebCoreResourceHandle>)startLoadingResource:(id <WebCoreResourceLoader>)resourceLoader withMethod:(NSString *)method URL:(NSURL *)URL customHeaders:(NSDictionary *)customHeaders
506 // If we are no longer attached to a WebView, this must be an attempted load from an
507 // onUnload handler, so let's just block it.
508 if ([[self webFrame] webView] == nil)
511 // Since this is a subresource, we can load any URL (we ignore the return value).
512 // But we still want to know whether we should hide the referrer or not, so we call the canLoadURL method.
514 [self canLoadURL:URL fromReferrer:[self referrer] hideReferrer:&hideReferrer];
516 return [WebSubresourceLoader startLoadingResource:resourceLoader
519 customHeaders:customHeaders
520 referrer:(hideReferrer ? nil : [self referrer])
521 forFrameLoader:[[self webFrame] _frameLoader]];
524 - (id <WebCoreResourceHandle>)startLoadingResource:(id <WebCoreResourceLoader>)resourceLoader withMethod:(NSString *)method URL:(NSURL *)URL customHeaders:(NSDictionary *)customHeaders postData:(NSArray *)postData
526 // If we are no longer attached to a WebView, this must be an attempted load from an
527 // onUnload handler, so let's just block it.
528 if ([[self webFrame] webView] == nil)
531 // Since this is a subresource, we can load any URL (we ignore the return value).
532 // But we still want to know whether we should hide the referrer or not, so we call the canLoadURL method.
534 [self canLoadURL:URL fromReferrer:[self referrer] hideReferrer:&hideReferrer];
536 return [WebSubresourceLoader startLoadingResource:resourceLoader
539 customHeaders:customHeaders
541 referrer:(hideReferrer ? nil : [self referrer])
542 forFrameLoader:[[self webFrame] _frameLoader]];
545 - (void)objectLoadedFromCacheWithURL:(NSURL *)URL response:(NSURLResponse *)response data:(NSData *)data
547 // FIXME: If the WebKit client changes or cancels the request, WebCore does not respect this and continues the load.
550 NSURLRequest *request = [[NSURLRequest alloc] initWithURL:URL];
551 [_frame _requestFromDelegateForRequest:request identifier:&identifier error:&error];
552 [_frame _sendRemainingDelegateMessagesWithIdentifier:identifier response:response length:[data length] error:error];
556 - (NSData *)syncLoadResourceWithMethod:(NSString *)method URL:(NSURL *)URL customHeaders:(NSDictionary *)requestHeaders postData:(NSArray *)postData finalURL:(NSURL **)finalURL responseHeaders:(NSDictionary **)responseHeaderDict statusCode:(int *)statusCode
558 // Since this is a subresource, we can load any URL (we ignore the return value).
559 // But we still want to know whether we should hide the referrer or not, so we call the canLoadURL method.
561 [self canLoadURL:URL fromReferrer:[self referrer] hideReferrer:&hideReferrer];
563 NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:URL];
564 [request setTimeoutInterval:10];
566 // setHTTPMethod is not called for GET requests to work around <rdar://4464032>.
567 if (![method isEqualToString:@"GET"])
568 [request setHTTPMethod:method];
571 webSetHTTPBody(request, postData);
573 NSEnumerator *e = [requestHeaders keyEnumerator];
575 while ((key = (NSString *)[e nextObject]) != nil) {
576 [request addValue:[requestHeaders objectForKey:key] forHTTPHeaderField:key];
579 if ([request _web_isConditionalRequest])
580 [request setCachePolicy:NSURLRequestReloadIgnoringCacheData];
582 [request setCachePolicy:[[[self dataSource] request] cachePolicy]];
584 [request _web_setHTTPReferrer:[self referrer]];
586 WebView *webView = [self webView];
587 [request setMainDocumentURL:[[[[webView mainFrame] dataSource] request] URL]];
588 [request _web_setHTTPUserAgent:[webView userAgentForURL:[request URL]]];
590 NSError *error = nil;
592 NSURLRequest *newRequest = [_frame _requestFromDelegateForRequest:request identifier:&identifier error:&error];
594 NSURLResponse *response = nil;
595 NSData *result = nil;
597 ASSERT(newRequest != nil);
598 result = [NSURLConnection sendSynchronousRequest:newRequest returningResponse:&response error:&error];
602 *finalURL = [response URL];
603 if ([response isKindOfClass:[NSHTTPURLResponse class]]) {
604 NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
605 *responseHeaderDict = [httpResponse allHeaderFields];
606 *statusCode = [httpResponse statusCode];
608 *responseHeaderDict = [NSDictionary dictionary];
613 *responseHeaderDict = [NSDictionary dictionary];
614 if ([error domain] == NSURLErrorDomain) {
615 *statusCode = [error code];
621 [_frame _sendRemainingDelegateMessagesWithIdentifier:identifier response:response length:[result length] error:error];
629 return [[[self dataSource] request] cachePolicy] == NSURLRequestReloadIgnoringCacheData;
632 // We would like a better value for a maximum time_t,
633 // but there is no way to do that in C with any certainty.
634 // INT_MAX should work well enough for our purposes.
635 #define MAX_TIME_T ((time_t)INT_MAX)
637 - (time_t)expiresTimeForResponse:(NSURLResponse *)response
639 // This check can be removed when the new Foundation method
640 // has been around long enough for everyone to have it.
641 ASSERT([response respondsToSelector:@selector(_calculatedExpiration)]);
643 NSTimeInterval expiration = [response _calculatedExpiration];
644 expiration += kCFAbsoluteTimeIntervalSince1970;
646 return expiration > MAX_TIME_T ? MAX_TIME_T : (time_t)expiration;
649 - (void)reportClientRedirectToURL:(NSURL *)URL delay:(NSTimeInterval)seconds fireDate:(NSDate *)date lockHistory:(BOOL)lockHistory isJavaScriptFormAction:(BOOL)isJavaScriptFormAction
651 [_frame _clientRedirectedTo:URL delay:seconds fireDate:date lockHistory:lockHistory isJavaScriptFormAction:(BOOL)isJavaScriptFormAction];
654 - (void)reportClientRedirectCancelled:(BOOL)cancelWithLoadInProgress
656 [_frame _clientRedirectCancelledOrFinished:cancelWithLoadInProgress];
666 - (void)activateWindow
668 [[[self webView] _UIDelegateForwarder] webViewFocus:[self webView]];
671 - (void)deactivateWindow
673 [[[self webView] _UIDelegateForwarder] webViewUnfocus:[self webView]];
676 - (void)formControlIsBecomingFirstResponder:(NSView *)formControl
678 // When a form element becomes first responder, its enclosing WebHTMLView might need to
679 // change its focus-displaying state, but isn't otherwise notified.
680 [(WebHTMLView *)[[_frame frameView] documentView] _formControlIsBecomingFirstResponder:formControl];
683 - (void)formControlIsResigningFirstResponder:(NSView *)formControl
685 // When a form element resigns first responder, its enclosing WebHTMLView might need to
686 // change its focus-displaying state, but isn't otherwise notified.
687 [(WebHTMLView *)[[_frame frameView] documentView] _formControlIsResigningFirstResponder:formControl];
690 - (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
693 if (![self canLoadURL:URL fromReferrer:referrer hideReferrer:&hideReferrer])
696 if ([target length] == 0) {
700 WebFrame *targetFrame = [_frame findFrameNamed:target];
701 if (![self canTargetLoadInFrame:[targetFrame _bridge]]) {
705 WebFrameLoadType loadType;
708 loadType = WebFrameLoadTypeReload;
710 loadType = WebFrameLoadTypeInternal;
712 loadType = WebFrameLoadTypeStandard;
713 [_frame _loadURL:URL referrer:(hideReferrer ? nil : referrer) loadType:loadType target:target triggeringEvent:event form:form formValues:values];
715 if (targetFrame != nil && _frame != targetFrame) {
716 [[targetFrame _bridge] activateWindow];
720 - (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
723 if (![self canLoadURL:URL fromReferrer:referrer hideReferrer:&hideReferrer])
726 if ([target length] == 0) {
730 WebFrame *targetFrame = [_frame findFrameNamed:target];
731 if (![self canTargetLoadInFrame:[targetFrame _bridge]]) {
735 [_frame _postWithURL:URL referrer:(hideReferrer ? nil : referrer) target:target data:postData contentType:contentType triggeringEvent:event form:form formValues:values];
737 if (targetFrame != nil && _frame != targetFrame) {
738 [[targetFrame _bridge] activateWindow];
742 - (WebCoreFrameBridge *)createChildFrameNamed:(NSString *)frameName
744 referrer:(NSString *)referrer
745 ownerElement:(WebCoreElement *)ownerElement
746 allowsScrolling:(BOOL)allowsScrolling
747 marginWidth:(int)width
748 marginHeight:(int)height
751 if (![self canLoadURL:URL fromReferrer:referrer hideReferrer:&hideReferrer])
756 WebFrameView *childView = [[WebFrameView alloc] initWithFrame:NSMakeRect(0,0,0,0)];
757 [childView setAllowsScrolling:allowsScrolling];
758 WebFrameBridge *newBridge = [[WebFrameBridge alloc] initSubframeWithOwnerElement:ownerElement frameName:frameName view:childView];
759 [_frame _addChild:[newBridge webFrame]];
762 [childView _setMarginWidth:width];
763 [childView _setMarginHeight:height];
770 [_frame _loadURL:URL referrer:(hideReferrer ? nil : referrer) intoChild:[newBridge webFrame]];
775 - (void)saveDocumentState:(NSArray *)documentState
777 WebHistoryItem *item = [_frame _itemForSavingDocState];
778 LOG(Loading, "%@: saving form state from to 0x%x", [_frame name], item);
780 [item setDocumentState:documentState];
781 // You might think we could save the scroll state here too, but unfortunately this
782 // often gets called after WebFrame::_transitionToCommitted has restored the scroll
783 // position of the next document.
787 - (NSArray *)documentState
789 LOG(Loading, "%@: restoring form state from item 0x%x", [_frame name], [_frame _itemForRestoringDocState]);
790 return [[_frame _itemForRestoringDocState] documentState];
793 - (BOOL)saveDocumentToPageCache:(id)documentInfo
795 WebHistoryItem *item = [_frame _itemForSavingDocState];
796 if (![item hasPageCache]) {
799 [[item pageCache] setObject:documentInfo forKey:WebCorePageCacheStateKey];
803 - (NSString *)userAgentForURL:(NSURL *)URL
805 return [[self webView] userAgentForURL:URL];
808 - (BOOL)inNextKeyViewOutsideWebFrameViews
810 return _inNextKeyViewOutsideWebFrameViews;
813 - (NSView *)_nextKeyViewOutsideWebFrameViewsWithValidityCheck:(BOOL)mustBeValid
815 // We can get here in unusual situations such as the one listed in 4451831, so we
816 // return nil to avoid an infinite recursion.
817 if (_inNextKeyViewOutsideWebFrameViews)
820 _inNextKeyViewOutsideWebFrameViews = YES;
821 WebView *webView = [self webView];
822 // Do not ask webView for its next key view, but rather, ask it for
823 // the next key view of the last view in its key view loop.
824 // Doing so gives us the correct answer as calculated by AppKit,
825 // and makes HTML views behave like other views.
826 NSView *lastViewInLoop = [webView _findLastViewInKeyViewLoop];
827 NSView *nextKeyView = mustBeValid ? [lastViewInLoop nextValidKeyView] : [lastViewInLoop nextKeyView];
828 _inNextKeyViewOutsideWebFrameViews = NO;
832 - (NSView *)nextKeyViewOutsideWebFrameViews
834 return [self _nextKeyViewOutsideWebFrameViewsWithValidityCheck:NO];
837 - (NSView *)nextValidKeyViewOutsideWebFrameViews
839 return [self _nextKeyViewOutsideWebFrameViewsWithValidityCheck:YES];
842 - (NSView *)previousKeyViewOutsideWebFrameViews
844 WebView *webView = [self webView];
845 NSView *previousKeyView = [webView previousKeyView];
846 return previousKeyView;
849 - (BOOL)defersLoading
851 return [[self webView] defersCallbacks];
854 - (void)setDefersLoading:(BOOL)defers
856 [[self webView] setDefersCallbacks:defers];
859 - (void)setNeedsReapplyStyles
861 NSView <WebDocumentView> *view = [[_frame frameView] documentView];
862 if ([view isKindOfClass:[WebHTMLView class]]) {
863 [(WebHTMLView *)view setNeedsToApplyStyles:YES];
864 [view setNeedsLayout:YES];
865 [view setNeedsDisplay:YES];
869 - (void)tokenizerProcessedData
871 [_frame _checkLoadComplete];
874 - (NSString *)incomingReferrer
876 return [[[self dataSource] request] _web_HTTPReferrer];
879 - (NSView *)pluginViewWithPackage:(WebPluginPackage *)pluginPackage
880 attributeNames:(NSArray *)attributeNames
881 attributeValues:(NSArray *)attributeValues
882 baseURL:(NSURL *)baseURL
883 DOMElement:(DOMElement *)element
884 loadManually:(BOOL)loadManually
886 WebHTMLView *docView = (WebHTMLView *)[[_frame frameView] documentView];
887 ASSERT([docView isKindOfClass:[WebHTMLView class]]);
889 WebPluginController *pluginController = [docView _pluginController];
891 // Store attributes in a dictionary so they can be passed to WebPlugins.
892 NSMutableDictionary *attributes = [[NSMutableDictionary alloc] initWithObjects:attributeValues forKeys:attributeNames];
894 [pluginPackage load];
895 Class viewFactory = [pluginPackage viewFactory];
898 NSDictionary *arguments = nil;
900 if ([viewFactory respondsToSelector:@selector(plugInViewWithArguments:)]) {
901 arguments = [NSDictionary dictionaryWithObjectsAndKeys:
902 baseURL, WebPlugInBaseURLKey,
903 attributes, WebPlugInAttributesKey,
904 pluginController, WebPlugInContainerKey,
905 [NSNumber numberWithInt:loadManually ? WebPlugInModeFull : WebPlugInModeEmbed], WebPlugInModeKey,
906 [NSNumber numberWithBool:!loadManually], WebPlugInShouldLoadMainResourceKey,
907 element, WebPlugInContainingElementKey,
909 LOG(Plugins, "arguments:\n%@", arguments);
910 } else if ([viewFactory respondsToSelector:@selector(pluginViewWithArguments:)]) {
911 arguments = [NSDictionary dictionaryWithObjectsAndKeys:
912 baseURL, WebPluginBaseURLKey,
913 attributes, WebPluginAttributesKey,
914 pluginController, WebPluginContainerKey,
915 element, WebPlugInContainingElementKey,
917 LOG(Plugins, "arguments:\n%@", arguments);
920 view = [WebPluginController plugInViewWithArguments:arguments fromPluginPackage:pluginPackage];
922 [attributes release];
926 - (NSString *)valueForKey:(NSString *)key keys:(NSArray *)keys values:(NSArray *)values
928 unsigned count = [keys count];
930 for (i = 0; i < count; i++) {
931 if ([[keys objectAtIndex:i] _webkit_isCaseInsensitiveEqualToString:key])
932 return [values objectAtIndex:i];
937 - (NSView *)viewForPluginWithURL:(NSURL *)URL
938 attributeNames:(NSArray *)attributeNames
939 attributeValues:(NSArray *)attributeValues
940 MIMEType:(NSString *)MIMEType
941 DOMElement:(DOMElement *)element
942 loadManually:(BOOL)loadManually
945 if (![self canLoadURL:URL fromReferrer:[self referrer] hideReferrer:&hideReferrer])
948 ASSERT([attributeNames count] == [attributeValues count]);
950 WebBasePluginPackage *pluginPackage = nil;
954 WebView *wv = [self webView];
955 id wd = [wv UIDelegate];
957 if ([wd respondsToSelector:@selector(webView:plugInViewWithArguments:)]) {
958 NSMutableDictionary *attributes = [[NSMutableDictionary alloc] initWithObjects:attributeValues forKeys:attributeNames];
959 NSDictionary *arguments = [NSDictionary dictionaryWithObjectsAndKeys:
960 attributes, WebPlugInAttributesKey,
961 [NSNumber numberWithInt:loadManually ? WebPlugInModeFull : WebPlugInModeEmbed], WebPlugInModeKey,
962 URL, WebPlugInBaseURLKey, // URL might be nil, so add it last
963 [NSNumber numberWithBool:!loadManually], WebPlugInShouldLoadMainResourceKey,
964 element, WebPlugInContainingElementKey,
966 [attributes release];
967 view = [wd webView:wv plugInViewWithArguments:arguments];
972 if ([MIMEType length] != 0)
973 pluginPackage = [[self webView] _pluginForMIMEType:MIMEType];
977 NSString *extension = [[URL path] pathExtension];
978 if (!pluginPackage && [extension length] != 0) {
979 pluginPackage = [[self webView] _pluginForExtension:extension];
981 NSString *newMIMEType = [pluginPackage MIMETypeForExtension:extension];
982 if ([newMIMEType length] != 0)
983 MIMEType = newMIMEType;
987 NSURL *baseURL = [self baseURL];
989 if ([pluginPackage isKindOfClass:[WebPluginPackage class]]) {
990 view = [self pluginViewWithPackage:(WebPluginPackage *)pluginPackage
991 attributeNames:attributeNames
992 attributeValues:attributeValues
995 loadManually:loadManually];
996 } else if ([pluginPackage isKindOfClass:[WebNetscapePluginPackage class]]) {
997 WebNetscapePluginEmbeddedView *embeddedView = [[[WebNetscapePluginEmbeddedView alloc] initWithFrame:NSZeroRect
998 plugin:(WebNetscapePluginPackage *)pluginPackage
1002 attributeKeys:attributeNames
1003 attributeValues:attributeValues
1004 loadManually:loadManually
1005 DOMElement:element] autorelease];
1006 view = embeddedView;
1007 [_frame _addPlugInView:embeddedView];
1009 ASSERT_NOT_REACHED();
1011 errorCode = WebKitErrorCannotFindPlugIn;
1013 if (!errorCode && !view)
1014 errorCode = WebKitErrorCannotLoadPlugIn;
1017 NSString *pluginPage = [self valueForKey:@"pluginspage" keys:attributeNames values:attributeValues];
1018 NSURL *pluginPageURL = pluginPage != nil ? [self URLWithAttributeString:pluginPage] : nil;
1019 NSError *error = [[NSError alloc] _initWithPluginErrorCode:errorCode
1021 pluginPageURL:pluginPageURL
1022 pluginName:[pluginPackage name]
1024 WebNullPluginView *nullView = [[[WebNullPluginView alloc] initWithFrame:NSZeroRect error:error] autorelease];
1025 [_frame _addPlugInView:nullView];
1034 - (void)redirectDataToPlugin:(NSView *)pluginView
1036 WebHTMLRepresentation *representation = (WebHTMLRepresentation *)[[_frame dataSource] representation];
1038 if ([pluginView isKindOfClass:[WebNetscapePluginEmbeddedView class]])
1039 [representation _redirectDataToManualLoader:(WebNetscapePluginEmbeddedView *)pluginView forPluginView:pluginView];
1041 WebHTMLView *docView = (WebHTMLView *)[[_frame frameView] documentView];
1042 ASSERT([docView isKindOfClass:[WebHTMLView class]]);
1044 WebPluginController *pluginController = [docView _pluginController];
1045 [representation _redirectDataToManualLoader:pluginController forPluginView:pluginView];
1049 - (NSView *)viewForJavaAppletWithFrame:(NSRect)theFrame
1050 attributeNames:(NSArray *)attributeNames
1051 attributeValues:(NSArray *)attributeValues
1052 baseURL:(NSURL *)baseURL
1053 DOMElement:(DOMElement *)element
1055 NSString *MIMEType = @"application/x-java-applet";
1056 WebBasePluginPackage *pluginPackage;
1059 pluginPackage = [[self webView] _pluginForMIMEType:MIMEType];
1061 if (pluginPackage) {
1062 if ([pluginPackage isKindOfClass:[WebPluginPackage class]]) {
1063 // For some reason, the Java plug-in requires that we pass the dimension of the plug-in as attributes.
1064 NSMutableArray *names = [attributeNames mutableCopy];
1065 NSMutableArray *values = [attributeValues mutableCopy];
1066 if ([self valueForKey:@"width" keys:attributeNames values:attributeValues] == nil) {
1067 [names addObject:@"width"];
1068 [values addObject:[NSString stringWithFormat:@"%d", (int)theFrame.size.width]];
1070 if ([self valueForKey:@"height" keys:attributeNames values:attributeValues] == nil) {
1071 [names addObject:@"height"];
1072 [values addObject:[NSString stringWithFormat:@"%d", (int)theFrame.size.height]];
1074 view = [self pluginViewWithPackage:(WebPluginPackage *)pluginPackage
1075 attributeNames:names
1076 attributeValues:values
1082 } else if ([pluginPackage isKindOfClass:[WebNetscapePluginPackage class]]) {
1083 view = [[[WebNetscapePluginEmbeddedView alloc] initWithFrame:theFrame
1084 plugin:(WebNetscapePluginPackage *)pluginPackage
1088 attributeKeys:attributeNames
1089 attributeValues:attributeValues
1091 DOMElement:element] autorelease];
1093 ASSERT_NOT_REACHED();
1098 NSError *error = [[NSError alloc] _initWithPluginErrorCode:WebKitErrorJavaUnavailable
1101 pluginName:[pluginPackage name]
1103 view = [[[WebNullPluginView alloc] initWithFrame:theFrame error:error] autorelease];
1113 static BOOL loggedObjectCacheSize = NO;
1116 -(int)getObjectCacheSize
1118 vm_size_t memSize = WebSystemMainMemory();
1119 int cacheSize = [[self _preferences] _objectCacheSize];
1121 if (memSize >= 1024 * 1024 * 1024)
1123 else if (memSize >= 512 * 1024 * 1024)
1127 if (!loggedObjectCacheSize){
1128 LOG (CacheSizes, "Object cache size set to %d bytes.", cacheSize * multiplier);
1129 loggedObjectCacheSize = YES;
1133 return cacheSize * multiplier;
1136 - (ObjectElementType)determineObjectFromMIMEType:(NSString*)MIMEType URL:(NSURL*)URL
1138 if ([MIMEType length] == 0) {
1139 // Try to guess the MIME type based off the extension.
1140 NSString *extension = [[URL path] pathExtension];
1141 if ([extension length] > 0) {
1142 MIMEType = WKGetMIMETypeForExtension(extension);
1143 if ([MIMEType length] == 0 && [[self webView] _pluginForExtension:extension])
1144 // If no MIME type is specified, use a plug-in if we have one that can handle the extension.
1145 return ObjectElementPlugin;
1149 if ([MIMEType length] == 0)
1150 return ObjectElementFrame; // Go ahead and hope that we can display the content.
1152 if ([[self webView] _isMIMETypeRegisteredAsPlugin:MIMEType])
1153 return ObjectElementPlugin;
1155 if ([WebFrameView _viewClassForMIMEType:MIMEType])
1156 return ObjectElementFrame;
1158 return ObjectElementNone;
1161 - (void)loadEmptyDocumentSynchronously
1163 NSURL *url = [[NSURL alloc] initWithString:@""];
1164 NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
1165 [_frame loadRequest:request];
1170 - (NSString *)MIMETypeForPath:(NSString *)path
1173 NSString *extension = [path pathExtension];
1174 NSString *type = WKGetMIMETypeForExtension(extension);
1175 return [type length] == 0 ? (NSString *)@"application/octet-stream" : type;
1178 - (void)allowDHTMLDrag:(BOOL *)flagDHTML UADrag:(BOOL *)flagUA
1180 WebHTMLView *docView = (WebHTMLView *)[[_frame frameView] documentView];
1181 ASSERT([docView isKindOfClass:[WebHTMLView class]]);
1182 unsigned int mask = [docView _delegateDragSourceActionMask];
1183 *flagDHTML = (mask & WebDragSourceActionDHTML) != 0;
1184 *flagUA = ((mask & WebDragSourceActionImage) || (mask & WebDragSourceActionLink) || (mask & WebDragSourceActionSelection));
1187 - (BOOL)startDraggingImage:(NSImage *)dragImage at:(NSPoint)dragLoc operation:(NSDragOperation)op event:(NSEvent *)event sourceIsDHTML:(BOOL)flag DHTMLWroteData:(BOOL)dhtmlWroteData
1189 WebHTMLView *docView = (WebHTMLView *)[[_frame frameView] documentView];
1190 ASSERT([docView isKindOfClass:[WebHTMLView class]]);
1191 [docView _setInitiatedDrag:YES];
1192 return [docView _startDraggingImage:dragImage at:dragLoc operation:op event:event sourceIsDHTML:flag DHTMLWroteData:dhtmlWroteData];
1195 - (void)handleAutoscrollForMouseDragged:(NSEvent *)event;
1197 WebHTMLView *docView = (WebHTMLView *)[[_frame frameView] documentView];
1199 ASSERT([docView isKindOfClass:[WebHTMLView class]]);
1201 [docView _handleAutoscrollForMouseDragged:event];
1204 - (BOOL)mayStartDragAtEventLocation:(NSPoint)location
1206 WebHTMLView *docView = (WebHTMLView *)[[_frame frameView] documentView];
1208 ASSERT([docView isKindOfClass:[WebHTMLView class]]);
1210 return [docView _mayStartDragAtEventLocation:location];
1213 - (BOOL)selectWordBeforeMenuEvent
1215 return [[self webView] _selectWordBeforeMenuEvent];
1218 - (int)historyLength
1220 return [[[self webView] backForwardList] backListCount] + 1;
1223 - (BOOL)canGoBackOrForward:(int)distance
1228 if (distance > 0 && distance <= [[[self webView] backForwardList] forwardListCount])
1231 if (distance < 0 && -distance <= [[[self webView] backForwardList] backListCount])
1237 - (void)goBackOrForward:(int)distance
1239 if (distance == 0) {
1242 WebView *webView = [self webView];
1243 WebBackForwardList *list = [webView backForwardList];
1244 WebHistoryItem *item = [list itemAtIndex:distance];
1247 int forwardListCount = [list forwardListCount];
1248 if (forwardListCount > 0) {
1249 item = [list itemAtIndex:forwardListCount];
1252 int backListCount = [list forwardListCount];
1253 if (backListCount > 0) {
1254 item = [list itemAtIndex:-backListCount];
1259 [webView goToBackForwardItem:item];
1263 - (NSURL*)historyURL:(int)distance
1265 WebView *webView = [self webView];
1266 WebBackForwardList *list = [webView backForwardList];
1267 WebHistoryItem *item = [list itemAtIndex:distance];
1270 int forwardListCount = [list forwardListCount];
1271 if (forwardListCount > 0)
1272 item = [list itemAtIndex:forwardListCount];
1274 int backListCount = [list forwardListCount];
1275 if (backListCount > 0)
1276 item = [list itemAtIndex:-backListCount];
1285 static id <WebFormDelegate> formDelegate(WebFrameBridge *self)
1287 ASSERT(self->_frame != nil);
1288 return [[self->_frame webView] _formDelegate];
1291 #define FormDelegateLog(ctrl) LOG(FormDelegate, "control=%@", ctrl)
1293 - (void)textFieldDidBeginEditing:(DOMHTMLInputElement *)element
1295 FormDelegateLog(element);
1296 [formDelegate(self) textFieldDidBeginEditing:element inFrame:_frame];
1299 - (void)textFieldDidEndEditing:(DOMHTMLInputElement *)element
1301 FormDelegateLog(element);
1302 [formDelegate(self) textFieldDidEndEditing:element inFrame:_frame];
1305 - (void)textDidChangeInTextField:(DOMHTMLInputElement *)element
1307 FormDelegateLog(element);
1308 [formDelegate(self) textDidChangeInTextField:(DOMHTMLInputElement *)element inFrame:_frame];
1311 - (void)textDidChangeInTextArea:(DOMHTMLTextAreaElement *)element
1313 FormDelegateLog(element);
1314 [formDelegate(self) textDidChangeInTextArea:element inFrame:_frame];
1317 - (BOOL)textField:(DOMHTMLInputElement *)element doCommandBySelector:(SEL)commandSelector
1319 FormDelegateLog(element);
1320 return [formDelegate(self) textField:element doCommandBySelector:commandSelector inFrame:_frame];
1323 - (BOOL)textField:(DOMHTMLInputElement *)element shouldHandleEvent:(NSEvent *)event
1325 FormDelegateLog(element);
1326 return [formDelegate(self) textField:element shouldHandleEvent:event inFrame:_frame];
1329 - (void)frameDetached
1331 [_frame stopLoading];
1332 [_frame _detachFromParent];
1335 - (void)setHasBorder:(BOOL)hasBorder
1337 [[_frame frameView] _setHasBorder:hasBorder];
1340 - (NSFileWrapper *)fileWrapperForURL:(NSURL *)URL
1342 return [[_frame dataSource] _fileWrapperForURL:URL];
1347 id wd = [[self webView] UIDelegate];
1349 if ([wd respondsToSelector:@selector(webView:printFrameView:)]) {
1350 [wd webView:[self webView] printFrameView:[_frame frameView]];
1352 [[WebDefaultUIDelegate sharedUIDelegate] webView:[self webView] printFrameView:[_frame frameView]];
1356 - (jobject)getAppletInView:(NSView *)view
1360 if ([view respondsToSelector:@selector(webPlugInGetApplet)])
1361 applet = [view webPlugInGetApplet];
1363 applet = [self pollForAppletInView:view];
1368 // NOTE: pollForAppletInView: will block until the block is ready to use, or
1369 // until a timeout is exceeded. It will return nil if the timeour is
1371 // Deprecated, use getAppletInView:.
1372 - (jobject)pollForAppletInView:(NSView *)view
1376 if ([view respondsToSelector:@selector(pollForAppletInWindow:)]) {
1377 // The Java VM needs the containing window of the view to
1378 // initialize. The view may not yet be in the window's view
1379 // hierarchy, so we have to pass the window when requesting
1381 applet = [view pollForAppletInWindow:[[self webView] window]];
1387 - (void)respondToChangedContents
1389 NSView <WebDocumentView> *view = [[_frame frameView] documentView];
1390 if ([view isKindOfClass:[WebHTMLView class]]) {
1391 [(WebHTMLView *)view _updateFontPanel];
1393 [[NSNotificationCenter defaultCenter] postNotificationName:WebViewDidChangeNotification object:[self webView]];
1396 - (void)respondToChangedSelection
1398 NSView <WebDocumentView> *view = [[_frame frameView] documentView];
1399 if ([view isKindOfClass:[WebHTMLView class]]) {
1400 [(WebHTMLView *)view _selectionChanged];
1402 [[NSNotificationCenter defaultCenter] postNotificationName:WebViewDidChangeSelectionNotification object:[self webView]];
1405 - (NSUndoManager *)undoManager
1407 return [[self webView] undoManager];
1410 - (void)issueCutCommand
1412 NSView* documentView = [[_frame frameView] documentView];
1413 if ([documentView isKindOfClass:[WebHTMLView class]])
1414 [(WebHTMLView*)documentView cut:nil];
1417 - (void)issueCopyCommand
1419 NSView* documentView = [[_frame frameView] documentView];
1420 if ([documentView isKindOfClass:[WebHTMLView class]])
1421 [(WebHTMLView*)documentView copy:nil];
1424 - (void)issuePasteCommand
1426 NSView* documentView = [[_frame frameView] documentView];
1427 if ([documentView isKindOfClass:[WebHTMLView class]])
1428 [(WebHTMLView*)documentView paste:nil];
1431 - (void)issuePasteAndMatchStyleCommand
1433 NSView <WebDocumentView> *documentView = [[_frame frameView] documentView];
1434 if ([documentView isKindOfClass:[WebHTMLView class]])
1435 [(WebHTMLView*)documentView pasteAsPlainText:nil];
1438 - (void)issueTransposeCommand
1440 NSView <WebDocumentView> *view = [[_frame frameView] documentView];
1441 if ([view isKindOfClass:[WebHTMLView class]])
1442 [(WebHTMLView *)view transpose:nil];
1447 NSView* documentView = [[_frame frameView] documentView];
1448 return [documentView isKindOfClass:[WebHTMLView class]] && [(WebHTMLView*)documentView _canPaste];
1451 - (void)setIsSelected:(BOOL)isSelected forView:(NSView *)view
1453 if ([view respondsToSelector:@selector(webPlugInSetIsSelected:)]) {
1454 [view webPlugInSetIsSelected:isSelected];
1456 else if ([view respondsToSelector:@selector(setIsSelected:)]) {
1457 [view setIsSelected:isSelected];
1461 - (NSString *)overrideMediaType
1463 return [[self webView] mediaStyle];
1468 return [[self webView] isEditable];
1471 - (BOOL)shouldChangeSelectedDOMRange:(DOMRange *)currentRange toDOMRange:(DOMRange *)proposedRange affinity:(NSSelectionAffinity)selectionAffinity stillSelecting:(BOOL)flag
1473 return [[self webView] _shouldChangeSelectedDOMRange:currentRange toDOMRange:proposedRange affinity:selectionAffinity stillSelecting:flag];
1476 - (BOOL)shouldDeleteSelectedDOMRange:(DOMRange *)range
1478 WebView *webView = [self webView];
1479 return [[webView _editingDelegateForwarder] webView:webView shouldDeleteDOMRange:range];
1482 - (BOOL)shouldBeginEditing:(DOMRange *)range
1484 return [[self webView] _shouldBeginEditingInDOMRange:range];
1487 - (BOOL)shouldEndEditing:(DOMRange *)range
1489 return [[self webView] _shouldEndEditingInDOMRange:range];
1492 - (void)didBeginEditing
1494 [[NSNotificationCenter defaultCenter] postNotificationName:WebViewDidBeginEditingNotification object:[_frame webView]];
1497 - (void)didEndEditing
1499 [[NSNotificationCenter defaultCenter] postNotificationName:WebViewDidEndEditingNotification object:[_frame webView]];
1502 - (void)windowObjectCleared
1504 WebView *wv = [self webView];
1505 [[wv _frameLoadDelegateForwarder] webView:wv windowScriptObjectAvailable:[self windowScriptObject]];
1506 if ([wv scriptDebugDelegate] || [WebScriptDebugServer listenerCount]) {
1507 [_frame _detachScriptDebugger]; // FIXME: remove this once <rdar://problem/4608404> is fixed
1508 [_frame _attachScriptDebugger];
1512 - (int)spellCheckerDocumentTag
1514 return [[self webView] spellCheckerDocumentTag];
1517 - (BOOL)isContinuousSpellCheckingEnabled
1519 return [[self webView] isContinuousSpellCheckingEnabled];
1522 - (void)didFirstLayout
1524 [_frame _didFirstLayout];
1525 WebView *wv = [self webView];
1526 [[wv _frameLoadDelegateForwarder] webView:wv didFirstLayoutInFrame:_frame];
1529 - (BOOL)_compareDashboardRegions:(NSDictionary *)regions
1531 return [lastDashboardRegions isEqualToDictionary:regions];
1534 - (void)dashboardRegionsChanged:(NSMutableDictionary *)regions
1536 WebView *wv = [self webView];
1537 id wd = [wv UIDelegate];
1539 [wv _addScrollerDashboardRegions:regions];
1541 if (![self _compareDashboardRegions:regions]) {
1542 if ([wd respondsToSelector:@selector(webView:dashboardRegionsChanged:)]) {
1543 [wd webView:wv dashboardRegionsChanged:regions];
1544 [lastDashboardRegions release];
1545 lastDashboardRegions = [regions retain];
1550 - (NSRect)customHighlightRect:(NSString*)type forLine:(NSRect)lineRect
1552 ASSERT(_frame != nil);
1553 NSView *documentView = [[_frame frameView] documentView];
1554 if (![documentView isKindOfClass:[WebHTMLView class]])
1557 WebHTMLView *webHTMLView = (WebHTMLView *)documentView;
1558 id<WebHTMLHighlighter> highlighter = [webHTMLView _highlighterForType:type];
1559 return [highlighter highlightRectForLine:lineRect];
1562 - (void)paintCustomHighlight:(NSString*)type forBox:(NSRect)boxRect onLine:(NSRect)lineRect behindText:(BOOL)text
1563 entireLine:(BOOL)line
1565 ASSERT(_frame != nil);
1566 NSView *documentView = [[_frame frameView] documentView];
1567 if (![documentView isKindOfClass:[WebHTMLView class]])
1570 WebHTMLView *webHTMLView = (WebHTMLView *)documentView;
1571 id<WebHTMLHighlighter> highlighter = [webHTMLView _highlighterForType:type];
1572 [highlighter paintHighlightForBox:boxRect onLine:lineRect behindText:text entireLine:line];
1575 - (NSString *)nameForUndoAction:(WebUndoAction)undoAction
1577 switch (undoAction) {
1578 case WebUndoActionUnspecified: return nil;
1579 case WebUndoActionSetColor: return UI_STRING_KEY("Set Color", "Set Color (Undo action name)", "Undo action name");
1580 case WebUndoActionSetBackgroundColor: return UI_STRING_KEY("Set Background Color", "Set Background Color (Undo action name)", "Undo action name");
1581 case WebUndoActionTurnOffKerning: return UI_STRING_KEY("Turn Off Kerning", "Turn Off Kerning (Undo action name)", "Undo action name");
1582 case WebUndoActionTightenKerning: return UI_STRING_KEY("Tighten Kerning", "Tighten Kerning (Undo action name)", "Undo action name");
1583 case WebUndoActionLoosenKerning: return UI_STRING_KEY("Loosen Kerning", "Loosen Kerning (Undo action name)", "Undo action name");
1584 case WebUndoActionUseStandardKerning: return UI_STRING_KEY("Use Standard Kerning", "Use Standard Kerning (Undo action name)", "Undo action name");
1585 case WebUndoActionTurnOffLigatures: return UI_STRING_KEY("Turn Off Ligatures", "Turn Off Ligatures (Undo action name)", "Undo action name");
1586 case WebUndoActionUseStandardLigatures: return UI_STRING_KEY("Use Standard Ligatures", "Use Standard Ligatures (Undo action name)", "Undo action name");
1587 case WebUndoActionUseAllLigatures: return UI_STRING_KEY("Use All Ligatures", "Use All Ligatures (Undo action name)", "Undo action name");
1588 case WebUndoActionRaiseBaseline: return UI_STRING_KEY("Raise Baseline", "Raise Baseline (Undo action name)", "Undo action name");
1589 case WebUndoActionLowerBaseline: return UI_STRING_KEY("Lower Baseline", "Lower Baseline (Undo action name)", "Undo action name");
1590 case WebUndoActionSetTraditionalCharacterShape: return UI_STRING_KEY("Set Traditional Character Shape", "Set Traditional Character Shape (Undo action name)", "Undo action name");
1591 case WebUndoActionSetFont: return UI_STRING_KEY("Set Font", "Set Font (Undo action name)", "Undo action name");
1592 case WebUndoActionChangeAttributes: return UI_STRING_KEY("Change Attributes", "Change Attributes (Undo action name)", "Undo action name");
1593 case WebUndoActionAlignLeft: return UI_STRING_KEY("Align Left", "Align Left (Undo action name)", "Undo action name");
1594 case WebUndoActionAlignRight: return UI_STRING_KEY("Align Right", "Align Right (Undo action name)", "Undo action name");
1595 case WebUndoActionCenter: return UI_STRING_KEY("Center", "Center (Undo action name)", "Undo action name");
1596 case WebUndoActionJustify: return UI_STRING_KEY("Justify", "Justify (Undo action name)", "Undo action name");
1597 case WebUndoActionSetWritingDirection: return UI_STRING_KEY("Set Writing Direction", "Set Writing Direction (Undo action name)", "Undo action name");
1598 case WebUndoActionSubscript: return UI_STRING_KEY("Subscript", "Subscript (Undo action name)", "Undo action name");
1599 case WebUndoActionSuperscript: return UI_STRING_KEY("Superscript", "Superscript (Undo action name)", "Undo action name");
1600 case WebUndoActionUnderline: return UI_STRING_KEY("Underline", "Underline (Undo action name)", "Undo action name");
1601 case WebUndoActionOutline: return UI_STRING_KEY("Outline", "Outline (Undo action name)", "Undo action name");
1602 case WebUndoActionUnscript: return UI_STRING_KEY("Unscript", "Unscript (Undo action name)", "Undo action name");
1603 case WebUndoActionDrag: return UI_STRING_KEY("Drag", "Drag (Undo action name)", "Undo action name");
1604 case WebUndoActionCut: return UI_STRING_KEY("Cut", "Cut (Undo action name)", "Undo action name");
1605 case WebUndoActionPaste: return UI_STRING_KEY("Paste", "Paste (Undo action name)", "Undo action name");
1606 case WebUndoActionPasteFont: return UI_STRING_KEY("Paste Font", "Paste Font (Undo action name)", "Undo action name");
1607 case WebUndoActionPasteRuler: return UI_STRING_KEY("Paste Ruler", "Paste Ruler (Undo action name)", "Undo action name");
1608 case WebUndoActionTyping: return UI_STRING_KEY("Typing", "Typing (Undo action name)", "Undo action name");
1609 case WebUndoActionCreateLink: return UI_STRING_KEY("Create Link", "Create Link (Undo action name)", "Undo action name");
1610 case WebUndoActionUnlink: return UI_STRING_KEY("Unlink", "Unlink (Undo action name)", "Undo action name");
1611 case WebUndoActionInsertList: return UI_STRING_KEY("Insert List", "Insert List (Undo action name)", "Undo action name");
1612 case WebUndoActionFormatBlock: return UI_STRING_KEY("Formatting", "Format Block (Undo action name)", "Undo action name");
1613 case WebUndoActionIndent: return UI_STRING_KEY("Indent", "Indent (Undo action name)", "Undo action name");
1614 case WebUndoActionOutdent: return UI_STRING_KEY("Outdent", "Outdent (Undo action name)", "Undo action name");
1619 - (WebCorePageBridge *)createModalDialogWithURL:(NSURL *)URL
1621 ASSERT(_frame != nil);
1623 NSMutableURLRequest *request = nil;
1625 if (URL != nil && ![URL _web_isEmpty]) {
1626 request = [NSMutableURLRequest requestWithURL:URL];
1627 [request _web_setHTTPReferrer:[self referrer]];
1630 WebView *currentWebView = [self webView];
1631 id UIDelegate = [currentWebView UIDelegate];
1633 WebView *newWebView = nil;
1634 if ([UIDelegate respondsToSelector:@selector(webView:createWebViewModalDialogWithRequest:)])
1635 newWebView = [UIDelegate webView:currentWebView createWebViewModalDialogWithRequest:request];
1636 else if ([UIDelegate respondsToSelector:@selector(webView:createWebViewWithRequest:)])
1637 newWebView = [UIDelegate webView:currentWebView createWebViewWithRequest:request];
1639 newWebView = [[WebDefaultUIDelegate sharedUIDelegate] webView:currentWebView createWebViewWithRequest:request];
1641 return [newWebView _pageBridge];
1646 WebView *webView = [self webView];
1647 id UIDelegate = [webView UIDelegate];
1648 return [UIDelegate respondsToSelector:@selector(webViewRunModal:)];
1651 - (BOOL)canRunModalNow
1653 return [self canRunModal] && ![WebLoader inConnectionCallback];
1658 if (![self canRunModal])
1661 WebView *webView = [self webView];
1662 if ([webView defersCallbacks]) {
1663 LOG_ERROR("tried to run modal in a view when it was deferring callbacks -- should never happen");
1667 // Defer callbacks in all the other views in this group, so we don't try to run JavaScript
1668 // in a way that could interact with this view.
1669 NSMutableArray *deferredWebViews = [NSMutableArray array];
1670 NSString *namespace = [webView groupName];
1672 NSEnumerator *enumerator = [WebCoreFrameNamespaces framesInNamespace:namespace];
1673 WebView *otherWebView;
1674 while ((otherWebView = [[enumerator nextObject] webView]) != nil) {
1675 if (otherWebView != webView && ![otherWebView defersCallbacks]) {
1676 [otherWebView setDefersCallbacks:YES];
1677 [deferredWebViews addObject:otherWebView];
1682 // Go run the modal event loop.
1683 [[webView UIDelegate] webViewRunModal:webView];
1685 // Restore the callbacks for any views that we deferred them for.
1686 unsigned count = [deferredWebViews count];
1688 for (i = 0; i < count; ++i) {
1689 WebView *otherWebView = [deferredWebViews objectAtIndex:i];
1690 [otherWebView setDefersCallbacks:NO];
1694 - (void)handledOnloadEvents
1696 [_frame _handledOnloadEvents];
1701 [_frame _willCloseURL];
1705 - (NSURLResponse*)mainResourceURLResponse
1707 return [[_frame dataSource] response];
1710 - (NSString*)imageTitleForFilename:(NSString*)filename size:(NSSize)size
1712 return [NSString stringWithFormat:UI_STRING("%@ %.0f×%.0f pixels", "window title for a standalone image (uses multiplication symbol, not x)"), filename, size.width, size.height];
1715 - (void)notifyIconChanged:(NSURL*)iconURL
1717 [[_frame _frameLoader] _notifyIconChanged:iconURL];
1720 - (NSURL*)originalRequestURL
1722 return [[[[_frame _frameLoader] activeDataSource] initialRequest] URL];
1725 - (BOOL)isLoadTypeReload
1727 return [[_frame _frameLoader] loadType] == WebFrameLoadTypeReload;