Title: [123535] trunk/Source
Revision
123535
Author
jia...@chromium.org
Date
2012-07-24 15:08:52 -0700 (Tue, 24 Jul 2012)

Log Message

Add per-context setting for html notifications
https://bugs.webkit.org/show_bug.cgi?id=91295

Reviewed by Adam Barth.

Source/WebCore:

Added a new per-context setting to control the enabling of html notifications.
For chromium port, we're going to disable html notifications for web
pages, but still keep it enabled for extensions.

Also enhance V8 code generator to support V8EnabledPerContext attribute
for methods.

Updated the binding tests.

* Modules/notifications/NotificationCenter.cpp:
(WebCore::NotificationCenter::document): Expose document for being used by installPerContextProperties.
(WebCore):
* Modules/notifications/NotificationCenter.h:
(NotificationCenter):
* Modules/notifications/NotificationCenter.idl: Add V8EnabledPerContext attribute.
* bindings/scripts/CodeGeneratorV8.pm: V8EnabledPerContext now supports methods.
(GenerateHeader):
(IsStandardFunction):
(GenerateNonStandardFunction):
(GenerateImplementation):
(GenerateToV8Converters):
(GetContextEnableFunction):
* bindings/scripts/test/TestObj.idl: Add test case for V8EnabledPerContext methods.
* bindings/scripts/test/V8/V8TestObj.cpp: Update test result.
(WebCore::TestObjV8Internal::enabledAtContextMethod1Callback):
(TestObjV8Internal):
(WebCore::TestObjV8Internal::enabledAtContextMethod2Callback):
(WebCore::V8TestObj::installPerContextProperties):
(WebCore::V8TestObj::wrapSlow):
* dom/ContextFeatures.cpp: Add a new per-context feature.
(WebCore::ContextFeatures::htmlNotificationsEnabled):
(WebCore):
* dom/ContextFeatures.h: Add a new per-context feature.

Source/WebKit/chromium:

Add new per-context feature for chromium port.

* public/WebPermissionClient.h:
(WebPermissionClient):
(WebKit::WebPermissionClient::allowHTMLNotifications):
* src/ContextFeaturesClientImpl.cpp:
(WebKit::ContextFeaturesClientImpl::askIfIsEnabled):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (123534 => 123535)


--- trunk/Source/WebCore/ChangeLog	2012-07-24 22:07:44 UTC (rev 123534)
+++ trunk/Source/WebCore/ChangeLog	2012-07-24 22:08:52 UTC (rev 123535)
@@ -1,3 +1,44 @@
+2012-07-24  Jian Li  <jia...@chromium.org>
+
+        Add per-context setting for html notifications
+        https://bugs.webkit.org/show_bug.cgi?id=91295
+
+        Reviewed by Adam Barth.
+
+        Added a new per-context setting to control the enabling of html notifications.
+        For chromium port, we're going to disable html notifications for web
+        pages, but still keep it enabled for extensions.
+
+        Also enhance V8 code generator to support V8EnabledPerContext attribute
+        for methods.
+
+        Updated the binding tests.
+
+        * Modules/notifications/NotificationCenter.cpp:
+        (WebCore::NotificationCenter::document): Expose document for being used by installPerContextProperties.
+        (WebCore):
+        * Modules/notifications/NotificationCenter.h:
+        (NotificationCenter):
+        * Modules/notifications/NotificationCenter.idl: Add V8EnabledPerContext attribute.
+        * bindings/scripts/CodeGeneratorV8.pm: V8EnabledPerContext now supports methods.
+        (GenerateHeader):
+        (IsStandardFunction):
+        (GenerateNonStandardFunction):
+        (GenerateImplementation):
+        (GenerateToV8Converters):
+        (GetContextEnableFunction):
+        * bindings/scripts/test/TestObj.idl: Add test case for V8EnabledPerContext methods.
+        * bindings/scripts/test/V8/V8TestObj.cpp: Update test result.
+        (WebCore::TestObjV8Internal::enabledAtContextMethod1Callback):
+        (TestObjV8Internal):
+        (WebCore::TestObjV8Internal::enabledAtContextMethod2Callback):
+        (WebCore::V8TestObj::installPerContextProperties):
+        (WebCore::V8TestObj::wrapSlow):
+        * dom/ContextFeatures.cpp: Add a new per-context feature.
+        (WebCore::ContextFeatures::htmlNotificationsEnabled):
+        (WebCore):
+        * dom/ContextFeatures.h: Add a new per-context feature.
+
 2012-07-24  Sheriff Bot  <webkit.review....@gmail.com>
 
         Unreviewed, rolling out r123499.

