Changeset 126113 in webkit


Ignore:
Timestamp:
Aug 20, 2012 6:14:51 PM (12 years ago)
Author:
adamk@chromium.org
Message:

Allow MutationEvents to be enabled/disabled per context
https://bugs.webkit.org/show_bug.cgi?id=94016

Reviewed by Ojan Vafai.

Source/WebCore:

Chromium wants to be able to turn MutationEvents off for some
Documents (e.g., for Apps V2). This patch makes the firing (and the
constructor on DOMWindow) of MutationEvents a per-context feature, with
the default being enabled.

No functional change (since the feature defaults to enabled).
It's not clear to me that there's a way to test this in DRT without
adding a special hook for this one feature. It will be tested in
Chromium once it's implemented in Chromium.

  • dom/ContextFeatures.cpp:

(WebCore::ContextFeatures::mutationEventsEnabled): Add new method,
with the default being enabled.

  • dom/ContextFeatures.h:
  • dom/Document.cpp:

(WebCore::Document::addMutationEventListenerTypeIfEnabled): Add new
method that checks the ContextFeature flag before adding the passed-in
listener type.
(WebCore::Document::addListenerTypeIfNeeded): Call the new method
instead of addListenerType for MutationEvent types.

  • dom/Document.h:

(WebCore::Document::addListenerType): Make private to avoid anyone
outside Document from enabling MutationEvent listeners. All callers
must go through addListenerTypeIfNeeded.

Source/WebKit/chromium:

Add Chromium/WebKit API for enabling/disabling MutationEvents via
WebPermissionClient.

  • public/WebPermissionClient.h:

(WebPermissionClient):
(WebKit::WebPermissionClient::allowMutationEvents):

  • src/ContextFeaturesClientImpl.cpp:

(WebKit::ContextFeaturesClientImpl::askIfIsEnabled):

