Commit 2cadd7b2 authored by pkasting@chromium.org's avatar pkasting@chromium.org

WebCore: Make Pasteboard::writeImage() safe against NULL cachedImages, and clean

up some code.
https://bugs.webkit.org/show_bug.cgi?id=35136

Reviewed by Darin Fisher.

* loader/ImageLoader.cpp:
(WebCore::ImageLoader::updateRenderer): Shorten some code.
* page/DragController.cpp:
(WebCore::getImage): Shorten some code.
* platform/chromium/PasteboardChromium.cpp:
(WebCore::Pasteboard::writeImage): NULL-check cachedImage().
* platform/gtk/PasteboardGtk.cpp:
(WebCore::Pasteboard::writeImage): NULL-check cachedImage().
* platform/mac/PasteboardMac.mm:
(WebCore::Pasteboard::writeImage): NULL-check cachedImage().
* platform/qt/PasteboardQt.cpp:
(WebCore::Pasteboard::writeImage): NULL-check cachedImage().
* platform/win/PasteboardWin.cpp:
(WebCore::Pasteboard::writeImage): NULL-check cachedImage().

WebKit/chromium: Add an isImageBlocked bool to the WebContextMenuData struct.
https://bugs.webkit.org/show_bug.cgi?id=35136
        
Reviewed by Darin Fisher.

This lets us properly enable/disable the "Copy Image" context menu entry
(and, in the future, maybe add a "Load Image" function).

