├── icons ├── icon128.png ├── icon16.png ├── icon24.png └── icon32.png ├── npapi ├── hostadmin.dll ├── hostadmin.x86.so ├── src │ ├── hostadmin.rc │ ├── hostadmin.def │ ├── hostadmin.h │ ├── hostadmin.xcodeproj │ │ ├── project.xcworkspace │ │ │ └── contents.xcworkspacedata │ │ └── project.pbxproj │ ├── const.h │ ├── Makefile │ ├── hostadmin-Info.plist │ ├── hostadmin.sln │ ├── npapi_headers │ │ ├── nptypes.h │ │ ├── npfunctions.h │ │ └── npruntime.h │ ├── hostadmin.vcproj │ └── hostadmin.c ├── hostadmin.amd64.so └── hostadmin.plugin │ └── Contents │ ├── MacOS │ └── hostadmin │ └── Info.plist ├── core ├── lib │ ├── bootstrap │ │ ├── img │ │ │ ├── glyphicons-halflings.png │ │ │ └── glyphicons-halflings-white.png │ │ └── js │ │ │ └── bootstrap.min.js │ ├── CodeMirror │ │ ├── LICENSE │ │ ├── addon │ │ │ └── selection │ │ │ │ └── active-line.js │ │ ├── mode │ │ │ └── hostadmin │ │ │ │ └── hostadmin.js │ │ └── lib │ │ │ └── codemirror.css │ └── levenshtein.js ├── glue.js ├── init.js ├── editor.js ├── popup.html ├── editor.html ├── popup.js └── hostadmin.js ├── container ├── chrome │ ├── timer.js │ ├── config.js │ ├── background.html │ ├── host_file_wrapper.js │ └── container.js └── firefox │ ├── hostadmin.css │ ├── timer.js │ ├── config.js │ ├── firstrun.js │ ├── refresh_dns.js │ ├── hostadmin.xul │ ├── container.js │ ├── host_file_wrapper.js │ └── statusbar.js ├── .gitignore ├── chrome.manifest ├── defaults └── preferences │ └── prefs.js ├── dist ├── manifest.json ├── dist-chrome.sh ├── install.rdf ├── CONTRIBUTING.markdown ├── README.markdown ├── dist-firefox.sh └── LICENSE /icons/icon128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tg123/chrome-hostadmin/HEAD/icons/icon128.png -------------------------------------------------------------------------------- /icons/icon16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tg123/chrome-hostadmin/HEAD/icons/icon16.png -------------------------------------------------------------------------------- /icons/icon24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tg123/chrome-hostadmin/HEAD/icons/icon24.png -------------------------------------------------------------------------------- /icons/icon32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tg123/chrome-hostadmin/HEAD/icons/icon32.png -------------------------------------------------------------------------------- /npapi/hostadmin.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tg123/chrome-hostadmin/HEAD/npapi/hostadmin.dll -------------------------------------------------------------------------------- /npapi/hostadmin.x86.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tg123/chrome-hostadmin/HEAD/npapi/hostadmin.x86.so -------------------------------------------------------------------------------- /npapi/src/hostadmin.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tg123/chrome-hostadmin/HEAD/npapi/src/hostadmin.rc -------------------------------------------------------------------------------- /npapi/hostadmin.amd64.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tg123/chrome-hostadmin/HEAD/npapi/hostadmin.amd64.so -------------------------------------------------------------------------------- /core/lib/bootstrap/img/glyphicons-halflings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tg123/chrome-hostadmin/HEAD/core/lib/bootstrap/img/glyphicons-halflings.png -------------------------------------------------------------------------------- /npapi/hostadmin.plugin/Contents/MacOS/hostadmin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tg123/chrome-hostadmin/HEAD/npapi/hostadmin.plugin/Contents/MacOS/hostadmin -------------------------------------------------------------------------------- /npapi/src/hostadmin.def: -------------------------------------------------------------------------------- 1 | LIBRARY hostadmin 2 | 3 | EXPORTS 4 | NP_GetEntryPoints @1 5 | NP_Initialize @2 6 | NP_Shutdown @3 -------------------------------------------------------------------------------- /npapi/src/hostadmin.h: -------------------------------------------------------------------------------- 1 | #ifdef XP_WIN 2 | #include 3 | #endif 4 | 5 | #include "npapi_headers/npapi.h" 6 | #include "npapi_headers/npfunctions.h" 7 | -------------------------------------------------------------------------------- /core/lib/bootstrap/img/glyphicons-halflings-white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tg123/chrome-hostadmin/HEAD/core/lib/bootstrap/img/glyphicons-halflings-white.png -------------------------------------------------------------------------------- /container/chrome/timer.js: -------------------------------------------------------------------------------- 1 | ;(function(HostAdmin){ 2 | var host_admin = HostAdmin.core; 3 | 4 | HostAdmin.dontgc = setInterval(function(){ 5 | host_admin.refresh(); 6 | }, 1000); 7 | })(window.HostAdmin); 8 | -------------------------------------------------------------------------------- /npapi/src/hostadmin.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .* 2 | 3 | npapi/src/hostadmin.vcproj.* 4 | npapi/src/hostadmin.ncb 5 | npapi/src/hostadmin.suo 6 | npapi/src/Release/ 7 | npapi/src/Debug/ 8 | 9 | npapi/src/*.so 10 | npapi/src/*.o 11 | 12 | xcuserdata 13 | 14 | .DS_Store 15 | *.swp 16 | *~.nib 17 | 18 | *.zip 19 | *.crx 20 | *.xpi 21 | -------------------------------------------------------------------------------- /chrome.manifest: -------------------------------------------------------------------------------- 1 | content hostadmin-container container/firefox/ 2 | content hostadmin core/ 3 | content hostadmin-icons icons/ 4 | 5 | style chrome://global/content/customizeToolbar.xul chrome://hostadmin-container/content/hostadmin.css 6 | overlay chrome://browser/content/browser.xul chrome://hostadmin-container/content/hostadmin.xul 7 | -------------------------------------------------------------------------------- /defaults/preferences/prefs.js: -------------------------------------------------------------------------------- 1 | pref("extensions.hostadmin.hostsfilepath", "default"); 2 | pref("extensions.hostadmin.charset", "auto"); 3 | pref("extensions.hostadmin.firstrun", true); 4 | 5 | // https://developer.mozilla.org/en/Localizing_extension_descriptions 6 | pref("extensions.{bd54afa8-b14a-4d7a-aecf-37e34e882796}.description", "chrome://hostadmin/locale/overlay.properties"); 7 | -------------------------------------------------------------------------------- /container/chrome/config.js: -------------------------------------------------------------------------------- 1 | (function(HostAdmin){ 2 | 3 | var chrome_config = (function(){ 4 | return { 5 | set: function(key, value){ 6 | localStorage.setItem(key, JSON.stringify(value)); 7 | }, 8 | get: function(key){ 9 | return JSON. parse(localStorage.getItem(key));; 10 | } 11 | }; 12 | })(); 13 | 14 | HostAdmin.config = chrome_config; 15 | })(window.HostAdmin); 16 | -------------------------------------------------------------------------------- /npapi/src/const.h: -------------------------------------------------------------------------------- 1 | #ifdef XP_WIN 2 | #define OSNAME "WINNT" 3 | #else 4 | #define OSNAME "Linux" 5 | #endif 6 | 7 | #define PROP_OS "os" 8 | #define PROP_WHERE "where" 9 | 10 | #define METHOD_SET "set" 11 | #define METHOD_GET "get" 12 | #define METHOD_TIME "time" 13 | 14 | 15 | #define MIMETYPE "application/x-hostadmin-helper" 16 | 17 | #define MIMETYPE_S "application/x-hostadmin-helper::HostAdmin" 18 | 19 | #define UTF8BOM "\xEF\xBB\xBF" 20 | -------------------------------------------------------------------------------- /container/chrome/background.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /container/firefox/hostadmin.css: -------------------------------------------------------------------------------- 1 | #hostadmin-toolbar-button 2 | { 3 | list-style-image: url("chrome://hostadmin-icons/content/icon32.png"); 4 | } 5 | [iconsize="small"] #hostadmin-toolbar-button 6 | { 7 | list-style-image: url("chrome://hostadmin-icons/content/icon16.png"); 8 | } 9 | 10 | #hostadmin-menu-content{ 11 | margin:0; 12 | padding:0; 13 | border:0; 14 | } 15 | #hostadmin-menu-panel{ 16 | width:322px; 17 | height:600px; 18 | margin:0; 19 | padding:0; 20 | border:0; 21 | } 22 | -------------------------------------------------------------------------------- /container/firefox/timer.js: -------------------------------------------------------------------------------- 1 | ;(function(HostAdmin){ 2 | 3 | var timer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer); 4 | timer.init((function(){ 5 | var host_admin = HostAdmin.core; 6 | 7 | return { 8 | observe: function(subject, topic, data){ 9 | host_admin.refresh(); 10 | }, 11 | }; 12 | 13 | })(), 1000, Components.interfaces.nsITimer.TYPE_REPEATING_SLACK); 14 | 15 | HostAdmin.dontgc = timer; //prevent form being gc 16 | 17 | })(window.HostAdmin); 18 | -------------------------------------------------------------------------------- /core/glue.js: -------------------------------------------------------------------------------- 1 | // 2 | // finding a method to be injected from container ... 3 | // 4 | window.run_from_glue = (function(){ 5 | 6 | var HostAdmin = null; 7 | 8 | if(typeof(chrome) == 'object'){ 9 | HostAdmin = chrome.extension.getBackgroundPage().HostAdmin; 10 | }else if(typeof(firefox) == 'object'){ 11 | HostAdmin = firefox.HostAdmin; 12 | } 13 | 14 | var _inner = function(callback){ 15 | callback(HostAdmin); 16 | }; 17 | 18 | return function(_callback){ 19 | _inner( _callback ); 20 | }; 21 | })(); 22 | -------------------------------------------------------------------------------- /npapi/src/Makefile: -------------------------------------------------------------------------------- 1 | FLAG = -Wall -fPIC -DXP_UNIX=1 -O2 2 | CC = cc 3 | 4 | define SO 5 | hostadmin.$(1).so: hostadmin.$(1).o 6 | $(CC) $(FLAG) -shared -m$(2) hostadmin.$(1).o -o hostadmin.$(1).so 7 | 8 | hostadmin.$(1).o: hostadmin.c hostadmin.h const.h 9 | $(CC) $(FLAG) -m$(2) -c -o hostadmin.$(1).o hostadmin.c 10 | endef 11 | 12 | 13 | all: hostadmin.x86.so hostadmin.amd64.so 14 | /bin/cp *.so ../ 15 | 16 | $(eval $(call SO,x86,32)) 17 | $(eval $(call SO,amd64,64)) 18 | 19 | 20 | clean : 21 | rm -f hostadmin.*.o hostadmin.*.so 22 | 23 | .PHONY: all clean 24 | -------------------------------------------------------------------------------- /core/init.js: -------------------------------------------------------------------------------- 1 | // HostAdmin 2 | // by T.G.(farmer1992@gmail.com) 3 | // 4 | // MPL v2 5 | // http://code.google.com/p/fire-hostadmin/ 6 | window.HostAdmin = {}; 7 | 8 | // event and cursor 9 | (function(HostAdmin){ 10 | HostAdmin.event_host = document; 11 | 12 | HostAdmin.requestCursorLine = function(line){ 13 | if(line || line === 0){ 14 | var e = HostAdmin.event_host.createEvent('CustomEvent'); 15 | e.initCustomEvent('HostAdminReqCursorLine', false, false, { cursorline : line }); 16 | HostAdmin.event_host.dispatchEvent(e); 17 | } 18 | } 19 | })(window.HostAdmin); 20 | 21 | -------------------------------------------------------------------------------- /dist: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function dist-clean(){ 4 | rm -f *.xpi 5 | rm -f *.zip 6 | rm -f *.crx 7 | echo "Cleaned" 8 | } 9 | 10 | function dist-check(){ 11 | ALLJS=`find . -name '*.js'` 12 | 13 | CHECKCONSOLE=`grep console -n $ALLJS` 14 | if [ "x$CHECKCONSOLE" != "x" ];then 15 | echo "Console decteted" 16 | echo $CHECKCONSOLE 17 | exit; 18 | fi 19 | } 20 | 21 | if [ -e "dist-$1.sh" ]; then 22 | "./dist-$1.sh" 23 | elif [ "$1" == "clean" ]; then 24 | dist-clean 25 | else 26 | dist-check 27 | for i in `ls dist-*.sh` ;do 28 | "./$i" ; 29 | done 30 | 31 | echo "All Done" 32 | fi 33 | 34 | for i in `ls *.zip *.xpi *.crx 2>/dev/null `;do 35 | md5sum $i 36 | done 37 | -------------------------------------------------------------------------------- /manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "HostAdmin", 3 | "icons": { 4 | "16" : "icons/icon16.png", 5 | "24" : "icons/icon24.png", 6 | "32" : "icons/icon32.png", 7 | "128": "icons/icon128.png" 8 | }, 9 | "version": "1.4.8", 10 | "manifest_version": 2, 11 | "permissions": ["tabs", "browsingData"], 12 | "description": "Saving your time when you switch domain-ip mapping (Hosts file) between different environment. Awesome host file editor !", 13 | "background": { 14 | "persistent": true, 15 | "page": "container/chrome/background.html" 16 | }, 17 | 18 | "plugins": [{"path": "npapi/hostadmin.x86.so"}, {"path": "npapi/hostadmin.amd64.so"}, {"path": "npapi/hostadmin.dll"},{"path": "npapi/hostadmin.plugin"}], 19 | "browser_action": { 20 | "default_icon": "icons/icon128.png", 21 | "default_popup": "core/popup.html" 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /container/chrome/host_file_wrapper.js: -------------------------------------------------------------------------------- 1 | ;(function(HostAdmin){ 2 | 3 | var helper = document.getElementById("host_admin_helper"); 4 | var splitchar = "\n"; 5 | var os = helper.os; 6 | 7 | var file_name; 8 | if (os == "WINNT"){ 9 | splitchar = "\r\n"; 10 | file_name = helper.where + "\\drivers\\etc\\hosts"; 11 | }else if(os == "Linux"){ 12 | file_name = "/etc/hosts"; 13 | }else if(os == "Darwin"){ 14 | file_name = "/etc/hosts"; 15 | } 16 | 17 | HostAdmin.host_file_wrapper = { 18 | get : function(){ 19 | return helper.get(file_name); 20 | }, 21 | set : function(data){ 22 | if (os == "WINNT"){ 23 | data = data.replace(/([^\r])\n/g, "$1\r\n"); 24 | } 25 | return helper.set(file_name, data); 26 | }, 27 | time : function(){ 28 | return helper.time(file_name); 29 | }, 30 | splitchar : splitchar 31 | }; 32 | })(window.HostAdmin); 33 | -------------------------------------------------------------------------------- /npapi/src/hostadmin-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | hostadmin.${PRODUCT_NAME:rfc1034identifier} 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BRPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | WebPluginMIMETypes 22 | 23 | application/x-hostadmin-helper 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /dist-chrome.sh: -------------------------------------------------------------------------------- 1 | #/bin/bash 2 | 3 | VER=`grep '"version".*:.*".*"' manifest.json -P -o | sed -e 's/["| ]//g' | cut -d : -f 2` 4 | TARGET=chrome-hostadmin-$VER 5 | 6 | CHROME_PROVIDERS="container/chrome/ core/ icons/ npapi/" 7 | 8 | # clean 9 | rm -f $TARGET.zip 10 | rm -f $TARGET.crx 11 | 12 | 13 | # build for store 14 | zip -r $TARGET.zip $CHROME_PROVIDERS manifest.json -x 'npapi/src/*' '**/.*' 15 | 16 | echo $TARGET.zip "DONE" 17 | 18 | if [ "$1" != "crx" ];then 19 | exit 20 | fi 21 | 22 | # build crx useless .... 23 | TMP=`mktemp -d` 24 | PLUGINDIR="$TMP/plugin" 25 | mkdir -p $PLUGINDIR 26 | 27 | unzip -d $PLUGINDIR/$TARGET $TARGET.zip 28 | 29 | CHROME="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" 30 | 31 | if [ ! -e "$CHROME" ] 32 | then 33 | CHROME='google-chrome' # ubuntu 34 | fi 35 | 36 | "$CHROME" --pack-extension=$PLUGINDIR/$TARGET 37 | 38 | cp $PLUGINDIR/$TARGET.crx . 39 | 40 | echo $TARGET.crx "DONE" 41 | -------------------------------------------------------------------------------- /npapi/src/hostadmin.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 10.00 3 | # Visual C++ Express 2008 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "hostadmin", "hostadmin.vcproj", "{FA1C69EE-D6A3-413B-845F-9BC7BDC7012C}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {FA1C69EE-D6A3-413B-845F-9BC7BDC7012C}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {FA1C69EE-D6A3-413B-845F-9BC7BDC7012C}.Debug|Win32.Build.0 = Debug|Win32 14 | {FA1C69EE-D6A3-413B-845F-9BC7BDC7012C}.Release|Win32.ActiveCfg = Release|Win32 15 | {FA1C69EE-D6A3-413B-845F-9BC7BDC7012C}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /install.rdf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {bd54afa8-b14a-4d7a-aecf-37e34e882796} 5 | 2 6 | HostAdmin 7 | 1.4.9.1 8 | T.G. 9 | 10 | Saving your time when you switch domain-ip mapping (Hosts file) between different environment. Awesome host file editor ! 11 | https://github.com/tg123/chrome-hostadmin 12 | true 13 | chrome://hostadmin-icons/content/icon32.png 14 | 15 | 16 | {ec8030f7-c20a-464f-9b0e-13a3a9e97384} 17 | 14.0 18 | 28.0 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /container/firefox/config.js: -------------------------------------------------------------------------------- 1 | (function(HostAdmin){ 2 | 3 | var fire_config = (function(){ 4 | var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService); 5 | prefs = prefs.getBranch("extensions.hostadmin."); 6 | 7 | return { 8 | set: function(key, value){ 9 | if (typeof(value) === "boolean"){ 10 | prefs.setBoolPref(key, value); 11 | }else{ 12 | prefs.setComplexValue(key, Components.interfaces.nsISupportsString, value); 13 | } 14 | }, 15 | get: function(key){ 16 | var type = prefs.getPrefType(key); 17 | if (type == prefs.PREF_BOOL){ 18 | return prefs.getBoolPref(key); 19 | //}else if(type == prefs.PREF_INT) { // no such now 20 | }else if(type == prefs.PREF_STRING) { 21 | return prefs.getComplexValue(key, Components.interfaces.nsISupportsString).data; 22 | } 23 | return undefined; 24 | }, 25 | run_when_not_equal: function(key, value, f){ 26 | var v = this.get(key); 27 | if(v && v != value){ 28 | f(v); 29 | } 30 | } 31 | }; 32 | })(); 33 | 34 | HostAdmin.config = fire_config; 35 | })(window.HostAdmin); 36 | -------------------------------------------------------------------------------- /container/firefox/firstrun.js: -------------------------------------------------------------------------------- 1 | // HostAdmin 2 | // by T.G.(farmer1992@gmail.com) 3 | // 4 | // MPL v2 5 | // http://code.google.com/p/fire-hostadmin/ 6 | 7 | (function(HostAdmin){ 8 | // {{{ 9 | // copy from https://developer.mozilla.org/en/Code_snippets/Toolbar 10 | function installButton(toolbarId, id, afterId) { 11 | if (!document.getElementById(id)) { 12 | var toolbar = document.getElementById(toolbarId); 13 | 14 | // If no afterId is given, then append the item to the toolbar 15 | var before = null; 16 | if (afterId) { 17 | var elem = document.getElementById(afterId); 18 | if (elem && elem.parentNode == toolbar) 19 | before = elem.nextElementSibling; 20 | } 21 | 22 | toolbar.insertItem(id, before); 23 | toolbar.setAttribute("currentset", toolbar.currentSet); 24 | document.persist(toolbar.id, "currentset"); 25 | 26 | if (toolbarId == "addon-bar") 27 | toolbar.collapsed = false; 28 | } 29 | } 30 | // }}} 31 | 32 | 33 | var fire_config = HostAdmin.config; 34 | var firstrun = fire_config.get("firstrun"); 35 | 36 | if (firstrun) { 37 | fire_config.set("firstrun", false); 38 | window.addEventListener("load", function(){ 39 | installButton("nav-bar", "hostadmin-toolbar-button"); 40 | }, false); 41 | } 42 | 43 | })(window.HostAdmin); 44 | -------------------------------------------------------------------------------- /core/lib/CodeMirror/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2012 by Marijn Haverbeke 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | 21 | Please note that some subdirectories of the CodeMirror distribution 22 | include their own LICENSE files, and are released under different 23 | licences. 24 | -------------------------------------------------------------------------------- /npapi/hostadmin.plugin/Contents/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildMachineOSBuild 6 | 12C3006 7 | CFBundleDevelopmentRegion 8 | English 9 | CFBundleExecutable 10 | hostadmin 11 | CFBundleIdentifier 12 | hostadmin.hostadmin 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | hostadmin 17 | CFBundlePackageType 18 | BRPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleVersion 22 | 1 23 | DTCompiler 24 | com.apple.compilers.llvm.clang.1_0 25 | DTPlatformBuild 26 | 4G2008a 27 | DTPlatformVersion 28 | GM 29 | DTSDKBuild 30 | 12C37 31 | DTSDKName 32 | macosx10.8 33 | DTXcode 34 | 0452 35 | DTXcodeBuild 36 | 4G2008a 37 | WebPluginMIMETypes 38 | 39 | application/x-hostadmin-helper 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /core/lib/CodeMirror/addon/selection/active-line.js: -------------------------------------------------------------------------------- 1 | // Because sometimes you need to style the cursor's line. 2 | // 3 | // Adds an option 'styleActiveLine' which, when enabled, gives the 4 | // active line's wrapping
the CSS class "CodeMirror-activeline", 5 | // and gives its background
the class "CodeMirror-activeline-background". 6 | 7 | (function() { 8 | "use strict"; 9 | var WRAP_CLASS = "CodeMirror-activeline"; 10 | var BACK_CLASS = "CodeMirror-activeline-background"; 11 | 12 | CodeMirror.defineOption("styleActiveLine", false, function(cm, val, old) { 13 | var prev = old && old != CodeMirror.Init; 14 | if (val && !prev) { 15 | updateActiveLine(cm); 16 | cm.on("cursorActivity", updateActiveLine); 17 | } else if (!val && prev) { 18 | cm.off("cursorActivity", updateActiveLine); 19 | clearActiveLine(cm); 20 | delete cm._activeLine; 21 | } 22 | }); 23 | 24 | function clearActiveLine(cm) { 25 | if ("_activeLine" in cm) { 26 | cm.removeLineClass(cm._activeLine, "wrap", WRAP_CLASS); 27 | cm.removeLineClass(cm._activeLine, "background", BACK_CLASS); 28 | } 29 | } 30 | 31 | function updateActiveLine(cm) { 32 | var line = cm.getLineHandle(cm.getCursor().line); 33 | if (cm._activeLine == line) return; 34 | clearActiveLine(cm); 35 | cm.addLineClass(line, "wrap", WRAP_CLASS); 36 | cm.addLineClass(line, "background", BACK_CLASS); 37 | cm._activeLine = line; 38 | } 39 | })(); 40 | -------------------------------------------------------------------------------- /container/firefox/refresh_dns.js: -------------------------------------------------------------------------------- 1 | (function(HostAdmin){ 2 | 3 | var event_host = HostAdmin.event_host; 4 | 5 | var refresh_dns = function(){ 6 | var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService); 7 | var cacheService = Components.classes["@mozilla.org/network/cache-service;1"].getService(Components.interfaces.nsICacheService); 8 | 9 | var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch); 10 | // Add Since Firefox 18 11 | // Firefox ioService.offline cant clear dns 12 | // actions below would led nsDNSService::Init @see firefox source netwerk/dns/nsDNSService2.cpp 13 | prefs.setIntPref("network.dnsCacheExpiration", "0"); 14 | prefs.setIntPref("network.dnsCacheEntries", "0"); 15 | 16 | // this funtion learn from addon dnsFlush 17 | // https://addons.mozilla.org/firefox/addon/dns-flusher/ 18 | // thanks to Marco Tulio 19 | // http://code.google.com/p/coderstech/source/browse/trunk/dnsFlusher/chrome/content/dnsFlusher/js/dnsFlusher.js#192 20 | 21 | try{ 22 | ioService.offline = true; 23 | cacheService.evictEntries(Components.interfaces.nsICache.STORE_ANYWHERE); 24 | }catch(e){} 25 | finally{ 26 | ioService.offline = false; 27 | } 28 | }; 29 | 30 | event_host.addEventListener('HostAdminRefresh', function(e) { 31 | refresh_dns(); 32 | }, false); 33 | 34 | HostAdmin.refresh_dns = refresh_dns; 35 | })(window.HostAdmin); 36 | -------------------------------------------------------------------------------- /container/firefox/hostadmin.xul: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 34 | 35 | 36 | 37 | 38 | 45 |
46 | Write hosts file failed check permissions, Learn more 47 |
48 | 49 | 64 | 65 | 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /container/chrome/container.js: -------------------------------------------------------------------------------- 1 | ;(function(HostAdmin){ 2 | 3 | var host_admin = HostAdmin.core; 4 | var event_host = HostAdmin.event_host; 5 | var cur_host; 6 | 7 | var opentab = function(t, line){ 8 | var url = null; 9 | if(t == 'EDITOR'){ 10 | url = chrome.runtime.getURL('core/editor.html'); 11 | }else if (t == 'PERMHELP'){ 12 | url = HostAdmin.PERM_HELP_URL; 13 | }else{ 14 | url = t; 15 | } 16 | 17 | if(url){ 18 | chrome.tabs.query({ url : url ,windowId: chrome.windows.WINDOW_ID_CURRENT }, function(t){ 19 | HostAdmin.cursorline = line; 20 | 21 | if (t.length > 0){ 22 | chrome.tabs.update(t[0].id, {active : true}); 23 | HostAdmin.requestCursorLine(line); 24 | }else{ 25 | chrome.tabs.create({url: url}); 26 | } 27 | 28 | }); 29 | } 30 | }; 31 | 32 | var hostreg = /:\/\/([\w\.\-]+)/; 33 | var extracthost = function(url){ 34 | if(url) { 35 | cur_host = url.match(hostreg)[1]; 36 | } 37 | updatelb(); 38 | 39 | }; 40 | 41 | var updatelb = function(){ 42 | var curHost = host_admin.real_hostname(cur_host); 43 | 44 | var str = ""; 45 | var hosts = host_admin.get_hosts(); 46 | if (typeof hosts[curHost] != "undefined") { 47 | hosts = hosts[curHost]; 48 | for (var i in hosts){ 49 | str = "*"; 50 | if(hosts[i].using){ 51 | str = hosts[i].addr + " " + hosts[i].comment; 52 | break; 53 | } 54 | } 55 | } 56 | 57 | chrome.browserAction.setBadgeBackgroundColor({color:'#0A0'}); 58 | chrome.browserAction.setBadgeText({text:str}); 59 | 60 | if(str == '*') { str = 'In Hosts';} 61 | else if( str === "" ) { str = 'Not In Hosts';} 62 | 63 | chrome.browserAction.setTitle({title: str}); 64 | 65 | }; 66 | 67 | chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab){ 68 | extracthost(changeInfo.url); 69 | }); 70 | chrome.tabs.onActivated.addListener(function(activeInfo){ 71 | chrome.tabs.query({ active: true , windowType: "normal", windowId: chrome.windows.WINDOW_ID_CURRENT }, function(t){ 72 | if (t.length > 0){ 73 | extracthost(t[0].url); } 74 | }); 75 | }); 76 | 77 | HostAdmin.container = { 78 | opentab : opentab, 79 | curhost : function(){ return cur_host;} 80 | }; 81 | 82 | event_host.addEventListener('HostAdminRefresh', function(e) { 83 | updatelb(); 84 | chrome.browsingData.removeCache({}); 85 | }, false); 86 | })(window.HostAdmin); 87 | -------------------------------------------------------------------------------- /core/lib/levenshtein.js: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Thanks to gf3 4 | 5 | from 6 | https://github.com/gf3/Levenshtein 7 | 8 | */ 9 | // Generics 10 | if ( ! Array.forEach ) { 11 | Array.forEach = function forEach ( array, iterator, context ) { 12 | iterator = context 13 | ? iterator.bind( context ) 14 | : iterator 15 | Array.prototype.forEach.call( array, iterator ) 16 | } 17 | } 18 | 19 | // Levenshtein distance 20 | function Levenshtein( str_m, str_n ) { var previous, current, matrix 21 | // Instance methods 22 | this.valueOf = function() { 23 | return this.distance 24 | } 25 | 26 | // add by tgic 27 | this.longestDistance = function(){ 28 | return Math.max(str_m.length, str_n.length) 29 | } 30 | 31 | this.toString = this.inspect = function inspect ( no_print ) { var max, buff, sep, rows 32 | max = matrix.reduce( function( m, o ) { 33 | return Math.max( m, o.reduce( Math.max, 0 ) ) 34 | }, 0 ) 35 | buff = Array( ( max + '' ).length ).join( ' ' ) 36 | 37 | sep = [] 38 | while ( sep.length < (matrix[0] && matrix[0].length || 0) ) 39 | sep[ sep.length ] = Array( buff.length + 1 ).join( '-' ) 40 | sep = sep.join( '-+' ) + '-' 41 | 42 | rows = matrix.map( function( row ) { var cells 43 | cells = row.map( function( cell ) { 44 | return ( buff + cell ).slice( - buff.length ) 45 | }) 46 | return cells.join( ' |' ) + ' ' 47 | }) 48 | 49 | return rows.join( "\n" + sep + "\n" ) 50 | } 51 | 52 | // Constructor 53 | matrix = [] 54 | 55 | // Sanity checks 56 | if ( str_m == str_n ) 57 | return this.distance = 0 58 | else if ( str_m == '' ) 59 | return this.distance = str_n.length 60 | else if ( str_n == '' ) 61 | return this.distance = str_m.length 62 | else { 63 | // Danger Will Robinson 64 | previous = [ 0 ] 65 | Array.forEach( str_m, function( v, i ) { i++, previous[ i ] = i } ) 66 | 67 | matrix[0] = previous 68 | Array.forEach( str_n, function( n_val, n_idx ) { 69 | current = [ ++n_idx ] 70 | Array.forEach( str_m, function( m_val, m_idx ) { 71 | m_idx++ 72 | if ( str_m.charAt( m_idx - 1 ) == str_n.charAt( n_idx - 1 ) ) 73 | current[ m_idx ] = previous[ m_idx - 1 ] 74 | else 75 | current[ m_idx ] = Math.min 76 | ( previous[ m_idx ] + 1 // Deletion 77 | , current[ m_idx - 1 ] + 1 // Insertion 78 | , previous[ m_idx - 1 ] + 1 // Subtraction 79 | ) 80 | }) 81 | previous = current 82 | matrix[ matrix.length ] = previous 83 | }) 84 | 85 | return this.distance = current[ current.length - 1 ] 86 | } 87 | } 88 | 89 | // Export 90 | if (typeof module == 'object' && module && module.exports) 91 | module.exports = Levenshtein 92 | 93 | -------------------------------------------------------------------------------- /core/lib/CodeMirror/mode/hostadmin/hostadmin.js: -------------------------------------------------------------------------------- 1 | CodeMirror.defineMode("hostadmin", function(config, parserConfig) { 2 | var ipv4 = /^((1?\d?\d|(2([0-4]\d|5[0-5])))\.){3}(1?\d?\d|(2([0-4]\d|5[0-5])))\s/; 3 | var ipv6 = /^((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s/ ; 4 | 5 | return { 6 | startState: function() {return { 7 | hasIp: false, 8 | groupline: false, 9 | groupid: 0 10 | };}, 11 | 12 | token: function(stream, state) { 13 | if(stream.sol()){ 14 | state.hasIP = false; 15 | state.groupline = false; 16 | } 17 | 18 | if(state.hide_all_of_below){ 19 | stream.skipToEnd(); 20 | return "comment"; 21 | } 22 | 23 | //stream.eatSpace(); 24 | var ch = stream.peek(); 25 | if (ch == "#") { 26 | if(stream.match(/#====\s/) || stream.match(/#====$/) ){ 27 | state.groupline = !stream.eol(); 28 | state.groupid++; 29 | 30 | return "keyword"; 31 | } 32 | 33 | stream.eatWhile(/[#\s]/); 34 | if(!state.hasIP && (stream.match(ipv4, false) || stream.match(ipv6, false))){ 35 | state.hasIP = true; 36 | return "keyword"; 37 | } 38 | 39 | if(stream.match(/^\s*hide_all_of_below/gi)){ 40 | state.hide_all_of_below = true; 41 | return "keyword" 42 | } 43 | 44 | if(stream.match(/^\s*hide/i) && !stream.match(/[^\s]/, false)){ 45 | return "keyword"; 46 | } 47 | 48 | state.groupline = false; 49 | state.hasIP = false; 50 | stream.skipToEnd(); 51 | return "comment"; 52 | } 53 | 54 | if(stream.match(ipv4) || stream.match(ipv6)){ 55 | return "number"; 56 | } 57 | 58 | if(state.groupline){ 59 | if(state.groupid % 2 == 1){ 60 | state.groupline = false; 61 | stream.eatWhile(/[#\s]/); 62 | if(stream.match(/^\s*hide/i) && !stream.match(/[^\s]/, false)){ 63 | return "keyword"; 64 | } 65 | 66 | return "comment"; 67 | }else{ 68 | stream.skipToEnd(); 69 | return "comment"; 70 | } 71 | } 72 | 73 | stream.next(); 74 | 75 | return null; 76 | } 77 | 78 | }; 79 | }); 80 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | HostAdmin 2 | ===================== 3 | Saving your time when you switch domain-ip mapping between different environment 4 | 5 | Chrome APP Version 6 | ------------------ 7 | Google banned NPAPI Please use [Chrome WebStore APP Version](https://chrome.google.com/webstore/detail/hostadmin-app/mfoaclfeiefiehgaojbmncmefhdnikeg) instead. 8 | 9 | It is true that is not easy to use than a menu bar edition. sad.. 10 | 11 | 12 | 13 | Installing 14 | ----------------------------- 15 | * [Chrome WebStore APP Version](https://chrome.google.com/webstore/detail/hostadmin-app/mfoaclfeiefiehgaojbmncmefhdnikeg) 16 | * [Firefox AddonSite](https://addons.mozilla.org/firefox/addon/hostadmin) 17 | * [Download from Google Code](http://code.google.com/p/fire-hostadmin/downloads/list) 18 | 19 | 20 | How HostAdmin analyze the Hosts file 21 | ------------------------------------ 22 | [Syntax detail](http://code.google.com/p/fire-hostadmin/wiki/HOST_SYNTAX) 23 | 24 | * ``Common`` 25 | 26 | IP DOMAIN [#COMMENT] 27 | 28 | *Example:* 29 | 30 | 127.0.0.1 localhost #comment here 31 | 32 | NOTE: A line with a comment, 'hide' (case-insensitive), would be hiden from HostAdmin. 33 | 34 | * ``Grouping`` 35 | 36 | #==== Groupname 37 | 38 | # some mappings 39 | 40 | #==== 41 | 42 | *Example:* 43 | 44 | #==== Project 1 45 | #127.0.0.1 localhost1 46 | 127.0.0.1 localhost2 47 | 127.0.0.1 localhost3 48 | #==== 49 | 50 | #==== Project 2 51 | #127.0.0.1 localhost1 52 | #127.0.0.1 localhost2 53 | #127.0.0.1 localhost3 54 | #==== 55 | 56 | 57 | * ``Bulk Hide`` 58 | 59 | 60 | #hide_all_of_below 61 | ... 62 | 63 | #All text here will be parsed as comment 64 | 65 | ... 66 | 67 | 68 | 69 | WRITE Permission to Hosts File 70 | ------------------------------ 71 | *WRITE Permission* to Hosts is needed, thus HostAdmin could modify your Host Files. 72 | XP users need NO additional setting. 73 | Here is a guide for you to gain write privilege for Vista/7/Linux/MacOS users 74 | 75 | http://code.google.com/p/fire-hostadmin/wiki/GAIN_HOSTS_WRITE_PERM 76 | 77 | DNS Auto refreshing 78 | ------------------- 79 | 80 | * ``Firefox`` 81 | 82 | HostAdmin borrowed code from [DNS flusher](https://addons.mozilla.org/en-US/firefox/addon/dns-flusher/) 83 | to refresh dns when hosts file is modified. 84 | 85 | * ``Chrome`` 86 | 87 | Since Chrome 21, Chrome will auto refresh dns by itself. 88 | More info at this [ticket](http://code.google.com/p/chromium/issues/detail?id=125599) 89 | 90 | > _KNOWN ISSUE_ 91 | > 92 | > DNS may not refresh as soon as hosts file changes due to a Chrome bug 93 | > reused socket pools by domain even if hosts changes 94 | > 95 | > To avoid this, open chrome://net-internals/#sockets and flush your host 96 | > 97 | > More info at Chrome Bug [152906](https://code.google.com/p/chromium/issues/detail?id=152906) [268059](https://code.google.com/p/chromium/issues/detail?id=268059) [288061](https://code.google.com/p/chromium/issues/detail?id=288061) 98 | 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /container/firefox/container.js: -------------------------------------------------------------------------------- 1 | ;(function(HostAdmin){ 2 | var EDITOR_URL = 'chrome://hostadmin/content/editor.html'; 3 | var PERM_HELP_URL = HostAdmin.PERM_HELP_URL; 4 | 5 | // {{{ copy from https://developer.mozilla.org/en-US/docs/Code_snippets/Tabbed_browser 6 | function openAndReuseOneTabPerURL(url) { 7 | var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"] 8 | .getService(Components.interfaces.nsIWindowMediator); 9 | var browserEnumerator = wm.getEnumerator("navigator:browser"); 10 | 11 | // Check each browser instance for our URL 12 | var found = false; 13 | while (!found && browserEnumerator.hasMoreElements()) { 14 | var browserWin = browserEnumerator.getNext(); 15 | var tabbrowser = browserWin.gBrowser; 16 | 17 | // Check each tab of this browser instance 18 | var numTabs = tabbrowser.browsers.length; 19 | for (var index = 0; index < numTabs; index++) { 20 | var currentBrowser = tabbrowser.getBrowserAtIndex(index); 21 | //if (url == currentBrowser.currentURI.spec) { 22 | if (currentBrowser.currentURI.spec.indexOf(url) == 0) { 23 | 24 | // The URL is already opened. Select this tab. 25 | tabbrowser.selectedTab = tabbrowser.tabContainer.childNodes[index]; 26 | 27 | // Focus *this* browser-window 28 | browserWin.focus(); 29 | 30 | found = true; 31 | break; 32 | } 33 | } 34 | } 35 | 36 | // Our URL isn't open. Open it now. 37 | if (!found) { 38 | var recentWindow = wm.getMostRecentWindow("navigator:browser"); 39 | if (recentWindow) { 40 | // Use an existing browser window 41 | recentWindow.delayedOpenTab(url, null, null, null, null); 42 | } 43 | else { 44 | // No browser windows are open, so open a new one. 45 | window.open(url); 46 | } 47 | } 48 | } 49 | // }}} 50 | 51 | var cur_host = ""; 52 | 53 | var tabchange = function(e){ 54 | var browser = gBrowser.selectedBrowser; 55 | cur_host = browser.contentWindow.window.location.hostname; 56 | }; 57 | 58 | 59 | var opentab = function(t, line){ 60 | var url = null; 61 | if(t == 'EDITOR'){ 62 | url = EDITOR_URL; 63 | }else if (t == 'PERMHELP'){ 64 | url = PERM_HELP_URL; 65 | }else{ 66 | url = t; 67 | } 68 | 69 | if(url){ 70 | 71 | HostAdmin.cursorline = line; 72 | 73 | openAndReuseOneTabPerURL(url); 74 | document.getElementById("hostadmin-menu-panel").hidePopup(); 75 | 76 | HostAdmin.requestCursorLine(line) 77 | } 78 | }; 79 | 80 | HostAdmin.container = { 81 | opentab : opentab, 82 | curhost : function(){ return cur_host; } 83 | }; 84 | 85 | var popuphelper = { 86 | HostAdmin : HostAdmin 87 | }; 88 | var host_admin = HostAdmin.core; 89 | 90 | window.addEventListener('DOMWindowCreated', function(e){ 91 | if( 92 | e.target.documentURI.indexOf(document.getElementById('hostadmin-menu-content').getAttribute('src')) === 0 93 | || 94 | e.target.documentURI.indexOf(EDITOR_URL) === 0 95 | ){ 96 | e.target.defaultView.window.firefox = popuphelper; 97 | } 98 | }, true); 99 | 100 | window.addEventListener("load", function(){ 101 | gBrowser.tabContainer.addEventListener("TabOpen", tabchange, false); 102 | gBrowser.tabContainer.addEventListener("TabSelect", tabchange, false); 103 | gBrowser.tabContainer.addEventListener("TabAttrModified", tabchange, false); 104 | 105 | var button = document.getElementById('hostadmin-toolbar-button'); 106 | if(button) 107 | button.addEventListener('command', function(e){ 108 | var menucontent = document.getElementById('hostadmin-menu-content').contentWindow; 109 | menucontent.focus(); 110 | // TODO dup code from popup.js 111 | host_admin.refresh(); 112 | var $ = menucontent.window.$; 113 | var searchval = host_admin.real_hostname(cur_host); 114 | $("#search input").val(searchval).select().keyup(); 115 | }, false); 116 | }, false); 117 | 118 | 119 | })(window.HostAdmin); 120 | -------------------------------------------------------------------------------- /npapi/src/npapi_headers/nptypes.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 | /* ***** BEGIN LICENSE BLOCK ***** 3 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.mozilla.org/MPL/ 9 | * 10 | * Software distributed under the License is distributed on an "AS IS" basis, 11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 12 | * for the specific language governing rights and limitations under the 13 | * License. 14 | * 15 | * The Original Code is mozilla.org code. 16 | * 17 | * The Initial Developer of the Original Code is 18 | * mozilla.org. 19 | * Portions created by the Initial Developer are Copyright (C) 2004 20 | * the Initial Developer. All Rights Reserved. 21 | * 22 | * Contributor(s): 23 | * Johnny Stenback (Original author) 24 | * 25 | * Alternatively, the contents of this file may be used under the terms of 26 | * either the GNU General Public License Version 2 or later (the "GPL"), or 27 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 28 | * in which case the provisions of the GPL or the LGPL are applicable instead 29 | * of those above. If you wish to allow use of your version of this file only 30 | * under the terms of either the GPL or the LGPL, and not to allow others to 31 | * use your version of this file under the terms of the MPL, indicate your 32 | * decision by deleting the provisions above and replace them with the notice 33 | * and other provisions required by the GPL or the LGPL. If you do not delete 34 | * the provisions above, a recipient may use your version of this file under 35 | * the terms of any one of the MPL, the GPL or the LGPL. 36 | * 37 | * ***** END LICENSE BLOCK ***** */ 38 | 39 | #ifndef nptypes_h_ 40 | #define nptypes_h_ 41 | 42 | /* 43 | * Header file for ensuring that C99 types ([u]int32_t, [u]int64_t and bool) and 44 | * true/false macros are available. 45 | */ 46 | 47 | #if defined(WIN32) || defined(OS2) 48 | /* 49 | * Win32 and OS/2 don't know C99, so define [u]int_16/32/64 here. The bool 50 | * is predefined tho, both in C and C++. 51 | */ 52 | typedef short int16_t; 53 | typedef unsigned short uint16_t; 54 | typedef int int32_t; 55 | typedef unsigned int uint32_t; 56 | typedef long long int64_t; 57 | typedef unsigned long long uint64_t; 58 | #elif defined(_AIX) || defined(__sun) || defined(__osf__) || defined(IRIX) || defined(HPUX) 59 | /* 60 | * AIX and SunOS ship a inttypes.h header that defines [u]int32_t, 61 | * but not bool for C. 62 | */ 63 | #include 64 | 65 | #ifndef __cplusplus 66 | typedef int bool; 67 | #define true 1 68 | #define false 0 69 | #endif 70 | #elif defined(bsdi) || defined(FREEBSD) || defined(OPENBSD) 71 | /* 72 | * BSD/OS, FreeBSD, and OpenBSD ship sys/types.h that define int32_t and 73 | * u_int32_t. 74 | */ 75 | #include 76 | 77 | /* 78 | * BSD/OS ships no header that defines uint32_t, nor bool (for C) 79 | */ 80 | #if defined(bsdi) 81 | typedef u_int32_t uint32_t; 82 | typedef u_int64_t uint64_t; 83 | 84 | #if !defined(__cplusplus) 85 | typedef int bool; 86 | #define true 1 87 | #define false 0 88 | #endif 89 | #else 90 | /* 91 | * FreeBSD and OpenBSD define uint32_t and bool. 92 | */ 93 | #include 94 | #include 95 | #endif 96 | #elif defined(BEOS) 97 | #include 98 | #else 99 | /* 100 | * For those that ship a standard C99 stdint.h header file, include 101 | * it. Can't do the same for stdbool.h tho, since some systems ship 102 | * with a stdbool.h file that doesn't compile! 103 | */ 104 | #include 105 | 106 | #ifndef __cplusplus 107 | #if !defined(__GNUC__) || (__GNUC__ > 2 || __GNUC_MINOR__ > 95) 108 | #include 109 | #else 110 | /* 111 | * GCC 2.91 can't deal with a typedef for bool, but a #define 112 | * works. 113 | */ 114 | #define bool int 115 | #define true 1 116 | #define false 0 117 | #endif 118 | #endif 119 | #endif 120 | 121 | #endif /* nptypes_h_ */ 122 | -------------------------------------------------------------------------------- /dist-firefox.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # build.sh -- builds JAR and XPI files for mozilla extensions 3 | # by Nickolay Ponomarev 4 | # (original version based on Nathan Yergler's build script) 5 | # Most recent version is at 6 | 7 | # This script assumes the following directory structure: 8 | # ./ 9 | # chrome.manifest (optional - for newer extensions) 10 | # install.rdf 11 | # (other files listed in $ROOT_FILES) 12 | # 13 | # content/ | 14 | # locale/ |} these can be named arbitrary and listed in $CHROME_PROVIDERS 15 | # skin/ | 16 | # 17 | # defaults/ | 18 | # components/ |} these must be listed in $ROOT_DIRS in order to be packaged 19 | # ... | 20 | # 21 | # It uses a temporary directory ./build when building; don't use that! 22 | # Script's output is: 23 | # ./$APP_NAME.xpi 24 | # ./$APP_NAME.jar (only if $KEEP_JAR=1) 25 | # ./files -- the list of packaged files 26 | # 27 | # Note: It modifies chrome.manifest when packaging so that it points to 28 | # chrome/$APP_NAME.jar!/* 29 | 30 | # 31 | # default configuration file is ./config_build.sh, unless another file is 32 | # specified in command-line. Available config variables: 33 | #APP_NAME= # short-name, jar and xpi files name. Must be lowercase with no spaces 34 | #CHROME_PROVIDERS= # which chrome providers we have (space-separated list) 35 | #CLEAN_UP= # delete the jar / "files" when done? (1/0) 36 | #ROOT_FILES= # put these files in root of xpi (space separated list of leaf filenames) 37 | #ROOT_DIRS= # ...and these directories (space separated list) 38 | #BEFORE_BUILD= # run this before building (bash command) 39 | #AFTER_BUILD= # ...and this after the build (bash command) 40 | 41 | APP_NAME=firefox-hostadmin-`grep '\(.*\)<\/em:version>' install.rdf |grep '(\d+\.?)+' -Po` 42 | CHROME_PROVIDERS="container/firefox/ core/ icons/" 43 | CLEAN_UP=1 44 | ROOT_DIRS="defaults/" 45 | BEFORE_BUILD= 46 | AFTER_BUILD= 47 | 48 | #if [ -z $1 ]; then 49 | # . ./dist-firefox-config.sh 50 | #else 51 | # . $1 52 | #fi 53 | 54 | if [ -z $APP_NAME ]; then 55 | echo "You need to create build config file first!" 56 | echo "Read comments at the beginning of this script for more info." 57 | exit; 58 | fi 59 | 60 | ROOT_DIR=`pwd` 61 | TMP_DIR=build 62 | 63 | #uncomment to debug 64 | #set -x 65 | 66 | # remove any left-over files from previous build 67 | rm -f $APP_NAME.jar $APP_NAME.xpi files 68 | rm -rf $TMP_DIR 69 | 70 | $BEFORE_BUILD 71 | 72 | mkdir --parents --verbose $TMP_DIR/chrome 73 | 74 | # generate the JAR file, excluding CVS, SVN, and temporary files 75 | JAR_FILE=$TMP_DIR/chrome/$APP_NAME.jar 76 | echo "Generating $JAR_FILE..." 77 | for CHROME_SUBDIR in $CHROME_PROVIDERS; do 78 | find $CHROME_SUBDIR \( -path '*CVS*' -o -name '.*' \) -prune -o -type f -print | grep -v \~ >> files 79 | done 80 | 81 | zip -0 -r $JAR_FILE -@ < files 82 | # The following statement should be used instead if you don't wish to use the JAR file 83 | #cp --verbose --parents `cat files` $TMP_DIR/chrome 84 | 85 | # prepare components and defaults 86 | echo "Copying various files to $TMP_DIR folder..." 87 | for DIR in $ROOT_DIRS; do 88 | mkdir $TMP_DIR/$DIR 89 | FILES="`find $DIR \( -path '*CVS*' -o -name '.*' \) -prune -o -type f -print | grep -v \~`" 90 | echo $FILES >> files 91 | cp --verbose --parents $FILES $TMP_DIR 92 | done 93 | 94 | # Copy other files to the root of future XPI. 95 | for ROOT_FILE in $ROOT_FILES install.rdf chrome.manifest; do 96 | cp --verbose $ROOT_FILE $TMP_DIR 97 | if [ -f $ROOT_FILE ]; then 98 | echo $ROOT_FILE >> files 99 | fi 100 | done 101 | 102 | cd $TMP_DIR 103 | 104 | if [ -f "chrome.manifest" ]; then 105 | echo "Preprocessing chrome.manifest..." 106 | # You think this is scary? 107 | #s/^(content\s+\S*\s+)(\S*\/)(.*)$/\1jar:chrome\/$APP_NAME\.jar!\/\2\3/ 108 | #s/^(skin|locale)(\s+\S*\s+\S*\s+)(.*\/)$/\1\2jar:chrome\/$APP_NAME\.jar!\/\3/ 109 | # 110 | # Then try this! (Same, but with characters escaped for bash :) 111 | sed -i -r s/^\(content\\s+\\S*\\s+\)\(\\S*\\/\)\(.*\)$/\\1jar:chrome\\/$APP_NAME\\.jar!\\/\\2\\3/ chrome.manifest 112 | sed -i -r s/^\(skin\|locale\)\(\\s+\\S*\\s+\\S*\\s+\)\(.*\\/\)$/\\1\\2jar:chrome\\/$APP_NAME\\.jar!\\/\\3/ chrome.manifest 113 | 114 | # (it simply adds jar:chrome/whatever.jar!/ at appropriate positions of chrome.manifest) 115 | fi 116 | 117 | # generate the XPI file 118 | echo "Generating $APP_NAME.xpi..." 119 | zip -r ../$APP_NAME.xpi * 120 | 121 | cd "$ROOT_DIR" 122 | 123 | echo "Cleanup..." 124 | if [ $CLEAN_UP = 0 ]; then 125 | # save the jar file 126 | mv $TMP_DIR/chrome/$APP_NAME.jar . 127 | else 128 | rm ./files 129 | fi 130 | 131 | # remove the working files 132 | rm -rf $TMP_DIR 133 | echo "Done!" 134 | 135 | $AFTER_BUILD 136 | -------------------------------------------------------------------------------- /npapi/src/hostadmin.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 25 | 28 | 31 | 34 | 37 | 40 | 53 | 56 | 59 | 62 | 70 | 73 | 76 | 79 | 82 | 85 | 88 | 92 | 93 | 99 | 102 | 106 | 109 | 112 | 115 | 125 | 128 | 131 | 134 | 144 | 147 | 150 | 153 | 156 | 159 | 162 | 166 | 167 | 168 | 169 | 170 | 171 | 176 | 179 | 180 | 183 | 184 | 187 | 188 | 191 | 192 | 195 | 196 | 199 | 200 | 201 | 206 | 209 | 210 | 211 | 216 | 219 | 220 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | -------------------------------------------------------------------------------- /core/editor.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | HostAdmin Host Editor 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 58 | 59 | 60 |
61 | 62 |

