Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Unified Diff: third_party/WebKit/Source/web/LocalFrameClientImpl.cpp

Issue 2912213002: Support serializing shadow DOM to MHTML (Closed)
Patch Set: Strip anoter shadow attribute Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/web/LocalFrameClientImpl.cpp
diff --git a/third_party/WebKit/Source/web/LocalFrameClientImpl.cpp b/third_party/WebKit/Source/web/LocalFrameClientImpl.cpp
index 7bc97f1198510386c695be3720b18c84da150189..b1e3d1e6c1fea70672dd1cad80e72a84662afce1 100644
--- a/third_party/WebKit/Source/web/LocalFrameClientImpl.cpp
+++ b/third_party/WebKit/Source/web/LocalFrameClientImpl.cpp
@@ -212,6 +212,45 @@ void LocalFrameClientImpl::RunScriptsAtDocumentElementAvailable() {
}
void LocalFrameClientImpl::RunScriptsAtDocumentReady(bool document_is_empty) {
+ if (!document_is_empty && IsLoadedAsMHTMLArchive(web_frame_->GetFrame())) {
+ // For MHTML pages, recreate the shadow DOM contents from the templates that
+ // are captured from the shadow DOM trees at serialization.
+ // Note that the MHTML page is loaded in sandboxing mode with script
+ // execution disabled and thus only the following script will be executed.
+ // Any other scripts and event handlers outside the scope of the following
+ // script, including those that may be inserted in shadow DOM templates,
+ // will NOT be run.
+ String script = R"(
+function createShadowRootWithin(node) {
+ var nodes = node.querySelectorAll('template[shadowmode]');
+ for (var i = 0; i < nodes.length; ++i) {
+ var template = nodes[i];
+ var mode = template.getAttribute('shadowmode');
+ var parent = template.parentNode;
+ if (!parent)
+ continue;
+ parent.removeChild(template);
+ var shadowRoot;
+ if (mode == 'v0') {
+ shadowRoot = parent.createShadowRoot();
+ } else if (mode == 'open' || mode == 'closed') {
+ var delegatesFocus = template.hasAttribute('shadowdelegatesfocus');
+ shadowRoot = parent.attachShadow({'mode': mode,
+ 'delegatesFocus': delegatesFocus});
+ }
+ if (!shadowRoot)
+ continue;
+ var clone = document.importNode(template.content, true);
+ shadowRoot.appendChild(clone);
+ createShadowRootWithin(shadowRoot);
+ }
+}
+createShadowRootWithin(document.body);
+)";
+ web_frame_->GetFrame()->GetScriptController().ExecuteScriptInMainWorld(
+ script, ScriptController::kExecuteScriptWhenScriptsDisabled);
+ }
+
if (web_frame_->Client()) {
web_frame_->Client()->RunScriptsAtDocumentReady(document_is_empty);
}
« no previous file with comments | « third_party/WebKit/Source/core/frame/FrameSerializer.cpp ('k') | third_party/WebKit/Source/web/WebFrameSerializer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698