* public/WebContextMenuData.h:
* src/ContextMenuClientImpl.cpp:
(WebKit::ContextMenuClientImpl::getCustomMenuFromDefaultItems):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@55029 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 1514b1ee
2010-02-18 Peter Kasting <pkasting@google.com>
Reviewed by Darin Fisher.
Make Pasteboard::writeImage() safe against NULL cachedImages, and clean
up some code.
https://bugs.webkit.org/show_bug.cgi?id=35136
* loader/ImageLoader.cpp:
(WebCore::ImageLoader::updateRenderer): Shorten some code.
* page/DragController.cpp:
(WebCore::getImage): Shorten some code.
* platform/chromium/PasteboardChromium.cpp:
(WebCore::Pasteboard::writeImage): NULL-check cachedImage().
* platform/gtk/PasteboardGtk.cpp:
(WebCore::Pasteboard::writeImage): NULL-check cachedImage().
* platform/mac/PasteboardMac.mm:
(WebCore::Pasteboard::writeImage): NULL-check cachedImage().
* platform/qt/PasteboardQt.cpp:
(WebCore::Pasteboard::writeImage): NULL-check cachedImage().
* platform/win/PasteboardWin.cpp:
(WebCore::Pasteboard::writeImage): NULL-check cachedImage().
2010-02-19 Kenneth Rohde Christiansen <kenneth@webkit.org>
Rubberstamped by Noam Rosenthal, who wrote the original code.
......
......@@ -230,7 +230,7 @@ void ImageLoader::updateRenderer()
// is a complete image. This prevents flickering in the case where a dynamic
// change is happening between two images.
CachedImage* cachedImage = imageRenderer->cachedImage();
if (m_image != cachedImage && (m_imageComplete || !imageRenderer->cachedImage()))
if (m_image != cachedImage && (m_imageComplete || !cachedImage))
imageRenderer->setCachedImage(m_image.get());
}
}
......
......@@ -556,14 +556,9 @@ static CachedImage* getCachedImage(Element* element)
static Image* getImage(Element* element)
{
ASSERT(element);
RenderObject* renderer = element->renderer();
if (!renderer || !renderer->isImage())
return 0;
RenderImage* image = toRenderImage(renderer);
if (image->cachedImage() && !image->cachedImage()->errorOccurred())
return image->cachedImage()->image();
return 0;
CachedImage* cachedImage = getCachedImage(element);
return (cachedImage && !cachedImage->errorOccurred()) ?
cachedImage->image() : 0;
}
static void prepareClipboardForImageDrag(Frame* src, Clipboard* clipboard, Element* node, const KURL& linkURL, const KURL& imageURL, const String& label)
......
......@@ -125,7 +125,8 @@ void Pasteboard::writeImage(Node* node, const KURL&, const String& title)
ASSERT(node->renderer()->isImage());
RenderImage* renderer = toRenderImage(node->renderer());
CachedImage* cachedImage = renderer->cachedImage();
ASSERT(cachedImage);
if (!cachedImage || cachedImage->errorOccurred())
return;
Image* image = cachedImage->image();
ASSERT(image);
......
......@@ -134,7 +134,8 @@ void Pasteboard::writeImage(Node* node, const KURL&, const String&)
ASSERT(node && node->renderer() && node->renderer()->isImage());
RenderImage* renderer = toRenderImage(node->renderer());
CachedImage* cachedImage = renderer->cachedImage();
ASSERT(cachedImage);
if (!cachedImage || cachedImage->errorOccurred())
return;
Image* image = cachedImage->image();
ASSERT(image);
......
......@@ -300,9 +300,7 @@ void Pasteboard::writeImage(Node* node, const KURL& url, const String& title)
ASSERT(node->renderer() && node->renderer()->isImage());
RenderImage* renderer = toRenderImage(node->renderer());
CachedImage* cachedImage = renderer->cachedImage();
ASSERT(cachedImage);
if (cachedImage->errorOccurred())
if (!cachedImage || cachedImage->errorOccurred())
return;
NSArray* types = writableTypesForImage();
......
......@@ -151,7 +151,8 @@ void Pasteboard::writeImage(Node* node, const KURL&, const String&)
#ifndef QT_NO_CLIPBOARD
CachedImage* cachedImage = toRenderImage(node->renderer())->cachedImage();
ASSERT(cachedImage);
if (!cachedImage || cachedImage->errorOccurred())
return;
Image* image = cachedImage->image();
ASSERT(image);
......
......@@ -205,7 +205,8 @@ void Pasteboard::writeImage(Node* node, const KURL&, const String&)
ASSERT(node && node->renderer() && node->renderer()->isImage());
RenderImage* renderer = toRenderImage(node->renderer());
CachedImage* cachedImage = renderer->cachedImage();
ASSERT(cachedImage);
if (!cachedImage || cachedImage->errorOccurred())
return;
Image* image = cachedImage->image();
ASSERT(image);
......
2010-02-18 Peter Kasting <pkasting@google.com>
Reviewed by Darin Fisher.
Add an isImageBlocked bool to the WebContextMenuData struct.
https://bugs.webkit.org/show_bug.cgi?id=35136
This lets us properly enable/disable the "Copy Image" context menu entry
(and, in the future, maybe add a "Load Image" function).
* public/WebContextMenuData.h:
* src/ContextMenuClientImpl.cpp:
(WebKit::ContextMenuClientImpl::getCustomMenuFromDefaultItems):
2010-02-19 Marcus Bulach <bulach@chromium.org>
Reviewed by Jeremy Orlow.
......
......@@ -63,6 +63,9 @@ struct WebContextMenuData {
// The absolute URL of the image/video/audio that is in context.
WebURL srcURL;
// Whether the image in context has been blocked.
bool isImageBlocked;
// The absolute URL of the page in context.
WebURL pageURL;
......
......@@ -182,6 +182,10 @@ PlatformMenuDescription ContextMenuClientImpl::getCustomMenuFromDefaultItems(
if (mediaElement->hasAudio())
data.mediaFlags |= WebContextMenuData::MediaHasAudio;
}
data.isImageBlocked =
(data.mediaType == WebContextMenuData::MediaTypeImage) && !r.image();
// If it's not a link, an image, a media element, or an image/media link,
// show a selection menu or a more generic page menu.
data.frameEncoding = selectedFrame->loader()->encoding();
......
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