void BrowserApp::_CreateNewPage(const BString& url, bool fullscreen) { uint32 workspace = 1 << current_workspace(); bool loadedInWindowOnCurrentWorkspace = false; for (int i = 0; BWindow* window = WindowAt(i); i++) { BrowserWindow* webWindow = dynamic_cast<BrowserWindow*>(window); if (!webWindow) continue; if (webWindow->Lock()) { if (webWindow->Workspaces() & workspace) { if (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 (loadedInWindowOnCurrentWorkspace) return; } _CreateNewWindow(url, fullscreen); }
bool BrowserApp::QuitRequested() { if (fDownloadWindow->DownloadsInProgress()) { BAlert* alert = new BAlert(B_TRANSLATE("Downloads in progress"), B_TRANSLATE("There are still downloads in progress, do you really " "want to quit WebPositive now?"), B_TRANSLATE("Quit"), B_TRANSLATE("Continue downloads")); int32 choice = alert->Go(); if (choice == 1) { if (fWindowCount == 0) { if (fDownloadWindow->Lock()) { fDownloadWindow->SetWorkspaces(1 << current_workspace()); if (fDownloadWindow->IsHidden()) fDownloadWindow->Show(); else fDownloadWindow->Activate(); fDownloadWindow->SetMinimizeOnClose(true); fDownloadWindow->Unlock(); return false; } } else return false; } } for (int i = 0; BWindow* window = WindowAt(i); i++) { BrowserWindow* webWindow = dynamic_cast<BrowserWindow*>(window); if (!webWindow) continue; if (!webWindow->Lock()) continue; if (webWindow->QuitRequested()) { fLastWindowFrame = webWindow->WindowFrame(); webWindow->Quit(); i--; } else { webWindow->Unlock(); return false; } } BWebPage::ShutdownOnce(); fSettings->SetValue("window frame", fLastWindowFrame); if (fDownloadWindow->Lock()) { fSettings->SetValue("downloads window frame", fDownloadWindow->Frame()); fSettings->SetValue("show downloads", !fDownloadWindow->IsHidden()); fDownloadWindow->Unlock(); } if (fSettingsWindow->Lock()) { fSettings->SetValue("settings window frame", fSettingsWindow->Frame()); fSettingsWindow->Unlock(); } BMessage cookieArchive; if (fCookieJar != NULL && fCookieJar->Archive(&cookieArchive) == B_OK) fCookies->SetValue("cookies", cookieArchive); return true; }
bool BrowserApp::QuitRequested() { if (fDownloadWindow->DownloadsInProgress()) { BAlert* alert = new BAlert(B_TRANSLATE("Downloads in progress"), B_TRANSLATE("There are still downloads in progress, do you really " "want to quit WebPositive now?"), B_TRANSLATE("Quit"), B_TRANSLATE("Continue downloads")); int32 choice = alert->Go(); if (choice == 1) { if (fWindowCount == 0) { if (fDownloadWindow->Lock()) { fDownloadWindow->SetWorkspaces(1 << current_workspace()); if (fDownloadWindow->IsHidden()) fDownloadWindow->Show(); else fDownloadWindow->Activate(); fDownloadWindow->SetMinimizeOnClose(true); fDownloadWindow->Unlock(); return false; } } else return false; } } fSession->MakeEmpty(); /* See if we got here because the last window is already closed. * In that case we only need to save that one, which is already archived */ BMessage* message = CurrentMessage(); BMessage windowMessage; status_t ret = message->FindMessage("window", &windowMessage); if (ret == B_OK) { fSession->AddMessage("window", &windowMessage); } else { for (int i = 0; BWindow* window = WindowAt(i); i++) { BrowserWindow* webWindow = dynamic_cast<BrowserWindow*>(window); if (!webWindow) continue; if (!webWindow->Lock()) continue; BMessage windowArchive; webWindow->Archive(&windowArchive, true); fSession->AddMessage("window", &windowArchive); if (webWindow->QuitRequested()) { fLastWindowFrame = webWindow->WindowFrame(); webWindow->Quit(); i--; } else { webWindow->Unlock(); return false; } } } BWebPage::ShutdownOnce(); fSettings->SetValue("window frame", fLastWindowFrame); if (fDownloadWindow->Lock()) { fSettings->SetValue("downloads window frame", fDownloadWindow->Frame()); fSettings->SetValue("show downloads", !fDownloadWindow->IsHidden()); fDownloadWindow->Unlock(); } if (fSettingsWindow->Lock()) { fSettings->SetValue("settings window frame", fSettingsWindow->Frame()); fSettingsWindow->Unlock(); } if (fConsoleWindow->Lock()) { fSettings->SetValue("console window frame", fConsoleWindow->Frame()); fConsoleWindow->Unlock(); } if (fCookieWindow->Lock()) { fSettings->SetValue("cookie window frame", fCookieWindow->Frame()); fCookieWindow->Unlock(); } BMessage cookieArchive; BNetworkCookieJar& cookieJar = fContext->GetCookieJar(); cookieJar.PurgeForExit(); if (cookieJar.Archive(&cookieArchive) == B_OK) fCookies->SetValue("cookies", cookieArchive); return true; }