⛏️ index : haiku.git

author Ilmari "ilzu" Siiteri <ilzu.siiteri@gmail.com> 2025-01-20 3:39:12.0 +02:00:00
committer Adrien Destugues <pulkomandy@pulkomandy.tk> 2025-04-09 11:19:53.0 +00:00:00
commit
e3a893afd8056ffdb50a00556cf95de439d2018d [patch]
tree
98b1fe349d68608a1bf2e32078620503e46b8141
parent
197dcc80dc462995acd56e568eda9d64bcce89e2
download
e3a893afd8056ffdb50a00556cf95de439d2018d.tar.gz

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 <nep-git@packageloss.eu>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Adrien Destugues <pulkomandy@pulkomandy.tk>

Diff

 src/apps/webpositive/BrowserApp.cpp    | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------
 src/apps/webpositive/BrowserApp.h      |  3 +++
 src/apps/webpositive/BrowserWindow.cpp | 21 ++++++++++++---------
 src/apps/webpositive/BrowserWindow.h   | 10 +++-------
 4 files changed, 81 insertions(+), 49 deletions(-)

diff --git a/src/apps/webpositive/BrowserApp.cpp b/src/apps/webpositive/BrowserApp.cpp
index 11bb6a4..09aaae9 100644
--- a/src/apps/webpositive/BrowserApp.cpp
+++ b/src/apps/webpositive/BrowserApp.cpp
@@ -248,29 +248,31 @@

	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();
@@ -285,10 +287,17 @@
				}
			}
		}
	}
	// 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 @@
	bool* _fullscreen)
{
	int32 pagesCreated = 0;
	if (_pagesCreated != NULL)
		pagesCreated = *_pagesCreated;

	BrowserWindow* window = NULL;
	if (message->FindPointer("window", (void**)&window) != B_OK)
@@ -503,6 +514,29 @@
		*_pagesCreated = pagesCreated;
	if (_fullscreen != NULL)
		*_fullscreen = fullscreen;
}


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;
}


@@ -524,30 +558,28 @@
	}

	// 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);
diff --git a/src/apps/webpositive/BrowserApp.h b/src/apps/webpositive/BrowserApp.h
index 845c908..44666d3 100644
--- a/src/apps/webpositive/BrowserApp.h
+++ b/src/apps/webpositive/BrowserApp.h
@@ -57,6 +57,8 @@
	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 @@
									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,
diff --git a/src/apps/webpositive/BrowserWindow.cpp b/src/apps/webpositive/BrowserWindow.cpp
index a0c3706..04c3e2e 100644
--- a/src/apps/webpositive/BrowserWindow.cpp
+++ b/src/apps/webpositive/BrowserWindow.cpp
@@ -345,13 +345,12 @@
// #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 @@
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 @@
			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;
}


diff --git a/src/apps/webpositive/BrowserWindow.h b/src/apps/webpositive/BrowserWindow.h
index 3b5dc43..1acb815 100644
--- a/src/apps/webpositive/BrowserWindow.h
+++ b/src/apps/webpositive/BrowserWindow.h
@@ -97,13 +97,9 @@

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,