@@ -428,6 +428,30 @@ var intervalCounter;
428428var intervalLog ;
429429var cbHandlers = { } ;
430430
431+ /**
432+ * Adds named callbacks to be executed when logging.
433+ * @param {Object } newCallbacks An object containing named callback functions.
434+ */
435+ function addCallbacks ( ) {
436+ for ( var _len = arguments . length , newCallbacks = new Array ( _len ) , _key = 0 ; _key < _len ; _key ++ ) {
437+ newCallbacks [ _key ] = arguments [ _key ] ;
438+ }
439+ newCallbacks . forEach ( function ( source ) {
440+ var descriptors = Object . keys ( source ) . reduce ( function ( descriptors , key ) {
441+ descriptors [ key ] = Object . getOwnPropertyDescriptor ( source , key ) ;
442+ return descriptors ;
443+ } , { } ) ;
444+ Object . getOwnPropertySymbols ( source ) . forEach ( function ( sym ) {
445+ var descriptor = Object . getOwnPropertyDescriptor ( source , sym ) ;
446+ if ( descriptor . enumerable ) {
447+ descriptors [ sym ] = descriptor ;
448+ }
449+ } ) ;
450+ Object . defineProperties ( cbHandlers , descriptors ) ;
451+ } ) ;
452+ return cbHandlers ;
453+ }
454+
431455/**
432456 * Assigns the config and log container to be used by the logging functions.
433457 * @param {Array } newLogs Log container.
@@ -1131,32 +1155,59 @@ var defaultConfig = {
11311155 authHeader : null ,
11321156 toolName : 'useralePlugin' ,
11331157 version : version
1158+ } ,
1159+ pluginConfig : {
1160+ // Default to a regex that will match no string
1161+ urlWhitelist : '(?!x)x'
11341162 }
11351163} ;
1136- browser . storage . local . get ( defaultConfig , function ( res ) {
1137- options ( res . useraleConfig ) ;
1138- } ) ;
1164+ var urlWhitelist ;
1165+ function updateConfig ( config ) {
1166+ console . log ( config ) ;
1167+ urlWhitelist = new RegExp ( config . pluginConfig . urlWhitelist ) ;
1168+ options ( config . useraleConfig ) ;
1169+ // TODO: tabs need a page load to apply this config change.
1170+ dispatchTabMessage ( config . useraleConfig ) ;
1171+ }
11391172function dispatchTabMessage ( message ) {
11401173 browser . tabs . query ( { } , function ( tabs ) {
11411174 tabs . forEach ( function ( tab ) {
11421175 browser . tabs . sendMessage ( tab . id , message ) ;
11431176 } ) ;
11441177 } ) ;
11451178}
1179+
1180+ // Filter out logs with urls that do not match the regex defined in extension options.
1181+ function filterUrl ( log ) {
1182+ if ( urlWhitelist . test ( log . pageUrl ) ) {
1183+ return log ;
1184+ }
1185+ return false ;
1186+ }
1187+ browser . storage . local . get ( defaultConfig , function ( res ) {
1188+ // Apply url filter to logs generated by the background page.
1189+ addCallbacks ( {
1190+ filterUrl : filterUrl
1191+ } ) ;
1192+ updateConfig ( res ) ;
1193+ } ) ;
11461194browser . runtime . onMessage . addListener ( function ( message , sender , sendResponse ) {
11471195 switch ( message . type ) {
1148- // Handles logs rerouted from content and option scripts
1196+ // Handles logs rerouted from content and option scripts.
11491197 case ADD_LOG :
11501198 var log$1 = message . payload ;
11511199 if ( "tab" in sender && "id" in sender . tab ) {
11521200 log$1 [ "tabId" ] = sender . tab . id ;
11531201 }
1154- log ( log$1 ) ;
1202+ // Apply url filter to logs generated outside the background page.
1203+ log$1 = filterUrl ( log$1 ) ;
1204+ if ( log$1 ) {
1205+ console . log ( "match" ) ;
1206+ log ( log$1 ) ;
1207+ }
11551208 break ;
11561209 case CONFIG_CHANGE :
1157- console . log ( message ) ;
1158- options ( message . payload ) ;
1159- dispatchTabMessage ( message ) ;
1210+ updateConfig ( message . payload ) ;
11601211 break ;
11611212 default :
11621213 console . log ( 'got unknown message type ' , message ) ;
0 commit comments