void BrowserApp::ReadyToRun() { // Since we will essentially run the GUI... set_thread_priority(Thread(), B_DISPLAY_PRIORITY); BWebPage::InitializeOnce(); BWebPage::SetCacheModel(B_WEBKIT_CACHE_MODEL_WEB_BROWSER); BPath path; if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK && path.Append(kApplicationName) == B_OK && create_directory(path.Path(), 0777) == B_OK) { BWebSettings::SetPersistentStoragePath(path.Path()); } BString mainSettingsPath(kApplicationName); mainSettingsPath << "/Application"; fSettings = new SettingsMessage(B_USER_SETTINGS_DIRECTORY, mainSettingsPath.String()); #if ENABLE_NATIVE_COOKIES mainSettingsPath = kApplicationName; mainSettingsPath << "/Cookies"; fCookies = new SettingsMessage(B_USER_SETTINGS_DIRECTORY, mainSettingsPath.String()); BMessage cookieArchive; cookieArchive = fCookies->GetValue("cookies", cookieArchive); fCookieJar = new BNetworkCookieJar(cookieArchive); BWebPage::SetCookieJar(fCookieJar); #endif fLastWindowFrame = fSettings->GetValue("window frame", fLastWindowFrame); BRect defaultDownloadWindowFrame(-10, -10, 365, 265); BRect downloadWindowFrame = fSettings->GetValue("downloads window frame", defaultDownloadWindowFrame); BRect settingsWindowFrame = fSettings->GetValue("settings window frame", BRect()); bool showDownloads = fSettings->GetValue("show downloads", false); fDownloadWindow = new DownloadWindow(downloadWindowFrame, showDownloads, fSettings); if (downloadWindowFrame == defaultDownloadWindowFrame) { // Initially put download window in lower right of screen. BRect screenFrame = BScreen().Frame(); BMessage decoratorSettings; fDownloadWindow->GetDecoratorSettings(&decoratorSettings); float borderWidth = 0; if (decoratorSettings.FindFloat("border width", &borderWidth) != B_OK) borderWidth = 5; fDownloadWindow->MoveTo(screenFrame.Width() - fDownloadWindow->Frame().Width() - borderWidth, screenFrame.Height() - fDownloadWindow->Frame().Height() - borderWidth); } fSettingsWindow = new SettingsWindow(settingsWindowFrame, fSettings); BWebPage::SetDownloadListener(BMessenger(fDownloadWindow)); fInitialized = true; int32 pagesCreated = 0; bool fullscreen = false; if (fLaunchRefsMessage) { _RefsReceived(fLaunchRefsMessage, &pagesCreated, &fullscreen); delete fLaunchRefsMessage; fLaunchRefsMessage = NULL; } if (pagesCreated == 0) _CreateNewWindow("", fullscreen); PostMessage(PRELOAD_BROWSING_HISTORY); }
void BrowserApp::ReadyToRun() { // Since we will essentially run the GUI... set_thread_priority(Thread(), B_DISPLAY_PRIORITY); BWebPage::InitializeOnce(); BWebPage::SetCacheModel(B_WEBKIT_CACHE_MODEL_WEB_BROWSER); BPath path; if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) == B_OK && path.Append(kApplicationName) == B_OK && create_directory(path.Path(), 0777) == B_OK) { BWebSettings::SetPersistentStoragePath(path.Path()); } BString mainSettingsPath(kApplicationName); mainSettingsPath << "/Application"; fSettings = new SettingsMessage(B_USER_SETTINGS_DIRECTORY, mainSettingsPath.String()); fLastWindowFrame = fSettings->GetValue("window frame", fLastWindowFrame); BRect defaultDownloadWindowFrame(-10, -10, 365, 265); BRect downloadWindowFrame = fSettings->GetValue("downloads window frame", defaultDownloadWindowFrame); BRect settingsWindowFrame = fSettings->GetValue("settings window frame", BRect()); BRect consoleWindowFrame = fSettings->GetValue("console window frame", BRect(50, 50, 400, 300)); BRect cookieWindowFrame = fSettings->GetValue("cookie window frame", BRect(50, 50, 400, 300)); bool showDownloads = fSettings->GetValue("show downloads", false); fDownloadWindow = new DownloadWindow(downloadWindowFrame, showDownloads, fSettings); if (downloadWindowFrame == defaultDownloadWindowFrame) { // Initially put download window in lower right of screen. BRect screenFrame = BScreen().Frame(); BMessage decoratorSettings; fDownloadWindow->GetDecoratorSettings(&decoratorSettings); float borderWidth = 0; if (decoratorSettings.FindFloat("border width", &borderWidth) != B_OK) borderWidth = 5; fDownloadWindow->MoveTo(screenFrame.Width() - fDownloadWindow->Frame().Width() - borderWidth, screenFrame.Height() - fDownloadWindow->Frame().Height() - borderWidth); } fSettingsWindow = new SettingsWindow(settingsWindowFrame, fSettings); BWebPage::SetDownloadListener(BMessenger(fDownloadWindow)); fConsoleWindow = new ConsoleWindow(consoleWindowFrame); fCookieWindow = new CookieWindow(cookieWindowFrame, fContext->GetCookieJar()); fInitialized = true; 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) { const char* kSettingsKeyStartUpPolicy = "start up policy"; uint32 fStartUpPolicy = fSettings->GetValue(kSettingsKeyStartUpPolicy, (uint32)ResumePriorSession); if (fStartUpPolicy == StartNewSession) { 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"); BString url; archivedWindow.FindString("tab", 0, &url); BrowserWindow* window = new(std::nothrow) BrowserWindow(frame, fSettings, url, fContext); if (window != NULL) { window->Show(); pagesCreated++; for (int j = 1; archivedWindow.FindString("tab", j, &url) == B_OK; j++) { printf("Create %d:%d\n", i, j); _CreateNewTab(window, url, false); pagesCreated++; } } } } } // If previous session did not contain any window, create a new empty one. if (pagesCreated == 0) _CreateNewWindow("", fullscreen); PostMessage(PRELOAD_BROWSING_HISTORY); }