Skip to content

Preliminary work on the switch to BUrlSession #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Source/WebCore/platform/network/NetworkStorageSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#if PLATFORM(COCOA) || USE(CFURLCONNECTION)
#include <wtf/RetainPtr.h>
#elif PLATFORM(HAIKU)
class BUrlContext;
class BUrlSession;
#endif

#if PLATFORM(COCOA)
Expand Down Expand Up @@ -144,8 +144,8 @@ class NetworkStorageSession : public CanMakeWeakPtr<NetworkStorageSession> {
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();
Expand Down Expand Up @@ -265,7 +265,7 @@ class NetworkStorageSession : public CanMakeWeakPtr<NetworkStorageSession> {
GRefPtr<SoupCookieJar> m_cookieStorage;
Function<void ()> m_cookieObserverHandler;
#elif USE(HAIKU)
BUrlContext* m_context;
BUrlSession* m_context;
#elif USE(CURL)
mutable UniqueRef<CookieJarDB> m_cookieDatabase;
#else
Expand Down
130 changes: 67 additions & 63 deletions Source/WebCore/platform/network/haiku/NetworkStorageSessionHaiku.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "NetworkStorageSession.h"

#include <support/Locker.h>
#include <UrlContext.h>
#include <UrlSession.h>

#include "Cookie.h"
#include "CookieRequestHeaderFieldProxy.h"
Expand Down Expand Up @@ -63,19 +63,19 @@ static std::unique_ptr<NetworkStorageSession>& defaultSession()
}

void NetworkStorageSession::setCookiesFromDOM(const URL& firstParty,
const SameSiteInfo& sameSiteInfo, const URL& url,
WTF::Optional<FrameIdentifier> frameID, WTF::Optional<PageIdentifier> pageID,
ShouldAskITP, const String& value, ShouldRelaxThirdPartyCookieBlocking) const
const SameSiteInfo& sameSiteInfo, const URL& url,
WTF::Optional<FrameIdentifier> frameID, WTF::Optional<PageIdentifier> 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
Expand All @@ -84,39 +84,39 @@ HTTPCookieAcceptPolicy NetworkStorageSession::cookieAcceptPolicy() const
}

std::pair<String, bool> NetworkStorageSession::cookiesForDOM(const URL& firstParty,
const SameSiteInfo& sameSiteInfo, const URL& url,
WTF::Optional<FrameIdentifier> frameID, WTF::Optional<PageIdentifier> pageID,
IncludeSecureCookies includeSecureCookies, ShouldAskITP,
ShouldRelaxThirdPartyCookieBlocking) const
const SameSiteInfo& sameSiteInfo, const URL& url,
WTF::Optional<FrameIdentifier> frameID, WTF::Optional<PageIdentifier> 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};
}
Expand All @@ -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()
Expand Down Expand Up @@ -177,13 +177,13 @@ Vector<Cookie> NetworkStorageSession::getCookies(const URL&)
}

bool NetworkStorageSession::getRawCookies(const URL& firstParty,
const SameSiteInfo& sameSiteInfo, const URL& url, WTF::Optional<FrameIdentifier> frameID,
WTF::Optional<PageIdentifier> pageID, ShouldAskITP, ShouldRelaxThirdPartyCookieBlocking, Vector<Cookie>& rawCookies) const
const SameSiteInfo& sameSiteInfo, const URL& url, WTF::Optional<FrameIdentifier> frameID,
WTF::Optional<PageIdentifier> pageID, ShouldAskITP, ShouldRelaxThirdPartyCookieBlocking, Vector<Cookie>& 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
Expand All @@ -195,33 +195,33 @@ void NetworkStorageSession::flushCookieStore()
}

std::pair<String, bool> NetworkStorageSession::cookieRequestHeaderFieldValue(const URL& firstParty,
const SameSiteInfo& sameSiteInfo, const URL& url, WTF::Optional<FrameIdentifier> frameID,
WTF::Optional<PageIdentifier> pageID, IncludeSecureCookies includeSecureCookies, ShouldAskITP,
ShouldRelaxThirdPartyCookieBlocking) const
const SameSiteInfo& sameSiteInfo, const URL& url, WTF::Optional<FrameIdentifier> frameID,
WTF::Optional<PageIdentifier> 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};
}
Expand All @@ -236,13 +236,17 @@ std::pair<String, bool> 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;
}
Expand Down
4 changes: 2 additions & 2 deletions Source/WebCore/platform/network/haiku/ResourceRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include <String.h>
#include <Referenceable.h>

class BUrlContext;
class BUrlSession;
class BUrlRequest;

namespace WebCore {
Expand Down Expand Up @@ -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; }
Expand Down
14 changes: 8 additions & 6 deletions Source/WebCore/platform/network/haiku/ResourceRequestHaiku.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,28 @@
#include "NetworkingContext.h"

#include <support/Locker.h>
#include <UrlProtocolRoster.h>
#include <UrlSession.h>
#include <UrlRequest.h>
#include <HttpRequest.h>
#include <LocaleRoster.h>
#include <wtf/text/CString.h>

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());

Expand Down
8 changes: 4 additions & 4 deletions Source/WebKitLegacy/haiku/API/WebPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions Source/WebKitLegacy/haiku/API/WebPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

class BNetworkCookieJar;
class BRegion;
class BUrlContext;
class BUrlSession;
class BView;
class BWebDownload;
class BWebFrame;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand Down
3 changes: 1 addition & 2 deletions Source/WebKitLegacy/haiku/API/WebSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
#include <Font.h>
#include <Path.h>
#include <stdio.h>
#include <UrlContext.h>

enum {
HANDLE_SET_PERSISTENT_STORAGE_PATH = 'hspp',
Expand Down Expand Up @@ -524,7 +523,7 @@ void BWebSettings::_HandleSetProxyInfo(BMessage* message)
// TODO there could be a cleaner way of accessing the default context from here.
RefPtr<WebCore::FrameNetworkingContextHaiku> context
= WebCore::FrameNetworkingContextHaiku::create(nullptr, nullptr);
context->context()->SetProxy(host, port);
context->session()->SetProxy(host, port);
}

void BWebSettings::_HandleApply()
Expand Down
4 changes: 2 additions & 2 deletions Source/WebKitLegacy/haiku/API/WebView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Loading