{"id":114,"date":"2022-10-18T09:54:22","date_gmt":"2022-10-18T09:54:22","guid":{"rendered":"https:\/\/blogs.igalia.com\/jkim\/?p=114"},"modified":"2022-10-26T10:49:50","modified_gmt":"2022-10-26T10:49:50","slug":"a-webview-tag-in-chromium","status":"publish","type":"post","link":"https:\/\/blogs.igalia.com\/jkim\/2022\/10\/18\/a-webview-tag-in-chromium\/","title":{"rendered":"A &lt;webview&gt; tag in Chromium"},"content":{"rendered":"\nI often talk about a webview as a common term. For instance, when I worked on <a href=\"https:\/\/www.automotivelinux.org\/\">AGL<\/a> project, we integrated <a href=\"https:\/\/static.sched.com\/hosted_files\/ossalsjp21\/74\/Flutter%20Apps%20On%20AGL%20With%20The%20Web%20Application%20Manager.pdf\">Web Runtime<\/a> in order to support a webview to native applications from AGL like Android WebView. However, I wasn\u2019t aware of &lt;webview&gt; tag implementation for a web page in Chromium. <br><br>\n\n\n\n\n<h2 class=\"wp-block-heading\"><em>&lt;webview&gt;<\/em><\/h2>\n\n\n\n\n&lt;webview&gt; is a tag that Chromium Apps and chrome:\/\/\u2026 pages could use.<br><br>\n\n\n\n<a href=\"https:\/\/source.chromium.org\/chromium\/chromium\/src\/+\/main:chrome\/test\/data\/extensions\/platform_apps\/web_view\/\">Chromium has some samples using &lt;webview&gt;<\/a> for testing. I launched one of these examples with some modification to include &lt;div&gt; at the same level with a &lt;webview&gt;.<br><br>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blogs.igalia.com\/jkim\/files\/2022\/10\/sample_webview.png\" alt=\"\" class=\"wp-image-115\" width=\"384\" height=\"319\" \/><\/figure>\n\n\n\nThe green box is a &lt;webview&gt; and the blue box is &lt;div&gt;.\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blogs.igalia.com\/jkim\/files\/2022\/10\/sample_inspector.png\" alt=\"\" class=\"wp-image-116\" width=\"581\" height=\"366\" srcset=\"https:\/\/blogs.igalia.com\/jkim\/files\/2022\/10\/sample_inspector.png 951w, https:\/\/blogs.igalia.com\/jkim\/files\/2022\/10\/sample_inspector-300x189.png 300w, https:\/\/blogs.igalia.com\/jkim\/files\/2022\/10\/sample_inspector-768x485.png 768w, https:\/\/blogs.igalia.com\/jkim\/files\/2022\/10\/sample_inspector-476x300.png 476w\" sizes=\"auto, (max-width: 581px) 100vw, 581px\" \/><\/figure>\n\n\n\nA web page includes &lt;webview&gt; that has another web page inside it. Note that a &lt;webview&gt; tag is not a standard and it\u2019s used for Chrome Apps and chrome:\/\/ pages.<br><br><br>\n\n\n\n\n<h2 class=\"wp-block-heading\">WebContents is<br><\/h2>\n\n\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">A reusable component that is the main class of the Content module. It&#8217;s easily embeddable to allow multiprocess rendering of HTML into a view. <\/p><\/blockquote>\n\n\n\n\nThis image shows the conceptual application layers in Chromium.\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"472\" height=\"204\" src=\"https:\/\/blogs.igalia.com\/jkim\/files\/2022\/10\/How-Chromium-Displays-Web-Pages_-Conceptual-application-layers.png\" alt=\"\" class=\"wp-image-117\" srcset=\"https:\/\/blogs.igalia.com\/jkim\/files\/2022\/10\/How-Chromium-Displays-Web-Pages_-Conceptual-application-layers.png 472w, https:\/\/blogs.igalia.com\/jkim\/files\/2022\/10\/How-Chromium-Displays-Web-Pages_-Conceptual-application-layers-300x130.png 300w\" sizes=\"auto, (max-width: 472px) 100vw, 472px\" \/>\n\n<figcaption><a href=\"https:\/\/www.chromium.org\/developers\/design-documents\/displaying-a-web-page-in-chrome\/\">https:\/\/www.chromium.org\/developers\/design-documents\/displaying-a-web-page-in-chrome\/<\/a><\/figcaption>\n\n<\/figure>\n\n\n\nWhen we open a web page in Chromium, you can imagine that Chromium creates a WebContents and it shows us the rendered web page.<br><br><br>\n\n\n\n\n<h2 class=\"wp-block-heading\">Current implementation<\/h2>\n\n\n\n\nWhen &lt;webview&gt; exists in a web page, how does it work and where is it located on these layers from the image above?<br><br>\n\n\n\nBased on the current implementation, WebContents can have inner WebContents. Chromium implements a &lt;webview&gt; tag with a <a href=\"https:\/\/source.chromium.org\/chromium\/chromium\/src\/+\/main:components\/guest_view\/browser\/guest_view.h\">GuestVIew<\/a> which is the templated base class for out-of-process frames in the chrome layer. A GuestView maintains an association between a guest WebContents and an owner WebContents. <br><br>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"438\" height=\"190\" src=\"https:\/\/blogs.igalia.com\/jkim\/files\/2022\/10\/innerWebContents-4.png\" alt=\"\" class=\"wp-image-172\" srcset=\"https:\/\/blogs.igalia.com\/jkim\/files\/2022\/10\/innerWebContents-4.png 438w, https:\/\/blogs.igalia.com\/jkim\/files\/2022\/10\/innerWebContents-4-300x130.png 300w\" sizes=\"auto, (max-width: 438px) 100vw, 438px\" \/><\/figure>\n\n\n\nFor a &lt;webview&gt; interface at Javascript, Chromium has custom bindings. When a &lt;webview&gt; tag is attached, the API connected by the custom bindings is called from the renderer. The request for attaching it is sent to the browser through <a href=\"https:\/\/source.chromium.org\/chromium\/chromium\/src\/+\/main:components\/guest_view\/common\/guest_view.mojom?q=guest_view.mojom\">Mojo interface<\/a>.<br><br><br>\n\n\n\n\n<pre class=\"wp-block-preformatted\">interface GuestViewHost {\n\/\/ We have a RenderFrame with routing id of |embedder_local_frame_routing_id|.\n\/\/ We want this local frame to be replaced with a remote frame that points\n\/\/ to a GuestView. This message will attach the local frame to the guest.\n\/\/ The GuestView is identified by its ID: |guest_instance_id|.\n&nbsp;AttachToEmbedderFrame(\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int32 embedder_local_frame_routing_id,\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int32 element_instance_id,\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int32 guest_instance_id,\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mojo_base.mojom.DictionaryValue params) =&gt; ();<\/pre>\n\n\n\n\nIt triggers <strong>WebContentsImpl::AttachInnerWebContents()<\/strong> to attach the inner WebContents to the outer WebContents.<br><br>\n\n\n\nChromium has also another type of GuestView internally. That is <a href=\"https:\/\/source.chromium.org\/chromium\/chromium\/src\/+\/main:extensions\/browser\/guest_view\/mime_handler_view\/mime_handler_view_guest.h;l=83\">MimeHandlerViewGuest<\/a> to handle mime types from tags such as &lt;object&gt; or &lt;embed&gt;. For instance, if &lt;embed&gt; tag is linked to pdf file, it\u2019s also managed by a GuestView.<br><br><br>\n\n\n\n\n<h2 class=\"wp-block-heading\">MPArch<\/h2>\n\n\n\n\nThese days I\u2019m working on MPArch, that <br>\n\n\n\n\n<blockquote class=\"wp-block-quote\">\u2022 enables one WebContents to host multiple (active \/ inactive, visible \/ invisible) pages.\n\nfrom <a href=\"https:\/\/docs.google.com\/document\/d\/1NginQ8k0w3znuwTiJ5qjYmBKgZDekvEPC22q0I4swxQ\/edit#\">MPArch document<\/a><\/p><\/blockquote>\n\n\n\n\nFor the detail for MPArch, you could refer to this blog post, &#8216;<a href=\"https:\/\/blogs.igalia.com\/gyuyoung\/2022\/10\/13\/mparchmultiple-page-architecture-project-in-chromium\/\">MPArch(Multiple Page Architecture) project in Chromium<\/a>&#8216;.<br><br>\n\n\n\nAs a GuestView is implemented with a Multiple-WebContents model, it\u2019s also considered for MPArch. <br>After <a href=\"https:\/\/www.youtube.com\/watch?v=vva1wCF6XE4\">working on Prerendering and fenced frames intensively<\/a>, our team started to migrate GuestView tests in order to avoid direct access to WebContents and manage it based on RenderFrameHost.<br>Once we have some progress regarding GuestView, I hope we could share the status, as well.<br><br><br>\n\n\n\nWe&#8217;re hiring. <a href=\"https:\/\/www.igalia.com\/jobs\/\">https:\/\/www.igalia.com\/jobs\/<\/a><br><br><br>\n","protected":false},"excerpt":{"rendered":"<p>I often talk about a webview as a common term. For instance, when I worked on AGL project, we integrated Web Runtime in order to support a webview to native applications from AGL like Android WebView. However, I wasn\u2019t aware &hellip; <a href=\"https:\/\/blogs.igalia.com\/jkim\/2022\/10\/18\/a-webview-tag-in-chromium\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":55,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[14,15,13],"class_list":["post-114","post","type-post","status-publish","format-standard","hentry","category-chromium","tag-guestview","tag-mparch","tag-webview"],"_links":{"self":[{"href":"https:\/\/blogs.igalia.com\/jkim\/wp-json\/wp\/v2\/posts\/114","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.igalia.com\/jkim\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.igalia.com\/jkim\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.igalia.com\/jkim\/wp-json\/wp\/v2\/users\/55"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.igalia.com\/jkim\/wp-json\/wp\/v2\/comments?post=114"}],"version-history":[{"count":56,"href":"https:\/\/blogs.igalia.com\/jkim\/wp-json\/wp\/v2\/posts\/114\/revisions"}],"predecessor-version":[{"id":182,"href":"https:\/\/blogs.igalia.com\/jkim\/wp-json\/wp\/v2\/posts\/114\/revisions\/182"}],"wp:attachment":[{"href":"https:\/\/blogs.igalia.com\/jkim\/wp-json\/wp\/v2\/media?parent=114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.igalia.com\/jkim\/wp-json\/wp\/v2\/categories?post=114"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.igalia.com\/jkim\/wp-json\/wp\/v2\/tags?post=114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}