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

时间: 2024-09-16 09:09:37

UIWebView体系结构(六)UIWebView的相关文章

UIWebView体系结构(七)WebView

在<iOS WebCore的wak目录>中证实了iOS的WebKit是想尽可能复用Mac上的代码,所以WebView在iOS和Mac上差不多. Mac WebView的参考文档: https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/WebKit/Classes/WebView_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40003822 当然,

UIWebView体系结构(三)UIWebDocumentView和WebView

WebView是UIWebDocumentView最重要的组合对象,先讲WebView吧. WebView的声明如下:(代码好长,点此跳过) @interface WebView : WAKView { WebViewPrivate *_private; } + (void)registerViewClass:(Class)arg1 representationClass:(Class)arg2 forMIMEType:(id)arg3; + (void)registerURLSchemeAsL

UIWebView体系结构(四)UIWebBrowserView

UIWebBrowserView的声明如下:(代码好长,点此跳过) @interface UIWebBrowserView : UIWebDocumentView <UIWebFormAccessoryDelegate, UIBrowserDocumentController, _UIWebRotationDelegate> { UIWebFormAccessory *_accessory; NSObject<UIFormPeripheral> *_input; DOMNode *

UIWebView体系结构(一)概貌

UIWebView属于UIKit,封装了WebKit.framework的WebView: WebView组合管理了WebCore.framework的Page,并提供了各种Clients: Page管理了Main Frame,Main Frame管理了sub Frame(FrameTree). UIWebView层(点击图片查看全图): WebView层(点击图片查看全图): Page层(未标明的关系为组合): Frame层(未标明的关系为组合): 转载请注明出处:http://blog.cs

UIWebView体系结构(五)_UIWebViewScrollView和UIWebScrollView

_UIWebViewScrollView的继承链为:_UIWebViewScrollView->UIWebScrollView->UIScrollView. 通过反编译可以得到实现._UIWebViewScrollView和UIWebScrollView的实现为:(代码好长,点此跳过) @interface UIWebScrollView : UIScrollView - (void)didMoveToWindow; - (BOOL)touchesShouldCancelInContentVi

iOS开发中使用UIWebView 屏蔽 alert警告框_IOS

 如果是网页内容里面的alert,我们可以等网页加载完毕,也就是在webViewDidFinishLoad中执行下面的js代码,就可以屏蔽alert了 [myWebView stringByEvaluatingJavaScriptFromString:@"window.alert=null;"]; 但上面的方法对于网页onLoad事件里面的alert就不起作用了 解决方法就是给UIWebView添加一个类别: 给工程添加JavaScriptAlert.h @interface UIWe

Objective-C头文件导出工具class-dump

首先,这个工具是开源的.作者网站:http://stevenygard.com/projects/class-dump/ 用途: 分析库文件或可执行文件,得到Objective-C类和部分C结构体的信息.常见使用场景是得到系统SDK的私有API.头文件的例子请参考<UIWebView体系结构(六)UIWebView> 原理: Objective-C类的信息会有字符串来对应描述,分析保存这些信息的区域,梳理成Objective-C头文件输出.请参见<IDA反汇编/反编译静态分析iOS模拟器

iOS小技巧总结,有你不知道的么

在这里总结一些iOS开发中的小技巧,能大大方便我们的开发,持续更新. UITableView的Group样式下顶部空白处理 //分组列表头部空白处理 UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0.1)]; self.tableView.tableHeaderView = view; UITableView的plain样式下,取消区头停滞效果 - (void)scrollViewDidScroll:(UIScr

iOS开发系列--网络开发

概览 大部分应用程序都或多或少会牵扯到网络开发,例如说新浪微博.微信等,这些应用本身可能采用iOS开发,但是所有的数据支撑都是基于后台网络服务器的.如今,网络编程越来越普遍,孤立的应用通常是没有生命力的.今天就会给大家介绍这部分内容: Web请求和响应 使用代理方法 简化请求方法 图片缓存 扩展--文件分段下载 扩展--文件上传 NSURLSession 数据请求 文件上传 文件下载 会话 UIWebView 浏览器实现 UIWebView与页面交互 网络状态 目 录 Web请求和响应 使用代理