Changeset 138729 in webkit


Ignore:
Timestamp:
Jan 3, 2013, 1:00:37 PM (13 years ago)
Author:
jonlee@apple.com
Message:

Revert auto-start plugins to snapshotted plugins after a period of inactivity
https://bugs.webkit.org/show_bug.cgi?id=105973
<rdar://problem/12947865>

Reviewed by Brady Eidson.

Source/WebCore:

  • html/HTMLPlugInElement.h:

(WebCore::HTMLPlugInElement::plugInOriginHash): Expose publicly for WebKit2.
Reorganize the protected members of the class.

  • html/HTMLPlugInImageElement.h: Move the member to HTMLPlugInElement.

Source/WebKit2:

Change the set of origin hashes maintained by the web process to a hash map that associates
a timestamp for each hash. If the plug-in's origin is marked for auto-start, we also check
it against the timestamp. If the time is later, then we consider the entry stale, and snapshot
the plug-in instead.

But, if the user interacts with the plug-in, we delay that expiration timestamp out, so that
it expires a month from first interaction. To avoid too much chatter between the web processes
and UI process, we only update the timestamp if a day a passed since the last change to the
timestamp.

  • WebProcess/Plugins/PluginView.h:

(PluginView): Add a member variable to flag whether the user had interacted with the plug-in.

  • WebProcess/Plugins/PluginView.cpp:

(WebKit::PluginView::PluginView): Initialize the flag to false.
(WebKit::PluginView::handleEvent): We consider mouse down, up, wheel, context menu, and keyboard
events as user interaction. Do not consider mouse enter, leave, and move events as user
interaction. Also, remove unneeded comments.
(WebKit::PluginView::pluginDidReceiveUserInteraction): If this is the first time the function is
called, tell the web process, so that the expiration timestamp can be updated.

  • WebProcess/WebProcess.messages.in: Update the messages to include the expiration time.
  • WebProcess/WebProcess.h:

(WebProcess): Update the cached copy of the auto-start origins to include their expiration
timestamps. Update the message signatures. Add a function to update the expiration timestamp
for a specific origin. Rename plugInAutoStartOriginsChanged to resetPlugInAutoStartOrigins.

  • WebProcess/WebProcess.cpp:

(WebKit::WebProcess::initializeWebProcess): Instead of individually adding the origins in the
provided vector, just call resetPlugInAutoStartOrigins().
(WebKit::WebProcess::isPlugInAutoStartOrigin): Check to see if the origin is in the table, and if
so, check the current time against the expiration time.
(WebKit::WebProcess::didAddPlugInAutoStartOrigin): Update the cached table.
(WebKit::WebProcess::resetPlugInAutoStartOrigins): Swap the tables between the provided parameter
and the member variable. We can safely do this because the function is called in two cases where
the parameter is afterwards thrown away: when a new web process is created, and when it is called
through an IPC message.
(WebKit::WebProcess::plugInDidReceiveUserInteraction): When invoked, we tell the UI process to
update the expiration time for the given origin if the time difference between the expiration
time and the current time is less than the threshold plugInAutoStartExpirationTimeUpdateThreshold.

  • UIProcess/WebContext.messages.in: Add message that is called when the web process wants to

update the expiration timestamp for the plug-in origin.

  • UIProcess/WebContext.cpp:

(WebKit::WebContext::plugInDidReceiveUserInteraction): Forward to the provider.

  • UIProcess/WebContext.h:
  • UIProcess/Plugins/PlugInAutoStartProvider.cpp:

