void BrowserApp::MessageReceived(BMessage* message) { switch (message->what) { case PRELOAD_BROWSING_HISTORY: // Accessing the default instance will load the history from disk. BrowsingHistory::DefaultInstance(); break; case B_SILENT_RELAUNCH: _CreateNewPage(""); break; case NEW_WINDOW: { BString url; if (message->FindString("url", &url) != B_OK) break; _CreateNewWindow(url); break; } case NEW_TAB: { BrowserWindow* window; if (message->FindPointer("window", reinterpret_cast<void**>(&window)) != B_OK) break; BString url; message->FindString("url", &url); bool select = false; message->FindBool("select", &select); _CreateNewTab(window, url, select); break; } case WINDOW_OPENED: fWindowCount++; fDownloadWindow->SetMinimizeOnClose(false); break; case WINDOW_CLOSED: fWindowCount--; message->FindRect("window frame", &fLastWindowFrame); if (fWindowCount <= 0) PostMessage(B_QUIT_REQUESTED); break; case SHOW_DOWNLOAD_WINDOW: _ShowWindow(message, fDownloadWindow); break; case SHOW_SETTINGS_WINDOW: _ShowWindow(message, fSettingsWindow); break; default: BApplication::MessageReceived(message); break; } }
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); }