Index: Source/core/frame/LocalDOMWindow.cpp |
diff --git a/Source/core/frame/LocalDOMWindow.cpp b/Source/core/frame/LocalDOMWindow.cpp |
index 7ee9063c803257a93a00d294f0d933139efea4ec..ab8978ea135f1afe80b43837dffee13403995674 100644 |
--- a/Source/core/frame/LocalDOMWindow.cpp |
+++ b/Source/core/frame/LocalDOMWindow.cpp |
@@ -35,6 +35,7 @@ |
#include "bindings/core/v8/ScriptController.h" |
#include "bindings/core/v8/SerializedScriptValue.h" |
#include "bindings/core/v8/V8DOMActivityLogger.h" |
+#include "bindings/core/v8/V8Document.h" |
#include "core/css/CSSComputedStyleDeclaration.h" |
#include "core/css/CSSRuleList.h" |
#include "core/css/DOMWindowCSS.h" |
@@ -70,6 +71,7 @@ |
#include "core/frame/Screen.h" |
#include "core/frame/ScrollOptions.h" |
#include "core/frame/Settings.h" |
+#include "core/frame/csp/ContentSecurityPolicy.h" |
#include "core/html/HTMLFrameOwnerElement.h" |
#include "core/inspector/ConsoleMessage.h" |
#include "core/inspector/ConsoleMessageStorage.h" |
@@ -1923,6 +1925,34 @@ PassOwnPtr<LifecycleNotifier<LocalDOMWindow> > LocalDOMWindow::createLifecycleNo |
return DOMWindowLifecycleNotifier::create(this); |
} |
+void LocalDOMWindow::replaceDocument(String documentSource, String contentType, String encodingName) |
+{ |
+ ASSERT(frame()); |
+ RefPtrWillBeRawPtr<Document> oldDocument(m_document); |
+ |
+ DocumentInit init(oldDocument->url(), frame()); |
+ |
+ bool forceXHTML = contentType == "text/plain"; |
+ |
+ RefPtrWillBeRawPtr<Document> newDocument = installNewDocument(contentType, init, forceXHTML); |
+ |
+ // Before parsing, we need to save & detach the old document and get the new document |
+ // in place. We have to do this only if we're rendering the result document. |
+ if (FrameView* view = frame()->view()) |
+ view->clear(); |
+ |
+ newDocument->updateSecurityOrigin(oldDocument->securityOrigin()); |
+ newDocument->setCookieURL(oldDocument->cookieURL()); |
+ newDocument->contentSecurityPolicy()->copyStateFrom(oldDocument->contentSecurityPolicy()); |
+ |
+ DocumentEncodingData data; |
+ data.setEncoding(WTF::TextEncoding(encodingName)); |
+ newDocument->setEncodingData(data); |
+ |
+ V8Document::PrivateScript::setTransformSourceDocumentMethod(frame(), newDocument.get(), oldDocument.get()); |
+ newDocument->setContent(documentSource); |
+} |
+ |
void LocalDOMWindow::trace(Visitor* visitor) |
{ |
#if ENABLE(OILPAN) |