(WebKit::expirationTimeFromNow): Returns a new time based on the current time + 1 month.
(WebKit::PlugInAutoStartProvider::addAutoStartOrigin): Refactor. Set the expiration time for the
added origin.
(WebKit::PlugInAutoStartProvider::autoStartOriginsCopy): Refactor.
(WebKit::PlugInAutoStartProvider::autoStartOriginsTableCopy): Refactor to include the expiration
times. Also, check the current time against the expiration time. If we are past the time, remove
the entry from the copy.
(WebKit::PlugInAutoStartProvider::setAutoStartOriginsTable): Refactor to extract and duplicate
the provided map of origins and expiration timestamps.
(WebKit::PlugInAutoStartProvider::didReceiveUserInteraction): Look for the origin hash. If found,
update the expiration time. Update all existing web processes with the new expiration time, and
tell the context client that the hashes have changed.

  • UIProcess/Plugins/PlugInAutoStartProvider.h:

(PlugInAutoStartProvider): Change the m_autoStartHashes variable to a map of a hash to its domain
entry in the auto-start table. It is used to cross-reference the auto-start table and update
the origin's expiration time.

  • Shared/WebProcessCreationParameters.h:

(WebProcessCreationParameters): Switch the creation parameter to seed the origin table to a map.

Location:
trunk/Source
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r138728 r138729  
     12013-01-02  Jon Lee  <jonlee@apple.com>
     2
     3        Revert auto-start plugins to snapshotted plugins after a period of inactivity
     4        https://bugs.webkit.org/show_bug.cgi?id=105973
     5        <rdar://problem/12947865>
     6
     7        Reviewed by Brady Eidson.
     8
     9        * html/HTMLPlugInElement.h:
     10        (WebCore::HTMLPlugInElement::plugInOriginHash): Expose publicly for WebKit2.
     11        Reorganize the protected members of the class.
     12        * html/HTMLPlugInImageElement.h: Move the member to HTMLPlugInElement.
     13
    1142013-01-03  Alexis Menard  <alexis@webkit.org>
    215
  • trunk/Source/WebCore/html/HTMLPlugInElement.h

    r135767 r138729  
    6060    virtual void dispatchPendingMouseClick() { }
    6161
     62    unsigned plugInOriginHash() const { return m_plugInOriginHash; }
     63
    6264#if ENABLE(NETSCAPE_PLUGIN_API)
    6365    NPObject* getNPObject();
     
    8183    virtual bool areAuthorShadowsAllowed() const OVERRIDE { return false; }
    8284
    83     bool m_inBeforeLoadEventHandler;
    8485    // Subclasses should use guardedDispatchBeforeLoadEvent instead of calling dispatchBeforeLoadEvent directly.
    8586    bool guardedDispatchBeforeLoadEvent(const String& sourceURL);
     87
     88    bool m_inBeforeLoadEventHandler;
     89
     90    unsigned m_plugInOriginHash;
    8691
    8792private:
  • trunk/Source/WebCore/html/HTMLPlugInImageElement.h

    r137868 r138729  
    109109    RefPtr<MouseEvent> m_pendingClickEventFromSnapshot;
    110110    DeferrableOneShotTimer<HTMLPlugInImageElement> m_simulatedMouseClickTimer;
    111     unsigned m_plugInOriginHash;
    112111};
    113112
  • trunk/Source/WebKit2/ChangeLog

    r138728 r138729  
     12013-01-02  Jon Lee  <jonlee@apple.com>
     2
     3        Revert auto-start plugins to snapshotted plugins after a period of inactivity
     4        https://bugs.webkit.org/show_bug.cgi?id=105973
     5        <rdar://problem/12947865>
     6
     7        Reviewed by Brady Eidson.
     8
     9        Change the set of origin hashes maintained by the web process to a hash map that associates
     10        a timestamp for each hash. If the plug-in's origin is marked for auto-start, we also check
     11        it against the timestamp. If the time is later, then we consider the entry stale, and snapshot
     12        the plug-in instead.
     13
     14        But, if the user interacts with the plug-in, we delay that expiration timestamp out, so that
     15        it expires a month from first interaction. To avoid too much chatter between the web processes
     16        and UI process, we only update the timestamp if a day a passed since the last change to the
     17        timestamp.
     18
     19        * WebProcess/Plugins/PluginView.h:
     20        (PluginView): Add a member variable to flag whether the user had interacted with the plug-in.
     21        * WebProcess/Plugins/PluginView.cpp:
     22        (WebKit::PluginView::PluginView): Initialize the flag to false.
     23        (WebKit::PluginView::handleEvent): We consider mouse down, up, wheel, context menu, and keyboard
     24        events as user interaction. Do not consider mouse enter, leave, and move events as user
     25        interaction. Also, remove unneeded comments.
     26        (WebKit::PluginView::pluginDidReceiveUserInteraction): If this is the first time the function is
     27        called, tell the web process, so that the expiration timestamp can be updated.
     28
     29        * WebProcess/WebProcess.messages.in: Update the messages to include the expiration time.
     30        * WebProcess/WebProcess.h:
     31        (WebProcess): Update the cached copy of the auto-start origins to include their expiration
     32        timestamps. Update the message signatures. Add a function to update the expiration timestamp
     33        for a specific origin. Rename plugInAutoStartOriginsChanged to resetPlugInAutoStartOrigins.
     34        * WebProcess/WebProcess.cpp:
     35        (WebKit::WebProcess::initializeWebProcess): Instead of individually adding the origins in the
     36        provided vector, just call resetPlugInAutoStartOrigins().
     37        (WebKit::WebProcess::isPlugInAutoStartOrigin): Check to see if the origin is in the table, and if
     38        so, check the current time against the expiration time.
     39        (WebKit::WebProcess::didAddPlugInAutoStartOrigin): Update the cached table.
     40        (WebKit::WebProcess::resetPlugInAutoStartOrigins): Swap the tables between the provided parameter
     41        and the member variable. We can safely do this because the function is called in two cases where
     42        the parameter is afterwards thrown away: when a new web process is created, and when it is called
     43        through an IPC message.
     44        (WebKit::WebProcess::plugInDidReceiveUserInteraction): When invoked, we tell the UI process to
     45        update the expiration time for the given origin if the time difference between the expiration
     46        time and the current time is less than the threshold plugInAutoStartExpirationTimeUpdateThreshold.
     47
     48        * UIProcess/WebContext.messages.in: Add message that is called when the web process wants to
     49        update the expiration timestamp for the plug-in origin.
     50        * UIProcess/WebContext.cpp:
     51        (WebKit::WebContext::plugInDidReceiveUserInteraction): Forward to the provider.
     52        * UIProcess/WebContext.h:
     53
     54        * UIProcess/Plugins/PlugInAutoStartProvider.cpp:
     55        (WebKit::expirationTimeFromNow): Returns a new time based on the current time + 1 month.
     56        (WebKit::PlugInAutoStartProvider::addAutoStartOrigin): Refactor. Set the expiration time for the
     57        added origin.
     58        (WebKit::PlugInAutoStartProvider::autoStartOriginsCopy): Refactor.
     59        (WebKit::PlugInAutoStartProvider::autoStartOriginsTableCopy): Refactor to include the expiration
     60        times. Also, check the current time against the expiration time. If we are past the time, remove
     61        the entry from the copy.
     62        (WebKit::PlugInAutoStartProvider::setAutoStartOriginsTable): Refactor to extract and duplicate
     63        the provided map of origins and expiration timestamps.
     64        (WebKit::PlugInAutoStartProvider::didReceiveUserInteraction): Look for the origin hash. If found,
     65        update the expiration time. Update all existing web processes with the new expiration time, and
     66        tell the context client that the hashes have changed.
     67        * UIProcess/Plugins/PlugInAutoStartProvider.h:
     68        (PlugInAutoStartProvider): Change the m_autoStartHashes variable to a map of a hash to its domain
     69        entry in the auto-start table. It is used to cross-reference the auto-start table and update
     70        the origin's expiration time.
     71
     72        * Shared/WebProcessCreationParameters.h:
     73        (WebProcessCreationParameters): Switch the creation parameter to seed the origin table to a map.
     74
    1752013-01-03  Alexis Menard  <alexis@webkit.org>
    276
  • trunk/Source/WebKit2/Shared/WebProcessCreationParameters.h

    r138273 r138729  
    145145#endif
    146146
    147     Vector<unsigned> plugInAutoStartOrigins;
     147    HashMap<unsigned, double> plugInAutoStartOrigins;
    148148};
    149149
  • trunk/Source/WebKit2/UIProcess/Plugins/PlugInAutoStartProvider.cpp

    r138203 r138729  
    3333using namespace WebCore;
    3434
     35static const double plugInAutoStartExpirationTimeThreshold = 30 * 24 * 60;
     36
    3537namespace WebKit {
    3638
     
    3840    : m_context(context)
    3941{
     42}
     43
     44static double expirationTimeFromNow()
     45{
     46    return currentTime() + plugInAutoStartExpirationTimeThreshold;
    4047}
    4148
     
    4754    AutoStartTable::iterator it = m_autoStartTable.find(pageOrigin);
    4855    if (it == m_autoStartTable.end())
    49         it = m_autoStartTable.add(pageOrigin, HashSet<unsigned>()).iterator;
     56        it = m_autoStartTable.add(pageOrigin, HashMap<unsigned, double>()).iterator;
     57
     58    double expirationTime = expirationTimeFromNow();
     59    it->value.set(plugInOriginHash, expirationTime);
     60    m_autoStartHashes.set(plugInOriginHash, pageOrigin);
    5061   
    51     it->value.add(plugInOriginHash);
    52     m_autoStartHashes.add(plugInOriginHash);
    53     m_context->sendToAllProcesses(Messages::WebProcess::DidAddPlugInAutoStartOrigin(plugInOriginHash));
     62    m_context->sendToAllProcesses(Messages::WebProcess::DidAddPlugInAutoStartOrigin(plugInOriginHash, expirationTime));
    5463    m_context->client().plugInAutoStartOriginHashesChanged(m_context);
    5564}
    5665
    57 Vector<unsigned> PlugInAutoStartProvider::autoStartOriginsCopy() const
     66HashMap<unsigned, double> PlugInAutoStartProvider::autoStartOriginsCopy() const
    5867{
    59     Vector<unsigned> copyVector;
    60     copyToVector(m_autoStartHashes, copyVector);
    61     return copyVector;
     68    HashMap<unsigned, double> copyMap;
     69    AutoStartTable::const_iterator end = m_autoStartTable.end();
     70    for (AutoStartTable::const_iterator it = m_autoStartTable.begin(); it != end; ++it) {
     71        HashMap<unsigned, double>::const_iterator mapEnd = it->value.end();
     72        for (HashMap<unsigned, double>::const_iterator mapIt = it->value.begin(); mapIt != mapEnd; ++mapIt)
     73            copyMap.set(mapIt->key, mapIt->value);
     74    }
     75    return copyMap;
    6276}
    6377
     
    6680    ImmutableDictionary::MapType map;
    6781    AutoStartTable::const_iterator end = m_autoStartTable.end();
     82    double now = currentTime();
    6883    for (AutoStartTable::const_iterator it = m_autoStartTable.begin(); it != end; ++it) {
    69         Vector<RefPtr<APIObject> > hashes;
    70         HashSet<unsigned>::iterator valueEnd = it->value.end();
    71         for (HashSet<unsigned>::iterator valueIt = it->value.begin(); valueIt != valueEnd; ++valueIt)
    72             hashes.append(WebUInt64::create(*valueIt));
     84        ImmutableDictionary::MapType hashMap;
     85        HashMap<unsigned, double>::const_iterator valueEnd = it->value.end();
     86        for (HashMap<unsigned, double>::const_iterator valueIt = it->value.begin(); valueIt != valueEnd; ++valueIt) {
     87            if (now > valueIt->value)
     88                continue;
     89            hashMap.set(String::number(valueIt->key), WebDouble::create(valueIt->value));
     90        }
    7391
    74         map.set(it->key, ImmutableArray::adopt(hashes));
     92        if (hashMap.size())
     93            map.set(it->key, ImmutableDictionary::adopt(hashMap));
    7594    }
    7695
     
    82101    m_autoStartTable.clear();
    83102    m_autoStartHashes.clear();
    84     Vector<unsigned> hashVector;
     103    HashMap<unsigned, double> hashMap;
    85104
    86105    ImmutableDictionary::MapType::const_iterator end = table.map().end();
    87106    for (ImmutableDictionary::MapType::const_iterator it = table.map().begin(); it != end; ++it) {
    88         HashSet<unsigned> hashes;
    89         ImmutableArray* tableHashes = static_cast<ImmutableArray*>(it->value.get());
    90         size_t hashSetSize = tableHashes->size();
    91         for (size_t i = 0; i < hashSetSize; ++i) {
    92             unsigned hash = static_cast<unsigned>(tableHashes->at<WebUInt64>(i)->value());
    93             hashes.add(hash);
    94             m_autoStartHashes.add(hash);
    95             hashVector.append(hash);
     107        HashMap<unsigned, double> hashes;
     108        ImmutableDictionary* hashesForPage = static_cast<ImmutableDictionary*>(it->value.get());
     109        ImmutableDictionary::MapType::const_iterator hashEnd = hashesForPage->map().end();
     110        for (ImmutableDictionary::MapType::const_iterator hashIt = hashesForPage->map().begin(); hashIt != hashEnd; ++hashIt) {
     111            bool ok;
     112            unsigned hash = hashIt->key.toUInt(&ok);
     113            if (!ok)
     114                continue;
     115
     116            if (hashIt->value->type() != WebDouble::APIType)
     117                continue;
     118
     119            double expirationTime = static_cast<WebDouble*>(hashIt->value.get())->value();
     120            hashes.set(hash, expirationTime);
     121            hashMap.set(hash, expirationTime);
     122            m_autoStartHashes.set(hash, it->key);
    96123        }
    97124
    98         m_autoStartTable.add(it->key, hashes);
     125        m_autoStartTable.set(it->key, hashes);
    99126    }
    100127
    101     m_context->sendToAllProcesses(Messages::WebProcess::PlugInAutoStartOriginsChanged(hashVector));
     128    m_context->sendToAllProcesses(Messages::WebProcess::ResetPlugInAutoStartOrigins(hashMap));
     129}
     130
     131void PlugInAutoStartProvider::didReceiveUserInteraction(unsigned plugInOriginHash)
     132{
     133    HashMap<unsigned, String>::const_iterator it = m_autoStartHashes.find(plugInOriginHash);
     134    if (it == m_autoStartHashes.end()) {
     135        ASSERT_NOT_REACHED();
     136        return;
     137    }
     138
     139    double newExpirationTime = expirationTimeFromNow();
     140    m_autoStartTable.find(it->value)->value.set(plugInOriginHash, newExpirationTime);
     141    m_context->sendToAllProcesses(Messages::WebProcess::DidAddPlugInAutoStartOrigin(plugInOriginHash, newExpirationTime));
     142    m_context->client().plugInAutoStartOriginHashesChanged(m_context);
    102143}
    103144
  • trunk/Source/WebKit2/UIProcess/Plugins/PlugInAutoStartProvider.h

    r138203 r138729  
    4444    void addAutoStartOrigin(const String& pageOrigin, unsigned plugInOriginHash);
    4545
    46     Vector<unsigned> autoStartOriginsCopy() const;
     46    HashMap<unsigned, double> autoStartOriginsCopy() const;
    4747    PassRefPtr<ImmutableDictionary> autoStartOriginsTableCopy() const;
    4848    void setAutoStartOriginsTable(ImmutableDictionary&);
     49    void didReceiveUserInteraction(unsigned plugInOriginHash);
    4950
    5051private:
    5152    WebContext* m_context;
    5253   
    53     typedef HashMap<String, HashSet<unsigned>, CaseFoldingHash> AutoStartTable;
     54    typedef HashMap<String, HashMap<unsigned, double>, CaseFoldingHash> AutoStartTable;
    5455    AutoStartTable m_autoStartTable;
    55     HashSet<unsigned> m_autoStartHashes;
     56    HashMap<unsigned, String> m_autoStartHashes;
    5657};
    5758
  • trunk/Source/WebKit2/UIProcess/WebContext.cpp

    r138613 r138729  
    11441144}
    11451145
     1146void WebContext::plugInDidReceiveUserInteraction(unsigned plugInOriginHash)
     1147{
     1148    m_plugInAutoStartProvider.didReceiveUserInteraction(plugInOriginHash);
     1149}
     1150
    11461151PassRefPtr<ImmutableDictionary> WebContext::plugInAutoStartOriginHashes() const
    11471152{
  • trunk/Source/WebKit2/UIProcess/WebContext.h

    r138607 r138729  
    367367
    368368    void addPlugInAutoStartOriginHash(const String& pageOrigin, unsigned plugInOriginHash);
     369    void plugInDidReceiveUserInteraction(unsigned plugInOriginHash);
    369370
    370371    CoreIPC::MessageReceiverMap m_messageReceiverMap;
  • trunk/Source/WebKit2/UIProcess/WebContext.messages.in

    r137230 r138729  
    5555    # Plug-in messages.
    5656    void AddPlugInAutoStartOriginHash(WTF::String pageOrigin, uint32_t hash)
     57    void PlugInDidReceiveUserInteraction(uint32_t hash)
    5758}
  • trunk/Source/WebKit2/WebProcess/Plugins/PluginView.cpp

    r138461 r138729  
    276276    , m_pluginSnapshotTimer(this, &PluginView::pluginSnapshotTimerFired, pluginSnapshotTimerDelay)
    277277    , m_countSnapshotRetries(0)
     278    , m_didReceiveUserInteraction(false)
    278279    , m_pageScaleFactor(1)
    279280{
     
    811812        || (event->type() == eventNames().mousedownEvent && currentEvent->type() == WebEvent::MouseDown)
    812813        || (event->type() == eventNames().mouseupEvent && currentEvent->type() == WebEvent::MouseUp)) {
    813         // We have a mouse event.
    814 
    815814        // FIXME: Clicking in a scroll bar should not change focus.
    816815        if (currentEvent->type() == WebEvent::MouseDown) {
     
    821820
    822821        didHandleEvent = m_plugin->handleMouseEvent(static_cast<const WebMouseEvent&>(*currentEvent));
     822        if (event->type() != eventNames().mousemoveEvent)
     823            pluginDidReceiveUserInteraction();
    823824    } else if (event->type() == eventNames().mousewheelEvent && currentEvent->type() == WebEvent::Wheel && m_plugin->wantsWheelEvents()) {
    824         // We have a wheel event.
    825825        didHandleEvent = m_plugin->handleWheelEvent(static_cast<const WebWheelEvent&>(*currentEvent));
    826     } else if (event->type() == eventNames().mouseoverEvent && currentEvent->type() == WebEvent::MouseMove) {
    827         // We have a mouse enter event.
     826        pluginDidReceiveUserInteraction();
     827    } else if (event->type() == eventNames().mouseoverEvent && currentEvent->type() == WebEvent::MouseMove)
    828828        didHandleEvent = m_plugin->handleMouseEnterEvent(static_cast<const WebMouseEvent&>(*currentEvent));
    829     } else if (event->type() == eventNames().mouseoutEvent && currentEvent->type() == WebEvent::MouseMove) {
    830         // We have a mouse leave event.
     829    else if (event->type() == eventNames().mouseoutEvent && currentEvent->type() == WebEvent::MouseMove)
    831830        didHandleEvent = m_plugin->handleMouseLeaveEvent(static_cast<const WebMouseEvent&>(*currentEvent));
    832     } else if (event->type() == eventNames().contextmenuEvent && currentEvent->type() == WebEvent::MouseDown) {
    833         // We have a context menu event.
     831    else if (event->type() == eventNames().contextmenuEvent && currentEvent->type() == WebEvent::MouseDown) {
    834832        didHandleEvent = m_plugin->handleContextMenuEvent(static_cast<const WebMouseEvent&>(*currentEvent));
     833        pluginDidReceiveUserInteraction();
    835834    } else if ((event->type() == eventNames().keydownEvent && currentEvent->type() == WebEvent::KeyDown)
    836835               || (event->type() == eventNames().keyupEvent && currentEvent->type() == WebEvent::KeyUp)) {
    837         // We have a keyboard event.
    838836        didHandleEvent = m_plugin->handleKeyboardEvent(static_cast<const WebKeyboardEvent&>(*currentEvent));
     837        pluginDidReceiveUserInteraction();
    839838    }
    840839
     
    16091608}
    16101609
     1610void PluginView::pluginDidReceiveUserInteraction()
     1611{
     1612    if (m_didReceiveUserInteraction)
     1613        return;
     1614
     1615    m_didReceiveUserInteraction = true;
     1616    WebProcess::shared().plugInDidReceiveUserInteraction(m_pluginElement->plugInOriginHash());
     1617}
     1618
    16111619} // namespace WebKit
  • trunk/Source/WebKit2/WebProcess/Plugins/PluginView.h

    r138461 r138729  
    129129
    130130    void pluginSnapshotTimerFired(WebCore::DeferrableOneShotTimer<PluginView>*);
     131    void pluginDidReceiveUserInteraction();
    131132
    132133    // WebCore::PluginViewBase
     
    258259    WebCore::DeferrableOneShotTimer<PluginView> m_pluginSnapshotTimer;
    259260    unsigned m_countSnapshotRetries;
     261    bool m_didReceiveUserInteraction;
    260262
    261263    double m_pageScaleFactor;
  • trunk/Source/WebKit2/WebProcess/WebProcess.cpp

    r138683 r138729  
    7878#include <WebCore/Settings.h>
    7979#include <WebCore/StorageTracker.h>
     80#include <wtf/CurrentTime.h>
    8081#include <wtf/HashCountedSet.h>
    8182#include <wtf/PassRefPtr.h>
     
    123124using namespace JSC;
    124125using namespace WebCore;
     126
     127// This should be less than plugInAutoStartExpirationTimeThreshold in PlugInAutoStartProvider.
     128static const double plugInAutoStartExpirationTimeUpdateThreshold = 29 * 24 * 60;
    125129
    126130namespace WebKit {
     
    319323    setTerminationTimeout(parameters.terminationTimeout);
    320324
    321     for (size_t i = 0; i < parameters.plugInAutoStartOrigins.size(); ++i)
    322         didAddPlugInAutoStartOrigin(parameters.plugInAutoStartOrigins[i]);
     325    resetPlugInAutoStartOrigins(parameters.plugInAutoStartOrigins);
    323326}
    324327
     
    783786bool WebProcess::isPlugInAutoStartOrigin(unsigned plugInOriginHash)
    784787{
    785     return m_plugInAutoStartOrigins.contains(plugInOriginHash);
     788    HashMap<unsigned, double>::const_iterator it = m_plugInAutoStartOrigins.find(plugInOriginHash);
     789    if (it == m_plugInAutoStartOrigins.end())
     790        return false;
     791    return currentTime() < it->value;
    786792}
    787793
     
    796802}
    797803
    798 void WebProcess::didAddPlugInAutoStartOrigin(unsigned plugInOriginHash)
    799 {
    800     m_plugInAutoStartOrigins.add(plugInOriginHash);
    801 }
    802 
    803 void WebProcess::plugInAutoStartOriginsChanged(const Vector<unsigned>& hashes)
    804 {
    805     m_plugInAutoStartOrigins.clear();
    806     for (size_t i = 0; i < hashes.size(); ++i)
    807         didAddPlugInAutoStartOrigin(hashes[i]);
     804void WebProcess::didAddPlugInAutoStartOrigin(unsigned plugInOriginHash, double expirationTime)
     805{
     806    // When called, some web process (which also might be this one) added the origin for auto-starting,
     807    // or received user interaction.
     808    // Set the bit to avoid having redundantly call into the UI process upon user interaction.
     809    m_plugInAutoStartOrigins.set(plugInOriginHash, expirationTime);
     810}
     811
     812void WebProcess::resetPlugInAutoStartOrigins(const HashMap<unsigned, double>& hashes)
     813{
     814    m_plugInAutoStartOrigins.swap(const_cast<HashMap<unsigned, double>&>(hashes));
     815}
     816
     817void WebProcess::plugInDidReceiveUserInteraction(unsigned plugInOriginHash)
     818{
     819    if (!plugInOriginHash)
     820        return;
     821
     822    HashMap<unsigned, double>::iterator it = m_plugInAutoStartOrigins.find(plugInOriginHash);
     823    ASSERT(it != m_plugInAutoStartOrigins.end());
     824    if (it->value - currentTime() > plugInAutoStartExpirationTimeUpdateThreshold)
     825        return;
     826
     827    connection()->send(Messages::WebContext::PlugInDidReceiveUserInteraction(plugInOriginHash), 0);
    808828}
    809829
  • trunk/Source/WebKit2/WebProcess/WebProcess.h

    r138683 r138729  
    154154    bool isLinkVisited(WebCore::LinkHash) const;
    155155
    156     bool isPlugInAutoStartOrigin(unsigned plugInOriginhash);
     156    bool isPlugInAutoStartOrigin(unsigned plugInOriginHash);
    157157    void addPlugInAutoStartOrigin(const String& pageOrigin, unsigned plugInOriginHash);
     158    void plugInDidReceiveUserInteraction(unsigned plugInOriginHash);
    158159
    159160    bool fullKeyboardAccessEnabled() const { return m_fullKeyboardAccessEnabled; }
     
    239240    void allVisitedLinkStateChanged();
    240241
    241     void didAddPlugInAutoStartOrigin(unsigned plugInOriginHash);
    242     void plugInAutoStartOriginsChanged(const Vector<unsigned>& hashes);
     242    void didAddPlugInAutoStartOrigin(unsigned plugInOriginHash, double expirationTime);
     243    void resetPlugInAutoStartOrigins(const HashMap<unsigned, double>& hashes);
    243244
    244245    void platformSetCacheModel(CacheModel);
     
    322323    bool m_shouldTrackVisitedLinks;
    323324
    324     HashSet<unsigned> m_plugInAutoStartOrigins;
     325    HashMap<unsigned, double> m_plugInAutoStartOrigins;
    325326
    326327    bool m_hasSetCacheModel;
  • trunk/Source/WebKit2/WebProcess/WebProcess.messages.in

    r138533 r138729  
    7171    ClearPluginSiteData(Vector<WTF::String> pluginPaths, Vector<WTF::String> sites, uint64_t flags, uint64_t maxAgeInSeconds, uint64_t callbackID)
    7272#endif
    73     DidAddPlugInAutoStartOrigin(uint32_t hash)
    74     PlugInAutoStartOriginsChanged(Vector<uint32_t> hashes)
     73    DidAddPlugInAutoStartOrigin(uint32_t hash, double expirationTime)
     74    ResetPlugInAutoStartOrigins(HashMap<uint32_t,double> hashes)
    7575
    7676#if ENABLE(PLUGIN_PROCESS)
Note: See TracChangeset for help on using the changeset viewer.