Assertion in LegacyWebArchive::create() in editing tests
authorrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Mar 2013 21:24:24 +0000 (21:24 +0000)
committerrniwa@webkit.org <rniwa@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 20 Mar 2013 21:24:24 +0000 (21:24 +0000)
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):

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

Source/WebCore/ChangeLog
Source/WebCore/platform/mac/PasteboardMac.mm

index 67ee455..957cb99 100644 (file)
@@ -1,3 +1,19 @@
+2011-03-20  Ryosuke Niwa  <rniwa@webkit.org>
+
+        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  <cfleizach@apple.com>
 
         WebSpeech: Crash in WebCore::PlatformSpeechSynthesisUtterance::client / WebCore::SpeechSynthesis::didResumeSpeaking
index 2ebec20..841b24f 100644 (file)
@@ -462,6 +462,30 @@ static NSURL* uniqueURLWithRelativePart(NSString *relativePart)
     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 @@ PassRefPtr<DocumentFragment> Pasteboard::documentFragment(Frame* frame, PassRefP
     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;