?? airintrospector.js
字號:
air.Introspector.highlightElement(e.srcElement);
air.Introspector.showHighlightLabels(e.srcElement.id, e.srcElement.nodeName, e.srcElement.outerHTML);
}else{
air.Introspector.highlightElement(e.srcElement, function(){
air.Introspector.noBridge(function(){
parentSandboxBridge.air_Introspector_showHighlightLabels(e.srcElement.id, e.srcElement.nodeName, e.srcElement.outerHTML);
});
});
}
if(hoverTimeout) clearTimeout(hoverTimeout);
hoverTimeout = setTimeout(function(){
air.Introspector.init(false, true, function (){
air.Introspector.debugWindow.setInspectElement(e.srcElement);
});
}, 100);
}else{
air.Introspector.hideHighlight();
}
}, 0);
}else if(isAppSandbox){
air.Introspector.lastElement = e.srcElement;
}
}, true);
//document.body.addEventListener('mouseout', function(e){
// air.Introspector.hideHighlight();
//});
},
/**
* @function cleanup
* @description Cleans up the html loader
*
*/
cleanup: function(){
for(var i=eventListeners.length-1;i>=0;i--){
var l = eventListeners[i];
try{
l[0].removeEventListener(l[1], l[2], l[3]);
}catch(e){}
}
eventListeners = [];
try{
window.htmlLoader.stage.removeChild(air.Introspector.highlightText);
}catch(e){}
},
/**
* @function register
* @description Registers current window in debugger
*
* Captures every XHR object created and any uncaught exception
* and sends it to the debugger
*/
register: function(){
if (window.XMLHttpRequest && window.XMLHttpRequest.prototype){
window.XMLHttpRequest.prototype.debugopen = window.XMLHttpRequest.prototype.open;
window.XMLHttpRequest.prototype.debugsend = window.XMLHttpRequest.prototype.send;
window.XMLHttpRequest.prototype.open = function(method, url, asyncFlag, username, password){
if(typeof this.doNotDebug=='undefined'){
var debugWindow = air.Introspector.findDebugWindow();
if(debugWindow!=null){
debugWindow.logNet(this, method, url, asyncFlag);
}
}
return this.debugopen(method, url, asyncFlag, username, password);
};
window.XMLHttpRequest.prototype.send = function(obj){
if(typeof this.doNotDebug=='undefined'){
var self = this;
var debugWindow = air.Introspector.findDebugWindow();
if(debugWindow!=null){
var a = this.onreadystatechange;
this.onreadystatechange = function(){
if (typeof a == 'function')a.call(self);
debugWindow.logNet(self, 'unknown', '', false);
};
if(typeof self.doNotDebug=='undefined')
debugWindow.logNetSend(this, obj);
}
var ret = this.debugsend(obj);
if(debugWindow!=null){
debugWindow.logNetSend(this, obj);
}
return ret;
}else{
return this.debugsend(obj);
}
}
}
if(isAppSandbox){
air.Introspector.addKeyboardEvents(window.htmlLoader.stage);
air.Introspector.registerUncaughtExceptionListener();
air.Introspector.registerCloseEventListener();
air.Introspector.registerCompleteEventListener();
air.Introspector.registerDeactivateEventListener();
air.Introspector.createHighlight();
}else{
air.Introspector.registerChildSandboxBridge();
}
air.Introspector.waitForBody(document, function(){
try{
if(!isAppSandbox){ air.Introspector.createOpenConsoleButton(); }
air.Introspector.registerDOMEventListeners();
window.addEventListener('unload', function(){
try{
air.Introspector.cleanup();
if(!isAppSandbox){
//our debugger can NOT live without it's parent
air.Introspector.debugWindow.window.close();
}
}catch(e){ }
});
}catch(e){
if(isAppSandbox){
runtime.trace(e);
runtime.trace(e.line);
}
air.Introspector.Console.log(e);
}
});
},
/**
* @function registerFrame
* @description Makes the parentSandboxBridge available to frame
*/
registerFrame: function(frame){
if(typeof frame.contentWindow.parentSandboxBridge=='undefined')
frame.contentWindow.parentSandboxBridge = {};
/*frame.contentWindow.parentSandboxBridge.trace = function(a){
runtime.trace(a);
};*/
//checking that the bridge is not already there
/*var modified = typeof frame.contentWindow.parentSandboxBridge.air_Introspector_hideHighlight=='undefined'
|| typeof frame.contentWindow.parentSandboxBridge.air_Introspector_showHighlight=='undefined'
|| typeof frame.contentWindow.parentSandboxBridge.air_Introspector_drawRect=='undefined'
|| typeof frame.contentWindow.parentSandboxBridge.air_Introspector_setInspect=='undefined'
|| typeof frame.contentWindow.parentSandboxBridge.air_Introspector_getWindowTitle=='undefined'
|| typeof frame.contentWindow.parentSandboxBridge.air_Introspector_checkNativeWindow=='undefined'
|| typeof frame.contentWindow.parentSandboxBridge.air_Introspector_writeConsoleToClipboard=='undefined'
|| typeof frame.contentWindow.parentSandboxBridge.air_Introspector_writeConsoleToFile=='undefined'
|| typeof frame.contentWindow.parentSandboxBridge.air_Introspector_writeConfigFile=='undefined'
|| typeof frame.contentWindow.parentSandboxBridge.air_Introspector_readConfigFile=='undefined'
|| typeof frame.contentWindow.parentSandboxBridge.air_Introspector_showHighlightLabels=='undefined'
|| typeof frame.contentWindow.parentSandboxBridge.air_Introspector_getFrameId=='undefined';*/
frame.contentWindow.parentSandboxBridge.air_Introspector_hideHighlight = function(){
air.Introspector.hideHighlight();
};
frame.contentWindow.parentSandboxBridge.air_Introspector_showHighlight = function(rect){
air.Introspector.showHighlight(rect);
};
frame.contentWindow.parentSandboxBridge.air_Introspector_drawRect = function(rect, tagName){
var frameRect = air.Introspector.getBorderBox(frame);
var blw = air.Introspector.getIntProp(frame, "border-left-width");
var btw = air.Introspector.getIntProp(frame, "border-top-width");
if(frameRect==null) return;
rect.x+=frameRect.x+2*blw;
rect.y+=frameRect.y+2*btw;
air.Introspector.drawRect(rect, tagName);
};
frame.contentWindow.parentSandboxBridge.air_Introspector_setInspect = function(enabled){
air.Introspector.inspectFrame = enabled?frame:null;
air.Introspector.remoteInspect = enabled;
if(!enabled){
air.Introspector.hideHighlight();
}
};
frame.contentWindow.parentSandboxBridge.air_Introspector_getWindowTitle = function(){
return document.title;
};
frame.contentWindow.parentSandboxBridge.air_Introspector_checkNativeWindow = function(title){
var htmlWindows = air.Introspector.runtime.NativeApplication.nativeApplication.openedWindows;
for(var i=htmlWindows.length-1;i>=0;i--){
if(htmlWindows[i].title==title){
return true;
}
}
return false;
};
frame.contentWindow.parentSandboxBridge.air_Introspector_writeConsoleToClipboard = function(str){
air.Introspector.writeConsoleToClipboard(str);
};
frame.contentWindow.parentSandboxBridge.air_Introspector_writeConsoleToFile = function(str){
air.Introspector.writeConsoleToFile(str);
};
frame.contentWindow.parentSandboxBridge.air_Introspector_writeConfigFile = function(config){
return air.Introspector.writeConfigFile(config, true);
}
frame.contentWindow.parentSandboxBridge.air_Introspector_readConfigFile = function(){
return air.Introspector.readConfigFile(true);
}
frame.contentWindow.parentSandboxBridge.air_Introspector_showHighlightLabels = function(id, nodeName, outerHTML){
air.Introspector.showHighlightLabels(id, nodeName, outerHTML);
};
frame.contentWindow.parentSandboxBridge.air_Introspector_getFrameId = function(){
return frame.id;
}
if(typeof frame.contentWindow.childSandboxBridge!='undefined'
&& typeof frame.contentWindow.childSandboxBridge.air_Introspector_bridgeLoaded!='undefined'){
frame.contentWindow.childSandboxBridge.air_Introspector_bridgeLoaded();
}
//return modified;
},
/**
* @function waitForBody
* @description Wait until document.body is available
*/
waitForBody: function(document, callback){
if(document.body){
callback();
}else{
setTimeout(air.Introspector.waitForBody, 10, document, callback);
}
},
/**
* @function toggleWindow
* @description Shows/Hides the debug tool
*/
toggleWindow:function(){
air.Introspector.init(true, false, function(justCreated){
if(!justCreated)
air.Introspector.debugWindow.nativeWindow.visible ^= true;
});
},
/**
* @function init
* @description Makes sure the debug tool is enabled
*/
init: function(showLoader, toggle, callback){
if(!air.Introspector.canInit())
return;
if(typeof showLoader=='undefined') showLoader = false;
if(typeof toggle=='undefined') toggle = true;
if(isAppSandbox){
if(typeof air.Introspector.debugWindow=='undefined' || air.Introspector.debugWindow.nativeWindow.closed){
delete air.Introspector.debugWindow;
var debugWindow = air.Introspector.findDebugWindow();
if(debugWindow!=null && !debugWindow.nativeWindow.closed){
air.Introspector.debugWindow = debugWindow;
if(toggle){
air.Introspector.debugWindow.nativeWindow.visible = true;
if(!showLoader){
nativeWindow.activate();
}
}
callback(false);
}else{
air.Introspector.loadDebugger(function(debugWindow){
air.Introspector.debugWindow = debugWindow;
callback(true);
}, showLoader);
}
}else{
if(toggle){
if(showLoader){
air.Introspector.debugWindow.nativeWindow.activate();
}
}
callback(false);
}
}else{
if(typeof activeWindow=='undefined'){
air.Introspector.registerChildSandboxBridge();
}
if(typeof air.Introspector.debugWindow=='undefined'||
typeof air.Introspector.debugWindow.window.air=='undefined'){
/* (air.Introspector.debugWindow.isWindowCreated
&&air.Introspector.debugWindow.isLoaded
&&air.Introspector.debugWindow.window
&&!parentSandboxBridge.air_Introspector_checkNativeWindow(air.Introspector.parentWindowTitle + ': '+air.Introspector.debugWindow.window.document.title))){*/
delete air.Introspector.debugWindow;
air.Introspector.loadDebugger(function(debugWindow){
air.Introspector.debugWindow = debugWindow;
callback(true);
});
// air.Introspector.debugWindow = new air.Introspector.DebugWindow ({activateDebug: showLoader, activeWindow: window});
}else if(!air.Introspector.debugWindow.isWindowCreated){
return;
}else{
callback(false);
}
}
},
times:0, //make the window.open page name unique - this is the number of opened and closed introspector windows
/**
* @function tryCreateWindow
* @description window.Open in browser/remote sandbox is not allowed if the action is not iniated by the user (eg. user gesture, mouse click)
* We can only wait for that moment. Until that happends we record all the callbacks and run them when the Introspector is laoded
* @runs in remote sandbox only
*/
tryCreateWindow: function(callbacks){
// try{
var self = this;
var w;
var iframeId;
/* if(typeof parentSandboxBridge=='undefined'){
air.Introspector.noBridge(function(){
air.Introspector.tryCreateWindow(callbacks);
});
return;
}*/
air.Introspector.parentWindowTitle = parentSandboxBridge.air_Introspector_getWindowTitle();
if(typeof parentSandboxBridge!='undefined'&&typeof parentSandboxBridge.air_Introspector_getFrameId!='undefined')
iframeId = parentSandboxBridge.air_Introspector_getFrameId();
air.Introspector.times++;
if(typeof air.Introspector.config.useAirDebugHtml=='undefined'||air.Introspector.config.useAirDebugHtml==false){
w = window.open('about:blank', 'debugger'+air.Introspector.times, 'width=640,height=480,resizable=1');
if(w&&w.document){
w.isAppSandbox = isAppSandbox;
w.opener = window;
w.iframeId = iframeId;
w.initCallbacks = callbacks;
w.activeWindow = window;
w.isLoaded = false;
w.config = air.Introspector.config;
w.document.write(air.Introspector.contentString);
w.document.close();
}
}else{
w = window.open('DebugUI.html', 'debugger'+air.Introspector.times, 'width=640,height=480,resizable=1');
if(w&&w.document){
w.opener = window;
w.iframeId = iframeId;
w.activeWindow = window;
w.config = air.Introspector.config;
w.initCallbacks = callbacks;
w.isLoaded = false;
w.isAppSandbox = isAppSandbox;
}
}
return w;
// }catch(e){
// alert(e+' '+e.line);
// }
},
/**
* @function loadDebugger
* @description Loads the debugger window, register callbacks until it is ready
* @runs in application sandbox only
*/
loadDebugger: function(callback, activateDebug){
var htmlLoader;
var loadDebugger = arguments.callee;
if(loadDebugger.htmlLoader && typeof loadDebugger.htmlLoader.window.isLoaded != 'undefined'){
if(loadDebugger.htmlLoader.window.isLoaded){
callback(loadDebugger.htmlLoader.window.debugWindow);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -