Changeset 145750 in webkit


Ignore:
Timestamp:
Mar 13, 2013 2:16:50 PM (11 years ago)
Author:
commit-queue@webkit.org
Message:

Add the default video poster if it doesn't exist in video tag
https://bugs.webkit.org/show_bug.cgi?id=110263

Patch by Tao Bai <michaelbai@chromium.org> on 2013-03-13
Reviewed by Eric Carlson.

Source/WebCore:

Tests: media/video-default-poster.html

media/video-no-default-poster.html

The Android web view application could provide the default poster
for a video that doesn't have the poster attribute.

To provide the default poster, the application must set defaultVideoPosterURL
setting and return the image in the response of that URL.

The way to do this would be:

A) Replace the Element::imageSourceAttributeName function with an

Element::imageSourceURL function that returns the imageSourceURL as a
const AtomicString&. The body will be the same as before, it will just also
include a call to getAttribute. Also will need to revise the four classes
that override that function.

B) Add a new HTMLVideoElement::posterImageURL function that implements the

default poster URL logic.

C) Update the four functions that get the poster attribute to handle poster

loading and display to call posterImageURL.

1) HTMLVideoElement::imageSourceURL.
2) HTMLVideoElement::setDisplayMode.
3) HTMLVideoElement::updateDisplayState.
4) HTMLMediaElement::getPluginProxyParams. Will need to cast to

HTMLVideoElement after checking isVideo.

  • dom/Element.cpp:

(WebCore::Element::imageSourceURL): Replace imageSourceAttributeName() with imageSourceURL()

  • dom/Element.h: Replace imageSourceAttributeName() with imageSourceURL()
  • html/HTMLEmbedElement.cpp:

(WebCore::HTMLEmbedElement::imageSourceURL): Replace imageSourceAttributeName() with imageSourceURL()

  • html/HTMLEmbedElement.h: Replace imageSourceAttributeName() with imageSourceURL()
  • html/HTMLMediaElement.cpp:

(WebCore::HTMLMediaElement::getPluginProxyParams): Change to use posterImageURL

  • html/HTMLObjectElement.cpp:

(WebCore::HTMLObjectElement::imageSourceURL): Replace imageSourceAttributeName() with imageSourceURL()

  • html/HTMLObjectElement.h: Replace imageSourceAttributeName with imageSourceURL
  • html/HTMLVideoElement.cpp:

(WebCore::HTMLVideoElement::HTMLVideoElement): set m_defaultPosterURL if there is such settings
(WebCore::HTMLVideoElement::imageSourceURL): Replace imageSourceAttributeName() with imageSourceURL()
(WebCore::HTMLVideoElement::setDisplayMode): Use imageSourceURL()
(WebCore::HTMLVideoElement::updateDisplayState): Use imageSourceURL()
(WebCore::HTMLVideoElement::posterImageURL): Return image source's KURL

  • html/HTMLVideoElement.h: Replace imageSourceAttributeName() with imageSourceURL() and add m_defaultPosterURL
  • loader/ImageLoader.cpp:

(WebCore::ImageLoader::updateFromElement): Use imageSourceURL()

  • page/Settings.in: Add defaultVideoPosterURL setting.
  • platform/chromium/PasteboardChromium.cpp:

(WebCore::Pasteboard::writeImage): use imageSourceURL()

  • platform/gtk/PasteboardGtk.cpp:

(WebCore::getURLForImageNode): use imageSourceURL()

  • rendering/HitTestResult.cpp:

(WebCore::HitTestResult::absoluteImageURL): use imageSourceURL()

  • svg/SVGImageElement.cpp:

(WebCore::SVGImageElement::imageSourceURL): Replace imageSourceAttributeName() with imageSourceURL()

  • svg/SVGImageElement.h: Replace imageSourceAttributeName() with imageSourceURL()
  • testing/InternalSettings.cpp:

(WebCore::InternalSettings::Backup::Backup): support backup defaultVideoPosterURL.
(WebCore::InternalSettings::Backup::restoreTo): support restore defaultVideoPosterURL.
(WebCore::InternalSettings::setDefaultVideoPosterURL): set defaultVideoPosterURL.

  • testing/InternalSettings.h:

(Backup): support backup defaultVideoPosterURL.
(InternalSettings): Add setDefaultVidoePosterURL method.

  • testing/InternalSettings.idl: Add setDefaultVideoPosterURL for test purpose.
  • testing/Internals.cpp:

(WebCore::Internals::getImageSourceURL): Add getImageSourceURL method.

  • testing/Internals.h: Add getImageSourceURL method.
  • testing/Internals.idl: Add getImageSourceURL method.

LayoutTests:

The Android web view application could provide the default poster
for a video that doesn't have the poster attribute.

To provide the default poster, the application must set defaultVideoPosterURL
setting and return the image in the response of that URL.

The way to do this would be:

A) Replace the Element::imageSourceAttributeName function with an

Element::imageSourceURL function that returns the imageSourceURL as a
const AtomicString&. The body will be the same as before, it will just also
include a call to getAttribute. Also will need to revise the four classes
that override that function.

B) Add a new HTMLVideoElement::posterImageURL function that implements the

default poster URL logic.

C) Update the four functions that get the poster attribute to handle poster

loading and display to call posterImageURL.

1) HTMLVideoElement::imageSourceURL.
2) HTMLVideoElement::setDisplayMode.
3) HTMLVideoElement::updateDisplayState.
4) HTMLMediaElement::getPluginProxyParams. Will need to cast to

HTMLVideoElement after checking isVideo.

  • media/video-default-poster-expected.txt: Added.
  • media/video-default-poster.html: Added.
  • media/video-no-default-poster-expected.txt: Added.
  • media/video-no-default-poster.html: Added.
