├── IOS ├── Example Apps │ ├── ExampleApp-OSX │ │ ├── en.lproj │ │ │ ├── InfoPlist.strings │ │ │ └── Credits.rtf │ │ ├── ExampleApp-OSX-Prefix.pch │ │ ├── main.m │ │ ├── AppDelegate.h │ │ ├── ExampleApp-OSX-Info.plist │ │ └── AppDelegate.m │ ├── ExampleApp-iOS │ │ ├── en.lproj │ │ │ └── InfoPlist.strings │ │ ├── Default-568h@2x.png │ │ ├── main.m │ │ ├── ExampleApp-iOS-Prefix.pch │ │ ├── ExampleAppDelegate.h │ │ ├── ExampleApp-iOS-Info.plist │ │ └── ExampleAppDelegate.m │ ├── ExampleApp.html │ ├── ExampleApp-iOS.xcodeproj │ │ └── project.pbxproj │ └── ExampleApp-OSX.xcodeproj │ │ └── project.pbxproj ├── WebViewJavascriptBridge.podspec ├── LICENSE ├── WebViewJavascriptBridge │ ├── WebViewJavascriptBridge.h │ └── WebViewJavascriptBridge.js.txt ├── Changelog └── README.md ├── Chrome ├── Example │ └── simple_extension │ │ ├── clock.png │ │ ├── manifest.json │ │ ├── user_server.js │ │ ├── user_client.js │ │ ├── bridgeClientChrome.js │ │ └── bridgeServerChrome.js └── js │ ├── bridgeClientChrome.js │ └── bridgeServerChrome.js ├── problem.txt ├── .gitignore ├── Android ├── Example │ ├── res │ │ ├── values │ │ │ └── strings.xml │ │ ├── layout │ │ │ └── main.xml │ │ └── raw │ │ │ ├── user_client.html │ │ │ └── WebViewJavascriptBridge.js │ ├── project.properties │ ├── Example.iml │ ├── AndroidManifest.xml │ ├── ant.properties │ ├── WebViewJavascriptBridgeExample.iml │ ├── proguard-project.txt │ ├── design │ │ ├── iosdesign.txt │ │ └── design.txt │ ├── src │ │ └── com │ │ │ ├── example │ │ │ └── WebViewJavascriptBridgeExample │ │ │ │ └── MyActivity.java │ │ │ └── fangjian │ │ │ └── WebViewJavascriptBridge.java │ ├── .gitignore │ └── build.xml ├── ExampleWithWebViewMap │ ├── res │ │ ├── values │ │ │ └── strings.xml │ │ ├── raw │ │ │ ├── user_client.html │ │ │ └── webviewjavascriptbridge.js │ │ └── layout │ │ │ └── main.xml │ ├── assets │ │ └── map │ │ │ ├── mapbox │ │ │ ├── images │ │ │ │ ├── icons-000000.png │ │ │ │ ├── icons-ffffff.png │ │ │ │ ├── icons-000000@2x.png │ │ │ │ ├── icons-ffffff@2x.png │ │ │ │ └── render.sh │ │ │ └── mapbox.css │ │ │ ├── leaflet-0.7.2 │ │ │ ├── images │ │ │ │ ├── layers.png │ │ │ │ ├── layers-2x.png │ │ │ │ ├── marker-icon.png │ │ │ │ ├── marker-icon-2x.png │ │ │ │ └── marker-shadow.png │ │ │ └── leaflet.css │ │ │ ├── poi.json │ │ │ ├── area.json │ │ │ ├── map.html │ │ │ └── map.json │ ├── project.properties │ ├── Example.iml │ ├── ant.properties │ ├── AndroidManifest.xml │ ├── WebViewJavascriptBridgeExample.iml │ ├── proguard-project.txt │ ├── design │ │ ├── iosdesign.txt │ │ └── design.txt │ ├── src │ │ └── com │ │ │ ├── example │ │ │ └── WebViewJavascriptBridgeExample │ │ │ │ └── MyActivity.java │ │ │ └── fangjian │ │ │ └── WebViewJavascriptBridge.java │ ├── .gitignore │ └── build.xml └── WebViewJavascriptBridge │ ├── res │ └── raw │ │ └── webviewjavascriptbridge.js │ └── src │ └── com │ └── fangjian │ └── WebViewJavascriptBridge.java ├── Html ├── Example │ ├── multi_js │ │ ├── example.html │ │ ├── user_server.js │ │ ├── user_client.js │ │ ├── bridgeServerHtml.js │ │ └── bridgeClientHtml.js │ └── single_page.html └── js │ ├── bridgeServerHtml.js │ └── bridgeClientHtml.js └── README.md /IOS/Example Apps/ExampleApp-OSX/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /IOS/Example Apps/ExampleApp-iOS/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /Chrome/Example/simple_extension/clock.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiXing/WebViewJavascriptBridge/HEAD/Chrome/Example/simple_extension/clock.png -------------------------------------------------------------------------------- /IOS/Example Apps/ExampleApp-iOS/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiXing/WebViewJavascriptBridge/HEAD/IOS/Example Apps/ExampleApp-iOS/Default-568h@2x.png -------------------------------------------------------------------------------- /problem.txt: -------------------------------------------------------------------------------- 1 | handler(message.data, responseCallback) 2 | responseCallback always exist , but if the other end do not have a callback, call responseCallback cause exception. 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Mac OS X 2 | *.DS_Store 3 | 4 | # Xcode 5 | *.pbxuser 6 | *.mode1v3 7 | *.mode2v3 8 | *.perspectivev3 9 | *.xcuserstate 10 | *.xcworkspace/ 11 | xcuserdata/ 12 | -------------------------------------------------------------------------------- /Android/Example/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | WebViewJavascriptBridgeExample 4 | 5 | -------------------------------------------------------------------------------- /Android/ExampleWithWebViewMap/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | WebViewJavascriptBridgeExample 4 | 5 | -------------------------------------------------------------------------------- /Android/ExampleWithWebViewMap/assets/map/mapbox/images/icons-000000.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiXing/WebViewJavascriptBridge/HEAD/Android/ExampleWithWebViewMap/assets/map/mapbox/images/icons-000000.png -------------------------------------------------------------------------------- /Android/ExampleWithWebViewMap/assets/map/mapbox/images/icons-ffffff.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiXing/WebViewJavascriptBridge/HEAD/Android/ExampleWithWebViewMap/assets/map/mapbox/images/icons-ffffff.png -------------------------------------------------------------------------------- /Android/ExampleWithWebViewMap/assets/map/leaflet-0.7.2/images/layers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiXing/WebViewJavascriptBridge/HEAD/Android/ExampleWithWebViewMap/assets/map/leaflet-0.7.2/images/layers.png -------------------------------------------------------------------------------- /Android/ExampleWithWebViewMap/assets/map/leaflet-0.7.2/images/layers-2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiXing/WebViewJavascriptBridge/HEAD/Android/ExampleWithWebViewMap/assets/map/leaflet-0.7.2/images/layers-2x.png -------------------------------------------------------------------------------- /Android/ExampleWithWebViewMap/assets/map/mapbox/images/icons-000000@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiXing/WebViewJavascriptBridge/HEAD/Android/ExampleWithWebViewMap/assets/map/mapbox/images/icons-000000@2x.png -------------------------------------------------------------------------------- /Android/ExampleWithWebViewMap/assets/map/mapbox/images/icons-ffffff@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiXing/WebViewJavascriptBridge/HEAD/Android/ExampleWithWebViewMap/assets/map/mapbox/images/icons-ffffff@2x.png -------------------------------------------------------------------------------- /Android/ExampleWithWebViewMap/assets/map/leaflet-0.7.2/images/marker-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiXing/WebViewJavascriptBridge/HEAD/Android/ExampleWithWebViewMap/assets/map/leaflet-0.7.2/images/marker-icon.png -------------------------------------------------------------------------------- /Android/ExampleWithWebViewMap/assets/map/leaflet-0.7.2/images/marker-icon-2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiXing/WebViewJavascriptBridge/HEAD/Android/ExampleWithWebViewMap/assets/map/leaflet-0.7.2/images/marker-icon-2x.png -------------------------------------------------------------------------------- /Android/ExampleWithWebViewMap/assets/map/leaflet-0.7.2/images/marker-shadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiXing/WebViewJavascriptBridge/HEAD/Android/ExampleWithWebViewMap/assets/map/leaflet-0.7.2/images/marker-shadow.png -------------------------------------------------------------------------------- /IOS/Example Apps/ExampleApp-OSX/ExampleApp-OSX-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'ExampleApp-OSX' target in the 'ExampleApp-OSX' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | -------------------------------------------------------------------------------- /IOS/Example Apps/ExampleApp-iOS/main.m: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | #import "ExampleAppDelegate.h" 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | @autoreleasepool { 8 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([ExampleAppDelegate class])); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /IOS/Example Apps/ExampleApp-OSX/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // ExampleApp-OSX 4 | // 5 | // Created by Marcus Westin on 6/8/13. 6 | // Copyright (c) 2013 Marcus Westin. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | return NSApplicationMain(argc, (const char **)argv); 14 | } 15 | -------------------------------------------------------------------------------- /IOS/Example Apps/ExampleApp-OSX/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // ExampleApp-OSX 4 | // 5 | // Created by Marcus Westin on 6/8/13. 6 | // Copyright (c) 2013 Marcus Westin. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : NSObject 12 | 13 | @property (assign) IBOutlet NSWindow *window; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /IOS/Example Apps/ExampleApp-iOS/ExampleApp-iOS-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'ExampleApp' target in the 'ExampleApp' project 3 | // 4 | 5 | #import 6 | 7 | #ifndef __IPHONE_3_0 8 | #warning "This project uses features only available in iOS SDK 3.0 and later." 9 | #endif 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #endif 15 | -------------------------------------------------------------------------------- /Html/Example/multi_js/example.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | WebBridge Example 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /IOS/Example Apps/ExampleApp-iOS/ExampleAppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import "WebViewJavascriptBridge.h" 3 | 4 | @interface ExampleAppDelegate : UIResponder 5 | 6 | @property (strong, nonatomic) UIWindow *window; 7 | @property (strong, nonatomic) WebViewJavascriptBridge *javascriptBridge; 8 | 9 | - (void)renderButtons:(UIWebView*)webView; 10 | - (void)loadExamplePage:(UIWebView*)webView; 11 | 12 | @end 13 | -------------------------------------------------------------------------------- /Android/Example/res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Html/Example/multi_js/user_server.js: -------------------------------------------------------------------------------- 1 | console.log("user_server.js called!"); 2 | bridge.sinit(function(data,responseCallback){ 3 | console.log("Received message from javascript: "+data); 4 | if(responseCallback){ 5 | responseCallback("Right back atcha"); 6 | } 7 | }) 8 | 9 | function serverSend(){ 10 | bridge.ssend("Well hello there"); 11 | bridge.ssend("Give me a response, will you?", function(responseData) { 12 | console.log("Background got its response! "+responseData); 13 | }) 14 | } 15 | 16 | setTimeout(serverSend,1000); 17 | -------------------------------------------------------------------------------- /Chrome/Example/simple_extension/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wanjuan", 3 | "version": "0.1", 4 | "description": "Wanjuan Reader", 5 | "permissions": ["tabs","storage"], 6 | "content_scripts": [ 7 | { 8 | "matches": ["*://*/*"], 9 | "js": ["user_client.js","bridgeClientChrome.js"] 10 | } 11 | ], 12 | "background": { 13 | "scripts": ["bridgeServerChrome.js","user_server.js"] 14 | }, 15 | "browser_action": { 16 | "default_title": "Wanjuan Reader", 17 | "default_icon": "clock.png" 18 | }, 19 | "manifest_version": 2 20 | } 21 | -------------------------------------------------------------------------------- /IOS/Example Apps/ExampleApp-OSX/en.lproj/Credits.rtf: -------------------------------------------------------------------------------- 1 | {\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;} 2 | {\colortbl;\red255\green255\blue255;} 3 | \paperw9840\paperh8400 4 | \pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\ql\qnatural 5 | 6 | \f0\b\fs24 \cf0 Engineering: 7 | \b0 \ 8 | Some people\ 9 | \ 10 | 11 | \b Human Interface Design: 12 | \b0 \ 13 | Some other people\ 14 | \ 15 | 16 | \b Testing: 17 | \b0 \ 18 | Hopefully not nobody\ 19 | \ 20 | 21 | \b Documentation: 22 | \b0 \ 23 | Whoever\ 24 | \ 25 | 26 | \b With special thanks to: 27 | \b0 \ 28 | Mom\ 29 | } 30 | -------------------------------------------------------------------------------- /Android/Example/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-18 15 | -------------------------------------------------------------------------------- /Html/Example/multi_js/user_client.js: -------------------------------------------------------------------------------- 1 | console.log("user_client.js called!"); 2 | document.addEventListener('WebViewJavascriptBridgeReady', function onBridgeReady(event) { 3 | var bridge = event.bridge 4 | bridge.init(function(message, responseCallback) { 5 | alert('Received message: ' + message) 6 | if (responseCallback) { 7 | responseCallback("Right back atcha") 8 | } 9 | }) 10 | bridge.send('Hello from the javascript') 11 | bridge.send('Please respond to this', function responseCallback(responseData) { 12 | console.log("Javascript got its response", responseData) 13 | }) 14 | }, false) -------------------------------------------------------------------------------- /Android/ExampleWithWebViewMap/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-18 15 | -------------------------------------------------------------------------------- /Html/js/bridgeServerHtml.js: -------------------------------------------------------------------------------- 1 | //server 2 | bridge={}; 3 | (function(d){var e=d.c_||{};d.publish=function(a,b){for(var c=e[a],f=c?c.length:0;f--;)c[f].apply(d,b||[])};d.subscribe=function(a,b){e[a]||(e[a]=[]);e[a].push(b);return[a,b]};d.unsubscribe=function(a){for(var b=e[a[0]],a=a[1],c=b?b.length:0;c--;)b[c]===a&&b.splice(c,1)}})(bridge); 4 | bridge.sinit=function(register){ 5 | //assert register is a function 6 | bridge.subscribe("MESSAGE2S",function(message,responseCallback){ 7 | register(message,responseCallback); 8 | }) 9 | } 10 | bridge.ssend=function(message,responseCallback){ 11 | bridge.publish("MESSAGE2C",[message,responseCallback]); 12 | } -------------------------------------------------------------------------------- /Android/Example/Example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Chrome/Example/simple_extension/user_server.js: -------------------------------------------------------------------------------- 1 | console.log("user_server.js called!"); 2 | bridge.sinit(function(data,responseCallback){ 3 | console.log("Received message from javascript: "+data); 4 | responseCallback("Right back atcha"); 5 | }) 6 | 7 | function serverSend(){ 8 | bridge.ssend("Well hello there"); 9 | bridge.ssend("Give me a response, will you?", function(responseData) { 10 | console.log("Background got its response! "+responseData); 11 | }) 12 | bridge.callHandler("showAlert","42",function(responseData){ 13 | console.log("got alert response:"+responseData); 14 | }); 15 | } 16 | 17 | bridge.registerHandler("handler1", function(data,responseCallback) 18 | { console.log("handler1:"+data);responseCallback("back from handerl1") }); 19 | 20 | -------------------------------------------------------------------------------- /Android/ExampleWithWebViewMap/Example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Android/Example/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Android/Example/ant.properties: -------------------------------------------------------------------------------- 1 | # This file is used to override default values used by the Ant build system. 2 | # 3 | # This file must be checked into Version Control Systems, as it is 4 | # integral to the build system of your project. 5 | 6 | # This file is only used by the Ant script. 7 | 8 | # You can use this to override default values such as 9 | # 'source.dir' for the location of your java source folder and 10 | # 'out.dir' for the location of your output folder. 11 | 12 | # You can also use it define how the release builds are signed by declaring 13 | # the following properties: 14 | # 'key.store' for the location of your keystore and 15 | # 'key.alias' for the name of the key to use. 16 | # The password will be asked during the build when you use the 'release' target. 17 | 18 | -------------------------------------------------------------------------------- /Html/js/bridgeClientHtml.js: -------------------------------------------------------------------------------- 1 | //client 2 | (function(bridge){ 3 | //common 4 | function assert(condition, message) { 5 | if (!condition) { 6 | throw message || "Assertion failed"; 7 | } 8 | } 9 | 10 | bridge.init=function(register){ 11 | //assert register is a function 12 | assert(register instanceof Function,"init() should has a function as parameter"); 13 | bridge.subscribe("MESSAGE2C",function(message,responseCallback){ 14 | register(message,responseCallback); 15 | }) 16 | } 17 | bridge.send=function(message,responseCallback){ 18 | bridge.publish("MESSAGE2S",[message,responseCallback]); 19 | } 20 | //dispatch event 21 | var event=new CustomEvent('WebViewJavascriptBridgeReady') 22 | event.bridge=bridge; 23 | document.dispatchEvent(event); 24 | })(bridge) -------------------------------------------------------------------------------- /Android/ExampleWithWebViewMap/ant.properties: -------------------------------------------------------------------------------- 1 | # This file is used to override default values used by the Ant build system. 2 | # 3 | # This file must be checked into Version Control Systems, as it is 4 | # integral to the build system of your project. 5 | 6 | # This file is only used by the Ant script. 7 | 8 | # You can use this to override default values such as 9 | # 'source.dir' for the location of your java source folder and 10 | # 'out.dir' for the location of your output folder. 11 | 12 | # You can also use it define how the release builds are signed by declaring 13 | # the following properties: 14 | # 'key.store' for the location of your keystore and 15 | # 'key.alias' for the name of the key to use. 16 | # The password will be asked during the build when you use the 'release' target. 17 | 18 | -------------------------------------------------------------------------------- /Android/ExampleWithWebViewMap/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Android/Example/WebViewJavascriptBridgeExample.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Android/Example/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /Android/ExampleWithWebViewMap/WebViewJavascriptBridgeExample.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Android/ExampleWithWebViewMap/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /Html/Example/multi_js/bridgeServerHtml.js: -------------------------------------------------------------------------------- 1 | //server 2 | bridge={}; 3 | (function(d){var e=d.c_||{};d.publish=function(a,b){for(var c=e[a],f=c?c.length:0;f--;)c[f].apply(d,b||[])};d.subscribe=function(a,b){e[a]||(e[a]=[]);e[a].push(b);return[a,b]};d.unsubscribe=function(a){for(var b=e[a[0]],a=a[1],c=b?b.length:0;c--;)b[c]===a&&b.splice(c,1)}})(bridge); 4 | bridge.sinit=function(register){ 5 | //assert register is a function 6 | bridge.subscribe("MESSAGE2S",function(message,responseCallback){ 7 | register(message,responseCallback); 8 | }) 9 | } 10 | bridge.ssend=function(message,responseCallback){ 11 | bridge.publish("MESSAGE2C",[message,responseCallback]); 12 | } 13 | bridge.scallHandler=function(handlerName, data, responseCallback) { 14 | bridge.publish("[c]"+handlerName,[data, responseCallback]); 15 | } 16 | bridge.sregisterHandler=function(handlerName, handler) { 17 | bridge.subscribe("[s]"+handlerName,handler); 18 | } -------------------------------------------------------------------------------- /IOS/WebViewJavascriptBridge.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'WebViewJavascriptBridge' 3 | s.version = '4.0.1' 4 | s.summary = 'An iOS/OSX bridge for sending messages between Obj-C and JavaScript in UIWebViews/WebViews.' 5 | s.homepage = 'http://github.com/marcuswestin/WebViewJavascriptBridge' 6 | s.license = { :type => 'MIT', :file => 'LICENSE' } 7 | s.author = { 'marcuswestin' => 'marcus.westin@gmail.com' } 8 | s.requires_arc = true 9 | s.source = { :git => 'https://github.com/marcuswestin/WebViewJavascriptBridge.git' } 10 | s.ios.platform = :ios, '5.0' 11 | s.osx.platform = :osx 12 | s.ios.source_files = 'WebViewJavascriptBridge/*.{h,m}' 13 | s.osx.source_files = 'WebViewJavascriptBridge/*.{h,m}' 14 | s.resource = 'WebViewJavascriptBridgeAbstract/WebViewJavascriptBridge.js.txt' 15 | s.ios.framework = 'UIKit' 16 | s.osx.framework = 'WebKit' 17 | end 18 | -------------------------------------------------------------------------------- /Chrome/Example/simple_extension/user_client.js: -------------------------------------------------------------------------------- 1 | console.log("user_client.js called!"); 2 | document.addEventListener('WebViewJavascriptBridgeReady', function onBridgeReady(event) { 3 | var bridge = event.bridge 4 | bridge.init(function(message, responseCallback) { 5 | alert('Received message: ' + message) 6 | if (responseCallback) { 7 | responseCallback("Right back atcha") 8 | } 9 | }) 10 | bridge.send('Hello from the javascript') 11 | bridge.send('Please respond to this', function responseCallback(responseData) { 12 | console.log("Javascript got its response", responseData) 13 | }) 14 | bridge.registerHandler("showAlert", function(data,responseCallback) 15 | { console.log("alert:"+data);responseCallback("response from alert") }); 16 | bridge.callHandler("handler1","gift for handler1",function(responseData){ 17 | console.log("got handler1 response:"+responseData); 18 | }); 19 | }, false) -------------------------------------------------------------------------------- /Html/Example/multi_js/bridgeClientHtml.js: -------------------------------------------------------------------------------- 1 | //client 2 | (function(bridge){ 3 | //common 4 | function assert(condition, message) { 5 | if (!condition) { 6 | throw message || "Assertion failed"; 7 | } 8 | } 9 | 10 | bridge.init=function(register){ 11 | //assert register is a function 12 | assert(register instanceof Function,"init() should has a function as parameter"); 13 | bridge.subscribe("MESSAGE2C",function(message,responseCallback){ 14 | register(message,responseCallback); 15 | }) 16 | } 17 | bridge.send=function(message,responseCallback){ 18 | bridge.publish("MESSAGE2S",[message,responseCallback]); 19 | } 20 | bridge.callHandler=function(handlerName, data, responseCallback) { 21 | bridge.publish("[s]"+handlerName,[data, responseCallback]); 22 | } 23 | bridge.registerHandler=function(handlerName, handler) { 24 | bridge.subscribe("[c]"+handlerName,handler); 25 | } 26 | //dispatch event 27 | var event=new CustomEvent('WebViewJavascriptBridgeReady') 28 | event.bridge=bridge; 29 | document.dispatchEvent(event); 30 | })(bridge) -------------------------------------------------------------------------------- /Android/ExampleWithWebViewMap/assets/map/poi.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "FeatureCollection", 3 | "features": [ 4 | { 5 | "type": "Feature", 6 | "geometry": { 7 | "type": "Point", 8 | "coordinates": [ 9 | 0.200909516011011, 10 | 0.037327561069884 11 | ] 12 | }, 13 | "properties": { 14 | "id": "2", 15 | "title": "磁悬浮列车" 16 | } 17 | }, 18 | { 19 | "type": "Feature", 20 | "geometry": { 21 | "type": "Point", 22 | "coordinates": [ 23 | -0.026763873271805, 24 | 0.230131436760048 25 | ] 26 | }, 27 | "properties": { 28 | "id": "1", 29 | "title": "机器人世界" 30 | } 31 | }, 32 | { 33 | "type": "Feature", 34 | "geometry": { 35 | "type": "Point", 36 | "coordinates": [ 37 | -0.189827246677065, 38 | -0.080610295914104 39 | ] 40 | }, 41 | "properties": { 42 | "id": "3", 43 | "title": "火山" 44 | } 45 | } 46 | ] 47 | } -------------------------------------------------------------------------------- /Android/Example/res/raw/user_client.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 27 | -------------------------------------------------------------------------------- /Android/ExampleWithWebViewMap/res/raw/user_client.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 27 | -------------------------------------------------------------------------------- /IOS/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011-2013 Marcus Westin, Antoine Lagadec 2 | 3 | Permission is hereby granted, free of charge, to any person 4 | obtaining a copy of this software and associated documentation 5 | files (the "Software"), to deal in the Software without 6 | restriction, including without limitation the rights to use, 7 | copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the 9 | Software is furnished to do so, subject to the following 10 | conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 17 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /Chrome/js/bridgeClientChrome.js: -------------------------------------------------------------------------------- 1 | (function(){ 2 | //common 3 | function assert(condition, message) { 4 | if (!condition) { 5 | throw message || "Assertion failed"; 6 | } 7 | } 8 | //const 9 | var MSG_REGISTER_WANJUAN_INTERFACE="MSG_REGISTER_WANJUAN_INTERFACE"; 10 | //bridge 11 | var bridge = {}; 12 | bridge.send=function(msg,responseCallback){ 13 | assert(!responseCallback || responseCallback instanceof Function,"responseCallback should be function"); 14 | if(responseCallback){ 15 | chrome.extension.sendMessage(msg,responseCallback) 16 | }else{ 17 | chrome.extension.sendMessage(msg) 18 | } 19 | }; 20 | bridge.init=function(onMessageCallback){ 21 | var adapter=onMessageCallbackAdapter(onMessageCallback); 22 | chrome.extension.onMessage.addListener(adapter); 23 | //register for accept message 24 | chrome.extension.sendMessage(MSG_REGISTER_WANJUAN_INTERFACE); 25 | } 26 | function onMessageCallbackAdapter(onMessageCallback){ 27 | var adapter=function(message, sender, sendResponse){ 28 | onMessageCallback(message,sendResponse); 29 | } 30 | return adapter; 31 | } 32 | //dispatch event 33 | var event = new CustomEvent('WebViewJavascriptBridgeReady'); 34 | event.bridge=bridge; 35 | document.dispatchEvent(event); 36 | })() 37 | -------------------------------------------------------------------------------- /IOS/Example Apps/ExampleApp-OSX/ExampleApp-OSX-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | WebViewJavascriptBridge.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSMinimumSystemVersion 26 | ${MACOSX_DEPLOYMENT_TARGET} 27 | NSHumanReadableCopyright 28 | Copyright © 2013 Marcus Westin. All rights reserved. 29 | NSMainNibFile 30 | MainMenu 31 | NSPrincipalClass 32 | NSApplication 33 | 34 | 35 | -------------------------------------------------------------------------------- /Android/ExampleWithWebViewMap/assets/map/mapbox/images/render.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e -u 3 | 4 | # Color variations to be generated 5 | COLORS="000000 ffffff" 6 | 7 | # Check for required commands 8 | COMMANDS="inkscape pngquant convert" 9 | for COMMAND in $COMMANDS; do 10 | if [ -z $(which $COMMAND) ]; then 11 | echo "Command '$COMMAND' not found." 12 | exit 1 13 | fi 14 | done 15 | 16 | BASE="$(dirname $0)" 17 | TMP="$(mktemp /tmp/tmp.XXXXXXXX)" 18 | 19 | # Render icons.svg variations. 20 | inkscape \ 21 | --export-dpi=90 \ 22 | --export-png=$TMP.png \ 23 | $BASE/icons.svg > /dev/null 24 | 25 | inkscape \ 26 | --export-dpi=180 \ 27 | --export-png=$TMP@2x.png \ 28 | $BASE/icons.svg > /dev/null 29 | 30 | echo "" 31 | 32 | for COLOR in $COLORS; do 33 | convert $TMP.png -fill "#$COLOR" -colorize 100,100,100,0 - | pngquant 32 > $BASE/icons-$COLOR.png 34 | echo -e "\033[01;33m✔ saved $BASE/icons-$COLOR.png" 35 | convert $TMP@2x.png -fill "#$COLOR" -colorize 100,100,100,0 - | pngquant 32 > $BASE/icons-$COLOR@2x.png 36 | echo -e "\033[01;33m✔ saved $BASE/icons-$COLOR@2x.png" 37 | done 38 | 39 | rm -f $TMP $TMP.png $TMP@2x.png 40 | 41 | echo -e "\n\033[00;33mCOMPLETE! Don't forget to update the \`background-size\` property if the sprite size changed\033[0m" 42 | -------------------------------------------------------------------------------- /Android/ExampleWithWebViewMap/res/layout/main.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 13 | 14 |