 Chromium Code Reviews
 Chromium Code Reviews Issue 13799007:
  Support for selective DOM activity logging, based on IDL attributes.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/blink.git@master
    
  
    Issue 13799007:
  Support for selective DOM activity logging, based on IDL attributes.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/blink.git@master| Index: Source/bindings/scripts/CodeGeneratorV8.pm | 
| diff --git a/Source/bindings/scripts/CodeGeneratorV8.pm b/Source/bindings/scripts/CodeGeneratorV8.pm | 
| index a20ebee35e6498a1d9ac311491f47e7fb2cf761a..a6ad96e8615e1c21f5f67e864724bdf4124bc079 100644 | 
| --- a/Source/bindings/scripts/CodeGeneratorV8.pm | 
| +++ b/Source/bindings/scripts/CodeGeneratorV8.pm | 
| @@ -777,6 +777,26 @@ sub GenerateHeaderCustomCall | 
| } | 
| } | 
| +sub HasActivityLogging | 
| +{ | 
| + my $forMainWorldSuffix = shift; | 
| + my $attrExt = shift; | 
| + my $access = shift; | 
| + | 
| + if (!$attrExt->{"ActivityLog"}) { | 
| + return 0; | 
| + } | 
| + my $logAllAccess = ($attrExt->{"ActivityLog"} =~ /^Access/); | 
| + my $logGetter = ($attrExt->{"ActivityLog"} =~ /^Getter/); | 
| + my $logSetter = ($attrExt->{"ActivityLog"} =~ /^Setter/); | 
| + my $logOnlyIsolatedWorlds = ($attrExt->{"ActivityLog"} =~ /ForIsolatedWorlds$/); | 
| + | 
| + if ($logOnlyIsolatedWorlds && $forMainWorldSuffix eq "ForMainWorld") { | 
| + return 0; | 
| + } | 
| + return $logAllAccess || ($logGetter && $access eq "Getter") || ($logSetter && $access eq "Setter"); | 
| +} | 
| + | 
| sub IsConstructable | 
| { | 
| my $interface = shift; | 
| @@ -920,6 +940,46 @@ sub GenerateFeatureObservation | 
| return ""; | 
| } | 
| +sub GenerateActivityLogging | 
| +{ | 
| + my $accessType = shift; | 
| + my $interface = shift; | 
| + my $propertyName = shift; | 
| + | 
| + my $visibleInterfaceName = $codeGenerator->GetVisibleInterfaceName($interface); | 
| + | 
| + AddToImplIncludes("V8Binding.h"); | 
| + AddToImplIncludes("V8DOMActivityLogger.h"); | 
| + AddToImplIncludes("wtf/Vector.h"); | 
| + | 
| + my $content = ""; | 
| 
haraken
2013/04/11 00:59:16
Nit: Remove this.
 
ulfar
2013/04/11 03:25:15
Done.
 | 
| + if ($accessType eq "Method") { | 
| + push(@implContentInternals, <<END); | 
| + V8DOMActivityLogger* logger = V8PerContextData::from(v8::Context::GetCurrent())->activityLogger(); | 
| + if (logger) { | 
| + Vector<v8::Handle<v8::Value> > loggerArgs = toVectorOfArguments<v8::Handle<v8::Value> >(args); | 
| + logger->log("${visibleInterfaceName}.${propertyName}", args.Length(), loggerArgs.data(), "${accessType}"); | 
| + } | 
| +END | 
| + } elsif ($accessType eq "Setter") { | 
| + push(@implContentInternals, <<END); | 
| + V8DOMActivityLogger* logger = V8PerContextData::from(v8::Context::GetCurrent())->activityLogger(); | 
| + if (logger) { | 
| + v8::Handle<v8::Value> loggerArg[] = { value }; | 
| + logger->log("${visibleInterfaceName}.${propertyName}", 1, &loggerArg[0], "${accessType}"); | 
| + } | 
| +END | 
| + } elsif ($accessType eq "Getter") { | 
| + push(@implContentInternals, <<END); | 
| + V8DOMActivityLogger* logger = V8PerContextData::from(v8::Context::GetCurrent())->activityLogger(); | 
| + if (logger) | 
| + logger->log("${visibleInterfaceName}.${propertyName}", 0, 0, "${accessType}"); | 
| +END | 
| + } else { | 
| + die "Unrecognized activity logging access type"; | 
| + } | 
| +} | 
| + | 
| sub GenerateNormalAttrGetterCallback | 
| { | 
| my $attribute = shift; | 
| @@ -937,6 +997,9 @@ sub GenerateNormalAttrGetterCallback | 
| push(@implContentInternals, "static v8::Handle<v8::Value> ${attrName}AttrGetterCallback${forMainWorldSuffix}(v8::Local<v8::String> name, const v8::AccessorInfo& info)\n"); | 
| push(@implContentInternals, "{\n"); | 
| push(@implContentInternals, GenerateFeatureObservation($attrExt->{"MeasureAs"})); | 
| + if (HasActivityLogging($forMainWorldSuffix, $attrExt, "Getter")) { | 
| + GenerateActivityLogging("Getter", $interface, "${attrName}"); | 
| + } | 
| if (HasCustomGetter($attrExt)) { | 
| push(@implContentInternals, " return ${v8InterfaceName}::${attrName}AttrGetterCustom(name, info);\n"); | 
| } else { | 
| @@ -1227,6 +1290,9 @@ sub GenerateReplaceableAttrSetterCallback | 
| push(@implContentInternals, "static void ${interfaceName}ReplaceableAttrSetterCallback(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)\n"); | 
| push(@implContentInternals, "{\n"); | 
| push(@implContentInternals, GenerateFeatureObservation($interface->extendedAttributes->{"MeasureAs"})); | 
| + if (HasActivityLogging("", $interface->extendedAttributes, "Setter")) { | 
| + die "IDL error: ActivityLog attribute cannot exist on a ReplacableAttrSetterCallback"; | 
| + } | 
| push(@implContentInternals, " return ${interfaceName}V8Internal::${interfaceName}ReplaceableAttrSetter(name, value, info);\n"); | 
| push(@implContentInternals, "}\n\n"); | 
| } | 
| @@ -1292,6 +1358,9 @@ sub GenerateNormalAttrSetterCallback | 
| push(@implContentInternals, "static void ${attrName}AttrSetterCallback${forMainWorldSuffix}(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)\n"); | 
| push(@implContentInternals, "{\n"); | 
| push(@implContentInternals, GenerateFeatureObservation($attrExt->{"MeasureAs"})); | 
| + if (HasActivityLogging($forMainWorldSuffix, $attrExt, "Setter")) { | 
| + GenerateActivityLogging("Setter", $interface, "${attrName}"); | 
| + } | 
| if (HasCustomSetter($attrExt)) { | 
| push(@implContentInternals, " ${v8InterfaceName}::${attrName}AttrSetterCustom(name, value, info);\n"); | 
| } else { | 
| @@ -1632,6 +1701,9 @@ static v8::Handle<v8::Value> ${name}MethodCallback${forMainWorldSuffix}(const v8 | 
| { | 
| END | 
| push(@implContentInternals, GenerateFeatureObservation($function->signature->extendedAttributes->{"MeasureAs"})); | 
| + if (HasActivityLogging($forMainWorldSuffix, $function->signature->extendedAttributes, "Access")) { | 
| 
haraken
2013/04/11 00:59:16
Nit: "Access" => "Method" (Just for readability. T
 
ulfar
2013/04/11 03:25:15
I'd rather not, since this is a bit awkward.  Ther
 | 
| + GenerateActivityLogging("Method", $interface, "${name}"); | 
| + } | 
| if (HasCustomMethod($function->signature->extendedAttributes)) { | 
| push(@implContentInternals, " return ${v8InterfaceName}::${name}MethodCustom(args);\n"); | 
| } else { |