我是靠谱客的博主 可靠毛巾,最近开发中收集的这篇文章主要介绍UIWebView体系结构(六)UIWebView,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

UIWebView的实际成员变量都由UIWebViewInternal保存,UIWebViewInternal的声明如下:

@interface UIWebViewInternal : NSObject
{
    UIScrollView *scroller;
    UIWebBrowserView *browserView;
    UICheckeredPatternView *checkeredPatternView;
    id <UIWebViewDelegate> delegate;
    unsigned int scalesPageToFit:1;
    unsigned int isLoading:1;
    unsigned int hasOverriddenOrientationChangeEventHandling:1;
    unsigned int drawsCheckeredPattern:1;
    unsigned int webSelectionEnabled:1;
    unsigned int drawInWebThread:1;
    unsigned int inRotation:1;
    NSURLRequest *request;
    int clickedAlertButtonIndex;
    UIWebViewWebViewDelegate *webViewDelegate;
    UIWebPDFViewHandler *pdfHandler;
}

@end
其中scroller指向_UIWebViewScrollView的实例。

UIWebViewWebViewDelegate的声明为:(代码很长,点此跳过)

@interface UIWebViewWebViewDelegate : NSObject
{
    UIWebView *uiWebView;
}

- (void)_clearUIWebView;
- (void)webView:(id)arg1 didChangeLocationWithinPageForFrame:(id)arg2;
- (BOOL)webView:(id)arg1 resource:(id)arg2 canAuthenticateAgainstProtectionSpace:(id)arg3 forDataSource:(id)arg4;
- (void)webView:(id)arg1 resource:(id)arg2 didCancelAuthenticationChallenge:(id)arg3 fromDataSource:(id)arg4;
- (void)webView:(id)arg1 resource:(id)arg2 didReceiveAuthenticationChallenge:(id)arg3 fromDataSource:(id)arg4;
- (void)webView:(id)arg1 resource:(id)arg2 didFailLoadingWithError:(id)arg3 fromDataSource:(id)arg4;
- (void)webView:(id)arg1 resource:(id)arg2 didFinishLoadingFromDataSource:(id)arg3;
- (id)webView:(id)arg1 identifierForInitialRequest:(id)arg2 fromDataSource:(id)arg3;
- (void)webView:(id)arg1 decidePolicyForGeolocationRequestFromOrigin:(id)arg2 frame:(id)arg3 listener:(id)arg4;
- (id)webView:(id)arg1 runJavaScriptTextInputPanelWithPrompt:(id)arg2 defaultText:(id)arg3 initiatedByFrame:(id)arg4;
- (BOOL)webView:(id)arg1 runJavaScriptConfirmPanelWithMessage:(id)arg2 initiatedByFrame:(id)arg3;
- (void)webView:(id)arg1 runJavaScriptAlertPanelWithMessage:(id)arg2 initiatedByFrame:(id)arg3;
- (void)webViewClose:(id)arg1;
- (void)webView:(id)arg1 didFirstLayoutInFrame:(id)arg2;
- (void)webView:(id)arg1 didFailLoadWithError:(id)arg2 forFrame:(id)arg3;
- (void)webView:(id)arg1 didFinishLoadForFrame:(id)arg2;
- (void)webView:(id)arg1 decidePolicyForMIMEType:(id)arg2 request:(id)arg3 frame:(id)arg4 decisionListener:(id)arg5;
- (void)webView:(id)arg1 didFailProvisionalLoadWithError:(id)arg2 forFrame:(id)arg3;
- (void)webView:(id)arg1 didReceiveServerRedirectForProvisionalLoadForFrame:(id)arg2;
- (void)webView:(id)arg1 didClearWindowObject:(id)arg2 forFrame:(id)arg3;
- (id)webView:(id)arg1 resource:(id)arg2 willSendRequest:(id)arg3 redirectResponse:(id)arg4 fromDataSource:(id)arg5;
- (id)webView:(id)arg1 connectionPropertiesForResource:(id)arg2 dataSource:(id)arg3;
- (void)webViewSupportedOrientationsUpdated:(id)arg1;
- (void)webView:(id)arg1 didReceiveTitle:(id)arg2 forFrame:(id)arg3;
- (void)webView:(id)arg1 didCommitLoadForFrame:(id)arg2;
- (void)webView:(id)arg1 didStartProvisionalLoadForFrame:(id)arg2;
- (void)webView:(id)arg1 printFrameView:(id)arg2;
- (void)webView:(id)arg1 exceededApplicationCacheOriginQuotaForSecurityOrigin:(id)arg2 totalSpaceNeeded:(unsigned int)arg3;
- (void)webView:(id)arg1 frame:(id)arg2 exceededDatabaseQuotaForSecurityOrigin:(id)arg3 database:(id)arg4;
- (void)webView:(id)arg1 unableToImplementPolicyWithError:(id)arg2 frame:(id)arg3;
- (void)webView:(id)arg1 decidePolicyForNavigationAction:(id)arg2 request:(id)arg3 frame:(id)arg4 decisionListener:(id)arg5;
- (void)webView:(id)arg1 decidePolicyForNewWindowAction:(id)arg2 request:(id)arg3 newFrameName:(id)arg4 decisionListener:(id)arg5;
- (id)webView:(id)arg1 createWebViewWithRequest:(id)arg2;
- (id)initWithUIWebView:(id)arg1;

