当前位置: 首页 > 工具软件 > WebCore > 使用案例 >

WebCore的mainframe或者frame和网页中的frame标签是什么关系?

宰烈
2023-12-01

原创,转载清注明!

1 什么是mainFrame?

     WebCore中,Page的mainFrame只是一个软件上的概念,并不针对具体的网页标签,是webview 创建第一个Frame实例之后,Page的mainFrame存储的是此Frame的引用。它与网页中有没有Frame标签没有关系。

     比如网页中这么写:

<html>

<head>

<title>hello world!</title>

</head>

<body>

</body>

</html>


WebCore这么创建Frame并把它设置为Page的mainFrame:

webkitwebframe.cpp: webkit_web_frame_new(){

       Frame::create(viewPriv->corePage, 0, client);

}

Frame的工厂方法:

Frame::create(Page* page, HTMLFrameOwnerElement* ownerElement, FrameLoaderClient* client) {

   RefPtr<Frame> frame = adoptRef(new Frame(page, ownerElement, client));

   注意:mainFrame没有宿主!在Frame中来说,此为区别普通的Frame和mainFrame的唯一差别。

   if (!ownerElement)

       page->setMainFrame(frame);

   return frame.release();

}

#0  WebCore::Frame::create,  Frame.cpp:205

#1 in webkit_web_frame_new (webView=0x6d2030)

   at ../../Source/WebKit/gtk/webkit/webkitwebframe.cpp:419

#2 in webkit_web_view_init (webView=0x6d2030)

   at ../../Source/WebKit/gtk/webkit/webkitwebview.cpp:3407


2 Frame标签和WebCore的Frame的区别和联系?

      Frame标签在WebCore中是用HTMLFrameElement来表示的,它是一个标准的Element。与其他element不同,不同的platform提供了不同的support,比如gtk是这样创建Frame的:

FrameLoaderClientGtk.cpp:

RefPtr<Frame> childFrame = Frame::create(page, ownerElement, new FrameLoaderClient(kitFrame));

     此时创建的叫child Frame,相对于mainFrame来说。你看,她有宿主ownerElement--其实就是FrameElement的基类FrameElementBase的实例。请参看下一节。


      网页中的Frame标签在WebCore中称为SubFrame,一个Frame标签就会使得WebCore 调用FrameLoaderClient以便new一个Frame,解释如下:


      如果网页中这么写:

<html>

<head>

<title>hello world!</title>

</head>

<frameset name="main_frame" cols="100%">

       <frame src="00000.gif" id="content_area" name="content_area">

</frameset>

</html>


WebCore是如下图这么工作的,与处理其他Element是一样的:

#0  WebCore::Frame::create (page=, ownerElement=, client=)   at ../../Source/WebCore/page/Frame.cpp:205

#1 in WebKit::FrameLoaderClient::createFrame (this ownerElement=)   at WebKit/gtk/WebCoreSupport/FrameLoaderClientGtk.cpp:652

#2 in WebCore::SubframeLoader::loadSubframe (this=, ownerElement=,   url=..., name=..., referrer=...) at loader/SubframeLoader.cpp:265

#3 in WebCore::SubframeLoader::loadOrRedirectSubframe (this ownerElement=, . lockBackForwardList=true)  at loader/SubframeLoader.cpp:240

#4 in WebCore::SubframeLoader::requestFrame (this, ownerElement,   =..., =..., lockHistory=true, lockBackForwardList=true)   at loader/SubframeLoader.cpp:83

#5 in WebCore::HTMLFrameElementBase::openURL (this, lockHistory=true,   lockBackForwardList=true) at ../../Source/WebCore/html/HTMLFrameElementBase.cpp:102

#6 in WebCore::HTMLFrameElementBase::setNameAndOpenURL (this)   at ../../Source/WebCore/html/HTMLFrameElementBase.cpp:153

#7 in WebCore::HTMLFrameElementBase::insertedIntoDocument (this)   at ../../Source/WebCore/html/HTMLFrameElementBase.cpp:187

#8 in WebCore::ContainerNode::parserAddChild (this, newChild=...)   at ../../Source/WebCore/dom/ContainerNode.cpp:690

#9 in WebCore::HTMLConstructionSite::attach<WebCore::Element> (this,  rawParent, prpChild=...) at../../Source/WebCore/html/parser/HTMLConstructionSite.cpp:103


3 Frame::create 时的 ownerElement是谁?其实就是HTMLFrameElement的基类HTMLFrameElementBase:

#0  WebCore::HTMLFrameElementBase::HTMLFrameElementBase (this=, tagName=..., document=)   at ../../Source/WebCore/html/HTMLFrameElementBase.cpp:56

#1   in WebCore::HTMLFrameElement::HTMLFrameElement (this=, tagName=...,   document=) at ../../Source/WebCore/html/HTMLFrameElement.cpp:40

#2   in WebCore::HTMLFrameElement::create (tagName=..., document=)   at ../../Source/WebCore/html/HTMLFrameElement.cpp:47

#3   in WebCore::frameConstructor (tagName=..., document=)   at DerivedSources/WebCore/HTMLElementFactory.cpp:266

#4   in WebCore::HTMLElementFactory::createHTMLElement (qName=..., document=,

   formElement=0x0, createdByParser=true) at DerivedSources/WebCore/HTMLElementFactory.cpp:649

#5   in WebCore::HTMLConstructionSite::createHTMLElement (this=, token=...)

   at ../../Source/WebCore/html/parser/HTMLConstructionSite.cpp:384

未完待续
 类似资料: