2007-03-28 Oliver Hunt <oliver@apple.com>
authoroliver <oliver@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Mar 2007 04:59:45 +0000 (04:59 +0000)
committeroliver <oliver@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Mar 2007 04:59:45 +0000 (04:59 +0000)
        Reviewed by Anders and Steve.

        Add a flag to DocLoader to prevent it from reloading
        when performing a paste or drop operation.

        Remove m_cachePolicy from CachedResource as it is never used

        Fixes rdar://problem/5044366 : REGRESSION: Repro ASSERT failures
        dragging image into GMail message in _web_writeImage and
        documentFragmentFromDragData

        * editing/Editor.cpp:
        (WebCore::Editor::paste):
          prevent the docloader from reloading resources on paste
        * html/HTMLImageLoader.cpp:
        (WebCore::HTMLImageLoader::updateFromElement):
        * loader/Cache.cpp:
        (WebCore::createResource):
        * loader/CachedCSSStyleSheet.cpp:
        (WebCore::CachedCSSStyleSheet::CachedCSSStyleSheet):
        * loader/CachedCSSStyleSheet.h:
        * loader/CachedImage.cpp:
        (WebCore::CachedImage::CachedImage):
        * loader/CachedImage.h:
        * loader/CachedResource.cpp:
        (WebCore::CachedResource::CachedResource):
        * loader/CachedResource.h:
        * loader/CachedScript.cpp:
        (WebCore::CachedScript::CachedScript):
        * loader/CachedScript.h:
        * loader/CachedXBLDocument.cpp:
        (WebCore::CachedXBLDocument::CachedXBLDocument):
        * loader/CachedXBLDocument.h:
        * loader/CachedXSLStyleSheet.cpp:
        (WebCore::CachedXSLStyleSheet::CachedXSLStyleSheet):
        * loader/CachedXSLStyleSheet.h:
        * loader/DocLoader.cpp:
        (WebCore::DocLoader::DocLoader):
           Tidy up constructor initialise new field
        (WebCore::DocLoader::checkForReload):
           Prevent reload when pasting
        * loader/DocLoader.h:
        (WebCore::DocLoader::setPasteInProgress):
          new field and setter
        * page/DragController.cpp:
        (WebCore::DragController::concludeDrag):
          prevent the docloader from reloading resources on drop

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

19 files changed:
WebCore/ChangeLog
WebCore/editing/Editor.cpp
WebCore/html/HTMLImageLoader.cpp
WebCore/loader/Cache.cpp
WebCore/loader/CachedCSSStyleSheet.cpp
WebCore/loader/CachedCSSStyleSheet.h
WebCore/loader/CachedImage.cpp
WebCore/loader/CachedImage.h
WebCore/loader/CachedResource.cpp
WebCore/loader/CachedResource.h
WebCore/loader/CachedScript.cpp
WebCore/loader/CachedScript.h
WebCore/loader/CachedXBLDocument.cpp
WebCore/loader/CachedXBLDocument.h
WebCore/loader/CachedXSLStyleSheet.cpp
WebCore/loader/CachedXSLStyleSheet.h
WebCore/loader/DocLoader.cpp
WebCore/loader/DocLoader.h
WebCore/page/DragController.cpp

index 4f9b87385666aa2e48c982a0c8de1bc0622dc802..e6d4f76f6d02f08d50a8ed5e1174daeea492f4de 100644 (file)
@@ -1,3 +1,53 @@
+2007-03-28  Oliver Hunt  <oliver@apple.com>
+
+        Reviewed by Anders and Steve.
+
+        Add a flag to DocLoader to prevent it from reloading 
+        when performing a paste or drop operation.
+        
+        Remove m_cachePolicy from CachedResource as it is never used
+        
+        Fixes rdar://problem/5044366 : REGRESSION: Repro ASSERT failures 
+        dragging image into GMail message in _web_writeImage and 
+        documentFragmentFromDragData
+
+        * editing/Editor.cpp:
+        (WebCore::Editor::paste):
+          prevent the docloader from reloading resources on paste
+        * html/HTMLImageLoader.cpp:
+        (WebCore::HTMLImageLoader::updateFromElement):
+        * loader/Cache.cpp:
+        (WebCore::createResource):
+        * loader/CachedCSSStyleSheet.cpp:
+        (WebCore::CachedCSSStyleSheet::CachedCSSStyleSheet):
+        * loader/CachedCSSStyleSheet.h:
+        * loader/CachedImage.cpp:
+        (WebCore::CachedImage::CachedImage):
+        * loader/CachedImage.h:
+        * loader/CachedResource.cpp:
+        (WebCore::CachedResource::CachedResource):
+        * loader/CachedResource.h:
+        * loader/CachedScript.cpp:
+        (WebCore::CachedScript::CachedScript):
+        * loader/CachedScript.h:
+        * loader/CachedXBLDocument.cpp:
+        (WebCore::CachedXBLDocument::CachedXBLDocument):
+        * loader/CachedXBLDocument.h:
+        * loader/CachedXSLStyleSheet.cpp:
+        (WebCore::CachedXSLStyleSheet::CachedXSLStyleSheet):
+        * loader/CachedXSLStyleSheet.h:
+        * loader/DocLoader.cpp:
+        (WebCore::DocLoader::DocLoader):
+           Tidy up constructor initialise new field
+        (WebCore::DocLoader::checkForReload):
+           Prevent reload when pasting
+        * loader/DocLoader.h:
+        (WebCore::DocLoader::setPasteInProgress):
+          new field and setter
+        * page/DragController.cpp:
+        (WebCore::DragController::concludeDrag):
+          prevent the docloader from reloading resources on drop
+
 2007-03-27  Krzysztof Kowalczyk  <kkowalczyk@gmail.com>
 
         Not reviewed - fix typo in gdk build.
index c88835689cd72477e19ac2a60630116407b8621d..f8040045c16a395a02aa79511ea0749be0e3733c 100644 (file)
@@ -37,6 +37,7 @@
 #include "ClipboardEvent.h"
 #include "DeleteButtonController.h"
 #include "DeleteSelectionCommand.h"
+#include "DocLoader.h"
 #include "Document.h"
 #include "DocumentFragment.h"
 #include "EditCommand.h"
@@ -1417,19 +1418,25 @@ void Editor::copy()
 
 void Editor::paste()
 {
+    ASSERT(m_frame->document());
+    DocLoader* loader = m_frame->document()->docLoader();
 #if PLATFORM(MAC)
     // using the platform independent code below requires moving all of
     // WEBHTMLView: _documentFragmentFromPasteboard over to PasteboardMac.
+    loader->setPasteInProgress(true);
     m_frame->issuePasteCommand();
+    loader->setPasteInProgress(false);
 #else
     if (tryDHTMLPaste())
         return;     // DHTML did the whole operation
     if (!canPaste())
         return;
+    loader->setPasteInProgress(true);
     if (m_frame->selectionController()->isContentRichlyEditable())
         pasteWithPasteboard(Pasteboard::generalPasteboard(), true);
     else
         pasteAsPlainTextWithPasteboard(Pasteboard::generalPasteboard());
+    loader->setPasteInProgress(false);
 #endif
 }
 
