webextension本机应用程序c ++ hello world

时间:2017-02-23 10:05:13

标签: javascript c++ firefox firefox-addon nativeapplication

我想在firefox上创建一个webextension,它与一个简单的c ++应用程序通信,我想向c ++应用程序发送一条消息,并收到一条简单的消息(例如Hello world)。

现在这就是我所做的:

manifest.json(webextension)

{
  "manifest_version": 2,
  "name": "nameofwebextension",
  "version": "1.0",

  "description": "test",
    "permissions": [
    "tabs",
    "activeTab",
    "downloads",
    "downloads.open",
    "nativeMessaging"
    ],
  "icons": {
    "48": "icons/border-48.png"
  },
  "content_scripts": [
  {
    "matches": ["http://www.testwebsite.com/*"],
    "js": ["content.js"]
  }
    ],
  "background": {
  "scripts": ["background.js"]
},
  "browser_action": {
    "default_icon": "icons/beasts-32.png",
    "default_title": "test",
    "default_popup": "popup/test.html",
    "browser_style": false
  },

    "applications": {
    "gecko": {
      "id": "name@example.org",
      "strict_min_version": "50.0"
    }
  }

}

background.js

var port = browser.runtime.connectNative("nameofapp");
console.log("Sending:  ping");
port.postMessage("ping");
port.onMessage.addListener((response) => {
  console.log("Received: " + response);
});

manifest.json(c ++ app)

{
  "name": "nameofapp",
  "description": "Example host for native messaging",
  "path": "bin/Debug/nameofapp.exe",
  "type": "stdio",
  "allowed_extensions": [ "name@example.org" ]
}

的main.cpp

#include <iostream>

using namespace std;

int main()
{
    cout << "Hello world!" << endl;
    //cin.get();
    return 0;
}

我还在注册表编辑器中创建了正确的密钥。

这是我进入浏览器控制台的内容:

Sending:  ping  
Native application tried to send a message of 1819043144 bytes, 
which exceeds the limit of 1048576 bytes.

1 个答案:

答案 0 :(得分:0)

我在这里找到答案:https://groups.google.com/a/chromium.org/forum/#!msg/chromium-extensions/Y5RckbPVnr8/xe5w9RC6O5sJ

let ar1: [[Int]] = [[1,2], [3, 4], [5, 6], [7, 8]]

let ar2: [[Int]] = [[2,4], [6,8],[10,12],[14,16]]

var ar3: [[Int]] = []

for i in 0...ar1.count-1 
       {

for j in 0...ar1.count-1 
{

ar3.append(ar1[i][j] + ar2 [i][j])

         }
}