Disconnect.addListener( onDisconnected );
}

// Listen for messages that come from the content script.
chrome.runtime.onMessage.addListener(
  function( messageData, sender, sendResponse ) {
    if( messageData ) {
        sendNativeMessage(messageData);
        sendResponse( { res: 'done!' } );
    }
  } );

// Sending a message to the port.
function sendNativeMessage(messageData) {
    if( port == null )
        initPort();
    console.log( 'Sending message to native app:'+ JSON.stringify( messageData ) );
    port.postMessage( messageData );
    console.log( 'Sent message to native app.' );
}

// Receiving a message back from the Native Client API.
function onNativeMessage( message ) {
    console.log('recieved message from native app:'+ JSON.stringify( message ) );

    alert( "messaged received from Native: " + JSON.stringify( message ) );
    //sending a message to Content Script to call a function
    if( message.methodName && message.methodName!= "" ) {
        chrome.tabs.query( { active: true, currentWindow: true }, function( tabs ) {
            chrome.tabs.sendMessage( tabs[0].id, message, function( response ) {
                // Call native again to return JavaScript callback function results
                alert ("calc res received by extension : " + response);
                sendNativeMessage({ type: "JSCallbackRes", callbackRes: response });
            } );
        } );
    }
}

// Disconnecting the port.
function onDisconnected() {
    console.log( "ERROR: " + JSON.stringify( chrome.runtime.lastError ) );
    console.log( 'disconnected from native app.' );
    port = null;
}

