[iOS][wk2] Use ImageDocument to display subframe PDFs
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Jun 2014 01:35:32 +0000 (01:35 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 18 Jun 2014 01:35:32 +0000 (01:35 +0000)
https://bugs.webkit.org/show_bug.cgi?id=133944
<rdar://problem/17205983>

Reviewed by Dan Bates.

* dom/DOMImplementation.cpp:
(WebCore::DOMImplementation::createDocument):
Make a ImageDocument to show our subframe PDF, if the setting is enabled.

* html/ImageDocument.cpp:
(WebCore::ImageDocument::finishedParsing):
(WebCore::ImageDocument::createDocumentStructure):
Set the ResourceResponse on the ImageElement upon creation, instead of
when the load finishes. This way, when the internal CachedImage creates
its Image, it can have the correct MIME type for the response, and can
make a PDFDocumentImage if necessary.

We never noticed this before because CachedImage falls back to making a
BitmapImage, and that was the only case that was normally used.

Throw an explicit white background behind PDF ImageDocuments; PDFDocumentImage
paints with a transparent background, but when used as an ImageDocument
it seems reasonable to assume that there should be a white page background
(similar to what PDFPlugin and friends do).

* loader/DocumentWriter.cpp:
(WebCore::DocumentWriter::createDocument):
Don't make a PDFDocument if we want to use an ImageDocument for this subframe PDF.

* page/Settings.in:

* platform/MIMETypeRegistry.cpp:
(WebCore::MIMETypeRegistry::isPDFMIMEType):
* platform/MIMETypeRegistry.h:
Expose the already implemented pdfMIMETypes table just like all the rest.

* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::updatePreferences):
Always use ImageDocument for subframe PDFs in WebKit2 on iOS.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@170091 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/dom/DOMImplementation.cpp
Source/WebCore/html/ImageDocument.cpp
Source/WebCore/loader/DocumentWriter.cpp
Source/WebCore/page/Settings.in
Source/WebCore/platform/MIMETypeRegistry.cpp
Source/WebCore/platform/MIMETypeRegistry.h
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/WebPage/WebPage.cpp

index 1a8e7dce615607cc6da7fcf8d6dce4b4b2603369..191b555c0547c6d4f6667b393b8cbd549de937e2 100644 (file)
@@ -1,3 +1,42 @@
+2014-06-17  Tim Horton  <timothy_horton@apple.com>
+
+        [iOS][wk2] Use ImageDocument to display subframe PDFs
+        https://bugs.webkit.org/show_bug.cgi?id=133944
+        <rdar://problem/17205983>
+
+        Reviewed by Dan Bates.
+
+        * dom/DOMImplementation.cpp:
+        (WebCore::DOMImplementation::createDocument):
+        Make a ImageDocument to show our subframe PDF, if the setting is enabled.
+
+        * html/ImageDocument.cpp:
+        (WebCore::ImageDocument::finishedParsing):
+        (WebCore::ImageDocument::createDocumentStructure):
+        Set the ResourceResponse on the ImageElement upon creation, instead of
+        when the load finishes. This way, when the internal CachedImage creates
+        its Image, it can have the correct MIME type for the response, and can
+        make a PDFDocumentImage if necessary.
+
+        We never noticed this before because CachedImage falls back to making a
+        BitmapImage, and that was the only case that was normally used.
+
+        Throw an explicit white background behind PDF ImageDocuments; PDFDocumentImage
+        paints with a transparent background, but when used as an ImageDocument
+        it seems reasonable to assume that there should be a white page background
+        (similar to what PDFPlugin and friends do).
+
+        * loader/DocumentWriter.cpp:
+        (WebCore::DocumentWriter::createDocument):
+        Don't make a PDFDocument if we want to use an ImageDocument for this subframe PDF.
+
+        * page/Settings.in:
+
+        * platform/MIMETypeRegistry.cpp:
+        (WebCore::MIMETypeRegistry::isPDFMIMEType):
+        * platform/MIMETypeRegistry.h:
+        Expose the already implemented pdfMIMETypes table just like all the rest.
+
 2014-06-17  Ryuan Choi  <ryuan.choi@samsung.com>
 
         Unreviewed build fix with ENABLE_NOSNIFF after r170021
