Chrome Plugin Development

Source: Internet
Author: User

This plugin is based on nativemessaging

CRX Package Content:

1. Manifest.json

{      "manifest_version": 2,  "name": "Demo",  "version": "1.0",  " Description ":" Simple Demo ",  " Browser_action ": {    " Default_icon ":" 13.png ",    "Default_title": "Simple Demo",    "Default_popup": "Popup.html"  },  "app" : {    "launch": {      "Local_path": "Popup.html"    }},  "Permissions" : ["Nativemessaging"]}  

2. popup.html

<Divstyle= "width:200px;">  <PID= "Label">A simple Demo</P>  <ButtonID= "Yes-button">Yes</Button></Div>  <Scripttype= "Text/javascript"src= "Script.js"></Script>

3. Script.js

 document.getElementById (' Yes-button '). AddEventListener (' click ', function   () { var  port =    Chrome.runtime.connectNative (' Com.google.chrome.demo '  function      () {Console.log ( "Disconnected"  "Hello, my_application" }); Port.onMessage.addListener ( function   (  Message, sender, Sendresponse) { var  strs =      Sendresponse;    Console.log ( "Received" +strs+ "" + message.text+ "" + json.stringify (message)); })});

Put the above 3 files and a picture into a folder, into the chrome://extensions/, click the developer mode, select, Package extension, you can package files in the folder into a CRX plug-in, in the plug-in, you can complete the installation, Just now Google requires the plugin to be downloaded by the App Store, so when you reopen Google Chrome, the plugin is automatically deactivated and can no longer be enabled.

Communication with EXE:

1. Host.json

{  "name": "Com.google.chrome.demo",  "description": "Native messaging API Host",  "path": "D:\\documents\\visual Studio 2008\\projectsgoogle\\googledemo\\release\\googledemo.exe",  "type": "Stdio",  "Allowed_origins": [    "chrome-extension:// agajdodbfodoocphplebagbgakgaodjj/"  ]}

Path: is the exe full path you want to invoke

Chrome-extension: Is the ID you just packaged CRX after installation, displayed on the interface

Name: Link Name

2. Host.reg

5.00 [hkey_current_user\software\google\chrome\nativemessaginghosts\com.google.chrome.demo]@=" d:\\360 Secure Browser Download \\host.json "

Create the registry key, Com.google.chrome.demo is the name in the Host.json file, and the item data is the path to the Host.json

Click on the Yes button to start the EXE, the above is the chrome plug-in to launch the local EXE program content

Here's what the EXE says: C + +

Creating a thread in the OnInitDialog function

HANDLE hthreadcom=CreateThread (NULL,        0,        (lpthread_start_routine) Commandthreadfunc ,        null,        0,        null);

HANDLE Hthreaddata=createthread (NULL,
0,
(Lpthread_start_routine) Datathreadfunc,
Null
0,
NULL);

Thread-handling functions

void Commandthreadfunc () {    char temp[];    StringStream STRs;      while (1)    {        int  ch;         if (ch = getchar ())! =EOF)        {            sprintf (temp,"%c", ch);            STRs<<temp;            OutputDebugString (Strs.str (). C_STR ());        }    }
}
voidDatathreadfunc () { while(1)    {        //Send to stdout//Define Our messageSTD::stringMessage ="{\ "text\": \ "This is a response message\"}"; //Collect The length of the messageUnsignedintLen =message.length (); //We need to send the 4 bytes of length informationStd::cout <<Char(((len>>0) &0xFF))            <<Char(((len>>8) &0xFF))            <<Char(((len>> -) &0xFF))            <<Char(((len>> -) &0xFF)); //Now we can output our messageStd::cout <<message; }}

Nativemessaging communication is based on the IO stream, using the GetChar () function to receive messages sent to the EXE

Now the problem is to receive EXE sent to the chrome plugin has a problem, not received, in the console can not see, do not know why? There is nativemessaging can not be in real-time communication, my demand is that the local EXE will always send data to Google Browser, basically 100-200 packets per second, drawing graphics on the browser, now still needs to be researched ....

Chrome Plugin Development

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.