@end

它负责接收很多来自WebView的通知,并转发给UIWebView。如第一节概貌中提到,它实现了多个WebView的delegate。

UIWebView的non-public declaration为: (代码很长,点此跳过)

@interface UIWebView : UIView <NSCoding, UIScrollViewDelegate>
{
    UIWebViewInternal *_internal;
}

+ (void)_updatePersistentStoragePaths;
+ (void)_fixPathsForSandboxDirectoryChange;
+ (id)_relativePathFromAbsolutePath:(id)arg1 removingPathComponents:(unsigned int)arg2;
- (void)_addShortcut:(id)arg1;
- (void)_define:(id)arg1;
- (void)selectAll:(id)arg1;
- (void)select:(id)arg1;
- (void)copy:(id)arg1;
- (BOOL)canPerformAction:(SEL)arg1 withSender:(id)arg2;
- (void)configureWithSettings:(id)arg1;
- (unsigned int)_audioSessionCategoryOverride;
- (void)_setAudioSessionCategoryOverride:(unsigned int)arg1;
- (BOOL)_alwaysDispatchesScrollEvents;
- (void)_setAlwaysDispatchesScrollEvents:(BOOL)arg1;
- (unsigned int)_pageCount;
- (void)_setGapBetweenPages:(float)arg1;
- (float)_gapBetweenPages;
- (void)_setPageLength:(float)arg1;
- (float)_pageLength;
- (void)_setPaginationBehavesLikeColumns:(BOOL)arg1;
- (BOOL)_paginationBehavesLikeColumns;
- (void)_setPaginationMode:(int)arg1;
- (int)_paginationMode;
- (void)_setDrawInWebThread:(BOOL)arg1;
- (void)_setWebSelectionEnabled:(BOOL)arg1;
- (void)_setDrawsCheckeredPattern:(BOOL)arg1;
- (void)_setOverridesOrientationChangeEventHandling:(BOOL)arg1;
- (id)_pdfViewHandler;
- (id)_scrollView;
- (id)_documentView;
- (id)_browserView;
- (id)_initWithWebView:(id)arg1;
- (struct CGImage *)newSnapshotWithRect:(struct CGRect)arg1;
- (struct CGImage *)createSnapshotWithRect:(struct CGRect)arg1;
- (void)webView:(id)arg1 didChangeLocationWithinPageForFrame:(id)arg2;
- (BOOL)webView:(id)arg1 resource:(id)arg2 canAuthenticateAgainstProtectionSpace:(id)arg3 forDataSource:(id)arg4;
- (void)webView:(id)arg1 resource:(id)arg2 didCancelAuthenticationChallenge:(id)arg3 fromDataSource:(id)arg4;
- (void)webView:(id)arg1 resource:(id)arg2 didReceiveAuthenticationChallenge:(id)arg3 fromDataSource:(id)arg4;
- (void)webView:(id)arg1 resource:(id)arg2 didFailLoadingWithError:(id)arg3 fromDataSource:(id)arg4;
- (void)webView:(id)arg1 resource:(id)arg2 didFinishLoadingFromDataSource:(id)arg3;
- (id)webView:(id)arg1 identifierForInitialRequest:(id)arg2 fromDataSource:(id)arg3;
- (void)webView:(id)arg1 decidePolicyForGeolocationRequestFromOrigin:(id)arg2 frame:(id)arg3 listener:(id)arg4;
- (id)webView:(id)arg1 runJavaScriptTextInputPanelWithPrompt:(id)arg2 defaultText:(id)arg3 initiatedByFrame:(id)arg4;
- (BOOL)webView:(id)arg1 runJavaScriptConfirmPanelWithMessage:(id)arg2 initiatedByFrame:(id)arg3;
- (void)webView:(id)arg1 runJavaScriptAlertPanelWithMessage:(id)arg2 initiatedByFrame:(id)arg3;
- (id)_makeAlertView;
- (void)webViewClose:(id)arg1;
- (void)alertView:(id)arg1 didDismissWithButtonIndex:(int)arg2;
- (void)webView:(id)arg1 didFirstLayoutInFrame:(id)arg2;
- (void)webView:(id)arg1 didFailLoadWithError:(id)arg2 forFrame:(id)arg3;
- (void)webView:(id)arg1 didFinishLoadForFrame:(id)arg2;
- (void)webView:(id)arg1 didFailProvisionalLoadWithError:(id)arg2 forFrame:(id)arg3;
- (void)webView:(id)arg1 didReceiveServerRedirectForProvisionalLoadForFrame:(id)arg2;
- (void)webView:(id)arg1 didClearWindowObject:(id)arg2 forFrame:(id)arg3;
- (id)webView:(id)arg1 resource:(id)arg2 willSendRequest:(id)arg3 redirectResponse:(id)arg4 fromDataSource:(id)arg5;
- (id)webView:(id)arg1 connectionPropertiesForResource:(id)arg2 dataSource:(id)arg3;
- (void)webView:(id)arg1 didReceiveTitle:(id)arg2 forFrame:(id)arg3;
- (void)webView:(id)arg1 didCommitLoadForFrame:(id)arg2;
- (void)webView:(id)arg1 didStartProvisionalLoadForFrame:(id)arg2;
- (void)_updateRequest;
- (void)webViewSupportedOrientationsUpdated:(id)arg1;
- (void)webView:(id)arg1 printFrameView:(id)arg2;
- (void)webView:(id)arg1 exceededApplicationCacheOriginQuotaForSecurityOrigin:(id)arg2 totalSpaceNeeded:(unsigned int)arg3;
- (void)webView:(id)arg1 frame:(id)arg2 exceededDatabaseQuotaForSecurityOrigin:(id)arg3 database:(id)arg4;
- (void)webView:(id)arg1 unableToImplementPolicyWithError:(id)arg2 frame:(id)arg3;
- (void)webView:(id)arg1 decidePolicyForMIMEType:(id)arg2 request:(id)arg3 frame:(id)arg4 decisionListener:(id)arg5;
- (void)webView:(id)arg1 decidePolicyForNavigationAction:(id)arg2 request:(id)arg3 frame:(id)arg4 decisionListener:(id)arg5;
- (void)webView:(id)arg1 decidePolicyForNewWindowAction:(id)arg2 request:(id)arg3 newFrameName:(id)arg4 decisionListener:(id)arg5;
- (void)_reportError:(id)arg1;
- (void)scrollViewWasRemoved:(id)arg1;
- (void)scrollViewDidScrollToTop:(id)arg1;
- (void)scrollViewDidEndDecelerating:(id)arg1;
- (void)scrollViewDidEndDragging:(id)arg1 willDecelerate:(BOOL)arg2;
- (void)_didCompleteScrolling;
- (void)scrollViewWillBeginDragging:(id)arg1;
- (void)scrollViewDidEndZooming:(id)arg1 withView:(id)arg2 atScale:(float)arg3;
- (void)scrollViewDidZoom:(id)arg1;
- (void)scrollViewWillBeginZooming:(id)arg1 withView:(id)arg2;
- (id)viewForZoomingInScrollView:(id)arg1;
- (void)restoreStateFromHistoryItem:(id)arg1 forWebView:(id)arg2;
- (void)saveStateToHistoryItem:(id)arg1 forWebView:(id)arg2;
- (void)webViewMainFrameDidFailLoad:(id)arg1 withError:(id)arg2;
- (void)webViewMainFrameDidFinishLoad:(id)arg1;
- (void)webViewMainFrameDidCommitLoad:(id)arg1;
- (void)webViewMainFrameDidFirstVisuallyNonEmptyLayoutInFrame:(id)arg1;
- (void)_updateScrollerViewForInputView:(id)arg1;
- (void)view:(id)arg1 didSetFrame:(struct CGRect)arg2 oldFrame:(struct CGRect)arg3;
- (BOOL)_appliesExclusiveTouchToSubviewTree;
- (void)setBackgroundColor:(id)arg1;
- (void)setOpaque:(BOOL)arg1;
- (void)_updateOpaqueAndBackgroundColor;
- (void)setBounds:(struct CGRect)arg1;
- (void)setFrame:(struct CGRect)arg1;
- (void)_frameOrBoundsChanged;
- (void)_rescaleDocument;
- (void)_finishRotation;
- (void)_beginRotation;
- (struct CGSize)sizeThatFits:(struct CGSize)arg1;
- (void)_updateCheckeredPattern;
@property(nonatomic) BOOL suppressesIncrementalRendering;
@property(readonly, nonatomic, getter=canGoForward) BOOL canGoForward;
@property(readonly, nonatomic, getter=canGoBack) BOOL canGoBack;
- (void)goForward;
- (void)goBack;
- (void)stopLoading;
- (void)reload;
@property(readonly, nonatomic) NSURLRequest *request;
- (void)loadData:(id)arg1 MIMEType:(id)arg2 textEncodingName:(id)arg3 baseURL:(id)arg4;
- (void)loadHTMLString:(id)arg1 baseURL:(id)arg2;
- (void)loadRequest:(id)arg1;
@property(readonly, nonatomic) UIScrollView *scrollView;
@property(nonatomic) id <UIWebViewDelegate> delegate;
@property(readonly, nonatomic, getter=isLoading) BOOL loading;
@property(nonatomic) BOOL scalesPageToFit;
@property(nonatomic) BOOL mediaPlaybackAllowsAirPlay;
@property(nonatomic) BOOL mediaPlaybackRequiresUserAction;
@property(nonatomic) BOOL allowsInlineMediaPlayback;
@property(nonatomic) unsigned int dataDetectorTypes;
@property(nonatomic) BOOL detectsPhoneNumbers;
- (id)stringByEvaluatingJavaScriptFromString:(id)arg1;
- (void)dealloc;
- (void)encodeWithCoder:(id)arg1;
- (void)_populateArchivedSubviews:(id)arg1;
- (id)initWithCoder:(id)arg1;
- (id)initWithFrame:(struct CGRect)arg1;
- (id)_initWithFrame:(struct CGRect)arg1 enableReachability:(BOOL)arg2;
- (void)_webViewCommonInitWithWebView:(id)arg1 scalesPageToFit:(BOOL)arg2 shouldEnableReachability:(BOOL)arg3;
- (void)_updateViewSettings;
- (void)_setRichTextReaderViewportSettings;
- (void)_setScalesPageToFitViewportSettings;
- (void)_didRotate:(id)arg1;
@property(nonatomic) BOOL keyboardDisplayRequiresUserAction;
- (void)decodeRestorableStateWithCoder:(id)arg1;
- (void)encodeRestorableStateWithCoder:(id)arg1;
- (BOOL)isElementAccessibilityExposedToInterfaceBuilder;
- (Class)_printFormatterClass;

@end

从函数名看其主要作用,只列non-public API:

  • 选择/全选/复制网页内容
  • 维护设置项
  • 设置是否在WebThread渲染页面
  • 设置是否允许选择网页内容
  • 提供截图的接口(newSnapshotWithRect)
  • 在UIWebDocumentView传过来的回调通知中做进一步处理
  • 展示alertView,包括由js alert发起的对话框
  • 响应UIScrollViewDelegate的回调,传递消息给UIWebBrowserView
  • 处理旋转屏幕的逻辑
  • 序列化/反序列化

有一些API虽然名字看懂了,但没办法猜出意义,后面做反编译研究时再详细说吧。这个系列都是浅探。


下一篇:UIWebView体系结构(七)WebView

最后

以上就是可靠毛巾为你收集整理的UIWebView体系结构(六)UIWebView的全部内容,希望文章能够帮你解决UIWebView体系结构(六)UIWebView所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(34)

评论列表共有 0 条评论

立即
投稿
返回
顶部