Commit 1c8a4876 authored by oliver's avatar oliver

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



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@20567 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent b6a0acea
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.
......
......@@ -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
}
......
......@@ -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
......
......@@ -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;
......
......@@ -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
......
......@@ -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; }
......
......@@ -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;
......
......@@ -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();
......
......@@ -37,14 +37,13 @@
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;
......
......@@ -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;
......
......@@ -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.
......
......@@ -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; }
......
......@@ -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");
......
......@@ -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; }
......
......@@ -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.
......
......@@ -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; }
......
......@@ -41,15 +41,15 @@
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());
......
......@@ -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;
};
}
......
......@@ -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;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment