@ -1,3 +1,4 @@
// » header
/* global addMessageListener, removeMessageListener, sendAsyncMessage */
/* global addMessageListener, removeMessageListener, sendAsyncMessage */
// for non background pages
// for non background pages
@ -51,8 +52,10 @@ var messagingConnector = function(response) {
var uniqueId = function ( ) {
var uniqueId = function ( ) {
return parseInt ( Math . random ( ) * 1e10 , 10 ) . toString ( 36 ) ;
return parseInt ( Math . random ( ) * 1e10 , 10 ) . toString ( 36 ) ;
} ;
} ;
// «
if ( self . chrome ) {
if ( self . chrome ) {
// » crx
vAPI . chrome = true ;
vAPI . chrome = true ;
vAPI . messaging = {
vAPI . messaging = {
port : null ,
port : null ,
@ -60,15 +63,14 @@ if (self.chrome) {
listeners : { } ,
listeners : { } ,
requestId : 0 ,
requestId : 0 ,
connectorId : uniqueId ( ) ,
connectorId : uniqueId ( ) ,
connector : messagingConnector ,
setup : function ( ) {
setup : function ( ) {
this . port = chrome . runtime . connect ( { name : this . connectorId } ) ;
this . port = chrome . runtime . connect ( { name : this . connectorId } ) ;
this . port . onMessage . addListener ( this . c onnector) ;
this . port . onMessage . addListener ( messagingC onnector) ;
} ,
} ,
close : function ( ) {
close : function ( ) {
if ( this . port ) {
if ( this . port ) {
this . port . disconnect ( ) ;
this . port . disconnect ( ) ;
this . port . onMessage . removeListener ( this . c onnector) ;
this . port . onMessage . removeListener ( messagingC onnector) ;
this . port = this . channels = this . listeners = this . connectorId = null ;
this . port = this . channels = this . listeners = this . connectorId = null ;
}
}
} ,
} ,
@ -105,7 +107,9 @@ if (self.chrome) {
return this . channels [ channelName ] ;
return this . channels [ channelName ] ;
}
}
} ;
} ;
// «
} else if ( self . safari ) {
} else if ( self . safari ) {
// » safariextz
vAPI . safari = true ;
vAPI . safari = true ;
// relevant?
// relevant?
@ -115,7 +119,6 @@ if (self.chrome) {
listeners : { } ,
listeners : { } ,
requestId : 0 ,
requestId : 0 ,
connectorId : uniqueId ( ) ,
connectorId : uniqueId ( ) ,
connector : messagingConnector ,
setup : function ( ) {
setup : function ( ) {
this . _connector = function ( msg ) {
this . _connector = function ( msg ) {
// messages from the background script are sent to every frame,
// messages from the background script are sent to every frame,
@ -123,7 +126,7 @@ if (self.chrome) {
// what is meant for the current context
// what is meant for the current context
if ( msg . name === vAPI . messaging . connectorId
if ( msg . name === vAPI . messaging . connectorId
|| msg . name === 'broadcast' ) {
|| msg . name === 'broadcast' ) {
vAPI. messaging . c onnector( msg . message ) ;
messagingC onnector( msg . message ) ;
}
}
} ;
} ;
safari . self . addEventListener ( 'message' , this . _connector , false ) ;
safari . self . addEventListener ( 'message' , this . _connector , false ) ;
@ -174,7 +177,7 @@ if (self.chrome) {
target : {
target : {
page : {
page : {
dispatchMessage : function ( name , msg ) {
dispatchMessage : function ( name , msg ) {
vAPI. messaging . c onnector( msg ) ;
messagingC onnector( msg ) ;
}
}
}
}
}
}
@ -371,6 +374,8 @@ if (self.chrome) {
url : window . location . href ,
url : window . location . href ,
type : 'main_frame'
type : 'main_frame'
} ) ;
} ) ;
// «
}
}
// » footer
} ) ( ) ;
} ) ( ) ;
// «