[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 1a8e7dc..191b555 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 dae3fdc..fd9dd7d 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 b9c8a99..8d63af3 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 4d10d37..fa6e44d 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 76e8001..19428c2 100644 (file)
@@ -221,3 +221,5 @@ enableInheritURIQueryComponent initial=false
 
 aggressiveTileRetentionEnabled initial=false
 temporaryTileCohortRetentionEnabled initial=true
+
+useImageDocumentForSubframePDF initial=false
index 3cef99e..a400df3 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 0ee2658..98e28f9 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 c5a7282..6323998 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 55b3b81..2ae6c68 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