Modified: trunk/Source/WebCore/Modules/notifications/NotificationCenter.cpp (123534 => 123535)


--- trunk/Source/WebCore/Modules/notifications/NotificationCenter.cpp	2012-07-24 22:07:44 UTC (rev 123534)
+++ trunk/Source/WebCore/Modules/notifications/NotificationCenter.cpp	2012-07-24 22:08:52 UTC (rev 123535)
@@ -56,6 +56,13 @@
 }
 
 #if ENABLE(LEGACY_NOTIFICATIONS)
+Document* NotificationCenter::document() const {
+    ScriptExecutionContext* context = scriptExecutionContext();
+    return context->isDocument() ? static_cast<Document*>(context) : 0;
+}
+#endif
+
+#if ENABLE(LEGACY_NOTIFICATIONS)
 int NotificationCenter::checkPermission()
 {
     if (!client() || !scriptExecutionContext())

Modified: trunk/Source/WebCore/Modules/notifications/NotificationCenter.h (123534 => 123535)


--- trunk/Source/WebCore/Modules/notifications/NotificationCenter.h	2012-07-24 22:07:44 UTC (rev 123534)
+++ trunk/Source/WebCore/Modules/notifications/NotificationCenter.h	2012-07-24 22:08:52 UTC (rev 123535)
@@ -84,6 +84,7 @@
 #if ENABLE(LEGACY_NOTIFICATIONS)
     int checkPermission();
     void requestPermission(PassRefPtr<VoidCallback>);
+    Document* document() const;
 #endif
 
     virtual void stop() OVERRIDE;

Modified: trunk/Source/WebCore/Modules/notifications/NotificationCenter.idl (123534 => 123535)


--- trunk/Source/WebCore/Modules/notifications/NotificationCenter.idl	2012-07-24 22:07:44 UTC (rev 123534)
+++ trunk/Source/WebCore/Modules/notifications/NotificationCenter.idl	2012-07-24 22:08:52 UTC (rev 123535)
@@ -37,7 +37,7 @@
         OmitConstructor
     ] NotificationCenter {
 #if !defined(ENABLE_TEXT_NOTIFICATIONS_ONLY) || !ENABLE_TEXT_NOTIFICATIONS_ONLY
-       [V8Custom] Notification createHTMLNotification(in DOMString url) raises(DOMException);
+       [V8Custom, V8EnabledPerContext=htmlNotifications] Notification createHTMLNotification(in DOMString url) raises(DOMException);
 #endif
        [V8Custom] Notification createNotification(in DOMString iconUrl, in DOMString title, in DOMString body) raises(DOMException);
 

Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm (123534 => 123535)


--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm	2012-07-24 22:07:44 UTC (rev 123534)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm	2012-07-24 22:08:52 UTC (rev 123535)
@@ -422,6 +422,9 @@
 END
             push(@headerContent, "#endif // ${conditionalString}\n") if $conditionalString;
         }
+        if ($attrExt->{"V8EnabledPerContext"}) {
+            push(@enabledPerContext, $function);
+        }
     }
 
     if (IsConstructable($dataNode)) {
@@ -2187,6 +2190,7 @@
     return 0 if $attrExt->{"V8Unforgeable"};
     return 0 if $function->isStatic;
     return 0 if $attrExt->{"V8EnabledAtRuntime"};
+    return 0 if $attrExt->{"V8EnabledPerContext"};
     return 0 if RequiresCustomSignature($function);
     return 0 if $attrExt->{"V8DoNotCheckSignature"};
     return 0 if ($attrExt->{"DoNotCheckSecurity"} && ($dataNode->extendedAttributes->{"CheckSecurity"} || $interfaceName eq "DOMWindow"));
@@ -2228,6 +2232,11 @@
         my $enable_function = GetRuntimeEnableFunctionName($function->signature);
         $conditional = "if (${enable_function}())\n        ";
     }
