diff --git a/Source/WebCore/platform/network/NetworkStorageSession.h b/Source/WebCore/platform/network/NetworkStorageSession.h index 6fb1c92bd95d..33ae12532911 100644 --- a/Source/WebCore/platform/network/NetworkStorageSession.h +++ b/Source/WebCore/platform/network/NetworkStorageSession.h @@ -42,7 +42,7 @@ #if PLATFORM(COCOA) || USE(CFURLCONNECTION) #include #elif PLATFORM(HAIKU) -class BUrlContext; +class BUrlSession; #endif #if PLATFORM(COCOA) @@ -144,8 +144,8 @@ class NetworkStorageSession : public CanMakeWeakPtr { WEBCORE_EXPORT NetworkStorageSession(PAL::SessionID); ~NetworkStorageSession(); - BUrlContext& platformSession() const; - void setPlatformSession(BUrlContext*); + BUrlSession& platformSession() const; + void setPlatformSession(BUrlSession*); #elif USE(CURL) WEBCORE_EXPORT NetworkStorageSession(PAL::SessionID); ~NetworkStorageSession(); @@ -265,7 +265,7 @@ class NetworkStorageSession : public CanMakeWeakPtr { GRefPtr m_cookieStorage; Function m_cookieObserverHandler; #elif USE(HAIKU) - BUrlContext* m_context; + BUrlSession* m_context; #elif USE(CURL) mutable UniqueRef m_cookieDatabase; #else diff --git a/Source/WebCore/platform/network/haiku/NetworkStorageSessionHaiku.cpp b/Source/WebCore/platform/network/haiku/NetworkStorageSessionHaiku.cpp index ef7f0d76cf96..4a3a96f3b0a9 100644 --- a/Source/WebCore/platform/network/haiku/NetworkStorageSessionHaiku.cpp +++ b/Source/WebCore/platform/network/haiku/NetworkStorageSessionHaiku.cpp @@ -28,7 +28,7 @@ #include "NetworkStorageSession.h" #include -#include +#include #include "Cookie.h" #include "CookieRequestHeaderFieldProxy.h" @@ -63,19 +63,19 @@ static std::unique_ptr& defaultSession() } void NetworkStorageSession::setCookiesFromDOM(const URL& firstParty, - const SameSiteInfo& sameSiteInfo, const URL& url, - WTF::Optional frameID, WTF::Optional pageID, - ShouldAskITP, const String& value, ShouldRelaxThirdPartyCookieBlocking) const + const SameSiteInfo& sameSiteInfo, const URL& url, + WTF::Optional frameID, WTF::Optional pageID, + ShouldAskITP, const String& value, ShouldRelaxThirdPartyCookieBlocking) const { - BNetworkCookie* heapCookie - = new BNetworkCookie(value, BUrl(url)); + BNetworkCookie* heapCookie + = new BNetworkCookie(value, BUrl(url)); #if TRACE_COOKIE_JAR - printf("CookieJar: Add %s for %s\n", heapCookie->RawCookie(true).String(), + printf("CookieJar: Add %s for %s\n", heapCookie->RawCookie(true).String(), url.string().utf8().data()); - printf(" from %s\n", value.utf8().data()); + printf(" from %s\n", value.utf8().data()); #endif - platformSession().GetCookieJar().AddCookie(heapCookie); + platformSession().GetCookieJar().AddCookie(heapCookie); } HTTPCookieAcceptPolicy NetworkStorageSession::cookieAcceptPolicy() const @@ -84,39 +84,39 @@ HTTPCookieAcceptPolicy NetworkStorageSession::cookieAcceptPolicy() const } std::pair NetworkStorageSession::cookiesForDOM(const URL& firstParty, - const SameSiteInfo& sameSiteInfo, const URL& url, - WTF::Optional frameID, WTF::Optional pageID, - IncludeSecureCookies includeSecureCookies, ShouldAskITP, - ShouldRelaxThirdPartyCookieBlocking) const + const SameSiteInfo& sameSiteInfo, const URL& url, + WTF::Optional frameID, WTF::Optional pageID, + IncludeSecureCookies includeSecureCookies, ShouldAskITP, + ShouldRelaxThirdPartyCookieBlocking) const { #if TRACE_COOKIE_JAR - printf("CookieJar: Request for %s\n", url.string().utf8().data()); + printf("CookieJar: Request for %s\n", url.string().utf8().data()); #endif - BString result; - BUrl hUrl(url); - bool secure = false; + BString result; + BUrl hUrl(url); + bool secure = false; - const BNetworkCookie* c; - for (BNetworkCookieJar::UrlIterator it( + const BNetworkCookie* c; + for (BNetworkCookieJar::UrlIterator it( platformSession().GetCookieJar().GetUrlIterator(hUrl)); - (c = it.Next()); ) { + (c = it.Next()); ) { // filter out httpOnly cookies,as this method is used to get cookies // from JS code and these shouldn't be visible there. if(c->HttpOnly()) - continue; + continue; - // filter out secure cookies if they should be - if (c->Secure()) - { - secure = true; + // filter out secure cookies if they should be + if (c->Secure()) + { + secure = true; if (includeSecureCookies == IncludeSecureCookies::No) - continue; - } - - result << "; " << c->RawCookie(false); - } - result.Remove(0, 2); + continue; + } + + result << "; " << c->RawCookie(false); + } + result.Remove(0, 2); return {result, secure}; } @@ -139,9 +139,9 @@ void NetworkStorageSession::deleteCookie(const Cookie&) void NetworkStorageSession::deleteCookie(const URL& url, const String& cookie) const { #if TRACE_COOKIE_JAR - printf("CookieJar: delete cookie for %s (NOT IMPLEMENTED)\n", url.string().utf8().data()); + printf("CookieJar: delete cookie for %s (NOT IMPLEMENTED)\n", url.string().utf8().data()); #endif - notImplemented(); + notImplemented(); } void NetworkStorageSession::deleteAllCookies() @@ -177,13 +177,13 @@ Vector NetworkStorageSession::getCookies(const URL&) } bool NetworkStorageSession::getRawCookies(const URL& firstParty, - const SameSiteInfo& sameSiteInfo, const URL& url, WTF::Optional frameID, - WTF::Optional pageID, ShouldAskITP, ShouldRelaxThirdPartyCookieBlocking, Vector& rawCookies) const + const SameSiteInfo& sameSiteInfo, const URL& url, WTF::Optional frameID, + WTF::Optional pageID, ShouldAskITP, ShouldRelaxThirdPartyCookieBlocking, Vector& rawCookies) const { #if TRACE_COOKIE_JAR - printf("CookieJar: get raw cookies for %s (NOT IMPLEMENTED)\n", url.string().utf8().data()); + printf("CookieJar: get raw cookies for %s (NOT IMPLEMENTED)\n", url.string().utf8().data()); #endif - notImplemented(); + notImplemented(); rawCookies.clear(); return false; // return true when implemented @@ -195,33 +195,33 @@ void NetworkStorageSession::flushCookieStore() } std::pair NetworkStorageSession::cookieRequestHeaderFieldValue(const URL& firstParty, - const SameSiteInfo& sameSiteInfo, const URL& url, WTF::Optional frameID, - WTF::Optional pageID, IncludeSecureCookies includeSecureCookies, ShouldAskITP, - ShouldRelaxThirdPartyCookieBlocking) const + const SameSiteInfo& sameSiteInfo, const URL& url, WTF::Optional frameID, + WTF::Optional pageID, IncludeSecureCookies includeSecureCookies, ShouldAskITP, + ShouldRelaxThirdPartyCookieBlocking) const { #if TRACE_COOKIE_JAR - printf("CookieJar: RequestHeaderField for %s\n", url.string().utf8().data()); + printf("CookieJar: RequestHeaderField for %s\n", url.string().utf8().data()); #endif - BString result; - BUrl hUrl(url); - bool secure = false; - - const BNetworkCookie* c; - for (BNetworkCookieJar::UrlIterator it( - platformSession().GetCookieJar().GetUrlIterator(hUrl)); - (c = it.Next()); ) { - // filter out secure cookies if they should be - if (c->Secure()) - { - secure = true; + BString result; + BUrl hUrl(url); + bool secure = false; + + const BNetworkCookie* c; + for (BNetworkCookieJar::UrlIterator it( + platformSession().GetCookieJar().GetUrlIterator(hUrl)); + (c = it.Next()); ) { + // filter out secure cookies if they should be + if (c->Secure()) + { + secure = true; if (includeSecureCookies == IncludeSecureCookies::No) - continue; - } - - result << "; " << c->RawCookie(false); - } - result.Remove(0, 2); + continue; + } + + result << "; " << c->RawCookie(false); + } + result.Remove(0, 2); return {result, secure}; } @@ -236,13 +236,17 @@ std::pair NetworkStorageSession::cookieRequestHeaderFieldValue( ShouldRelaxThirdPartyCookieBlocking::No); } -BUrlContext& NetworkStorageSession::platformSession() const +BUrlSession& NetworkStorageSession::platformSession() const { - static BUrlContext sDefaultContext; - return m_context ? *m_context : sDefaultContext; + static BUrlSession sDefaultSession; + if (sDefaultSession.InitCheck() != B_OK) { + // TODO: Handle this somehow? or just throw std::bad_alloc? + abort(); + } + return m_context ? *m_context : sDefaultSession; } -void NetworkStorageSession::setPlatformSession(BUrlContext* context) +void NetworkStorageSession::setPlatformSession(BUrlSession* context) { m_context = context; } diff --git a/Source/WebCore/platform/network/haiku/ResourceRequest.h b/Source/WebCore/platform/network/haiku/ResourceRequest.h index 115f242e793f..f61333479998 100644 --- a/Source/WebCore/platform/network/haiku/ResourceRequest.h +++ b/Source/WebCore/platform/network/haiku/ResourceRequest.h @@ -32,7 +32,7 @@ #include #include -class BUrlContext; +class BUrlSession; class BUrlRequest; namespace WebCore { @@ -60,7 +60,7 @@ namespace WebCore { { } - BUrlRequest* toNetworkRequest(BUrlContext*); + BUrlRequest* toNetworkRequest(BUrlSession*); void setCredentials(const char* username, const char* password); void updateFromDelegatePreservingOldProperties(const ResourceRequest& delegateProvidedRequest) { *this = delegateProvidedRequest; } diff --git a/Source/WebCore/platform/network/haiku/ResourceRequestHaiku.cpp b/Source/WebCore/platform/network/haiku/ResourceRequestHaiku.cpp index dc027abf23b9..3fc2eef62a30 100644 --- a/Source/WebCore/platform/network/haiku/ResourceRequestHaiku.cpp +++ b/Source/WebCore/platform/network/haiku/ResourceRequestHaiku.cpp @@ -24,7 +24,7 @@ #include "NetworkingContext.h" #include -#include +#include #include #include #include @@ -32,18 +32,20 @@ namespace WebCore { -BUrlRequest* ResourceRequest::toNetworkRequest(BUrlContext* context) +BUrlRequest* ResourceRequest::toNetworkRequest(BUrlSession* session) { - BUrlRequest* request = BUrlProtocolRoster::MakeRequest(url(), nullptr); + if (!session) { + m_url = WTF::aboutBlankURL(); + return NULL; + } + + BUrlRequest* request = session->MakeRequest(url(), nullptr); if (!request) { m_url = WTF::aboutBlankURL(); // This tells the ResourceLoader we failed. return NULL; } - if (context) - request->SetContext(context); - if (timeoutInterval() > 0) request->SetTimeout(timeoutInterval()); diff --git a/Source/WebKitLegacy/haiku/API/WebPage.cpp b/Source/WebKitLegacy/haiku/API/WebPage.cpp index 2cfb742b26dd..2f9cdbb595e0 100644 --- a/Source/WebKitLegacy/haiku/API/WebPage.cpp +++ b/Source/WebKitLegacy/haiku/API/WebPage.cpp @@ -235,12 +235,12 @@ class MediaRecorderProviderHaiku: public MediaRecorderProvider }; -BWebPage::BWebPage(BWebView* webView, BUrlContext* context) +BWebPage::BWebPage(BWebView* webView, BUrlSession* session) : BHandler("BWebPage") , fWebView(webView) , fMainFrame(NULL) , fSettings(NULL) - , fContext(context) + , fSession(session) , fPage(NULL) , fDumpRenderTree(NULL) , fLoadingProgress(100) @@ -365,9 +365,9 @@ void BWebPage::SetDownloadListener(const BMessenger& listener) sDownloadListener = listener; } -BUrlContext* BWebPage::GetContext() +BUrlSession* BWebPage::GetSession() { - return fContext; + return fSession; } void BWebPage::LoadURL(const char* urlString) diff --git a/Source/WebKitLegacy/haiku/API/WebPage.h b/Source/WebKitLegacy/haiku/API/WebPage.h index 1da36fe2613f..fcf5a94e5ded 100644 --- a/Source/WebKitLegacy/haiku/API/WebPage.h +++ b/Source/WebKitLegacy/haiku/API/WebPage.h @@ -36,7 +36,7 @@ class BNetworkCookieJar; class BRegion; -class BUrlContext; +class BUrlSession; class BView; class BWebDownload; class BWebFrame; @@ -128,7 +128,7 @@ class __attribute__ ((visibility ("default"))) BWebPage : private BHandler { friend class BWebView; friend class BPrivate::WebDownloadPrivate; - BWebPage(BWebView* webView, BUrlContext* context); + BWebPage(BWebView* webView, BUrlSession* session); // These calls are private, since they are called from the BWebView only. void setVisible(bool visible); @@ -166,7 +166,7 @@ class __attribute__ ((visibility ("default"))) BWebPage : private BHandler { bool modalDialog = false, bool resizable = true, bool activate = true); - BUrlContext* GetContext(); + BUrlSession* GetSession(); BRect windowFrame(); BRect windowBounds(); void setWindowBounds(const BRect& bounds); @@ -235,7 +235,7 @@ class __attribute__ ((visibility ("default"))) BWebPage : private BHandler { BWebView* fWebView; BWebFrame* fMainFrame; BWebSettings* fSettings; - BUrlContext* fContext; + BUrlSession* fSession; WebCore::Page* fPage; WebCore::DumpRenderTreeClient* fDumpRenderTree; diff --git a/Source/WebKitLegacy/haiku/API/WebSettings.cpp b/Source/WebKitLegacy/haiku/API/WebSettings.cpp index 5d6ef853fb11..ff294fc81ac2 100644 --- a/Source/WebKitLegacy/haiku/API/WebSettings.cpp +++ b/Source/WebKitLegacy/haiku/API/WebSettings.cpp @@ -46,7 +46,6 @@ #include #include #include -#include enum { HANDLE_SET_PERSISTENT_STORAGE_PATH = 'hspp', @@ -524,7 +523,7 @@ void BWebSettings::_HandleSetProxyInfo(BMessage* message) // TODO there could be a cleaner way of accessing the default context from here. RefPtr context = WebCore::FrameNetworkingContextHaiku::create(nullptr, nullptr); - context->context()->SetProxy(host, port); + context->session()->SetProxy(host, port); } void BWebSettings::_HandleApply() diff --git a/Source/WebKitLegacy/haiku/API/WebView.cpp b/Source/WebKitLegacy/haiku/API/WebView.cpp index c378adf4cfa6..cb0a5c4ebef4 100644 --- a/Source/WebKitLegacy/haiku/API/WebView.cpp +++ b/Source/WebKitLegacy/haiku/API/WebView.cpp @@ -62,7 +62,7 @@ BWebView::UserData::~UserData() } -BWebView::BWebView(const char* name, BUrlContext* urlContext) +BWebView::BWebView(const char* name, BUrlSession* urlSession) : BView(name, B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE | B_NAVIGABLE | B_PULSE_NEEDED) , fLastMouseButtons(0) @@ -71,7 +71,7 @@ BWebView::BWebView(const char* name, BUrlContext* urlContext) , fAutoHidePointer(false) , fOffscreenBitmap(nullptr) , fOffscreenView(nullptr) - , fWebPage(new BWebPage(this, urlContext)) + , fWebPage(new BWebPage(this, urlSession)) , fUserData(nullptr) { #if USE(TEXTURE_MAPPER) diff --git a/Source/WebKitLegacy/haiku/API/WebView.h b/Source/WebKitLegacy/haiku/API/WebView.h index ea824d616e68..cceb474baa93 100644 --- a/Source/WebKitLegacy/haiku/API/WebView.h +++ b/Source/WebKitLegacy/haiku/API/WebView.h @@ -34,7 +34,7 @@ #include -class BUrlContext; +class BUrlSession; class BWebPage; namespace WebCore { @@ -53,7 +53,7 @@ class __attribute__ ((visibility ("default"))) BWebView : public BView { }; public: - BWebView(const char* name, BUrlContext* context = nullptr); + BWebView(const char* name, BUrlSession* session = nullptr); virtual ~BWebView(); // The BWebView needs to be deleted by the BWebPage instance running diff --git a/Source/WebKitLegacy/haiku/WebCoreSupport/FrameLoaderClientHaiku.cpp b/Source/WebKitLegacy/haiku/WebCoreSupport/FrameLoaderClientHaiku.cpp index 6d1dd88e0590..b8d07049a8ef 100644 --- a/Source/WebKitLegacy/haiku/WebCoreSupport/FrameLoaderClientHaiku.cpp +++ b/Source/WebKitLegacy/haiku/WebCoreSupport/FrameLoaderClientHaiku.cpp @@ -995,7 +995,7 @@ void FrameLoaderClientHaiku::dispatchDidClearWindowObjectInWorld(DOMWrapperWorld Ref FrameLoaderClientHaiku::createNetworkingContext() { - return FrameNetworkingContextHaiku::create(m_webFrame->Frame(), m_webPage->GetContext()); + return FrameNetworkingContextHaiku::create(m_webFrame->Frame(), m_webPage->GetSession()); } // #pragma mark - private diff --git a/Source/WebKitLegacy/haiku/WebCoreSupport/FrameNetworkingContextHaiku.cpp b/Source/WebKitLegacy/haiku/WebCoreSupport/FrameNetworkingContextHaiku.cpp index 7bbd0d4f219f..8734eb0ddf18 100644 --- a/Source/WebKitLegacy/haiku/WebCoreSupport/FrameNetworkingContextHaiku.cpp +++ b/Source/WebKitLegacy/haiku/WebCoreSupport/FrameNetworkingContextHaiku.cpp @@ -36,7 +36,7 @@ #include "Page.h" #include "ResourceHandle.h" -#include +#include #include namespace WebCore { @@ -47,22 +47,22 @@ static std::unique_ptr& privateSession() return session; } -Ref FrameNetworkingContextHaiku::create(Frame* frame, BUrlContext* context) +Ref FrameNetworkingContextHaiku::create(Frame* frame, BUrlSession* session) { - return adoptRef(*new FrameNetworkingContextHaiku(frame, context)); + return adoptRef(*new FrameNetworkingContextHaiku(frame, session)); } -FrameNetworkingContextHaiku::FrameNetworkingContextHaiku(Frame* frame, BUrlContext* context) +FrameNetworkingContextHaiku::FrameNetworkingContextHaiku(Frame* frame, BUrlSession* session) : FrameNetworkingContext(frame) { - storageSession()->setPlatformSession(context); + storageSession()->setPlatformSession(session); } FrameNetworkingContextHaiku::~FrameNetworkingContextHaiku() { } -BUrlContext* FrameNetworkingContextHaiku::context() +BUrlSession* FrameNetworkingContextHaiku::session() { return &storageSession()->platformSession(); } diff --git a/Source/WebKitLegacy/haiku/WebCoreSupport/FrameNetworkingContextHaiku.h b/Source/WebKitLegacy/haiku/WebCoreSupport/FrameNetworkingContextHaiku.h index 0384eda1e09a..f630f313ac59 100644 --- a/Source/WebKitLegacy/haiku/WebCoreSupport/FrameNetworkingContextHaiku.h +++ b/Source/WebKitLegacy/haiku/WebCoreSupport/FrameNetworkingContextHaiku.h @@ -33,22 +33,22 @@ #include #include -#include +#include namespace WebCore { class FrameNetworkingContextHaiku : public WebCore::FrameNetworkingContext { public: - static Ref create(Frame*, BUrlContext* context); + static Ref create(Frame*, BUrlSession*); virtual ~FrameNetworkingContextHaiku(); WebCore::Frame* coreFrame() const { return frame(); } virtual uint64_t initiatingPageID() const; - BUrlContext* context(); + BUrlSession* session(); private: - FrameNetworkingContextHaiku(Frame*, BUrlContext* context); + FrameNetworkingContextHaiku(Frame*, BUrlSession*); WebCore::NetworkStorageSession* storageSession() const override; }; diff --git a/Source/WebKitLegacy/haiku/WebCoreSupport/NotificationClientHaiku.cpp b/Source/WebKitLegacy/haiku/WebCoreSupport/NotificationClientHaiku.cpp index 48cfc5cf1f4c..34ec1bcebbd6 100644 --- a/Source/WebKitLegacy/haiku/WebCoreSupport/NotificationClientHaiku.cpp +++ b/Source/WebKitLegacy/haiku/WebCoreSupport/NotificationClientHaiku.cpp @@ -8,6 +8,8 @@ #include "WebPage.h" +#include + namespace WebCore { BNotification @@ -27,20 +29,21 @@ NotificationClientHaiku::fromDescriptor(Notification* descriptor) // with some changes for an update. BUrl iconURL(descriptor->icon()); BMallocIO buffer; - BUrlRequest* request = BUrlProtocolRoster::MakeRequest(iconURL, &buffer); - if (request) { - thread_id thread = request->Run(); - status_t dummy; - if (thread > B_OK) - wait_for_thread(thread, &dummy); - - BBitmap* bitmap = BTranslationUtils::GetBitmap(&buffer); - if (bitmap) { - notification.SetIcon(bitmap); - delete bitmap; + BUrlSession session; + if (session.InitCheck() == B_OK) { + BUrlRequest* request = session.MakeRequest(iconURL, &buffer); + if (request) { + if (request->Run()) + request->WaitForCompletion(); + + BBitmap* bitmap = BTranslationUtils::GetBitmap(&buffer); + if (bitmap) { + notification.SetIcon(bitmap); + delete bitmap; + } + + delete request; } - - delete request; } notification.SetMessageID(descriptor->tag()); diff --git a/Source/WebKitLegacy/haiku/WebCoreSupport/NotificationClientHaiku.h b/Source/WebKitLegacy/haiku/WebCoreSupport/NotificationClientHaiku.h index b986fd17e8a1..e42fda2170ad 100644 --- a/Source/WebKitLegacy/haiku/WebCoreSupport/NotificationClientHaiku.h +++ b/Source/WebKitLegacy/haiku/WebCoreSupport/NotificationClientHaiku.h @@ -36,8 +36,7 @@ #include #include -#include -#include +#include class BWebPage; @@ -61,7 +60,7 @@ class NotificationClientHaiku: public NotificationClient { void notificationObjectDestroyed(Notification*) override {} void notificationControllerDestroyed() override {} - void requestPermission(ScriptExecutionContext*, + void requestPermission(ScriptExecutionContext*, RefPtr&& callback) override { if (callback) callback->handleEvent(NotificationPermission::Granted); @@ -74,8 +73,6 @@ class NotificationClientHaiku: public NotificationClient { } private: - class SynchronousListener; - BNotification fromDescriptor(Notification* descriptor); }; diff --git a/Tools/HaikuLauncher/LauncherApp.cpp b/Tools/HaikuLauncher/LauncherApp.cpp index ed9ae770e246..6f4a1e5e5411 100644 --- a/Tools/HaikuLauncher/LauncherApp.cpp +++ b/Tools/HaikuLauncher/LauncherApp.cpp @@ -60,7 +60,7 @@ LauncherApp::LauncherApp() LauncherApp::~LauncherApp() { - delete m_launchRefsMessage; + delete m_launchRefsMessage; } void LauncherApp::AboutRequested() @@ -72,23 +72,23 @@ void LauncherApp::AboutRequested() void LauncherApp::ArgvReceived(int32 argc, char** argv) { - for (int i = 1; i < argc; i++) { - const char* url = argv[i]; - BEntry entry(argv[i], true); - BPath path; - if (entry.Exists() && entry.GetPath(&path) == B_OK) - url = path.Path(); - BMessage message(LOAD_AT_STARTING); - message.AddString("url", url); - message.AddBool("new window", m_initialized || i > 1); - PostMessage(&message); - } + for (int i = 1; i < argc; i++) { + const char* url = argv[i]; + BEntry entry(argv[i], true); + BPath path; + if (entry.Exists() && entry.GetPath(&path) == B_OK) + url = path.Path(); + BMessage message(LOAD_AT_STARTING); + message.AddString("url", url); + message.AddBool("new window", m_initialized || i > 1); + PostMessage(&message); + } } void LauncherApp::ReadyToRun() { - // Since we will essentially run the GUI... - set_thread_priority(Thread(), B_DISPLAY_PRIORITY); + // Since we will essentially run the GUI... + set_thread_priority(Thread(), B_DISPLAY_PRIORITY); BWebPage::InitializeOnce(); BWebPage::SetCacheModel(B_WEBKIT_CACHE_MODEL_WEB_BROWSER); @@ -96,25 +96,25 @@ void LauncherApp::ReadyToRun() mkdir("localStorage", 0755); BWebSettings::SetPersistentStoragePath("localStorage"); - BFile settingsFile; - BRect windowFrameFromSettings = m_lastWindowFrame; - if (openSettingsFile(settingsFile, B_READ_ONLY)) { - BMessage settingsArchive; - settingsArchive.Unflatten(&settingsFile); - settingsArchive.FindRect("window frame", &windowFrameFromSettings); - } - m_lastWindowFrame = windowFrameFromSettings; + BFile settingsFile; + BRect windowFrameFromSettings = m_lastWindowFrame; + if (openSettingsFile(settingsFile, B_READ_ONLY)) { + BMessage settingsArchive; + settingsArchive.Unflatten(&settingsFile); + settingsArchive.FindRect("window frame", &windowFrameFromSettings); + } + m_lastWindowFrame = windowFrameFromSettings; - m_initialized = true; + m_initialized = true; - if (m_launchRefsMessage) { - RefsReceived(m_launchRefsMessage); - delete m_launchRefsMessage; - m_launchRefsMessage = 0; - } else { - LauncherWindow* window = new LauncherWindow(m_lastWindowFrame); - window->Show(); - } + if (m_launchRefsMessage) { + RefsReceived(m_launchRefsMessage); + delete m_launchRefsMessage; + m_launchRefsMessage = 0; + } else { + LauncherWindow* window = new LauncherWindow(m_lastWindowFrame, &m_session); + window->Show(); + } } void LauncherApp::MessageReceived(BMessage* message) @@ -123,68 +123,68 @@ void LauncherApp::MessageReceived(BMessage* message) case LOAD_AT_STARTING: { BString url; if (message->FindString("url", &url) != B_OK) - break; + break; bool openNewWindow = false; message->FindBool("new window", &openNewWindow); LauncherWindow* webWindow = NULL; for (int i = 0; BWindow* window = WindowAt(i); i++) { webWindow = dynamic_cast(window); if (!webWindow) - continue; + continue; if (!openNewWindow) { - // stop at the first window - break; + // stop at the first window + break; } } if (webWindow) { - // There should always be at least one window open. If not, maybe we are about - // to quit anyway... - if (openNewWindow) { - // open a new window with an offset to the last window + // There should always be at least one window open. If not, maybe we are about + // to quit anyway... + if (openNewWindow) { + // open a new window with an offset to the last window newWindow(url); - } else { - // load the URL in the first window + } else { + // load the URL in the first window webWindow->CurrentWebView()->LoadURL(url.String()); - } + } } break; } case B_SILENT_RELAUNCH: - newWindow(""); - break; + newWindow(""); + break; case NEW_WINDOW: { - BString url; - if (message->FindString("url", &url) != B_OK) - break; - newWindow(url); - break; + BString url; + if (message->FindString("url", &url) != B_OK) + break; + newWindow(url); + break; } case WINDOW_OPENED: - m_windowCount++; - break; + m_windowCount++; + break; case WINDOW_CLOSED: - m_windowCount--; + m_windowCount--; message->FindRect("window frame", &m_lastWindowFrame); - if (m_windowCount <= 0) - PostMessage(B_QUIT_REQUESTED); - break; + if (m_windowCount <= 0) + PostMessage(B_QUIT_REQUESTED); + break; - case B_SAVE_REQUESTED: - { - entry_ref dir; - message->FindRef("directory", &dir); - BString name = message->FindString("name"); + case B_SAVE_REQUESTED: + { + entry_ref dir; + message->FindRef("directory", &dir); + BString name = message->FindString("name"); BDirectory saveTo(&dir); - BFile file(&saveTo, name, - B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE); + BFile file(&saveTo, name, + B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE); - BWebPage* page = NULL; + BWebPage* page = NULL; message->FindPointer("page", (void**)&page); page->GetContentsAsMHTML(file); - break; - } + break; + } default: BApplication::MessageReceived(message); break; @@ -193,24 +193,24 @@ void LauncherApp::MessageReceived(BMessage* message) void LauncherApp::RefsReceived(BMessage* message) { - if (!m_initialized) { - delete m_launchRefsMessage; - m_launchRefsMessage = new BMessage(*message); - return; - } + if (!m_initialized) { + delete m_launchRefsMessage; + m_launchRefsMessage = new BMessage(*message); + return; + } - entry_ref ref; - for (int32 i = 0; message->FindRef("refs", i, &ref) == B_OK; i++) { - BEntry entry(&ref, true); - if (!entry.Exists()) - continue; - BPath path; - if (entry.GetPath(&path) != B_OK) - continue; - BString url; - url << path.Path(); - newWindow(url); - } + entry_ref ref; + for (int32 i = 0; message->FindRef("refs", i, &ref) == B_OK; i++) { + BEntry entry(&ref, true); + if (!entry.Exists()) + continue; + BPath path; + if (entry.GetPath(&path) != B_OK) + continue; + BString url; + url << path.Path(); + newWindow(url); + } } bool LauncherApp::QuitRequested() @@ -218,51 +218,51 @@ bool LauncherApp::QuitRequested() for (int i = 0; BWindow* window = WindowAt(i); i++) { LauncherWindow* webWindow = dynamic_cast(window); if (!webWindow) - continue; + continue; if (!webWindow->Lock()) - continue; + continue; if (webWindow->QuitRequested()) { - m_lastWindowFrame = webWindow->Frame(); + m_lastWindowFrame = webWindow->Frame(); webWindow->CurrentWebView()->Shutdown(); delete webWindow->CurrentWebView(); - webWindow->Quit(); - i--; + webWindow->Quit(); + i--; } else { - webWindow->Unlock(); - return false; + webWindow->Unlock(); + return false; } } - BFile settingsFile; - if (openSettingsFile(settingsFile, B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY)) { - BMessage settingsArchive; - settingsArchive.AddRect("window frame", m_lastWindowFrame); - settingsArchive.Flatten(&settingsFile); - } + BFile settingsFile; + if (openSettingsFile(settingsFile, B_CREATE_FILE | B_ERASE_FILE | B_WRITE_ONLY)) { + BMessage settingsArchive; + settingsArchive.AddRect("window frame", m_lastWindowFrame); + settingsArchive.Flatten(&settingsFile); + } return true; } bool LauncherApp::openSettingsFile(BFile& file, uint32 mode) { - BPath path; - if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK - || path.Append("HaikuLauncher") != B_OK) { - return false; - } - return file.SetTo(path.Path(), mode) == B_OK; + BPath path; + if (find_directory(B_USER_SETTINGS_DIRECTORY, &path) != B_OK + || path.Append("HaikuLauncher") != B_OK) { + return false; + } + return file.SetTo(path.Path(), mode) == B_OK; } void LauncherApp::newWindow(const BString& url) { - m_lastWindowFrame.OffsetBy(20, 20); - if (!BScreen().Frame().Contains(m_lastWindowFrame)) - m_lastWindowFrame.OffsetTo(50, 50); + m_lastWindowFrame.OffsetBy(20, 20); + if (!BScreen().Frame().Contains(m_lastWindowFrame)) + m_lastWindowFrame.OffsetTo(50, 50); - LauncherWindow* window = new LauncherWindow(m_lastWindowFrame); - window->Show(); - if (url.Length()) - window->CurrentWebView()->LoadURL(url.String()); + LauncherWindow* window = new LauncherWindow(m_lastWindowFrame, &m_session); + window->Show(); + if (url.Length()) + window->CurrentWebView()->LoadURL(url.String()); } // #pragma mark - diff --git a/Tools/HaikuLauncher/LauncherApp.h b/Tools/HaikuLauncher/LauncherApp.h index 7e1e37aeba94..d1e9323cf05b 100644 --- a/Tools/HaikuLauncher/LauncherApp.h +++ b/Tools/HaikuLauncher/LauncherApp.h @@ -32,6 +32,7 @@ #include #include #include +#include class BFile; class LauncherWindow; @@ -49,13 +50,15 @@ class LauncherApp : public BApplication { virtual bool QuitRequested(); private: - bool openSettingsFile(BFile& file, uint32 mode); - void newWindow(const BString& url); + bool openSettingsFile(BFile& file, uint32 mode); + void newWindow(const BString& url); int m_windowCount; BRect m_lastWindowFrame; BMessage* m_launchRefsMessage; bool m_initialized; + + BUrlSession m_session; }; extern const char* kApplicationSignature; diff --git a/Tools/HaikuLauncher/LauncherWindow.cpp b/Tools/HaikuLauncher/LauncherWindow.cpp index 9d010c01b12b..d8651e1d223c 100644 --- a/Tools/HaikuLauncher/LauncherWindow.cpp +++ b/Tools/HaikuLauncher/LauncherWindow.cpp @@ -57,9 +57,9 @@ #include enum { - OPEN_LOCATION = 'open', - OPEN_INSPECTOR = 'insp', - SAVE_PAGE = 'save', + OPEN_LOCATION = 'open', + OPEN_INSPECTOR = 'insp', + SAVE_PAGE = 'save', GO_BACK = 'goba', GO_FORWARD = 'gofo', STOP = 'stop', @@ -71,21 +71,21 @@ enum { TEXT_SIZE_RESET = 'tsrs', }; -LauncherWindow::LauncherWindow(BRect frame, ToolbarPolicy toolbarPolicy) +LauncherWindow::LauncherWindow(BRect frame, BUrlSession* session, ToolbarPolicy toolbarPolicy) : BWebWindow(frame, "HaikuLauncher", B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS) { - init(new BWebView("web view"), toolbarPolicy); + init(new BWebView("web view", session), toolbarPolicy); } LauncherWindow::LauncherWindow(BRect frame, BWebView* webView, - ToolbarPolicy toolbarPolicy) + ToolbarPolicy toolbarPolicy) : BWebWindow(frame, "HaikuLauncher", B_DOCUMENT_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL, B_AUTO_UPDATE_SIZE_LIMITS | B_ASYNCHRONOUS_CONTROLS) { - init(webView, toolbarPolicy); + init(webView, toolbarPolicy); } LauncherWindow::~LauncherWindow() @@ -95,23 +95,23 @@ LauncherWindow::~LauncherWindow() void LauncherWindow::DispatchMessage(BMessage* message, BHandler* target) { - if (m_url && message->what == B_KEY_DOWN && target == m_url->TextView()) { - // Handle B_RETURN in the URL text control. This is the easiest - // way to react *only* when the user presses the return key in the - // address bar, as opposed to trying to load whatever is in there when - // the text control just goes out of focus. - const char* bytes; - if (message->FindString("bytes", &bytes) == B_OK - && bytes[0] == B_RETURN) { - // Do it in such a way that the user sees the Go-button go down. - m_goButton->SetValue(B_CONTROL_ON); - UpdateIfNeeded(); - m_goButton->Invoke(); - snooze(1000); - m_goButton->SetValue(B_CONTROL_OFF); - } - } - BWebWindow::DispatchMessage(message, target); + if (m_url && message->what == B_KEY_DOWN && target == m_url->TextView()) { + // Handle B_RETURN in the URL text control. This is the easiest + // way to react *only* when the user presses the return key in the + // address bar, as opposed to trying to load whatever is in there when + // the text control just goes out of focus. + const char* bytes; + if (message->FindString("bytes", &bytes) == B_OK + && bytes[0] == B_RETURN) { + // Do it in such a way that the user sees the Go-button go down. + m_goButton->SetValue(B_CONTROL_ON); + UpdateIfNeeded(); + m_goButton->Invoke(); + snooze(1000); + m_goButton->SetValue(B_CONTROL_OFF); + } + } + BWebWindow::DispatchMessage(message, target); } void LauncherWindow::MessageReceived(BMessage* message) @@ -119,36 +119,36 @@ void LauncherWindow::MessageReceived(BMessage* message) switch (message->what) { case OPEN_LOCATION: if (m_url) { - if (m_url->TextView()->IsFocus()) - m_url->TextView()->SelectAll(); - else - m_url->MakeFocus(true); + if (m_url->TextView()->IsFocus()) + m_url->TextView()->SelectAll(); + else + m_url->MakeFocus(true); } - break; + break; case OPEN_INSPECTOR: { // FIXME: wouldn't the view better be in the same window? BRect frame = Frame(); frame.OffsetBy(20, 20); - LauncherWindow* inspectorWindow = new LauncherWindow(frame); + LauncherWindow* inspectorWindow = new LauncherWindow(frame, (BUrlSession*)NULL); inspectorWindow->Show(); CurrentWebView()->SetInspectorView(inspectorWindow->CurrentWebView()); break; } - case SAVE_PAGE: { - BMessage* message = new BMessage(B_SAVE_REQUESTED); - message->AddPointer("page", CurrentWebView()->WebPage()); - + case SAVE_PAGE: { + BMessage* message = new BMessage(B_SAVE_REQUESTED); + message->AddPointer("page", CurrentWebView()->WebPage()); + if (m_saveFilePanel == NULL) { - m_saveFilePanel = new BFilePanel(B_SAVE_PANEL, NULL, NULL, + m_saveFilePanel = new BFilePanel(B_SAVE_PANEL, NULL, NULL, B_DIRECTORY_NODE, false); } m_saveFilePanel->SetSaveText(CurrentWebView()->WebPage()->MainFrameTitle()); m_saveFilePanel->SetMessage(message); - m_saveFilePanel->Show(); - break; - } + m_saveFilePanel->Show(); + break; + } case RELOAD: CurrentWebView()->Reload(); @@ -156,7 +156,7 @@ void LauncherWindow::MessageReceived(BMessage* message) case GOTO_URL: { BString url; if (message->FindString("url", &url) != B_OK) - url = m_url->Text(); + url = m_url->Text(); CurrentWebView()->LoadURL(url.String()); break; } @@ -239,12 +239,12 @@ void LauncherWindow::NewWindowRequested(const BString& url, bool primaryAction) } void LauncherWindow::NewPageCreated(BWebView* view, BRect windowFrame, - bool modalDialog, bool resizable, bool activate) + bool modalDialog, bool resizable, bool activate) { - if (!windowFrame.IsValid()) - windowFrame = Frame().OffsetByCopy(10, 10); - LauncherWindow* window = new LauncherWindow(windowFrame, view, HaveToolbar); - window->Show(); + if (!windowFrame.IsValid()) + windowFrame = Frame().OffsetByCopy(10, 10); + LauncherWindow* window = new LauncherWindow(windowFrame, view, HaveToolbar); + window->Show(); } void LauncherWindow::LoadNegotiating(const BString& url, BWebView* view) @@ -256,7 +256,7 @@ void LauncherWindow::LoadNegotiating(const BString& url, BWebView* view) void LauncherWindow::LoadCommitted(const BString& url, BWebView* view) { - // This hook is invoked when the load is commited. + // This hook is invoked when the load is commited. if (m_url) m_url->SetText(url.String()); @@ -343,21 +343,21 @@ void LauncherWindow::NavigationCapabilitiesChanged(bool canGoBackward, bool LauncherWindow::AuthenticationChallenge(BString message, BString& inOutUser, - BString& inOutPassword, bool& inOutRememberCredentials, - uint32 failureCount, BWebView* view) + BString& inOutPassword, bool& inOutRememberCredentials, + uint32 failureCount, BWebView* view) { - AuthenticationPanel* panel = new AuthenticationPanel(Frame()); - // Panel auto-destructs. - bool success = panel->getAuthentication(message, inOutUser, inOutPassword, - inOutRememberCredentials, failureCount > 0, inOutUser, inOutPassword, - &inOutRememberCredentials); - return success; + AuthenticationPanel* panel = new AuthenticationPanel(Frame()); + // Panel auto-destructs. + bool success = panel->getAuthentication(message, inOutUser, inOutPassword, + inOutRememberCredentials, failureCount > 0, inOutUser, inOutPassword, + &inOutRememberCredentials); + return success; } void LauncherWindow::init(BWebView* webView, ToolbarPolicy toolbarPolicy) { - SetCurrentWebView(webView); + SetCurrentWebView(webView); if (toolbarPolicy == HaveToolbar) { // Menu @@ -370,7 +370,7 @@ void LauncherWindow::init(BWebView* webView, ToolbarPolicy toolbarPolicy) newItem->SetTarget(be_app); menu->AddItem(new BMenuItem("Open location", new BMessage(OPEN_LOCATION), 'L')); menu->AddItem(new BMenuItem("Inspect page", new BMessage(OPEN_INSPECTOR), 'I')); - menu->AddItem(new BMenuItem("Save page", new BMessage(SAVE_PAGE), 'S')); + menu->AddItem(new BMenuItem("Save page", new BMessage(SAVE_PAGE), 'S')); menu->AddSeparatorItem(); menu->AddItem(new BMenuItem("Close", new BMessage(B_QUIT_REQUESTED), 'W', B_SHIFT_KEY)); BMenuItem* quitItem = new BMenuItem("Quit", new BMessage(B_QUIT_REQUESTED), 'Q'); diff --git a/Tools/HaikuLauncher/LauncherWindow.h b/Tools/HaikuLauncher/LauncherWindow.h index 45e6738747c7..243827212038 100644 --- a/Tools/HaikuLauncher/LauncherWindow.h +++ b/Tools/HaikuLauncher/LauncherWindow.h @@ -43,6 +43,7 @@ class BStatusBar; class BStringView; class BTextControl; class BWebView; +class BUrlSession; enum ToolbarPolicy { HaveToolbar, @@ -57,7 +58,7 @@ enum { class LauncherWindow : public BWebWindow { public: - LauncherWindow(BRect frame, ToolbarPolicy = HaveToolbar); + LauncherWindow(BRect frame, BUrlSession*, ToolbarPolicy = HaveToolbar); LauncherWindow(BRect frame, BWebView* view, ToolbarPolicy = HaveToolbar); virtual ~LauncherWindow();