📄 webview.mm
字号:
bzero(cache, sizeof(WebFrameLoadDelegateImplementationCache)); return; } cache->didCancelClientRedirectForFrameFunc = getMethod(delegate, @selector(webView:didCancelClientRedirectForFrame:)); cache->didChangeLocationWithinPageForFrameFunc = getMethod(delegate, @selector(webView:didChangeLocationWithinPageForFrame:)); cache->didClearWindowObjectForFrameFunc = getMethod(delegate, @selector(webView:didClearWindowObject:forFrame:)); cache->didCommitLoadForFrameFunc = getMethod(delegate, @selector(webView:didCommitLoadForFrame:)); cache->didFailLoadWithErrorForFrameFunc = getMethod(delegate, @selector(webView:didFailLoadWithError:forFrame:)); cache->didFailProvisionalLoadWithErrorForFrameFunc = getMethod(delegate, @selector(webView:didFailProvisionalLoadWithError:forFrame:)); cache->didFinishDocumentLoadForFrameFunc = getMethod(delegate, @selector(webView:didFinishDocumentLoadForFrame:)); cache->didFinishLoadForFrameFunc = getMethod(delegate, @selector(webView:didFinishLoadForFrame:)); cache->didFirstLayoutInFrameFunc = getMethod(delegate, @selector(webView:didFirstLayoutInFrame:)); cache->didFirstVisuallyNonEmptyLayoutInFrameFunc = getMethod(delegate, @selector(webView:didFirstVisuallyNonEmptyLayoutInFrame:)); cache->didHandleOnloadEventsForFrameFunc = getMethod(delegate, @selector(webView:didHandleOnloadEventsForFrame:)); cache->didReceiveIconForFrameFunc = getMethod(delegate, @selector(webView:didReceiveIcon:forFrame:)); cache->didReceiveServerRedirectForProvisionalLoadForFrameFunc = getMethod(delegate, @selector(webView:didReceiveServerRedirectForProvisionalLoadForFrame:)); cache->didReceiveTitleForFrameFunc = getMethod(delegate, @selector(webView:didReceiveTitle:forFrame:)); cache->didStartProvisionalLoadForFrameFunc = getMethod(delegate, @selector(webView:didStartProvisionalLoadForFrame:)); cache->willCloseFrameFunc = getMethod(delegate, @selector(webView:willCloseFrame:)); cache->willPerformClientRedirectToURLDelayFireDateForFrameFunc = getMethod(delegate, @selector(webView:willPerformClientRedirectToURL:delay:fireDate:forFrame:)); cache->windowScriptObjectAvailableFunc = getMethod(delegate, @selector(webView:windowScriptObjectAvailable:));}WebFrameLoadDelegateImplementationCache* WebViewGetFrameLoadDelegateImplementations(WebView *webView){ static WebFrameLoadDelegateImplementationCache empty; if (!webView) return ∅ return &webView->_private->frameLoadDelegateImplementations;}- (void)_cacheScriptDebugDelegateImplementations{ WebScriptDebugDelegateImplementationCache *cache = &_private->scriptDebugDelegateImplementations; id delegate = _private->scriptDebugDelegate; if (!delegate) { bzero(cache, sizeof(WebScriptDebugDelegateImplementationCache)); return; } cache->didParseSourceFunc = getMethod(delegate, @selector(webView:didParseSource:baseLineNumber:fromURL:sourceId:forWebFrame:)); if (cache->didParseSourceFunc) cache->didParseSourceExpectsBaseLineNumber = YES; else cache->didParseSourceFunc = getMethod(delegate, @selector(webView:didParseSource:fromURL:sourceId:forWebFrame:)); cache->failedToParseSourceFunc = getMethod(delegate, @selector(webView:failedToParseSource:baseLineNumber:fromURL:withError:forWebFrame:)); cache->didEnterCallFrameFunc = getMethod(delegate, @selector(webView:didEnterCallFrame:sourceId:line:forWebFrame:)); cache->willExecuteStatementFunc = getMethod(delegate, @selector(webView:willExecuteStatement:sourceId:line:forWebFrame:)); cache->willLeaveCallFrameFunc = getMethod(delegate, @selector(webView:willLeaveCallFrame:sourceId:line:forWebFrame:)); cache->exceptionWasRaisedFunc = getMethod(delegate, @selector(webView:exceptionWasRaised:sourceId:line:forWebFrame:));}WebScriptDebugDelegateImplementationCache* WebViewGetScriptDebugDelegateImplementations(WebView *webView){ static WebScriptDebugDelegateImplementationCache empty; if (!webView) return ∅ return &webView->_private->scriptDebugDelegateImplementations;}- (id)_policyDelegateForwarder{ if (!_private->policyDelegateForwarder) _private->policyDelegateForwarder = [[_WebSafeForwarder alloc] initWithTarget:_private->policyDelegate defaultTarget:[WebDefaultPolicyDelegate sharedPolicyDelegate] catchExceptions:_private->catchesDelegateExceptions]; return _private->policyDelegateForwarder;}- (id)_UIDelegateForwarder{ if (!_private->UIDelegateForwarder) _private->UIDelegateForwarder = [[_WebSafeForwarder alloc] initWithTarget:_private->UIDelegate defaultTarget:[WebDefaultUIDelegate sharedUIDelegate] catchExceptions:_private->catchesDelegateExceptions]; return _private->UIDelegateForwarder;}- (id)_editingDelegateForwarder{ // This can be called during window deallocation by QTMovieView in the QuickTime Cocoa Plug-in. // Not sure if that is a bug or not. if (!_private) return nil; if (!_private->editingDelegateForwarder) _private->editingDelegateForwarder = [[_WebSafeForwarder alloc] initWithTarget:_private->editingDelegate defaultTarget:[WebDefaultEditingDelegate sharedEditingDelegate] catchExceptions:_private->catchesDelegateExceptions]; return _private->editingDelegateForwarder;}- (void)_closeWindow{ [[self _UIDelegateForwarder] webViewClose:self];}+ (void)_unregisterViewClassAndRepresentationClassForMIMEType:(NSString *)MIMEType{ [[WebFrameView _viewTypesAllowImageTypeOmission:NO] removeObjectForKey:MIMEType]; [[WebDataSource _repTypesAllowImageTypeOmission:NO] removeObjectForKey:MIMEType]; // FIXME: We also need to maintain MIMEType registrations (which can be dynamically changed) // in the WebCore MIMEType registry. For now we're doing this in a safe, limited manner // to fix <rdar://problem/5372989> - a future revamping of the entire system is neccesary for future robustness MIMETypeRegistry::getSupportedNonImageMIMETypes().remove(MIMEType);}+ (void)_registerViewClass:(Class)viewClass representationClass:(Class)representationClass forURLScheme:(NSString *)URLScheme{ NSString *MIMEType = [self _generatedMIMETypeForURLScheme:URLScheme]; [self registerViewClass:viewClass representationClass:representationClass forMIMEType:MIMEType]; // FIXME: We also need to maintain MIMEType registrations (which can be dynamically changed) // in the WebCore MIMEType registry. For now we're doing this in a safe, limited manner // to fix <rdar://problem/5372989> - a future revamping of the entire system is neccesary for future robustness if ([viewClass class] == [WebHTMLView class]) MIMETypeRegistry::getSupportedNonImageMIMETypes().add(MIMEType); // This is used to make _representationExistsForURLScheme faster. // Without this set, we'd have to create the MIME type each time. if (schemesWithRepresentationsSet == nil) { schemesWithRepresentationsSet = [[NSMutableSet alloc] init]; } [schemesWithRepresentationsSet addObject:[[[URLScheme lowercaseString] copy] autorelease]];}+ (NSString *)_generatedMIMETypeForURLScheme:(NSString *)URLScheme{ return [@"x-apple-web-kit/" stringByAppendingString:[URLScheme lowercaseString]];}+ (BOOL)_representationExistsForURLScheme:(NSString *)URLScheme{ return [schemesWithRepresentationsSet containsObject:[URLScheme lowercaseString]];}+ (BOOL)_canHandleRequest:(NSURLRequest *)request forMainFrame:(BOOL)forMainFrame{ // FIXME: If <rdar://problem/5217309> gets fixed, this check can be removed. if (!request) return NO; if ([NSURLConnection canHandleRequest:request]) return YES; NSString *scheme = [[request URL] scheme]; // Representations for URL schemes work at the top level. if (forMainFrame && [self _representationExistsForURLScheme:scheme]) return YES; return [scheme _webkit_isCaseInsensitiveEqualToString:@"applewebdata"];}+ (BOOL)_canHandleRequest:(NSURLRequest *)request{ return [self _canHandleRequest:request forMainFrame:YES];}+ (NSString *)_decodeData:(NSData *)data{ HTMLNames::init(); // this method is used for importing bookmarks at startup, so HTMLNames are likely to be uninitialized yet RefPtr<TextResourceDecoder> decoder = TextResourceDecoder::create("text/html"); // bookmark files are HTML String result = decoder->decode(static_cast<const char*>([data bytes]), [data length]); result += decoder->flush(); return result;}- (void)_pushPerformingProgrammaticFocus{ _private->programmaticFocusCount++;}- (void)_popPerformingProgrammaticFocus{ _private->programmaticFocusCount--;}- (BOOL)_isPerformingProgrammaticFocus{ return _private->programmaticFocusCount != 0;}- (void)_didChangeValueForKey: (NSString *)key{ LOG (Bindings, "calling didChangeValueForKey: %@", key); [self didChangeValueForKey: key];}- (void)_willChangeValueForKey: (NSString *)key{ LOG (Bindings, "calling willChangeValueForKey: %@", key); [self willChangeValueForKey: key];}+ (BOOL)automaticallyNotifiesObserversForKey:(NSString *)key { static NSSet *manualNotifyKeys = nil; if (!manualNotifyKeys) manualNotifyKeys = [[NSSet alloc] initWithObjects:_WebMainFrameURLKey, _WebIsLoadingKey, _WebEstimatedProgressKey, _WebCanGoBackKey, _WebCanGoForwardKey, _WebMainFrameTitleKey, _WebMainFrameIconKey, _WebMainFrameDocumentKey,#if USE(ACCELERATED_COMPOSITING) UsingAcceleratedCompositingProperty, // used by DRT#endif nil]; if ([manualNotifyKeys containsObject:key]) return NO; return YES;}- (NSArray *)_declaredKeys { static NSArray *declaredKeys = nil; if (!declaredKeys) declaredKeys = [[NSArray alloc] initWithObjects:_WebMainFrameURLKey, _WebIsLoadingKey, _WebEstimatedProgressKey, _WebCanGoBackKey, _WebCanGoForwardKey, _WebMainFrameTitleKey, _WebMainFrameIconKey, _WebMainFrameDocumentKey, nil]; return declaredKeys;}- (void)setObservationInfo:(void *)info{ _private->observationInfo = info;}- (void *)observationInfo{ return _private->observationInfo;}- (void)_willChangeBackForwardKeys{ [self _willChangeValueForKey: _WebCanGoBackKey]; [self _willChangeValueForKey: _WebCanGoForwardKey];}- (void)_didChangeBackForwardKeys{ [self _didChangeValueForKey: _WebCanGoBackKey]; [self _didChangeValueForKey: _WebCanGoForwardKey];}- (void)_didStartProvisionalLoadForFrame:(WebFrame *)frame{ [self _willChangeBackForwardKeys]; if (frame == [self mainFrame]){ // Force an observer update by sending a will/did. [self _willChangeValueForKey: _WebIsLoadingKey]; [self _didChangeValueForKey: _WebIsLoadingKey]; [self _willChangeValueForKey: _WebMainFrameURLKey]; } [NSApp setWindowsNeedUpdate:YES];}- (void)_didCommitLoadForFrame:(WebFrame *)frame{ if (frame == [self mainFrame]) [self _didChangeValueForKey: _WebMainFrameURLKey]; [NSApp setWindowsNeedUpdate:YES];}- (void)_didFinishLoadForFrame:(WebFrame *)frame{ [self _didChangeBackForwardKeys]; if (frame == [self mainFrame]){ // Force an observer update by sending a will/did. [self _willChangeValueForKey: _WebIsLoadingKey]; [self _didChangeValueForKey: _WebIsLoadingKey]; } [NSApp setWindowsNeedUpdate:YES];}- (void)_didFailLoadWithError:(NSError *)error forFrame:(WebFrame *)frame{ [self _didChangeBackForwardKeys]; if (frame == [self mainFrame]){ // Force an observer update by sending a will/did. [self _willChangeValueForKey: _WebIsLoadingKey]; [self _didChangeValueForKey: _WebIsLoadingKey]; } [NSApp setWindowsNeedUpdate:YES];}- (void)_didFailProvisionalLoadWithError:(NSError *)error forFrame:(WebFrame *)frame{ [self _didChangeBackForwardKeys]; if (frame == [self mainFrame]){ // Force an observer update by sending a will/did. [self _willChangeValueForKey: _WebIsLoadingKey]; [self _didChangeValueForKey: _WebIsLoadingKey]; [self _didChangeValueForKey: _WebMainFrameURLKey]; } [NSApp setWindowsNeedUpdate:YES];}- (NSCachedURLResponse *)_cachedResponseForURL:(NSURL *)URL{ NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:URL]; [request _web_setHTTPUserAgent:[self userAgentForURL:URL]]; NSCachedURLResponse *cachedResponse = [[NSURLCache sharedURLCache] cachedResponseForRequest:request]; [request release]; return cachedResponse;}- (void)_writeImageForElement:(NSDictionary *)element withPasteboardTypes:(NSArray *)types toPasteboard:(NSPasteboard *)pasteboard{ NSURL *linkURL = [element objectForKey:WebElementLinkURLKey]; DOMElement *domElement = [element objectForKey:WebElementDOMNodeKey]; [pasteboard _web_writeImage:(NSImage *)(domElement ? nil : [element objectForKey:WebElementImageKey]) element:domElement URL:linkURL ? linkURL : (NSURL *)[element objectForKey:WebElementImageURLKey] title:[element objectForKey:WebElementImageAltStringKey] archive:[[element objectForKey:WebElementDOMNodeKey] webArchive] types:types source:nil];}- (void)_writeLinkElement:(NSDictionary *)element withPasteboardTypes:(NSArray *)types toPasteboard:(NSPasteboard *)pasteboard{ [pasteboard _web_writeURL:[element objectForKey:WebElementLinkURLKey] andTitle:[element objectForKey:WebElementLinkLabelKey] types:types];}- (void)_setInitiatedDrag:(BOOL)initiatedDrag{ if (!_private->page) return; _private->page->dragController()->setDidInitiateDrag(initiatedDrag);}#if ENABLE(DASHBOARD_SUPPORT)#define DASHBOARD_CONTROL_LABEL @"control"- (void)_addScrollerDashboardRegions:(NSMutableDictionary *)regions from:(NSArray *)views{ // Add scroller regions for NSScroller and KWQScrollBar int i, count = [views count]; for (i = 0; i < count; i++) { NSView *aView = [views objectAtIndex:i]; if ([aView isKindOfClass:[NSScroller class]] || [aView isKindOfClass:NSClassFromString (@"KWQScrollBar")]) { NSRect bounds = [aView bounds]; NSRect adjustedBounds; adjustedBounds.o
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -