private void _explorerBrowserControl_AboutBlankDocumentComplete(object sender, BrowserDocumentEventArgs e)
        {
            try
            {
                // unsubscribe from the event
                _explorerBrowserControl.DocumentComplete -= new BrowserDocumentEventHandler(_explorerBrowserControl_AboutBlankDocumentComplete);

                // set borders to none
                IHTMLDocument2 document = _explorerBrowserControl.Document as IHTMLDocument2;
                if (document != null)
                {
                    ICustomDoc customDoc = (ICustomDoc)document;
                    customDoc.SetUIHandler(new BrowserDocHostUIHandler());

                    if (document.body != null && document.body.style != null)
                    {
                        document.body.style.borderStyle = "none";
                    }
                    else
                    {
                        Debug.Fail("Couldn't set document body style after document completed!");
                    }
                }
                else
                {
                    Debug.Fail("Couldn't get document after document completed!");
                }
            }
            catch (Exception ex)
            {
                Trace.Fail("Unexpected exception in BrowserMiniForm.AboutBlankDocumentComplete: " + ex.ToString());
            }
        }
Exemplo n.º 2
0
        private void CheckUIHostRegistration()
        {
            lock (_uiHostRegisteredLock)
            {
                if (testHelp != null)
                {
                    testHelp.StartInfo = this.StartInfo;
                }

                if (isUIHostRegistered || ieInstance == null)
                {
                    return;
                }

                ICustomDoc cDoc   = ieInstance.Document as ICustomDoc;
                IOleObject oleObj = ieInstance.Document as IOleObject;

                if (oleObj != null && cDoc != null)
                {
                    IOleClientSite clientSite = null;
                    oleObj.GetClientSite(ref clientSite);

                    if (cDoc != null)
                    {
                        _browser = new BrowserIEImpl(ieInstance, _mainHWND, _canvasHWND);
                        testHelp = new IETestHelp(clientSite as IDocHostUIHandler, _browser, host);
                        cDoc.SetUIHandler(testHelp);
                        isUIHostRegistered = true;
                    }
                }
            }
        }
Exemplo n.º 3
0
        public override void RegisterDoc()
        {
            base.RegisterDoc();

            if (registeredUIHandler == false)
            {
                registeredUIHandler = true;

                ICustomDoc cDoc   = this.m_pIWebBrowser2.Document as ICustomDoc;
                IOleObject oleObj = this.m_pIWebBrowser2.Document as IOleObject;

                if (oleObj != null && cDoc != null)
                {
                    IOleClientSite clientSite = null;
                    oleObj.GetClientSite(ref clientSite);

                    if (m_defaultUIHandler == null && clientSite != null)
                    {
                        m_defaultUIHandler = clientSite as IDocHostUIHandler;
                    }
                    if (cDoc != null)
                    {
                        cDoc.SetUIHandler(this);
                    }
                }
            }
        }
Exemplo n.º 4
0
        void UpdateDocumentRef()
        {
            if (currentDocument != view.Document)
            {
                var doc = view.Document as ICustomDoc;
                if (doc != null)
                {
                    doc.SetUIHandler(this);
                    if (mshtmlDocType == null)
                    {
                        mshtmlDocType = view.Document.GetType();
                    }
                }
                if (currentDocument != null)
                {
                    currentDocument.SetUIHandler(null);
                }
                currentDocument = doc;
            }

            // on initialization we load "about:blank" to initialize the document,
            // in that case we load the requested url
            if (currentDocument != null && !initialized)
            {
                initialized = true;
                if (!string.IsNullOrEmpty(url))
                {
                    view.Navigate(url);
                }
            }
        }
Exemplo n.º 5
0
        protected override void OnInitialized(EventArgs e)
        {
            base.OnInitialized(e);

            string path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;

            HtmlView.Navigate(new Uri(Path.Combine(path, "ThreadView.html")));

            ICustomDoc doc = (ICustomDoc)HtmlView.Document;

            doc.SetUIHandler(new DocHostUIHandler());
        }
Exemplo n.º 6
0
        public void RefreshView()
        {
            ICustomDoc cDoc = (ICustomDoc)this.ieInstance.Document;

            if (cDoc != null)
            {
                IOleClientSite oleObj = cDoc as IOleClientSite;
                if (oleObj != null)
                {
                    oleObj.ShowObject();
                }
            }
        }
Exemplo n.º 7
0
        public void Init(
            int left, int top, int width, int height, int borderWidth,
            int titleHeight, bool isResizable, bool hasMin, bool hasMax,
            int minWidth, int minHeight, string text,
            bool allowDrop
            )
        {
            Init(left, top, width, height, borderWidth, titleHeight, isResizable, hasMin, hasMax, minWidth, minHeight, text);

            if (allowDrop)
            {
                _extent = new WebBrowserExtent(this, Browser);
                ICustomDoc icd = Browser.Document.DomDocument as ICustomDoc;
                icd.SetUIHandler(_extent);
            }
        }
Exemplo n.º 8
0
        private bool TrySetUIHandler()
        {
            SHDocVw.IWebBrowser2 webBrowser2 = this.ActiveXInstance as SHDocVw.IWebBrowser2;
            if (webBrowser2 == null)
            {
                return(false);
            }

            ICustomDoc document = webBrowser2.Document as ICustomDoc;

            if (document == null)
            {
                return(false);
            }

            document.SetUIHandler((WebBrowserSiteEx)CreateWebBrowserSiteBase());
            return(true);
        }
    public void CapturePage(string url)
    {
        this.url = url;

        mWb = new AxWebBrowser();

        mWb.BeginInit();
        mWb.Parent = new Form();
        mWb.EndInit();

        // Set the initial dimensions of the browser's client area.
        mWb.SetBounds(0, 0, width, height);

        object oBlank = "about:blank";
        object oURL   = url;
        object oNull  = String.Empty;

        // Internet Explorer should show no dialog boxes; this does not dis-
        // able script debugging however, I am not aware of a method to dis-
        // able that, other than manual configuration in he Internet Settings
        // or perhaps the registry.
        mWb.Silent = true;

        // The custom UI handler can only be registered on a document, so we
        // navigate to about:blank as a first step, then register the handler.
        mWb.Navigate2(ref oBlank, ref oNull, ref oNull, ref oNull, ref oNull);

        ICustomDoc cdoc = mWb.Document as ICustomDoc;

        cdoc.SetUIHandler(new IECaptUIHandler());

        // Register a document complete handler. It will be called whenever a
        // document completes loading, including embedded documents and the
        // initial about:blank document.
        mWb.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(IE_DocumentComplete);

        // Register an error handler. If the main document cannot be loaded,
        // the document complete event will not fire, so we have to listen to
        // this and shut the application down in case of a fatal error.
        mWb.NavigateError += new DWebBrowserEvents2_NavigateErrorEventHandler(IE_NavigateError);

        // Now navigate to the final destination.
        mWb.Navigate2(ref oURL, ref oNull, ref oNull, ref oNull, ref oNull);
    }
Exemplo n.º 10
0
        public HtmlUIForm()
        {
            InitializeComponent();

            this.WebBrowser.DocumentComplete += new DWebBrowserEvents2_DocumentCompleteEventHandler(this.WebBrowser_DocumentComplete);

            object flags       = 0;
            object targetFrame = String.Empty;
            object postData    = String.Empty;
            object headers     = String.Empty;

            this.WebBrowser.Navigate("about:blank", ref flags, ref targetFrame, ref postData, ref headers);

            ICustomDoc cDoc = (ICustomDoc)this.WebBrowser.Document;

            cDoc.SetUIHandler((IDocHostUIHandler)this);

            this.WebBrowser.Navigate(@"res://HtmlUI.exe/Sample1.htm", ref flags, ref targetFrame, ref postData, ref headers);
        }
Exemplo n.º 11
0
        public Form1()
        {
            InitializeComponent();


            object flags       = 0;
            object targetFrame = String.Empty;
            object postData    = String.Empty;
            object headers     = String.Empty;

            this.axWebBrowser1.Navigate("about:blank"); //, ref flags, ref targetFrame,
            //ref postData, ref headers);

            ICustomDoc cDoc = (ICustomDoc)this.axWebBrowser1.Document;

            cDoc.SetUIHandler((IDocHostUIHandler)this);

            var starturl = ConfigurationManager.AppSettings["starturl"];

            this.axWebBrowser1.Navigate(starturl);
        }
Exemplo n.º 12
0
        public void Init(object config)
        {
            config_ = config;

            onclose_ = Utility.GetProperty(config, "OnClose");
            translate_accelerator_handler_ = Utility.GetProperty(config, "TranslateAccelerator");

            tag_ = Utility.GetProperty(config, "Tag");

            object title = Utility.GetProperty(config, "Title");

            base.Init(
                (int)Utility.GetProperty(config, "Left"),
                (int)Utility.GetProperty(config, "Top"),
                (int)Utility.GetProperty(config, "Width"),
                (int)Utility.GetProperty(config, "Height"),
                (int)Utility.GetProperty(config, "BorderWidth"),
                (int)Utility.GetProperty(title, "Height"),
                (bool)Utility.GetProperty(config, "Resizable"),
                (bool)Utility.GetProperty(config, "HasMinButton"),
                (bool)Utility.GetProperty(config, "HasMaxButton"),
                (int)Utility.GetProperty(config, "MinWidth"),
                (int)Utility.GetProperty(config, "MinHeight"),
                (string)Utility.GetProperty(title, "InnerHTML")
                );

            ShowInTaskbar = (bool)Utility.GetProperty(config, "ShowInTaskbar");

            TopMost = Convert.ToBoolean(Utility.GetProperty(config, "TopMost"));

            bool allowDrop = Convert.ToBoolean(Utility.GetProperty(config, "AllowDrop"));

            if (allowDrop)
            {
                _extent = new WebBrowserExtent(this, Browser);
                ICustomDoc icd = Browser.Document.DomDocument as ICustomDoc;
                icd.SetUIHandler(_extent);
            }
        }
Exemplo n.º 13
0
        private void Form1_Load(object sender, System.EventArgs e)
        {
            this.axWebBrowser1.BeginInit();

            this.Width     = ww;
            this.Height    = hh;
            this.BackColor = bgcolor;

            this.axWebBrowser1.Left   = 10;
            this.axWebBrowser1.Top    = 5;
            this.axWebBrowser1.Width  = this.ClientSize.Width - 20;
            this.axWebBrowser1.Height = this.ClientSize.Height - 15;

            this.axWebBrowser1.EndInit();

            object o     = string.Empty;
            object flags = 0;

            axWebBrowser1.Navigate("about:blank", ref flags, ref o, ref o, ref o);

            ICustomDoc cDoc = (ICustomDoc)this.axWebBrowser1.Document;

            cDoc.SetUIHandler((IDocHostUIHandler)this);

            if (htmlfn == null)
            {
                htmlfn = "about:blank";
            }
            else
            {
                if (htmlfn.IndexOf(":") < 0)
                {
                    htmlfn = Directory.GetCurrentDirectory() + "\\" + htmlfn;
                }
            }
            axWebBrowser1.Navigate(htmlfn, ref flags, ref o, ref o, ref o);
        }
Exemplo n.º 14
0
        void UpdateDocumentRef()
        {
            if (currentDocument != view.Document)
            {
                var doc = view.Document as ICustomDoc;
                if (doc != null)
                {
                    doc.SetUIHandler(this);
                    if (mshtmlDocType == null)
                        mshtmlDocType = view.Document.GetType();
                }
                if (currentDocument != null)
                    currentDocument.SetUIHandler(null);
                currentDocument = doc;
            }

            // on initialization we load "about:blank" to initialize the document,
            // in that case we load the requested url
            if (currentDocument != null && !initialized)
            {
                initialized = true;
                if (!string.IsNullOrEmpty (url))
                    view.Navigate(url);
            }
        }
Exemplo n.º 15
0
 public void SetDocUIHandler()
 {
     _cDoc = (ICustomDoc)Document;
     _cDoc.SetUIHandler(this);
 }
