Exemple #1
0
        protected virtual bool HandleRawKey(IWebBrowser browserControl, IBrowser browser, Keys key, CefEventFlags modifiers)
        {
            if (modifiers == (CefEventFlags.ControlDown | CefEventFlags.ShiftDown) && key == Keys.I)
            {
                if (BrowserUtils.HasDevTools)
                {
                    browserControl.OpenDevToolsCustom();
                }
                else
                {
                    browserControl.AsControl().InvokeSafe(() => {
                        string extraMessage;

                        if (Program.IsPortable)
                        {
                            extraMessage = "Please download the portable installer, select the folder with your current installation of TweetDuck Portable, and tick 'Install dev tools' during the installation process.";
                        }
                        else
                        {
                            extraMessage = "Please download the installer, and tick 'Install dev tools' during the installation process. The installer will automatically find and update your current installation of TweetDuck.";
                        }

                        FormMessage.Information("Dev Tools", "You do not have dev tools installed. " + extraMessage, FormMessage.OK);
                    });
                }

                return(true);
            }

            return(false);
        }
Exemple #2
0
        bool IJsDialogHandler.OnJSDialog(IWebBrowser browserControl, IBrowser browser, string originUrl, CefJsDialogType dialogType, string messageText, string defaultPromptText, IJsDialogCallback callback, ref bool suppressMessage)
        {
            browserControl.AsControl().InvokeSafe(() => {
                FormMessage form;
                TextBox input = null;

                if (dialogType == CefJsDialogType.Alert)
                {
                    form = CreateMessageForm("Browser Message", messageText);
                    form.AddButton(FormMessage.OK, ControlType.Accept | ControlType.Focused);
                }
                else if (dialogType == CefJsDialogType.Confirm)
                {
                    form = CreateMessageForm("Browser Confirmation", messageText);
                    form.AddButton(FormMessage.No, DialogResult.No, ControlType.Cancel);
                    form.AddButton(FormMessage.Yes, ControlType.Focused);
                }
                else if (dialogType == CefJsDialogType.Prompt)
                {
                    form = CreateMessageForm("Browser Prompt", messageText);
                    form.AddButton(FormMessage.Cancel, DialogResult.Cancel, ControlType.Cancel);
                    form.AddButton(FormMessage.OK, ControlType.Accept | ControlType.Focused);

                    float dpiScale = form.GetDPIScale();
                    int inputPad   = form.HasIcon ? 43 : 0;

                    input = new TextBox {
                        Anchor   = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom,
                        Font     = SystemFonts.MessageBoxFont,
                        Location = new Point(BrowserUtils.Scale(22 + inputPad, dpiScale), form.ActionPanelY - BrowserUtils.Scale(46, dpiScale)),
                        Size     = new Size(form.ClientSize.Width - BrowserUtils.Scale(44 + inputPad, dpiScale), BrowserUtils.Scale(23, dpiScale))
                    };

                    form.Controls.Add(input);
                    form.ActiveControl = input;
                    form.Height       += input.Size.Height + input.Margin.Vertical;
                }
                else
                {
                    callback.Continue(false);
                    return;
                }

                bool success = form.ShowDialog() == DialogResult.OK;

                if (input == null)
                {
                    callback.Continue(success);
                }
                else
                {
                    callback.Continue(success, input.Text);
                    input.Dispose();
                }

                form.Dispose();
            });

            return(true);
        }
Exemple #3
0
        public static bool HandleLinkClick(IWebBrowser browserControl, WindowOpenDisposition targetDisposition, string targetUrl)
        {
            switch (targetDisposition)
            {
            case WindowOpenDisposition.NewBackgroundTab:
            case WindowOpenDisposition.NewForegroundTab:
            case WindowOpenDisposition.NewPopup when !IsPopupAllowed(targetUrl):
            case WindowOpenDisposition.NewWindow:
                browserControl.AsControl().InvokeAsyncSafe(() => BrowserUtils.OpenExternalBrowser(targetUrl));
                return(true);

            default:
                return(false);
            }
        }
Exemple #4
0
        public bool OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
        {
            newBrowser = null;

            switch (targetDisposition)
            {
            case WindowOpenDisposition.NewBackgroundTab:
            case WindowOpenDisposition.NewForegroundTab:
            case WindowOpenDisposition.NewPopup:
            case WindowOpenDisposition.NewWindow:
                browserControl.AsControl().InvokeAsyncSafe(() => BrowserUtils.OpenExternalBrowser(targetUrl));
                return(true);

            default:
                return(false);
            }
        }
