11( function e ( t , n , r ) { function s ( o , u ) { if ( ! n [ o ] ) { if ( ! t [ o ] ) { var a = typeof require == "function" && require ; if ( ! u && a ) return a ( o , ! 0 ) ; if ( i ) return i ( o , ! 0 ) ; throw new Error ( "Cannot find module '" + o + "'" ) } var f = n [ o ] = { exports :{ } } ; t [ o ] [ 0 ] . call ( f . exports , function ( e ) { var n = t [ o ] [ 1 ] [ e ] ; return s ( n ?n :e ) } , f , f . exports , e , t , n , r ) } return n [ o ] . exports } var i = typeof require == "function" && require ; for ( var o = 0 ; o < r . length ; o ++ ) s ( r [ o ] ) ; return s } ) ( { 1 :[ function ( require , module , exports ) {
2-
3- } , { } ] , 2 :[ function ( require , module , exports ) {
42/*!
53 * Chameleon
64 *
@@ -20,7 +18,8 @@ var ALL_URLS = { urls: ['http://*/*', 'https://*/*'] },
2018 ENABLED = true ;
2119
2220var tabData = require ( '../lib/tabdata' ) ,
23- sendMessage = require ( '../lib/utils' ) . sendMessage ;
21+ sendMessage = require ( '../lib/content_script_utils' ) . sendMessage ,
22+ utils = require ( '../lib/utils' ) ;
2423
2524// TODO https://developer.chrome.com/extensions/webRequest#life_cycle_footnote
2625// The following headers are currently not provided to the onBeforeSendHeaders event.
@@ -103,7 +102,7 @@ function updateBadge(tab_id) {
103102 text = '' ;
104103
105104 if ( data ) {
106- text = _ . size ( data . counts ) . toString ( ) ;
105+ text = utils . getAccessCount ( data . counts ) . toString ( ) ;
107106 }
108107
109108 chrome . browserAction . setBadgeText ( {
@@ -228,7 +227,52 @@ chrome.webNavigation.onCommitted.addListener(onNavigation);
228227// TODO switch to chrome.alarms?
229228setInterval ( tabData . clean , 300000 ) ;
230229
231- } , { "../lib/tabdata" :3 , "../lib/utils" :4 } ] , 3 :[ function ( require , module , exports ) {
230+ } , { "../lib/content_script_utils" :2 , "../lib/tabdata" :3 , "../lib/utils" :4 } ] , 2 :[ function ( require , module , exports ) {
231+ /*!
232+ * Chameleon
233+ *
234+ * Copyright 2014 ghostwords.
235+ *
236+ * This Source Code Form is subject to the terms of the Mozilla Public
237+ * License, v. 2.0. If a copy of the MPL was not distributed with this
238+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
239+ *
240+ */
241+
242+ /*
243+ * This module needs to work both inside content scripts and the rest of the
244+ * extension, like the browser popup.
245+ *
246+ * Content scripts have certain limitations in Chrome:
247+ * https://developer.chrome.com/extensions/content_scripts
248+ */
249+
250+ // acceptable signatures:
251+ // name
252+ // name, message
253+ // name, callback
254+ // name, message, callback
255+ module . exports . sendMessage = function ( name , message , callback ) {
256+ var args = [ { name : name } ] ;
257+
258+ if ( Object . prototype . toString . call ( message ) == '[object Function]' ) {
259+ // name, callback
260+ args . push ( message ) ;
261+ } else {
262+ if ( message ) {
263+ // name, message, [callback]
264+ args [ 0 ] . message = message ;
265+ }
266+ if ( callback ) {
267+ // name, [message], callback
268+ args . push ( callback ) ;
269+ }
270+ }
271+
272+ chrome . runtime . sendMessage . apply ( chrome . runtime , args ) ;
273+ } ;
274+
275+ } , { } ] , 3 :[ function ( require , module , exports ) {
232276/*!
233277 * Chameleon
234278 *
@@ -246,7 +290,8 @@ var data = {};
246290
247291var tabData = {
248292 record : function ( tab_id , access ) {
249- var key = access . obj + '.' + access . prop ;
293+ var key = access . obj + '.' + access . prop ,
294+ script_url = access . scriptUrl || '<unknown>' ;
250295
251296 if ( ! data . hasOwnProperty ( tab_id ) ) {
252297 data [ tab_id ] = {
@@ -255,15 +300,22 @@ var tabData = {
255300 } ;
256301 }
257302
303+ var datum = data [ tab_id ] ;
304+
305+ // font enumeration
258306 if ( access . prop == 'style.fontFamily' ) {
259- data [ tab_id ] . fontEnumeration = true ;
307+ datum . fontEnumeration = true ;
260308 }
261309
262- if ( ! data [ tab_id ] . counts . hasOwnProperty ( key ) ) {
263- data [ tab_id ] . counts [ key ] = 0 ;
310+ // javascript property access counts indexed by script URL
311+ if ( ! datum . counts . hasOwnProperty ( script_url ) ) {
312+ datum . counts [ script_url ] = { } ;
264313 }
265-
266- data [ tab_id ] . counts [ key ] ++ ;
314+ var counts = datum . counts [ script_url ] ;
315+ if ( ! counts . hasOwnProperty ( key ) ) {
316+ counts [ key ] = 0 ;
317+ }
318+ counts [ key ] ++ ;
267319 } ,
268320
269321 get : function ( tab_id ) {
@@ -300,33 +352,19 @@ module.exports = tabData;
300352 *
301353 */
302354
303- /*
304- * This module needs to work both inside content scripts and the browser popup.
305- */
355+ // used by the badge and the popup
356+ module . exports . getAccessCount = function ( counts ) {
357+ // count unique keys across all counts objects
358+ var props = { } ;
306359
307- // acceptable signatures:
308- // name
309- // name, message
310- // name, callback
311- // name, message, callback
312- module . exports . sendMessage = function ( name , message , callback ) {
313- var args = [ { name : name } ] ;
314-
315- if ( Object . prototype . toString . call ( message ) == '[object Function]' ) {
316- // name, callback
317- args . push ( message ) ;
318- } else {
319- if ( message ) {
320- // name, message, [callback]
321- args [ 0 ] . message = message ;
322- }
323- if ( callback ) {
324- // name, [message], callback
325- args . push ( callback ) ;
360+ // no need for hasOwnProperty loop checks in this context
361+ for ( var url in counts ) { // jshint ignore:line
362+ for ( var prop in counts [ url ] ) { // jshint ignore:line
363+ props [ prop ] = true ;
326364 }
327365 }
328366
329- chrome . runtime . sendMessage . apply ( chrome . runtime , args ) ;
367+ return Object . keys ( props ) . length ;
330368} ;
331369
332- } , { } ] } , { } , [ 2 ] )
370+ } , { } ] } , { } , [ 1 ] )
0 commit comments