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):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@126113 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/dom/ContextFeatures.cpp b/Source/WebCore/dom/ContextFeatures.cpp
index 0f22730..13bbb38 100644
--- a/Source/WebCore/dom/ContextFeatures.cpp
+++ b/Source/WebCore/dom/ContextFeatures.cpp
@@ -111,6 +111,14 @@
 #endif
 }
 
+bool ContextFeatures::mutationEventsEnabled(Document* document)
+{
+    ASSERT(document);
+    if (!document)
+        return true;
+    return document->contextFeatures()->isEnabled(document, MutationEvents, true);
+}
+
 void provideContextFeaturesTo(Page* page, ContextFeaturesClient* client)
 {
     RefCountedSupplement<Page, ContextFeatures>::provideTo(page, ContextFeatures::supplementName(), ContextFeatures::create(client));