Exemplo n.º 16
0
    static void Main(string[] args)
    {
        string URL      = null;
        string file     = null;
        int    minWidth = 800;
        int    delay    = 1;

        if (args.Length == 0)
        {
            PrintUsage();
            return;
        }

        // Parse command line parameters
        foreach (string arg in args)
        {
            string[] tmp = arg.Split(new char[] { '=' }, 2);

            if (tmp.Length < 2)
            {
                PrintUsage();
                return;
            }
            else if (tmp[0].Equals("--url"))
            {
                URL = tmp[1];
            }
            else if (tmp[0].Equals("--out"))
            {
                file = tmp[1];;
            }
            else if (tmp[0].Equals("--min-width"))
            {
                minWidth = int.Parse(tmp[1]);
            }
            else if (tmp[0].Equals("--delay"))
            {
                delay = int.Parse(tmp[1]);
            }
            else
            {
                Console.WriteLine("Warning: unknown parameter {0}", tmp[0]);
            }
        }

        if (delay < 1 || URL == null || file == null)
        {
            PrintUsage();
            return;
        }

        AxWebBrowser wb = new AxWebBrowser();

        System.Windows.Forms.Form main = new IECaptForm(URL, file, minWidth, delay, wb);

        wb.BeginInit();
        wb.Parent = main;
        wb.EndInit();

        // Set the initial dimensions of the browser's client area.
        wb.SetBounds(0, 0, minWidth, 600);

        object oBlank = "about:blank";
        object oURL   = URL;
        object oNull  = String.Empty;

        // Internet Explorer should show no dialog boxes; this does not dis-
        // able script debugging however, I am not aware of a method to dis-
        // able that, other than manual configuration in he Internet Settings
        // or perhaps the registry.
        wb.Silent = true;

        // The custom UI handler can only be registered on a document, so we
        // navigate to about:blank as a first step, then register the handler.
        wb.Navigate2(ref oBlank, ref oNull, ref oNull, ref oNull, ref oNull);

        ICustomDoc cdoc = wb.Document as ICustomDoc;

        cdoc.SetUIHandler(new IECaptUIHandler());

        // Register a document complete handler. It will be called whenever a
        // document completes loading, including embedded documents and the
        // initial about:blank document.
        wb.DocumentComplete +=
            new DWebBrowserEvents2_DocumentCompleteEventHandler(IE_DocumentComplete);

        // Register an error handler. If the main document cannot be loaded,
        // the document complete event will not fire, so we have to listen to
        // this and shut the application down in case of a fatal error.
        wb.NavigateError +=
            new DWebBrowserEvents2_NavigateErrorEventHandler(IE_NavigateError);

        // Now navigate to the final destination.
        wb.Navigate2(ref oURL, ref oNull, ref oNull, ref oNull, ref oNull);

        System.Windows.Forms.Application.Run();
    }
Exemplo n.º 17
0
		public void SetDocUIHandler()
		{
			_cDoc = (ICustomDoc)Document;
			_cDoc.SetUIHandler(this);
		}
    static void Main(string[] args)
    {
        string URL       = null;
        string file      = null;
        int    minWidth  = 800;
        int    minHeight = 600;
        int    delay     = 1;
        string mode      = "edge";
        bool   diff      = false;
        string reference = null;
        string tmpPath   = System.IO.Path.GetTempPath() + @"IECapt\";

        Directory.CreateDirectory(tmpPath);
        bool   debug     = false;
        bool   silent    = false;
        string IEversion = "";

        string debugMessage = "";

        if (args.Length == 0)
        {
            PrintUsage();
            return;
        }

        // Parse command line parameters
        foreach (string arg in args)
        {
            string[] tmp = arg.Split(new char[] { '=' }, 2);

            if (tmp.Length < 2)
            {
                PrintUsage();
                return;
            }
            else if (tmp[0].Equals("-u") || tmp[0].Equals("--url"))
            {
                URL = tmp[1];
            }
            else if (tmp[0].Equals("-o") || tmp[0].Equals("--out"))
            {
                file = tmp[1];;
            }
            else if (tmp[0].Equals("-rf") || tmp[0].Equals("--reference"))
            {
                reference = tmp[1];;
            }
            else if (tmp[0].Equals("-mw") || tmp[0].Equals("--min-width"))
            {
                minWidth = int.Parse(tmp[1]);
            }
            else if (tmp[0].Equals("-mh") || tmp[0].Equals("--min-height"))
            {
                minHeight = int.Parse(tmp[1]);
            }
            else if (tmp[0].Equals("-dy") || tmp[0].Equals("--delay"))
            {
                delay = int.Parse(tmp[1]);
            }
            else if (tmp[0].Equals("-df") || tmp[0].Equals("--diff"))
            {
                diff = (tmp[1].ToString() == "yes");
            }
            else if (tmp[0].Equals("-ie") || tmp[0].Equals("--internet-explorer"))
            {
                Dictionary <string, int> dic = new Dictionary <string, int>();
                dic.Add("quirks", 0x1388);
                dic.Add("7", 0x1b58);
                dic.Add("8", 0x1f40);
                dic.Add("8+", 0x22b8);
                dic.Add("9", 0x2328);
                dic.Add("9+", 0x270f);
                dic.Add("10", 0x3e8);

                object o = "edge";
                IEversion = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Version Vector", "IE", o).ToString();

                Int32 value = 0;
                mode = tmp[1];

                if (mode == "edge")
                {
                    value = dic[IEversion.Split('.')[0]];
                }
                else if (dic.ContainsKey(mode))
                {
                    value     = dic[mode];
                    IEversion = value.ToString();
                }

                try
                {
                    Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\MAIN\FeatureControl\FEATURE_BROWSER_EMULATION", Path.GetFileName(System.Windows.Forms.Application.ExecutablePath), value, RegistryValueKind.DWord);
                }
                catch (System.UnauthorizedAccessException e)
                {
                    Console.Error.WriteLine(e.Message.ToString());
                    return;
                }
            }
            else if (tmp[0].Equals("-dg") || tmp[0].Equals("--debug"))
            {
                debug = (tmp[1].ToString() == "yes");
            }
            else if (tmp[0].Equals("-s") || tmp[0].Equals("--silent"))
            {
                silent = (tmp[1].ToString() == "yes");
            }
            else
            {
                Console.WriteLine("Warning: unknown parameter {0}", tmp[0]);
            }
        }

        if (delay < 1 || URL == null)
        {
            PrintUsage();
            return;
        }

        if (String.IsNullOrEmpty(file))
        {
            file = tmpPath + URL.ToLower().Replace("http://", "").Replace("/", "-") + "-" + mode + ".png";
        }

        Debug dbg = new Debug(debug);

        debugMessage += "URL: " + URL + "\n";
        debugMessage += "Output: " + file + "{" + (File.Exists(reference)) + "}\n";
        debugMessage += "Reference: " + reference + "{" + (File.Exists(reference)) + "}\n";
        debugMessage += "Min-width: " + minWidth + "px\n";
        debugMessage += "Min-height: " + minHeight + "px\n";
        debugMessage += "Delay: " + delay + "ms\n";
        debugMessage += "Diff: " + diff + "\n";
        debugMessage += "IE Mode: " + IEversion + "\n";
        debugMessage += "IE Silent Mode: " + silent + "\n";
        dbg.log(debugMessage);

        ImageDiff imageDiff = null;

        if (reference != null)
        {
            imageDiff = new ImageDiff(reference, file);
        }
        AxWebBrowser wb = new AxWebBrowser();

        System.Windows.Forms.Form main = new IECaptForm(URL, file, minWidth, delay, wb, imageDiff);

        wb.BeginInit();
        wb.Parent = main;
        wb.EndInit();

        // Set the initial dimensions of the browser's client area.
        wb.SetBounds(0, 0, minWidth, minHeight);

        object oBlank = "about:blank";
        object oURL   = URL;
        object oNull  = String.Empty;

        // Internet Explorer should show no dialog boxes; this does not dis-
        // able script debugging however, I am not aware of a method to dis-
        // able that, other than manual configuration in he Internet Settings
        // or perhaps the registry.
        wb.Silent = silent;

        // The custom UI handler can only be registered on a document, so we
        // navigate to about:blank as a first step, then register the handler.
        wb.Navigate2(ref oBlank, ref oNull, ref oNull, ref oNull, ref oNull);

        ICustomDoc cdoc = wb.Document as ICustomDoc;

        cdoc.SetUIHandler(new IECaptUIHandler());

        // Register a document complete handler. It will be called whenever a
        // document completes loading, including embedded documents and the
        // initial about:blank document.
        wb.DocumentComplete +=
            new DWebBrowserEvents2_DocumentCompleteEventHandler(IE_DocumentComplete);

        // Register an error handler. If the main document cannot be loaded,
        // the document complete event will not fire, so we have to listen to
        // this and shut the application down in case of a fatal error.
        wb.NavigateError +=
            new DWebBrowserEvents2_NavigateErrorEventHandler(IE_NavigateError);

        // Now navigate to the final destination.
        wb.Navigate2(ref oURL, ref oNull, ref oNull, ref oNull, ref oNull);

        System.Windows.Forms.Application.Run();
    }