+2007-12-01 Darin Adler <darin@apple.com>
+
+ Reviewed by Mitz.
+
+ - fix problem tracked by these bugs:
+ http://bugs.webkit.org/show_bug.cgi?id=16097
+ <rdar://problem/5619305> Safari crashes during load of LexisNexis search results
+ <rdar://problem/5510779> CrashTracer: [USER] 25 crashes in Safari at
+ WebCore::DocumentLoader::isLoadingMultipartContent const
+
+ * loader/ImageDocument.cpp:
+ (WebCore::ImageDocument::createDocumentStructure): Create an ImageDocumentElement
+ instead of an HTMLImageElement.
+ (WebCore::ImageDocument::scale): Added a null check for m_imageElement.
+ (WebCore::ImageDocument::resizeImageToFit): Ditto.
+ (WebCore::ImageDocument::restoreImageSize): Ditto.
+ (WebCore::ImageDocument::imageFitsInWindow): Ditto.
+ (WebCore::ImageDocument::windowSizeChanged): Ditto.
+ (WebCore::ImageDocumentElement::~ImageDocumentElement): Call
+ disconnectImageElement so m_imageElement will be set to 0
+ if we're still connected to the document.
+ (WebCore::ImageDocumentElement::willMoveToNewOwnerDocument): Ditto.
+
+ * loader/ImageDocument.h: Changed image element type to be
+ ImageDocumentElement instead of HTMLImageElement. Also added
+ a disconnectImageElement function that sets m_imageElement to 0.
+
2007-12-01 Darin Adler <darin@apple.com>
- remove the empty directories
* Don't hide symbols when in Debug mode
* On Linux (glibc) provide a backtrace in the test output for debugging purposes
-
* WebCore.pro:
2007-11-30 Alp Toker <alp@atoker.com>
/*
- * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
class ImageEventListener : public EventListener {
public:
ImageEventListener(ImageDocument* doc) : m_doc(doc) { }
-
virtual void handleEvent(Event*, bool isWindowEvent);
+
private:
ImageDocument* m_doc;
};
class ImageTokenizer : public Tokenizer {
public:
ImageTokenizer(ImageDocument* doc) : m_doc(doc) {}
-
+
virtual bool write(const SegmentedString&, bool appendData);
virtual void finish();
virtual bool isWaitingForScripts() const;
virtual bool wantsRawData() const { return true; }
virtual bool writeRawData(const char* data, int len);
+
private:
ImageDocument* m_doc;
};
+class ImageDocumentElement : public HTMLImageElement {
+public:
+ ImageDocumentElement(ImageDocument* doc) : HTMLImageElement(doc), m_imageDocument(doc) { }
+ virtual ~ImageDocumentElement();
+ virtual void willMoveToNewOwnerDocument();
+
+private:
+ ImageDocument* m_imageDocument;
+};
+
+// --------
+
bool ImageTokenizer::write(const SegmentedString& s, bool appendData)
{
ASSERT_NOT_REACHED();
return false;
}
+// --------
+
ImageDocument::ImageDocument(DOMImplementation* implementation, Frame* frame)
: HTMLDocument(implementation, frame)
, m_imageElement(0)
rootElement->appendChild(body, ec);
- RefPtr<Element> imageElement = createElementNS(xhtmlNamespaceURI, "img", ec);
+ RefPtr<ImageDocumentElement> imageElement = new ImageDocumentElement(this);
- m_imageElement = static_cast<HTMLImageElement *>(imageElement.get());
- m_imageElement->setAttribute(styleAttr, "-webkit-user-select: none");
- m_imageElement->setLoadManually(true);
- m_imageElement->setSrc(URL());
+ imageElement->setAttribute(styleAttr, "-webkit-user-select: none");
+ imageElement->setLoadManually(true);
+ imageElement->setSrc(URL());
body->appendChild(imageElement, ec);
// Add event listeners
RefPtr<EventListener> listener = new ImageEventListener(this);
addWindowEventListener("resize", listener, false);
- m_imageElement->addEventListener("click", listener.release(), false);
+ imageElement->addEventListener("click", listener.release(), false);
}
+
+ m_imageElement = imageElement.get();
}
float ImageDocument::scale() const
{
+ if (!m_imageElement)
+ return 1.0f;
+
IntSize imageSize = m_imageElement->cachedImage()->imageSize();
IntSize windowSize = IntSize(frame()->view()->width(), frame()->view()->height());
void ImageDocument::resizeImageToFit()
{
+ if (!m_imageElement)
+ return;
+
IntSize imageSize = m_imageElement->cachedImage()->imageSize();
float scale = this->scale();
void ImageDocument::restoreImageSize()
{
- if (!m_imageSizeIsKnown)
+ if (!m_imageElement || !m_imageSizeIsKnown)
return;
m_imageElement->setWidth(m_imageElement->cachedImage()->imageSize().width());
bool ImageDocument::imageFitsInWindow() const
{
+ if (!m_imageElement)
+ return true;
+
IntSize imageSize = m_imageElement->cachedImage()->imageSize();
IntSize windowSize = IntSize(frame()->view()->width(), frame()->view()->height());
void ImageDocument::windowSizeChanged()
{
- if (!m_imageSizeIsKnown)
+ if (!m_imageElement || !m_imageSizeIsKnown)
return;
bool fitsInWindow = imageFitsInWindow();
frame()->page()->mainFrame() == frame();
}
+// --------
+
void ImageEventListener::handleEvent(Event* event, bool isWindowEvent)
{
if (event->type() == resizeEvent)
}
}
+// --------
+
+ImageDocumentElement::~ImageDocumentElement()
+{
+ if (m_imageDocument)
+ m_imageDocument->disconnectImageElement();
+}
+
+void ImageDocumentElement::willMoveToNewOwnerDocument()
+{
+ if (m_imageDocument) {
+ m_imageDocument->disconnectImageElement();
+ m_imageDocument = 0;
+ }
+ HTMLImageElement::willMoveToNewOwnerDocument();
+}
+
}
/*
- * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+
#ifndef ImageDocument_h
#define ImageDocument_h
namespace WebCore {
-class DOMImplementation;
-class FrameView;
-class HTMLImageElement;
+class ImageDocumentElement;
-class ImageDocument : public HTMLDocument
-{
+class ImageDocument : public HTMLDocument {
public:
ImageDocument(DOMImplementation*, Frame*);
virtual Tokenizer* createTokenizer();
CachedImage* cachedImage();
- HTMLImageElement* imageElement() const { return m_imageElement; }
+ ImageDocumentElement* imageElement() const { return m_imageElement; }
+ void disconnectImageElement() { m_imageElement = 0; }
void windowSizeChanged();
void imageChanged();
void imageClicked(int x, int y);
+
private:
void createDocumentStructure();
void resizeImageToFit();
bool shouldShrinkToFit() const;
float scale() const;
- HTMLImageElement* m_imageElement;
+ ImageDocumentElement* m_imageElement;
// Whether enough of the image has been loaded to determine its size
bool m_imageSizeIsKnown;