HostAdmin Host Editor

63 |
64 | Write hosts file failed check permissions, Learn more 65 |
66 |
67 |
68 |
69 |
70 | 79 |
80 |
81 |
82 |
83 |

Common Hosts File Syntax

84 |
 85 |   [#] <IP> <HOSTNAME_1> [<HOSTNAME_2>] [# COMMENT]
 86 | 
87 |

Note

88 |

Setting facultative [COMMENT] with 'hide' word prevents this line to be managed by HostAdmin and will not be displayed on quick edit tool.

89 | 90 |

Example

91 |
 92 |   127.0.0.1 localhost # hide
 93 | 
94 |
95 |
96 |

Grouping

97 |
 98 | #==== GROUPNAME
 99 |   [#] <IP_2>	<HOSTNAME_2> [<HOSTNAME_3>] [# COMMENT]
100 |   [#] <IP_3>	<HOSTNAME_4> [<HOSTNAME_5>] [# COMMENT]
101 |   [...]
102 | #====
103 | 
104 |

Example

105 |
106 | #==== Project 1
107 |   #127.0.0.1	localhost1
108 |   127.0.0.1	localhost2
109 |   127.0.0.1	localhost3
110 | #====
111 | 
112 | #==== Project 2
113 |   #127.0.0.1	localhost1
114 |   #127.0.0.1	localhost2
115 |   #127.0.0.1	localhost3
116 | #====
117 | 
118 |

Note

119 |

Grouping "hosts lines" let you enable/disable all records in group just clicking group name into "quick edit tool" in the bottom. These lines will have also a tag that will display the group name of appurtenance.

120 |
121 |
122 |

Bulk Hide

123 |
124 | #hide_all_of_below
125 | ....
126 | #All text here will be parsed as comment
127 | ....
128 | 
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |

139 |
Hosts file
   140 |

141 |
142 |
143 |
144 | 145 |
146 |
147 |
148 |
149 | 155 |
156 | 165 | 166 | 167 | Fork me on GitHub 168 | 169 | 170 | -------------------------------------------------------------------------------- /container/firefox/host_file_wrapper.js: -------------------------------------------------------------------------------- 1 | // HostAdmin 2 | // by T.G.(farmer1992@gmail.com) 3 | // 4 | // file wrapper module 5 | // enable hostadmin read and set hosts file 6 | // 7 | (function(HostAdmin){ 8 | 9 | // copy from io.js 10 | // http://kb.mozillazine.org/Dev_:_Extensions_:_Example_Code_:_File_IO_:_jsio 11 | var FileIO = { 12 | 13 | localfileCID : '@mozilla.org/file/local;1', 14 | localfileIID : Components.interfaces.nsIFile, 15 | 16 | finstreamCID : '@mozilla.org/network/file-input-stream;1', 17 | finstreamIID : Components.interfaces.nsIFileInputStream, 18 | 19 | foutstreamCID : '@mozilla.org/network/file-output-stream;1', 20 | foutstreamIID : Components.interfaces.nsIFileOutputStream, 21 | 22 | sinstreamCID : '@mozilla.org/scriptableinputstream;1', 23 | sinstreamIID : Components.interfaces.nsIScriptableInputStream, 24 | 25 | suniconvCID : '@mozilla.org/intl/scriptableunicodeconverter', 26 | suniconvIID : Components.interfaces.nsIScriptableUnicodeConverter, 27 | 28 | open : function(path) { 29 | try { 30 | var file = Components.classes[this.localfileCID] 31 | .createInstance(this.localfileIID); 32 | file.initWithPath(path); 33 | return file; 34 | } 35 | catch(e) { 36 | return false; 37 | } 38 | }, 39 | 40 | read : function(file, charset) { 41 | try { 42 | var data = new String(); 43 | var fiStream = Components.classes[this.finstreamCID] 44 | .createInstance(this.finstreamIID); 45 | var siStream = Components.classes[this.sinstreamCID] 46 | .createInstance(this.sinstreamIID); 47 | fiStream.init(file, 1, 0, false); 48 | siStream.init(fiStream); 49 | data += siStream.read(-1); 50 | siStream.close(); 51 | fiStream.close(); 52 | if (charset) { 53 | data = this.toUnicode(charset, data); 54 | } 55 | return data; 56 | } 57 | catch(e) { 58 | return false; 59 | } 60 | }, 61 | 62 | write : function(file, data, mode, charset) { 63 | try { 64 | var foStream = Components.classes[this.foutstreamCID] 65 | .createInstance(this.foutstreamIID); 66 | if (charset) { 67 | data = this.fromUnicode(charset, data); 68 | } 69 | var flags = 0x02 | 0x08 | 0x20; // wronly | create | truncate 70 | if (mode == 'a') { 71 | flags = 0x02 | 0x10; // wronly | append 72 | } 73 | foStream.init(file, flags, 0664, 0); 74 | foStream.write(data, data.length); 75 | // foStream.flush(); 76 | foStream.close(); 77 | return true; 78 | } 79 | catch(e) { 80 | return false; 81 | } 82 | }, 83 | 84 | create : function(file) { 85 | try { 86 | file.create(0x00, 0664); 87 | return true; 88 | } 89 | catch(e) { 90 | return false; 91 | } 92 | }, 93 | 94 | unlink : function(file) { 95 | try { 96 | file.remove(false); 97 | return true; 98 | } 99 | catch(e) { 100 | return false; 101 | } 102 | }, 103 | 104 | path : function(file) { 105 | try { 106 | return 'file:///' + file.path.replace(/\\/g, '\/') 107 | .replace(/^\s*\/?/, '').replace(/\ /g, '%20'); 108 | } 109 | catch(e) { 110 | return false; 111 | } 112 | }, 113 | 114 | toUnicode : function(charset, data) { 115 | try{ 116 | var uniConv = Components.classes[this.suniconvCID] 117 | .createInstance(this.suniconvIID); 118 | uniConv.charset = charset; 119 | data = uniConv.ConvertToUnicode(data); 120 | } 121 | catch(e) { 122 | // foobar! 123 | } 124 | return data; 125 | }, 126 | 127 | fromUnicode : function(charset, data) { 128 | try { 129 | var uniConv = Components.classes[this.suniconvCID] 130 | .createInstance(this.suniconvIID); 131 | uniConv.charset = charset; 132 | data = uniConv.ConvertFromUnicode(data); 133 | // data += uniConv.Finish(); 134 | } 135 | catch(e) { 136 | // foobar! 137 | } 138 | return data; 139 | } 140 | 141 | }; 142 | 143 | var fire_config = HostAdmin.config; 144 | 145 | var host_file_wrapper = (function(){ 146 | const os = Components.classes["@mozilla.org/xre/app-info;1"].getService(Components.interfaces.nsIXULRuntime).OS; 147 | var splitchar = "\n"; 148 | 149 | 150 | var file_names = []; 151 | 152 | fire_config.run_when_not_equal("hostsfilepath", "default", function(configpath){ 153 | file_names.push(configpath); 154 | }); 155 | 156 | if (os == "WINNT"){ 157 | splitchar = "\r\n"; 158 | try { 159 | var winDir = Components.classes["@mozilla.org/file/directory_service;1"]. 160 | getService(Components.interfaces.nsIProperties).get("WinD", Components.interfaces.nsIFile); 161 | file_names.push(winDir.path + "\\system32\\drivers\\etc\\hosts"); 162 | } 163 | catch (err) {} 164 | 165 | file_names.push("C:\\windows\\system32\\drivers\\etc\\hosts"); 166 | }else if(os == "Linux"){ 167 | file_names.push("/etc/hosts"); 168 | }else if(os == "Darwin"){ 169 | file_names.push("/etc/hosts"); 170 | } 171 | 172 | var file_name; 173 | for(var i in file_names){ 174 | file_name = file_names[i]; 175 | var _f = FileIO.open(file_name); 176 | if(_f && _f.exists()){ 177 | break; 178 | } 179 | } 180 | 181 | var charset = "utf8"; // null means auto 182 | 183 | // detect using jschardet 184 | // but maybe unqualified 185 | if(!charset){ 186 | // -- temp for windows before charset detector 187 | if (os == "WINNT"){ 188 | charset = 'gbk'; 189 | } 190 | 191 | //var file = FileIO.open(file_name); 192 | //charset = jschardet.detect(FileIO.read(file)); 193 | //charset = charset ? charset.encoding : "utf8"; 194 | } 195 | 196 | fire_config.run_when_not_equal("charset", "auto", function(c){ 197 | charset = c; 198 | }); 199 | 200 | return { 201 | get : function(){ 202 | var file = FileIO.open(file_name); 203 | return FileIO.read(file, charset); 204 | } 205 | , 206 | set : function(data){ 207 | if (os == "WINNT"){ 208 | data = data.replace(/([^\r])\n/g, "$1\r\n"); 209 | } 210 | 211 | var file = FileIO.open(file_name); 212 | return FileIO.write(file, data, '', charset); 213 | } 214 | , 215 | time : function(){ 216 | var file = FileIO.open(file_name); 217 | return file.lastModifiedTime; 218 | } 219 | , 220 | splitchar : splitchar 221 | }; 222 | })(); 223 | 224 | HostAdmin.host_file_wrapper = host_file_wrapper; 225 | })(window.HostAdmin); 226 | -------------------------------------------------------------------------------- /core/popup.js: -------------------------------------------------------------------------------- 1 | run_from_glue(function(HostAdmin){ 2 | var host_admin = HostAdmin.core; 3 | var event_host = HostAdmin.event_host; 4 | var configure = HostAdmin.config; 5 | 6 | var container = HostAdmin.container; 7 | var searchval = container.curhost(); 8 | var opentab = container.opentab; 9 | 10 | var searchbar = $("#search input"); 11 | 12 | var save_alert = function(r){ 13 | if(r){ 14 | $(".alert").hide('slow'); 15 | }else{ 16 | $(".alert").show('slow'); 17 | } 18 | }; 19 | 20 | var host_ul = $("#list"); 21 | 22 | var weight = function(stra, strb){ 23 | var l = new Levenshtein(stra, strb); 24 | l = l.distance / l.longestDistance(); 25 | 26 | // Rule 27 | var p = strb.indexOf(stra); 28 | if(p === 0) l -= 0.15; 29 | if(p > 0) l -= 0.1; 30 | 31 | if(stra[0] == strb[0]) l -= 0.1; 32 | 33 | return l; 34 | }; 35 | 36 | var GROUP_PLACE_HOLDER_KEY = '@GROUP'; 37 | var findhost = function(wanted, hosts, group_names){ 38 | var found = []; 39 | var min_groupl = 1; 40 | 41 | for (var h in hosts){ 42 | var minl = weight(wanted, h); 43 | 44 | for(var i in hosts[h]){ 45 | var host = hosts[h][i]; 46 | var gn = group_names[host.group]; 47 | 48 | if (gn) { 49 | var gl = weight(wanted, gn); 50 | minl = Math.min(minl, gl); 51 | min_groupl = Math.min(min_groupl, gl); 52 | } 53 | 54 | var comment = host.comment; 55 | if (comment) { 56 | minl = Math.min(minl, weight(wanted, comment)); 57 | } 58 | 59 | } 60 | 61 | found.push({'host': h , 'ld': minl}); 62 | } 63 | found.push({'host': GROUP_PLACE_HOLDER_KEY , 'ld': configure.get('groupup') ? 0 : min_groupl}); 64 | 65 | 66 | // TODO insert might be better 67 | found.sort(function(a,b) { return a.ld - b.ld; }); 68 | return found; 69 | }; 70 | 71 | var make_host_item = function(host,h,i){ 72 | 73 | var a = $('' + 74 | host.addr + (host.comment ? '' + host.comment + '' : '' ) + 75 | // ''); 76 | ''); 77 | 78 | a.click(function(){ 79 | save_alert(host_admin.host_toggle_and_save(h, i)); 80 | }); 81 | 82 | var em = $(''); 83 | em.click(function(){ 84 | opentab('EDITOR', host.line); 85 | }); 86 | 87 | var li = $("
  • ").append(a); 88 | li.prepend(em); 89 | 90 | if(host.using){ 91 | li.find('i.icon-').addClass('icon-ok'); 92 | } 93 | 94 | if(host.group > 0){ 95 | a.hover(function(){ 96 | var group = li.find('i.hostgroup'); 97 | group.addClass('icon-folder-open'); 98 | }); 99 | } 100 | 101 | return li; 102 | }; 103 | 104 | var make_host_header = function(h, wanted){ 105 | var em = $(''); 106 | em.attr('title', 'Open http://' + h); 107 | em.click(function(){ 108 | opentab('http://' + h); 109 | }); 110 | var li = $('
  • '); 111 | li.html(h.replace(wanted, '' + wanted + '')); 112 | li.prepend(em); 113 | 114 | return li; 115 | }; 116 | 117 | var make_group_item = function(group_name, group_id, host_list){ 118 | var a = $('' + group_name + '' + '' +''); 119 | 120 | a.click(function(){ 121 | save_alert(host_admin.group_toggle_and_save(host_list, group_id)); 122 | }); 123 | 124 | var li = $("
  • ").append(a); 125 | 126 | if(host_admin.group_checked(host_list, group_id)){ 127 | li.find('i').addClass('icon-ok'); 128 | } 129 | 130 | return li; 131 | }; 132 | 133 | var redraw = function(){ 134 | var wanted = searchbar.val(); 135 | wanted = $.trim(wanted); 136 | 137 | var oldcontainer = host_ul.find("div"); 138 | var newcontainer = $("
    "); 139 | var hosts = host_admin.get_hosts(); 140 | var group_names = host_admin.get_groups(); 141 | var groups = []; 142 | 143 | var group_place_holder = null; 144 | 145 | findhost(wanted, hosts, group_names).forEach(function(h){ 146 | h = h.host; 147 | var hul = $("
      "); 148 | hul.addClass('nav nav-list'); 149 | 150 | if(h === GROUP_PLACE_HOLDER_KEY){ 151 | group_place_holder = hul; 152 | }else{ 153 | var added = false; 154 | var addblock = {}; 155 | for(var i in hosts[h]){ 156 | 157 | var host = hosts[h][i]; 158 | 159 | if(host.hide){ 160 | continue; 161 | } 162 | 163 | if(!added){ 164 | hul.append(make_host_header(h, wanted)); 165 | added = true; 166 | } 167 | 168 | var g = host.group; 169 | var gn = group_names[g]; 170 | if(gn){ 171 | if(typeof groups[g] == "undefined"){ 172 | groups[g] = []; 173 | } 174 | 175 | groups[g].push(h); 176 | 177 | if(!host.comment){ 178 | host.comment = gn; 179 | } 180 | } 181 | 182 | // auto merge blocker 183 | // do not block if has comment 184 | if(host.comment || !addblock[host.addr]){ 185 | addblock[host.addr] = true; 186 | hul.append(make_host_item(host, h, i)); 187 | } 188 | 189 | } 190 | } 191 | 192 | newcontainer.append(hul); 193 | }); 194 | 195 | if ( groups.length > 0){ 196 | 197 | var em = $(''); 198 | if(configure.get('groupup')){ 199 | em.addClass('icon-arrow-down'); 200 | }else{ 201 | em.addClass('icon-arrow-up'); 202 | } 203 | em.click(function(){ 204 | configure.set('groupup', !configure.get('groupup')); 205 | redraw(); 206 | }); 207 | var gul = group_place_holder; 208 | var gli = $('') 209 | gli.append(em); 210 | gul.append(gli); 211 | 212 | for(var group_id in groups){ 213 | var group_name = group_names[group_id]; 214 | var host_list = groups[group_id]; 215 | 216 | gul.append(make_group_item(group_name, group_id, host_list)); 217 | } 218 | }else{ 219 | // because of #hide 220 | group_place_holder.remove(); 221 | } 222 | 223 | oldcontainer.replaceWith(newcontainer); 224 | }; 225 | 226 | 227 | searchbar.keyup(function(){ 228 | redraw(); 229 | //host_ul.animate({scrollTop:0}, 'fast'); 230 | host_ul.scrollTop(0); 231 | }); 232 | 233 | $(document.body).keydown(function(){ 234 | searchbar.focus(); 235 | }); 236 | 237 | $("#openeditor").click(function(){ 238 | opentab('EDITOR'); 239 | }); 240 | 241 | $(".alert a").click(function(){ 242 | opentab('PERMHELP'); 243 | }); 244 | 245 | event_host.addEventListener('HostAdminRefresh', function(e) { 246 | redraw(); 247 | }, false); 248 | 249 | 250 | // -- init 251 | host_admin.refresh(); 252 | 253 | searchval = host_admin.real_hostname(searchval); 254 | searchbar.val(searchval).select(); 255 | 256 | redraw(); 257 | host_ul.scrollTop(0); 258 | } 259 | ); 260 | -------------------------------------------------------------------------------- /core/lib/CodeMirror/lib/codemirror.css: -------------------------------------------------------------------------------- 1 | /* BASICS */ 2 | 3 | .CodeMirror { 4 | /* Set height, width, borders, and global font properties here */ 5 | font-family: monospace; 6 | height: 300px; 7 | } 8 | .CodeMirror-scroll { 9 | /* Set scrolling behaviour here */ 10 | overflow: auto; 11 | } 12 | 13 | /* PADDING */ 14 | 15 | .CodeMirror-lines { 16 | padding: 4px 0; /* Vertical padding around content */ 17 | } 18 | .CodeMirror pre { 19 | padding: 0 4px; /* Horizontal padding of content */ 20 | } 21 | 22 | .CodeMirror-scrollbar-filler { 23 | background-color: white; /* The little square between H and V scrollbars */ 24 | } 25 | 26 | /* GUTTER */ 27 | 28 | .CodeMirror-gutters { 29 | border-right: 1px solid #ddd; 30 | background-color: #f7f7f7; 31 | } 32 | .CodeMirror-linenumbers {} 33 | .CodeMirror-linenumber { 34 | padding: 0 3px 0 5px; 35 | min-width: 20px; 36 | text-align: right; 37 | color: #999; 38 | } 39 | 40 | /* CURSOR */ 41 | 42 | .CodeMirror pre.CodeMirror-cursor { 43 | border-left: 1px solid black; 44 | } 45 | /* Shown when moving in bi-directional text */ 46 | .CodeMirror pre.CodeMirror-secondarycursor { 47 | border-left: 1px solid silver; 48 | } 49 | .cm-keymap-fat-cursor pre.CodeMirror-cursor { 50 | width: auto; 51 | border: 0; 52 | background: transparent; 53 | background: rgba(0, 200, 0, .4); 54 | filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#6600c800, endColorstr=#4c00c800); 55 | } 56 | /* Kludge to turn off filter in ie9+, which also accepts rgba */ 57 | .cm-keymap-fat-cursor pre.CodeMirror-cursor:not(#nonsense_id) { 58 | filter: progid:DXImageTransform.Microsoft.gradient(enabled=false); 59 | } 60 | /* Can style cursor different in overwrite (non-insert) mode */ 61 | .CodeMirror pre.CodeMirror-cursor.CodeMirror-overwrite {} 62 | 63 | /* DEFAULT THEME */ 64 | 65 | .cm-s-default .cm-keyword {color: #708;} 66 | .cm-s-default .cm-atom {color: #219;} 67 | .cm-s-default .cm-number {color: #164;} 68 | .cm-s-default .cm-def {color: #00f;} 69 | .cm-s-default .cm-variable {color: black;} 70 | .cm-s-default .cm-variable-2 {color: #05a;} 71 | .cm-s-default .cm-variable-3 {color: #085;} 72 | .cm-s-default .cm-property {color: black;} 73 | .cm-s-default .cm-operator {color: black;} 74 | .cm-s-default .cm-comment {color: #a50;} 75 | .cm-s-default .cm-string {color: #a11;} 76 | .cm-s-default .cm-string-2 {color: #f50;} 77 | .cm-s-default .cm-meta {color: #555;} 78 | .cm-s-default .cm-error {color: #f00;} 79 | .cm-s-default .cm-qualifier {color: #555;} 80 | .cm-s-default .cm-builtin {color: #30a;} 81 | .cm-s-default .cm-bracket {color: #997;} 82 | .cm-s-default .cm-tag {color: #170;} 83 | .cm-s-default .cm-attribute {color: #00c;} 84 | .cm-s-default .cm-header {color: blue;} 85 | .cm-s-default .cm-quote {color: #090;} 86 | .cm-s-default .cm-hr {color: #999;} 87 | .cm-s-default .cm-link {color: #00c;} 88 | 89 | .cm-negative {color: #d44;} 90 | .cm-positive {color: #292;} 91 | .cm-header, .cm-strong {font-weight: bold;} 92 | .cm-em {font-style: italic;} 93 | .cm-emstrong {font-style: italic; font-weight: bold;} 94 | .cm-link {text-decoration: underline;} 95 | 96 | .cm-invalidchar {color: #f00;} 97 | 98 | div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;} 99 | div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;} 100 | 101 | /* STOP */ 102 | 103 | /* The rest of this file contains styles related to the mechanics of 104 | the editor. You probably shouldn't touch them. */ 105 | 106 | .CodeMirror { 107 | line-height: 1; 108 | position: relative; 109 | overflow: hidden; 110 | } 111 | 112 | .CodeMirror-scroll { 113 | /* 30px is the magic margin used to hide the element's real scrollbars */ 114 | /* See overflow: hidden in .CodeMirror, and the paddings in .CodeMirror-sizer */ 115 | margin-bottom: -30px; margin-right: -30px; 116 | padding-bottom: 30px; padding-right: 30px; 117 | height: 100%; 118 | outline: none; /* Prevent dragging from highlighting the element */ 119 | position: relative; 120 | } 121 | .CodeMirror-sizer { 122 | position: relative; 123 | } 124 | 125 | /* The fake, visible scrollbars. Used to force redraw during scrolling 126 | before actuall scrolling happens, thus preventing shaking and 127 | flickering artifacts. */ 128 | .CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler { 129 | position: absolute; 130 | z-index: 6; 131 | display: none; 132 | } 133 | .CodeMirror-vscrollbar { 134 | right: 0; top: 0; 135 | overflow-x: hidden; 136 | overflow-y: scroll; 137 | } 138 | .CodeMirror-hscrollbar { 139 | bottom: 0; left: 0; 140 | overflow-y: hidden; 141 | overflow-x: scroll; 142 | } 143 | .CodeMirror-scrollbar-filler { 144 | right: 0; bottom: 0; 145 | z-index: 6; 146 | } 147 | 148 | .CodeMirror-gutters { 149 | position: absolute; left: 0; top: 0; 150 | height: 100%; 151 | z-index: 3; 152 | } 153 | .CodeMirror-gutter { 154 | height: 100%; 155 | display: inline-block; 156 | /* Hack to make IE7 behave */ 157 | *zoom:1; 158 | *display:inline; 159 | } 160 | .CodeMirror-gutter-elt { 161 | position: absolute; 162 | cursor: default; 163 | z-index: 4; 164 | } 165 | 166 | .CodeMirror-lines { 167 | cursor: text; 168 | } 169 | .CodeMirror pre { 170 | /* Reset some styles that the rest of the page might have set */ 171 | -moz-border-radius: 0; -webkit-border-radius: 0; -o-border-radius: 0; border-radius: 0; 172 | border-width: 0; 173 | background: transparent; 174 | font-family: inherit; 175 | font-size: inherit; 176 | margin: 0; 177 | white-space: pre; 178 | word-wrap: normal; 179 | line-height: inherit; 180 | color: inherit; 181 | z-index: 2; 182 | position: relative; 183 | overflow: visible; 184 | } 185 | .CodeMirror-wrap pre { 186 | word-wrap: break-word; 187 | white-space: pre-wrap; 188 | word-break: normal; 189 | } 190 | .CodeMirror-linebackground { 191 | position: absolute; 192 | left: 0; right: 0; top: 0; bottom: 0; 193 | z-index: 0; 194 | } 195 | 196 | .CodeMirror-linewidget { 197 | position: relative; 198 | z-index: 2; 199 | } 200 | 201 | .CodeMirror-wrap .CodeMirror-scroll { 202 | overflow-x: hidden; 203 | } 204 | 205 | .CodeMirror-measure { 206 | position: absolute; 207 | width: 100%; height: 0px; 208 | overflow: hidden; 209 | visibility: hidden; 210 | } 211 | .CodeMirror-measure pre { position: static; } 212 | 213 | .CodeMirror pre.CodeMirror-cursor { 214 | position: absolute; 215 | visibility: hidden; 216 | border-right: none; 217 | width: 0; 218 | } 219 | .CodeMirror-focused pre.CodeMirror-cursor { 220 | visibility: visible; 221 | } 222 | 223 | .CodeMirror-selected { background: #d9d9d9; } 224 | .CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; } 225 | 226 | .CodeMirror-searching { 227 | background: #ffa; 228 | background: rgba(255, 255, 0, .4); 229 | } 230 | 231 | /* IE7 hack to prevent it from returning funny offsetTops on the spans */ 232 | .CodeMirror span { *vertical-align: text-bottom; } 233 | 234 | @media print { 235 | /* Hide the cursor when printing */ 236 | .CodeMirror pre.CodeMirror-cursor { 237 | visibility: hidden; 238 | } 239 | } 240 | -------------------------------------------------------------------------------- /container/firefox/statusbar.js: -------------------------------------------------------------------------------- 1 | // TODO this file has too many duplicate code 2 | // clean up needed 3 | ;(function(HostAdmin){ 4 | 5 | var host_admin = HostAdmin.core; 6 | var event_host = HostAdmin.event_host; 7 | var container = HostAdmin.container; 8 | var opentab = container.opentab; 9 | 10 | var nslookup = function(cb, hostname){ 11 | var dnsService = Components.classes["@mozilla.org/network/dns-service;1"].getService(Components.interfaces.nsIDNSService); 12 | 13 | try{ 14 | var records = dnsService.asyncResolve(hostname, 0, { 15 | onLookupComplete: function(aRequest, aRecord, aStatus){ 16 | var ip = aRecord.getNextAddrAsString(); 17 | cb(ip); 18 | return; 19 | } 20 | }, null); 21 | }catch(e){ 22 | } 23 | 24 | cb(""); 25 | }; 26 | 27 | var updatelb = function(){ 28 | var _curHost = container.curhost(); 29 | 30 | nslookup(function(ip){ 31 | var curHost = host_admin.real_hostname(_curHost); 32 | var comment = "Not in Hosts"; 33 | var hosts = host_admin.get_hosts(); 34 | if (typeof hosts[curHost] != "undefined") { 35 | hosts = hosts[curHost]; 36 | for (var i in hosts){ 37 | comment = "In Hosts"; 38 | if(hosts[i].using){ 39 | ip = hosts[i].addr; 40 | comment = hosts[i].comment; 41 | break; 42 | } 43 | } 44 | } 45 | 46 | if (_curHost == container.curhost()) 47 | document.getElementById("hostadmin-label").value = ip + " " + comment; 48 | 49 | }, _curHost); 50 | }; 51 | 52 | var save_alert = function(r){ 53 | if(!r){ 54 | try{ 55 | var alertsService = Components.classes["@mozilla.org/alerts-service;1"] 56 | .getService(Components.interfaces.nsIAlertsService); 57 | 58 | alertsService.showAlertNotification('chrome://hostadmin-icons/content/icon32.png', 'HostAdmin', 59 | 'Write hosts file failed check permissions, Click to Learn more', 60 | true, null,{ 61 | observe: function(subject, topic, data) { 62 | if(topic == 'alertclickcallback'){ 63 | opentab('PERMHELP'); 64 | } 65 | } 66 | }); 67 | }catch(e){} // mac without growl 68 | } 69 | }; 70 | 71 | var mk_menu_item = function(hostname, host , host_index){ 72 | var mi = document.createElement("menuitem"); 73 | mi.setAttribute("label",host.addr); 74 | mi.setAttribute("acceltext", host.comment.substr(0,20)); 75 | mi.setAttribute("description", "Double Click to Visit"); 76 | mi.setAttribute("type","checkbox"); 77 | mi.addEventListener("command", function(){ 78 | save_alert(host_admin.host_toggle_and_save(hostname, host_index)); 79 | }, false); 80 | 81 | if(host.using){ 82 | mi.setAttribute("checked",true); 83 | } 84 | return mi; 85 | }; 86 | 87 | var mk_menu_gp_item = function(group_name, group_id, host_list){ 88 | var mi = document.createElement("menuitem"); 89 | mi.setAttribute("label", group_name.substr(0,35)); 90 | mi.setAttribute("acceltext", "Group"); 91 | mi.setAttribute("type","checkbox"); 92 | mi.addEventListener("command", function(){ 93 | save_alert(host_admin.group_toggle_and_save(host_list, group_id)); 94 | }, false); 95 | if(host_admin.group_checked(host_list, group_id)){ 96 | mi.setAttribute("checked",true); 97 | } 98 | return mi; 99 | }; 100 | 101 | var editor_item = (function(){ 102 | var mi = document.createElement("menuitem"); 103 | mi.setAttribute("label", "Host Editor"); 104 | 105 | mi.addEventListener("command", function(){ 106 | opentab('EDITOR'); 107 | }, false); 108 | return mi; 109 | })(); 110 | 111 | // {{{ refresh menu 112 | var refresh_menu = function(){ 113 | var curHost = container.curhost(); 114 | var menu = document.getElementById("hostadmin-popup"); 115 | 116 | while (menu.lastChild) menu.removeChild(menu.lastChild); 117 | var hosts = host_admin.get_hosts(); 118 | var group_names = host_admin.get_groups(); 119 | var groups = []; 120 | 121 | var hasOther = false; 122 | var tosortKey = []; 123 | var tosortM = []; 124 | 125 | for (var h in hosts){ 126 | var sub = document.createElement("menu"); 127 | sub.setAttribute("label", h); 128 | 129 | sub.addEventListener("dblclick", (function(h){ 130 | return function(){ 131 | opentab("http://" + h); 132 | }; 133 | })(h), false); 134 | 135 | sub.setAttribute("acceltext", h.charAt(0).toUpperCase()); 136 | var popup = document.createElement("menupopup"); 137 | sub.appendChild(popup); 138 | 139 | var hide = true; 140 | var addblock = {}; 141 | // TODO clean up 142 | for (var i in hosts[h]){ 143 | var host = hosts[h][i]; 144 | 145 | if(host.hide){ 146 | continue; 147 | } 148 | 149 | if(host.comment || !addblock[host.addr]){ 150 | addblock[host.addr] = true; 151 | popup.appendChild(mk_menu_item(h, hosts[h][i], i)); 152 | hasOther = true; 153 | hide = false; 154 | } 155 | 156 | var g = hosts[h][i].group; 157 | var gn = group_names[g]; 158 | if(gn){ 159 | if(typeof groups[g] == "undefined"){ 160 | groups[g] = []; 161 | } 162 | 163 | groups[g].push(h); 164 | } 165 | } 166 | 167 | if(!hide && h!= curHost){ 168 | tosortKey.push(h); 169 | tosortM[h] = sub; 170 | } 171 | } 172 | tosortKey = tosortKey.sort(); 173 | for (var k in tosortKey){ 174 | menu.appendChild(tosortM[tosortKey[k]]); 175 | } 176 | 177 | if ( groups.length > 0){ 178 | if(hasOther){ 179 | menu.appendChild(document.createElement("menuseparator")); 180 | } 181 | 182 | for(var g in groups){ 183 | menu.appendChild(mk_menu_gp_item(group_names[g], g, groups[g])); 184 | } 185 | } 186 | 187 | var hasCur = false; 188 | if (typeof hosts[curHost] != "undefined") { 189 | if(hasOther){ 190 | menu.appendChild(document.createElement("menuseparator")); 191 | } 192 | hosts = hosts[curHost]; 193 | var addblock = {}; 194 | for (var i in hosts){ 195 | if(!hosts[i].hide){ 196 | if(hosts[i].comment || !addblock[hosts[i].addr]){ 197 | addblock[hosts[i].addr] = true; 198 | menu.appendChild(mk_menu_item(curHost, hosts[i], i)); 199 | hasCur = true; 200 | } 201 | } 202 | } 203 | if(!hasCur && hasOther){ 204 | menu.removeChild(menu.lastChild); 205 | } 206 | } 207 | 208 | 209 | if(hasOther || hasCur){ 210 | menu.insertBefore(document.createElement("menuseparator"), menu.firstChild); 211 | } 212 | menu.insertBefore(editor_item, menu.firstChild); 213 | }; 214 | // }}} refresh menu 215 | 216 | 217 | var onclick = function(target, event){ 218 | if(event.button && event.button !== 0) return false; 219 | 220 | host_admin.refresh(); 221 | refresh_menu(); 222 | 223 | var menu = document.getElementById("hostadmin-popup"); 224 | 225 | menu.openPopup(target, "before_end", 0 ,0, true); 226 | return false; 227 | }; 228 | 229 | var onload = function(event){ 230 | 231 | var panel_label = document.getElementById("hostadmin-label"); 232 | panel_label.addEventListener('mousedown', function(e) { 233 | onclick(panel_label, e); 234 | }, false); 235 | 236 | 237 | gBrowser.tabContainer.addEventListener("TabOpen", updatelb, false); 238 | gBrowser.tabContainer.addEventListener("TabSelect", updatelb, false); 239 | gBrowser.tabContainer.addEventListener("TabAttrModified", updatelb, false); 240 | 241 | }; 242 | 243 | 244 | window.addEventListener("load", onload, false); 245 | 246 | event_host.addEventListener('HostAdminRefresh', function() { 247 | updatelb(); 248 | }, false); 249 | 250 | })(window.HostAdmin); 251 | 252 | -------------------------------------------------------------------------------- /npapi/src/hostadmin.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | #include "hostadmin.h" 9 | #include "const.h" 10 | 11 | static void logmsg(const char *msg) { 12 | FILE *out = fopen("/tmp/x.log", "a"); 13 | if(out) { 14 | fputs(msg, out); 15 | fputs("\n", out); 16 | fclose(out); 17 | } 18 | } 19 | 20 | static NPNetscapeFuncs* npnfuncs; 21 | 22 | bool NP_HasProperty(NPObject *npobj, NPIdentifier propName){ 23 | char * name = npnfuncs->utf8fromidentifier(propName); 24 | return 25 | strcmp(name, PROP_OS) == 0 26 | || strcmp(name, PROP_WHERE) == 0 ; 27 | } 28 | 29 | bool NP_GetProperty(NPObject *npobj, NPIdentifier propName, NPVariant *result){ 30 | char * name = npnfuncs->utf8fromidentifier(propName); 31 | if(strcmp(name, PROP_OS) == 0){ 32 | size_t l = strlen(OSNAME); 33 | char * s = (char *)npnfuncs->memalloc(l + 1); 34 | memcpy(s, OSNAME, l); 35 | s[l] = '\0'; 36 | STRINGN_TO_NPVARIANT(s, l, *result); 37 | return true; 38 | #ifdef XP_WIN 39 | }else if(strcmp(name, PROP_WHERE) == 0){ 40 | char * buf = (char *)npnfuncs->memalloc(MAX_PATH); 41 | GetSystemDirectory(buf, MAX_PATH + 1); 42 | STRINGN_TO_NPVARIANT(buf, strlen(buf) , *result); 43 | return true; 44 | #endif 45 | } 46 | return false; 47 | } 48 | 49 | bool NP_HasMethod(NPObject *obj, NPIdentifier methodName){ 50 | char * name = npnfuncs->utf8fromidentifier(methodName); 51 | //logmsg(name); 52 | return 53 | (strcmp(name, METHOD_TIME) == 0 ) 54 | || (strcmp(name, METHOD_GET) == 0) 55 | || (strcmp(name, METHOD_SET) == 0) 56 | ; 57 | } 58 | 59 | static char * ArgToStr(const NPVariant arg) { 60 | NPString str = NPVARIANT_TO_STRING(arg); 61 | char * r = (char *)malloc(str.UTF8Length + 1); 62 | memcpy(r, str.UTF8Characters, str.UTF8Length); 63 | r[str.UTF8Length] = '\0'; 64 | return r; 65 | } 66 | 67 | #if XP_WIN 68 | static bool HasNonAscii(const char * str ,size_t len){ 69 | for(size_t i=0; i< len; i++) 70 | if(str[i] > 127) 71 | return true; 72 | return false; 73 | } 74 | #endif 75 | 76 | 77 | bool NP_Invoke(NPObject* obj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result){ 78 | char * name = npnfuncs->utf8fromidentifier(methodName); 79 | 80 | if(strcmp(name, METHOD_TIME) == 0 && argCount > 0 && 81 | NPVARIANT_IS_STRING(args[0]) 82 | ){ 83 | 84 | char * filename = ArgToStr(args[0]); 85 | struct stat * buf = (struct stat *)malloc(sizeof(struct stat)); 86 | 87 | stat(filename, buf); 88 | free(filename); 89 | 90 | INT32_TO_NPVARIANT(buf->st_mtime, *result); 91 | free(buf); 92 | 93 | return true; 94 | }else 95 | if(strcmp(name, METHOD_GET) == 0 && argCount > 0 && 96 | NPVARIANT_IS_STRING(args[0]) 97 | ){ 98 | char * filename = ArgToStr(args[0]); 99 | 100 | //logmsg(filename); 101 | FILE * f = fopen(filename, "rb"); 102 | if(f) { 103 | fseek(f, 0 , SEEK_END); 104 | long int size = ftell(f); 105 | 106 | rewind(f); 107 | 108 | char * buf = (char *)npnfuncs->memalloc(size); 109 | memset(buf, 0, size); 110 | fread(buf, 1, size, f); 111 | fclose(f); 112 | 113 | #if XP_WIN 114 | /* make sure text are utf8*/ 115 | 116 | if(strncmp(buf, UTF8BOM, strlen(UTF8BOM)) != 0){ 117 | if(HasNonAscii(buf, size)){ 118 | int usize = MultiByteToWideChar(CP_ACP, 0, buf, size, NULL, 0); 119 | 120 | wchar_t * ubuf = (wchar_t *)malloc((usize + 1) * sizeof(wchar_t)); 121 | memset(ubuf, 0, (usize + 1) * sizeof(wchar_t)); 122 | 123 | MultiByteToWideChar(CP_ACP, 0, buf, size, ubuf, usize); 124 | 125 | size = WideCharToMultiByte(CP_UTF8, 0, ubuf, usize, NULL, 0, NULL, NULL); 126 | 127 | npnfuncs->memfree(buf); 128 | buf = (char *)npnfuncs->memalloc(size + 1); 129 | memset(buf, 0, size + 1); 130 | 131 | WideCharToMultiByte(CP_UTF8, 0, ubuf, usize, buf, size, NULL,NULL); 132 | 133 | free(ubuf); 134 | } 135 | } else{ 136 | 137 | char * oldbuf = buf; 138 | size -= strlen(UTF8BOM); 139 | buf = (char *)npnfuncs->memalloc(size); 140 | 141 | memcpy(buf, oldbuf + strlen(UTF8BOM), size); 142 | npnfuncs->memfree(oldbuf); 143 | 144 | } 145 | 146 | #endif 147 | 148 | STRINGN_TO_NPVARIANT(buf, size, *result); 149 | //npnfuncs->memfree(buf); 150 | } 151 | 152 | free(filename); 153 | return true; 154 | }else 155 | if(strcmp(name, METHOD_SET) == 0 && argCount > 1 && 156 | NPVARIANT_IS_STRING(args[0]) && NPVARIANT_IS_STRING(args[1]) 157 | ){ 158 | char * filename = ArgToStr(args[0]); 159 | char * content = ArgToStr(args[1]); 160 | 161 | FILE * f = fopen(filename, "wb"); 162 | bool succ = false; 163 | if(f) { 164 | 165 | #if XP_WIN 166 | if(HasNonAscii(content, strlen(content))) 167 | fputs(UTF8BOM, f); 168 | #endif 169 | fputs(content, f); 170 | succ = ferror(f) == 0; 171 | fclose(f); 172 | } 173 | 174 | free(filename); 175 | free(content); 176 | 177 | BOOLEAN_TO_NPVARIANT(succ, *result); 178 | return true; 179 | } 180 | return false; 181 | } 182 | 183 | static struct NPClass hostadmin_class = { 184 | NP_CLASS_STRUCT_VERSION, 185 | NULL, 186 | NULL, 187 | NULL, 188 | NP_HasMethod, 189 | NP_Invoke, 190 | NULL, 191 | NP_HasProperty, 192 | NP_GetProperty, 193 | NULL, 194 | NULL, 195 | NULL, 196 | NULL, 197 | }; 198 | static NPObject * hostadmin_helper; 199 | 200 | const char* 201 | NP_GetMIMEDescription(){ 202 | return MIMETYPE_S; 203 | } 204 | 205 | NPError NPP_New(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData* saved) { 206 | 207 | 208 | #ifdef __APPLE_CC__ 209 | NPBool supportsCoreGraphics = false; 210 | if (npnfuncs->getvalue(instance, NPNVsupportsCoreGraphicsBool, &supportsCoreGraphics) == NPERR_NO_ERROR && supportsCoreGraphics) { 211 | npnfuncs->setvalue(instance, NPPVpluginDrawingModel, (void*)NPDrawingModelCoreGraphics); 212 | } 213 | 214 | NPBool supportsCocoaEvents = false; 215 | if (npnfuncs->getvalue(instance, NPNVsupportsCocoaBool, &supportsCocoaEvents) == NPERR_NO_ERROR && supportsCocoaEvents) { 216 | npnfuncs->setvalue(instance, NPPVpluginEventModel, (void*)NPEventModelCocoa); 217 | } 218 | #endif 219 | 220 | return NPERR_NO_ERROR; 221 | } 222 | NPError NPP_Destroy(NPP instance, NPSavedData** save) { 223 | if(!hostadmin_helper) { 224 | npnfuncs->releaseobject(hostadmin_helper); 225 | hostadmin_helper = NULL; 226 | } 227 | return NPERR_NO_ERROR; 228 | } 229 | 230 | NPError NPP_GetValue(NPP instance, NPPVariable variable, void *value) { 231 | switch(variable) { 232 | case NPPVpluginScriptableNPObject: 233 | if(!hostadmin_helper) { 234 | hostadmin_helper = npnfuncs->createobject(instance, &hostadmin_class); 235 | npnfuncs->retainobject(hostadmin_helper); 236 | } 237 | *(NPObject **)value = hostadmin_helper; 238 | break; 239 | case NPPVpluginNeedsXEmbed: 240 | *((bool *)value) = true; 241 | break; 242 | default: 243 | return NPERR_GENERIC_ERROR; 244 | } 245 | return NPERR_NO_ERROR; 246 | } 247 | 248 | 249 | void HookbFuncs(NPNetscapeFuncs* bFuncs){ 250 | npnfuncs = bFuncs; 251 | } 252 | 253 | void HookpFuncs(NPPluginFuncs* pFuncs){ 254 | pFuncs->version = (NP_VERSION_MAJOR << 8) | NP_VERSION_MINOR; 255 | pFuncs->size = sizeof(pFuncs); 256 | pFuncs->newp = NPP_New; 257 | pFuncs->destroy = NPP_Destroy; 258 | pFuncs->getvalue = NPP_GetValue; 259 | } 260 | 261 | 262 | 263 | #ifdef XP_UNIX 264 | NP_EXPORT(NPError) 265 | NP_Initialize(NPNetscapeFuncs* bFuncs, NPPluginFuncs* pFuncs){ 266 | HookbFuncs(bFuncs); 267 | HookpFuncs(pFuncs); 268 | return NPERR_NO_ERROR; 269 | } 270 | 271 | //#elif XP_WIN 272 | #else 273 | NPError OSCALL 274 | NP_GetEntryPoints(NPPluginFuncs* pFuncs) { 275 | HookpFuncs(pFuncs); 276 | return NPERR_NO_ERROR; 277 | } 278 | 279 | NPError OSCALL 280 | NP_Initialize(NPNetscapeFuncs* bFuncs) { 281 | HookbFuncs(bFuncs); 282 | return NPERR_NO_ERROR; 283 | } 284 | #endif 285 | 286 | #ifdef XP_UNIX 287 | NP_EXPORT(NPError) 288 | //#elif XP_WIN 289 | #else 290 | NPError OSCALL 291 | #endif 292 | NP_Shutdown(){ 293 | return NPERR_NO_ERROR; 294 | } 295 | 296 | -------------------------------------------------------------------------------- /core/hostadmin.js: -------------------------------------------------------------------------------- 1 | // HostAdmin 2 | // by T.G.(farmer1992@gmail.com) 3 | // 4 | // core module 5 | // implentment of hostadmin syntax 6 | // http://code.google.com/p/fire-hostadmin/wiki/HOST_SYNTAX 7 | // 8 | (function(HostAdmin){ 9 | 10 | var host_file_wrapper = HostAdmin.host_file_wrapper; 11 | var event_host = HostAdmin.event_host; 12 | 13 | var host_admin = (function(){ 14 | var ip_regx = /^((1?\d?\d|(2([0-4]\d|5[0-5])))\.){3}(1?\d?\d|(2([0-4]\d|5[0-5])))$/; 15 | 16 | // copy from http://forums.intermapper.com/viewtopic.php?t=452 17 | var ip6_regx = /^((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?$/ ; 18 | 19 | var lines = []; 20 | var hosts = {}; 21 | var groups = {}; 22 | var hostname_withoutcase = {}; 23 | 24 | var cur_host_content = ""; 25 | 26 | var loadhost = function() { 27 | 28 | lines = []; 29 | hosts = {}; 30 | groups = {}; 31 | hostname_withoutcase = {}; 32 | //read 33 | var host = host_file_wrapper.get(); 34 | cur_host_content = host; 35 | 36 | if (host && host.charAt(host.length - 1) != "\n"){ //fix no lf 37 | host += host_file_wrapper.splitchar; 38 | } 39 | 40 | var l_p = 0; //pointer to line 41 | var regx = /(.*?)\r?\n/mg; 42 | var group_id = 0; 43 | var group_c = 0; 44 | var ingroup = false; 45 | var bulk_hide = false; 46 | var group_hided = {}; 47 | 48 | while(true){ 49 | var l = regx.exec(host); 50 | if(!l){ 51 | break; 52 | } 53 | 54 | var i; 55 | l = l[0]; 56 | 57 | lines[l_p++] = l; 58 | 59 | l = l.replace(/^(\s*#)+/,"#"); 60 | l = l.replace(/#/g," # "); 61 | l = l.replace(/^\s+|\s+$/g,""); 62 | l = l.replace(/\s+/g," "); 63 | 64 | var tks = l.split(" "); 65 | 66 | if (tks[0] == "#" && tks[1] == "===="){ 67 | if(group_c === 0){ 68 | group_id++; 69 | } 70 | 71 | if(group_c++ % 2 === 0){ 72 | tks.splice(0,2); 73 | var group_name = ""; 74 | for(i in tks){ 75 | group_name += tks[i] + " "; 76 | } 77 | 78 | if( tks[i-1] === "#" && tks[i].toUpperCase() == 'HIDE' ){ 79 | group_hided[group_id] = true; 80 | } 81 | 82 | if(group_name === ""){ 83 | group_name = "Group " + group_id; 84 | } 85 | 86 | groups[group_id] = group_name; 87 | ingroup = true; 88 | }else{ 89 | ingroup = false; 90 | group_id++; 91 | } 92 | continue; 93 | 94 | } else if (tks[0] == "#" && tks[1] && tks[1].toUpperCase() == "HIDE_ALL_OF_BELOW"){ 95 | bulk_hide = true; 96 | } 97 | 98 | var using = true; 99 | if (tks[0] == "#"){ 100 | using = false; 101 | tks.splice(0,1); 102 | } 103 | 104 | var ip = ""; 105 | if (ip_regx.test(tks[0]) || ip6_regx.test(tks[0])){ 106 | ip = tks[0]; 107 | tks.splice(0,1); 108 | }else{ 109 | continue; 110 | } 111 | 112 | var comment = ""; 113 | 114 | var names = []; 115 | var findc = false; 116 | var findhide = false; 117 | for (i in tks){ 118 | if(tks[i] == "#"){ 119 | findc = true; 120 | continue; 121 | } 122 | 123 | findhide = tks[i].toUpperCase() == 'HIDE' 124 | 125 | if(findc){ 126 | comment += tks[i] + " "; 127 | }else{ 128 | names.push(tks[i]); 129 | } 130 | } 131 | 132 | if(typeof(comment) == "string"){ 133 | comment = comment.replace(/^\s+|\s+$/g, ''); 134 | } 135 | 136 | ip = { 137 | addr : ip, 138 | using : using , 139 | line : l_p - 1, 140 | comment : comment, 141 | group : ingroup ? group_id : 0, 142 | hide : bulk_hide || findhide || (ingroup && group_hided[group_id] === true) 143 | }; 144 | 145 | for (i in names){ 146 | var name = names[i]; 147 | if(typeof hosts[name] == "undefined"){ 148 | hosts[name] = []; 149 | } 150 | 151 | hosts[name].push(ip); 152 | hostname_withoutcase[name.toUpperCase()] = name; 153 | } 154 | } 155 | }; 156 | 157 | var line_enable = function(ip){ 158 | if(!ip.using){ 159 | lines[ip.line] = lines[ip.line].replace(/^(\s*#)+/,""); 160 | } 161 | ip.using = true; 162 | }; 163 | 164 | var line_disable = function(ip){ 165 | if(ip.using){ 166 | lines[ip.line] = "#" + lines[ip.line]; 167 | } 168 | ip.using = false; 169 | }; 170 | 171 | var host_toggle = function(host_name, ip_p){ 172 | if(hosts[host_name]){ 173 | var addr = hosts[host_name][ip_p].addr; 174 | var using = hosts[host_name][ip_p].using; 175 | for (var i in hosts[host_name]){ 176 | var ip = hosts[host_name][i]; 177 | 178 | if(ip.addr == addr && !using){ 179 | line_enable(ip); 180 | }else{ 181 | line_disable(ip); 182 | } 183 | } 184 | } 185 | }; 186 | 187 | var is_group_all_using = function(host_list, gp_p){ 188 | for(var h in host_list){ 189 | for (var i in hosts[host_list[h]]){ 190 | var ip = hosts[host_list[h]][i]; 191 | if(ip.group == gp_p && !ip.using){ 192 | return false; 193 | } 194 | } 195 | } 196 | return true; 197 | }; 198 | 199 | var group_toggle = function(host_list, gp_p){ 200 | var using = is_group_all_using(host_list, gp_p); 201 | 202 | for(var h in host_list){ 203 | for (var i in hosts[host_list[h]]){ 204 | var ip = hosts[host_list[h]][i]; 205 | 206 | if(ip.group == gp_p){ 207 | if(using){ 208 | line_disable(ip); 209 | }else{ 210 | line_enable(ip); 211 | } 212 | }else if(ip.using){ 213 | line_disable(ip); 214 | } 215 | } 216 | } 217 | }; 218 | 219 | var mk_host = function(){ 220 | var str = ""; 221 | for (var i in lines){ 222 | str += lines[i]; 223 | } 224 | return str; 225 | }; 226 | 227 | var last_modify = 0; 228 | 229 | // {{{ 230 | 231 | var disp_refresh_event = function(){ 232 | var e = event_host.createEvent('Events'); 233 | e.initEvent('HostAdminRefresh', false, false); 234 | event_host.dispatchEvent(e); 235 | }; 236 | 237 | var last_host_content; 238 | var refresh = function(){ 239 | var t = host_file_wrapper.time(); 240 | 241 | if( t != last_modify){ 242 | loadhost(); 243 | 244 | if(last_host_content != cur_host_content){ 245 | // prevent from saving failed cause editor refresh 246 | last_host_content = cur_host_content; 247 | disp_refresh_event(); 248 | } 249 | 250 | last_modify = t; 251 | 252 | return true; 253 | } 254 | return false; 255 | }; 256 | // }}} 257 | 258 | return { 259 | get_hosts : function(){ 260 | return hosts; 261 | }, 262 | get_groups : function(){ 263 | return groups; 264 | }, 265 | host_toggle : host_toggle, 266 | group_toggle : group_toggle, 267 | group_checked : is_group_all_using, 268 | // mk_host : mk_host, 269 | 270 | host_toggle_and_save : function(host_name, ip_p){ 271 | host_toggle(host_name, ip_p); 272 | return this.save(); 273 | } , 274 | group_toggle_and_save : function(host_list, gp_p){ 275 | group_toggle(host_list, gp_p); 276 | return this.save(); 277 | }, 278 | save : function(hoststr){ 279 | if(!hoststr){ hoststr = mk_host();} 280 | 281 | var succ = host_file_wrapper.set(hoststr); 282 | 283 | last_modify = 0; 284 | this.refresh(); 285 | return succ; 286 | }, 287 | 288 | load : function(){ 289 | return cur_host_content; 290 | }, 291 | 292 | refresh : refresh, 293 | 294 | real_hostname: function(hostname){ 295 | if(hostname) return hostname_withoutcase[hostname.toUpperCase()]; 296 | } 297 | 298 | }; 299 | 300 | })(); 301 | 302 | HostAdmin.core = host_admin; 303 | HostAdmin.PERM_HELP_URL = 'http://code.google.com/p/fire-hostadmin/wiki/GAIN_HOSTS_WRITE_PERM'; 304 | })(window.HostAdmin); 305 | 306 | -------------------------------------------------------------------------------- /npapi/src/hostadmin.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 1430E41214FBFC6500B7D910 /* hostadmin.c in Sources */ = {isa = PBXBuildFile; fileRef = 1430E3FD14FBFACA00B7D910 /* hostadmin.c */; }; 11 | /* End PBXBuildFile section */ 12 | 13 | /* Begin PBXFileReference section */ 14 | 1430E3F614FBFAB700B7D910 /* npapi.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = npapi.h; sourceTree = ""; }; 15 | 1430E3F714FBFAB700B7D910 /* npfunctions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = npfunctions.h; sourceTree = ""; }; 16 | 1430E3F814FBFAB700B7D910 /* npruntime.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = npruntime.h; sourceTree = ""; }; 17 | 1430E3F914FBFAB700B7D910 /* nptypes.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = nptypes.h; sourceTree = ""; }; 18 | 1430E3FB14FBFACA00B7D910 /* const.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = const.h; sourceTree = ""; }; 19 | 1430E3FC14FBFACA00B7D910 /* hostadmin-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "hostadmin-Info.plist"; sourceTree = ""; }; 20 | 1430E3FD14FBFACA00B7D910 /* hostadmin.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = hostadmin.c; sourceTree = ""; }; 21 | 1430E3FE14FBFAD900B7D910 /* hostadmin.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = hostadmin.h; sourceTree = ""; }; 22 | 1430E40314FBFAF900B7D910 /* hostadmin.plugin */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = hostadmin.plugin; sourceTree = BUILT_PRODUCTS_DIR; }; 23 | /* End PBXFileReference section */ 24 | 25 | /* Begin PBXFrameworksBuildPhase section */ 26 | 1430E40014FBFAF900B7D910 /* Frameworks */ = { 27 | isa = PBXFrameworksBuildPhase; 28 | buildActionMask = 2147483647; 29 | files = ( 30 | ); 31 | runOnlyForDeploymentPostprocessing = 0; 32 | }; 33 | /* End PBXFrameworksBuildPhase section */ 34 | 35 | /* Begin PBXGroup section */ 36 | 1430E3E914FBFA8100B7D910 = { 37 | isa = PBXGroup; 38 | children = ( 39 | 1430E41814FBFE5300B7D910 /* Support */, 40 | 1430E41714FBFE3000B7D910 /* Sources */, 41 | 1430E40414FBFAF900B7D910 /* Products */, 42 | ); 43 | sourceTree = ""; 44 | }; 45 | 1430E3F514FBFAB700B7D910 /* npapi_headers */ = { 46 | isa = PBXGroup; 47 | children = ( 48 | 1430E3F614FBFAB700B7D910 /* npapi.h */, 49 | 1430E3F714FBFAB700B7D910 /* npfunctions.h */, 50 | 1430E3F814FBFAB700B7D910 /* npruntime.h */, 51 | 1430E3F914FBFAB700B7D910 /* nptypes.h */, 52 | ); 53 | path = npapi_headers; 54 | sourceTree = ""; 55 | }; 56 | 1430E40414FBFAF900B7D910 /* Products */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | 1430E40314FBFAF900B7D910 /* hostadmin.plugin */, 60 | ); 61 | name = Products; 62 | sourceTree = ""; 63 | }; 64 | 1430E41714FBFE3000B7D910 /* Sources */ = { 65 | isa = PBXGroup; 66 | children = ( 67 | 1430E3FE14FBFAD900B7D910 /* hostadmin.h */, 68 | 1430E3FB14FBFACA00B7D910 /* const.h */, 69 | 1430E3F514FBFAB700B7D910 /* npapi_headers */, 70 | 1430E3FD14FBFACA00B7D910 /* hostadmin.c */, 71 | ); 72 | name = Sources; 73 | sourceTree = ""; 74 | }; 75 | 1430E41814FBFE5300B7D910 /* Support */ = { 76 | isa = PBXGroup; 77 | children = ( 78 | 1430E3FC14FBFACA00B7D910 /* hostadmin-Info.plist */, 79 | ); 80 | name = Support; 81 | sourceTree = ""; 82 | }; 83 | /* End PBXGroup section */ 84 | 85 | /* Begin PBXNativeTarget section */ 86 | 1430E40214FBFAF900B7D910 /* hostadmin */ = { 87 | isa = PBXNativeTarget; 88 | buildConfigurationList = 1430E40F14FBFAF900B7D910 /* Build configuration list for PBXNativeTarget "hostadmin" */; 89 | buildPhases = ( 90 | 1430E3FF14FBFAF900B7D910 /* Sources */, 91 | 1430E40014FBFAF900B7D910 /* Frameworks */, 92 | 1430E40114FBFAF900B7D910 /* Resources */, 93 | 1430E41614FBFCD200B7D910 /* ShellScript */, 94 | ); 95 | buildRules = ( 96 | ); 97 | dependencies = ( 98 | ); 99 | name = hostadmin; 100 | productName = hostadmin; 101 | productReference = 1430E40314FBFAF900B7D910 /* hostadmin.plugin */; 102 | productType = "com.apple.product-type.bundle"; 103 | }; 104 | /* End PBXNativeTarget section */ 105 | 106 | /* Begin PBXProject section */ 107 | 1430E3EB14FBFA8100B7D910 /* Project object */ = { 108 | isa = PBXProject; 109 | attributes = { 110 | LastUpgradeCheck = 0430; 111 | }; 112 | buildConfigurationList = 1430E3EE14FBFA8100B7D910 /* Build configuration list for PBXProject "hostadmin" */; 113 | compatibilityVersion = "Xcode 3.2"; 114 | developmentRegion = English; 115 | hasScannedForEncodings = 0; 116 | knownRegions = ( 117 | en, 118 | ); 119 | mainGroup = 1430E3E914FBFA8100B7D910; 120 | productRefGroup = 1430E40414FBFAF900B7D910 /* Products */; 121 | projectDirPath = ""; 122 | projectRoot = ""; 123 | targets = ( 124 | 1430E40214FBFAF900B7D910 /* hostadmin */, 125 | ); 126 | }; 127 | /* End PBXProject section */ 128 | 129 | /* Begin PBXResourcesBuildPhase section */ 130 | 1430E40114FBFAF900B7D910 /* Resources */ = { 131 | isa = PBXResourcesBuildPhase; 132 | buildActionMask = 2147483647; 133 | files = ( 134 | ); 135 | runOnlyForDeploymentPostprocessing = 0; 136 | }; 137 | /* End PBXResourcesBuildPhase section */ 138 | 139 | /* Begin PBXShellScriptBuildPhase section */ 140 | 1430E41614FBFCD200B7D910 /* ShellScript */ = { 141 | isa = PBXShellScriptBuildPhase; 142 | buildActionMask = 2147483647; 143 | files = ( 144 | ); 145 | inputPaths = ( 146 | ); 147 | outputPaths = ( 148 | ); 149 | runOnlyForDeploymentPostprocessing = 0; 150 | shellPath = /bin/sh; 151 | shellScript = "BUILD=\"${TARGET_BUILD_DIR}/${FULL_PRODUCT_NAME}\"\nTARGET=\"${SRCROOT}/../${FULL_PRODUCT_NAME}\"\n\n/bin/rm -rf $TARGET\n/bin/cp -r $BUILD $TARGET"; 152 | }; 153 | /* End PBXShellScriptBuildPhase section */ 154 | 155 | /* Begin PBXSourcesBuildPhase section */ 156 | 1430E3FF14FBFAF900B7D910 /* Sources */ = { 157 | isa = PBXSourcesBuildPhase; 158 | buildActionMask = 2147483647; 159 | files = ( 160 | 1430E41214FBFC6500B7D910 /* hostadmin.c in Sources */, 161 | ); 162 | runOnlyForDeploymentPostprocessing = 0; 163 | }; 164 | /* End PBXSourcesBuildPhase section */ 165 | 166 | /* Begin XCBuildConfiguration section */ 167 | 1430E3F014FBFA8100B7D910 /* Debug */ = { 168 | isa = XCBuildConfiguration; 169 | buildSettings = { 170 | }; 171 | name = Debug; 172 | }; 173 | 1430E3F114FBFA8100B7D910 /* Release */ = { 174 | isa = XCBuildConfiguration; 175 | buildSettings = { 176 | }; 177 | name = Release; 178 | }; 179 | 1430E41014FBFAF900B7D910 /* Debug */ = { 180 | isa = XCBuildConfiguration; 181 | buildSettings = { 182 | ALWAYS_SEARCH_USER_PATHS = NO; 183 | ARCHS = "$(ARCHS_STANDARD_32_BIT)"; 184 | COPY_PHASE_STRIP = NO; 185 | GCC_C_LANGUAGE_STANDARD = gnu99; 186 | GCC_DYNAMIC_NO_PIC = NO; 187 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 188 | GCC_OPTIMIZATION_LEVEL = 0; 189 | GCC_PRECOMPILE_PREFIX_HEADER = NO; 190 | GCC_PREFIX_HEADER = ""; 191 | GCC_PREPROCESSOR_DEFINITIONS = ( 192 | "DEBUG=1", 193 | "$(inherited)", 194 | ); 195 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 196 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0; 197 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 198 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 199 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 200 | GCC_WARN_UNUSED_VARIABLE = YES; 201 | INFOPLIST_FILE = "hostadmin-Info.plist"; 202 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Bundles"; 203 | MACOSX_DEPLOYMENT_TARGET = 10.7; 204 | ONLY_ACTIVE_ARCH = YES; 205 | PRODUCT_NAME = "$(TARGET_NAME)"; 206 | SDKROOT = macosx; 207 | WRAPPER_EXTENSION = plugin; 208 | }; 209 | name = Debug; 210 | }; 211 | 1430E41114FBFAF900B7D910 /* Release */ = { 212 | isa = XCBuildConfiguration; 213 | buildSettings = { 214 | ALWAYS_SEARCH_USER_PATHS = NO; 215 | ARCHS = "$(ARCHS_STANDARD_32_BIT)"; 216 | COPY_PHASE_STRIP = YES; 217 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 218 | GCC_C_LANGUAGE_STANDARD = gnu99; 219 | GCC_ENABLE_OBJC_EXCEPTIONS = YES; 220 | GCC_PRECOMPILE_PREFIX_HEADER = NO; 221 | GCC_PREFIX_HEADER = ""; 222 | GCC_VERSION = com.apple.compilers.llvm.clang.1_0; 223 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 224 | GCC_WARN_ABOUT_RETURN_TYPE = YES; 225 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 226 | GCC_WARN_UNUSED_VARIABLE = YES; 227 | INFOPLIST_FILE = "hostadmin-Info.plist"; 228 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Bundles"; 229 | MACOSX_DEPLOYMENT_TARGET = 10.7; 230 | PRODUCT_NAME = "$(TARGET_NAME)"; 231 | SDKROOT = macosx; 232 | WRAPPER_EXTENSION = plugin; 233 | }; 234 | name = Release; 235 | }; 236 | /* End XCBuildConfiguration section */ 237 | 238 | /* Begin XCConfigurationList section */ 239 | 1430E3EE14FBFA8100B7D910 /* Build configuration list for PBXProject "hostadmin" */ = { 240 | isa = XCConfigurationList; 241 | buildConfigurations = ( 242 | 1430E3F014FBFA8100B7D910 /* Debug */, 243 | 1430E3F114FBFA8100B7D910 /* Release */, 244 | ); 245 | defaultConfigurationIsVisible = 0; 246 | defaultConfigurationName = Release; 247 | }; 248 | 1430E40F14FBFAF900B7D910 /* Build configuration list for PBXNativeTarget "hostadmin" */ = { 249 | isa = XCConfigurationList; 250 | buildConfigurations = ( 251 | 1430E41014FBFAF900B7D910 /* Debug */, 252 | 1430E41114FBFAF900B7D910 /* Release */, 253 | ); 254 | defaultConfigurationIsVisible = 0; 255 | defaultConfigurationName = Release; 256 | }; 257 | /* End XCConfigurationList section */ 258 | }; 259 | rootObject = 1430E3EB14FBFA8100B7D910 /* Project object */; 260 | } 261 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Mozilla Public License, version 2.0 2 | 3 | 1. Definitions 4 | 5 | 1.1. "Contributor" 6 | 7 | means each individual or legal entity that creates, contributes to the 8 | creation of, or owns Covered Software. 9 | 10 | 1.2. "Contributor Version" 11 | 12 | means the combination of the Contributions of others (if any) used by a 13 | Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | 17 | means Covered Software of a particular Contributor. 18 | 19 | 1.4. "Covered Software" 20 | 21 | means Source Code Form to which the initial Contributor has attached the 22 | notice in Exhibit A, the Executable Form of such Source Code Form, and 23 | Modifications of such Source Code Form, in each case including portions 24 | thereof. 25 | 26 | 1.5. "Incompatible With Secondary Licenses" 27 | means 28 | 29 | a. that the initial Contributor has attached the notice described in 30 | Exhibit B to the Covered Software; or 31 | 32 | b. that the Covered Software was made available under the terms of 33 | version 1.1 or earlier of the License, but not also under the terms of 34 | a Secondary License. 35 | 36 | 1.6. "Executable Form" 37 | 38 | means any form of the work other than Source Code Form. 39 | 40 | 1.7. "Larger Work" 41 | 42 | means a work that combines Covered Software with other material, in a 43 | separate file or files, that is not Covered Software. 44 | 45 | 1.8. "License" 46 | 47 | means this document. 48 | 49 | 1.9. "Licensable" 50 | 51 | means having the right to grant, to the maximum extent possible, whether 52 | at the time of the initial grant or subsequently, any and all of the 53 | rights conveyed by this License. 54 | 55 | 1.10. "Modifications" 56 | 57 | means any of the following: 58 | 59 | a. any file in Source Code Form that results from an addition to, 60 | deletion from, or modification of the contents of Covered Software; or 61 | 62 | b. any new file in Source Code Form that contains any Covered Software. 63 | 64 | 1.11. "Patent Claims" of a Contributor 65 | 66 | means any patent claim(s), including without limitation, method, 67 | process, and apparatus claims, in any patent Licensable by such 68 | Contributor that would be infringed, but for the grant of the License, 69 | by the making, using, selling, offering for sale, having made, import, 70 | or transfer of either its Contributions or its Contributor Version. 71 | 72 | 1.12. "Secondary License" 73 | 74 | means either the GNU General Public License, Version 2.0, the GNU Lesser 75 | General Public License, Version 2.1, the GNU Affero General Public 76 | License, Version 3.0, or any later versions of those licenses. 77 | 78 | 1.13. "Source Code Form" 79 | 80 | means the form of the work preferred for making modifications. 81 | 82 | 1.14. "You" (or "Your") 83 | 84 | means an individual or a legal entity exercising rights under this 85 | License. For legal entities, "You" includes any entity that controls, is 86 | controlled by, or is under common control with You. For purposes of this 87 | definition, "control" means (a) the power, direct or indirect, to cause 88 | the direction or management of such entity, whether by contract or 89 | otherwise, or (b) ownership of more than fifty percent (50%) of the 90 | outstanding shares or beneficial ownership of such entity. 91 | 92 | 93 | 2. License Grants and Conditions 94 | 95 | 2.1. Grants 96 | 97 | Each Contributor hereby grants You a world-wide, royalty-free, 98 | non-exclusive license: 99 | 100 | a. under intellectual property rights (other than patent or trademark) 101 | Licensable by such Contributor to use, reproduce, make available, 102 | modify, display, perform, distribute, and otherwise exploit its 103 | Contributions, either on an unmodified basis, with Modifications, or 104 | as part of a Larger Work; and 105 | 106 | b. under Patent Claims of such Contributor to make, use, sell, offer for 107 | sale, have made, import, and otherwise transfer either its 108 | Contributions or its Contributor Version. 109 | 110 | 2.2. Effective Date 111 | 112 | The licenses granted in Section 2.1 with respect to any Contribution 113 | become effective for each Contribution on the date the Contributor first 114 | distributes such Contribution. 115 | 116 | 2.3. Limitations on Grant Scope 117 | 118 | The licenses granted in this Section 2 are the only rights granted under 119 | this License. No additional rights or licenses will be implied from the 120 | distribution or licensing of Covered Software under this License. 121 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 122 | Contributor: 123 | 124 | a. for any code that a Contributor has removed from Covered Software; or 125 | 126 | b. for infringements caused by: (i) Your and any other third party's 127 | modifications of Covered Software, or (ii) the combination of its 128 | Contributions with other software (except as part of its Contributor 129 | Version); or 130 | 131 | c. under Patent Claims infringed by Covered Software in the absence of 132 | its Contributions. 133 | 134 | This License does not grant any rights in the trademarks, service marks, 135 | or logos of any Contributor (except as may be necessary to comply with 136 | the notice requirements in Section 3.4). 137 | 138 | 2.4. Subsequent Licenses 139 | 140 | No Contributor makes additional grants as a result of Your choice to 141 | distribute the Covered Software under a subsequent version of this 142 | License (see Section 10.2) or under the terms of a Secondary License (if 143 | permitted under the terms of Section 3.3). 144 | 145 | 2.5. Representation 146 | 147 | Each Contributor represents that the Contributor believes its 148 | Contributions are its original creation(s) or it has sufficient rights to 149 | grant the rights to its Contributions conveyed by this License. 150 | 151 | 2.6. Fair Use 152 | 153 | This License is not intended to limit any rights You have under 154 | applicable copyright doctrines of fair use, fair dealing, or other 155 | equivalents. 156 | 157 | 2.7. Conditions 158 | 159 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted in 160 | Section 2.1. 161 | 162 | 163 | 3. Responsibilities 164 | 165 | 3.1. Distribution of Source Form 166 | 167 | All distribution of Covered Software in Source Code Form, including any 168 | Modifications that You create or to which You contribute, must be under 169 | the terms of this License. You must inform recipients that the Source 170 | Code Form of the Covered Software is governed by the terms of this 171 | License, and how they can obtain a copy of this License. You may not 172 | attempt to alter or restrict the recipients' rights in the Source Code 173 | Form. 174 | 175 | 3.2. Distribution of Executable Form 176 | 177 | If You distribute Covered Software in Executable Form then: 178 | 179 | a. such Covered Software must also be made available in Source Code Form, 180 | as described in Section 3.1, and You must inform recipients of the 181 | Executable Form how they can obtain a copy of such Source Code Form by 182 | reasonable means in a timely manner, at a charge no more than the cost 183 | of distribution to the recipient; and 184 | 185 | b. You may distribute such Executable Form under the terms of this 186 | License, or sublicense it under different terms, provided that the 187 | license for the Executable Form does not attempt to limit or alter the 188 | recipients' rights in the Source Code Form under this License. 189 | 190 | 3.3. Distribution of a Larger Work 191 | 192 | You may create and distribute a Larger Work under terms of Your choice, 193 | provided that You also comply with the requirements of this License for 194 | the Covered Software. If the Larger Work is a combination of Covered 195 | Software with a work governed by one or more Secondary Licenses, and the 196 | Covered Software is not Incompatible With Secondary Licenses, this 197 | License permits You to additionally distribute such Covered Software 198 | under the terms of such Secondary License(s), so that the recipient of 199 | the Larger Work may, at their option, further distribute the Covered 200 | Software under the terms of either this License or such Secondary 201 | License(s). 202 | 203 | 3.4. Notices 204 | 205 | You may not remove or alter the substance of any license notices 206 | (including copyright notices, patent notices, disclaimers of warranty, or 207 | limitations of liability) contained within the Source Code Form of the 208 | Covered Software, except that You may alter any license notices to the 209 | extent required to remedy known factual inaccuracies. 210 | 211 | 3.5. Application of Additional Terms 212 | 213 | You may choose to offer, and to charge a fee for, warranty, support, 214 | indemnity or liability obligations to one or more recipients of Covered 215 | Software. However, You may do so only on Your own behalf, and not on 216 | behalf of any Contributor. You must make it absolutely clear that any 217 | such warranty, support, indemnity, or liability obligation is offered by 218 | You alone, and You hereby agree to indemnify every Contributor for any 219 | liability incurred by such Contributor as a result of warranty, support, 220 | indemnity or liability terms You offer. You may include additional 221 | disclaimers of warranty and limitations of liability specific to any 222 | jurisdiction. 223 | 224 | 4. Inability to Comply Due to Statute or Regulation 225 | 226 | If it is impossible for You to comply with any of the terms of this License 227 | with respect to some or all of the Covered Software due to statute, 228 | judicial order, or regulation then You must: (a) comply with the terms of 229 | this License to the maximum extent possible; and (b) describe the 230 | limitations and the code they affect. Such description must be placed in a 231 | text file included with all distributions of the Covered Software under 232 | this License. Except to the extent prohibited by statute or regulation, 233 | such description must be sufficiently detailed for a recipient of ordinary 234 | skill to be able to understand it. 235 | 236 | 5. Termination 237 | 238 | 5.1. The rights granted under this License will terminate automatically if You 239 | fail to comply with any of its terms. However, if You become compliant, 240 | then the rights granted under this License from a particular Contributor 241 | are reinstated (a) provisionally, unless and until such Contributor 242 | explicitly and finally terminates Your grants, and (b) on an ongoing 243 | basis, if such Contributor fails to notify You of the non-compliance by 244 | some reasonable means prior to 60 days after You have come back into 245 | compliance. Moreover, Your grants from a particular Contributor are 246 | reinstated on an ongoing basis if such Contributor notifies You of the 247 | non-compliance by some reasonable means, this is the first time You have 248 | received notice of non-compliance with this License from such 249 | Contributor, and You become compliant prior to 30 days after Your receipt 250 | of the notice. 251 | 252 | 5.2. If You initiate litigation against any entity by asserting a patent 253 | infringement claim (excluding declaratory judgment actions, 254 | counter-claims, and cross-claims) alleging that a Contributor Version 255 | directly or indirectly infringes any patent, then the rights granted to 256 | You by any and all Contributors for the Covered Software under Section 257 | 2.1 of this License shall terminate. 258 | 259 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all end user 260 | license agreements (excluding distributors and resellers) which have been 261 | validly granted by You or Your distributors under this License prior to 262 | termination shall survive termination. 263 | 264 | 6. Disclaimer of Warranty 265 | 266 | Covered Software is provided under this License on an "as is" basis, 267 | without warranty of any kind, either expressed, implied, or statutory, 268 | including, without limitation, warranties that the Covered Software is free 269 | of defects, merchantable, fit for a particular purpose or non-infringing. 270 | The entire risk as to the quality and performance of the Covered Software 271 | is with You. Should any Covered Software prove defective in any respect, 272 | You (not any Contributor) assume the cost of any necessary servicing, 273 | repair, or correction. This disclaimer of warranty constitutes an essential 274 | part of this License. No use of any Covered Software is authorized under 275 | this License except under this disclaimer. 276 | 277 | 7. Limitation of Liability 278 | 279 | Under no circumstances and under no legal theory, whether tort (including 280 | negligence), contract, or otherwise, shall any Contributor, or anyone who 281 | distributes Covered Software as permitted above, be liable to You for any 282 | direct, indirect, special, incidental, or consequential damages of any 283 | character including, without limitation, damages for lost profits, loss of 284 | goodwill, work stoppage, computer failure or malfunction, or any and all 285 | other commercial damages or losses, even if such party shall have been 286 | informed of the possibility of such damages. This limitation of liability 287 | shall not apply to liability for death or personal injury resulting from 288 | such party's negligence to the extent applicable law prohibits such 289 | limitation. Some jurisdictions do not allow the exclusion or limitation of 290 | incidental or consequential damages, so this exclusion and limitation may 291 | not apply to You. 292 | 293 | 8. Litigation 294 | 295 | Any litigation relating to this License may be brought only in the courts 296 | of a jurisdiction where the defendant maintains its principal place of 297 | business and such litigation shall be governed by laws of that 298 | jurisdiction, without reference to its conflict-of-law provisions. Nothing 299 | in this Section shall prevent a party's ability to bring cross-claims or 300 | counter-claims. 301 | 302 | 9. Miscellaneous 303 | 304 | This License represents the complete agreement concerning the subject 305 | matter hereof. If any provision of this License is held to be 306 | unenforceable, such provision shall be reformed only to the extent 307 | necessary to make it enforceable. Any law or regulation which provides that 308 | the language of a contract shall be construed against the drafter shall not 309 | be used to construe this License against a Contributor. 310 | 311 | 312 | 10. Versions of the License 313 | 314 | 10.1. New Versions 315 | 316 | Mozilla Foundation is the license steward. Except as provided in Section 317 | 10.3, no one other than the license steward has the right to modify or 318 | publish new versions of this License. Each version will be given a 319 | distinguishing version number. 320 | 321 | 10.2. Effect of New Versions 322 | 323 | You may distribute the Covered Software under the terms of the version 324 | of the License under which You originally received the Covered Software, 325 | or under the terms of any subsequent version published by the license 326 | steward. 327 | 328 | 10.3. Modified Versions 329 | 330 | If you create software not governed by this License, and you want to 331 | create a new license for such software, you may create and use a 332 | modified version of this License if you rename the license and remove 333 | any references to the name of the license steward (except to note that 334 | such modified license differs from this License). 335 | 336 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 337 | Licenses If You choose to distribute Source Code Form that is 338 | Incompatible With Secondary Licenses under the terms of this version of 339 | the License, the notice described in Exhibit B of this License must be 340 | attached. 341 | 342 | Exhibit A - Source Code Form License Notice 343 | 344 | This Source Code Form is subject to the 345 | terms of the Mozilla Public License, v. 346 | 2.0. If a copy of the MPL was not 347 | distributed with this file, You can 348 | obtain one at 349 | http://mozilla.org/MPL/2.0/. 350 | 351 | If it is not possible or desirable to put the notice in a particular file, 352 | then You may include the notice in a location (such as a LICENSE file in a 353 | relevant directory) where a recipient would be likely to look for such a 354 | notice. 355 | 356 | You may add additional accurate notices of copyright ownership. 357 | 358 | Exhibit B - "Incompatible With Secondary Licenses" Notice 359 | 360 | This Source Code Form is "Incompatible 361 | With Secondary Licenses", as defined by 362 | the Mozilla Public License, v. 2.0. 363 | -------------------------------------------------------------------------------- /npapi/src/npapi_headers/npfunctions.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* ***** BEGIN LICENSE BLOCK ***** 3 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1 4 | * 5 | * The contents of this file are subject to the Mozilla Public License Version 6 | * 1.1 (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * http://www.mozilla.org/MPL/ 9 | * 10 | * Software distributed under the License is distributed on an "AS IS" basis, 11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 12 | * for the specific language governing rights and limitations under the 13 | * License. 14 | * 15 | * The Original Code is mozilla.org code. 16 | * 17 | * The Initial Developer of the Original Code is 18 | * Netscape Communications Corporation. 19 | * Portions created by the Initial Developer are Copyright (C) 1998 20 | * the Initial Developer. All Rights Reserved. 21 | * 22 | * Contributor(s): 23 | * 24 | * Alternatively, the contents of this file may be used under the terms of 25 | * either the GNU General Public License Version 2 or later (the "GPL"), or 26 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 27 | * in which case the provisions of the GPL or the LGPL are applicable instead 28 | * of those above. If you wish to allow use of your version of this file only 29 | * under the terms of either the GPL or the LGPL, and not to allow others to 30 | * use your version of this file under the terms of the MPL, indicate your 31 | * decision by deleting the provisions above and replace them with the notice 32 | * and other provisions required by the GPL or the LGPL. If you do not delete 33 | * the provisions above, a recipient may use your version of this file under 34 | * the terms of any one of the MPL, the GPL or the LGPL. 35 | * 36 | * ***** END LICENSE BLOCK ***** */ 37 | 38 | #ifndef npfunctions_h_ 39 | #define npfunctions_h_ 40 | 41 | #ifdef __OS2__ 42 | #pragma pack(1) 43 | #define NP_LOADDS _System 44 | #else 45 | #define NP_LOADDS 46 | #endif 47 | 48 | #include "npapi.h" 49 | #include "npruntime.h" 50 | 51 | typedef NPError (* NP_LOADDS NPP_NewProcPtr)(NPMIMEType pluginType, NPP instance, uint16_t mode, int16_t argc, char* argn[], char* argv[], NPSavedData* saved); 52 | typedef NPError (* NP_LOADDS NPP_DestroyProcPtr)(NPP instance, NPSavedData** save); 53 | typedef NPError (* NP_LOADDS NPP_SetWindowProcPtr)(NPP instance, NPWindow* window); 54 | typedef NPError (* NP_LOADDS NPP_NewStreamProcPtr)(NPP instance, NPMIMEType type, NPStream* stream, NPBool seekable, uint16_t* stype); 55 | typedef NPError (* NP_LOADDS NPP_DestroyStreamProcPtr)(NPP instance, NPStream* stream, NPReason reason); 56 | typedef int32_t (* NP_LOADDS NPP_WriteReadyProcPtr)(NPP instance, NPStream* stream); 57 | typedef int32_t (* NP_LOADDS NPP_WriteProcPtr)(NPP instance, NPStream* stream, int32_t offset, int32_t len, void* buffer); 58 | typedef void (* NP_LOADDS NPP_StreamAsFileProcPtr)(NPP instance, NPStream* stream, const char* fname); 59 | typedef void (* NP_LOADDS NPP_PrintProcPtr)(NPP instance, NPPrint* platformPrint); 60 | typedef int16_t (* NP_LOADDS NPP_HandleEventProcPtr)(NPP instance, void* event); 61 | typedef void (* NP_LOADDS NPP_URLNotifyProcPtr)(NPP instance, const char* url, NPReason reason, void* notifyData); 62 | /* Any NPObjects returned to the browser via NPP_GetValue should be retained 63 | by the plugin on the way out. The browser is responsible for releasing. */ 64 | typedef NPError (* NP_LOADDS NPP_GetValueProcPtr)(NPP instance, NPPVariable variable, void *ret_value); 65 | typedef NPError (* NP_LOADDS NPP_SetValueProcPtr)(NPP instance, NPNVariable variable, void *value); 66 | typedef NPBool (* NP_LOADDS NPP_GotFocusPtr)(NPP instance, NPFocusDirection direction); 67 | typedef void (* NP_LOADDS NPP_LostFocusPtr)(NPP instance); 68 | typedef void (* NP_LOADDS NPP_URLRedirectNotifyPtr)(NPP instance, const char* url, int32_t status, void* notifyData); 69 | typedef NPError (* NP_LOADDS NPP_ClearSiteDataPtr)(const char* site, uint64_t flags, uint64_t maxAge); 70 | typedef char** (* NP_LOADDS NPP_GetSitesWithDataPtr)(void); 71 | 72 | typedef NPError (*NPN_GetValueProcPtr)(NPP instance, NPNVariable variable, void *ret_value); 73 | typedef NPError (*NPN_SetValueProcPtr)(NPP instance, NPPVariable variable, void *value); 74 | typedef NPError (*NPN_GetURLNotifyProcPtr)(NPP instance, const char* url, const char* window, void* notifyData); 75 | typedef NPError (*NPN_PostURLNotifyProcPtr)(NPP instance, const char* url, const char* window, uint32_t len, const char* buf, NPBool file, void* notifyData); 76 | typedef NPError (*NPN_GetURLProcPtr)(NPP instance, const char* url, const char* window); 77 | typedef NPError (*NPN_PostURLProcPtr)(NPP instance, const char* url, const char* window, uint32_t len, const char* buf, NPBool file); 78 | typedef NPError (*NPN_RequestReadProcPtr)(NPStream* stream, NPByteRange* rangeList); 79 | typedef NPError (*NPN_NewStreamProcPtr)(NPP instance, NPMIMEType type, const char* window, NPStream** stream); 80 | typedef int32_t (*NPN_WriteProcPtr)(NPP instance, NPStream* stream, int32_t len, void* buffer); 81 | typedef NPError (*NPN_DestroyStreamProcPtr)(NPP instance, NPStream* stream, NPReason reason); 82 | typedef void (*NPN_StatusProcPtr)(NPP instance, const char* message); 83 | /* Browser manages the lifetime of the buffer returned by NPN_UserAgent, don't 84 | depend on it sticking around and don't free it. */ 85 | typedef const char* (*NPN_UserAgentProcPtr)(NPP instance); 86 | typedef void* (*NPN_MemAllocProcPtr)(uint32_t size); 87 | typedef void (*NPN_MemFreeProcPtr)(void* ptr); 88 | typedef uint32_t (*NPN_MemFlushProcPtr)(uint32_t size); 89 | typedef void (*NPN_ReloadPluginsProcPtr)(NPBool reloadPages); 90 | typedef void* (*NPN_GetJavaEnvProcPtr)(void); 91 | typedef void* (*NPN_GetJavaPeerProcPtr)(NPP instance); 92 | typedef void (*NPN_InvalidateRectProcPtr)(NPP instance, NPRect *rect); 93 | typedef void (*NPN_InvalidateRegionProcPtr)(NPP instance, NPRegion region); 94 | typedef void (*NPN_ForceRedrawProcPtr)(NPP instance); 95 | typedef NPIdentifier (*NPN_GetStringIdentifierProcPtr)(const NPUTF8* name); 96 | typedef void (*NPN_GetStringIdentifiersProcPtr)(const NPUTF8** names, int32_t nameCount, NPIdentifier* identifiers); 97 | typedef NPIdentifier (*NPN_GetIntIdentifierProcPtr)(int32_t intid); 98 | typedef bool (*NPN_IdentifierIsStringProcPtr)(NPIdentifier identifier); 99 | typedef NPUTF8* (*NPN_UTF8FromIdentifierProcPtr)(NPIdentifier identifier); 100 | typedef int32_t (*NPN_IntFromIdentifierProcPtr)(NPIdentifier identifier); 101 | typedef NPObject* (*NPN_CreateObjectProcPtr)(NPP npp, NPClass *aClass); 102 | typedef NPObject* (*NPN_RetainObjectProcPtr)(NPObject *obj); 103 | typedef void (*NPN_ReleaseObjectProcPtr)(NPObject *obj); 104 | typedef bool (*NPN_InvokeProcPtr)(NPP npp, NPObject* obj, NPIdentifier methodName, const NPVariant *args, uint32_t argCount, NPVariant *result); 105 | typedef bool (*NPN_InvokeDefaultProcPtr)(NPP npp, NPObject* obj, const NPVariant *args, uint32_t argCount, NPVariant *result); 106 | typedef bool (*NPN_EvaluateProcPtr)(NPP npp, NPObject *obj, NPString *script, NPVariant *result); 107 | typedef bool (*NPN_GetPropertyProcPtr)(NPP npp, NPObject *obj, NPIdentifier propertyName, NPVariant *result); 108 | typedef bool (*NPN_SetPropertyProcPtr)(NPP npp, NPObject *obj, NPIdentifier propertyName, const NPVariant *value); 109 | typedef bool (*NPN_RemovePropertyProcPtr)(NPP npp, NPObject *obj, NPIdentifier propertyName); 110 | typedef bool (*NPN_HasPropertyProcPtr)(NPP npp, NPObject *obj, NPIdentifier propertyName); 111 | typedef bool (*NPN_HasMethodProcPtr)(NPP npp, NPObject *obj, NPIdentifier propertyName); 112 | typedef void (*NPN_ReleaseVariantValueProcPtr)(NPVariant *variant); 113 | typedef void (*NPN_SetExceptionProcPtr)(NPObject *obj, const NPUTF8 *message); 114 | typedef void (*NPN_PushPopupsEnabledStateProcPtr)(NPP npp, NPBool enabled); 115 | typedef void (*NPN_PopPopupsEnabledStateProcPtr)(NPP npp); 116 | typedef bool (*NPN_EnumerateProcPtr)(NPP npp, NPObject *obj, NPIdentifier **identifier, uint32_t *count); 117 | typedef void (*NPN_PluginThreadAsyncCallProcPtr)(NPP instance, void (*func)(void *), void *userData); 118 | typedef bool (*NPN_ConstructProcPtr)(NPP npp, NPObject* obj, const NPVariant *args, uint32_t argCount, NPVariant *result); 119 | typedef NPError (*NPN_GetValueForURLPtr)(NPP npp, NPNURLVariable variable, const char *url, char **value, uint32_t *len); 120 | typedef NPError (*NPN_SetValueForURLPtr)(NPP npp, NPNURLVariable variable, const char *url, const char *value, uint32_t len); 121 | typedef NPError (*NPN_GetAuthenticationInfoPtr)(NPP npp, const char *protocol, const char *host, int32_t port, const char *scheme, const char *realm, char **username, uint32_t *ulen, char **password, uint32_t *plen); 122 | typedef uint32_t (*NPN_ScheduleTimerPtr)(NPP instance, uint32_t interval, NPBool repeat, void (*timerFunc)(NPP npp, uint32_t timerID)); 123 | typedef void (*NPN_UnscheduleTimerPtr)(NPP instance, uint32_t timerID); 124 | typedef NPError (*NPN_PopUpContextMenuPtr)(NPP instance, NPMenu* menu); 125 | typedef NPBool (*NPN_ConvertPointPtr)(NPP instance, double sourceX, double sourceY, NPCoordinateSpace sourceSpace, double *destX, double *destY, NPCoordinateSpace destSpace); 126 | typedef NPBool (*NPN_HandleEventPtr)(NPP instance, void *event, NPBool handled); 127 | typedef NPBool (*NPN_UnfocusInstancePtr)(NPP instance, NPFocusDirection direction); 128 | typedef void (*NPN_URLRedirectResponsePtr)(NPP instance, void* notifyData, NPBool allow); 129 | 130 | typedef struct _NPPluginFuncs { 131 | uint16_t size; 132 | uint16_t version; 133 | NPP_NewProcPtr newp; 134 | NPP_DestroyProcPtr destroy; 135 | NPP_SetWindowProcPtr setwindow; 136 | NPP_NewStreamProcPtr newstream; 137 | NPP_DestroyStreamProcPtr destroystream; 138 | NPP_StreamAsFileProcPtr asfile; 139 | NPP_WriteReadyProcPtr writeready; 140 | NPP_WriteProcPtr write; 141 | NPP_PrintProcPtr print; 142 | NPP_HandleEventProcPtr event; 143 | NPP_URLNotifyProcPtr urlnotify; 144 | void* javaClass; 145 | NPP_GetValueProcPtr getvalue; 146 | NPP_SetValueProcPtr setvalue; 147 | NPP_GotFocusPtr gotfocus; 148 | NPP_LostFocusPtr lostfocus; 149 | NPP_URLRedirectNotifyPtr urlredirectnotify; 150 | NPP_ClearSiteDataPtr clearsitedata; 151 | NPP_GetSitesWithDataPtr getsiteswithdata; 152 | } NPPluginFuncs; 153 | 154 | typedef struct _NPNetscapeFuncs { 155 | uint16_t size; 156 | uint16_t version; 157 | NPN_GetURLProcPtr geturl; 158 | NPN_PostURLProcPtr posturl; 159 | NPN_RequestReadProcPtr requestread; 160 | NPN_NewStreamProcPtr newstream; 161 | NPN_WriteProcPtr write; 162 | NPN_DestroyStreamProcPtr destroystream; 163 | NPN_StatusProcPtr status; 164 | NPN_UserAgentProcPtr uagent; 165 | NPN_MemAllocProcPtr memalloc; 166 | NPN_MemFreeProcPtr memfree; 167 | NPN_MemFlushProcPtr memflush; 168 | NPN_ReloadPluginsProcPtr reloadplugins; 169 | NPN_GetJavaEnvProcPtr getJavaEnv; 170 | NPN_GetJavaPeerProcPtr getJavaPeer; 171 | NPN_GetURLNotifyProcPtr geturlnotify; 172 | NPN_PostURLNotifyProcPtr posturlnotify; 173 | NPN_GetValueProcPtr getvalue; 174 | NPN_SetValueProcPtr setvalue; 175 | NPN_InvalidateRectProcPtr invalidaterect; 176 | NPN_InvalidateRegionProcPtr invalidateregion; 177 | NPN_ForceRedrawProcPtr forceredraw; 178 | NPN_GetStringIdentifierProcPtr getstringidentifier; 179 | NPN_GetStringIdentifiersProcPtr getstringidentifiers; 180 | NPN_GetIntIdentifierProcPtr getintidentifier; 181 | NPN_IdentifierIsStringProcPtr identifierisstring; 182 | NPN_UTF8FromIdentifierProcPtr utf8fromidentifier; 183 | NPN_IntFromIdentifierProcPtr intfromidentifier; 184 | NPN_CreateObjectProcPtr createobject; 185 | NPN_RetainObjectProcPtr retainobject; 186 | NPN_ReleaseObjectProcPtr releaseobject; 187 | NPN_InvokeProcPtr invoke; 188 | NPN_InvokeDefaultProcPtr invokeDefault; 189 | NPN_EvaluateProcPtr evaluate; 190 | NPN_GetPropertyProcPtr getproperty; 191 | NPN_SetPropertyProcPtr setproperty; 192 | NPN_RemovePropertyProcPtr removeproperty; 193 | NPN_HasPropertyProcPtr hasproperty; 194 | NPN_HasMethodProcPtr hasmethod; 195 | NPN_ReleaseVariantValueProcPtr releasevariantvalue; 196 | NPN_SetExceptionProcPtr setexception; 197 | NPN_PushPopupsEnabledStateProcPtr pushpopupsenabledstate; 198 | NPN_PopPopupsEnabledStateProcPtr poppopupsenabledstate; 199 | NPN_EnumerateProcPtr enumerate; 200 | NPN_PluginThreadAsyncCallProcPtr pluginthreadasynccall; 201 | NPN_ConstructProcPtr construct; 202 | NPN_GetValueForURLPtr getvalueforurl; 203 | NPN_SetValueForURLPtr setvalueforurl; 204 | NPN_GetAuthenticationInfoPtr getauthenticationinfo; 205 | NPN_ScheduleTimerPtr scheduletimer; 206 | NPN_UnscheduleTimerPtr unscheduletimer; 207 | NPN_PopUpContextMenuPtr popupcontextmenu; 208 | NPN_ConvertPointPtr convertpoint; 209 | NPN_HandleEventPtr handleevent; 210 | NPN_UnfocusInstancePtr unfocusinstance; 211 | NPN_URLRedirectResponsePtr urlredirectresponse; 212 | } NPNetscapeFuncs; 213 | 214 | #ifdef XP_MACOSX 215 | /* 216 | * Mac OS X version(s) of NP_GetMIMEDescription(const char *) 217 | * These can be called to retreive MIME information from the plugin dynamically 218 | * 219 | * Note: For compatibility with Quicktime, BPSupportedMIMEtypes is another way 220 | * to get mime info from the plugin only on OSX and may not be supported 221 | * in furture version -- use NP_GetMIMEDescription instead 222 | */ 223 | enum 224 | { 225 | kBPSupportedMIMETypesStructVers_1 = 1 226 | }; 227 | typedef struct _BPSupportedMIMETypes 228 | { 229 | SInt32 structVersion; /* struct version */ 230 | Handle typeStrings; /* STR# formated handle, allocated by plug-in */ 231 | Handle infoStrings; /* STR# formated handle, allocated by plug-in */ 232 | } BPSupportedMIMETypes; 233 | OSErr BP_GetSupportedMIMETypes(BPSupportedMIMETypes *mimeInfo, UInt32 flags); 234 | #define NP_GETMIMEDESCRIPTION_NAME "NP_GetMIMEDescription" 235 | typedef const char* (*NP_GetMIMEDescriptionProcPtr)(void); 236 | typedef OSErr (*BP_GetSupportedMIMETypesProcPtr)(BPSupportedMIMETypes*, UInt32); 237 | #endif 238 | 239 | #if defined(_WIN32) 240 | #define OSCALL WINAPI 241 | #else 242 | #if defined(__OS2__) 243 | #define OSCALL _System 244 | #else 245 | #define OSCALL 246 | #endif 247 | #endif 248 | 249 | #if defined(XP_UNIX) 250 | /* GCC 3.3 and later support the visibility attribute. */ 251 | #if defined(__GNUC__) && ((__GNUC__ >= 4) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) 252 | #define NP_VISIBILITY_DEFAULT __attribute__((visibility("default"))) 253 | #elif defined(__SUNPRO_C) || defined(__SUNPRO_CC) 254 | #define NP_VISIBILITY_DEFAULT __global 255 | #else 256 | #define NP_VISIBILITY_DEFAULT 257 | #endif 258 | #define NP_EXPORT(__type) NP_VISIBILITY_DEFAULT __type 259 | #endif 260 | 261 | #if defined(_WIN32) || defined (__OS2__) 262 | #ifdef __cplusplus 263 | extern "C" { 264 | #endif 265 | /* plugin meta member functions */ 266 | #if defined(__OS2__) 267 | typedef struct _NPPluginData { /* Alternate OS2 Plugin interface */ 268 | char *pMimeTypes; 269 | char *pFileExtents; 270 | char *pFileOpenTemplate; 271 | char *pProductName; 272 | char *pProductDescription; 273 | unsigned long dwProductVersionMS; 274 | unsigned long dwProductVersionLS; 275 | } NPPluginData; 276 | typedef NPError (*NP_GetPluginDataFunc)(NPPluginData*); 277 | NPError OSCALL NP_GetPluginData(NPPluginData * pPluginData); 278 | #endif 279 | typedef NPError (*NP_GetEntryPointsFunc)(NPPluginFuncs*); 280 | NPError OSCALL NP_GetEntryPoints(NPPluginFuncs* pFuncs); 281 | typedef NPError (*NP_InitializeFunc)(NPNetscapeFuncs*); 282 | NPError OSCALL NP_Initialize(NPNetscapeFuncs* bFuncs); 283 | typedef NPError (*NP_ShutdownFunc)(void); 284 | NPError OSCALL NP_Shutdown(void); 285 | typedef const char* (*NP_GetMIMEDescriptionFunc)(void); 286 | const char* NP_GetMIMEDescription(void); 287 | #ifdef __cplusplus 288 | } 289 | #endif 290 | #endif 291 | 292 | #if defined(__OS2__) 293 | #pragma pack() 294 | #endif 295 | 296 | #ifdef XP_UNIX 297 | #ifdef __cplusplus 298 | extern "C" { 299 | #endif 300 | typedef char* (*NP_GetPluginVersionFunc)(void); 301 | NP_EXPORT(char*) NP_GetPluginVersion(void); 302 | typedef const char* (*NP_GetMIMEDescriptionFunc)(void); 303 | NP_EXPORT(const char*) NP_GetMIMEDescription(void); 304 | #ifdef XP_MACOSX 305 | typedef NPError (*NP_InitializeFunc)(NPNetscapeFuncs*); 306 | NP_EXPORT(NPError) NP_Initialize(NPNetscapeFuncs* bFuncs); 307 | typedef NPError (*NP_GetEntryPointsFunc)(NPPluginFuncs*); 308 | NP_EXPORT(NPError) NP_GetEntryPoints(NPPluginFuncs* pFuncs); 309 | #else 310 | typedef NPError (*NP_InitializeFunc)(NPNetscapeFuncs*, NPPluginFuncs*); 311 | NP_EXPORT(NPError) NP_Initialize(NPNetscapeFuncs* bFuncs, NPPluginFuncs* pFuncs); 312 | #endif 313 | typedef NPError (*NP_ShutdownFunc)(void); 314 | NP_EXPORT(NPError) NP_Shutdown(void); 315 | typedef NPError (*NP_GetValueFunc)(void *, NPPVariable, void *); 316 | NP_EXPORT(NPError) NP_GetValue(void *future, NPPVariable aVariable, void *aValue); 317 | #ifdef __cplusplus 318 | } 319 | #endif 320 | #endif 321 | 322 | #endif /* npfunctions_h_ */ 323 | -------------------------------------------------------------------------------- /npapi/src/npapi_headers/npruntime.h: -------------------------------------------------------------------------------- 1 | /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 | /* 3 | * Copyright (c) 2004, Apple Computer, Inc. and The Mozilla Foundation. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions are 8 | * met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the names of Apple Computer, Inc. ("Apple") or The Mozilla 16 | * Foundation ("Mozilla") nor the names of their contributors may be used 17 | * to endorse or promote products derived from this software without 18 | * specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY APPLE, MOZILLA AND THEIR CONTRIBUTORS "AS 21 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 23 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE, MOZILLA OR 24 | * THEIR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 26 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | */ 33 | #ifndef _NP_RUNTIME_H_ 34 | #define _NP_RUNTIME_H_ 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | #include "nptypes.h" 41 | 42 | /* 43 | This API is used to facilitate binding code written in C to script 44 | objects. The API in this header does not assume the presence of a 45 | user agent. That is, it can be used to bind C code to scripting 46 | environments outside of the context of a user agent. 47 | 48 | However, the normal use of the this API is in the context of a 49 | scripting environment running in a browser or other user agent. 50 | In particular it is used to support the extended Netscape 51 | script-ability API for plugins (NP-SAP). NP-SAP is an extension 52 | of the Netscape plugin API. As such we have adopted the use of 53 | the "NP" prefix for this API. 54 | 55 | The following NP{N|P}Variables were added to the Netscape plugin 56 | API (in npapi.h): 57 | 58 | NPNVWindowNPObject 59 | NPNVPluginElementNPObject 60 | NPPVpluginScriptableNPObject 61 | 62 | These variables are exposed through NPN_GetValue() and 63 | NPP_GetValue() (respectively) and are used to establish the 64 | initial binding between the user agent and native code. The DOM 65 | objects in the user agent can be examined and manipulated using 66 | the NPN_ functions that operate on NPObjects described in this 67 | header. 68 | 69 | To the extent possible the assumptions about the scripting 70 | language used by the scripting environment have been minimized. 71 | */ 72 | 73 | #define NP_BEGIN_MACRO do { 74 | #define NP_END_MACRO } while (0) 75 | 76 | /* 77 | Objects (non-primitive data) passed between 'C' and script is 78 | always wrapped in an NPObject. The 'interface' of an NPObject is 79 | described by an NPClass. 80 | */ 81 | typedef struct NPObject NPObject; 82 | typedef struct NPClass NPClass; 83 | 84 | typedef char NPUTF8; 85 | typedef struct _NPString { 86 | const NPUTF8 *UTF8Characters; 87 | uint32_t UTF8Length; 88 | } NPString; 89 | 90 | typedef enum { 91 | NPVariantType_Void, 92 | NPVariantType_Null, 93 | NPVariantType_Bool, 94 | NPVariantType_Int32, 95 | NPVariantType_Double, 96 | NPVariantType_String, 97 | NPVariantType_Object 98 | } NPVariantType; 99 | 100 | typedef struct _NPVariant { 101 | NPVariantType type; 102 | union { 103 | bool boolValue; 104 | int32_t intValue; 105 | double doubleValue; 106 | NPString stringValue; 107 | NPObject *objectValue; 108 | } value; 109 | } NPVariant; 110 | 111 | /* 112 | NPN_ReleaseVariantValue is called on all 'out' parameters 113 | references. Specifically it is to be called on variants that own 114 | their value, as is the case with all non-const NPVariant* 115 | arguments after a successful call to any methods (except this one) 116 | in this API. 117 | 118 | After calling NPN_ReleaseVariantValue, the type of the variant 119 | will be NPVariantType_Void. 120 | */ 121 | void NPN_ReleaseVariantValue(NPVariant *variant); 122 | 123 | #define NPVARIANT_IS_VOID(_v) ((_v).type == NPVariantType_Void) 124 | #define NPVARIANT_IS_NULL(_v) ((_v).type == NPVariantType_Null) 125 | #define NPVARIANT_IS_BOOLEAN(_v) ((_v).type == NPVariantType_Bool) 126 | #define NPVARIANT_IS_INT32(_v) ((_v).type == NPVariantType_Int32) 127 | #define NPVARIANT_IS_DOUBLE(_v) ((_v).type == NPVariantType_Double) 128 | #define NPVARIANT_IS_STRING(_v) ((_v).type == NPVariantType_String) 129 | #define NPVARIANT_IS_OBJECT(_v) ((_v).type == NPVariantType_Object) 130 | 131 | #define NPVARIANT_TO_BOOLEAN(_v) ((_v).value.boolValue) 132 | #define NPVARIANT_TO_INT32(_v) ((_v).value.intValue) 133 | #define NPVARIANT_TO_DOUBLE(_v) ((_v).value.doubleValue) 134 | #define NPVARIANT_TO_STRING(_v) ((_v).value.stringValue) 135 | #define NPVARIANT_TO_OBJECT(_v) ((_v).value.objectValue) 136 | 137 | #define VOID_TO_NPVARIANT(_v) \ 138 | NP_BEGIN_MACRO \ 139 | (_v).type = NPVariantType_Void; \ 140 | (_v).value.objectValue = NULL; \ 141 | NP_END_MACRO 142 | 143 | #define NULL_TO_NPVARIANT(_v) \ 144 | NP_BEGIN_MACRO \ 145 | (_v).type = NPVariantType_Null; \ 146 | (_v).value.objectValue = NULL; \ 147 | NP_END_MACRO 148 | 149 | #define BOOLEAN_TO_NPVARIANT(_val, _v) \ 150 | NP_BEGIN_MACRO \ 151 | (_v).type = NPVariantType_Bool; \ 152 | (_v).value.boolValue = !!(_val); \ 153 | NP_END_MACRO 154 | 155 | #define INT32_TO_NPVARIANT(_val, _v) \ 156 | NP_BEGIN_MACRO \ 157 | (_v).type = NPVariantType_Int32; \ 158 | (_v).value.intValue = _val; \ 159 | NP_END_MACRO 160 | 161 | #define DOUBLE_TO_NPVARIANT(_val, _v) \ 162 | NP_BEGIN_MACRO \ 163 | (_v).type = NPVariantType_Double; \ 164 | (_v).value.doubleValue = _val; \ 165 | NP_END_MACRO 166 | 167 | #define STRINGZ_TO_NPVARIANT(_val, _v) \ 168 | NP_BEGIN_MACRO \ 169 | (_v).type = NPVariantType_String; \ 170 | NPString str = { _val, (uint32_t)(strlen(_val)) }; \ 171 | (_v).value.stringValue = str; \ 172 | NP_END_MACRO 173 | 174 | #define STRINGN_TO_NPVARIANT(_val, _len, _v) \ 175 | NP_BEGIN_MACRO \ 176 | (_v).type = NPVariantType_String; \ 177 | NPString str = { _val, (uint32_t)(_len) }; \ 178 | (_v).value.stringValue = str; \ 179 | NP_END_MACRO 180 | 181 | #define OBJECT_TO_NPVARIANT(_val, _v) \ 182 | NP_BEGIN_MACRO \ 183 | (_v).type = NPVariantType_Object; \ 184 | (_v).value.objectValue = _val; \ 185 | NP_END_MACRO 186 | 187 | 188 | /* 189 | Type mappings (JavaScript types have been used for illustration 190 | purposes): 191 | 192 | JavaScript to C (NPVariant with type:) 193 | undefined NPVariantType_Void 194 | null NPVariantType_Null 195 | Boolean NPVariantType_Bool 196 | Number NPVariantType_Double or NPVariantType_Int32 197 | String NPVariantType_String 198 | Object NPVariantType_Object 199 | 200 | C (NPVariant with type:) to JavaScript 201 | NPVariantType_Void undefined 202 | NPVariantType_Null null 203 | NPVariantType_Bool Boolean 204 | NPVariantType_Int32 Number 205 | NPVariantType_Double Number 206 | NPVariantType_String String 207 | NPVariantType_Object Object 208 | */ 209 | 210 | typedef void *NPIdentifier; 211 | 212 | /* 213 | NPObjects have methods and properties. Methods and properties are 214 | identified with NPIdentifiers. These identifiers may be reflected 215 | in script. NPIdentifiers can be either strings or integers, IOW, 216 | methods and properties can be identified by either strings or 217 | integers (i.e. foo["bar"] vs foo[1]). NPIdentifiers can be 218 | compared using ==. In case of any errors, the requested 219 | NPIdentifier(s) will be NULL. NPIdentifier lifetime is controlled 220 | by the browser. Plugins do not need to worry about memory management 221 | with regards to NPIdentifiers. 222 | */ 223 | NPIdentifier NPN_GetStringIdentifier(const NPUTF8 *name); 224 | void NPN_GetStringIdentifiers(const NPUTF8 **names, int32_t nameCount, 225 | NPIdentifier *identifiers); 226 | NPIdentifier NPN_GetIntIdentifier(int32_t intid); 227 | bool NPN_IdentifierIsString(NPIdentifier identifier); 228 | 229 | /* 230 | The NPUTF8 returned from NPN_UTF8FromIdentifier SHOULD be freed. 231 | */ 232 | NPUTF8 *NPN_UTF8FromIdentifier(NPIdentifier identifier); 233 | 234 | /* 235 | Get the integer represented by identifier. If identifier is not an 236 | integer identifier, the behaviour is undefined. 237 | */ 238 | int32_t NPN_IntFromIdentifier(NPIdentifier identifier); 239 | 240 | /* 241 | NPObject behavior is implemented using the following set of 242 | callback functions. 243 | 244 | The NPVariant *result argument of these functions (where 245 | applicable) should be released using NPN_ReleaseVariantValue(). 246 | */ 247 | typedef NPObject *(*NPAllocateFunctionPtr)(NPP npp, NPClass *aClass); 248 | typedef void (*NPDeallocateFunctionPtr)(NPObject *npobj); 249 | typedef void (*NPInvalidateFunctionPtr)(NPObject *npobj); 250 | typedef bool (*NPHasMethodFunctionPtr)(NPObject *npobj, NPIdentifier name); 251 | typedef bool (*NPInvokeFunctionPtr)(NPObject *npobj, NPIdentifier name, 252 | const NPVariant *args, uint32_t argCount, 253 | NPVariant *result); 254 | typedef bool (*NPInvokeDefaultFunctionPtr)(NPObject *npobj, 255 | const NPVariant *args, 256 | uint32_t argCount, 257 | NPVariant *result); 258 | typedef bool (*NPHasPropertyFunctionPtr)(NPObject *npobj, NPIdentifier name); 259 | typedef bool (*NPGetPropertyFunctionPtr)(NPObject *npobj, NPIdentifier name, 260 | NPVariant *result); 261 | typedef bool (*NPSetPropertyFunctionPtr)(NPObject *npobj, NPIdentifier name, 262 | const NPVariant *value); 263 | typedef bool (*NPRemovePropertyFunctionPtr)(NPObject *npobj, 264 | NPIdentifier name); 265 | typedef bool (*NPEnumerationFunctionPtr)(NPObject *npobj, NPIdentifier **value, 266 | uint32_t *count); 267 | typedef bool (*NPConstructFunctionPtr)(NPObject *npobj, 268 | const NPVariant *args, 269 | uint32_t argCount, 270 | NPVariant *result); 271 | 272 | /* 273 | NPObjects returned by create, retain, invoke, and getProperty pass 274 | a reference count to the caller. That is, the callee adds a 275 | reference count which passes to the caller. It is the caller's 276 | responsibility to release the returned object. 277 | 278 | NPInvokeFunctionPtr function may return 0 to indicate a void 279 | result. 280 | 281 | NPInvalidateFunctionPtr is called by the scripting environment 282 | when the native code is shutdown. Any attempt to message a 283 | NPObject instance after the invalidate callback has been 284 | called will result in undefined behavior, even if the native code 285 | is still retaining those NPObject instances. (The runtime 286 | will typically return immediately, with 0 or NULL, from an attempt 287 | to dispatch to a NPObject, but this behavior should not be 288 | depended upon.) 289 | 290 | The NPEnumerationFunctionPtr function may pass an array of 291 | NPIdentifiers back to the caller. The callee allocs the memory of 292 | the array using NPN_MemAlloc(), and it's the caller's responsibility 293 | to release it using NPN_MemFree(). 294 | */ 295 | struct NPClass 296 | { 297 | uint32_t structVersion; 298 | NPAllocateFunctionPtr allocate; 299 | NPDeallocateFunctionPtr deallocate; 300 | NPInvalidateFunctionPtr invalidate; 301 | NPHasMethodFunctionPtr hasMethod; 302 | NPInvokeFunctionPtr invoke; 303 | NPInvokeDefaultFunctionPtr invokeDefault; 304 | NPHasPropertyFunctionPtr hasProperty; 305 | NPGetPropertyFunctionPtr getProperty; 306 | NPSetPropertyFunctionPtr setProperty; 307 | NPRemovePropertyFunctionPtr removeProperty; 308 | NPEnumerationFunctionPtr enumerate; 309 | NPConstructFunctionPtr construct; 310 | }; 311 | 312 | #define NP_CLASS_STRUCT_VERSION 3 313 | 314 | #define NP_CLASS_STRUCT_VERSION_ENUM 2 315 | #define NP_CLASS_STRUCT_VERSION_CTOR 3 316 | 317 | #define NP_CLASS_STRUCT_VERSION_HAS_ENUM(npclass) \ 318 | ((npclass)->structVersion >= NP_CLASS_STRUCT_VERSION_ENUM) 319 | 320 | #define NP_CLASS_STRUCT_VERSION_HAS_CTOR(npclass) \ 321 | ((npclass)->structVersion >= NP_CLASS_STRUCT_VERSION_CTOR) 322 | 323 | struct NPObject { 324 | NPClass *_class; 325 | uint32_t referenceCount; 326 | /* 327 | * Additional space may be allocated here by types of NPObjects 328 | */ 329 | }; 330 | 331 | /* 332 | If the class has an allocate function, NPN_CreateObject invokes 333 | that function, otherwise a NPObject is allocated and 334 | returned. This method will initialize the referenceCount member of 335 | the NPObject to 1. 336 | */ 337 | NPObject *NPN_CreateObject(NPP npp, NPClass *aClass); 338 | 339 | /* 340 | Increment the NPObject's reference count. 341 | */ 342 | NPObject *NPN_RetainObject(NPObject *npobj); 343 | 344 | /* 345 | Decremented the NPObject's reference count. If the reference 346 | count goes to zero, the class's destroy function is invoke if 347 | specified, otherwise the object is freed directly. 348 | */ 349 | void NPN_ReleaseObject(NPObject *npobj); 350 | 351 | /* 352 | Functions to access script objects represented by NPObject. 353 | 354 | Calls to script objects are synchronous. If a function returns a 355 | value, it will be supplied via the result NPVariant 356 | argument. Successful calls will return true, false will be 357 | returned in case of an error. 358 | 359 | Calls made from plugin code to script must be made from the thread 360 | on which the plugin was initialized. 361 | */ 362 | 363 | bool NPN_Invoke(NPP npp, NPObject *npobj, NPIdentifier methodName, 364 | const NPVariant *args, uint32_t argCount, NPVariant *result); 365 | bool NPN_InvokeDefault(NPP npp, NPObject *npobj, const NPVariant *args, 366 | uint32_t argCount, NPVariant *result); 367 | bool NPN_Evaluate(NPP npp, NPObject *npobj, NPString *script, 368 | NPVariant *result); 369 | bool NPN_GetProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName, 370 | NPVariant *result); 371 | bool NPN_SetProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName, 372 | const NPVariant *value); 373 | bool NPN_RemoveProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName); 374 | bool NPN_HasProperty(NPP npp, NPObject *npobj, NPIdentifier propertyName); 375 | bool NPN_HasMethod(NPP npp, NPObject *npobj, NPIdentifier methodName); 376 | bool NPN_Enumerate(NPP npp, NPObject *npobj, NPIdentifier **identifier, 377 | uint32_t *count); 378 | bool NPN_Construct(NPP npp, NPObject *npobj, const NPVariant *args, 379 | uint32_t argCount, NPVariant *result); 380 | 381 | /* 382 | NPN_SetException may be called to trigger a script exception upon 383 | return from entry points into NPObjects. Typical usage: 384 | 385 | NPN_SetException (npobj, message); 386 | */ 387 | void NPN_SetException(NPObject *npobj, const NPUTF8 *message); 388 | 389 | #ifdef __cplusplus 390 | } 391 | #endif 392 | 393 | #endif 394 | -------------------------------------------------------------------------------- /core/lib/bootstrap/js/bootstrap.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap.js by @fat & @mdo 3 | * Copyright 2013 Twitter, Inc. 4 | * http://www.apache.org/licenses/LICENSE-2.0.txt 5 | */ 6 | !function(e){"use strict";e(function(){e.support.transition=function(){var e=function(){var e=document.createElement("bootstrap"),t={WebkitTransition:"webkitTransitionEnd",MozTransition:"transitionend",OTransition:"oTransitionEnd otransitionend",transition:"transitionend"},n;for(n in t)if(e.style[n]!==undefined)return t[n]}();return e&&{end:e}}()})}(window.jQuery),!function(e){"use strict";var t='[data-dismiss="alert"]',n=function(n){e(n).on("click",t,this.close)};n.prototype.close=function(t){function s(){i.trigger("closed").remove()}var n=e(this),r=n.attr("data-target"),i;r||(r=n.attr("href"),r=r&&r.replace(/.*(?=#[^\s]*$)/,"")),i=e(r),t&&t.preventDefault(),i.length||(i=n.hasClass("alert")?n:n.parent()),i.trigger(t=e.Event("close"));if(t.isDefaultPrevented())return;i.removeClass("in"),e.support.transition&&i.hasClass("fade")?i.on(e.support.transition.end,s):s()};var r=e.fn.alert;e.fn.alert=function(t){return this.each(function(){var r=e(this),i=r.data("alert");i||r.data("alert",i=new n(this)),typeof t=="string"&&i[t].call(r)})},e.fn.alert.Constructor=n,e.fn.alert.noConflict=function(){return e.fn.alert=r,this},e(document).on("click.alert.data-api",t,n.prototype.close)}(window.jQuery),!function(e){"use strict";var t=function(t,n){this.$element=e(t),this.options=e.extend({},e.fn.button.defaults,n)};t.prototype.setState=function(e){var t="disabled",n=this.$element,r=n.data(),i=n.is("input")?"val":"html";e+="Text",r.resetText||n.data("resetText",n[i]()),n[i](r[e]||this.options[e]),setTimeout(function(){e=="loadingText"?n.addClass(t).attr(t,t):n.removeClass(t).removeAttr(t)},0)},t.prototype.toggle=function(){var e=this.$element.closest('[data-toggle="buttons-radio"]');e&&e.find(".active").removeClass("active"),this.$element.toggleClass("active")};var n=e.fn.button;e.fn.button=function(n){return this.each(function(){var r=e(this),i=r.data("button"),s=typeof n=="object"&&n;i||r.data("button",i=new t(this,s)),n=="toggle"?i.toggle():n&&i.setState(n)})},e.fn.button.defaults={loadingText:"loading..."},e.fn.button.Constructor=t,e.fn.button.noConflict=function(){return e.fn.button=n,this},e(document).on("click.button.data-api","[data-toggle^=button]",function(t){var n=e(t.target);n.hasClass("btn")||(n=n.closest(".btn")),n.button("toggle")})}(window.jQuery),!function(e){"use strict";var t=function(t,n){this.$element=e(t),this.$indicators=this.$element.find(".carousel-indicators"),this.options=n,this.options.pause=="hover"&&this.$element.on("mouseenter",e.proxy(this.pause,this)).on("mouseleave",e.proxy(this.cycle,this))};t.prototype={cycle:function(t){return t||(this.paused=!1),this.interval&&clearInterval(this.interval),this.options.interval&&!this.paused&&(this.interval=setInterval(e.proxy(this.next,this),this.options.interval)),this},getActiveIndex:function(){return this.$active=this.$element.find(".item.active"),this.$items=this.$active.parent().children(),this.$items.index(this.$active)},to:function(t){var n=this.getActiveIndex(),r=this;if(t>this.$items.length-1||t<0)return;return this.sliding?this.$element.one("slid",function(){r.to(t)}):n==t?this.pause().cycle():this.slide(t>n?"next":"prev",e(this.$items[t]))},pause:function(t){return t||(this.paused=!0),this.$element.find(".next, .prev").length&&e.support.transition.end&&(this.$element.trigger(e.support.transition.end),this.cycle(!0)),clearInterval(this.interval),this.interval=null,this},next:function(){if(this.sliding)return;return this.slide("next")},prev:function(){if(this.sliding)return;return this.slide("prev")},slide:function(t,n){var r=this.$element.find(".item.active"),i=n||r[t](),s=this.interval,o=t=="next"?"left":"right",u=t=="next"?"first":"last",a=this,f;this.sliding=!0,s&&this.pause(),i=i.length?i:this.$element.find(".item")[u](),f=e.Event("slide",{relatedTarget:i[0],direction:o});if(i.hasClass("active"))return;this.$indicators.length&&(this.$indicators.find(".active").removeClass("active"),this.$element.one("slid",function(){var t=e(a.$indicators.children()[a.getActiveIndex()]);t&&t.addClass("active")}));if(e.support.transition&&this.$element.hasClass("slide")){this.$element.trigger(f);if(f.isDefaultPrevented())return;i.addClass(t),i[0].offsetWidth,r.addClass(o),i.addClass(o),this.$element.one(e.support.transition.end,function(){i.removeClass([t,o].join(" ")).addClass("active"),r.removeClass(["active",o].join(" ")),a.sliding=!1,setTimeout(function(){a.$element.trigger("slid")},0)})}else{this.$element.trigger(f);if(f.isDefaultPrevented())return;r.removeClass("active"),i.addClass("active"),this.sliding=!1,this.$element.trigger("slid")}return s&&this.cycle(),this}};var n=e.fn.carousel;e.fn.carousel=function(n){return this.each(function(){var r=e(this),i=r.data("carousel"),s=e.extend({},e.fn.carousel.defaults,typeof n=="object"&&n),o=typeof n=="string"?n:s.slide;i||r.data("carousel",i=new t(this,s)),typeof n=="number"?i.to(n):o?i[o]():s.interval&&i.pause().cycle()})},e.fn.carousel.defaults={interval:5e3,pause:"hover"},e.fn.carousel.Constructor=t,e.fn.carousel.noConflict=function(){return e.fn.carousel=n,this},e(document).on("click.carousel.data-api","[data-slide], [data-slide-to]",function(t){var n=e(this),r,i=e(n.attr("data-target")||(r=n.attr("href"))&&r.replace(/.*(?=#[^\s]+$)/,"")),s=e.extend({},i.data(),n.data()),o;i.carousel(s),(o=n.attr("data-slide-to"))&&i.data("carousel").pause().to(o).cycle(),t.preventDefault()})}(window.jQuery),!function(e){"use strict";var t=function(t,n){this.$element=e(t),this.options=e.extend({},e.fn.collapse.defaults,n),this.options.parent&&(this.$parent=e(this.options.parent)),this.options.toggle&&this.toggle()};t.prototype={constructor:t,dimension:function(){var e=this.$element.hasClass("width");return e?"width":"height"},show:function(){var t,n,r,i;if(this.transitioning||this.$element.hasClass("in"))return;t=this.dimension(),n=e.camelCase(["scroll",t].join("-")),r=this.$parent&&this.$parent.find("> .accordion-group > .in");if(r&&r.length){i=r.data("collapse");if(i&&i.transitioning)return;r.collapse("hide"),i||r.data("collapse",null)}this.$element[t](0),this.transition("addClass",e.Event("show"),"shown"),e.support.transition&&this.$element[t](this.$element[0][n])},hide:function(){var t;if(this.transitioning||!this.$element.hasClass("in"))return;t=this.dimension(),this.reset(this.$element[t]()),this.transition("removeClass",e.Event("hide"),"hidden"),this.$element[t](0)},reset:function(e){var t=this.dimension();return this.$element.removeClass("collapse")[t](e||"auto")[0].offsetWidth,this.$element[e!==null?"addClass":"removeClass"]("collapse"),this},transition:function(t,n,r){var i=this,s=function(){n.type=="show"&&i.reset(),i.transitioning=0,i.$element.trigger(r)};this.$element.trigger(n);if(n.isDefaultPrevented())return;this.transitioning=1,this.$element[t]("in"),e.support.transition&&this.$element.hasClass("collapse")?this.$element.one(e.support.transition.end,s):s()},toggle:function(){this[this.$element.hasClass("in")?"hide":"show"]()}};var n=e.fn.collapse;e.fn.collapse=function(n){return this.each(function(){var r=e(this),i=r.data("collapse"),s=e.extend({},e.fn.collapse.defaults,r.data(),typeof n=="object"&&n);i||r.data("collapse",i=new t(this,s)),typeof n=="string"&&i[n]()})},e.fn.collapse.defaults={toggle:!0},e.fn.collapse.Constructor=t,e.fn.collapse.noConflict=function(){return e.fn.collapse=n,this},e(document).on("click.collapse.data-api","[data-toggle=collapse]",function(t){var n=e(this),r,i=n.attr("data-target")||t.preventDefault()||(r=n.attr("href"))&&r.replace(/.*(?=#[^\s]+$)/,""),s=e(i).data("collapse")?"toggle":n.data();n[e(i).hasClass("in")?"addClass":"removeClass"]("collapsed"),e(i).collapse(s)})}(window.jQuery),!function(e){"use strict";function r(){e(".dropdown-backdrop").remove(),e(t).each(function(){i(e(this)).removeClass("open")})}function i(t){var n=t.attr("data-target"),r;n||(n=t.attr("href"),n=n&&/#/.test(n)&&n.replace(/.*(?=#[^\s]*$)/,"")),r=n&&e(n);if(!r||!r.length)r=t.parent();return r}var t="[data-toggle=dropdown]",n=function(t){var n=e(t).on("click.dropdown.data-api",this.toggle);e("html").on("click.dropdown.data-api",function(){n.parent().removeClass("open")})};n.prototype={constructor:n,toggle:function(t){var n=e(this),s,o;if(n.is(".disabled, :disabled"))return;return s=i(n),o=s.hasClass("open"),r(),o||("ontouchstart"in document.documentElement&&e('