Exemple #5
0
        public virtual bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags)
        {
            Control control = browserControl.AsControl();

            switch (commandId)
            {
            case MenuOpenLinkUrl:
                OpenBrowser(control, Context.LinkUrl);
                break;

            case MenuCopyLinkUrl:
                SetClipboardText(control, Context.UnsafeLinkUrl);
                break;

            case MenuCopyUsername: {
                string url   = Context.UnsafeLinkUrl;
                Match  match = TwitterUtils.RegexAccount.Match(url);

                SetClipboardText(control, match.Success ? match.Groups[1].Value : url);
                control.InvokeAsyncSafe(analytics.AnalyticsFile.CopiedUsernames.Trigger);
                break;
            }

            case MenuOpenMediaUrl:
                OpenBrowser(control, TwitterUtils.GetMediaLink(Context.MediaUrl, ImageQuality));
                break;

            case MenuCopyMediaUrl:
                SetClipboardText(control, TwitterUtils.GetMediaLink(Context.MediaUrl, ImageQuality));
                break;

            case MenuViewImage: {
                string url = Context.MediaUrl;

                control.InvokeAsyncSafe(() => {
                        TwitterUtils.ViewImage(url, ImageQuality);
                        analytics.AnalyticsFile.ViewedImages.Trigger();
                    });

                break;
            }

            case MenuSaveMedia: {
                bool   isVideo  = Context.Types.HasFlag(ContextInfo.ContextType.Video);
                string url      = Context.MediaUrl;
                string username = Context.Chirp.Authors.LastOrDefault();

                control.InvokeAsyncSafe(() => {
                        if (isVideo)
                        {
                            TwitterUtils.DownloadVideo(url, username);
                            analytics.AnalyticsFile.DownloadedVideos.Trigger();
                        }
                        else
                        {
                            TwitterUtils.DownloadImage(url, username, ImageQuality);
                            analytics.AnalyticsFile.DownloadedImages.Trigger();
                        }
                    });

                break;
            }

            case MenuSaveTweetImages: {
                string[] urls     = Context.Chirp.Images;
                string   username = Context.Chirp.Authors.LastOrDefault();

                control.InvokeAsyncSafe(() => {
                        TwitterUtils.DownloadImages(urls, username, ImageQuality);
                        analytics.AnalyticsFile.DownloadedImages.Trigger();
                    });

                break;
            }

            case MenuReadApplyROT13:
                string selection = parameters.SelectionText;
                control.InvokeAsyncSafe(() => FormMessage.Information("ROT13", StringUtils.ConvertRot13(selection), FormMessage.OK));
                control.InvokeAsyncSafe(analytics.AnalyticsFile.UsedROT13.Trigger);
                return(true);

            case MenuSearchInBrowser:
                string query = parameters.SelectionText;
                control.InvokeAsyncSafe(() => BrowserUtils.OpenExternalSearch(query));
                DeselectAll(frame);
                break;

            case MenuOpenDevTools:
                browserControl.ShowDevTools();
                break;
            }

            return(false);
        }
Exemple #6
0
        public virtual bool OnContextMenuCommand(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, CefMenuCommand commandId, CefEventFlags eventFlags)
        {
            switch (commandId)
            {
            case MenuOpenLinkUrl:
                OpenBrowser(browserControl.AsControl(), IsLink ? ContextInfo.Value : parameters.LinkUrl);
                break;

            case MenuCopyLinkUrl:
                SetClipboardText(browserControl.AsControl(), IsLink ? ContextInfo.Value : parameters.UnfilteredLinkUrl);
                break;

            case MenuCopyUsername:
                Match match = TwitterUtils.RegexAccount.Match(parameters.UnfilteredLinkUrl);
                SetClipboardText(browserControl.AsControl(), match.Success ? match.Groups[1].Value : parameters.UnfilteredLinkUrl);
                break;

            case MenuOpenMediaUrl:
                OpenBrowser(browserControl.AsControl(), TwitterUtils.GetMediaLink(GetMediaLink(parameters), ImageQuality));
                break;

            case MenuCopyMediaUrl:
                SetClipboardText(browserControl.AsControl(), TwitterUtils.GetMediaLink(GetMediaLink(parameters), ImageQuality));
                break;

            case MenuViewImage:
                string url  = GetMediaLink(parameters);
                string file = Path.Combine(BrowserCache.CacheFolder, TwitterUtils.GetImageFileName(url));

                void ViewFile()
                {
                    string ext = Path.GetExtension(file);

                    if (TwitterUtils.ValidImageExtensions.Contains(ext))
                    {
                        WindowsUtils.OpenAssociatedProgram(file);
                    }
                    else
                    {
                        FormMessage.Error("Image Download", "Invalid file extension " + ext, FormMessage.OK);
                    }
                }

                if (File.Exists(file))
                {
                    ViewFile();
                }
                else
                {
                    BrowserUtils.DownloadFileAsync(TwitterUtils.GetMediaLink(url, ImageQuality), file, ViewFile, ex => {
                        FormMessage.Error("Image Download", "An error occurred while downloading the image: " + ex.Message, FormMessage.OK);
                    });
                }

                break;

            case MenuSaveMedia:
                if (IsVideo)
                {
                    TwitterUtils.DownloadVideo(GetMediaLink(parameters), lastHighlightedTweetAuthors.LastOrDefault());
                }
                else
                {
                    TwitterUtils.DownloadImage(GetMediaLink(parameters), lastHighlightedTweetAuthors.LastOrDefault(), ImageQuality);
                }

                break;

            case MenuSaveTweetImages:
                TwitterUtils.DownloadImages(lastHighlightedTweetImageList, lastHighlightedTweetAuthors.LastOrDefault(), ImageQuality);
                break;

            case MenuOpenDevTools:
                browserControl.ShowDevTools();
                break;
            }

            return(false);
        }