+    if ($attrExt->{"V8EnabledPerContext"}) {
+        # Only call Set()/SetAccessor() if this method should be enabled
+        my $enable_function = GetContextEnableFunction($function->signature);
+        $conditional = "if (${enable_function}(impl->document()))\n        ";
+    }
 
     if ($attrExt->{"DoNotCheckSecurity"} &&
         ($dataNode->extendedAttributes->{"CheckSecurity"} || $interfaceName eq "DOMWindow")) {
@@ -2580,6 +2589,8 @@
 
     my $indexer;
     my $namedPropertyGetter;
+    my @enabledPerContextFunctions;
+    my @normalFunctions;
     # Generate methods for functions.
     foreach my $function (@{$dataNode->functions}) {
         my $isCustom = $function->signature->extendedAttributes->{"Custom"} || $function->signature->extendedAttributes->{"V8Custom"};
@@ -2606,6 +2617,13 @@
                 GenerateDomainSafeFunctionGetter($function, $implClassName);
             }
         }
+
+        # Separate out functions that are enabled per context so we can process them specially.
+        if ($function->signature->extendedAttributes->{"V8EnabledPerContext"}) {
+            push(@enabledPerContextFunctions, $function);
+        } else {
+            push(@normalFunctions, $function);
+        }
     }
 
     # Attributes
@@ -2615,22 +2633,22 @@
     # ones that disallows shadowing and the rest.
     my @disallowsShadowing;
     # Also separate out attributes that are enabled at runtime so we can process them specially.
-    my @enabledAtRuntime;
-    my @enabledPerContext;
-    my @normal;
+    my @enabledAtRuntimeAttributes;
+    my @enabledPerContextAttributes;
+    my @normalAttributes;
     foreach my $attribute (@$attributes) {
 
         if ($interfaceName eq "DOMWindow" && $attribute->signature->extendedAttributes->{"V8Unforgeable"}) {
             push(@disallowsShadowing, $attribute);
         } elsif ($attribute->signature->extendedAttributes->{"V8EnabledAtRuntime"}) {
-            push(@enabledAtRuntime, $attribute);
+            push(@enabledAtRuntimeAttributes, $attribute);
         } elsif ($attribute->signature->extendedAttributes->{"V8EnabledPerContext"}) {
-            push(@enabledPerContext, $attribute);
+            push(@enabledPerContextAttributes, $attribute);
         } else {
-            push(@normal, $attribute);
+            push(@normalAttributes, $attribute);
         }
     }
