Title: [146389] trunk/Source/WebCore
Revision
146389
Author
[email protected]
Date
2013-03-20 14:24:24 -0700 (Wed, 20 Mar 2013)

Log Message

Assertion in LegacyWebArchive::create() in editing tests
https://bugs.webkit.org/show_bug.cgi?id=112642

Reviewed by Enrica Casucci.

It's possible for clipboard to be overriden between the time we retrieve clipboard types and the time
we actually retrieve the Web archive buffer. Add a null check to take this into account.

Also extracted fragmentFromWebArchive for clarity.

* platform/mac/PasteboardMac.mm:
(WebCore::fragmentFromWebArchive): Extracted.
(WebCore::Pasteboard::documentFragment):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (146388 => 146389)


--- trunk/Source/WebCore/ChangeLog	2013-03-20 21:16:08 UTC (rev 146388)
+++ trunk/Source/WebCore/ChangeLog	2013-03-20 21:24:24 UTC (rev 146389)
@@ -1,3 +1,19 @@
+2011-03-20  Ryosuke Niwa  <[email protected]>
+
+        Assertion in LegacyWebArchive::create() in editing tests
+        https://bugs.webkit.org/show_bug.cgi?id=112642
+
+        Reviewed by Enrica Casucci.
+
+        It's possible for clipboard to be overriden between the time we retrieve clipboard types and the time
+        we actually retrieve the Web archive buffer. Add a null check to take this into account.
+
+        Also extracted fragmentFromWebArchive for clarity.
+
+        * platform/mac/PasteboardMac.mm:
+        (WebCore::fragmentFromWebArchive): Extracted.
+        (WebCore::Pasteboard::documentFragment):
+
 2013-03-20  Chris Fleizach  <[email protected]>
 
         WebSpeech: Crash in WebCore::PlatformSpeechSynthesisUtterance::client / WebCore::SpeechSynthesis::didResumeSpeaking

Modified: trunk/Source/WebCore/platform/mac/PasteboardMac.mm (146388 => 146389)


--- trunk/Source/WebCore/platform/mac/PasteboardMac.mm	2013-03-20 21:16:08 UTC (rev 146388)
+++ trunk/Source/WebCore/platform/mac/PasteboardMac.mm	2013-03-20 21:24:24 UTC (rev 146389)
@@ -462,6 +462,30 @@
     return URL;
 }
 
+static PassRefPtr<DocumentFragment> fragmentFromWebArchive(Frame* frame, PassRefPtr<LegacyWebArchive> coreArchive)
+{
+    RefPtr<ArchiveResource> mainResource = coreArchive->mainResource();
+    if (!mainResource)
+        return 0;
+
+    NSString *MIMEType = mainResource->mimeType();
+    if (!frame || !frame->document())
+        return 0;
+
+    if (frame->loader()->client()->canShowMIMETypeAsHTML(MIMEType)) {
+        RetainPtr<NSString> markupString(AdoptNS, [[NSString alloc] initWithData:[mainResource->data()->createNSData() autorelease] encoding:NSUTF8StringEncoding]);
+        // FIXME: seems poor form to do this as a side effect of getting a document fragment
+        if (DocumentLoader* loader = frame->loader()->documentLoader())
+            loader->addAllArchiveResources(coreArchive.get());
+        return createFragmentFromMarkup(frame->document(), markupString.get(), mainResource->url(), DisallowScriptingAndPluginContent);
+    }
+
+    if (MIMETypeRegistry::isSupportedImageMIMEType(MIMEType))
+        return documentFragmentWithImageResource(frame, mainResource);
+
+    return 0;
+}
+
 PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefPtr<Range> context, bool allowPlainText, bool& chosePlainText)
 {
     Vector<String> types;
@@ -470,28 +494,13 @@
     chosePlainText = false;
 
     if (types.contains(WebArchivePboardType)) {
-        RefPtr<LegacyWebArchive> coreArchive = LegacyWebArchive::create(KURL(), platformStrategies()->pasteboardStrategy()->bufferForType(WebArchivePboardType, m_pasteboardName).get());
-        if (coreArchive) {
-            RefPtr<ArchiveResource> mainResource = coreArchive->mainResource();
-            if (mainResource) {
-                NSString *MIMEType = mainResource->mimeType();
-                if (!frame || !frame->document())
-                    return 0;
-                if (frame->loader()->client()->canShowMIMETypeAsHTML(MIMEType)) {
-                    NSString *markupString = [[NSString alloc] initWithData:[mainResource->data()->createNSData() autorelease] encoding:NSUTF8StringEncoding];
-                    // FIXME: seems poor form to do this as a side effect of getting a document fragment
-                    if (DocumentLoader* loader = frame->loader()->documentLoader())
-                        loader->addAllArchiveResources(coreArchive.get());
-
-                    fragment = createFragmentFromMarkup(frame->document(), markupString, mainResource->url(), DisallowScriptingAndPluginContent);
-                    [markupString release];
-                } else if (MIMETypeRegistry::isSupportedImageMIMEType(MIMEType))
-                   fragment = documentFragmentWithImageResource(frame, mainResource);                    
+        if (RefPtr<SharedBuffer> webArchiveBuffer = platformStrategies()->pasteboardStrategy()->bufferForType(WebArchivePboardType, m_pasteboardName)) {
+            if (RefPtr<LegacyWebArchive> coreArchive = LegacyWebArchive::create(KURL(), webArchiveBuffer.get())) {
+                if ((fragment = fragmentFromWebArchive(frame, coreArchive)))
+                    return fragment.release();
             }
         }
-        if (fragment)
-            return fragment.release();
-    } 
+    }
 
     if (types.contains(String(NSFilenamesPboardType))) {
         Vector<String> paths;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to