Web+: Rework startup session code

* Loads previous session if lauched by link and setting to use previous
  session is enabled
* Fixes #18722
* Adds window workspaces to archive message
* Adds opening session windows to same workspace it was previously
  (could be made optional)

Change-Id: I8c56516fa8770011346989a59e8ecd22440eef36
Reviewed-on: https://review.haiku-os.org/c/haiku/+/8859
Reviewed-by: nephele nephele <[email protected]>
Tested-by: Commit checker robot <[email protected]>
Reviewed-by: Adrien Destugues <[email protected]>
This commit is contained in:
Ilmari "ilzu" Siiteri
2025-04-09 11:19:53 +00:00
committed by Adrien Destugues
parent 197dcc80dc
commit e3a893afd8
4 changed files with 81 additions and 49 deletions
+64 -32
View File
@@ -248,29 +248,31 @@ BrowserApp::ReadyToRun()
int32 pagesCreated = 0; int32 pagesCreated = 0;
bool fullscreen = false; bool fullscreen = false;
if (fLaunchRefsMessage) {
_RefsReceived(fLaunchRefsMessage, &pagesCreated, &fullscreen);
delete fLaunchRefsMessage;
fLaunchRefsMessage = NULL;
}
// If no refs led to a new open page, open new session if set // Handle startup session / page
if (fSession->InitCheck() == B_OK && pagesCreated == 0) { if (fSession->InitCheck() == B_OK) {
const char* kSettingsKeyStartUpPolicy = "start up policy"; const char* kSettingsKeyStartUpPolicy = "start up policy";
uint32 fStartUpPolicy = fSettings->GetValue(kSettingsKeyStartUpPolicy, uint32 fStartUpPolicy = fSettings->GetValue(kSettingsKeyStartUpPolicy,
(uint32)ResumePriorSession); (uint32)ResumePriorSession);
// If requested not to load previous session
if (fStartUpPolicy == StartNewSession) { if (fStartUpPolicy == StartNewSession) {
PostMessage(NEW_WINDOW); // Check if lauchrefs will open a page
if (fLaunchRefsMessage == NULL) {
// else open new window
PostMessage(NEW_WINDOW);
}
} else { } else {
// otherwise, restore previous session // otherwise, restore previous session
BMessage archivedWindow; BMessage archivedWindow;
for (int i = 0; fSession->FindMessage("window", i, &archivedWindow) for (int i = 0; fSession->FindMessage("window", i, &archivedWindow)
== B_OK; i++) { == B_OK; i++) {
BRect frame = archivedWindow.FindRect("window frame"); BRect frame = archivedWindow.FindRect("window frame");
uint32 workspaces = B_CURRENT_WORKSPACE;
archivedWindow.FindUInt32("window workspaces", 0, &workspaces);
BString url; BString url;
archivedWindow.FindString("tab", 0, &url); archivedWindow.FindString("tab", 0, &url);
BrowserWindow* window = new(std::nothrow) BrowserWindow(frame, BrowserWindow* window = new(std::nothrow) BrowserWindow(frame, fSettings, url,
fSettings, url, fContext); fContext, INTERFACE_ELEMENT_ALL, NULL, workspaces);
if (window != NULL) { if (window != NULL) {
window->Show(); window->Show();
@@ -286,9 +288,16 @@ BrowserApp::ReadyToRun()
} }
} }
} }
// If there is fLauchRefs message,
if (fLaunchRefsMessage != NULL) {
_RefsReceived(fLaunchRefsMessage, &pagesCreated, &fullscreen);
delete fLaunchRefsMessage;
fLaunchRefsMessage = NULL;
}
// If previous session did not contain any window, create a new empty one. // If previous session did not contain any window on this workspace, create a new empty one.
if (pagesCreated == 0) BrowserWindow* window = _FindWindowOnCurrentWorkspace();
if (pagesCreated == 0 || window == NULL)
_CreateNewWindow("", fullscreen); _CreateNewWindow("", fullscreen);
PostMessage(PRELOAD_BROWSING_HISTORY); PostMessage(PRELOAD_BROWSING_HISTORY);
@@ -470,6 +479,8 @@ BrowserApp::_RefsReceived(BMessage* message, int32* _pagesCreated,
bool* _fullscreen) bool* _fullscreen)
{ {
int32 pagesCreated = 0; int32 pagesCreated = 0;
if (_pagesCreated != NULL)
pagesCreated = *_pagesCreated;
BrowserWindow* window = NULL; BrowserWindow* window = NULL;
if (message->FindPointer("window", (void**)&window) != B_OK) if (message->FindPointer("window", (void**)&window) != B_OK)
@@ -506,6 +517,29 @@ BrowserApp::_RefsReceived(BMessage* message, int32* _pagesCreated,
} }
BrowserWindow*
BrowserApp::_FindWindowOnCurrentWorkspace()
{
BrowserWindow* windowOnCurrentWorkspace = NULL;
uint32 workspace = 1 << current_workspace();
for (int i = 0; BWindow* window = WindowAt(i); i++) {
BrowserWindow* webWindow = dynamic_cast<BrowserWindow*>(window);
if (webWindow == NULL)
continue;
if (webWindow->Lock()) {
if (webWindow->Workspaces() & workspace)
windowOnCurrentWorkspace = webWindow;
webWindow->Unlock();
if (windowOnCurrentWorkspace)
return windowOnCurrentWorkspace;
}
}
return NULL;
}
BrowserWindow* BrowserWindow*
BrowserApp::_CreateNewPage(const BString& url, BrowserWindow* webWindow, BrowserApp::_CreateNewPage(const BString& url, BrowserWindow* webWindow,
bool fullscreen, bool useBlankTab) bool fullscreen, bool useBlankTab)
@@ -524,30 +558,28 @@ BrowserApp::_CreateNewPage(const BString& url, BrowserWindow* webWindow,
} }
// Otherwise, try to find one in the current workspace // Otherwise, try to find one in the current workspace
uint32 workspace = 1 << current_workspace();
bool loadedInWindowOnCurrentWorkspace = false; bool loadedInWindowOnCurrentWorkspace = false;
for (int i = 0; BWindow* window = WindowAt(i); i++) { BrowserWindow* window = _FindWindowOnCurrentWorkspace();
webWindow = dynamic_cast<BrowserWindow*>(window);
if (!webWindow)
continue;
if (webWindow->Lock()) { if (window == NULL)
if (webWindow->Workspaces() & workspace) { return _CreateNewWindow(url, fullscreen);
if (useBlankTab && webWindow->IsBlankTab()) {
if (url.Length() != 0)
webWindow->CurrentWebView()->LoadURL(url); if (window->Lock()) {
} else if (useBlankTab && window->IsBlankTab()) {
webWindow->CreateNewTab(url, true); if (url.Length() != 0)
webWindow->Activate(); window->CurrentWebView()->LoadURL(url);
webWindow->CurrentWebView()->MakeFocus(true); } else {
loadedInWindowOnCurrentWorkspace = true; window->CreateNewTab(url, true);
}
webWindow->Unlock();
} }
if (loadedInWindowOnCurrentWorkspace) window->Activate();
return webWindow; window->CurrentWebView()->MakeFocus(true);
loadedInWindowOnCurrentWorkspace = true;
window->Unlock();
} }
if (loadedInWindowOnCurrentWorkspace)
return window;
// Finally, if no window is available, let's create one. // Finally, if no window is available, let's create one.
return _CreateNewWindow(url, fullscreen); return _CreateNewWindow(url, fullscreen);
+3
View File
@@ -57,6 +57,8 @@ public:
virtual bool QuitRequested(); virtual bool QuitRequested();
private: private:
/*! @param[in,out] _pagesCreated if set, the pointed integer will be incremented by the number of created pages
*/
void _RefsReceived(BMessage* message, void _RefsReceived(BMessage* message,
int32* pagesCreated = NULL, int32* pagesCreated = NULL,
bool* fullscreen = NULL); bool* fullscreen = NULL);
@@ -66,6 +68,7 @@ private:
bool useBlankTab = true); bool useBlankTab = true);
BrowserWindow* _CreateNewWindow(const BString& url, BrowserWindow* _CreateNewWindow(const BString& url,
bool fullscreen = false); bool fullscreen = false);
BrowserWindow* _FindWindowOnCurrentWorkspace();
void _CreateNewTab(BrowserWindow* window, void _CreateNewTab(BrowserWindow* window,
const BString& url, bool select); const BString& url, bool select);
void _ShowWindow(const BMessage* message, void _ShowWindow(const BMessage* message,
+11 -10
View File
@@ -345,13 +345,12 @@ private:
// #pragma mark - BrowserWindow // #pragma mark - BrowserWindow
BrowserWindow::BrowserWindow(BRect frame, SettingsMessage* appSettings, BrowserWindow::BrowserWindow(BRect frame, SettingsMessage* appSettings, const BString& url,
const BString& url, BPrivate::Network::BUrlContext* context, BPrivate::Network::BUrlContext* context, uint32 interfaceElements, BWebView* webView,
uint32 interfaceElements, BWebView* webView) uint32 workspaces)
: :
BWebWindow(frame, kApplicationName, BWebWindow(frame, kApplicationName, B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS, workspaces),
B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS),
fIsFullscreen(false), fIsFullscreen(false),
fInterfaceVisible(false), fInterfaceVisible(false),
fMenusRunning(false), fMenusRunning(false),
@@ -1239,7 +1238,9 @@ BrowserWindow::MessageReceived(BMessage* message)
status_t status_t
BrowserWindow::Archive(BMessage* archive, bool deep) const BrowserWindow::Archive(BMessage* archive, bool deep) const
{ {
status_t ret = archive->AddRect("window frame", Frame()); status_t status = archive->AddRect("window frame", Frame());
if (status == B_OK)
status = archive->AddUInt32("window workspaces", Workspaces());
for (int i = 0; i < fTabManager->CountTabs(); i++) { for (int i = 0; i < fTabManager->CountTabs(); i++) {
BWebView* view = dynamic_cast<BWebView*>(fTabManager->ViewForTab(i)); BWebView* view = dynamic_cast<BWebView*>(fTabManager->ViewForTab(i));
@@ -1247,11 +1248,11 @@ BrowserWindow::Archive(BMessage* archive, bool deep) const
continue; continue;
} }
if (ret == B_OK) if (status == B_OK)
ret = archive->AddString("tab", view->MainFrameURL()); status = archive->AddString("tab", view->MainFrameURL());
} }
return ret; return status;
} }
+3 -7
View File
@@ -97,13 +97,9 @@ enum {
class BrowserWindow : public BWebWindow { class BrowserWindow : public BWebWindow {
public: public:
BrowserWindow(BRect frame, BrowserWindow(BRect frame, SettingsMessage* appSettings, const BString& url,
SettingsMessage* appSettings, BPrivate::Network::BUrlContext* context, uint32 interfaceElements = INTERFACE_ELEMENT_ALL,
const BString& url, BWebView* webView = NULL, uint32 workspaces = B_CURRENT_WORKSPACE);
BPrivate::Network::BUrlContext* context,
uint32 interfaceElements
= INTERFACE_ELEMENT_ALL,
BWebView* webView = NULL);
virtual ~BrowserWindow(); virtual ~BrowserWindow();
virtual void DispatchMessage(BMessage* message, virtual void DispatchMessage(BMessage* message,