diff --git a/Browser/Handling/KeyboardHandlerBase.cs b/Browser/Handling/KeyboardHandlerBase.cs index 57ba2b2a..e218f83c 100644 --- a/Browser/Handling/KeyboardHandlerBase.cs +++ b/Browser/Handling/KeyboardHandlerBase.cs @@ -33,7 +33,7 @@ protected virtual bool HandleRawKey(IWebBrowser browserControl, IBrowser browser } bool IKeyboardHandler.OnPreKeyEvent(IWebBrowser browserControl, IBrowser browser, KeyType type, int windowsKeyCode, int nativeKeyCode, CefEventFlags modifiers, bool isSystemKey, ref bool isKeyboardShortcut){ - if (type == KeyType.RawKeyDown && !browser.FocusedFrame.Url.StartsWith("chrome-devtools://")){ + if (type == KeyType.RawKeyDown && !browser.FocusedFrame.Url.StartsWith("devtools://")){ return HandleRawKey(browserControl, browser, (Keys)windowsKeyCode, modifiers); } diff --git a/Browser/Handling/ResourceHandlerNotification.cs b/Browser/Handling/ResourceHandlerNotification.cs index bbfd5bdc..3b8daf29 100644 --- a/Browser/Handling/ResourceHandlerNotification.cs +++ b/Browser/Handling/ResourceHandlerNotification.cs @@ -23,8 +23,13 @@ public void Dispose(){ } bool IResourceHandler.Open(IRequest request, out bool handleRequest, ICallback callback){ + callback.Dispose(); handleRequest = true; - callback.Continue(); + + if (dataIn != null){ + dataIn.Position = 0; + } + return true; } @@ -48,11 +53,11 @@ bool IResourceHandler.Read(Stream dataOut, out int bytesRead, IResourceReadCallb dataIn.Read(buffer, 0, length); dataOut.Write(buffer, 0, length); bytesRead = length; - return true; }catch{ // catch IOException, possibly NullReferenceException if dataIn is null bytesRead = 0; - return false; } + + return bytesRead > 0; } bool IResourceHandler.Skip(long bytesToSkip, out long bytesSkipped, IResourceSkipCallback callback){ diff --git a/Browser/Handling/ResourceRequestHandlerBrowser.cs b/Browser/Handling/ResourceRequestHandlerBrowser.cs index 8f17d98d..5f36d770 100644 --- a/Browser/Handling/ResourceRequestHandlerBrowser.cs +++ b/Browser/Handling/ResourceRequestHandlerBrowser.cs @@ -1,5 +1,4 @@ -using System.Collections.Specialized; -using CefSharp; +using CefSharp; using TweetDuck.Browser.Handling.Filters; using TweetDuck.Utils; using TweetLib.Core.Features.Twitter; @@ -28,9 +27,7 @@ protected override CefReturnValue OnBeforeResourceLoad(IWebBrowser browserContro return CefReturnValue.Cancel; } else if (url.Contains(UrlVendorResource)){ - NameValueCollection headers = request.Headers; - headers["Accept-Encoding"] = "identity"; - request.Headers = headers; + request.SetHeaderByName("Accept-Encoding", "identity", overwrite: true); } } diff --git a/Browser/Notification/FormNotificationMain.cs b/Browser/Notification/FormNotificationMain.cs index e3ea4399..79e6d271 100644 --- a/Browser/Notification/FormNotificationMain.cs +++ b/Browser/Notification/FormNotificationMain.cs @@ -73,7 +73,7 @@ protected FormNotificationMain(FormBrowser owner, PluginManager pluginManager, b this.timerBarHeight = BrowserUtils.Scale(4, DpiScale); browser.KeyboardHandler = new KeyboardHandlerNotification(this); - browser.RegisterAsyncJsObject("$TD", new TweetDeckBridge.Notification(owner, this)); + browser.RegisterJsBridge("$TD", new TweetDeckBridge.Notification(owner, this)); browser.LoadingStateChanged += Browser_LoadingStateChanged; browser.FrameLoadEnd += Browser_FrameLoadEnd; diff --git a/Browser/Notification/Screenshot/FormNotificationScreenshotable.cs b/Browser/Notification/Screenshot/FormNotificationScreenshotable.cs index a0628fbb..12e4aa81 100644 --- a/Browser/Notification/Screenshot/FormNotificationScreenshotable.cs +++ b/Browser/Notification/Screenshot/FormNotificationScreenshotable.cs @@ -23,7 +23,7 @@ public FormNotificationScreenshotable(Action callback, FormBrowser owner, Plugin int realWidth = BrowserUtils.Scale(width, DpiScale); - browser.RegisterAsyncJsObject("$TD_NotificationScreenshot", new ScreenshotBridge(this, SetScreenshotHeight, callback)); + browser.RegisterJsBridge("$TD_NotificationScreenshot", new ScreenshotBridge(this, SetScreenshotHeight, callback)); browser.LoadingStateChanged += (sender, args) => { if (args.IsLoading){ diff --git a/Browser/TweetDeckBrowser.cs b/Browser/TweetDeckBrowser.cs index cdb8d5c2..ad40e3f6 100644 --- a/Browser/TweetDeckBrowser.cs +++ b/Browser/TweetDeckBrowser.cs @@ -74,8 +74,8 @@ public TweetDeckBrowser(FormBrowser owner, PluginManager plugins, TweetDeckBridg this.browser.FrameLoadEnd += browser_FrameLoadEnd; this.browser.LoadError += browser_LoadError; - this.browser.RegisterAsyncJsObject("$TD", tdBridge); - this.browser.RegisterAsyncJsObject("$TDU", updateBridge); + this.browser.RegisterJsBridge("$TD", tdBridge); + this.browser.RegisterJsBridge("$TDU", updateBridge); this.browser.BrowserSettings.BackgroundColor = (uint)TwitterUtils.BackgroundColor.ToArgb(); this.browser.Dock = DockStyle.None; diff --git a/Dialogs/Settings/TabSettingsNotifications.cs b/Dialogs/Settings/TabSettingsNotifications.cs index 503a3f22..289e1e04 100644 --- a/Dialogs/Settings/TabSettingsNotifications.cs +++ b/Dialogs/Settings/TabSettingsNotifications.cs @@ -23,7 +23,6 @@ public TabSettingsNotifications(FormNotificationExample notification){ }); }; - this.notification.Activated += notification_Activated; this.notification.Show(); Disposed += (sender, args) => this.notification.Dispose(); @@ -139,11 +138,6 @@ private void TabSettingsNotifications_ParentChanged(object sender, EventArgs e){ } } - private void notification_Activated(object sender, EventArgs e){ - notification.Hide(); - notification.Activated -= notification_Activated; - } - private void notification_Move(object sender, EventArgs e){ if (radioLocCustom.Checked && notification.Location != ControlExtensions.InvisibleLocation){ Config.CustomNotificationPosition = notification.Location; diff --git a/Plugins/PluginDispatcher.cs b/Plugins/PluginDispatcher.cs index 199a98ec..23c0e9b4 100644 --- a/Plugins/PluginDispatcher.cs +++ b/Plugins/PluginDispatcher.cs @@ -1,6 +1,7 @@ using System; using CefSharp; using TweetDuck.Browser.Adapters; +using TweetDuck.Utils; using TweetLib.Core.Browser; using TweetLib.Core.Features.Plugins; using TweetLib.Core.Features.Plugins.Events; @@ -22,7 +23,7 @@ public PluginDispatcher(IWebBrowser browser, Func<string, bool> executeOnUrl){ } void IPluginDispatcher.AttachBridge(string name, object bridge){ - browser.RegisterAsyncJsObject(name, bridge); + browser.RegisterJsBridge(name, bridge); } private void browser_FrameLoadEnd(object sender, FrameLoadEndEventArgs e){ diff --git a/Plugins/PluginSchemeFactory.cs b/Plugins/PluginSchemeFactory.cs index 275f7466..2cee0a64 100644 --- a/Plugins/PluginSchemeFactory.cs +++ b/Plugins/PluginSchemeFactory.cs @@ -27,7 +27,7 @@ public IResourceHandler File(byte[] bytes, string extension){ return Status(HttpStatusCode.NoContent, "File is empty."); // FromByteArray crashes CEF internals with no contents } else{ - return ResourceHandler.FromByteArray(bytes, ResourceHandler.GetMimeType(extension)); + return ResourceHandler.FromByteArray(bytes, Cef.GetMimeType(extension)); } } } diff --git a/Program.cs b/Program.cs index 4d643563..26e8f438 100644 --- a/Program.cs +++ b/Program.cs @@ -144,6 +144,7 @@ private static void Main(){ if (Arguments.HasFlag(Arguments.ArgUpdated)){ WindowsUtils.TryDeleteFolderWhenAble(InstallerPath, 8000); + WindowsUtils.TryDeleteFolderWhenAble(Path.Combine(StoragePath, "Service Worker"), 4000); BrowserCache.TryClearNow(); } @@ -161,7 +162,7 @@ private static void Main(){ CefSettings settings = new CefSettings{ UserAgent = BrowserUtils.UserAgentChrome, - BrowserSubprocessPath = BrandName + ".Browser.exe", + BrowserSubprocessPath = Path.Combine(ProgramPath, BrandName + ".Browser.exe"), CachePath = StoragePath, UserDataPath = CefDataPath, LogFile = ConsoleLogFilePath, diff --git a/Utils/BrowserUtils.cs b/Utils/BrowserUtils.cs index 5e0b0910..98119ad0 100644 --- a/Utils/BrowserUtils.cs +++ b/Utils/BrowserUtils.cs @@ -81,6 +81,11 @@ void UpdateZoomLevel(object sender, EventArgs args){ }; } + public static void RegisterJsBridge(this IWebBrowser browserControl, string name, object bridge){ + CefSharpSettings.LegacyJavascriptBindingEnabled = true; + browserControl.JavascriptObjectRepository.Register(name, bridge, isAsync: true, BindingOptions.DefaultBinder); + } + public static void OpenDevToolsCustom(this IWebBrowser browser){ var info = new WindowInfo(); info.SetAsPopup(IntPtr.Zero, "Dev Tools");