Title: [100550] trunk
Revision
100550
Author
[email protected]
Date
2011-11-16 19:08:21 -0800 (Wed, 16 Nov 2011)

Log Message

Make sure MHTML documents use the domain of the MHTML file.
https://bugs.webkit.org/show_bug.cgi?id=72445

Reviewed by Adam Barth.

Source/WebCore:

* dom/Document.h:
(WebCore::Document::setBaseURL):
* loader/FrameLoader.cpp:
(WebCore::FrameLoader::receivedFirstData):

LayoutTests:

* mhtml/check_domain-expected.txt: Added.
* mhtml/check_domain.mht: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (100549 => 100550)


--- trunk/LayoutTests/ChangeLog	2011-11-17 03:06:36 UTC (rev 100549)
+++ trunk/LayoutTests/ChangeLog	2011-11-17 03:08:21 UTC (rev 100550)
@@ -1,3 +1,13 @@
+2011-11-16  Jay Civelli  <[email protected]>
+
+        Make sure MHTML documents use the domain of the MHTML file.
+        https://bugs.webkit.org/show_bug.cgi?id=72445
+
+        Reviewed by Adam Barth.
+
+        * mhtml/check_domain-expected.txt: Added.
+        * mhtml/check_domain.mht: Added.
+
 2011-11-11  Adrienne Walker  <[email protected]>
 
         [chromium] Expose mock scrollbars to window.internals

Added: trunk/LayoutTests/mhtml/check_domain-expected.txt (0 => 100550)


--- trunk/LayoutTests/mhtml/check_domain-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/mhtml/check_domain-expected.txt	2011-11-17 03:08:21 UTC (rev 100550)
@@ -0,0 +1,4 @@
+This is a very simple page
+
+Very basic page.
+PASS

Added: trunk/LayoutTests/mhtml/check_domain.mht (0 => 100550)


--- trunk/LayoutTests/mhtml/check_domain.mht	                        (rev 0)
+++ trunk/LayoutTests/mhtml/check_domain.mht	2011-11-17 03:08:21 UTC (rev 100550)
@@ -0,0 +1,45 @@
+From: <Saved by UnMHT>
+Subject: =?iso-2022-jp?B?QSBzaW1wbGUgcGFnZQ==?=
+Date: Wed, May 11 2011 15:36:36 GMT-0700
+MIME-Version: 1.0
+Content-Type: multipart/related;
+	boundary="----=_NextPart_000_0000_87206557.D2C008B0";
+	type="text/html"
+
+------=_NextPart_000_0000_87206557.D2C008B0
+Content-Type: text/html; charset="ISO-8859-1"
+Content-Transfer-Encoding: quoted-printable
+Content-Location: http://localhost/simple_page.html
+
+<html><head><meta http-equiv=3D"Content-Type" content=3D"text/html; charset=
+=3Diso-8859-1">
+
+
+<title>A simple page</title>
+<script>
+if (window.layoutTestController) {
+  layoutTestController.dumpAsText();
+  layoutTestController.waitUntilDone();
+}
+
+window._onload_ = function() {
+  var span=3Ddocument.createElement("span");
+  if (window.location !=3D 'http://localhost/simple_page.html' &&
+      document.domain !=3D 'localhost') {
+     span.innerHTML = "PASS";
+  } else {
+     span.innerHTML = "FAIL window.location=" + window.location +
+         " document.domain=" + document.domain;
+  }
+
+  document.getElementById('locDiv').appendChild(span);
+  layoutTestController.notifyDone();
+}
+
+</script>
+<base href=""
+<h1>This is a very simple page</h1>
+Very <b>basic</b> page.
+<div id=3D'locDiv'></div>
+</body></html>
+------=_NextPart_000_0000_87206557.D2C008B0--

Modified: trunk/Source/WebCore/ChangeLog (100549 => 100550)


--- trunk/Source/WebCore/ChangeLog	2011-11-17 03:06:36 UTC (rev 100549)
+++ trunk/Source/WebCore/ChangeLog	2011-11-17 03:08:21 UTC (rev 100550)
@@ -1,3 +1,15 @@
+2011-11-16  Jay Civelli  <[email protected]>
+
+        Make sure MHTML documents use the domain of the MHTML file.
+        https://bugs.webkit.org/show_bug.cgi?id=72445
+
+        Reviewed by Adam Barth.
+
+        * dom/Document.h:
+        (WebCore::Document::setBaseURL):
+        * loader/FrameLoader.cpp:
+        (WebCore::FrameLoader::receivedFirstData):
+
 2011-11-16  Julien Chaffraix  <[email protected]>
 
         Update supported display list after -webkit-grid and -webkit-inline-grid addition

