public override void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model) { if (!TwitterUrls.IsTweetDeck(frame.Url) || browser.IsLoading) { extraContext.Reset(); } base.OnBeforeContextMenu(browserControl, browser, frame, parameters, model); bool isSelecting = parameters.TypeFlags.HasFlag(ContextMenuType.Selection); bool isEditing = parameters.TypeFlags.HasFlag(ContextMenuType.Editable); if (!isSelecting && !isEditing) { AddSeparator(model); IMenuModel globalMenu = model.Count == 0 ? model : model.AddSubMenu(MenuGlobal, Program.BrandName); globalMenu.AddItem(CefMenuCommand.Reload, TitleReloadBrowser); globalMenu.AddCheckItem(MenuMute, TitleMuteNotifications); globalMenu.SetChecked(MenuMute, Config.MuteNotifications); globalMenu.AddSeparator(); globalMenu.AddItem(MenuSettings, TitleSettings); globalMenu.AddItem(MenuPlugins, TitlePlugins); globalMenu.AddItem(MenuAbout, TitleAboutProgram); AddDebugMenuItems(globalMenu); } }
public string GetTwitterUser(string ConsumerKey, string ConsumerSecret, string auth_token, string auth_secret) { // see all comments from GenerateTokenUrl as they apply here as well string Nonce = Convert.ToBase64String(new ASCIIEncoding().GetBytes(DateTime.Now.Ticks.ToString())); TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); string timestamp = Convert.ToInt64(ts.TotalSeconds).ToString(); TwitterUrls TwitterUrls = new TwitterUrls("https://api.twitter.com/1.1/account/verify_credentials.json"); List <KeyValuePair <string, string> > Parameters = new List <KeyValuePair <string, string> >(); Parameters.Add(new KeyValuePair <string, string>("include_email", "true")); Parameters.Add(new KeyValuePair <string, string>("oauth_consumer_key", ConsumerKey)); Parameters.Add(new KeyValuePair <string, string>("oauth_nonce", Nonce)); Parameters.Add(new KeyValuePair <string, string>("oauth_signature_method", "HMAC-SHA1")); Parameters.Add(new KeyValuePair <string, string>("oauth_timestamp", timestamp)); Parameters.Add(new KeyValuePair <string, string>("oauth_token", auth_token)); Parameters.Add(new KeyValuePair <string, string>("oauth_version", "1.0")); string signature = TwitterUrls.GenerateSignature(ConsumerSecret, Parameters, auth_secret); Parameters.Insert(3, new KeyValuePair <string, string>("oauth_signature", signature)); string retVal = string.Empty; string url = TwitterUrls.GenerateCallingUrls(Parameters); using (WebClient client = new WebClient()) { retVal = client.DownloadString(url); } return(retVal); }
protected override void OnBeforeContextMenu(CefBrowser browser, CefFrame frame, CefContextMenuParams state, CefMenuModel model) { if (!TwitterUrls.IsTweetDeck(frame.Url) || browser.IsLoading) { extraContext.Reset(); } base.OnBeforeContextMenu(browser, frame, state, model); }
private void BrowserComponentOnPageLoadEnd(object sender, PageLoadEventArgs e) { string url = e.Url; if (TwitterUrls.IsTweetDeck(url) && url != BlankURL) { pluginManager.Execute(PluginEnvironment.Notification, browserComponent); } }
private void browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e) { IFrame frame = e.Frame; if (frame.IsMain && TwitterUrls.IsTweetDeck(frame.Url)) { Ready?.Invoke(this, new PluginDispatchEventArgs(executor)); } }
protected override bool OnBeforeBrowse(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, bool userGesture, bool isRedirect) { if (userGesture && request.TransitionType == TransitionType.LinkClicked) { bool block = request.Url == BlockNextUserNavUrl; BlockNextUserNavUrl = string.Empty; return(block); } else if (request.TransitionType.HasFlag(TransitionType.ForwardBack) && TwitterUrls.IsTweetDeck(frame.Url)) { return(true); } return(base.OnBeforeBrowse(browserControl, browser, frame, request, userGesture, isRedirect)); }
private void DownloadTempImage(string url, Action <string> process) { string?staticFileName = TwitterUrls.GetImageFileName(url); string file = Path.Combine(browserComponent.CacheFolder, staticFileName ?? Path.GetRandomFileName()); if (staticFileName != null && FileUtils.FileExistsAndNotEmpty(file)) { process(file); } else { void OnSuccess() { process(file); }
private static Media?GetMedia(IContextMenuParams parameters, TweetDeckExtraContext extraContext, ImageQuality imageQuality) { var media = extraContext?.Media; if (media != null) { return(media); } if (parameters.TypeFlags.HasFlag(ContextMenuType.Media) && parameters.HasImageContents) { return(new Media(Media.Type.Image, TwitterUrls.GetMediaLink(parameters.SourceUrl, imageQuality))); } return(null); }
private static void DownloadTempImage(string url, ImageQuality quality, Action <string> process) { string file = Path.Combine(BrowserCache.CacheFolder, TwitterUrls.GetImageFileName(url) ?? Path.GetRandomFileName()); if (FileUtils.FileExistsAndNotEmpty(file)) { process(file); } else { DownloadFileAuth(TwitterUrls.GetMediaLink(url, quality), file, () => { process(file); }, ex => { FormMessage.Error("Image Download", "An error occurred while downloading the image: " + ex.Message, FormMessage.OK); }); } }
public virtual void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model) { if (!TwitterUrls.IsTweetDeck(frame.Url) || browser.IsLoading) { Context = CurrentInfo.Reset(); } else { Context = CurrentInfo.Create(parameters); } if (parameters.TypeFlags.HasFlag(ContextMenuType.Selection) && !parameters.TypeFlags.HasFlag(ContextMenuType.Editable)) { model.AddItem(MenuSearchInBrowser, "Search in browser"); model.AddSeparator(); model.AddItem(MenuReadApplyROT13, "Apply ROT13"); model.AddSeparator(); }
public static void DownloadImages(string[] urls, string username, ImageQuality quality) { if (urls.Length == 0) { return; } string firstImageLink = TwitterUrls.GetMediaLink(urls[0], quality); int qualityIndex = firstImageLink.IndexOf(':', firstImageLink.LastIndexOf('/')); string filename = TwitterUrls.GetImageFileName(firstImageLink); string ext = Path.GetExtension(filename); // includes dot using SaveFileDialog dialog = new SaveFileDialog { AutoUpgradeEnabled = true, OverwritePrompt = urls.Length == 1, Title = "Save Image", FileName = qualityIndex == -1 ? filename : $"{username} {Path.ChangeExtension(filename, null)} {firstImageLink.Substring(qualityIndex + 1)}".Trim() + ext, Filter = (urls.Length == 1 ? "Image" : "Images") + (string.IsNullOrEmpty(ext) ? " (unknown)|*.*" : $" (*{ext})|*{ext}") }; if (dialog.ShowDialog() == DialogResult.OK) {
public override void OnBeforeContextMenu(IWebBrowser browserControl, IBrowser browser, IFrame frame, IContextMenuParams parameters, IMenuModel model) { bool isSelecting = parameters.TypeFlags.HasFlag(ContextMenuType.Selection); bool isEditing = parameters.TypeFlags.HasFlag(ContextMenuType.Editable); model.Remove(CefMenuCommand.Back); model.Remove(CefMenuCommand.Forward); model.Remove(CefMenuCommand.Print); model.Remove(CefMenuCommand.ViewSource); RemoveSeparatorIfLast(model); if (isSelecting) { if (isEditing) { model.AddSeparator(); model.AddItem(MenuWriteApplyROT13, "Apply ROT13"); } model.AddSeparator(); } base.OnBeforeContextMenu(browserControl, browser, frame, parameters, model); if (isSelecting && !isEditing && TwitterUrls.IsTweetDeck(frame.Url)) { InsertSelectionSearchItem(model, MenuSearchInColumn, "Search in a column"); } if (Context.Types.HasFlag(ContextInfo.ContextType.Chirp) && !isSelecting && !isEditing) { model.AddItem(MenuOpenTweetUrl, "Open tweet in browser"); model.AddItem(MenuCopyTweetUrl, "Copy tweet address"); model.AddItem(MenuScreenshotTweet, "Screenshot tweet to clipboard"); if (!string.IsNullOrEmpty(Context.Chirp.QuoteUrl)) { model.AddSeparator(); model.AddItem(MenuOpenQuotedTweetUrl, "Open quoted tweet in browser"); model.AddItem(MenuCopyQuotedTweetUrl, "Copy quoted tweet address"); } model.AddSeparator(); } if (!isSelecting && !isEditing) { AddSeparator(model); IMenuModel globalMenu = model.Count == 0 ? model : model.AddSubMenu(MenuGlobal, Program.BrandName); globalMenu.AddItem(CefMenuCommand.Reload, TitleReloadBrowser); globalMenu.AddCheckItem(MenuMute, TitleMuteNotifications); globalMenu.SetChecked(MenuMute, Config.MuteNotifications); globalMenu.AddSeparator(); globalMenu.AddItem(MenuSettings, TitleSettings); globalMenu.AddItem(MenuPlugins, TitlePlugins); globalMenu.AddItem(MenuAbout, TitleAboutProgram); AddDebugMenuItems(globalMenu); } RemoveSeparatorIfLast(model); form.InvokeAsyncSafe(form.AnalyticsFile.BrowserContextMenus.Trigger); }
public void OpenBrowser(string url) { if (string.IsNullOrWhiteSpace(url)) { return; } FormManager.RunOnUIThreadAsync(() => { var config = Program.Config.User; switch (TwitterUrls.Check(url)) { case TwitterUrls.UrlType.Fine: string browserPath = config.BrowserPath; if (browserPath == null || !File.Exists(browserPath)) { OpenAssociatedProgram(url); } else { string quotedUrl = '"' + url + '"'; string browserArgs = config.BrowserPathArgs == null ? quotedUrl : config.BrowserPathArgs + ' ' + quotedUrl; try { using (Process.Start(browserPath, browserArgs)) {} } catch (Exception e) { App.ErrorHandler.HandleException("Error Opening Browser", "Could not open the browser.", true, e); } } break; case TwitterUrls.UrlType.Tracking: if (config.IgnoreTrackingUrlWarning) { goto case TwitterUrls.UrlType.Fine; } using (FormMessage form = new FormMessage("Blocked URL", "TweetDuck has blocked a tracking url due to privacy concerns. Do you want to visit it anyway?\n" + url, MessageBoxIcon.Warning)) { form.AddButton(FormMessage.No, DialogResult.No, ControlType.Cancel | ControlType.Focused); form.AddButton(FormMessage.Yes, DialogResult.Yes, ControlType.Accept); form.AddButton("Always Visit", DialogResult.Ignore); DialogResult result = form.ShowDialog(); if (result == DialogResult.Ignore) { config.IgnoreTrackingUrlWarning = true; config.Save(); } if (result == DialogResult.Ignore || result == DialogResult.Yes) { goto case TwitterUrls.UrlType.Fine; } } break; case TwitterUrls.UrlType.Invalid: FormMessage.Warning("Blocked URL", "A potentially malicious or invalid URL was blocked from opening:\n" + url, FormMessage.OK); break; } }); }
public bool IsPopupAllowed(string url) { return(TwitterUrls.IsAllowedPopupUrl(url)); }