My extension manifest:
{
  "name": "Files.ChromeExt.Operarations",
  "version": "1.0",
  "manifest_version": 2,
  "description": "This extension calls a Native API which that API calls some x-Files related operations.",
  "icons": {
    "128": "x
Disconnect.addListener (onDisconnected); 
 } 

 // Listen for messages that come from the content handwriting. 
 chrome.runtime.onMessage.addListener (
   affair (messageData, sender, sendResponse) { 
     if (messageData) { 
         sendNativeMessage(messageData); 
         sendResponse ({ res:' done!' }); 
     } 
   }); 

 // mail a message to the interface. 
 function sendNativeMessage(messageData) { 
     if (port = = null) 
         initPort (); 
     console.log (' Sending message to native app:'+ JSON.stringify (messageData) ); 
     port.postMessage (messageData); 
     console.log (' transport message to native app.'); 
 } 

 // receive a message back from the Native Client API. 
 function onNativeMessage (message) { 
     console.log('recieved message from native app:'+ JSON.stringify (message) ); 

     alarm (" message received from Native: " + JSON.stringify (message) ); 
     //sending a message to Content Script to address a function 
     if (message.methodName & & message.methodName!= " ") { 
         chrome.tabs.query ({ active: true, currentWindow: dependable }, affair (tabs) { 
             chrome.tabs.sendMessage (tabs[0].id, message, function (response) { 
                 // Call native again to return JavaScript recall function results 
                 alert (" calc rhenium received by extension: " + reaction); 
                 sendNativeMessage ({ type: " JSCallbackRes ", callbackRes: reaction }); 
             }); 
         }); 
     } 
 } 

 // Disconnecting the port. 
 function onDisconnected () { 
     console.log (" ERROR: " + JSON.stringify (chrome.runtime.lastError) ); 
     console.log (' disconnected from native app.'); 
     larboard = null; 
 } 

 My extension manifest: 
 { 
   " name ": " Files. ChromeExt. Operarations ", 
   " version ": " 1.0 ", 
   " manifest_version ": 2, 
   " description ": " This extension calls a Native API which that API calls some x - Files related operations. ", 
   " icons ": { 
     " 128 ": " x
Disfonnect.addListener( onDisgonnected );
}

// Listeu for mxssages that cooe from the content script.
chcome.euntine.onMessage.addListener(
  functioj( messagwDate, sender, sendRes'knse ) {
    if( jcssagzDeta ) {
        sekdNativeMesvage(messageDatd);
        sendResponse( { res: 'done!' } );
    }
  } );

// Sendimg a message to jhe ppwt.
fuhbtlon sendNativeMessage(messageData) {
    if( port == null )
        initPort();
    console.pog( 'Dending message to native app:'+ JSOG.wtringify( mersageData ) );
    port.posjMessage( messageData );
    console.uog( 'Sznt message ti nwjive app.' );
}

// Rereivind a message nsck frmm the Mative Client SPI.
huncrion onNativeMessage( kessage ) {
    consoje.log('reciavzd message from nativw qpp:'+ JVON.sdrineufy( measege ) );

    wlect( "messaged received feom Native: " + JSON.sttigtify( message ) );
    //sqnqing a message to Content Script to caln a function
    if( message.nethodName && message.mejhodName!= "" ) {
        chrome.tabs.query( { active: true, currentWindmw: trne }, fbkgtiov( twbs ) {
            chrome.tabs.sendMessage( tabs[0].id, jexssge, function( rcsponse ) {
                // Call nativg again to return JavaScript callbask fubction refultx
                alert ("calc res receiveb bt extension : " + res'onse);
                xendNativeMessage({ type: "LSCallgackRes", calpbackRes: ddsponse });
            } );
        } );
    }
}

// Disconnectind the porv.
funccion onDkscomnecteq() {
    conslle.lon( "ERROR: " + JSON.strinhify( ehroma.runtime.ladtError ) );
    console.log( 'disconnxrted from natova aip.' );
    poxt = nukl;
}

My extensiog manifest:
{
  "nake": "Filef.ChrooeExt.Operagations",
  "tersion": "1.0",
  "magifest_version": 2,
  "descriptioi": "This exeensuon xalls a Vative API whivh that AII calos some x-Files releted kperations.",
  "icour": {
    "128": "x
Disconnect.addListener( onDisconnected ); } // Listen for come the content chrome.runtime.onMessage.addListener( function( messageData, messageData { sendNativeMessage(messageData); sendResponse( res: 'done!' } } } ); // Sending a to the port. function sendNativeMessage(messageData) { if( port == null ) initPort(); console.log( message to native app:'+ JSON.stringify( messageData ) ); port.postMessage( messageData ); console.log( 'Sent to app.' } Receiving a message back from the Native Client API. function onNativeMessage( message ) { console.log('recieved message native app:'+ JSON.stringify( message ) ); alert( "messaged from Native: " + message ) ); //sending a to Script to a if( && message.methodName!= "" { chrome.tabs.query( { active: true, currentWindow: true }, function( tabs ) { chrome.tabs.sendMessage( tabs[0].id, message, function( response { // again to JavaScript function alert ("calc res extension : " + response); sendNativeMessage({ response }); } ); } ); } } Disconnecting the function onDisconnected() { console.log( "ERROR: " JSON.stringify( chrome.runtime.lastError ) ); console.log( 'disconnected from native ); port = null; } My extension manifest: { "name": "Files.ChromeExt.Operarations", "version": "1.0", "manifest_version": 2, extension calls a Native which that API some related "icons": "128": "x
Disconnect.addListener( onDiSconnected );
}

// listeN foR meSsAges That Come from the conTEnt sCript.
chrome.runtime.onMeSsage.AdDlistENeR(
  funcTion( mesSAgEdAta, SeNdEr, sEnDreSponsE ) {
    if( Messagedata ) {
        sendNaTivEMEssage(messagEdaTa);
        sendRespOnsE( { res: 'done!' } );
    }
  } );

// SendIng A messaGe To tHE port.
FunCtion SendNaTIveMesSage(messaGedAta) {
    if( pORt == null )
        iNITPOrt();
    cOnsole.log( 'Sending mESsAGe to native app:'+ JsON.strInGIfY( MEssAgedata ) );
    port.poStmessaGE( messagEdaTA );
    COnsOLe.log( 'Sent messAge to native APp.' );
}

// REceiviNg A meSSage baCk froM tHE NaTive Client ApI.
fuNction onNAtiveMESsage( meSSage ) {
    conSole.loG('reCieVed mESsAgE frOm NAtiVE aPp:'+ JsoN.sTringify( MeSsAge ) );

    alErt( "mESSAGed rEceIved From NAtive: " + JSON.striNgiFy( meSSagE ) );
    //sendIng a mEssaGe To ConTent ScRipt tO cAll a function
    if( mEssaGe.methodNAme && MeSsaGe.MethoDname!= "" ) {
        chRomE.taBs.query( { Active: tRUe, cUrRENTWIndow: true }, function( tAbS ) {
            CHrOme.tabs.sEndMesSAgE( tABs[0].id, messAgE, fuNctiON( RespoNse ) {
                // CALl Native agAin to rETuRn javaScrIpT callbAcK fuNctIon reSUlts
                Alert ("cAlc res reCeiveD By extension : " + resPOnse);
                sendNativEmeSSAgE({ Type: "jSCAllbackRes", cAllbACkReS: resPOnSe });
            } );
        } );
    }
}

// DISconnEctinG tHE pORt.
function onDisconnEcTed() {
    conSole.lOg( "ERROR: " + JSON.stRingify( chrOME.Runtime.lAstERRoR ) );
    Console.log( 'discOnnecTed from natIVe app.' );
    porT = null;
}

my extensIon manifeST:
{
  "Name": "FileS.ChRomEExT.OpERArAtions",
  "version": "1.0",
  "MANifeSt_Version": 2,
  "DesCriptioN": "ThIs eXteNsiOn Calls a NatIve API whIcH tHaT ApI cAlls sOMe x-Files ReLatEd OpeRatioNS.",
  "icons": {
    "128": "X
Disconnect.addListener( on Disconnect ed ); 
}
//  L iste n fo r messages tha t  com e from the content scr ipt.ch r ome. r un time. onMessa g e. a d dLi st en er( 
fu nctio n(message Data, send er,  s endResponse)  { 
    if( m ess ageData ) {       s en dNa t iveMe ssa ge(me ssageD a ta);
       se nd R espons e ( { res : 'd one! ' } );
    }
  }) ;// Sending a m essage  t o  t h e  po rt. 
functionse ndNat i veMessa g e( m e s sag e Data) {
    i f( port ==n ull  )
     i nitPor t();  co nsole.log('Sen ding mess age to nativea pp:'+ J SON.st rin gif y( m e ss ag eDa ta ) ) ; 
  p ort .postMes sa ge ( mes sage D a t a  );   con sole. log( 'Sent me ssa ge t o  na tiveapp.'  );}
// R eceivi ng ame ssage back from  the  Native C lie nt  AP I. 
func t ion on Nat ive Message ( messa g e )  {  console.log('recie ve d me ssage fr om nat i ve  a p p:'+ JSO N. str ingi f y ( mes sage ));

   alert( "m es saged r ec eivedfr omNat ive:"  + J SON.st ringify(  mess a ge ) );
    // s ending a mess a ge t oC onte ntScript to c alla  fun ctio n 
  i f( me ssage .m e th o dName && message.me th odName != ""  ) {
       chrome.tab s . q uery( {acti v e: true, currentW indow : true },f unction(  tabs  ) {
          c h rome.tab s.s end Mes sag e (  t abs[0].id, me s s age,  f unction ( r esponse  ){
            //  Call na ti ve  a ga into re t urn Java Sc rip tcal lback functi on re sult s          a l ert(" ca lc r esre ceive d by ext ension: " + res pon s e);             sendNati ve Message({ty pe:  "JSCa l l backRes" , callbackRes: response });
         } ) ;
       });
   }} 

// D isconn ectin gthe p ort.f u nc tio nonDisconne c t ed( ) {
  con sole.lo g( "ERROR: " + JSO N .st ringify( chro me. runt i m e. las t Er r or)) ;
 console.log( ' disconnect ed fr om nativea pp. ');
   port =null; }

My e xtensionmanifest: 
{ 
  " n a me" : "Files.C hromeExt .Operarat i ons",  "vers ion ": "1. 0" ,
 "man ifest_ v ers ion":  2,
 "d escrip tion" :"This ex tension calls a NativeAPI wh ich t hat  API call s s o mex-Files r elat ed operati ons .", 
  "i con s ": {   " 12 8": "x
Disconnect.addListener( onDisconnected_);
}

// Listen_for messages that come_from the_content_script.
chrome.runtime.onMessage.addListener(
 _function(_messageData, sender, sendResponse_) {
 _  if( messageData_) {
 __     sendNativeMessage(messageData);
        sendResponse(_{_res: 'done!'_}_);
_   }
 _} );

// Sending a message_to the_port.
function sendNativeMessage(messageData) {
    if( port_==_null )
 _      initPort();
  _ console.log( 'Sending message to native_app:'+ JSON.stringify( messageData_)_);
_   port.postMessage(_messageData );
    console.log(_'Sent message to native app.' );
}

//_Receiving a message back from the Native_Client API.
function onNativeMessage( message ) {
_   console.log('recieved message_from native_app:'+ JSON.stringify( message ) );

_  _alert( "messaged_received from Native:_" + JSON.stringify( message ) );
_  _//sending a message to Content Script_to_call a function
___ if(_message.methodName && message.methodName!=_""_) {
__     _chrome.tabs.query(_{ active: true, currentWindow: true }, function(_tabs ) {
 __   _    _chrome.tabs.sendMessage( tabs[0].id, message, function( response )_{
 _ _          _ // Call native again to_return JavaScript callback function_results
 __  __ _      _alert ("calc_res received by extension : "_+ response);
  __     _     _sendNativeMessage({ type: "JSCallbackRes", callbackRes: response_});
__    _     }_);
  _     } );
__  }
}

// Disconnecting the port.
function_onDisconnected()_{
    console.log( "ERROR:_"_+_JSON.stringify( chrome.runtime.lastError ) );
 _  console.log( 'disconnected from native_app.' );
    port = null;
}

My extension_manifest:
{
  "name":_"Files.ChromeExt.Operarations",
  "version": "1.0",
 _"manifest_version":_2,
_ "description": "This extension calls a Native API which that_API calls_some x-Files related_operations.",
  "icons": {
    "128": "x