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

Side by Side Diff: third_party/WebKit/Source/web/LocalFrameClientImpl.cpp

Issue 2912213002: Support serializing shadow DOM to MHTML (Closed)
Patch Set: Add .gitattributes 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009, 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2009, 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2011 Apple Inc. All rights reserved. 3 * Copyright (C) 2011 Apple Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are 6 * modification, are permitted provided that the following conditions are
7 * met: 7 * met:
8 * 8 *
9 * * Redistributions of source code must retain the above copyright 9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 web_frame_->Client()->DidCreateDocumentElement(web_frame_); 205 web_frame_->Client()->DidCreateDocumentElement(web_frame_);
206 } 206 }
207 207
208 void LocalFrameClientImpl::RunScriptsAtDocumentElementAvailable() { 208 void LocalFrameClientImpl::RunScriptsAtDocumentElementAvailable() {
209 if (web_frame_->Client()) 209 if (web_frame_->Client())
210 web_frame_->Client()->RunScriptsAtDocumentElementAvailable(web_frame_); 210 web_frame_->Client()->RunScriptsAtDocumentElementAvailable(web_frame_);
211 // The callback might have deleted the frame, do not use |this|! 211 // The callback might have deleted the frame, do not use |this|!
212 } 212 }
213 213
214 void LocalFrameClientImpl::RunScriptsAtDocumentReady(bool document_is_empty) { 214 void LocalFrameClientImpl::RunScriptsAtDocumentReady(bool document_is_empty) {
215 if (!document_is_empty && IsLoadedAsMHTMLArchive(web_frame_->GetFrame())) {
216 // For MHTML pages, recreate the shadow DOM contents from the templates that
217 // are captured from the shadow DOM trees at serialization.
218 // Note that the MHTML page is loaded in sandboxing mode with script
219 // execution disabled and thus only the following script will be executed.
220 // Any other scripts and event handlers outside the scope of the following
221 // script, including those that may be inserted in shadow DOM templates,
222 // will NOT be run.
223 String script = R"(
224 function createShadowRootWithin(node) {
225 var nodes = node.querySelectorAll('template[shadowmode]');
226 for (var i = 0; i < nodes.length; ++i) {
227 var template = nodes[i];
228 var mode = template.getAttribute('shadowmode');
229 var parent = template.parentNode;
230 parent.removeChild(template);
Dmitry Titov 2017/06/06 04:42:09 Just to be on a safe side, lets check parent for n
jianli 2017/06/07 00:53:42 Done.
231 var shadowRoot;
232 if (mode == 'v0') {
233 shadowRoot = parent.createShadowRoot();
234 } else if (mode == 'open' || mode == 'closed') {
235 var delegatesFocus = template.hasAttribute('shadowdelegatesfocus');
236 shadowRoot = parent.attachShadow({'mode': mode,
237 'delegatesFocus': delegatesFocus});
238 }
239 if (!shadowRoot)
240 continue;
241 var clone = document.importNode(template.content, true);
242 shadowRoot.appendChild(clone);
243 createShadowRootWithin(shadowRoot);
244 }
245 }
246 createShadowRootWithin(document.body);
247 )";
248 web_frame_->GetFrame()->GetScriptController().ExecuteScriptInMainWorld(
249 script, ScriptController::kExecuteScriptWhenScriptsDisabled);
250 }
251
215 if (web_frame_->Client()) { 252 if (web_frame_->Client()) {
216 web_frame_->Client()->RunScriptsAtDocumentReady(document_is_empty); 253 web_frame_->Client()->RunScriptsAtDocumentReady(document_is_empty);
217 } 254 }
218 // The callback might have deleted the frame, do not use |this|! 255 // The callback might have deleted the frame, do not use |this|!
219 } 256 }
220 257
221 void LocalFrameClientImpl::RunScriptsAtDocumentIdle() { 258 void LocalFrameClientImpl::RunScriptsAtDocumentIdle() {
222 if (web_frame_->Client()) 259 if (web_frame_->Client())
223 web_frame_->Client()->RunScriptsAtDocumentIdle(); 260 web_frame_->Client()->RunScriptsAtDocumentIdle();
224 // The callback might have deleted the frame, do not use |this|! 261 // The callback might have deleted the frame, do not use |this|!
(...skipping 815 matching lines...) Expand 10 before | Expand all | Expand 10 after
1040 1077
1041 TextCheckerClient& LocalFrameClientImpl::GetTextCheckerClient() const { 1078 TextCheckerClient& LocalFrameClientImpl::GetTextCheckerClient() const {
1042 return web_frame_->GetTextCheckerClient(); 1079 return web_frame_->GetTextCheckerClient();
1043 } 1080 }
1044 1081
1045 std::unique_ptr<blink::WebURLLoader> LocalFrameClientImpl::CreateURLLoader() { 1082 std::unique_ptr<blink::WebURLLoader> LocalFrameClientImpl::CreateURLLoader() {
1046 return web_frame_->CreateURLLoader(); 1083 return web_frame_->CreateURLLoader();
1047 } 1084 }
1048 1085
1049 } // namespace blink 1086 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698