InspectorFrontendHost.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. class InspectorFrontendHostStub{constructor(){function stopEventPropagation(event){const zoomModifier=this.platform()==='mac'?event.metaKey:event.ctrlKey;if(zoomModifier&&(event.keyCode===187||event.keyCode===189)){event.stopPropagation();}}
  2. document.addEventListener('keydown',stopEventPropagation.bind(this),true);this._urlsBeingSaved=new Map();this.events;}
  3. platform(){let match=navigator.userAgent.match(/Windows NT/);if(match){return'windows';}
  4. match=navigator.userAgent.match(/Mac OS X/);if(match){return'mac';}
  5. return'linux';}
  6. loadCompleted(){}
  7. bringToFront(){this._windowVisible=true;}
  8. closeWindow(){this._windowVisible=false;}
  9. setIsDocked(isDocked,callback){setTimeout(callback,0);}
  10. setInspectedPageBounds(bounds){}
  11. inspectElementCompleted(){}
  12. setInjectedScriptForOrigin(origin,script){}
  13. inspectedURLChanged(url){document.title=Common.UIString('DevTools - %s',url.replace(/^https?:\/\//,''));}
  14. copyText(text){if(text===undefined||text===null){return;}
  15. if(navigator.clipboard){navigator.clipboard.writeText(text);}else if(document.queryCommandSupported('copy')){const input=document.createElement('input');input.value=text;document.body.appendChild(input);input.select();document.execCommand('copy');document.body.removeChild(input);}else{Common.console.error('Clipboard is not enabled in hosted mode. Please inspect using chrome://inspect');}}
  16. openInNewTab(url){window.open(url,'_blank');}
  17. showItemInFolder(fileSystemPath){Common.console.error('Show item in folder is not enabled in hosted mode. Please inspect using chrome://inspect');}
  18. save(url,content,forceSaveAs){let buffer=this._urlsBeingSaved.get(url);if(!buffer){buffer=[];this._urlsBeingSaved.set(url,buffer);}
  19. buffer.push(content);this.events.dispatchEventToListeners(Host.InspectorFrontendHostAPI.Events.SavedURL,{url,fileSystemPath:url});}
  20. append(url,content){const buffer=this._urlsBeingSaved.get(url);buffer.push(content);this.events.dispatchEventToListeners(Host.InspectorFrontendHostAPI.Events.AppendedToURL,url);}
  21. close(url){const buffer=this._urlsBeingSaved.get(url);this._urlsBeingSaved.delete(url);const fileName=url?url.trimURL().removeURLFragment():'';const link=createElement('a');link.download=fileName;const blob=new Blob([buffer.join('')],{type:'text/plain'});link.href=URL.createObjectURL(blob);link.click();}
  22. sendMessageToBackend(message){}
  23. recordEnumeratedHistogram(actionName,actionCode,bucketSize){}
  24. recordPerformanceHistogram(histogramName,duration){}
  25. recordUserMetricsAction(umaName){}
  26. requestFileSystems(){this.events.dispatchEventToListeners(Host.InspectorFrontendHostAPI.Events.FileSystemsLoaded,[]);}
  27. addFileSystem(type){}
  28. removeFileSystem(fileSystemPath){}
  29. isolatedFileSystem(fileSystemId,registeredName){return null;}
  30. loadNetworkResource(url,headers,streamId,callback){Root.Runtime.loadResourcePromise(url).then(function(text){Host.ResourceLoader.streamWrite(streamId,text);callback({statusCode:200});}).catch(function(){callback({statusCode:404});});}
  31. getPreferences(callback){const prefs={};for(const name in window.localStorage){prefs[name]=window.localStorage[name];}
  32. callback(prefs);}
  33. setPreference(name,value){window.localStorage[name]=value;}
  34. removePreference(name){delete window.localStorage[name];}
  35. clearPreferences(){window.localStorage.clear();}
  36. upgradeDraggedFileSystemPermissions(fileSystem){}
  37. indexPath(requestId,fileSystemPath,excludedFolders){}
  38. stopIndexing(requestId){}
  39. searchInPath(requestId,fileSystemPath,query){}
  40. zoomFactor(){return 1;}
  41. zoomIn(){}
  42. zoomOut(){}
  43. resetZoom(){}
  44. setWhitelistedShortcuts(shortcuts){}
  45. setEyeDropperActive(active){}
  46. showCertificateViewer(certChain){}
  47. reattach(callback){}
  48. readyForTest(){}
  49. connectionReady(){}
  50. setOpenNewWindowForPopups(value){}
  51. setDevicesDiscoveryConfig(config){}
  52. setDevicesUpdatesEnabled(enabled){}
  53. performActionOnRemotePage(pageId,action){}
  54. openRemotePage(browserId,url){}
  55. openNodeFrontend(){}
  56. showContextMenuAtPoint(x,y,items,document){throw'Soft context menu should be used';}
  57. isHostedMode(){return true;}
  58. setAddExtensionCallback(callback){}}
  59. let _InspectorFrontendHost=window.InspectorFrontendHost;class InspectorFrontendAPIImpl{constructor(){this._debugFrontend=!!Root.Runtime.queryParam('debugFrontend')||(window['InspectorTest']&&window['InspectorTest']['debugTest']);const descriptors=Host.InspectorFrontendHostAPI.EventDescriptors;for(let i=0;i<descriptors.length;++i){this[descriptors[i][1]]=this._dispatch.bind(this,descriptors[i][0],descriptors[i][2],descriptors[i][3]);}}
  60. _dispatch(name,signature,runOnceLoaded){const params=Array.prototype.slice.call(arguments,3);if(this._debugFrontend){setImmediate(innerDispatch);}else{innerDispatch();}
  61. function innerDispatch(){if(signature.length<2){try{_InspectorFrontendHost.events.dispatchEventToListeners(name,params[0]);}catch(e){console.error(e+' '+e.stack);}
  62. return;}
  63. const data={};for(let i=0;i<signature.length;++i){data[signature[i]]=params[i];}
  64. try{_InspectorFrontendHost.events.dispatchEventToListeners(name,data);}catch(e){console.error(e+' '+e.stack);}}}
  65. streamWrite(id,chunk){Host.ResourceLoader.streamWrite(id,chunk);}}
  66. (function(){function initializeInspectorFrontendHost(){let proto;if(!_InspectorFrontendHost){window.InspectorFrontendHost=_InspectorFrontendHost=new InspectorFrontendHostStub();}else{proto=InspectorFrontendHostStub.prototype;for(const name of Object.getOwnPropertyNames(proto)){const stub=proto[name];if(typeof stub!=='function'||_InspectorFrontendHost[name]){continue;}
  67. console.error('Incompatible embedder: method Host.InspectorFrontendHost.'+name+' is missing. Using stub instead.');_InspectorFrontendHost[name]=stub;}}
  68. _InspectorFrontendHost.events=new Common.Object();}
  69. initializeInspectorFrontendHost();window.InspectorFrontendAPI=new InspectorFrontendAPIImpl();})();export function isUnderTest(prefs){if(Root.Runtime.queryParam('test')){return true;}
  70. if(prefs){return prefs['isUnderTest']==='true';}
  71. return Common.settings&&Common.settings.createSetting('isUnderTest',false).get();}
  72. self.Host=self.Host||{};Host=Host||{};Host.InspectorFrontendHost=_InspectorFrontendHost;Host.isUnderTest=isUnderTest;