Esempio n. 1
0
 public static bool IsDangerous(string filename)
 {
     try
     {
         // First check the zone, if they are not an untrusted zone, they aren't dangerous
         if (internetSecurityManager == null)
         {
             Type iismType = Type.GetTypeFromCLSID(new Guid(CLSID_InternetSecurityManager));
             internetSecurityManager = (IInternetSecurityManager)Activator.CreateInstance(iismType);
         }
         int zone = 0;
         internetSecurityManager.MapUrlToZone(Path.GetFullPath(filename), out zone, 0);
         if (zone < ZoneInternet)
         {
             return(false);
         }
         // By default all file types that get here are considered dangerous
         return(true);
     }
     catch (COMException ex) when(ex.ErrorCode == REGDB_E_CLASSNOTREG)
     {
         // When the COM is missing(Class not registered error), it is in a locked down
         // version like Nano Server
         return(false);
     }
 }
Esempio n. 2
0
        static void Main()
        {
            try
            {
                Type   t = Type.GetTypeFromCLSID(CLSID_InternetSecurityManager);
                object securityManager = Activator.CreateInstance(t);
                if (securityManager != null)
                {
                    IInternetSecurityManager ism = (IInternetSecurityManager)securityManager;
                    ism.SetZoneMapping(URLZONE_TRUSTED, "http://127.0.0.1", SZM_CREATE);
                    ism.SetZoneMapping(URLZONE_INTRANET, "http://127.0.0.1", SZM_CREATE);
                    ism.SetZoneMapping(URLZONE_ESC_FLAG | URLZONE_TRUSTED, "http://127.0.0.1", SZM_CREATE);
                    ism.SetZoneMapping(URLZONE_ESC_FLAG | URLZONE_INTRANET, "http://127.0.0.1", SZM_CREATE);
                }
            }
            catch
            {
                // Okay to continue if adding URL to trusted zone doesn't work...
            }

            Application.EnableVisualStyles();

            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
Esempio n. 3
0
        public static void SetInternetZone()
        {
            Type t = Type.GetTypeFromCLSID(CLSID_InternetSecurityManager);

            _securityManager = Activator.CreateInstance(t);
            _ism             = (IInternetSecurityManager)_securityManager;

            int result = _ism.SetZoneMapping(0, "about:blank", SZM_CREATE);
        }
        public ContentEditor(IMainFrameWindow mainFrameWindow, Control editorContainer, IBlogPostEditingSite postEditingSite, IInternetSecurityManager internetSecurityManager, BlogPostHtmlEditorControl.TemplateStrategy templateStrategy, int dlControlFlags)
        {
            // create a docked panel to host the editor
            Panel panel = new Panel();
            panel.Dock = DockStyle.Fill;

            if (!BidiHelper.IsRightToLeft)
                panel.DockPadding.Right = 0;
            else
                panel.DockPadding.Left = 0;

            editorContainer.Controls.Add(panel);
            panel.Resize += new EventHandler(panel_Resize);
            if (BidiHelper.IsRightToLeft)
                editorContainer.RightToLeft = RightToLeft.Yes;

            // save references
            _mainFrameWindow = mainFrameWindow;
            _editorContainer = panel;
            _postEditingSite = postEditingSite;

            _commandManager = new CommandManager();

            _userPreferencesMonitor = new UserPreferencesMonitor();

            // To be high-contrast-aware we need to respond to changes in the high contrast mode
            // by invalidating commands, forcing the ribbon to ask us for new high contrast images.
            _userPreferencesMonitor.AccessibilityUserPreferencesChanged +=
                new EventHandler(delegate (object sender, EventArgs args)
                                     {
                                         _commandManager.InvalidateAllImages();
                                     });

            _imageDecoratorsManager = new LazyLoader<ImageDecoratorsManager>(() => new ImageDecoratorsManager(components, CommandManager, GlobalEditorOptions.SupportsFeature(ContentEditorFeature.ImageBorderInherit)));
            _emoticonsManager = new EmoticonsManager(this, this);

            // initialize commands
            InitializeCommands();

            // initialize normal editor
            InitializeNormalEditor(postEditingSite, internetSecurityManager, templateStrategy, dlControlFlags);

            // initialize source editor
            if (GlobalEditorOptions.SupportsFeature(ContentEditorFeature.SourceEditor))
                InitializeSourceEditor();

            InitializeViewCommands();

            // initialize custom content
            InitializeContentSources();

            // bring main editor panel to front (this must be here for the sidebar to work!!!!)
            panel.BringToFront();
        }
Esempio n. 5
0
            public static bool IsDangerous(string filename)
            {
                // First check the zone, if they are not an untrusted zone, they aren't dangerous
                if (internetSecurityManager == null)
                {
                    Type iismType = Type.GetTypeFromCLSID(new Guid(CLSID_InternetSecurityManager));
                    internetSecurityManager = (IInternetSecurityManager)Activator.CreateInstance(iismType);
                }
                int zone = 0;

                internetSecurityManager.MapUrlToZone(Path.GetFullPath(filename), out zone, 0);
                if (zone < ZoneInternet)
                {
                    return(false);
                }
                // By default all file types that get here are considered dangerous
                return(true);
            }
        //ToDo: OLW Spell Checker
        //public BlogPostHtmlEditorControl(IMainFrameWindow mainFrameWindow, IStatusBar statusBar, MshtmlOptions options, IBlogPostImageEditingContext imageEditingContext, IBlogPostSidebarContext sidebarContext, IContentSourceSidebarContext sourceContext, SmartContentResizedListener resizedListener, IBlogPostSpellCheckingContext spellingContext, IImageReferenceFixer referenceFixer, IInternetSecurityManager internetSecurityManager, CommandManager commandManager, TemplateStrategy strategy, IEditingMode editingModeContext)  : base(mainFrameWindow, statusBar, options, internetSecurityManager, commandManager)
        public BlogPostHtmlEditorControl(IMainFrameWindow mainFrameWindow, IStatusBar statusBar, MshtmlOptions options, IBlogPostImageEditingContext imageEditingContext, IBlogPostSidebarContext sidebarContext, IContentSourceSidebarContext sourceContext, SmartContentResizedListener resizedListener, IImageReferenceFixer referenceFixer, IInternetSecurityManager internetSecurityManager, CommandManager commandManager, TemplateStrategy strategy, IEditingMode editingModeContext)
            : base(mainFrameWindow, statusBar, options, internetSecurityManager, commandManager)
        {
            _strategy = strategy;
            _imageEditingContext = imageEditingContext;
            _sidebarContext = sidebarContext;
            _sourceContext = sourceContext;
            _resizedListener = resizedListener;
            //ToDo: OLW Spell Checker
            //_spellingContext = spellingContext;

            //_spellingManager = new SpellingManager(CommandManager);
            _keyBoardHandler = new PostEditorKeyboardHandler(this, imageEditingContext, editingModeContext);
            _referenceFixer = referenceFixer;

            InitializeTableEditingManager();

            InitializeElementBehaviors();

            SelectionChanged += BlogPostHtmlEditorControl_SelectionChanged;
            KeyPress += new HtmlEventHandler(BlogPostHtmlEditorControl_KeyPress);
        }
Esempio n. 7
0
    public static string GetUrlZone(string url)
    {
        Type t = System.Type.GetTypeFromCLSID(_CLSID_SecurityManager);
        IInternetSecurityManager securityManager = (IInternetSecurityManager)System.Activator.CreateInstance(t);

        try
        {
            uint zone    = 0;
            int  hResult = securityManager.MapUrlToZone(url, ref zone, 0);
            if (hResult != 0)
            {
                throw new COMException("Error calling MapUrlToZone, HRESULT = " + hResult.ToString("x"), hResult);
            }
            if (zone < ZoneNames.Length)
            {
                return(ZoneNames[zone]);
            }
            return("Unknown - " + zone);
        }
        finally
        {
            Marshal.ReleaseComObject(securityManager);
        }
    }
Esempio n. 8
0
        public IContentEditor CreateEditorFromMoniker(IContentEditorSite contentEditorSite, IInternetSecurityManager internetSecurityManager, IMoniker moniker, uint codepage, HtmlInsertOptions options, string color, int dlControlFlags, string wpost)
        {
            codepage = EmailShim.GetCodepage(codepage);
            string name;
            string html = HTMLDocumentHelper.MonikerToString(moniker, codepage, out name);

            if (CultureHelper.IsRtlCodepage(codepage))
            {
                EmailContentTarget target =
                    GlobalEditorOptions.ContentTarget as EmailContentTarget;
                if (target != null)
                {
                    target.EnableRtlMode();
                }
            }

            if (string.IsNullOrEmpty(html))
                html = "<html><body></body></html>";

            html = EmailShim.GetContentHtml(name, html);

            // Create a IHtmlDocument2 from the html which will then be loaded into the editor
            IHTMLDocument2 htmlDocument;
            htmlDocument = HTMLDocumentHelper.StringToHTMLDoc(html, name);

            return new ContentEditorProxy(this, contentEditorSite, internetSecurityManager, htmlDocument, options, dlControlFlags, color, wpost);
        }
Esempio n. 9
0
 public ContentEditorProxy(ContentEditorFactory factory, IContentEditorSite contentEditorSite, IInternetSecurityManager internetSecurityManager, string wysiwygHTML, string previewHTML, int dlControlFlags)
 {
     ContentEditorProxyCore(factory, contentEditorSite, internetSecurityManager, wysiwygHTML, previewHTML, new BlogPostEditingContext(ContentEditorAccountAdapter.AccountId, new BlogPost()), new ContentEditorTemplateStrategy(), dlControlFlags, null);
 }
 public IntranetZoneCredentialPolicy()
 {
     ExceptionHelper.ControlPolicyPermission.Demand();
     _ManagerRef = (IInternetSecurityManager)new InternetSecurityManager();
 }
 private bool IsIntranet(string schemeHost)
 {
     bool flag = false;
     int pdwZone = -1;
     int num2 = -2147467259;
     if (this.m_Syntax.SchemeName.Length > 0x20)
     {
         return false;
     }
     if (s_ManagerRef == null)
     {
         lock (s_IntranetLock)
         {
             if (s_ManagerRef == null)
             {
                 s_ManagerRef = (IInternetSecurityManager) new InternetSecurityManager();
             }
         }
     }
     try
     {
         s_ManagerRef.MapUrlToZone(schemeHost.TrimStart(_WSchars), out pdwZone, 0);
     }
     catch (COMException exception)
     {
         if (exception.ErrorCode == num2)
         {
             flag = true;
         }
     }
     if (pdwZone != 1)
     {
         if (((pdwZone != 2) && (pdwZone != 4)) && !flag)
         {
             return false;
         }
         for (int i = 0; i < schemeHost.Length; i++)
         {
             if (schemeHost[i] == '.')
             {
                 return false;
             }
         }
     }
     return true;
 }
Esempio n. 12
0
 public IContentEditor CreateEditorFromHtmlDocument(IContentEditorSite contentEditorSite, IInternetSecurityManager internetSecurityManager, IHTMLDocument2 htmlDocument, HtmlInsertOptions options, int dlControlFlags)
 {
     return new ContentEditorProxy(this, contentEditorSite, internetSecurityManager, htmlDocument, options, dlControlFlags, null, null);
 }
Esempio n. 13
0
        public ContentEditorProxy(ContentEditorFactory factory, IContentEditorSite contentEditorSite, IInternetSecurityManager internetSecurityManager, IHTMLDocument2 htmlDocument, HtmlInsertOptions options, int dlControlFlags, string color, string wpost)
        {
            string content = htmlDocument.body.innerHTML;

            htmlDocument.body.innerHTML = "{post-body}";
            string   wysiwygHTML                   = HTMLDocumentHelper.HTMLDocToString(htmlDocument);
            BlogPost documentToBeLoaded            = null;
            IBlogPostEditingContext editingContext = null;

            if (string.IsNullOrEmpty(wpost) || !File.Exists(wpost))
            {
                documentToBeLoaded = new BlogPost();
                editingContext     = new BlogPostEditingContext(ContentEditorAccountAdapter.AccountId,
                                                                documentToBeLoaded);
            }
            else
            {
                PostEditorFile wpostxFile = PostEditorFile.GetExisting(new FileInfo(wpost));
                editingContext = wpostxFile.Load(false);
                editingContext.BlogPost.Contents = "";
            }

            if (!string.IsNullOrEmpty(content))
            {
                delayedInsertOperations.Enqueue(new DelayedInsert(content, options));
            }

            ContentEditorProxyCore(factory, contentEditorSite, internetSecurityManager, wysiwygHTML, null, editingContext, new ContentEditorTemplateStrategy(), dlControlFlags, color);
        }
Esempio n. 14
0
        private void InitializeNormalEditor(IBlogPostEditingSite postEditingSite, IInternetSecurityManager internetSecurityManager, BlogPostHtmlEditorControl.TemplateStrategy templateStrategy, int dlControlFlags)
        {
            // configure editing options
            _mshtmlOptions = new MshtmlOptions();
            _mshtmlOptions.UseDivForCarriageReturn = GlobalEditorOptions.SupportsFeature(ContentEditorFeature.DivNewLine);
            // Commented out for now to prevent first chance exception
            //_mshtmlOptions.EditingOptions.Add(IDM.RESPECTVISIBILITY_INDESIGN, GlobalEditorOptions.SupportsFeature(ContentEditorFeature.HideNonVisibleElements));
            _mshtmlOptions.EditingOptions.Add(IDM.AUTOURLDETECT_MODE, false);
            _mshtmlOptions.EditingOptions.Add(IDM.MULTIPLESELECTION, false);
            _mshtmlOptions.EditingOptions.Add(IDM.LIVERESIZE, true);
            _mshtmlOptions.EditingOptions.Add(IDM.KEEPSELECTION, true);
            _mshtmlOptions.EditingOptions.Add(IDM.DISABLE_EDITFOCUS_UI, true);
            _mshtmlOptions.DLCTLOptions = dlControlFlags;
            _mshtmlOptions.DocHostUIOptionKeyPath = GlobalEditorOptions.GetSetting<string>(ContentEditorSetting.MshtmlOptionKeyPath);

            // create the editor
            _normalHtmlContentEditor = new BlogPostHtmlEditorControl(_mainFrameWindow, StatusBar, _mshtmlOptions, this, this, this, new SmartContentResizedListener(ResizedListener), new SharedCanvasImageReferenceFixer(ReferenceFixer), internetSecurityManager, CommandManager, templateStrategy, this);
            _normalHtmlContentEditor.PostBodyInlineStyle = GetPostBodyInlineStyleOverrides();
            // hookup services and events
            _normalHtmlContentEditor.HtmlGenerationService = new HtmlGenerator(this);
            _normalHtmlContentEditor.DataFormatHandlerFactory = new ExtendedHtmlEditorMashallingHandler(_normalHtmlContentEditor, this, this, postEditingSite as IDropTarget);
            _normalHtmlContentEditor.DocumentComplete += new EventHandler(htmlEditor_DocumentComplete);
            _normalHtmlContentEditor.GotFocus += htmlEditor_GotFocus;
            _normalHtmlContentEditor.LostFocus += htmlEditor_LostFocus;

            _normalHtmlContentEditor.SelectedImageResized += new SelectedImageResizedHandler(_normalHtmlContentEditor_SelectedImageResized);
            _normalHtmlContentEditor.UpdateImageLink += new UpdateImageLinkHandler(_normalHtmlContentEditor_UpdateImageLink);
            _normalHtmlContentEditor.HtmlInserted += new EventHandler(_normalHtmlContentEditor_HtmlInserted);
            _normalHtmlContentEditor.HelpRequest += new EventHandler(_normalHtmlContentEditor_HelpRequest);
            _normalHtmlContentEditor.EditorControl.AccessibleName = "Editor";

            _normalHtmlContentEditor.KeyboardLanguageChanged += new EventHandler(_normalHtmlContentEditor_KeyboardLanguageChanged);
            _normalHtmlContentEditor.TrackKeyboardLanguageChanges = true;

            // initialize the sidebar
            _htmlEditorSidebarHost = new HtmlEditorSidebarHost(_normalHtmlContentEditor);
            _htmlEditorSidebarHost.Dock = !BidiHelper.IsRightToLeft ? DockStyle.Right : DockStyle.Left;
            _htmlEditorSidebarHost.Width = Res.SidebarWidth;
            if (BidiHelper.IsRightToLeft)
            {
                _htmlEditorSidebarHost.RightToLeft = RightToLeft.Yes;
                BidiHelper.RtlLayoutFixup(_htmlEditorSidebarHost);
            }
            _editorContainer.Controls.Add(_htmlEditorSidebarHost);
            _htmlEditorSidebarHost.BringToFront();
            _htmlEditorSidebarHost.VisibleChanged += _htmlEditorSidebarHost_VisibleChanged;

            // register sidebars
            _htmlEditorSidebarHost.RegisterSidebar(new DisabledContentSourceSidebar(this));
            _htmlEditorSidebarHost.RegisterSidebar(new BrokenContentSourceSidebar(this));
            _htmlEditorSidebarHost.RegisterSidebar(new ContentSourceSidebar(this));
            _htmlEditorSidebarHost.RegisterSidebar(new ImagePropertiesSidebar(_normalHtmlContentEditor, this, new CreateFileCallback(CreateFileHandler)));
            _htmlEditorSidebarHost.AccessibleName = "Sidebar";

            // register the normal editor
            RegisterEditor(_normalHtmlContentEditor);
        }
Esempio n. 15
0
        /// <summary>
        /// Initializes the IContentEditor.
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="contentEditorSite"></param>
        /// <param name="internetSecurityManager"></param>
        /// <param name="wysiwygHTML"></param>
        /// <param name="previewHTML"></param>
        /// <param name="newEditingContext"></param>
        /// <param name="templateStrategy"></param>
        /// <param name="dlControlFlags">
        /// For Mail, these flags should always include DLCTL_DLIMAGES | DLCTL_VIDEOS | DLCTL_BGSOUNDS so that local
        /// images, videos and sounds are loaded. To block external content, it should also include
        /// DLCTL_PRAGMA_NO_CACHE | DLCTL_FORCEOFFLINE | DLCTL_NO_CLIENTPULL so that external images are not loaded
        /// and are displayed as a red X instead.
        /// </param>
        /// <param name="color"></param>
        private void ContentEditorProxyCore(ContentEditorFactory factory, IContentEditorSite contentEditorSite, IInternetSecurityManager internetSecurityManager, string wysiwygHTML, string previewHTML, IBlogPostEditingContext newEditingContext, BlogPostHtmlEditorControl.TemplateStrategy templateStrategy, int dlControlFlags, string color)
        {
            try
            {
                Debug.Assert(contentEditorSite is IUIFramework, "IContentEditorSite must also implement IUIFramework");
                Debug.Assert(contentEditorSite is IDropTarget, "IContentEditorSite must also implement IDropTarget");

                ApplyInstalledCulture();

                this.factory = factory;

                _wysiwygHTML = wysiwygHTML;
                _previewHTML = previewHTML;
                _contentEditorSite = contentEditorSite;

                IntPtr p = _contentEditorSite.GetWindowHandle();
                WINDOWINFO info = new WINDOWINFO();
                User32.GetWindowInfo(p, ref info);
                panel = new Panel();
                panel.Top = 0;
                panel.Left = 0;
                panel.Width = Math.Max(info.rcWindow.Width, 200);
                panel.Height = Math.Max(info.rcWindow.Height, 200);
                panel.CreateControl();
                User32.SetParent(panel.Handle, p);

                accountAdapter = new ContentEditorAccountAdapter();
                mainFrame = new MainFrameWindowAdapter(p, panel, _contentEditorSite, accountAdapter.Id);
                context = newEditingContext;
                contentEditor = new ContentEditor(mainFrame, panel, mainFrame, internetSecurityManager, templateStrategy, dlControlFlags);

                // Prevents asserts
                contentEditor.DisableSpelling();

                contentEditor.OnEditorAccountChanged(accountAdapter);
                contentEditor.DocumentComplete += new EventHandler(blogPostHtmlEditor_DocumentComplete);
                contentEditor.GotFocus += new EventHandler(contentEditor_GotFocus);
                contentEditor.LostFocus += new EventHandler(contentEditor_LostFocus);
                contentEditor.Initialize(context, accountAdapter, wysiwygHTML, previewHTML, false);

                if (!string.IsNullOrEmpty(color))
                {
                    contentEditor.IndentColor = color;
                }
            }
            catch (Exception ex)
            {
                // Something went wrong, make sure we don't reuse a cached editor
                HtmlEditorControl.DisposeCachedEditor();
                Trace.Fail(ex.ToString());
                Trace.Flush();
                throw;
            }
        }
Esempio n. 16
0
 public ContentEditorProxy(ContentEditorFactory factory, IContentEditorSite contentEditorSite, IInternetSecurityManager internetSecurityManager, string wysiwygHTML, string previewHTML, int dlControlFlags)
 {
     ContentEditorProxyCore(factory, contentEditorSite, internetSecurityManager, wysiwygHTML, previewHTML, new BlogPostEditingContext(ContentEditorAccountAdapter.AccountId, new BlogPost()), new ContentEditorTemplateStrategy(), dlControlFlags, null);
 }
Esempio n. 17
0
        public IContentEditor CreateEditorFromMoniker(IContentEditorSite contentEditorSite, IInternetSecurityManager internetSecurityManager, IMoniker moniker, uint codepage, HtmlInsertOptions options, string color, int dlControlFlags, string wpost)
        {
            codepage = EmailShim.GetCodepage(codepage);
            string name;
            string html = HTMLDocumentHelper.MonikerToString(moniker, codepage, out name);

            if (CultureHelper.IsRtlCodepage(codepage))
            {
                EmailContentTarget target =
                    GlobalEditorOptions.ContentTarget as EmailContentTarget;
                if (target != null)
                {
                    target.EnableRtlMode();
                }
            }

            if (string.IsNullOrEmpty(html))
            {
                html = "<html><body></body></html>";
            }

            html = EmailShim.GetContentHtml(name, html);

            // Create a IHtmlDocument2 from the html which will then be loaded into the editor
            IHTMLDocument2 htmlDocument;

            htmlDocument = HTMLDocumentHelper.StringToHTMLDoc(html, name);

            return(new ContentEditorProxy(this, contentEditorSite, internetSecurityManager, htmlDocument, options, dlControlFlags, color, wpost));
        }
Esempio n. 18
0
 public IContentEditor CreateEditorFromHtmlDocument(IContentEditorSite contentEditorSite, IInternetSecurityManager internetSecurityManager, IHTMLDocument2 htmlDocument, HtmlInsertOptions options, int dlControlFlags)
 {
     return(new ContentEditorProxy(this, contentEditorSite, internetSecurityManager, htmlDocument, options, dlControlFlags, null, null));
 }
Esempio n. 19
0
 public IContentEditor CreateEditorFromDraft(IContentEditorSite contentEditorSite, IInternetSecurityManager internetSecurityManager, string wysiwygHtml, string pathToDraftFile, int dlControlFlags)
 {
     return(new ContentEditorProxy(this, contentEditorSite, internetSecurityManager, wysiwygHtml, null, pathToDraftFile, dlControlFlags));
 }
Esempio n. 20
0
        /// <summary>
        /// Initializes the IContentEditor.
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="contentEditorSite"></param>
        /// <param name="internetSecurityManager"></param>
        /// <param name="wysiwygHTML"></param>
        /// <param name="previewHTML"></param>
        /// <param name="newEditingContext"></param>
        /// <param name="templateStrategy"></param>
        /// <param name="dlControlFlags">
        /// For Mail, these flags should always include DLCTL_DLIMAGES | DLCTL_VIDEOS | DLCTL_BGSOUNDS so that local
        /// images, videos and sounds are loaded. To block external content, it should also include
        /// DLCTL_PRAGMA_NO_CACHE | DLCTL_FORCEOFFLINE | DLCTL_NO_CLIENTPULL so that external images are not loaded
        /// and are displayed as a red X instead.
        /// </param>
        /// <param name="color"></param>
        private void ContentEditorProxyCore(ContentEditorFactory factory, IContentEditorSite contentEditorSite, IInternetSecurityManager internetSecurityManager, string wysiwygHTML, string previewHTML, IBlogPostEditingContext newEditingContext, BlogPostHtmlEditorControl.TemplateStrategy templateStrategy, int dlControlFlags, string color)
        {
            try
            {
                Debug.Assert(contentEditorSite is IUIFramework, "IContentEditorSite must also implement IUIFramework");
                Debug.Assert(contentEditorSite is IDropTarget, "IContentEditorSite must also implement IDropTarget");

                ApplyInstalledCulture();

                this.factory = factory;

                _wysiwygHTML       = wysiwygHTML;
                _previewHTML       = previewHTML;
                _contentEditorSite = contentEditorSite;

                IntPtr     p    = _contentEditorSite.GetWindowHandle();
                WINDOWINFO info = new WINDOWINFO();
                User32.GetWindowInfo(p, ref info);
                panel        = new Panel();
                panel.Top    = 0;
                panel.Left   = 0;
                panel.Width  = Math.Max(info.rcWindow.Width, 200);
                panel.Height = Math.Max(info.rcWindow.Height, 200);
                panel.CreateControl();
                User32.SetParent(panel.Handle, p);

                accountAdapter = new ContentEditorAccountAdapter();
                mainFrame      = new MainFrameWindowAdapter(p, panel, _contentEditorSite, accountAdapter.Id);
                context        = newEditingContext;
                contentEditor  = new ContentEditor(mainFrame, panel, mainFrame, internetSecurityManager, templateStrategy, dlControlFlags);

                // Prevents asserts
                contentEditor.DisableSpelling();

                contentEditor.OnEditorAccountChanged(accountAdapter);
                contentEditor.DocumentComplete += new EventHandler(blogPostHtmlEditor_DocumentComplete);
                contentEditor.GotFocus         += new EventHandler(contentEditor_GotFocus);
                contentEditor.LostFocus        += new EventHandler(contentEditor_LostFocus);
                contentEditor.Initialize(context, accountAdapter, wysiwygHTML, previewHTML, false);

                if (!string.IsNullOrEmpty(color))
                {
                    contentEditor.IndentColor = color;
                }
            }
            catch (Exception ex)
            {
                // Something went wrong, make sure we don't reuse a cached editor
                HtmlEditorControl.DisposeCachedEditor();
                Trace.Fail(ex.ToString());
                Trace.Flush();
                throw;
            }
        }
Esempio n. 21
0
 public ContentEditorProxy(ContentEditorFactory factory, IContentEditorSite contentEditorSite, IInternetSecurityManager internetSecurityManager, string wysiwygHTML, string previewHTML, string pathToFile, int dlControlFlags)
 {
     ContentEditorProxyCore(factory, contentEditorSite, internetSecurityManager, wysiwygHTML, previewHTML, PostEditorFile.GetExisting(new FileInfo(pathToFile)).Load(false), new ContentEditorTemplateStrategy(), dlControlFlags, null);
 }
Esempio n. 22
0
        public void ReleaseInnerSecurityManager()
        {
            HandleProcessUrlAction = null;

            if (SecurityManager != null && Marshal.IsComObject(SecurityManager))
                Marshal.ReleaseComObject(SecurityManager);

            // Install a dummy handler.
            SecurityManager = new InternetSecurityManager();
        }
Esempio n. 23
0
        public ContentEditorProxy(ContentEditorFactory factory, IContentEditorSite contentEditorSite, IInternetSecurityManager internetSecurityManager, IHTMLDocument2 htmlDocument, HtmlInsertOptions options, int dlControlFlags, string color, string wpost)
        {
            string content = htmlDocument.body.innerHTML;
            htmlDocument.body.innerHTML = "{post-body}";
            string wysiwygHTML = HTMLDocumentHelper.HTMLDocToString(htmlDocument);
            BlogPost documentToBeLoaded = null;
            IBlogPostEditingContext editingContext = null;

            if (string.IsNullOrEmpty(wpost) || !File.Exists(wpost))
            {
                documentToBeLoaded = new BlogPost();
                editingContext = new BlogPostEditingContext(ContentEditorAccountAdapter.AccountId,
                                                                               documentToBeLoaded);
            }
            else
            {
                PostEditorFile wpostxFile = PostEditorFile.GetExisting(new FileInfo(wpost));
                editingContext = wpostxFile.Load(false);
                editingContext.BlogPost.Contents = "";
            }

            if (!string.IsNullOrEmpty(content))
                delayedInsertOperations.Enqueue(new DelayedInsert(content, options));

            ContentEditorProxyCore(factory, contentEditorSite, internetSecurityManager, wysiwygHTML, null, editingContext, new ContentEditorTemplateStrategy(), dlControlFlags, color);

        }
Esempio n. 24
0
        public HtmlEditorControl(IMainFrameWindow mainFrameWindow, IStatusBar statusBar, MshtmlOptions options, ISpellingChecker spellingChecker, IInternetSecurityManager internetSecurityManager, CommandManager commandManager)
        {
            _commandManager = commandManager;

            // save reference to main frame window
            _mainFrameWindow = mainFrameWindow;
            _statusBar = statusBar;

            _spellingChecker = spellingChecker;

            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();

            //initialize the data format handlers for this control
            DataFormatHandlerFactory = new HtmlEditorMarshallingHandler(this);
            MarshalImagesSupported = true;
            MarshalFilesSupported = true;
            MarshalUrlSupported = true;
            MarshalHtmlSupported = true;
            MarshalTextSupported = true;

            // The version host service provider tells MSHTML what feature versions are available (e.g. VML 1.0).
            VersionHostServiceProvider = new VersionHostServiceProvider(new DisableVmlVersionHost());

            // initialize the html editor
            if (_editorCache == null)
            {
                _internetSecurityManager = new InternetSecurityManagerShim(internetSecurityManager);
                // If mainFrameWindow == null, then we are pre-caching mshtml and don't want it to steal focus
                _mshtmlEditor = new MshtmlEditor(this, options, (mainFrameWindow == null));
            }
            else
            {
                _mshtmlEditor = _editorCache.Editor;
                _internetSecurityManager = _editorCache.SecurityManager;
                _internetSecurityManager.SecurityManager = internetSecurityManager;

                _editorCache = null;
                _mshtmlEditor.Active = true;
                _mshtmlEditor.MshtmlControl.ProtectFocus = false;
                _mshtmlEditor.ClearContextMenuHandlers();
                _mshtmlEditor.SetServiceProvider(this);
                _mshtmlEditor.UpdateOptions(options, true);
            }

            _mshtmlOptions = options;
            this.DefaultBlockElement = _mshtmlOptions.UseDivForCarriageReturn
                                           ? (DefaultBlockElement)new DivDefaultBlockElement()
                                           : new ParagraphDefaultBlockElement();

            PostEditorEvent += new MshtmlEditor.EditDesignerEventHandler(HtmlEditorControl_PostEditorEvent);
            HandleClear += new HtmlEditorSelectionOperationEventHandler(TryMoveIntoNextTable);

            // Hook the editor into the stream of the security manager so we
            // can allow our own objects (smart content, image resizing) to load in the editor
            _internetSecurityManager.HandleProcessUrlAction = HandleProcessUrlAction;

            //  Automation uses this to find the editor to automate it
            _mshtmlEditor.Name = "BorderControl";

            // subscribe to key events
            _mshtmlEditor.DocumentComplete += new EventHandler(_mshtmlEditor_DocumentComplete);
            _mshtmlEditor.DocumentEvents.GotFocus += htmlEditor_GotFocus;
            _mshtmlEditor.DocumentEvents.LostFocus += htmlEditor_LostFocus;
            _mshtmlEditor.DocumentEvents.KeyDown += new HtmlEventHandler(DocumentEvents_KeyDown);
            _mshtmlEditor.DocumentEvents.KeyUp += new HtmlEventHandler(DocumentEvents_KeyUp);
            _mshtmlEditor.DocumentEvents.KeyPress += new HtmlEventHandler(DocumentEvents_KeyPress);
            _mshtmlEditor.DocumentEvents.MouseDown += new HtmlEventHandler(DocumentEvents_MouseDown);
            _mshtmlEditor.DocumentEvents.MouseUp += new HtmlEventHandler(DocumentEvents_MouseUp);
            _mshtmlEditor.DocumentEvents.SelectionChanged += new EventHandler(DocumentEvents_SelectionChanged);
            _mshtmlEditor.DisplayChanged += new EventHandler(_mshtmlEditor_DisplayChanged);
            _mshtmlEditor.DocumentEvents.Click += new HtmlEventHandler(DocumentEvents_Click);
            _mshtmlEditor.CommandKey += new KeyEventHandler(_mshtmlEditor_CommandKey);
            _mshtmlEditor.DropTargetHandler = new MshtmlEditor.DropTargetUIHandler(_mshtmlEditor_GetDropTarget);
            _mshtmlEditor.BeforeShowContextMenu += new EventHandler(_mshtmlEditor_BeforeShowContextMenu);
            _mshtmlEditor.MshtmlControl.DLControlFlagsChanged += new EventHandler(_mshtmlControl_DLControlFlagsChanged);
            _mshtmlEditor.TranslateAccelerator += new HtmlEditDesignerEventHandler(_mshtmlEditor_TranslateAccelerator);

            InitDamageServices();

            // notify subclasses that the editor has been created
            OnEditorCreated();
        }
Esempio n. 25
0
 public IContentEditor CreateEditorFromDraft(IContentEditorSite contentEditorSite, IInternetSecurityManager internetSecurityManager, string wysiwygHtml, string pathToDraftFile, int dlControlFlags)
 {
     return new ContentEditorProxy(this, contentEditorSite, internetSecurityManager, wysiwygHtml, null, pathToDraftFile, dlControlFlags);
 }
Esempio n. 26
0
 public InternetSecurityManagerShim(IInternetSecurityManager manager)
 {
     SecurityManager = manager;
 }
 public IntranetZoneCredentialPolicy()
 {
     ExceptionHelper.ControlPolicyPermission.Demand();
     _ManagerRef = (IInternetSecurityManager) new InternetSecurityManager();
 }
Esempio n. 28
0
 public ContentEditorProxy(ContentEditorFactory factory, IContentEditorSite contentEditorSite, IInternetSecurityManager internetSecurityManager, string wysiwygHTML, string previewHTML, string pathToFile, int dlControlFlags)
 {
     ContentEditorProxyCore(factory, contentEditorSite, internetSecurityManager, wysiwygHTML, previewHTML, PostEditorFile.GetExisting(new FileInfo(pathToFile)).Load(false), new ContentEditorTemplateStrategy(), dlControlFlags, null);
 }