Esempio n. 1
0
 private void _browser_OnBeforeResourceLoad(object sender, BeforeResourceLoadEventArgs e)
 {
     if (e.ResourceType == ResourceType.Image)
     {
         e.CacheToQueue = true;
     }
 }
Esempio n. 2
0
        internal byte[] DownloadHttpData(string rawurl, Interop.IInternetProtocolSink pSink)
        {
            BeforeResourceLoadEventArgs args = new BeforeResourceLoadEventArgs(rawurl);

            editor.OnBeforeResourceLoad(args);
            if (!args.Cancel)
            {
                try
                {
                    this.url = args.Url;
                    if (args.ResourceStream == null)
                    {
                        mre = new ManualResetEvent(false);
                        int timeOut = Convert.ToInt32(args.TimeOut.TotalMilliseconds);
                        SendRequest(timeOut);
                        mre.WaitOne(timeOut, true);
                    }
                    else
                    {
                        args.ResourceStream.Seek(0, SeekOrigin.Begin);
                        s = new byte[args.ResourceStream.Length];
                        args.ResourceStream.Read(s, 0, s.Length);
                    }
                    return(s);
                }
                catch (WebException wex)
                {
                    editor.OnWebException(wex, ref this.url);
                    System.Diagnostics.Debug.WriteLine(wex.Message);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                }
            }
            return(null);
        }
Esempio n. 3
0
        /// <summary>
        /// Called during the start of any load sequence. If the caller does not provide a valid source, such
        /// as an empty string, a standard HTML code block will created.
        /// </summary>
        /// <param name="szUrl">Complete URL to download from, including pluggable protocol.</param>
        /// <param name="protocolSink">The IInternetProtocolSink interface, to which the loader communicates.</param>
        /// <returns>0 in case of success</returns>
        public byte[] Start(string szUrl, Interop.IInternetProtocolSink protocolSink) //, Interop.IInternetBindInfo bindInfo, uint grfPI, uint dwReserved)
        {
            _length = 0;
            szUrl   = GetLocalPath(szUrl);
            string mimeType;

            _index = 0;
            if (!htmlEditor.IsFileBasedDocument)
            {
                throw new ApplicationException("Improper Call To File Loader");
            }
            else
            {
                BeforeResourceLoadEventArgs args = new BeforeResourceLoadEventArgs(szUrl);
                htmlEditor.OnBeforeResourceLoad(args);
                if (!args.Cancel)
                {
                    bool hasStream = false;
                    if (args.ResourceStream != null)
                    {
                        hasStream = true;
                    }
                    if (!Directory.Exists(Path.GetDirectoryName(szUrl)) || !File.Exists(szUrl) && !hasStream)
                    {
                        _data   = ContentEncoding.GetBytes(String.Concat("File not found: ", szUrl));
                        _length = (uint)_data.Length;
                    }
                    else
                    {
                        // call handler and look if the resource should be changed
                        Stream fs;
                        if (hasStream)
                        {
                            fs = args.ResourceStream;
                            fs.Seek(0, SeekOrigin.Begin);
                        }
                        else
                        {
                            fs = new FileStream(szUrl, FileMode.Open);
                        }
                        _data   = (byte[])Array.CreateInstance(typeof(byte), (int)fs.Length);
                        _length = (uint)fs.Read(_data, _index, (int)fs.Length);
                        fs.Close();
                        if (htmlEditor.CanBuildMht)
                        {
                            # region MHT Builder Only
                            if (!this.baseDocumentLoaded || mht == null)
                            {
                                mht = new MhtBuilder(szUrl);
                                mht.AddQuotedString(System.Text.Encoding.GetEncoding(ContentEncoding.WebName).GetString(_data), true);
                                baseDocumentLoaded = true;
                            }
                            else
                            {
                                mht.AppendBoundary();
                                mht.AppendText(String.Format("Content-Type: {0}", GetMIMEType(szUrl, _data, _length)), true);
                                mht.AppendText("Content-Transfer-Encoding: base64", true);
                                if (htmlEditor.BaseUrl != null)
                                {
                                    string str = Path.GetDirectoryName(htmlEditor.BaseUrl);
                                    str += str.EndsWith("\\") ? String.Empty : Path.DirectorySeparatorChar.ToString();
                                    if (str != null && str.Length > 0)
                                    {
                                        Uri uri1 = new Uri(str);
                                        Uri uri2 = new Uri(szUrl);
                                        str = uri1.MakeRelative(uri2);
                                    }
                                    else
                                    {
                                        str = szUrl;
                                    }
                                    mht.AppendText(String.Format("Content-Location: {0}", str), true);
                                    mht.AppendNewLine();
                                    mht.AppendChunkBase64(_data, 76);
                                }
                            }
                            mht.AppendNewLine();
                            mht.AppendNewLine();
                            // Set the current state to the main control
                            this.htmlEditor.MhtBuilder = mht.GetStringBuilder();
                            # endregion
                        }
                    }
                }