/// <summary>Loads the content of this iframe now.</summary> private void LoadContent() { if (!Loaded) { return; } string parentLocation = null; if (Element.parentNode != null) { parentLocation = Element.Document.basepath; } if (string.IsNullOrEmpty(Src)) { ContentDocument.location = new FilePath("", parentLocation, false); SetContent(""); return; } ContentDocument.location = new FilePath(Src, parentLocation, false); TextPackage package = new TextPackage(Src, parentLocation); package.Get(OnTextReady); }
// Textual stuff; usually .html files public override void OnGetText(TextPackage package, FilePath path) { // Get the bytes: string data = System.Text.Encoding.UTF8.GetString(System.IO.File.ReadAllBytes(path.Path)); // Let the package know: package.GotText(data, null); }
/// <summary>The callback used when the html text for this iframe has been loaded.</summary> /// <param name="package">The text package containing the html, if it is ok.</param> private void OnTextReady(TextPackage package){ if(package.Errored){ // Output it to our iframe: SetContent("Error: "+package.Error); }else{ SetContent(package.Text); } Element.OnLoaded("webpage"); }
public override void OnGetText(TextPackage package, FilePath path) { // Work like a proper browser - Let's go grab text from the given url. // Note that this will only work with simple sites (no JS - nitro only) or ones built specifically for PowerUI. HttpRequest request = new HttpRequest(path.Url, GotTextResult); request.ExtraData = package; request.Send(); }
// Textual stuff; usually .html files public override void OnGetText(TextPackage package,FilePath path){ // Get the bytes: string data=System.Text.Encoding.UTF8.GetString(System.IO.File.ReadAllBytes(path.Path)); // Let the package know: package.GotText(data,null); }
public FileErrorInfo(TextPackage package) { // Store the package: Package = package; // Grab the URL: Url = new FilePath(package.Url, ""); // Grab the message: Message = package.Error; }
/// <summary>Loads a link into the given document.</summary> /// <param name="path">The path the link was pointing at.</param> /// <param name="document">The document the link will load into.</param> private void LoadIntoDocument(FilePath path, Document document) { // Clear the document so it's obvious to the player the link is now loading: document.innerHTML = ""; document.location = path; // Load the html. Note that path.Url is fully resolved at this point: TextPackage package = new TextPackage(path.Url, ""); package.ExtraData = document; package.Get(GotLinkText); }
/// <summary>Sends a request off to get the content of this tag if it's external (i.e. has an src attribute).</summary> private void LoadContent() { if (!Loaded || string.IsNullOrEmpty(Src)) { return; } // The code index makes sure that this script is loaded into this position relative to other script on the page: CodeIndex = Element.Document.GetCodeIndex(); TextPackage package = new TextPackage(Src, Element.Document.basepath); package.Get(OnTextReady); }
public FileErrorInfo(TextPackage package){ // Store the package: Package=package; // Grab the URL: Url=new FilePath(package.Url,""); // Grab the message: Message=package.Error; }
/// <summary>The callback used when the html text for this iframe has been loaded.</summary> /// <param name="package">The text package containing the html, if it is ok.</param> private void OnTextReady(TextPackage package) { if (package.Errored) { // Output it to our iframe: SetContent("Error: " + package.Error); } else { SetContent(package.Text); } Element.OnLoaded("webpage"); }
private void GotLinkText(TextPackage package){ Document document=(Document)package.ExtraData; if(package.Errored){ if(ErrorHandlers.PageNotFound!=null){ ErrorHandlers.PageNotFound(new FileErrorInfo(package),document); }else{ document.innerHTML="Error: "+package.Error; } }else{ document.innerHTML=package.Text; } }
public override void OnGetText(TextPackage package,FilePath path){ if(Callback.WillDelay){ // Buffer this call until later - we're not on the main thread. // Create the callback: ResourcesProtocolCallback callback=new ResourcesProtocolCallback(package,path); // Hook up the protocol handler for speed later: callback.Protocol=this; // Request it to run: callback.Go(); return; } // Getting a files text content from resources. string text=null; string error=null; string resPath=null; string filetype=path.Filetype; if(filetype=="html" || filetype=="htm" || filetype=="txt"){ resPath=path.Directory+path.Filename; }else{ // The file MUST end in .bytes for this to work. resPath=path.Path; } TextAsset asset=(TextAsset)Resources.Load(resPath); if(asset==null){ error="File not found in resources ("+path.Directory+path.Filename+" from URL '"+path.Url+"')"; if(filetype=="css" || filetype=="ns" || filetype=="nitro"){ error+=" Additionally, note that '."+filetype+"' files are not recognised by Unity as a text file. Try renaming the file to ."+filetype+".bytes in your Resources folder."; } }else{ text=asset.text; } package.GotText(text,error); }
public override void OnFollowLink(Element linkElement,FilePath path){ string target=linkElement["target"]; if(target!=null && target=="_blank"){ // Open the given url. Application.OpenURL(path.Url); return; } // Clear the document so it's obvious to the player the link is now loading: linkElement.Document.innerHTML=""; linkElement.Document.location=path; // Load the html. Note that path.Url is fully resolved at this point: TextPackage package=new TextPackage(path.Url,""); package.ExtraData=linkElement.Document; package.Get(GotLinkText); }
/// <summary>Loads the content of this iframe now.</summary> private void LoadContent(){ if(!Loaded){ return; } string parentLocation=null; if(Element.parentNode!=null){ parentLocation=Element.Document.basepath; } if(string.IsNullOrEmpty(Src)){ ContentDocument.location=new FilePath("",parentLocation,false); SetContent(""); return; } ContentDocument.location=new FilePath(Src,parentLocation,false); TextPackage package=new TextPackage(Src,parentLocation); package.Get(OnTextReady); }
/// <summary>The callback for the request to get the external script.</summary> /// <param name="package">The text package containing the script if the request was ok.</param> private void OnTextReady(TextPackage package) { if (Element.Document == null || CodeIndex < 0) { return; } // The element is still somewhere on the UI. string code = ""; if (package.Ok) { // Grabbed it okay. code = package.Text; } Element.Document.AddCode(code, CodeIndex); CodeIndex = -1; // We might also be the last code to download - attempt a compile now, but only if the document is done parsing. // If the doc isn't done parsing, it might not have added all the script to the buffer yet (and will try compile itself). if (Element.Document.FinishedParsing) { Element.Document.TryCompile(); } }
/// <summary>Get the file at the given path as some html text using this protocol. /// Once it's been retrieved, this must call package.GotText(theText) internally.</summary> public virtual void OnGetText(TextPackage package,FilePath path){}
public ResourcesProtocolCallback(TextPackage package,FilePath path){ Text=package; Path=path; }
/// <summary>Sends a request off to get the content of this tag if it's external (i.e. has an src attribute).</summary> private void LoadContent(){ if(!Loaded || string.IsNullOrEmpty(Src)){ return; } // The code index makes sure that this script is loaded into this position relative to other script on the page: CodeIndex=Element.Document.GetCodeIndex(); TextPackage package=new TextPackage(Src,Element.Document.basepath); package.Get(OnTextReady); }
/// <summary>The callback for the request to get the external script.</summary> /// <param name="package">The text package containing the script if the request was ok.</param> private void OnTextReady(TextPackage package){ if(Element.Document==null || CodeIndex<0){ return; } // The element is still somewhere on the UI. string code=""; if(package.Ok){ // Grabbed it okay. code=package.Text; } Element.Document.AddCode(code,CodeIndex); CodeIndex=-1; // We might also be the last code to download - attempt a compile now, but only if the document is done parsing. // If the doc isn't done parsing, it might not have added all the script to the buffer yet (and will try compile itself). if(Element.Document.FinishedParsing){ Element.Document.TryCompile(); } }
public ResourcesProtocolCallback(TextPackage package, FilePath path) { Text = package; Path = path; }
public override void OnGetText(TextPackage package,FilePath path){ // Work like a proper browser - Let's go grab text from the given url. // Note that this will only work with simple sites (no JS - nitro only) or ones built specifically for PowerUI. HttpRequest request=new HttpRequest(path.Url,GotTextResult); request.ExtraData=package; request.Send(); }
private void GotTextResult(HttpRequest request) { TextPackage package = (TextPackage)request.ExtraData; package.GotText(request.Text, request.Error); }
/// <summary>Loads a link into the given document.</summary> /// <param name="path">The path the link was pointing at.</param> /// <param name="document">The document the link will load into.</param> private void LoadIntoDocument(FilePath path,Document document){ // Clear the document so it's obvious to the player the link is now loading: document.innerHTML=""; document.location=path; // Load the html. Note that path.Url is fully resolved at this point: TextPackage package=new TextPackage(path.Url,""); package.ExtraData=document; package.Get(GotLinkText); }
/// <summary>Get the file at the given path as some html text using this protocol. /// Once it's been retrieved, this must call package.GotText(theText) internally.</summary> public virtual void OnGetText(TextPackage package, FilePath path) { }