Changeset 142343 in webkit


Ignore:
Timestamp:
Feb 8, 2013 7:29:20 PM (11 years ago)
Author:
dino@apple.com
Message:

Source/WebCore: Snapshotted plug-in should use shadow root
https://bugs.webkit.org/show_bug.cgi?id=108284

Reviewed by Simon Fraser.

Take two! This time with updated exports file.

A snapshotted plugin needs to indicate to the user that it can be clicked
to be restarted. Previously this was done with an image that had embedded
text. Instead, we now use an internal shadow root to embed some markup that
will display instructions that can be localised.

The UA stylesheet for plug-ins provides a default styling for the label, which
can be overridden by ports.

In the process, RenderSnapshottedPlugIn no longer inherits from RenderEmbeddedObject,
since it is only responsible for drawing a paused plug-in. The snapshot creation
can work with the default renderer, but a shadow root requires something like
RenderBlock in order to draw its children. We swap from one renderer to another when
necessary either by creating the shadow root or by explicitly detaching and attaching
the plugin element.

Unfortunately this is difficult to test, because the snapshotting requires
time to execute, and also a PluginView to be instantiated.

  • WebCore.exp.in: Export the InlineBox interface.
  • css/plugIns.css:

(object::-webkit-snapshotted-plugin-content): New rules for a default label style.

  • platform/LocalizedStrings.cpp: Make sure all ports have plugin strings, now it is called.
  • platform/LocalizedStrings.h:
  • platform/blackberry/LocalizedStringsBlackBerry.cpp:
  • platform/chromium/LocalizedStringsChromium.cpp:
  • platform/efl/LocalizedStringsEfl.cpp:
  • platform/gtk/LocalizedStringsGtk.cpp:
  • platform/qt/LocalizedStringsQt.cpp:
  • html/HTMLPlugInElement.cpp:

(WebCore::HTMLPlugInElement::defaultEventHandler): Take into account the fact
that RenderSnapshottedPlugIn no longer is an embedded object.

  • html/HTMLPlugInImageElement.cpp:

(WebCore::HTMLPlugInImageElement::HTMLPlugInImageElement): New default values in constructor.
(WebCore::HTMLPlugInElement::defaultEventHandler): Make sure to call base class.
(WebCore::HTMLPlugInElement::willRecalcStyle): No need to reattach if we're a snapshot.
(WebCore::HTMLPlugInImageElement::createRenderer): If we're showing a snapshot, create such

a renderer, otherwise use the typical plug-in path.

(WebCore::HTMLPlugInImageElement::updateSnapshot): Keep a record of the snapshot, since we'll

need to give it to the renderer.

(WebCore::HTMLPlugInImageElement::didAddUserAgentShadowRoot): Build a subtree that will display a label.

  • html/HTMLPlugInImageElement.h:

(HTMLPlugInImageElement): New member variable to record the snapshot image and whether the label

should show immediately.

(WebCore::HTMLPlugInImageElement::swapRendererTimerFired): The callback function triggered when we need

to swap to the Shadow Root.

(WebCore::HTMLPlugInImageElement::userDidClickSnapshot): The user has tapped on the snapshot so the plugin

in being recreated. Make sure we reattach so that a plugin renderer will be created.

(WebCore::HTMLPlugInImageElement::subframeLoaderWillCreatePlugIn): Make sure we set the right

displayState for snapshots.

  • html/HTMLPlugInImageElement.h:

(HTMLPlugInImageElement): The new methods listed above.
(WebCore::HTMLPlugInImageElement::setShouldShowSnapshotLabelAutomatically): Indicates whether or not

a snapshot should be immediately labeled.

  • page/ChromeClient.h: No need for plugInStartLabelImage any more.
  • rendering/RenderSnapshottedPlugIn.cpp:

(WebCore::RenderSnapshottedPlugIn::RenderSnapshottedPlugIn): New inheritance.
(WebCore::RenderSnapshottedPlugIn::paint): If we're in the background paint phase, render the snapshot image.
(WebCore::RenderSnapshottedPlugIn::paintSnapshotImage): Rename.
(WebCore::RenderSnapshottedPlugIn::paintSnapshot): Rename.
(WebCore::RenderSnapshottedPlugIn::paintSnapshotWithLabel): Rename. No need for label sizes.
(WebCore::RenderSnapshottedPlugIn::getCursor):
(WebCore::RenderSnapshottedPlugIn::handleEvent): The renderer doesn't restart the plug-in any more. Tell the element and it will do it.

  • rendering/RenderSnapshottedPlugIn.h:

(RenderSnapshottedPlugIn): New inheritance. Some method renaming.

Source/WebKit2:

  • WebProcess/InjectedBundle/InjectedBundlePageUIClient.cpp:
  • WebProcess/InjectedBundle/InjectedBundlePageUIClient.h:

(InjectedBundlePageUIClient):

  • WebProcess/WebCoreSupport/WebChromeClient.cpp:
  • WebProcess/WebCoreSupport/WebChromeClient.h:

(WebChromeClient):