Location:
trunk
Files:
4 added
24 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r145749 r145750  
     12013-03-13  Tao Bai  <michaelbai@chromium.org>
     2
     3        Add the default video poster if it doesn't exist in video tag
     4        https://bugs.webkit.org/show_bug.cgi?id=110263
     5
     6        Reviewed by Eric Carlson.
     7
     8        The Android web view application could provide the default poster
     9        for a video that doesn't have the poster attribute.
     10
     11        To provide the default poster, the application must set defaultVideoPosterURL
     12        setting and return the image in the response of that URL.
     13
     14        The way to do this would be:
     15
     16        A) Replace the Element::imageSourceAttributeName function with an
     17           Element::imageSourceURL function that returns the imageSourceURL as a
     18           const AtomicString&. The body will be the same as before, it will just also
     19           include a call to getAttribute. Also will need to revise the four classes
     20           that override that function.
     21
     22        B) Add a new HTMLVideoElement::posterImageURL function that implements the
     23           default poster URL logic.
     24
     25        C) Update the four functions that get the poster attribute to handle poster
     26           loading and display to call posterImageURL.
     27
     28           1) HTMLVideoElement::imageSourceURL.
     29           2) HTMLVideoElement::setDisplayMode.
     30           3) HTMLVideoElement::updateDisplayState.
     31           4) HTMLMediaElement::getPluginProxyParams. Will need to cast to
     32              HTMLVideoElement after checking isVideo.
     33
     34        * media/video-default-poster-expected.txt: Added.
     35        * media/video-default-poster.html: Added.
     36        * media/video-no-default-poster-expected.txt: Added.
     37        * media/video-no-default-poster.html: Added.
     38
    1392013-03-13  James Robinson  <jamesr@chromium.org>
    240
  • trunk/Source/WebCore/ChangeLog

    r145745 r145750  
     12013-03-13  Tao Bai  <michaelbai@chromium.org>
     2
     3        Add the default video poster if it doesn't exist in video tag
     4        https://bugs.webkit.org/show_bug.cgi?id=110263
     5
     6        Reviewed by Eric Carlson.
     7
     8        Tests: media/video-default-poster.html
     9               media/video-no-default-poster.html
     10
     11        The Android web view application could provide the default poster
     12        for a video that doesn't have the poster attribute.
     13
     14        To provide the default poster, the application must set defaultVideoPosterURL
     15        setting and return the image in the response of that URL.
     16
     17        The way to do this would be:
     18
     19        A) Replace the Element::imageSourceAttributeName function with an
     20           Element::imageSourceURL function that returns the imageSourceURL as a
     21           const AtomicString&. The body will be the same as before, it will just also
     22           include a call to getAttribute. Also will need to revise the four classes
     23           that override that function.
     24
     25        B) Add a new HTMLVideoElement::posterImageURL function that implements the
     26           default poster URL logic.
     27
     28        C) Update the four functions that get the poster attribute to handle poster
     29           loading and display to call posterImageURL.
     30
     31           1) HTMLVideoElement::imageSourceURL.
     32           2) HTMLVideoElement::setDisplayMode.
     33           3) HTMLVideoElement::updateDisplayState.
     34           4) HTMLMediaElement::getPluginProxyParams. Will need to cast to
     35              HTMLVideoElement after checking isVideo.
     36
     37        * dom/Element.cpp:
     38        (WebCore::Element::imageSourceURL): Replace imageSourceAttributeName() with imageSourceURL()
     39        * dom/Element.h: Replace imageSourceAttributeName() with imageSourceURL()
     40        * html/HTMLEmbedElement.cpp:
     41        (WebCore::HTMLEmbedElement::imageSourceURL): Replace imageSourceAttributeName() with imageSourceURL()
     42        * html/HTMLEmbedElement.h: Replace imageSourceAttributeName() with imageSourceURL()
     43        * html/HTMLMediaElement.cpp:
     44        (WebCore::HTMLMediaElement::getPluginProxyParams): Change to use posterImageURL
     45        * html/HTMLObjectElement.cpp:
     46        (WebCore::HTMLObjectElement::imageSourceURL): Replace imageSourceAttributeName() with imageSourceURL()
     47        * html/HTMLObjectElement.h: Replace imageSourceAttributeName with imageSourceURL
     48        * html/HTMLVideoElement.cpp:
     49        (WebCore::HTMLVideoElement::HTMLVideoElement): set m_defaultPosterURL if there is such settings
     50        (WebCore::HTMLVideoElement::imageSourceURL): Replace imageSourceAttributeName() with imageSourceURL()
     51        (WebCore::HTMLVideoElement::setDisplayMode): Use imageSourceURL()
     52        (WebCore::HTMLVideoElement::updateDisplayState): Use imageSourceURL()
     53        (WebCore::HTMLVideoElement::posterImageURL): Return image source's KURL
     54        * html/HTMLVideoElement.h: Replace imageSourceAttributeName() with imageSourceURL() and add m_defaultPosterURL
     55        * loader/ImageLoader.cpp:
     56        (WebCore::ImageLoader::updateFromElement): Use imageSourceURL()
     57        * page/Settings.in: Add defaultVideoPosterURL setting.
     58        * platform/chromium/PasteboardChromium.cpp:
     59        (WebCore::Pasteboard::writeImage): use imageSourceURL()
     60        * platform/gtk/PasteboardGtk.cpp:
     61        (WebCore::getURLForImageNode): use imageSourceURL()
     62        * rendering/HitTestResult.cpp:
     63        (WebCore::HitTestResult::absoluteImageURL): use imageSourceURL()
     64        * svg/SVGImageElement.cpp:
     65        (WebCore::SVGImageElement::imageSourceURL): Replace imageSourceAttributeName() with imageSourceURL()
     66        * svg/SVGImageElement.h: Replace imageSourceAttributeName() with imageSourceURL()
     67        * testing/InternalSettings.cpp:
     68        (WebCore::InternalSettings::Backup::Backup): support backup defaultVideoPosterURL.
     69        (WebCore::InternalSettings::Backup::restoreTo): support restore defaultVideoPosterURL.
     70        (WebCore::InternalSettings::setDefaultVideoPosterURL): set defaultVideoPosterURL.
     71        * testing/InternalSettings.h:
     72        (Backup): support backup defaultVideoPosterURL.
     73        (InternalSettings): Add setDefaultVidoePosterURL method.
     74        * testing/InternalSettings.idl: Add setDefaultVideoPosterURL for test purpose.
     75        * testing/Internals.cpp:
     76        (WebCore::Internals::getImageSourceURL): Add getImageSourceURL method.
     77        * testing/Internals.h: Add getImageSourceURL method.
     78        * testing/Internals.idl: Add getImageSourceURL method.
     79
    1802013-03-13  Abhishek Arya  <inferno@chromium.org>
    281
  • trunk/Source/WebCore/dom/Element.cpp

    r145745 r145750  
    11221122}
    11231123
    1124 const QualifiedName& Element::imageSourceAttributeName() const
    1125 {
    1126     return srcAttr;
     1124const AtomicString& Element::imageSourceURL() const
     1125{
     1126    return getAttribute(srcAttr);
    11271127}
    11281128
  • trunk/Source/WebCore/dom/Element.h

    r145524 r145750  
    452452    KURL getNonEmptyURLAttribute(const QualifiedName&) const;
    453453
    454     virtual const QualifiedName& imageSourceAttributeName() const;
     454    virtual const AtomicString& imageSourceURL() const;
    455455    virtual String target() const { return String(); }
    456456
  • trunk/Source/WebCore/html/HTMLEmbedElement.cpp

    r144568 r145750  
    211211}
    212212
    213 const QualifiedName& HTMLEmbedElement::imageSourceAttributeName() const
    214 {
    215     return srcAttr;
     213const AtomicString& HTMLEmbedElement::imageSourceURL() const
     214{
     215    return getAttribute(srcAttr);
    216216}
    217217
  • trunk/Source/WebCore/html/HTMLEmbedElement.h

    r143843 r145750  
    4242
    4343    virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
    44     virtual const QualifiedName& imageSourceAttributeName() const;
     44    virtual const AtomicString& imageSourceURL() const OVERRIDE;
    4545
    4646    virtual RenderWidget* renderWidgetForJSBindings() const;
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r145745 r145750  
    41414141
    41424142    if (isVideo()) {
    4143         KURL posterURL = getNonEmptyURLAttribute(posterAttr);
     4143        HTMLVideoElement* video = static_cast<HTMLVideoElement*>(this);
     4144        KURL posterURL = video->posterImageURL();
    41444145        if (!posterURL.isEmpty() && frame && frame->loader()->willLoadMediaElementURL(posterURL)) {
    41454146            names.append(ASCIILiteral("_media_element_poster_"));
  • trunk/Source/WebCore/html/HTMLObjectElement.cpp

    r145745 r145750  
    365365}
    366366
    367 const QualifiedName& HTMLObjectElement::imageSourceAttributeName() const
    368 {
    369     return dataAttr;
     367const AtomicString& HTMLObjectElement::imageSourceURL() const
     368{
     369    return getAttribute(dataAttr);
    370370}
    371371
  • trunk/Source/WebCore/html/HTMLObjectElement.h

    r143843 r145750  
    8080
    8181    virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
    82     virtual const QualifiedName& imageSourceAttributeName() const;
     82    virtual const AtomicString& imageSourceURL() const OVERRIDE;
    8383
    8484    virtual RenderWidget* renderWidgetForJSBindings() const;
  • trunk/Source/WebCore/html/HTMLVideoElement.cpp

    r145669 r145750  
    3737#include "HTMLImageLoader.h"
    3838#include "HTMLNames.h"
     39#include "HTMLParserIdioms.h"
    3940#include "Page.h"
    4041#include "RenderImage.h"
    4142#include "RenderVideo.h"
    4243#include "ScriptController.h"
     44#include "Settings.h"
    4345
    4446namespace WebCore {
     
    5052{
    5153    ASSERT(hasTagName(videoTag));
     54    if (document->settings())
     55        m_defaultPosterURL = document->settings()->defaultVideoPosterURL();
    5256}
    5357
     
    179183}
    180184
    181 const QualifiedName& HTMLVideoElement::imageSourceAttributeName() const
    182 {
    183     return posterAttr;
     185const AtomicString& HTMLVideoElement::imageSourceURL() const
     186{
     187    const AtomicString& url = getAttribute(posterAttr);
     188    if (!stripLeadingAndTrailingHTMLSpaces(url).isEmpty())
     189        return url;
     190    return m_defaultPosterURL;
    184191}
    185192
     
    187194{
    188195    DisplayMode oldMode = displayMode();
    189     KURL poster = getNonEmptyURLAttribute(posterAttr);
     196    KURL poster = posterImageURL();
    190197
    191198    if (!poster.isEmpty()) {
     
    222229void HTMLVideoElement::updateDisplayState()
    223230{
    224     if (getNonEmptyURLAttribute(posterAttr).isEmpty())
     231    if (posterImageURL().isEmpty())
    225232        setDisplayMode(Video);
    226233    else if (displayMode() < Poster)
     
    309316#endif
    310317
    311 }
    312 
    313 #endif
     318KURL HTMLVideoElement::posterImageURL() const
     319{
     320    const AtomicString& url = stripLeadingAndTrailingHTMLSpaces(imageSourceURL());
     321    if (url.isEmpty())
     322        return KURL();
     323    return document()->completeURL(url);
     324}
     325
     326}
     327
     328#endif
  • trunk/Source/WebCore/html/HTMLVideoElement.h

    r145669 r145750  
    7070    bool shouldDisplayPosterImage() const { return displayMode() == Poster || displayMode() == PosterWaitingForVideo; }
    7171
     72    KURL posterImageURL() const;
     73
    7274private:
    7375    HTMLVideoElement(const QualifiedName&, Document*, bool);
     
    8587    virtual bool supportsFullscreen() const;
    8688    virtual bool isURLAttribute(const Attribute&) const OVERRIDE;
    87     virtual const QualifiedName& imageSourceAttributeName() const;
     89    virtual const AtomicString& imageSourceURL() const OVERRIDE;
    8890
    8991    virtual bool hasAvailableVideoFrame() const;
     
    9496    OwnPtr<HTMLImageLoader> m_imageLoader;
    9597
     98    AtomicString m_defaultPosterURL;
    9699};
    97100
  • trunk/Source/WebCore/loader/ImageLoader.cpp

    r145501 r145750  
    173173        return;
    174174
    175     AtomicString attr = m_element->getAttribute(m_element->imageSourceAttributeName());
     175    AtomicString attr = m_element->imageSourceURL();
    176176
    177177    if (attr == m_failedLoadURL)
  • trunk/Source/WebCore/page/Settings.in

    r144221 r145750  
    196196logsPageMessagesToSystemConsoleEnabled initial=false
    197197
     198# Some apps could have a default video poster if it is not set.
     199defaultVideoPosterURL type=String
     200
    198201smartInsertDeleteEnabled initial=true
  • trunk/Source/WebCore/platform/chromium/PasteboardChromium.cpp

    r145444 r145750  
    154154    else if (node->hasTagName(HTMLNames::embedTag) || node->hasTagName(HTMLNames::objectTag)) {
    155155        Element* element = toElement(node);
    156         urlString = element->getAttribute(element->imageSourceAttributeName());
     156        urlString = element->imageSourceURL();
    157157    }
    158158    KURL url = urlString.isEmpty() ? KURL() : node->document()->completeURL(stripLeadingAndTrailingHTMLSpaces(urlString));
  • trunk/Source/WebCore/platform/gtk/PasteboardGtk.cpp

    r145596 r145750  
    108108    else if (node->hasTagName(HTMLNames::embedTag) || node->hasTagName(HTMLNames::objectTag)) {
    109109        Element* element = toElement(node);
    110         urlString = element->getAttribute(element->imageSourceAttributeName());
     110        urlString = element->imageSourceURL();
    111111    }
    112112    return urlString.isEmpty() ? KURL() : node->document()->completeURL(stripLeadingAndTrailingHTMLSpaces(urlString));
  • trunk/Source/WebCore/rendering/HitTestResult.cpp

    r145596 r145750  
    321321       ) {
    322322        Element* element = toElement(m_innerNonSharedNode.get());
    323         urlString = element->getAttribute(element->imageSourceAttributeName());
     323        urlString = element->imageSourceURL();
    324324    } else
    325325        return KURL();
  • trunk/Source/WebCore/svg/SVGImageElement.cpp

    r143843 r145750  
    223223}
    224224
    225 const QualifiedName& SVGImageElement::imageSourceAttributeName() const
    226 {
    227     return XLinkNames::hrefAttr;
     225const AtomicString& SVGImageElement::imageSourceURL() const
     226{
     227    return getAttribute(XLinkNames::hrefAttr);
    228228}
    229229
  • trunk/Source/WebCore/svg/SVGImageElement.h

    r143843 r145750  
    5959
    6060    virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
    61  
    62     virtual const QualifiedName& imageSourceAttributeName() const;       
     61
     62    virtual const AtomicString& imageSourceURL() const OVERRIDE;
    6363    virtual void addSubresourceAttributeURLs(ListHashSet<KURL>&) const;
    6464
  • trunk/Source/WebCore/testing/InternalSettings.cpp

    r145003 r145750  
    9595    , m_shouldDisplayTextDescriptions(settings->shouldDisplayTextDescriptions())
    9696#endif
     97    , m_defaultVideoPosterURL(settings->defaultVideoPosterURL())
    9798    , m_originalTimeWithoutMouseMovementBeforeHidingControls(settings->timeWithoutMouseMovementBeforeHidingControls())
    9899{
     
    131132    settings->setShouldDisplayTextDescriptions(m_shouldDisplayTextDescriptions);
    132133#endif
     134    settings->setDefaultVideoPosterURL(m_defaultVideoPosterURL);
    133135    settings->setTimeWithoutMouseMovementBeforeHidingControls(m_originalTimeWithoutMouseMovementBeforeHidingControls);
    134136}
     
    490492}
    491493
     494void InternalSettings::setDefaultVideoPosterURL(const String& url, ExceptionCode& ec)
     495{
     496    InternalSettingsGuardForSettings();
     497    settings()->setDefaultVideoPosterURL(url);
     498}
     499
    492500void InternalSettings::setTimeWithoutMouseMovementBeforeHidingControls(double time, ExceptionCode& ec)
    493501{
  • trunk/Source/WebCore/testing/InternalSettings.h

    r145003 r145750  
    8383        bool m_shouldDisplayTextDescriptions;
    8484#endif
     85        String m_defaultVideoPosterURL;
    8586        bool m_originalTimeWithoutMouseMovementBeforeHidingControls;
    8687    };
     
    128129    void setImagesEnabled(bool enabled, ExceptionCode&);
    129130    void setMinimumTimerInterval(double intervalInSeconds, ExceptionCode&);
     131    void setDefaultVideoPosterURL(const String& url, ExceptionCode&);
    130132    void setTimeWithoutMouseMovementBeforeHidingControls(double time, ExceptionCode&);
    131133
  • trunk/Source/WebCore/testing/InternalSettings.idl

    r145003 r145750  
    6060    void setImagesEnabled(in boolean enabled) raises(DOMException);
    6161    void setMinimumTimerInterval(in double intervalInSeconds) raises(DOMException);
     62    void setDefaultVideoPosterURL(in DOMString poster) raises(DOMException);
    6263    void setTimeWithoutMouseMovementBeforeHidingControls(in double time) raises(DOMException);
    6364};
  • trunk/Source/WebCore/testing/Internals.cpp

    r145745 r145750  
    20632063}
    20642064
    2065 }
     2065String Internals::getImageSourceURL(Element* element, ExceptionCode& ec)
     2066{
     2067    if (!element) {
     2068        ec = INVALID_ACCESS_ERR;
     2069        return String();
     2070    }
     2071    return element->imageSourceURL();
     2072}
     2073
     2074}
  • trunk/Source/WebCore/testing/Internals.h

    r145735 r145750  
    298298    void enableMockSpeechSynthesizer();
    299299#endif
     300
     301    String getImageSourceURL(Element*, ExceptionCode&);
    300302                   
    301303private:
  • trunk/Source/WebCore/testing/Internals.idl

    r145735 r145750  
    263263
    264264    [Conditional=SPEECH_SYNTHESIS] void enableMockSpeechSynthesizer();
     265
     266    DOMString getImageSourceURL(in Element element) raises(DOMException);
    265267};
Note: See TracChangeset for help on using the changeset viewer.