From 48af26c7d3d247d790fcd7531708aca4e83e7e94 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Tue, 14 Jan 2014 10:59:20 +0100 Subject: [PATCH] Don't reuse same tab for multiple bookmarks. As WebKit is asynchronous to the window, when launching a request in a BWebView, IsBlankTab() will keep returning true until it gets the BMessage and updates its state. When opening bookmarks or refs, we would send them too fast, not detect this, and reuse the same tab for several items. Make sure the blank tab is only used once when looping over the refs, and force opening all remaining refs in new tabs of the same window. Fixes #6625. Also optimizes the ref loading by not looking up the window for each ref. Pick one window, then use it for all the bookmarks in the loop. --- src/apps/webpositive/BrowserApp.cpp | 28 ++++++++++++++++------------ src/apps/webpositive/BrowserApp.h | 7 ++++--- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/apps/webpositive/BrowserApp.cpp b/src/apps/webpositive/BrowserApp.cpp index 384ab7629d..ba6f50b863 100644 --- a/src/apps/webpositive/BrowserApp.cpp +++ b/src/apps/webpositive/BrowserApp.cpp @@ -374,13 +374,13 @@ BrowserApp::_RefsReceived(BMessage* message, int32* _pagesCreated, continue; BString url; url << path.Path(); - _CreateNewPage(url, window, fullscreen); + window = _CreateNewPage(url, window, fullscreen, pagesCreated == 0); pagesCreated++; } BString url; for (int32 i = 0; message->FindString("url", i, &url) == B_OK; i++) { - _CreateNewPage(url, window, fullscreen); + window = _CreateNewPage(url, window, fullscreen, pagesCreated == 0); pagesCreated++; } @@ -391,13 +391,13 @@ BrowserApp::_RefsReceived(BMessage* message, int32* _pagesCreated, } -void +BrowserWindow* BrowserApp::_CreateNewPage(const BString& url, BrowserWindow* webWindow, - bool fullscreen) + bool fullscreen, bool useBlankTab) { - // Let's first see if we must target a specific window + // Let's first see if we must target a specific window... if (webWindow && webWindow->Lock()) { - if (webWindow->IsBlankTab()) { + if (useBlankTab && webWindow->IsBlankTab()) { if (url.Length() != 0) webWindow->CurrentWebView()->LoadURL(url); } else @@ -405,10 +405,10 @@ BrowserApp::_CreateNewPage(const BString& url, BrowserWindow* webWindow, webWindow->Activate(); webWindow->CurrentWebView()->MakeFocus(true); webWindow->Unlock(); - return; + return webWindow; } - // In other cases, try to find a suitable one + // Otherwise, try to find one in the current workspace uint32 workspace = 1 << current_workspace(); bool loadedInWindowOnCurrentWorkspace = false; @@ -416,9 +416,10 @@ BrowserApp::_CreateNewPage(const BString& url, BrowserWindow* webWindow, webWindow = dynamic_cast(window); if (!webWindow) continue; + if (webWindow->Lock()) { if (webWindow->Workspaces() & workspace) { - if (webWindow->IsBlankTab()) { + if (useBlankTab && webWindow->IsBlankTab()) { if (url.Length() != 0) webWindow->CurrentWebView()->LoadURL(url); } else @@ -430,13 +431,15 @@ BrowserApp::_CreateNewPage(const BString& url, BrowserWindow* webWindow, webWindow->Unlock(); } if (loadedInWindowOnCurrentWorkspace) - return; + return webWindow; } - _CreateNewWindow(url, fullscreen); + + // Finally, if no window is available, let's create one. + return _CreateNewWindow(url, fullscreen); } -void +BrowserWindow* BrowserApp::_CreateNewWindow(const BString& url, bool fullscreen) { // Offset the window frame unless this is the first window created in the @@ -451,6 +454,7 @@ BrowserApp::_CreateNewWindow(const BString& url, bool fullscreen) if (fullscreen) window->ToggleFullscreen(); window->Show(); + return window; } diff --git a/src/apps/webpositive/BrowserApp.h b/src/apps/webpositive/BrowserApp.h index 96b3aefb6c..937cd05a79 100644 --- a/src/apps/webpositive/BrowserApp.h +++ b/src/apps/webpositive/BrowserApp.h @@ -58,10 +58,11 @@ private: void _RefsReceived(BMessage* message, int32* pagesCreated = NULL, bool* fullscreen = NULL); - void _CreateNewPage(const BString& url, + BrowserWindow* _CreateNewPage(const BString& url, BrowserWindow* window = NULL, - bool fullscreen = false); - void _CreateNewWindow(const BString& url, + bool fullscreen = false, + bool useBlankTab = true); + BrowserWindow* _CreateNewWindow(const BString& url, bool fullscreen = false); void _CreateNewTab(BrowserWindow* window, const BString& url, bool select);