index dae3fdc517d860a9e1990096ad48aa27d77477c9..fd9dd7dd36850e9fb7bb7393d29965f97b685c9a 100644 (file)
@@ -37,6 +37,7 @@
 #include "HTMLDocument.h"
 #include "Image.h"
 #include "ImageDocument.h"
+#include "MainFrame.h"
 #include "MediaDocument.h"
 #include "MediaList.h"
 #include "MIMETypeRegistry.h"
@@ -314,6 +315,10 @@ PassRefPtr<Document> DOMImplementation::createDocument(const String& type, Frame
         return FTPDirectoryDocument::create(frame, url);
 #endif
 
+    // If we want to useImageDocumentForSubframePDF, we'll let that override plugin support.
+    if (frame && !frame->isMainFrame() && MIMETypeRegistry::isPDFMIMEType(type) && frame->settings().useImageDocumentForSubframePDF())
+        return ImageDocument::create(*frame, url);
+
     PluginData* pluginData = 0;
     PluginData::AllowedPluginTypes allowedPluginTypes = PluginData::OnlyApplicationPlugins;
     if (frame && frame->page()) {
@@ -325,7 +330,7 @@ PassRefPtr<Document> DOMImplementation::createDocument(const String& type, Frame
 
     // PDF is one image type for which a plugin can override built-in support.
     // We do not want QuickTime to take over all image types, obviously.
-    if ((MIMETypeRegistry::isPDFOrPostScriptMIMEType(type)) && pluginData && pluginData->supportsMimeType(type, allowedPluginTypes))
+    if (MIMETypeRegistry::isPDFOrPostScriptMIMEType(type) && pluginData && pluginData->supportsMimeType(type, allowedPluginTypes))
         return PluginDocument::create(frame, url);
     if (Image::supportsType(type))
         return ImageDocument::create(*frame, url);
index b9c8a9952e2d4000c24d2bc93d065bb3a92c2cf9..8d63af381d68a1e7016c3cd0c1783b1d8b57de20 100644 (file)
 #include "FrameLoader.h"
 #include "FrameLoaderClient.h"
 #include "FrameView.h"
+#include "HTMLBodyElement.h"
 #include "HTMLHtmlElement.h"
 #include "HTMLImageElement.h"
 #include "HTMLNames.h"
 #include "LocalizedStrings.h"
+#include "MIMETypeRegistry.h"
 #include "MainFrame.h"
 #include "MouseEvent.h"
 #include "Page.h"
@@ -151,8 +153,6 @@ void ImageDocument::finishedParsing()
         cachedImage.finishLoading(data.get());
         cachedImage.finish();
 
-        cachedImage.setResponse(loader()->response());
-
         // Report the natural image size in the page title, regardless of zoom level.
         // At a zoom level of 1 the image is guaranteed to have an integer size.
         updateStyleIfNeeded();
@@ -217,6 +217,8 @@ void ImageDocument::createDocumentStructure()
 
     RefPtr<Element> body = Document::createElement(bodyTag, false);
     body->setAttribute(styleAttr, "margin: 0px");
+    if (MIMETypeRegistry::isPDFMIMEType(document().loader()->responseMIMEType()))
+        toHTMLBodyElement(body.get())->setInlineStyleProperty(CSSPropertyBackgroundColor, "white", CSSPrimitiveValue::CSS_IDENT);
     rootElement->appendChild(body);
     
     RefPtr<ImageDocumentElement> imageElement = ImageDocumentElement::create(*this);
@@ -226,6 +228,7 @@ void ImageDocument::createDocumentStructure()
         imageElement->setAttribute(styleAttr, "-webkit-user-select:none;");
     imageElement->setLoadManually(true);
     imageElement->setSrc(url().string());
+    imageElement->cachedImage()->setResponse(loader()->response());
     body->appendChild(imageElement);
     
     if (m_shouldShrinkImage) {
index 4d10d37914bd658ca6a60778123fe7cd097b6bf0..fa6e44da5ea82949465acb3bec914848a97ab4cd 100644 (file)
@@ -36,6 +36,8 @@
 #include "FrameLoaderClient.h"
 #include "FrameLoaderStateMachine.h"
 #include "FrameView.h"
+#include "MIMETypeRegistry.h"
+#include "MainFrame.h"
 #include "PluginDocument.h"
 #include "RawDataDocumentParser.h"
 #include "ScriptController.h"
@@ -107,7 +109,7 @@ PassRefPtr<Document> DocumentWriter::createDocument(const URL& url)
     if (!m_frame->loader().stateMachine().isDisplayingInitialEmptyDocument() && m_frame->loader().client().shouldAlwaysUsePluginDocument(m_mimeType))
         return PluginDocument::create(m_frame, url);
 #if PLATFORM(IOS)
-    if (equalIgnoringCase(m_mimeType, "application/pdf"))
+    if (MIMETypeRegistry::isPDFMIMEType(m_mimeType) && (m_frame->isMainFrame() || !m_frame->settings().useImageDocumentForSubframePDF()))
         return PDFDocument::create(m_frame, url);
 #endif
     if (!m_frame->loader().client().hasHTMLView())
index 76e8001a2d75433febace6a1e1ab95fc5a7348c7..19428c221a15b0c660111104e5d1eda59993b8eb 100644 (file)
@@ -221,3 +221,5 @@ enableInheritURIQueryComponent initial=false
 
 aggressiveTileRetentionEnabled initial=false
 temporaryTileCohortRetentionEnabled initial=true
+
+useImageDocumentForSubframePDF initial=false
index 3cef99eaf3feee448748ea82de2d7009baa21b30..a400df3ae3a916f0668f74c725e173341f04a188 100644 (file)
@@ -561,6 +561,15 @@ bool MIMETypeRegistry::isPDFOrPostScriptMIMEType(const String& mimeType)
     return pdfAndPostScriptMIMETypes->contains(mimeType);
 }
 
+bool MIMETypeRegistry::isPDFMIMEType(const String& mimeType)
+{
+    if (mimeType.isEmpty())
+        return false;
+    if (!pdfMIMETypes)
+        initializeMIMETypeRegistry();
+    return pdfMIMETypes->contains(mimeType);
+}
+
 bool MIMETypeRegistry::canShowMIMEType(const String& mimeType)
 {
     if (isSupportedImageMIMEType(mimeType) || isSupportedNonImageMIMEType(mimeType) || isSupportedMediaMIMEType(mimeType))
index 0ee26584ba7948ade7f36414182ac2459750f70d..98e28f9928276de054bc470588ae6a508db0e19d 100644 (file)
@@ -79,6 +79,7 @@ public:
 
     // Check to see if a mime type is one of the common PDF/PS types.
     static bool isPDFOrPostScriptMIMEType(const String& mimeType);
+    static bool isPDFMIMEType(const String& mimeType);
 
     // Check to see if a mime type is suitable for being shown inside a page.
     // Returns true if any of isSupportedImageMIMEType(), isSupportedNonImageMIMEType(), isSupportedMediaMIMEType() returns true
index c5a72827c2c94d99cd88f2db78f8f7174cb2255b..63239984717b69d535466a347c1bbebb282290ab 100644 (file)
@@ -1,3 +1,15 @@
+2014-06-17  Tim Horton  <timothy_horton@apple.com>
+
+        [iOS][wk2] Use ImageDocument to display subframe PDFs
+        https://bugs.webkit.org/show_bug.cgi?id=133944
+        <rdar://problem/17205983>
+
+        Reviewed by Dan Bates.
+
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::updatePreferences):
+        Always use ImageDocument for subframe PDFs in WebKit2 on iOS.
+
 2014-06-17  Anders Carlsson  <andersca@apple.com>
 
         Make it possible to use -[NSBundle classNamed:] to find WebKitLegacy classes
index 55b3b812668dceb3b1b261a0c060b5edacf684a4..2ae6c68bdb6e30ab0e1d91b7ae9f8211bd0c5224 100644 (file)
@@ -2766,6 +2766,10 @@ void WebPage::updatePreferences(const WebPreferencesStore& store)
 
     settings.setShouldDispatchJavaScriptWindowOnErrorEvents(true);
 
+#if PLATFORM(IOS)
+    settings.setUseImageDocumentForSubframePDF(true);
+#endif
+
     if (store.getBoolValueForKey(WebPreferencesKey::pageVisibilityBasedProcessSuppressionEnabledKey()))
         m_processSuppressionDisabledByWebPreference.stop();
     else