Пример #1
0
        void HandleWebViewFinishedLoad(object sender, WebFrameEventArgs e)
        {
            if (match != null)
            {
                ShowNode(match);
                match = null;
            }
            if (navigationCells.SelectedSegment != -1)
            {
                navigationCells.SetSelected(false, navigationCells.SelectedSegment);
            }
            var dom = e.ForFrame.DomDocument;

            // Update the title of the current page
            var elements = dom.GetElementsByTagName("title");

            if (elements.Count > 0 && !string.IsNullOrWhiteSpace(elements[0].TextContent))
            {
                currentTitle = elements[0].TextContent.Length > 2 ? elements[0].TextContent.Substring(2) : elements[0].TextContent;
            }

            // Process embedded images coming from doc source
            // Because WebView doesn't let me answer a NSUrlRequest myself I have to resort to this piece of crap of a solution
            var imgs = dom.GetElementsByTagName("img").Where(node => node.Attributes["src"].NodeValue.StartsWith("source-id"));

            byte[] buffer = new byte[4096];

            foreach (var img in imgs)
            {
                var src       = img.Attributes["src"].NodeValue;
                var imgStream = AppDelegate.Root.GetImage(src);
                if (imgStream == null)
                {
                    continue;
                }
                var length = imgStream.Read(buffer, 0, buffer.Length);
                var read   = length;
                while (read != 0)
                {
                    if (length == buffer.Length)
                    {
                        var oldBuffer = buffer;
                        buffer = new byte[oldBuffer.Length * 2];
                        Buffer.BlockCopy(oldBuffer, 0, buffer, 0, oldBuffer.Length);
                    }
                    length += read = imgStream.Read(buffer, length, buffer.Length - length);
                }

                var data = Convert.ToBase64String(buffer, 0, length, Base64FormattingOptions.None);
                var uri  = "data:image/" + src.Substring(src.LastIndexOf('.')) + ";base64," + data;
                ((DomElement)img).SetAttribute("src", uri);
            }
        }
Пример #2
0
        void HandleStartedProvisionalLoad(object sender, WebFrameEventArgs e)
        {
            var url = String.Empty;

            if (e.ForFrame.ProvisionalDataSource.Request.MainDocumentURL != null)
            {
                url = e.ForFrame.ProvisionalDataSource.Request.MainDocumentURL.ToString();
            }
            if (String.IsNullOrEmpty(url))
            {
                return;
            }

            bool cancel = false;

            ApplicationContext.InvokeUserCode(delegate {
                cancel = EventSink.OnNavigateToUrl(url);
            });
            if (cancel)
            {
                e.ForFrame.StopLoading();
            }
        }
Пример #3
0
		void HandleWebViewFinishedLoad (object sender, WebFrameEventArgs e)
		{
			if (match != null) {
				ShowNode (match);
				match = null;
			}
			if (navigationCells.SelectedSegment != -1)
				navigationCells.SetSelected (false, navigationCells.SelectedSegment);
			var dom = e.ForFrame.DomDocument;
			
			// Update the title of the current page
			var elements = dom.GetElementsByTagName ("title");
			if (elements.Count > 0 && !string.IsNullOrWhiteSpace (elements[0].TextContent))
				currentTitle = elements[0].TextContent.Length > 2 ? elements[0].TextContent.Substring (2) : elements[0].TextContent;
			
			// Process embedded images coming from doc source
			// Because WebView doesn't let me answer a NSUrlRequest myself I have to resort to this piece of crap of a solution
			var imgs = dom.GetElementsByTagName ("img").Where (node => node.Attributes["src"].Value.StartsWith ("source-id"));
			byte[] buffer = new byte[4096];
			
			foreach (var img in imgs) {
				var src = img.Attributes["src"].Value;
				var imgStream = AppDelegate.Root.GetImage (src);
				if (imgStream == null)
					continue;
				var length = imgStream.Read (buffer, 0, buffer.Length);
				var read = length;
				while (read != 0) {
					if (length == buffer.Length) {
						var oldBuffer = buffer;
						buffer = new byte[oldBuffer.Length * 2];
						Buffer.BlockCopy (oldBuffer, 0, buffer, 0, oldBuffer.Length);
					}
					length += read = imgStream.Read (buffer, length, buffer.Length - length);
				}
				
				var data = Convert.ToBase64String (buffer, 0, length, Base64FormattingOptions.None);
				var uri = "data:image/" + src.Substring (src.LastIndexOf ('.')) + ";base64," + data;
				((DomElement)img).SetAttribute ("src", uri);
			}
		}
Пример #4
0
 void HandleFinishedLoadForCss(object sender, WebFrameEventArgs e)
 {
     SetCustomCss();
 }
Пример #5
0
 private void WebViewWillCloseFrame(object sender, WebFrameEventArgs e)
 {
 }
Пример #6
0
 private void WebViewFinishedLoad(object sender, WebFrameEventArgs e)
 {
 }
Пример #7
0
 private void WebViewCommitedLoad(object sender, WebFrameEventArgs e)
 {
 }
Пример #8
0
 private void WebViewStartedProvisionalLoad(object sender, WebFrameEventArgs e)
 {
 }
Пример #9
0
		private void HandleFinishedLoad (object sender, WebFrameEventArgs e) {
            		NoteTitle(currentNote.Title); // this needs to be here once the Window has loaded, otherwise the default window settings will override
        	}
Пример #10
0
 private void HandleFinishedLoad(object sender, WebFrameEventArgs e)
 {
     NoteTitle(currentNote.Title); // this needs to be here once the Window has loaded, otherwise the default window settings will override
 }