ExtensionPanel.js 3.9 KB

1234567891011121314151617181920212223242526272829303132
  1. export default class ExtensionPanel extends UI.Panel{constructor(server,panelName,id,pageURL){super(panelName);this._server=server;this._id=id;this.setHideOnDetach();this._panelToolbar=new UI.Toolbar('hidden',this.element);this._searchableView=new UI.SearchableView(this);this._searchableView.show(this.element);const extensionView=new Extensions.ExtensionView(server,this._id,pageURL,'extension');extensionView.show(this._searchableView.element);}
  2. addToolbarItem(item){this._panelToolbar.element.classList.remove('hidden');this._panelToolbar.appendToolbarItem(item);}
  3. searchCanceled(){this._server.notifySearchAction(this._id,Extensions.extensionAPI.panels.SearchAction.CancelSearch);this._searchableView.updateSearchMatchesCount(0);}
  4. searchableView(){return this._searchableView;}
  5. performSearch(searchConfig,shouldJump,jumpBackwards){const query=searchConfig.query;this._server.notifySearchAction(this._id,Extensions.extensionAPI.panels.SearchAction.PerformSearch,query);}
  6. jumpToNextSearchResult(){this._server.notifySearchAction(this._id,Extensions.extensionAPI.panels.SearchAction.NextSearchResult);}
  7. jumpToPreviousSearchResult(){this._server.notifySearchAction(this._id,Extensions.extensionAPI.panels.SearchAction.PreviousSearchResult);}
  8. supportsCaseSensitiveSearch(){return false;}
  9. supportsRegexSearch(){return false;}}
  10. export class ExtensionButton{constructor(server,id,iconURL,tooltip,disabled){this._id=id;this._toolbarButton=new UI.ToolbarButton('','');this._toolbarButton.addEventListener(UI.ToolbarButton.Events.Click,server.notifyButtonClicked.bind(server,this._id));this.update(iconURL,tooltip,disabled);}
  11. update(iconURL,tooltip,disabled){if(typeof iconURL==='string'){this._toolbarButton.setBackgroundImage(iconURL);}
  12. if(typeof tooltip==='string'){this._toolbarButton.setTitle(tooltip);}
  13. if(typeof disabled==='boolean'){this._toolbarButton.setEnabled(!disabled);}}
  14. toolbarButton(){return this._toolbarButton;}}
  15. export class ExtensionSidebarPane extends UI.SimpleView{constructor(server,panelName,title,id){super(title);this.element.classList.add('fill');this._panelName=panelName;this._server=server;this._id=id;}
  16. id(){return this._id;}
  17. panelName(){return this._panelName;}
  18. setObject(object,title,callback){this._createObjectPropertiesView();this._setObject(SDK.RemoteObject.fromLocalObject(object),title,callback);}
  19. setExpression(expression,title,evaluateOptions,securityOrigin,callback){this._createObjectPropertiesView();this._server.evaluate(expression,true,false,evaluateOptions,securityOrigin,this._onEvaluate.bind(this,title,callback));}
  20. setPage(url){if(this._objectPropertiesView){this._objectPropertiesView.detach();delete this._objectPropertiesView;}
  21. if(this._extensionView){this._extensionView.detach(true);}
  22. this._extensionView=new Extensions.ExtensionView(this._server,this._id,url,'extension fill');this._extensionView.show(this.element);if(!this.element.style.height){this.setHeight('150px');}}
  23. setHeight(height){this.element.style.height=height;}
  24. _onEvaluate(title,callback,error,result,wasThrown){if(error||!result){callback(error.toString());}else{this._setObject(result,title,callback);}}
  25. _createObjectPropertiesView(){if(this._objectPropertiesView){return;}
  26. if(this._extensionView){this._extensionView.detach(true);delete this._extensionView;}
  27. this._objectPropertiesView=new Extensions.ExtensionNotifierView(this._server,this._id);this._objectPropertiesView.show(this.element);}
  28. _setObject(object,title,callback){if(!this._objectPropertiesView){callback('operation cancelled');return;}
  29. this._objectPropertiesView.element.removeChildren();UI.Renderer.render(object,{title,editable:false}).then(result=>{if(!result){callback();return;}
  30. if(result.tree&&result.tree.firstChild()){result.tree.firstChild().expand();}
  31. this._objectPropertiesView.element.appendChild(result.node);callback();});}}
  32. self.Extensions=self.Extensions||{};Extensions=Extensions||{};Extensions.ExtensionPanel=ExtensionPanel;Extensions.ExtensionButton=ExtensionButton;Extensions.ExtensionSidebarPane=ExtensionSidebarPane;