Modified: trunk/Source/WebCore/dom/Document.cpp (100549 => 100550)


--- trunk/Source/WebCore/dom/Document.cpp	2011-11-17 03:06:36 UTC (rev 100549)
+++ trunk/Source/WebCore/dom/Document.cpp	2011-11-17 03:08:21 UTC (rev 100550)
@@ -2403,12 +2403,16 @@
     // DOM 3 Core: When the Document supports the feature "HTML" [DOM Level 2 HTML], the base URI is computed using
     // first the value of the href attribute of the HTML BASE element if any, and the value of the documentURI attribute
     // from the Document interface otherwise.
-    if (m_baseElementURL.isEmpty()) {
+    if (!m_baseElementURL.isEmpty())
+        m_baseURL = m_baseElementURL;
+    else if (!m_baseURLOverride.isEmpty())
+        m_baseURL = m_baseURLOverride;
+    else {
         // The documentURI attribute is an arbitrary string. DOM 3 Core does not specify how it should be resolved,
         // so we use a null base URL.
         m_baseURL = KURL(KURL(), documentURI());
-    } else
-        m_baseURL = m_baseElementURL;
+    }
+
     if (!m_baseURL.isValid())
         m_baseURL = KURL();
 
@@ -2418,6 +2422,12 @@
         m_mappedElementSheet->setFinalURL(m_baseURL);
 }
 
+void Document::setBaseURLOverride(const KURL& url)
+{
+    m_baseURLOverride = url;
+    updateBaseURL();
+}
+
 void Document::processBaseElement()
 {
     // Find the first href attribute in a base element and the first target attribute in a base element.

Modified: trunk/Source/WebCore/dom/Document.h (100549 => 100550)


--- trunk/Source/WebCore/dom/Document.h	2011-11-17 03:06:36 UTC (rev 100549)
+++ trunk/Source/WebCore/dom/Document.h	2011-11-17 03:08:21 UTC (rev 100550)
@@ -608,6 +608,8 @@
     void setURL(const KURL&);
 
     const KURL& baseURL() const { return m_baseURL; }
+    void setBaseURLOverride(const KURL&);
+    const KURL& baseURLOverride() const { return m_baseURLOverride; }
     const String& baseTarget() const { return m_baseTarget; }
     void processBaseElement();
 
@@ -1186,6 +1188,7 @@
     // Document URLs.
     KURL m_url; // Document.URL: The URL from which this document was retrieved.
     KURL m_baseURL; // Node.baseURI: The URL to use when resolving relative URLs.
+    KURL m_baseURLOverride; // An alternative base URL that takes precedence ove m_baseURL (but not m_baseElementURL).
     KURL m_baseElementURL; // The URL set by the <base> element.
     KURL m_cookieURL; // The URL to use for cookie access.
     KURL m_firstPartyForCookies; // The policy URL for third-party cookie blocking.

Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (100549 => 100550)


--- trunk/Source/WebCore/loader/FrameLoader.cpp	2011-11-17 03:06:36 UTC (rev 100549)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp	2011-11-17 03:08:21 UTC (rev 100550)
@@ -563,7 +563,7 @@
 void FrameLoader::receivedFirstData()
 {
     KURL workingURL = activeDocumentLoader()->documentURL();
-#if ENABLE(WEB_ARCHIVE) || ENABLE(MHTML)
+#if ENABLE(WEB_ARCHIVE)
     // FIXME: The document loader, not the frame loader, should be in charge of loading web archives.
     // Once this is done, we can just make DocumentLoader::documentURL() return the right URL
     // based on whether it has a non-null archive or not.
@@ -576,7 +576,15 @@
 
     dispatchDidCommitLoad();
     dispatchDidClearWindowObjectsInAllWorlds();
-    
+
+#if ENABLE(MHTML)
+    if (m_archive) {
+        // The origin is the MHTML file, we need to set the base URL to the document encoded in the MHTML so
+        // relative URLs are resolved properly.
+        m_frame->document()->setBaseURLOverride(m_archive->mainResource()->url());
+    }
+#endif
+
     if (m_documentLoader) {
         StringWithDirection ptitle = m_documentLoader->title();
         // If we have a title let the WebView know about it.
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to