index 122c3113f3215412958be8377851a6326555071d..340994e085ddd8136df59a1cc2b1351715d06c0d 100644 (file)
@@ -95,7 +95,7 @@ void HTMLImageLoader::updateFromElement()
     if (!attr.isEmpty()) {
         if (m_loadManually) {
             doc->docLoader()->setAutoLoadImages(false);
-            newImage = new CachedImage(doc->docLoader(), parseURL(attr), CachePolicyVerify, 0);
+            newImage = new CachedImage(doc->docLoader(), parseURL(attr), 0);
             newImage->setLoading(true);
             doc->docLoader()->m_docResources.set(newImage->url(), newImage);
         } else
index 20a9e3475f625c892ed637680da01515a0786edd..54c5c4144d20d099006ead930288cf56b310d6d2 100644 (file)
@@ -65,18 +65,18 @@ static CachedResource* createResource(CachedResource::Type type, DocLoader* docL
     switch (type) {
     case CachedResource::ImageResource:
         // User agent images need to null check the docloader.  No other resources need to.
-        return new CachedImage(docLoader, url.url(), docLoader ? docLoader->cachePolicy() : CachePolicyCache, expireDate);
+        return new CachedImage(docLoader, url.url(), expireDate);
     case CachedResource::CSSStyleSheet:
-        return new CachedCSSStyleSheet(docLoader, url.url(), docLoader->cachePolicy(), expireDate, *charset, skipCanLoadCheck);
+        return new CachedCSSStyleSheet(docLoader, url.url(), expireDate, *charset, skipCanLoadCheck);
     case CachedResource::Script:
-        return new CachedScript(docLoader, url.url(), docLoader->cachePolicy(), expireDate, *charset);
+        return new CachedScript(docLoader, url.url(), expireDate, *charset);
 #if ENABLE(XSLT)
     case CachedResource::XSLStyleSheet:
-        return new CachedXSLStyleSheet(docLoader, url.url(), docLoader->cachePolicy(), expireDate);
+        return new CachedXSLStyleSheet(docLoader, url.url(), expireDate);
 #endif
 #if ENABLE(XBL)
     case CachedResource::XBLStyleSheet:
-        return new CachedXBLDocument(docLoader, url.url(), docLoader->cachePolicy(), expireDate);
+        return new CachedXBLDocument(docLoader, url.url(), expireDate);
 #endif
     default:
         break;
index ebe28c49dd6b980108624aee1faa04ff5407be66..5338ebf6b4fb4a3d384e7eb64c6f270e67d67ed5 100644 (file)
@@ -39,8 +39,8 @@
 
 namespace WebCore {
 
-CachedCSSStyleSheet::CachedCSSStyleSheet(DocLoader* dl, const String& url, CachePolicy cachePolicy, time_t _expireDate, const String& charset, bool skipCanLoadCheck)
-    : CachedResource(url, CSSStyleSheet, cachePolicy, _expireDate)
+CachedCSSStyleSheet::CachedCSSStyleSheet(DocLoader* dl, const String& url, time_t _expireDate, const String& charset, bool skipCanLoadCheck)
+    : CachedResource(url, CSSStyleSheet, _expireDate)
     , m_decoder(new TextResourceDecoder("text/css", charset))
 {
     // Prefer text/css but accept any type (dell.com serves a stylesheet
index 184df023d11c3daea5e2bf037eabaa8f7b4f0150..df242a8dc4acb7d18ba5df2c060afd827a99f3e1 100644 (file)
@@ -39,7 +39,7 @@ namespace WebCore {
 
     class CachedCSSStyleSheet : public CachedResource {
     public:
-        CachedCSSStyleSheet(DocLoader*, const String& URL, CachePolicy, time_t expireDate, const String& charset, bool skipCanLoadCheck = false);
+        CachedCSSStyleSheet(DocLoader*, const String& URL, time_t expireDate, const String& charset, bool skipCanLoadCheck = false);
         virtual ~CachedCSSStyleSheet();
 
         const String& sheet() const { return m_sheet; }
index 2edcc4491c8977fb479d335827905d2ad748b086..a7f767d01de22c34bb5d7669a3f42b02a208c8af 100644 (file)
@@ -51,8 +51,8 @@ using std::max;
 
 namespace WebCore {
 
-CachedImage::CachedImage(DocLoader* docLoader, const String& url, CachePolicy cachePolicy, time_t _expireDate)
-    : CachedResource(url, ImageResource, cachePolicy, _expireDate)
+CachedImage::CachedImage(DocLoader* docLoader, const String& url, time_t _expireDate)
+    : CachedResource(url, ImageResource, _expireDate)
 {
     m_image = 0;
     m_status = Unknown;
@@ -64,7 +64,7 @@ CachedImage::CachedImage(DocLoader* docLoader, const String& url, CachePolicy ca
 }
 
 CachedImage::CachedImage(Image* image)
-    : CachedResource(String(), ImageResource, CachePolicyCache, 0)
+    : CachedResource(String(), ImageResource, 0)
 {
     m_image = image;
     m_status = Cached;
index 6d9726c02a8e2f5a8a35a2412df612e99124b80f..a6a10cdbacb50f7234ceb67b832ff62f02acb8a0 100644 (file)
@@ -41,7 +41,7 @@ class Image;
 
 class CachedImage : public CachedResource, public ImageObserver {
 public:
-    CachedImage(DocLoader*, const String& url, CachePolicy, time_t expireDate);
+    CachedImage(DocLoader*, const String& url, time_t expireDate);
     CachedImage(Image*);
     virtual ~CachedImage();
 
index 369fab3bfa2feda0564e7ad050fb7acf07d976c7..6d90251719dd415e05b24fab252429ac7ea4668e 100644 (file)
 
 namespace WebCore {
 
-CachedResource::CachedResource(const String& URL, Type type, CachePolicy cachePolicy, unsigned size)
+CachedResource::CachedResource(const String& URL, Type type, unsigned size)
 {
     m_url = URL;
     m_type = type;
     m_status = Pending;
     m_encodedSize = size;
     m_inCache = false;
-    m_cachePolicy = cachePolicy;
     m_request = 0;
     m_expireDateChanged = false;
 
index 44590a11fcb8a9c9e52bb3092e2ac58e08c1345e..8f0f8af2b5a03058b810e776c01cdb97ff62f6fa 100644 (file)
@@ -28,7 +28,6 @@
 #ifndef CachedResource_h
 #define CachedResource_h
 
-#include "CachePolicy.h"
 #include "PlatformString.h"
 #include "ResourceResponse.h"
 #include "SharedBuffer.h"
@@ -67,7 +66,7 @@ public:
         Cached       // regular case
     };
 
-    CachedResource(const String& URL, Type type, CachePolicy cachePolicy, unsigned encodedSize = 0);
+    CachedResource(const String& URL, Type type, unsigned encodedSize = 0);
     virtual ~CachedResource();
 
     virtual void setEncoding(const String&) { }
@@ -113,8 +112,6 @@ public:
     void setInCache(bool b) { m_inCache = b; }
     bool inCache() const { return m_inCache; }
     
-    CachePolicy cachePolicy() const { return m_cachePolicy; }
-
     void setRequest(Request*);
 
     SharedBuffer* data() const { return m_data.get(); }
@@ -161,7 +158,6 @@ private:
     unsigned m_liveAccessCount;
     
 protected:
-    CachePolicy m_cachePolicy;
     bool m_inCache;
     bool m_loading;
     bool m_expireDateChanged;
index 693c5119f0a3e58cdbb423aca99098e41cc3de4c..bfe53e39562216e84c39f4bc60556111ee1fdb56 100644 (file)
@@ -37,8 +37,8 @@
 
 namespace WebCore {
 
-CachedScript::CachedScript(DocLoader* dl, const String& url, CachePolicy cachePolicy, time_t _expireDate, const String& charset)
-    : CachedResource(url, Script, cachePolicy, _expireDate)
+CachedScript::CachedScript(DocLoader* dl, const String& url, time_t _expireDate, const String& charset)
+    : CachedResource(url, Script, _expireDate)
     , m_encoding(charset)
 {
     // It's javascript we want.
index 56a4a3900a8438a47e60dddf63218ff4c8c295f3..a20a6d138da111e0472d1e45e3e1a6875e0c650e 100644 (file)
@@ -37,7 +37,7 @@ namespace WebCore {
 
     class CachedScript : public CachedResource {
     public:
-        CachedScript(DocLoader*, const String& URL, CachePolicy, time_t expireDate, const String& charset);
+        CachedScript(DocLoader*, const String& URL, time_t expireDate, const String& charset);
         virtual ~CachedScript();
 
         const String& script() const { return m_script; }
index c74027c23baf89427f00261d862332e22db30f4c..12ba866c4f7e46e98484f741cabb6fd70f647576 100644 (file)
@@ -40,8 +40,8 @@
 
 namespace WebCore {
 
-CachedXBLDocument::CachedXBLDocument(DocLoader* dl, const String &url, CachePolicy cachePolicy, time_t _expireDate)
-: CachedResource(url, XBL, cachePolicy, _expireDate), m_document(0)
+CachedXBLDocument::CachedXBLDocument(DocLoader* dl, const String &url, time_t _expireDate)
+: CachedResource(url, XBL, _expireDate), m_document(0)
 {
     // It's XML we want.
     setAccept("text/xml, application/xml, application/xhtml+xml, text/xsl, application/rss+xml, application/atom+xml");
index eed0989f7af73b3dbb60ea8449c75d940e64ecd4..32578c45d882a6357e0c84cab5257675a406ce96 100644 (file)
@@ -41,7 +41,7 @@ namespace WebCore {
 #if ENABLE(XBL)
     class CachedXBLDocument : public CachedResource {
     public:
-        CachedXBLDocument(DocLoader*, const String& url, CachePolicy, time_t expireDate);
+        CachedXBLDocument(DocLoader*, const String& url, time_t expireDate);
         virtual ~CachedXBLDocument();
         
         XBL::XBLDocument* document() const { return m_document; }
index 7d19008151809a407b785f0cd5938e4bbbeb4f1c..d15373e2e78bd057b4ef122a2d140b6db52fac34 100644 (file)
@@ -40,8 +40,8 @@ namespace WebCore {
 
 #if ENABLE(XSLT)
 
-CachedXSLStyleSheet::CachedXSLStyleSheet(DocLoader* dl, const String &url, CachePolicy cachePolicy, time_t _expireDate)
-    : CachedResource(url, XSLStyleSheet, cachePolicy, _expireDate)
+CachedXSLStyleSheet::CachedXSLStyleSheet(DocLoader* dl, const String &url, time_t _expireDate)
+    : CachedResource(url, XSLStyleSheet, _expireDate)
     , m_decoder(new TextResourceDecoder("text/xsl"))
 {
     // It's XML we want.
index d4ba168cc94f141047944a3dad75e266a48a5a17..6b29264e7a6a7d1281a164c200772ce7eb4c2498 100644 (file)
@@ -39,7 +39,7 @@ namespace WebCore {
 #if ENABLE(XSLT)
     class CachedXSLStyleSheet : public CachedResource {
     public:
-        CachedXSLStyleSheet(DocLoader*, const String& url, CachePolicy, time_t expireDate);
+        CachedXSLStyleSheet(DocLoader*, const String& url, time_t expireDate);
 
         const String& sheet() const { return m_sheet; }
         
index 3a3cf859b822e13176e58f486124844b23b1b268..33311a2ffe9f3b30514eea0b41fd80019f5d1470 100644 (file)
 namespace WebCore {
 
 DocLoader::DocLoader(Frame *frame, Document* doc)
-: m_cache(cache())
+    : m_cache(cache())
+    , m_expireDate(0)
+    , m_cachePolicy(CachePolicyVerify)
+    , m_frame(frame)
+    , m_doc(doc)
+    , m_autoLoadImages(true)
+    , m_loadInProgress(false)
+    , m_pasteInProgress(false)
 {
-    m_cachePolicy = CachePolicyVerify;
-    m_expireDate = 0;
-    m_autoLoadImages = true;
-    m_frame = frame;
-    m_doc = doc;
-    m_loadInProgress = false;
-
     m_cache->addDocLoader(this);
 }
 
@@ -65,6 +65,8 @@ void DocLoader::setExpireDate(time_t _expireDate)
 
 void DocLoader::checkForReload(const KURL& fullURL)
 {
+    if (m_pasteInProgress)
+        return; //Don't reload resources while pasting
     if (m_cachePolicy == CachePolicyVerify) {
        if (!m_reloadedURLs.contains(fullURL.url())) {
           CachedResource* existing = cache()->resourceForURL(fullURL.url());
index e6e95a7aee866e26a934aebe96384f076e6a325d..04512f1b7e4322d8318a448b79c3092f497fbcf6 100644 (file)
@@ -86,6 +86,8 @@ public:
 
     void setLoadInProgress(bool);
     bool loadInProgress() const { return m_loadInProgress; }
+    
+    void setPasteInProgress(bool pasteInProgress) { m_pasteInProgress = pasteInProgress; }
 
 private:
     CachedResource* requestResource(CachedResource::Type, const String& url, const String* charset = 0, bool skipCanLoadCheck = false);
@@ -98,10 +100,13 @@ private:
     mutable HashMap<String, CachedResource*> m_docResources;
     time_t m_expireDate;
     CachePolicy m_cachePolicy;
-    bool m_autoLoadImages : 1;
     Frame* m_frame;
     Document *m_doc;
-    bool m_loadInProgress;
+    
+    //29 bits left
+    bool m_autoLoadImages : 1;
+    bool m_loadInProgress : 1;
+    bool m_pasteInProgress : 1;
 };
 
 }
index da76baa3aeac6ec9f8f227a90c2343e643bb4eb6..085cca05c167d674d9f46e7e4f0a25e8b146b660 100644 (file)
@@ -31,6 +31,7 @@
 #include "CSSStyleDeclaration.h"
 #include "Document.h"
 #include "DocumentFragment.h"
+#include "DocLoader.h"
 #include "DragActions.h"
 #include "Editor.h"
 #include "EditorClient.h"
@@ -349,11 +350,15 @@ bool DragController::concludeDrag(DragData* dragData, DragDestinationAction acti
     Selection dragCaret(m_page->dragCaretController()->selection());
     m_page->dragCaretController()->clear();
     RefPtr<Range> range = dragCaret.toRange();
+    DocLoader* loader = range->ownerDocument()->docLoader();
+    loader->setPasteInProgress(true);
     if (dragIsMove(innerFrame->selectionController(), dragData) || dragCaret.isContentRichlyEditable()) { 
         bool chosePlainText = false;
         RefPtr<DocumentFragment> fragment = documentFragmentFromDragData(dragData, range, true, chosePlainText);
-        if (!fragment || !innerFrame->editor()->shouldInsertFragment(fragment, range, EditorInsertActionDropped))
+        if (!fragment || !innerFrame->editor()->shouldInsertFragment(fragment, range, EditorInsertActionDropped)) {
+            loader->setPasteInProgress(false);
             return false;
+        }
         
         m_client->willPerformDragDestinationAction(DragDestinationActionEdit, dragData);
         if (dragIsMove(innerFrame->selectionController(), dragData)) {
@@ -367,13 +372,16 @@ bool DragController::concludeDrag(DragData* dragData, DragDestinationAction acti
         }    
     } else {
         String text = dragData->asPlainText();
-        if (text.isEmpty() || !innerFrame->editor()->shouldInsertText(text, range.get(), EditorInsertActionDropped))
+        if (text.isEmpty() || !innerFrame->editor()->shouldInsertText(text, range.get(), EditorInsertActionDropped)) {
+            loader->setPasteInProgress(false);
             return false;
+        }
         
         m_client->willPerformDragDestinationAction(DragDestinationActionEdit, dragData);
         if (setSelectionToDragCaret(innerFrame, dragCaret, range, point))
             applyCommand(new ReplaceSelectionCommand(m_document, createFragmentFromText(range.get(), text), true, false, true)); 
     }
+    loader->setPasteInProgress(false);
 
     return true;
 }