PreviewFactory.js 1.3 KB

123456789
  1. export class PreviewFactory{static async createPreview(provider,mimeType){let resourceType=Common.ResourceType.fromMimeType(mimeType);if(resourceType===Common.resourceTypes.Other){resourceType=provider.contentType();}
  2. switch(resourceType){case Common.resourceTypes.Image:return new SourceFrame.ImageView(mimeType,provider);case Common.resourceTypes.Font:return new SourceFrame.FontView(mimeType,provider);}
  3. const deferredContent=await provider.requestContent();if(deferredContent.error){return new UI.EmptyWidget(deferredContent.error);}else if(!deferredContent.content){return new UI.EmptyWidget(Common.UIString('Nothing to preview'));}
  4. let content=deferredContent.content;if(await provider.contentEncoded()){content=window.atob(content);}
  5. const parsedXML=SourceFrame.XMLView.parseXML(content,mimeType);if(parsedXML){return SourceFrame.XMLView.createSearchableView(parsedXML);}
  6. const jsonView=await SourceFrame.JSONView.createView(content);if(jsonView){return jsonView;}
  7. if(resourceType.isTextType()){const highlighterType=provider.contentType().canonicalMimeType()||mimeType.replace(/;.*/,'');return SourceFrame.ResourceSourceFrame.createSearchableView(provider,highlighterType,true);}
  8. return null;}}
  9. self.SourceFrame=self.SourceFrame||{};SourceFrame=SourceFrame||{};SourceFrame.PreviewFactory=PreviewFactory;