gecko中的js扩展
1 创建js对象对应的idl文件
假设要扩展一个hiGecko对象,那么先创建一个idl文件,命名为nsIDOMHiGecko.idl,它的内容如下
<!DOCTYPE html><html> <head> <meta charset="utf-8"> <meta name="viewport" http-equiv="pragma"> <title>Cut The Rope</title> </head> <body> <script> window.self.console.log("************ok************"); window.hiGecko.myval = 34; window.console.log(window.hiGecko.myval); window.console.log(window.hiGecko.getIsOK()); </script> </body></html>运行webruntime,在终端执行adb logcat | grep -E "^E"
如果能找到下面一段日志,证明扩展成功
E/GeckoConsole(16685): Content JS LOG at file:///sdcard/index.html:10 in anonymous: ************ok************
E/GeckoConsole(16685): Content JS LOG at file:///sdcard/index.html:12 in anonymous: 34
E/GeckoConsole(16685): Content JS LOG at file:///sdcard/index.html:13 in anonymous: true