webkit之webview

这里介绍的是WebKit的基础知识,主要针对初学者。闲话少叙,直表正文:

WebKit松散的遵循model-view-controller paradigm,一些对象表现为view-controllers,另一些对象则表现为models。

+

WebView是WebKit中的核心view类,管理WebFrameView对象和WebFrame对象的交互。

WebView、WebFrameView和WebFrame的关系图如下:

Figure 1 WebView and WebFrameView objects

 

以下是Apple的官方文档中的描述

For example, suppose a webpage contains a frame with two children frames, as illustrated in Figure 1.
To load this page, you send a request to the main frame of aWebView, an instance of WebView.
The mainframe initiates a client request.
While it receives the server response (that is, loads the page content), the main frame creates WebFrame objects to encapsulate the content contained in each frame element.
A hierarchy ofWebFrame objects is used to model an entire webpage, where the root is called the main frame.

As the content for each WebFrame object is loaded, a corresponding WebFrameView object is created to
display that content。

+

下图展示了WebFrame、WebDataSource、WebDocumentRepresentation、WebDocumentView对象的关系

Figure 2  WebFrame and WebDataSource objects

以下是Apple的官方文档中的描述

For each WebFrame object, there’s one WebDataSource object that loads the content for that frame.
For each WebDataSource object, there’s one document representation object, conforming to the WebDocumentRepresentation protocol, that encapsulates the data for a specific MIME type.
For each documentation representation object, there’s a document view object, conforming to the WebDocumentView protocol, that handles the display of that data.
The document view object is contained in the corresponding WebFrameView object

WebKit采用了异步方式来处理页面的加载,因此在发起请求到第一个字节返回这段时间内,WebKit需要维护各个相关对象的状态。也有可能在访问一个页面时出现错误,诸如网络错误、bad URL等。

一个请求初始化后到请求的内容返,需要一个时间段,在此时间段内WebKit需要处理各个相关对象的状态,因此而创建了一个被称作provisional的data source。这个data source不知道清请求的内容是否成功返回。(注释:provisional和committed只是data source的两个状态)

当请求内容的第一个字节返回后,data source就变成了被称作committed的data source。如果provisional超过了有效期或请求发生了错误,则不会变成committed。当data source变成committed后,创建相应的doucment representation和document view对象。

+

WebView提供了一系列的delegate,以支持用户自定义行为,描述如下:

·Frame load delegate - 用于获取frame级的请求和响应消息,能够追踪页面的加载过程。

·Resource load delegate - 用于获取resource级的请求和响应消息,能够追踪资源的加载过程(图片、css等统称为资源)

·User interface delegate - 用于界面相关

·Policy delegate - 策略相关

随后会比较详细的介绍上述四类delegate。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值