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;
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
if (fSession->InitCheck() == B_OK && pagesCreated == 0) {
// Handle startup session / page
if (fSession->InitCheck() == B_OK) {
const char* kSettingsKeyStartUpPolicy = "start up policy";
uint32 fStartUpPolicy = fSettings->GetValue(kSettingsKeyStartUpPolicy,
(uint32)ResumePriorSession);
// If requested not to load previous session
if (fStartUpPolicy == StartNewSession) {
PostMessage(NEW_WINDOW);
// Check if lauchrefs will open a page
if (fLaunchRefsMessage == NULL) {
// else open new window
PostMessage(NEW_WINDOW);
}
} else {
// otherwise, restore previous session
BMessage archivedWindow;
for (int i = 0; fSession->FindMessage("window", i, &archivedWindow)
== B_OK; i++) {
BRect frame = archivedWindow.FindRect("window frame");
uint32 workspaces = B_CURRENT_WORKSPACE;
archivedWindow.FindUInt32("window workspaces", 0, &workspaces);
BString url;
archivedWindow.FindString("tab", 0, &url);
BrowserWindow* window = new(std::nothrow) BrowserWindow(frame,
fSettings, url, fContext);
BrowserWindow* window = new(std::nothrow) BrowserWindow(frame, fSettings, url,
fContext, INTERFACE_ELEMENT_ALL, NULL, workspaces);
if (window != NULL) {
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 (pagesCreated == 0)
// If previous session did not contain any window on this workspace, create a new empty one.
BrowserWindow* window = _FindWindowOnCurrentWorkspace();
if (pagesCreated == 0 || window == NULL)
_CreateNewWindow("", fullscreen);
PostMessage(PRELOAD_BROWSING_HISTORY);
@@ -470,6 +479,8 @@ BrowserApp::_RefsReceived(BMessage* message, int32* _pagesCreated,
bool* _fullscreen)
{
int32 pagesCreated = 0;
if (_pagesCreated != NULL)
pagesCreated = *_pagesCreated;
BrowserWindow* window = NULL;
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*
BrowserApp::_CreateNewPage(const BString& url, BrowserWindow* webWindow,
bool fullscreen, bool useBlankTab)
@@ -524,30 +558,28 @@ BrowserApp::_CreateNewPage(const BString& url, BrowserWindow* webWindow,
}
// Otherwise, try to find one in the current workspace
uint32 workspace = 1 << current_workspace();
bool loadedInWindowOnCurrentWorkspace = false;
for (int i = 0; BWindow* window = WindowAt(i); i++) {
webWindow = dynamic_cast<BrowserWindow*>(window);
if (!webWindow)
continue;
BrowserWindow* window = _FindWindowOnCurrentWorkspace();
if (webWindow->Lock()) {
if (webWindow->Workspaces() & workspace) {
if (useBlankTab && webWindow->IsBlankTab()) {
if (url.Length() != 0)
webWindow->CurrentWebView()->LoadURL(url);
} else
webWindow->CreateNewTab(url, true);
webWindow->Activate();
webWindow->CurrentWebView()->MakeFocus(true);
loadedInWindowOnCurrentWorkspace = true;
}
webWindow->Unlock();
if (window == NULL)
return _CreateNewWindow(url, fullscreen);
if (window->Lock()) {
if (useBlankTab && window->IsBlankTab()) {
if (url.Length() != 0)
window->CurrentWebView()->LoadURL(url);
} else {
window->CreateNewTab(url, true);
}
if (loadedInWindowOnCurrentWorkspace)
return webWindow;
window->Activate();
window->CurrentWebView()->MakeFocus(true);
loadedInWindowOnCurrentWorkspace = true;
window->Unlock();
}
if (loadedInWindowOnCurrentWorkspace)
return window;
// Finally, if no window is available, let's create one.
return _CreateNewWindow(url, fullscreen);
+3
View File
@@ -57,6 +57,8 @@ public:
virtual bool QuitRequested();
private:
/*! @param[in,out] _pagesCreated if set, the pointed integer will be incremented by the number of created pages
*/
void _RefsReceived(BMessage* message,
int32* pagesCreated = NULL,
bool* fullscreen = NULL);
@@ -66,6 +68,7 @@ private:
bool useBlankTab = true);
BrowserWindow* _CreateNewWindow(const BString& url,
bool fullscreen = false);
BrowserWindow* _FindWindowOnCurrentWorkspace();
void _CreateNewTab(BrowserWindow* window,
const BString& url, bool select);
void _ShowWindow(const BMessage* message,
+11 -10
View File
@@ -345,13 +345,12 @@ private:
// #pragma mark - BrowserWindow
BrowserWindow::BrowserWindow(BRect frame, SettingsMessage* appSettings,
const BString& url, BPrivate::Network::BUrlContext* context,
uint32 interfaceElements, BWebView* webView)
BrowserWindow::BrowserWindow(BRect frame, SettingsMessage* appSettings, const BString& url,
BPrivate::Network::BUrlContext* context, uint32 interfaceElements, BWebView* webView,
uint32 workspaces)
:
BWebWindow(frame, kApplicationName,
B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS),
BWebWindow(frame, kApplicationName, B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,
B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS, workspaces),
fIsFullscreen(false),
fInterfaceVisible(false),
fMenusRunning(false),
@@ -1239,7 +1238,9 @@ BrowserWindow::MessageReceived(BMessage* message)
status_t
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++) {
BWebView* view = dynamic_cast<BWebView*>(fTabManager->ViewForTab(i));
@@ -1247,11 +1248,11 @@ BrowserWindow::Archive(BMessage* archive, bool deep) const
continue;
}
if (ret == B_OK)
ret = archive->AddString("tab", view->MainFrameURL());
if (status == B_OK)
status = archive->AddString("tab", view->MainFrameURL());
}
return ret;
return status;
}
+3 -7
View File
@@ -97,13 +97,9 @@ enum {
class BrowserWindow : public BWebWindow {
public:
BrowserWindow(BRect frame,
SettingsMessage* appSettings,
const BString& url,
BPrivate::Network::BUrlContext* context,
uint32 interfaceElements
= INTERFACE_ELEMENT_ALL,
BWebView* webView = NULL);
BrowserWindow(BRect frame, SettingsMessage* appSettings, const BString& url,
BPrivate::Network::BUrlContext* context, uint32 interfaceElements = INTERFACE_ELEMENT_ALL,
BWebView* webView = NULL, uint32 workspaces = B_CURRENT_WORKSPACE);
virtual ~BrowserWindow();
virtual void DispatchMessage(BMessage* message,