Location:
trunk/Source
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r142341 r142343  
     12013-02-08  Dean Jackson  <dino@apple.com>
     2
     3        Snapshotted plug-in should use shadow root
     4        https://bugs.webkit.org/show_bug.cgi?id=108284
     5
     6        Reviewed by Simon Fraser.
     7
     8        Take two! This time with updated exports file.
     9
     10        A snapshotted plugin needs to indicate to the user that it can be clicked
     11        to be restarted. Previously this was done with an image that had embedded
     12        text. Instead, we now use an internal shadow root to embed some markup that
     13        will display instructions that can be localised.
     14
     15        The UA stylesheet for plug-ins provides a default styling for the label, which
     16        can be overridden by ports.
     17
     18        In the process, RenderSnapshottedPlugIn no longer inherits from RenderEmbeddedObject,
     19        since it is only responsible for drawing a paused plug-in. The snapshot creation
     20        can work with the default renderer, but a shadow root requires something like
     21        RenderBlock in order to draw its children. We swap from one renderer to another when
     22        necessary either by creating the shadow root or by explicitly detaching and attaching
     23        the plugin element.
     24
     25        Unfortunately this is difficult to test, because the snapshotting requires
     26        time to execute, and also a PluginView to be instantiated.
     27
     28        * WebCore.exp.in: Export the InlineBox interface.
     29
     30        * css/plugIns.css:
     31        (object::-webkit-snapshotted-plugin-content): New rules for a default label style.
     32
     33        * platform/LocalizedStrings.cpp: Make sure all ports have plugin strings, now it is called.
     34        * platform/LocalizedStrings.h:
     35        * platform/blackberry/LocalizedStringsBlackBerry.cpp:
     36        * platform/chromium/LocalizedStringsChromium.cpp:
     37        * platform/efl/LocalizedStringsEfl.cpp:
     38        * platform/gtk/LocalizedStringsGtk.cpp:
     39        * platform/qt/LocalizedStringsQt.cpp:
     40
     41        * html/HTMLPlugInElement.cpp:
     42        (WebCore::HTMLPlugInElement::defaultEventHandler): Take into account the fact
     43        that RenderSnapshottedPlugIn no longer is an embedded object.
     44
     45        * html/HTMLPlugInImageElement.cpp:
     46        (WebCore::HTMLPlugInImageElement::HTMLPlugInImageElement): New default values in constructor.
     47        (WebCore::HTMLPlugInElement::defaultEventHandler): Make sure to call base class.
     48        (WebCore::HTMLPlugInElement::willRecalcStyle): No need to reattach if we're a snapshot.
     49        (WebCore::HTMLPlugInImageElement::createRenderer): If we're showing a snapshot, create such
     50            a renderer, otherwise use the typical plug-in path.
     51        (WebCore::HTMLPlugInImageElement::updateSnapshot): Keep a record of the snapshot, since we'll
     52            need to give it to the renderer.
     53        (WebCore::HTMLPlugInImageElement::didAddUserAgentShadowRoot): Build a subtree that will display a label.
     54        * html/HTMLPlugInImageElement.h:
     55        (HTMLPlugInImageElement): New member variable to record the snapshot image and whether the label
     56            should show immediately.
     57        (WebCore::HTMLPlugInImageElement::swapRendererTimerFired): The callback function triggered when we need
     58            to swap to the Shadow Root.
     59        (WebCore::HTMLPlugInImageElement::userDidClickSnapshot): The user has tapped on the snapshot so the plugin
     60            in being recreated. Make sure we reattach so that a plugin renderer will be created.
     61        (WebCore::HTMLPlugInImageElement::subframeLoaderWillCreatePlugIn): Make sure we set the right
     62            displayState for snapshots.
     63        * html/HTMLPlugInImageElement.h:
     64        (HTMLPlugInImageElement): The new methods listed above.
     65        (WebCore::HTMLPlugInImageElement::setShouldShowSnapshotLabelAutomatically): Indicates whether or not
     66            a snapshot should be immediately labeled.
     67
     68        * page/ChromeClient.h: No need for plugInStartLabelImage any more.
     69
     70        * rendering/RenderSnapshottedPlugIn.cpp:
     71        (WebCore::RenderSnapshottedPlugIn::RenderSnapshottedPlugIn): New inheritance.
     72        (WebCore::RenderSnapshottedPlugIn::paint): If we're in the background paint phase, render the snapshot image.
     73        (WebCore::RenderSnapshottedPlugIn::paintSnapshotImage): Rename.
     74        (WebCore::RenderSnapshottedPlugIn::paintSnapshot): Rename.
     75        (WebCore::RenderSnapshottedPlugIn::paintSnapshotWithLabel): Rename. No need for label sizes.
     76        (WebCore::RenderSnapshottedPlugIn::getCursor):
     77        (WebCore::RenderSnapshottedPlugIn::handleEvent): The renderer doesn't restart the plug-in any more. Tell the element and it will do it.
     78        * rendering/RenderSnapshottedPlugIn.h:
     79        (RenderSnapshottedPlugIn): New inheritance. Some method renaming.
     80
    1812013-02-08  Dean Jackson  <dino@apple.com>
    282
  • trunk/Source/WebCore/WebCore.exp.in

    r142327 r142343  
    140140__ZN7WebCore11HistoryItemC1Ev
    141141__ZN7WebCore11HistoryItemD1Ev
     142__ZNK7WebCore9InlineBox14caretMaxOffsetEv
     143__ZN7WebCore9InlineBox14selectionStateEv
     144__ZN7WebCore9InlineBox14dirtyLineBoxesEv
     145__ZNK7WebCore9InlineBox22canAccommodateEllipsisEbii
     146__ZN7WebCore9InlineBox11extractLineEv
     147__ZN7WebCore9InlineBox14adjustPositionEff
     148__ZN7WebCore9InlineBoxdlEPvm
     149__ZN7WebCore9InlineBox5paintERNS_9PaintInfoERKNS_11LayoutPointENS_10LayoutUnitES6_
     150__ZN7WebCore9InlineBox10attachLineEv
     151__ZNK7WebCore9InlineBox16baselinePositionENS_12FontBaselineE
     152__ZN7WebCore9InlineBox11nodeAtPointERKNS_14HitTestRequestERNS_13HitTestResultERKNS_15HitTestLocationERKNS_11LayoutPointENS_10LayoutUnitESC_
     153__ZN7WebCore9InlineBox10deleteLineEPNS_11RenderArenaE
     154__ZN7WebCore9InlineBox7destroyEPNS_11RenderArenaE
     155__ZN7WebCore9InlineBox16placeEllipsisBoxEbfffRfRb
     156__ZNK7WebCore9InlineBox17reportMemoryUsageEPN3WTF16MemoryObjectInfoE
     157__ZNK7WebCore9InlineBox14caretMinOffsetEv
     158__ZNK7WebCore9InlineBox10lineHeightEv
    142159__ZN7WebCore11JSDOMWindow6s_infoE
    143160__ZN7WebCore11MemoryCache11setDisabledEb
  • trunk/Source/WebCore/css/plugIns.css

    r142341 r142343  
    2323 */
    2424
    25 /* plug-ins */
    26 p{} /*Needed by Windows because it doesn't like empty files*/
     25/*
     26 * This is the UA StyleSheet for <object> and <embed> elements.
     27 *
     28 * Such elements, when snapshotted (paused), will contain a ShadowRoot
     29 * with the following structure:
     30 *
     31 * <object>
     32 *   #ShadowRoot
     33 *     <div class="snapshot-container">
     34 *       <div class="snapshot-overlay"></div> <!-- e.g. for dimming content -->
     35 *         <div class="snapshot-label">
     36 *           <div class="snapshot-title">Snapshotted Plug-In</div>
     37 *           <div class="snapshot-subtitle">Click to restart</div>
     38 *         </div>
     39 *       </div>
     40 *     </div>
     41 *
     42 */
     43
     44object::-webkit-snapshotted-plugin-content,
     45embed::-webkit-snapshotted-plugin-content
     46{
     47    position: relative;
     48    display: inline-block;
     49    width: 100%;
     50    height: 100%;
     51}
     52
     53object::-webkit-snapshotted-plugin-content *,
     54embed::-webkit-snapshotted-plugin-content *
     55{
     56    -webkit-user-select: none;
     57}
     58
     59object::-webkit-snapshotted-plugin-content .snapshot-container,
     60embed::-webkit-snapshotted-plugin-content .snapshot-container
     61{
     62    position: absolute;
     63    width: 100%;
     64    height: 100%;
     65}
     66
     67object::-webkit-snapshotted-plugin-content .snapshot-container .snapshot-overlay,
     68embed::-webkit-snapshotted-plugin-content .snapshot-container .snapshot-overlay
     69{
     70    display: none;
     71}
     72
     73object::-webkit-snapshotted-plugin-content .snapshot-container .snapshot-label,
     74embed::-webkit-snapshotted-plugin-content .snapshot-container .snapshot-label
     75{
     76    position: absolute;
     77    background-color: white;
     78    color: black;
     79    margin: 1em;
     80    padding: 0.25em 2em;
     81    text-align: center;
     82}
     83
     84object::-webkit-snapshotted-plugin-content .snapshot-container .snapshot-label .snapshot-title,
     85embed::-webkit-snapshotted-plugin-content .snapshot-container .snapshot-label .snapshot-title
     86{
     87    font-weight: bold;
     88}
     89
     90object::-webkit-snapshotted-plugin-content .snapshot-container .snapshot-label .snapshot-subtitle,
     91embed::-webkit-snapshotted-plugin-content .snapshot-container .snapshot-label .snapshot-subtitle
     92{
     93    font-style: italic;
     94    color: #444;
     95}
  • trunk/Source/WebCore/html/HTMLPlugInElement.cpp

    r142341 r142343  
    202202            return;
    203203        }
    204         if (r->isSnapshottedPlugIn() && displayState() < PlayingWithPendingMouseClick) {
    205             toRenderSnapshottedPlugIn(r)->handleEvent(event);
    206             return;
    207         }
     204    } else if (r && r->isSnapshottedPlugIn() && displayState() < PlayingWithPendingMouseClick) {
     205        toRenderSnapshottedPlugIn(r)->handleEvent(event);
     206        HTMLFrameOwnerElement::defaultEventHandler(event);
     207        return;
    208208    }
    209209
  • trunk/Source/WebCore/html/HTMLPlugInImageElement.cpp

    r142341 r142343  
    2222#include "HTMLPlugInImageElement.h"
    2323
     24#include "Chrome.h"
     25#include "ChromeClient.h"
    2426#include "Frame.h"
    2527#include "FrameLoader.h"
    2628#include "FrameLoaderClient.h"
    2729#include "FrameView.h"
     30#include "HTMLDivElement.h"
    2831#include "HTMLImageLoader.h"
    29 #include "HTMLNames.h"
    3032#include "Image.h"
     33#include "LocalizedStrings.h"
    3134#include "Logging.h"
    3235#include "MouseEvent.h"
    3336#include "NodeRenderStyle.h"
     37#include "NodeRenderingContext.h"
    3438#include "Page.h"
    3539#include "PlugInClient.h"
     
    4246#include "SecurityOrigin.h"
    4347#include "Settings.h"
     48#include "ShadowRoot.h"
    4449#include "StyleResolver.h"
     50#include "Text.h"
    4551
    4652namespace WebCore {
     53
     54using namespace HTMLNames;
    4755
    4856static const int autoStartPlugInSizeThresholdWidth = 1;
     
    6270    , m_shouldPreferPlugInsForImages(preferPlugInsForImagesOption == ShouldPreferPlugInsForImages)
    6371    , m_needsDocumentActivationCallbacks(false)
     72    , m_shouldShowSnapshotLabelAutomatically(false)
    6473    , m_simulatedMouseClickTimer(this, &HTMLPlugInImageElement::simulatedMouseClickTimerFired, simulatedMouseClickTimerDelay)
     74    , m_swapRendererTimer(this, &HTMLPlugInImageElement::swapRendererTimerFired)
    6575{
    6676    setHasCustomCallbacks();
     
    133143        document()->registerForPageCacheSuspensionCallbacks(this);
    134144    }
    135    
     145
     146    if (displayState() == DisplayingSnapshot) {
     147        RenderSnapshottedPlugIn* renderSnapshottedPlugIn = new (arena) RenderSnapshottedPlugIn(this);
     148        renderSnapshottedPlugIn->updateSnapshot(m_snapshotImage);
     149        if (m_shouldShowSnapshotLabelAutomatically)
     150            renderSnapshottedPlugIn->setShouldShowLabelAutomatically();
     151        return renderSnapshottedPlugIn;
     152    }
     153
    136154    // Fallback content breaks the DOM->Renderer class relationship of this
    137155    // class and all superclasses because createObject won't necessarily
     
    139157    if (useFallbackContent())
    140158        return RenderObject::createObject(this, style);
     159
    141160    if (isImageType()) {
    142161        RenderImage* image = new (arena) RenderImage(this);
     
    145164    }
    146165
    147     if (document()->page() && document()->page()->settings()->plugInSnapshottingEnabled())
    148         return new (arena) RenderSnapshottedPlugIn(this);
    149166    return new (arena) RenderEmbeddedObject(this);
    150167}
     
    153170{
    154171    // FIXME: Why is this necessary?  Manual re-attach is almost always wrong.
    155     if (!useFallbackContent() && needsWidgetUpdate() && renderer() && !isImageType())
     172    if (!useFallbackContent() && needsWidgetUpdate() && renderer() && !isImageType() && (displayState() != DisplayingSnapshot))
    156173        reattach();
    157174    return true;
     
    259276void HTMLPlugInImageElement::updateSnapshot(PassRefPtr<Image> image)
    260277{
    261     if (displayState() > DisplayingSnapshot || !renderer()->isSnapshottedPlugIn())
    262         return;
    263 
    264     toRenderSnapshottedPlugIn(renderer())->updateSnapshot(image);
     278    if (displayState() > DisplayingSnapshot)
     279        return;
     280
     281    m_snapshotImage = image;
     282    if (renderer()->isSnapshottedPlugIn()) {
     283        toRenderSnapshottedPlugIn(renderer())->updateSnapshot(image);
     284        return;
     285    }
     286
    265287    setDisplayState(DisplayingSnapshot);
     288    m_swapRendererTimer.startOneShot(0);
     289}
     290
     291void HTMLPlugInImageElement::didAddUserAgentShadowRoot(ShadowRoot* root)
     292{
     293    Document* doc = document();
     294
     295    RefPtr<Element> shadowContainer = HTMLDivElement::create(doc);
     296    shadowContainer->setPseudo(AtomicString("-webkit-snapshotted-plugin-content", AtomicString::ConstructFromLiteral));
     297
     298    RefPtr<Element> container = HTMLDivElement::create(doc);
     299    container->setAttribute(classAttr, AtomicString("snapshot-container", AtomicString::ConstructFromLiteral));
     300
     301    RefPtr<Element> overlay = HTMLDivElement::create(doc);
     302    overlay->setAttribute(classAttr, AtomicString("snapshot-overlay", AtomicString::ConstructFromLiteral));
     303    container->appendChild(overlay, ASSERT_NO_EXCEPTION);
     304
     305    RefPtr<Element> label = HTMLDivElement::create(doc);
     306    label->setAttribute(classAttr, AtomicString("snapshot-label", AtomicString::ConstructFromLiteral));
     307
     308    String titleText = snapshottedPlugInLabelTitle();
     309    String subtitleText = snapshottedPlugInLabelSubtitle();
     310    if (document()->page()) {
     311        String clientTitleText = document()->page()->chrome()->client()->plugInStartLabelTitle();
     312        if (!clientTitleText.isEmpty())
     313            titleText = clientTitleText;
     314        String clientSubtitleText = document()->page()->chrome()->client()->plugInStartLabelSubtitle();
     315        if (!clientSubtitleText.isEmpty())
     316            subtitleText = clientSubtitleText;
     317    }
     318
     319    RefPtr<Element> title = HTMLDivElement::create(doc);
     320    title->setAttribute(classAttr, AtomicString("snapshot-title", AtomicString::ConstructFromLiteral));
     321    title->appendChild(doc->createTextNode(titleText), ASSERT_NO_EXCEPTION);
     322    label->appendChild(title, ASSERT_NO_EXCEPTION);
     323
     324    RefPtr<Element> subTitle = HTMLDivElement::create(doc);
     325    subTitle->setAttribute(classAttr, AtomicString("snapshot-subtitle", AtomicString::ConstructFromLiteral));
     326    subTitle->appendChild(doc->createTextNode(subtitleText), ASSERT_NO_EXCEPTION);
     327    label->appendChild(subTitle, ASSERT_NO_EXCEPTION);
     328
     329    container->appendChild(label, ASSERT_NO_EXCEPTION);
     330
     331    shadowContainer->appendChild(container, ASSERT_NO_EXCEPTION);
     332    root->appendChild(shadowContainer, ASSERT_NO_EXCEPTION);
     333}
     334
     335void HTMLPlugInImageElement::swapRendererTimerFired(Timer<HTMLPlugInImageElement>*)
     336{
     337    ASSERT(displayState() == DisplayingSnapshot);
     338    if (userAgentShadowRoot())
     339        return;
     340
     341    // Create a shadow root, which will trigger the code to add a snapshot container
     342    // and reattach, thus making a new Renderer.
     343    ensureUserAgentShadowRoot();
    266344}
    267345
     
    271349    if (document()->page() && !SchemeRegistry::shouldTreatURLSchemeAsLocal(document()->page()->mainFrame()->document()->baseURL().protocol()))
    272350        document()->page()->plugInClient()->addAutoStartOrigin(document()->page()->mainFrame()->document()->baseURL().host(), m_plugInOriginHash);
     351
     352    reattach();
    273353}
    274354
     
    320400    }
    321401
    322     if (!renderer()->isSnapshottedPlugIn()) {
    323         LOG(Plugins, "%p Renderer is not snapshotted plugin, set to play", this);
    324         return;
    325     }
    326402    if (ScriptController::processingUserGesture()) {
    327403        LOG(Plugins, "%p Script is processing user gesture, set to play", this);
     
    329405    }
    330406
    331     LayoutRect rect = toRenderSnapshottedPlugIn(renderer())->contentBoxRect();
     407    LayoutRect rect = toRenderEmbeddedObject(renderer())->contentBoxRect();
    332408    int width = rect.width();
    333409    int height = rect.height();
     
    352428
    353429    if (shouldPlugInShowLabelAutomatically(document()->page()->mainFrame()->view()->contentsSize(), this))
    354         toRenderSnapshottedPlugIn(renderer())->setShouldShowLabelAutomatically();
     430        setShouldShowSnapshotLabelAutomatically();
    355431
    356432    LOG(Plugins, "%p Plug-in hash %x is %dx%d, origin is not auto-start, set to wait for snapshot", this, m_plugInOriginHash, width, height);
    357     setDisplayState(WaitingForSnapshot);
     433    // We may have got to this point by restarting a snapshotted plug-in, in which case we don't want to
     434    // reset the display state.
     435    if (displayState() != PlayingWithPendingMouseClick)
     436        setDisplayState(WaitingForSnapshot);
    358437}
    359438
  • trunk/Source/WebCore/html/HTMLPlugInImageElement.h

    r142341 r142343  
    2626#include "RenderStyle.h"
    2727#include <wtf/OwnPtr.h>
     28#include <wtf/RefPtr.h>
    2829
    2930namespace WebCore {
     
    3132class HTMLImageLoader;
    3233class FrameLoader;
     34class Image;
    3335class MouseEvent;
    3436class Widget;
     
    3840    CreateOnlyNonNetscapePlugins,
    3941};
    40    
     42
    4143enum PreferPlugInsForImagesOption {
    4244    ShouldPreferPlugInsForImages,
     
    9395    virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
    9496    virtual bool willRecalcStyle(StyleChange);
    95    
     97
     98    void didAddUserAgentShadowRoot(ShadowRoot*) OVERRIDE;
     99
    96100    virtual void finishParsingChildren();
    97101
    98102    void updateWidgetIfNecessary();
    99103    virtual bool useFallbackContent() const { return false; }
    100    
     104
    101105    virtual void updateSnapshot(PassRefPtr<Image>) OVERRIDE;
    102106    virtual void dispatchPendingMouseClick() OVERRIDE;
    103107    void simulatedMouseClickTimerFired(DeferrableOneShotTimer<HTMLPlugInImageElement>*);
    104108
     109    void swapRendererTimerFired(Timer<HTMLPlugInImageElement>*);
     110
     111    void setShouldShowSnapshotLabelAutomatically() { m_shouldShowSnapshotLabelAutomatically = true; }
     112
    105113    bool m_needsWidgetUpdate;
    106114    bool m_shouldPreferPlugInsForImages;
    107115    bool m_needsDocumentActivationCallbacks;
     116    bool m_shouldShowSnapshotLabelAutomatically;
    108117    RefPtr<RenderStyle> m_customStyleForPageCache;
    109118    RefPtr<MouseEvent> m_pendingClickEventFromSnapshot;
    110119    DeferrableOneShotTimer<HTMLPlugInImageElement> m_simulatedMouseClickTimer;
     120    Timer<HTMLPlugInImageElement> m_swapRendererTimer;
     121    RefPtr<Image> m_snapshotImage;
    111122};
    112123
  • trunk/Source/WebCore/page/ChromeClient.h

    r142341 r142343  
    374374    virtual bool isEmptyChromeClient() const { return false; }
    375375
    376     virtual PassRefPtr<Image> plugInStartLabelImage(RenderSnapshottedPlugIn::LabelSize) const { return 0; }
    377376    virtual String plugInStartLabelTitle() const { return String(); }
    378377    virtual String plugInStartLabelSubtitle() const { return String(); }
  • trunk/Source/WebCore/platform/LocalizedStrings.cpp

    r142341 r142343  
    11/*
    2  * Copyright (C) 2003, 2006, 2009, 2010, 2012 Apple Inc. All rights reserved.
     2 * Copyright (C) 2003, 2006, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved.
    33 * Copyright (C) 2010 Igalia S.L
    44 *
  • trunk/Source/WebCore/platform/LocalizedStrings.h

    r142341 r142343  
    11/*
    2  * Copyright (C) 2003, 2006, 2009, 2011 Apple Inc.  All rights reserved.
     2 * Copyright (C) 2003, 2006, 2009, 2011, 2012, 2013 Apple Inc.  All rights reserved.
    33 * Copyright (C) 2010 Igalia S.L
    44 *
  • trunk/Source/WebCore/platform/blackberry/LocalizedStringsBlackBerry.cpp

    r142341 r142343  
    618618}
    619619
     620String snapshottedPlugInLabelTitle()
     621{
     622    notImplemented();
     623    return String();
     624}
     625
     626String snapshottedPlugInLabelSubtitle()
     627{
     628    notImplemented();
     629    return String();
     630}
     631
    620632} // namespace WebCore
  • trunk/Source/WebCore/platform/chromium/LocalizedStringsChromium.cpp

    r142341 r142343  
    417417String contextMenuItemTagMediaPause() { return String(); }
    418418String contextMenuItemTagMediaMute() { return String(); }
     419String snapshottedPlugInLabelTitle() { return String(); }
     420String snapshottedPlugInLabelSubtitle() { return String(); }
    419421
    420422#if ENABLE(VIDEO_TRACK)
  • trunk/Source/WebCore/platform/efl/LocalizedStringsEfl.cpp

    r142341 r142343  
    611611#endif
    612612
    613 }
     613String snapshottedPlugInLabelTitle()
     614{
     615    return String("Snapshotted Plug-In");
     616}
     617
     618String snapshottedPlugInLabelSubtitle()
     619{
     620    return String("Click to restart");
     621}
     622
     623
     624}
  • trunk/Source/WebCore/platform/gtk/LocalizedStringsGtk.cpp

    r142341 r142343  
    775775#endif
    776776
    777 }
     777String snapshottedPlugInLabelTitle()
     778{
     779    return String::fromUTF8(C_("Snapshotted Plug-In", "Title of the label to show on a snapshotted plug-in"));
     780}
     781
     782String snapshottedPlugInLabelSubtitle()
     783{
     784    return String::fromUTF8(C_("Click to restart", "Subtitle of the label to show on a snapshotted plug-in"));
     785}
     786
     787}
  • trunk/Source/WebCore/platform/qt/LocalizedStringsQt.cpp

    r142341 r142343  
    724724}
    725725
     726String snapshottedPlugInLabelTitle()
     727{
     728    notImplemented();
     729    return String();
     730}
     731
     732String snapshottedPlugInLabelSubtitle()
     733{
     734    notImplemented();
     735    return String();
     736}
     737
    726738String localizedString(const char* key)
    727739{
  • trunk/Source/WebCore/rendering/RenderSnapshottedPlugIn.cpp

    r142341 r142343  
    4141#include "PaintInfo.h"
    4242#include "Path.h"
     43#include "RenderView.h"
    4344#include "SourceGraphic.h"
    4445
     
    4748static const int autoStartPlugInSizeThresholdWidth = 1;
    4849static const int autoStartPlugInSizeThresholdHeight = 1;
    49 static const int startLabelPadding = 10; // Label should be 10px from edge of box.
    50 static const int startLabelInset = 20; // But the label is inset from its box also. FIXME: This will be removed when we go to a ShadowDOM approach.
    5150static const double showLabelAfterMouseOverDelay = 1;
    5251static const double showLabelAutomaticallyDelay = 3;
     
    101100
    102101RenderSnapshottedPlugIn::RenderSnapshottedPlugIn(HTMLPlugInImageElement* element)
    103     : RenderEmbeddedObject(element)
     102    : RenderBlock(element)
    104103    , m_snapshotResource(RenderImageResource::create())
    105104    , m_shouldShowLabel(false)
     
    146145void RenderSnapshottedPlugIn::paint(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
    147146{
    148     if (plugInImageElement()->displayState() < HTMLPlugInElement::PlayingWithPendingMouseClick) {
    149         RenderReplaced::paint(paintInfo, paintOffset);
    150         return;
    151     }
    152 
    153     RenderEmbeddedObject::paint(paintInfo, paintOffset);
    154 }
    155 
    156 void RenderSnapshottedPlugIn::paintReplaced(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
    157 {
    158     if (plugInImageElement()->displayState() < HTMLPlugInElement::PlayingWithPendingMouseClick) {
     147    if (paintInfo.phase == PaintPhaseBlockBackground && plugInImageElement()->displayState() < HTMLPlugInElement::PlayingWithPendingMouseClick) {
    159148        if (m_shouldShowLabel)
    160             paintReplacedSnapshotWithLabel(paintInfo, paintOffset);
     149            paintSnapshotWithLabel(paintInfo, paintOffset);
    161150        else
    162             paintReplacedSnapshot(paintInfo, paintOffset);
    163         return;
    164     }
    165 
    166     RenderEmbeddedObject::paintReplaced(paintInfo, paintOffset);
    167 }
    168 
    169 void RenderSnapshottedPlugIn::paintSnapshot(Image* image, PaintInfo& paintInfo, const LayoutPoint& paintOffset)
     151            paintSnapshot(paintInfo, paintOffset);
     152    }
     153
     154    RenderBlock::paint(paintInfo, paintOffset);
     155}
     156
     157void RenderSnapshottedPlugIn::paintSnapshotImage(Image* image, PaintInfo& paintInfo, const LayoutPoint& paintOffset)
    170158{
    171159    LayoutUnit cWidth = contentWidth();
     
    181169
    182170    LayoutSize contentSize(cWidth, cHeight);
    183     LayoutPoint contentLocation = paintOffset;
     171    LayoutPoint contentLocation = location() + paintOffset;
    184172    contentLocation.move(borderLeft() + paddingLeft(), borderTop() + paddingTop());
    185173
     
    193181}
    194182
    195 void RenderSnapshottedPlugIn::paintReplacedSnapshot(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
     183void RenderSnapshottedPlugIn::paintSnapshot(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
    196184{
    197185    RefPtr<Image> image = m_snapshotResource->image();
     
    199187        return;
    200188
    201     paintSnapshot(image.get(), paintInfo, paintOffset);
    202 }
    203 
    204 Image* RenderSnapshottedPlugIn::startLabelImage(LabelSize size) const
    205 {
    206     static Image* labelImages[2] = { 0, 0 };
    207     static bool initializedImages[2] = { false, false };
    208 
    209     int arrayIndex = static_cast<int>(size);
    210     if (labelImages[arrayIndex])
    211         return labelImages[arrayIndex];
    212     if (initializedImages[arrayIndex])
    213         return 0;
    214 
    215     if (document()->page()) {
    216         labelImages[arrayIndex] = document()->page()->chrome()->client()->plugInStartLabelImage(size).leakRef();
    217         initializedImages[arrayIndex] = true;
    218     }
    219     return labelImages[arrayIndex];
     189    paintSnapshotImage(image.get(), paintInfo, paintOffset);
    220190}
    221191
     
    239209#endif
    240210
    241 void RenderSnapshottedPlugIn::paintReplacedSnapshotWithLabel(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
     211void RenderSnapshottedPlugIn::paintSnapshotWithLabel(PaintInfo& paintInfo, const LayoutPoint& paintOffset)
    242212{
    243213    if (contentBoxRect().isEmpty())
     
    248218
    249219    m_showedLabelOnce = true;
    250     LayoutRect rect = contentBoxRect();
    251     LayoutRect labelRect = tryToFitStartLabel(LabelSizeLarge, rect);
    252     LabelSize size = NoLabel;
    253     if (!labelRect.isEmpty())
    254         size = LabelSizeLarge;
    255     else {
    256         labelRect = tryToFitStartLabel(LabelSizeSmall, rect);
    257         if (!labelRect.isEmpty())
    258             size = LabelSizeSmall;
    259         else
    260             return;
    261     }
    262 
    263     Image* labelImage = startLabelImage(size);
    264     if (!labelImage)
    265         return;
     220    LayoutRect labelRect;
    266221
    267222    RefPtr<Image> snapshotImage = m_snapshotResource->image();
     
    270225
    271226#if ENABLE(FILTERS)
    272     RefPtr<Image> blurredSnapshotImage = m_snapshotResourceForLabel->image();
    273     if (!blurredSnapshotImage || blurredSnapshotImage->isNull()) {
    274         blurredSnapshotImage = snapshottedPluginImageForLabelDisplay(snapshotImage, labelRect);
    275         m_snapshotResourceForLabel->setCachedImage(new CachedImage(blurredSnapshotImage.get()));
    276     }
    277     snapshotImage = blurredSnapshotImage;
     227    // FIXME: Temporarily disabling the blur behind the label.
     228    // https://bugs.webkit.org/show_bug.cgi?id=108368
     229    if (!labelRect.isEmpty()) {
     230        RefPtr<Image> blurredSnapshotImage = m_snapshotResourceForLabel->image();
     231        if (!blurredSnapshotImage || blurredSnapshotImage->isNull()) {
     232            blurredSnapshotImage = snapshottedPluginImageForLabelDisplay(snapshotImage, labelRect);
     233            m_snapshotResourceForLabel->setCachedImage(new CachedImage(blurredSnapshotImage.get()));
     234        }
     235        snapshotImage = blurredSnapshotImage;
     236    }
    278237#endif
    279238
    280     paintSnapshot(snapshotImage.get(), paintInfo, paintOffset);
    281 
    282     // Remember that the labelRect includes the label inset, so we need to adjust for it.
    283     paintInfo.context->drawImage(labelImage, ColorSpaceDeviceRGB,
    284                                  IntRect(roundedIntPoint(paintOffset + labelRect.location() - IntSize(startLabelInset, startLabelInset)),
    285                                          roundedIntSize(labelRect.size() + IntSize(2 * startLabelInset, 2 * startLabelInset))),
    286                                  labelImage->rect());
     239    paintSnapshotImage(snapshotImage.get(), paintInfo, paintOffset);
    287240}
    288241
     
    310263        return SetCursor;
    311264    }
    312     return RenderEmbeddedObject::getCursor(point, overrideCursor);
     265    return RenderBlock::getCursor(point, overrideCursor);
    313266}
    314267
     
    326279        plugInImageElement()->setDisplayState(HTMLPlugInElement::PlayingWithPendingMouseClick);
    327280        plugInImageElement()->userDidClickSnapshot(mouseEvent);
    328 
    329         if (widget()) {
    330             if (Frame* frame = document()->frame())
    331                 frame->loader()->client()->recreatePlugin(widget());
    332             repaint();
    333         }
    334281        event->setDefaultHandled();
    335282    } else if (event->type() == eventNames().mousedownEvent) {
     
    359306}
    360307
    361 LayoutRect RenderSnapshottedPlugIn::tryToFitStartLabel(LabelSize size, const LayoutRect& contentBox) const
    362 {
    363     Image* labelImage = startLabelImage(size);
    364     if (!labelImage)
    365         return LayoutRect();
    366 
    367     // Assume that the labelImage has been provided to match our device scale.
    368     float scaleFactor = 1;
    369     if (document()->page())
    370         scaleFactor = document()->page()->deviceScaleFactor();
    371     IntSize labelImageSize = labelImage->size();
    372     labelImageSize.scale(1 / (scaleFactor ? scaleFactor : 1));
    373 
    374     LayoutSize labelSize = labelImageSize - LayoutSize(2 * startLabelInset, 2 * startLabelInset);
    375     LayoutRect candidateRect(contentBox.maxXMinYCorner() + LayoutSize(-startLabelPadding, startLabelPadding) + LayoutSize(-labelSize.width(), 0), labelSize);
    376     // The minimum allowed content box size is the label image placed in the center of the box, surrounded by startLabelPadding.
    377     if (candidateRect.x() < startLabelPadding || candidateRect.maxY() > contentBox.height() - startLabelPadding)
    378         return LayoutRect();
    379     return candidateRect;
    380 }
    381 
    382308void RenderSnapshottedPlugIn::resetDelayTimer(ShowReason reason)
    383309{
  • trunk/Source/WebCore/rendering/RenderSnapshottedPlugIn.h

    r142341 r142343  
    2828
    2929#include "RenderBlock.h"
    30 #include "RenderEmbeddedObject.h"
    3130#include "RenderImageResource.h"
    3231#include "Timer.h"
     
    3635class HTMLPlugInImageElement;
    3736
    38 class RenderSnapshottedPlugIn : public RenderEmbeddedObject {
     37class RenderSnapshottedPlugIn : public RenderBlock {
    3938public:
    4039    explicit RenderSnapshottedPlugIn(HTMLPlugInImageElement*);
    4140    virtual ~RenderSnapshottedPlugIn();
    42 
    43     enum LabelSize {
    44         LabelSizeSmall,
    45         LabelSizeLarge,
    46         NoLabel,
    47     };
    4841
    4942    void updateSnapshot(PassRefPtr<Image>);
     
    6154    virtual bool isSnapshottedPlugIn() const OVERRIDE { return true; }
    6255    virtual void paint(PaintInfo&, const LayoutPoint&) OVERRIDE;
    63     virtual void paintReplaced(PaintInfo&, const LayoutPoint&) OVERRIDE;
    6456
    65     void paintReplacedSnapshot(PaintInfo&, const LayoutPoint&);
    66     void paintReplacedSnapshotWithLabel(PaintInfo&, const LayoutPoint&);
    67     void paintSnapshot(Image*, PaintInfo&, const LayoutPoint&);
     57    void paintSnapshot(PaintInfo&, const LayoutPoint&);
     58    void paintSnapshotWithLabel(PaintInfo&, const LayoutPoint&);
     59    void paintSnapshotImage(Image*, PaintInfo&, const LayoutPoint&);
    6860    void repaintLabel();
    69 
    70     LayoutRect tryToFitStartLabel(LabelSize, const LayoutRect& contentBox) const;
    71     Image* startLabelImage(LabelSize) const;
    7261
    7362    enum ShowReason {
  • trunk/Source/WebKit2/ChangeLog

    r142341 r142343  
     12013-02-08  Dean Jackson  <dino@apple.com>
     2
     3        Snapshotted plug-in should use shadow root
     4        https://bugs.webkit.org/show_bug.cgi?id=108284
     5
     6        Reviewed by Simon Fraser.
     7
     8        Take two of this commit! We no longer have any need for plugInStartLabelImage.
     9
     10        * WebProcess/InjectedBundle/InjectedBundlePageUIClient.cpp: Remove plugInStartLabelImage.
     11        * WebProcess/InjectedBundle/InjectedBundlePageUIClient.h: Ditto.
     12        * WebProcess/WebCoreSupport/WebChromeClient.cpp: Ditto.
     13        * WebProcess/WebCoreSupport/WebChromeClient.h: Ditto.
     14
    1152013-02-08  Dean Jackson  <dino@apple.com>
    216
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageUIClient.cpp

    r142341 r142343  
    164164}
    165165
    166 PassRefPtr<WebImage> InjectedBundlePageUIClient::plugInStartLabelImage(RenderSnapshottedPlugIn::LabelSize size) const
    167 {
    168     if (!m_client.plugInStartLabelImage)
    169         return 0;
    170 
    171     WKBundlePageLabelSize wkSize;
    172     switch (size) {
    173     case RenderSnapshottedPlugIn::LabelSizeSmall:
    174         wkSize = WKBundlePageLabelSizeSmall;
    175         break;
    176     case RenderSnapshottedPlugIn::LabelSizeLarge:
    177         wkSize = WKBundlePageLabelSizeLarge;
    178         break;
    179     default:
    180         return 0;
    181     }
    182 
    183     return adoptRef(toImpl(m_client.plugInStartLabelImage(wkSize, m_client.clientInfo)));
    184 }
    185 
    186166String InjectedBundlePageUIClient::plugInStartLabelTitle() const
    187167{
  • trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundlePageUIClient.h

    r142341 r142343  
    3030#include "WKBundlePage.h"
    3131#include "WebEvent.h"
    32 #include "WebImage.h"
    3332#include <WebCore/RenderSnapshottedPlugIn.h>
    3433#include <wtf/Forward.h>
     
    7271    uint64_t didExceedDatabaseQuota(WebPage*, WebSecurityOrigin*, const String& databaseName, const String& databaseDisplayName, uint64_t currentQuotaBytes, uint64_t currentOriginUsageBytes, uint64_t currentDatabaseUsageBytes, uint64_t expectedUsageBytes);
    7372
    74     PassRefPtr<WebImage> plugInStartLabelImage(WebCore::RenderSnapshottedPlugIn::LabelSize) const;
    7573    String plugInStartLabelTitle() const;
    7674    String plugInStartLabelSubtitle() const;
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.cpp

    r142341 r142343  
    799799}
    800800
    801 PassRefPtr<Image> WebChromeClient::plugInStartLabelImage(RenderSnapshottedPlugIn::LabelSize size) const
    802 {
    803     return m_page->injectedBundleUIClient().plugInStartLabelImage(size)->bitmap()->createImage();
    804 }
    805 
    806801String WebChromeClient::plugInStartLabelTitle() const
    807802{
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h

    r142341 r142343  
    2929
    3030#include <WebCore/ChromeClient.h>
    31 #include <WebCore/Image.h>
    3231#include <WebCore/ViewportArguments.h>
    3332#include <wtf/text/WTFString.h>
     
    219218    virtual void logDiagnosticMessage(const String& message, const String& description, const String& success) OVERRIDE;
    220219
    221     virtual PassRefPtr<WebCore::Image> plugInStartLabelImage(WebCore::RenderSnapshottedPlugIn::LabelSize) const OVERRIDE;
    222220    virtual String plugInStartLabelTitle() const OVERRIDE;
    223221    virtual String plugInStartLabelSubtitle() const OVERRIDE;
Note: See TracChangeset for help on using the changeset viewer.