-    $attributes = \@normal;
+    $attributes = \@normalAttributes;
     # Put the attributes that disallow shadowing on the shadow object.
     if (@disallowsShadowing) {
         push(@implContent, "static const BatchedAttribute shadowAttrs[] = {\n");
@@ -2649,7 +2667,7 @@
     # Setup table of standard callback functions
     my $num_callbacks = 0;
     my $has_callbacks = 0;
-    foreach my $function (@{$dataNode->functions}) {
+    foreach my $function (@normalFunctions) {
         # Only one table entry is needed for overloaded methods:
         next if $function->{overloadIndex} > 1;
         # Don't put any nonstandard functions into this table:
@@ -2793,7 +2811,7 @@
 END
     }
 
-    if ($access_check or @enabledAtRuntime or @{$dataNode->functions} or $has_constants) {
+    if ($access_check or @enabledAtRuntimeAttributes or @normalFunctions or $has_constants) {
         push(@implContent,  <<END);
     v8::Local<v8::ObjectTemplate> instance = desc->InstanceTemplate();
     v8::Local<v8::ObjectTemplate> proto = desc->PrototypeTemplate();
@@ -2805,7 +2823,7 @@
     push(@implContent,  "    $access_check\n");
 
     # Setup the enable-at-runtime attrs if we have them
-    foreach my $runtime_attr (@enabledAtRuntime) {
+    foreach my $runtime_attr (@enabledAtRuntimeAttributes) {
         my $enable_function = GetRuntimeEnableFunctionName($runtime_attr->signature);
         my $conditionalString = $codeGenerator->GenerateConditionalString($runtime_attr->signature);
         push(@implContent, "\n#if ${conditionalString}\n") if $conditionalString;
@@ -2842,7 +2860,7 @@
 
     # Define our functions with Set() or SetAccessor()
     my $total_functions = 0;
-    foreach my $function (@{$dataNode->functions}) {
+    foreach my $function (@normalFunctions) {
         # Only one accessor is needed for overloaded methods:
         next if $function->{overloadIndex} > 1;
 
@@ -2931,7 +2949,7 @@
 
 END
 
-    if (@enabledPerContext) {
+    if (@enabledPerContextAttributes or @enabledPerContextFunctions) {
         push(@implContent, <<END);
 void ${className}::installPerContextProperties(v8::Handle<v8::Object> instance, ${implClassName}* impl)
 {
@@ -2939,21 +2957,46 @@
     // When building QtWebkit with V8 this variable is unused when none of the features are enabled.
     UNUSED_PARAM(proto);
 END
-        # Setup the enable-by-settings attrs if we have them
-        foreach my $runtimeAttr (@enabledPerContext) {
-            my $enableFunction = GetContextEnableFunction($runtimeAttr->signature);
-            my $conditionalString = $codeGenerator->GenerateConditionalString($runtimeAttr->signature);
-            push(@implContent, "\n#if ${conditionalString}\n") if $conditionalString;
-            push(@implContent, "    if (ContextFeatures::${enableFunction}(impl->document())) {\n");
-            push(@implContent, "        static const BatchedAttribute attrData =\\\n");
-            GenerateSingleBatchedAttribute($interfaceName, $runtimeAttr, ";", "    ");
-            push(@implContent, <<END);
+
+        if (@enabledPerContextAttributes) {
+            # Setup the enable-by-settings attrs if we have them
+            foreach my $runtimeAttr (@enabledPerContextAttributes) {
+                my $enableFunction = GetContextEnableFunction($runtimeAttr->signature);
+                my $conditionalString = $codeGenerator->GenerateConditionalString($runtimeAttr->signature);
+                push(@implContent, "\n#if ${conditionalString}\n") if $conditionalString;
+                push(@implContent, "    if (${enableFunction}(impl->document())) {\n");
+                push(@implContent, "        static const BatchedAttribute attrData =\\\n");
+                GenerateSingleBatchedAttribute($interfaceName, $runtimeAttr, ";", "    ");
+                push(@implContent, <<END);
         configureAttribute(instance, proto, attrData);
 END
-            push(@implContent, "    }\n");
-            push(@implContent, "#endif // ${conditionalString}\n") if $conditionalString;
+                push(@implContent, "    }\n");
+                push(@implContent, "#endif // ${conditionalString}\n") if $conditionalString;
+            }
         }
 
+        # Setup the enable-by-settings functions if we have them
+        if (@enabledPerContextFunctions) {
+            push(@implContent,  <<END);
+    v8::Local<v8::Signature> defaultSignature = v8::Signature::New(GetTemplate());
+    UNUSED_PARAM(defaultSignature); // In some cases, it will not be used.
+END
+
+            foreach my $runtimeFunc (@enabledPerContextFunctions) {
+                my $enableFunction = GetContextEnableFunction($runtimeFunc->signature);
+                my $conditionalString = $codeGenerator->GenerateConditionalString($runtimeFunc->signature);
+                push(@implContent, "\n#if ${conditionalString}\n") if $conditionalString;
+                push(@implContent, "    if (${enableFunction}(impl->document())) {\n");
+                my $name = $runtimeFunc->signature->name;
+                my $callback = GetFunctionTemplateCallbackName($runtimeFunc, $interfaceName);
+                push(@implContent, <<END);
+        proto->Set(v8::String::New("${name}"), v8::FunctionTemplate::New(${callback}, v8::Handle<v8::Value>(), defaultSignature)->GetFunction());
+END
+                push(@implContent, "    }\n");
+                push(@implContent, "#endif // ${conditionalString}\n") if $conditionalString;
+            }
+        }
+
         push(@implContent, <<END);
 }
 END
@@ -3307,7 +3350,22 @@
     push(@implContent, <<END);
     if (UNLIKELY(wrapper.IsEmpty()))
         return wrapper;
+END
 
+    my $hasEnabledPerContextFunctions = 0;
+    foreach my $function (@{$dataNode->functions}) {
+        if ($function->signature->extendedAttributes->{"V8EnabledPerContext"}) {
+            $hasEnabledPerContextFunctions = 1;
+        }
+    }
+    if ($hasEnabledPerContextFunctions) {
+        push(@implContent, <<END);
+    installPerContextProperties(wrapper, impl.get());
+END
+    }
+
+    push(@implContent, <<END);
+
     v8::Persistent<v8::Object> wrapperHandle = v8::Persistent<v8::Object>::New(wrapper);
 
     if (!hasDependentLifetime)
@@ -4084,12 +4142,12 @@
 
     # If a parameter is given (e.g. "V8EnabledPerContext=FeatureName") return the {FeatureName}Allowed() method.
     if ($signature->extendedAttributes->{"V8EnabledPerContext"} && $signature->extendedAttributes->{"V8EnabledPerContext"} ne "VALUE_IS_MISSING") {
-        return $codeGenerator->WK_lcfirst($signature->extendedAttributes->{"V8EnabledPerContext"}) . "Enabled";
+        return "ContextFeatures::" . $codeGenerator->WK_lcfirst($signature->extendedAttributes->{"V8EnabledPerContext"}) . "Enabled";
     }
 
     # Or it fallbacks to the attribute name if the parameter value is missing.
     my $attributeName = $signature->name;
-    return $codeGenerator->WK_lcfirst($attributeName) . "Enabled";
+    return "ContextFeatures::" . $codeGenerator->WK_lcfirst($attributeName) . "Enabled";
 }
 
 sub GetPassRefPtrType

Modified: trunk/Source/WebCore/bindings/scripts/test/TestObj.idl (123534 => 123535)


--- trunk/Source/WebCore/bindings/scripts/test/TestObj.idl	2012-07-24 22:07:44 UTC (rev 123534)
+++ trunk/Source/WebCore/bindings/scripts/test/TestObj.idl	2012-07-24 22:08:52 UTC (rev 123535)
@@ -193,9 +193,11 @@
         [V8EnabledAtRuntime=FeatureName] void enabledAtRuntimeMethod2(in int intArg);
         attribute [V8EnabledAtRuntime] long enabledAtRuntimeAttr1;
         attribute [V8EnabledAtRuntime=FeatureName] long enabledAtRuntimeAttr2;
-        // V8EnabledPerContext currently only supports attributes.
-        attribute [V8EnabledPerContext] long enabledAtContextAttr1;
-        attribute [V8EnabledPerContext=FeatureName] long enabledAtContextAttr2;
+        // 'V8EnabledPerContext' methods and attributes.
+        [V8EnabledPerContext] void enabledPerContextMethod1(in int intArg);
+        [V8EnabledPerContext=FeatureName] void enabledPerContextMethod2(in int intArg);
+        attribute [V8EnabledPerContext] long enabledPerContextAttr1;
+        attribute [V8EnabledPerContext=FeatureName] long enabledPerContextAttr2;
 #endif
 
 

Modified: trunk/Source/WebCore/bindings/scripts/test/V8/V8TestObj.cpp (123534 => 123535)


--- trunk/Source/WebCore/bindings/scripts/test/V8/V8TestObj.cpp	2012-07-24 22:07:44 UTC (rev 123534)
+++ trunk/Source/WebCore/bindings/scripts/test/V8/V8TestObj.cpp	2012-07-24 22:08:52 UTC (rev 123535)
@@ -862,35 +862,35 @@
     return;
 }
 
-static v8::Handle<v8::Value> enabledAtContextAttr1AttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
+static v8::Handle<v8::Value> enabledPerContextAttr1AttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
 {
-    INC_STATS("DOM.TestObj.enabledAtContextAttr1._get");
+    INC_STATS("DOM.TestObj.enabledPerContextAttr1._get");
     TestObj* imp = V8TestObj::toNative(info.Holder());
-    return v8Integer(imp->enabledAtContextAttr1(), info.GetIsolate());
+    return v8Integer(imp->enabledPerContextAttr1(), info.GetIsolate());
 }
 
-static void enabledAtContextAttr1AttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
+static void enabledPerContextAttr1AttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
 {
-    INC_STATS("DOM.TestObj.enabledAtContextAttr1._set");
+    INC_STATS("DOM.TestObj.enabledPerContextAttr1._set");
     TestObj* imp = V8TestObj::toNative(info.Holder());
     int v = toInt32(value);
-    imp->setEnabledAtContextAttr1(v);
+    imp->setEnabledPerContextAttr1(v);
     return;
 }
 
-static v8::Handle<v8::Value> enabledAtContextAttr2AttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
+static v8::Handle<v8::Value> enabledPerContextAttr2AttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
 {
-    INC_STATS("DOM.TestObj.enabledAtContextAttr2._get");
+    INC_STATS("DOM.TestObj.enabledPerContextAttr2._get");
     TestObj* imp = V8TestObj::toNative(info.Holder());
-    return v8Integer(imp->enabledAtContextAttr2(), info.GetIsolate());
+    return v8Integer(imp->enabledPerContextAttr2(), info.GetIsolate());
 }
 
-static void enabledAtContextAttr2AttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
+static void enabledPerContextAttr2AttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
 {
-    INC_STATS("DOM.TestObj.enabledAtContextAttr2._set");
+    INC_STATS("DOM.TestObj.enabledPerContextAttr2._set");
     TestObj* imp = V8TestObj::toNative(info.Holder());
     int v = toInt32(value);
-    imp->setEnabledAtContextAttr2(v);
+    imp->setEnabledPerContextAttr2(v);
     return;
 }
 
@@ -1731,6 +1731,28 @@
     return v8::Handle<v8::Value>();
 }
 
+static v8::Handle<v8::Value> enabledPerContextMethod1Callback(const v8::Arguments& args)
+{
+    INC_STATS("DOM.TestObj.enabledPerContextMethod1");
+    if (args.Length() < 1)
+        return V8Proxy::throwNotEnoughArgumentsError(args.GetIsolate());
+    TestObj* imp = V8TestObj::toNative(args.Holder());
+    EXCEPTION_BLOCK(int, intArg, V8int::HasInstance(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined)) ? V8int::toNative(v8::Handle<v8::Object>::Cast(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined))) : 0);
+    imp->enabledPerContextMethod1(intArg);
+    return v8::Handle<v8::Value>();
+}
+
+static v8::Handle<v8::Value> enabledPerContextMethod2Callback(const v8::Arguments& args)
+{
+    INC_STATS("DOM.TestObj.enabledPerContextMethod2");
+    if (args.Length() < 1)
+        return V8Proxy::throwNotEnoughArgumentsError(args.GetIsolate());
+    TestObj* imp = V8TestObj::toNative(args.Holder());
+    EXCEPTION_BLOCK(int, intArg, V8int::HasInstance(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined)) ? V8int::toNative(v8::Handle<v8::Object>::Cast(MAYBE_MISSING_PARAMETER(args, 0, DefaultIsUndefined))) : 0);
+    imp->enabledPerContextMethod2(intArg);
+    return v8::Handle<v8::Value>();
+}
+
 static v8::Handle<v8::Value> stringArrayFunctionCallback(const v8::Arguments& args)
 {
     INC_STATS("DOM.TestObj.stringArrayFunction");
@@ -2238,18 +2260,26 @@
     v8::Local<v8::Object> proto = v8::Local<v8::Object>::Cast(instance->GetPrototype());
     // When building QtWebkit with V8 this variable is unused when none of the features are enabled.
     UNUSED_PARAM(proto);
-    if (ContextFeatures::enabledAtContextAttr1Enabled(impl->document())) {
+    if (ContextFeatures::enabledPerContextAttr1Enabled(impl->document())) {
         static const BatchedAttribute attrData =\
-        // Attribute 'enabledAtContextAttr1' (Type: 'attribute' ExtAttr: 'V8EnabledPerContext')
-        {"enabledAtContextAttr1", TestObjV8Internal::enabledAtContextAttr1AttrGetter, TestObjV8Internal::enabledAtContextAttr1AttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */};
+        // Attribute 'enabledPerContextAttr1' (Type: 'attribute' ExtAttr: 'V8EnabledPerContext')
+        {"enabledPerContextAttr1", TestObjV8Internal::enabledPerContextAttr1AttrGetter, TestObjV8Internal::enabledPerContextAttr1AttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */};
         configureAttribute(instance, proto, attrData);
     }
     if (ContextFeatures::featureNameEnabled(impl->document())) {
         static const BatchedAttribute attrData =\
-        // Attribute 'enabledAtContextAttr2' (Type: 'attribute' ExtAttr: 'V8EnabledPerContext')
-        {"enabledAtContextAttr2", TestObjV8Internal::enabledAtContextAttr2AttrGetter, TestObjV8Internal::enabledAtContextAttr2AttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */};
+        // Attribute 'enabledPerContextAttr2' (Type: 'attribute' ExtAttr: 'V8EnabledPerContext')
+        {"enabledPerContextAttr2", TestObjV8Internal::enabledPerContextAttr2AttrGetter, TestObjV8Internal::enabledPerContextAttr2AttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */};
         configureAttribute(instance, proto, attrData);
     }
+    v8::Local<v8::Signature> defaultSignature = v8::Signature::New(GetTemplate());
+    UNUSED_PARAM(defaultSignature); // In some cases, it will not be used.
+    if (ContextFeatures::enabledPerContextMethod1Enabled(impl->document())) {
+        proto->Set(v8::String::New("enabledPerContextMethod1"), v8::FunctionTemplate::New(TestObjV8Internal::enabledPerContextMethod1Callback, v8::Handle<v8::Value>(), defaultSignature)->GetFunction());
+    }
+    if (ContextFeatures::featureNameEnabled(impl->document())) {
+        proto->Set(v8::String::New("enabledPerContextMethod2"), v8::FunctionTemplate::New(TestObjV8Internal::enabledPerContextMethod2Callback, v8::Handle<v8::Value>(), defaultSignature)->GetFunction());
+    }
 }
 
 v8::Handle<v8::Object> V8TestObj::wrapSlow(PassRefPtr<TestObj> impl, v8::Isolate* isolate)
@@ -2259,6 +2289,7 @@
     wrapper = V8DOMWrapper::instantiateV8Object(proxy, &info, impl.get());
     if (UNLIKELY(wrapper.IsEmpty()))
         return wrapper;
+    installPerContextProperties(wrapper, impl.get());
 
     v8::Persistent<v8::Object> wrapperHandle = v8::Persistent<v8::Object>::New(wrapper);
 

Modified: trunk/Source/WebCore/dom/ContextFeatures.cpp (123534 => 123535)


--- trunk/Source/WebCore/dom/ContextFeatures.cpp	2012-07-24 22:07:44 UTC (rev 123534)
+++ trunk/Source/WebCore/dom/ContextFeatures.cpp	2012-07-24 22:08:52 UTC (rev 123535)
@@ -99,6 +99,18 @@
 #endif
 }
 
+bool ContextFeatures::htmlNotificationsEnabled(Document* document)
+{
+#if ENABLE(LEGACY_NOTIFICATIONS)
+    if (!document)
+        return false;
+    return document->contextFeatures()->isEnabled(document, HTMLNotifications, false);
+#else
+    UNUSED_PARAM(document);
+    return false;
+#endif
+}
+
 void provideContextFeaturesTo(Page* page, ContextFeaturesClient* client)
 {
     RefCountedSupplement<Page, ContextFeatures>::provideTo(page, ContextFeatures::supplementName(), ContextFeatures::create(client));

Modified: trunk/Source/WebCore/dom/ContextFeatures.h (123534 => 123535)


--- trunk/Source/WebCore/dom/ContextFeatures.h	2012-07-24 22:07:44 UTC (rev 123534)
+++ trunk/Source/WebCore/dom/ContextFeatures.h	2012-07-24 22:08:52 UTC (rev 123535)
@@ -43,6 +43,7 @@
         ShadowDOM,
         StyleScoped,
         PagePopup,
+        HTMLNotifications,
         FeatureTypeSize // Should be the last entry.
     };
 
@@ -54,6 +55,7 @@
     static bool shadowDOMEnabled(Document*);
     static bool styleScopedEnabled(Document*);
     static bool pagePopupEnabled(Document*);
+    static bool htmlNotificationsEnabled(Document*);
 
     bool isEnabled(Document*, FeatureType, bool) const;
     void urlDidChange(Document*);

Modified: trunk/Source/WebKit/chromium/ChangeLog (123534 => 123535)


--- trunk/Source/WebKit/chromium/ChangeLog	2012-07-24 22:07:44 UTC (rev 123534)
+++ trunk/Source/WebKit/chromium/ChangeLog	2012-07-24 22:08:52 UTC (rev 123535)
@@ -1,3 +1,18 @@
+2012-07-24  Jian Li  <jia...@chromium.org>
+
+        Add per-context setting for html notifications
+        https://bugs.webkit.org/show_bug.cgi?id=91295
+
+        Reviewed by Adam Barth.
+
+        Add new per-context feature for chromium port.
+
+        * public/WebPermissionClient.h:
+        (WebPermissionClient):
+        (WebKit::WebPermissionClient::allowHTMLNotifications):
+        * src/ContextFeaturesClientImpl.cpp:
+        (WebKit::ContextFeaturesClientImpl::askIfIsEnabled):
+
 2012-07-24  Sheriff Bot  <webkit.review....@gmail.com>
 
         Unreviewed, rolling out r123499.

Modified: trunk/Source/WebKit/chromium/public/WebPermissionClient.h (123534 => 123535)


--- trunk/Source/WebKit/chromium/public/WebPermissionClient.h	2012-07-24 22:07:44 UTC (rev 123534)
+++ trunk/Source/WebKit/chromium/public/WebPermissionClient.h	2012-07-24 22:08:52 UTC (rev 123535)
@@ -93,6 +93,9 @@
     // Controls whether enabling Web Components API for this frame.
     virtual bool allowWebComponents(const WebDocument&, bool defaultValue) { return defaultValue; }
 
+    // Controls whether enabling HTML notifications for this frame.
+    virtual bool allowHTMLNotifications(const WebDocument&) { return true; }
+
     // Notifies the client that the frame would have instantiated a plug-in if plug-ins were enabled.
     virtual void didNotAllowPlugins(WebFrame*) { }
 

Modified: trunk/Source/WebKit/chromium/src/ContextFeaturesClientImpl.cpp (123534 => 123535)


--- trunk/Source/WebKit/chromium/src/ContextFeaturesClientImpl.cpp	2012-07-24 22:07:44 UTC (rev 123534)
+++ trunk/Source/WebKit/chromium/src/ContextFeaturesClientImpl.cpp	2012-07-24 22:08:52 UTC (rev 123535)
@@ -143,6 +143,8 @@
     case ContextFeatures::ShadowDOM:
     case ContextFeatures::StyleScoped:
         return m_client->allowWebComponents(WebDocument(document), defaultValue);
+    case ContextFeatures::HTMLNotifications:
+        return m_client->allowHTMLNotifications(WebDocument(document));
     default:
         return defaultValue;
     }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to