Location:
trunk/Source
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r126110 r126113  
     12012-08-20  Adam Klein  <adamk@chromium.org>
     2
     3        Allow MutationEvents to be enabled/disabled per context
     4        https://bugs.webkit.org/show_bug.cgi?id=94016
     5
     6        Reviewed by Ojan Vafai.
     7
     8        Chromium wants to be able to turn MutationEvents off for some
     9        Documents (e.g., for Apps V2). This patch makes the firing (and the
     10        constructor on DOMWindow) of MutationEvents a per-context feature, with
     11        the default being enabled.
     12
     13        No functional change (since the feature defaults to enabled).
     14        It's not clear to me that there's a way to test this in DRT without
     15        adding a special hook for this one feature. It will be tested in
     16        Chromium once it's implemented in Chromium.
     17
     18        * dom/ContextFeatures.cpp:
     19        (WebCore::ContextFeatures::mutationEventsEnabled): Add new method,
     20        with the default being enabled.
     21        * dom/ContextFeatures.h:
     22        * dom/Document.cpp:
     23        (WebCore::Document::addMutationEventListenerTypeIfEnabled): Add new
     24        method that checks the ContextFeature flag before adding the passed-in
     25        listener type.
     26        (WebCore::Document::addListenerTypeIfNeeded): Call the new method
     27        instead of addListenerType for MutationEvent types.
     28        * dom/Document.h:
     29        (WebCore::Document::addListenerType): Make private to avoid anyone
     30        outside Document from enabling MutationEvent listeners. All callers
     31        must go through addListenerTypeIfNeeded.
     32
    1332012-08-20  Levi Weintraub  <leviw@chromium.org>
    234
  • trunk/Source/WebCore/dom/ContextFeatures.cpp

    r123535 r126113  
    112112}
    113113
     114bool ContextFeatures::mutationEventsEnabled(Document* document)
     115{
     116    ASSERT(document);
     117    if (!document)
     118        return true;
     119    return document->contextFeatures()->isEnabled(document, MutationEvents, true);
     120}
     121
    114122void provideContextFeaturesTo(Page* page, ContextFeaturesClient* client)
    115123{
  • trunk/Source/WebCore/dom/ContextFeatures.h

    r123535 r126113  
    4545        PagePopup,
    4646        HTMLNotifications,
     47        MutationEvents,
    4748        FeatureTypeSize // Should be the last entry.
    4849    };
     
    5758    static bool pagePopupEnabled(Document*);
    5859    static bool htmlNotificationsEnabled(Document*);
     60    static bool mutationEventsEnabled(Document*);
    5961
    6062    bool isEnabled(Document*, FeatureType, bool) const;
  • trunk/Source/WebCore/dom/Document.cpp

    r126080 r126113  
    41224122}
    41234123
     4124void Document::addMutationEventListenerTypeIfEnabled(ListenerType listenerType)
     4125{
     4126    if (ContextFeatures::mutationEventsEnabled(this))
     4127        addListenerType(listenerType);
     4128}
     4129
    41244130void Document::addListenerTypeIfNeeded(const AtomicString& eventType)
    41254131{
    41264132    if (eventType == eventNames().DOMSubtreeModifiedEvent)
    4127         addListenerType(DOMSUBTREEMODIFIED_LISTENER);
     4133        addMutationEventListenerTypeIfEnabled(DOMSUBTREEMODIFIED_LISTENER);
    41284134    else if (eventType == eventNames().DOMNodeInsertedEvent)
    4129         addListenerType(DOMNODEINSERTED_LISTENER);
     4135        addMutationEventListenerTypeIfEnabled(DOMNODEINSERTED_LISTENER);
    41304136    else if (eventType == eventNames().DOMNodeRemovedEvent)
    4131         addListenerType(DOMNODEREMOVED_LISTENER);
     4137        addMutationEventListenerTypeIfEnabled(DOMNODEREMOVED_LISTENER);
    41324138    else if (eventType == eventNames().DOMNodeRemovedFromDocumentEvent)
    4133         addListenerType(DOMNODEREMOVEDFROMDOCUMENT_LISTENER);
     4139        addMutationEventListenerTypeIfEnabled(DOMNODEREMOVEDFROMDOCUMENT_LISTENER);
    41344140    else if (eventType == eventNames().DOMNodeInsertedIntoDocumentEvent)
    4135         addListenerType(DOMNODEINSERTEDINTODOCUMENT_LISTENER);
     4141        addMutationEventListenerTypeIfEnabled(DOMNODEINSERTEDINTODOCUMENT_LISTENER);
    41364142    else if (eventType == eventNames().DOMAttrModifiedEvent)
    4137         addListenerType(DOMATTRMODIFIED_LISTENER);
     4143        addMutationEventListenerTypeIfEnabled(DOMATTRMODIFIED_LISTENER);
    41384144    else if (eventType == eventNames().DOMCharacterDataModifiedEvent)
    4139         addListenerType(DOMCHARACTERDATAMODIFIED_LISTENER);
     4145        addMutationEventListenerTypeIfEnabled(DOMCHARACTERDATAMODIFIED_LISTENER);
    41404146    else if (eventType == eventNames().overflowchangedEvent)
    41414147        addListenerType(OVERFLOWCHANGED_LISTENER);
  • trunk/Source/WebCore/dom/Document.h

    r126080 r126113  
    808808
    809809    bool hasListenerType(ListenerType listenerType) const { return (m_listenerTypes & listenerType); }
    810     void addListenerType(ListenerType listenerType) { m_listenerTypes = m_listenerTypes | listenerType; }
    811810    void addListenerTypeIfNeeded(const AtomicString& eventType);
    812811
     
    12681267    void setVisualUpdatesAllowed(bool);
    12691268    void visualUpdatesSuppressionTimerFired(Timer<Document>*);
     1269
     1270    void addListenerType(ListenerType listenerType) { m_listenerTypes |= listenerType; }
     1271    void addMutationEventListenerTypeIfEnabled(ListenerType);
    12701272
    12711273    int m_guardRefCount;
  • trunk/Source/WebKit/chromium/ChangeLog

    r126111 r126113  
     12012-08-20  Adam Klein  <adamk@chromium.org>
     2
     3        Allow MutationEvents to be enabled/disabled per context
     4        https://bugs.webkit.org/show_bug.cgi?id=94016
     5
     6        Reviewed by Ojan Vafai.
     7
     8        Add Chromium/WebKit API for enabling/disabling MutationEvents via
     9        WebPermissionClient.
     10
     11        * public/WebPermissionClient.h:
     12        (WebPermissionClient):
     13        (WebKit::WebPermissionClient::allowMutationEvents):
     14        * src/ContextFeaturesClientImpl.cpp:
     15        (WebKit::ContextFeaturesClientImpl::askIfIsEnabled):
     16
    1172012-08-20  Sheriff Bot  <webkit.review.bot@gmail.com>
    218
  • trunk/Source/WebKit/chromium/public/WebPermissionClient.h

    r123535 r126113  
    9797    virtual bool allowHTMLNotifications(const WebDocument&) { return true; }
    9898
     99    // Controls whether to enable MutationEvents for this document.
     100    // The common use case of this method is actually to selectively disable MutationEvents,
     101    // but it's been named for consistency with the rest of the interface.
     102    virtual bool allowMutationEvents(const WebDocument&, bool defaultValue) { return defaultValue; }
     103
    99104    // Notifies the client that the frame would have instantiated a plug-in if plug-ins were enabled.
    100105    virtual void didNotAllowPlugins(WebFrame*) { }
  • trunk/Source/WebKit/chromium/src/ContextFeaturesClientImpl.cpp

    r123535 r126113  
    146146    case ContextFeatures::HTMLNotifications:
    147147        return m_client->allowHTMLNotifications(WebDocument(document));
     148    case ContextFeatures::MutationEvents:
     149        return m_client->allowMutationEvents(WebDocument(document), defaultValue);
    148150    default:
    149151        return defaultValue;
Note: See TracChangeset for help on using the changeset viewer.