Skip to content
Permalink
Browse files

Widget and shared memory

1) Few callbacks for finished loading and forward and backward stop etc is now fully functional
2) status text is partially done
3)shared memory done with mapping part pending(i need to understand a little bit more)
  • Loading branch information...
RAJAGOPALAN-GANGADHARAN authored and pulkomandy committed Jun 14, 2019
1 parent 0467072 commit e5c14d2f67dfe92f0f7edf85b86133daaa1cdee5
@@ -60,11 +60,14 @@ namespace IPC{
};
void Connection::finalizeConnection(BMessage* message)
{

//unwrap the message
status_t result = message->FindMessenger("target",&targetMessenger);
if(result == B_OK)
m_isConnected = true;

m_connectionQueue->dispatch([protectedThis = makeRef(*this)]() mutable {
protectedThis->sendOutgoingMessages();
});
}
void Connection::platformInitialize(Identifier identifier)
{
@@ -137,7 +140,7 @@ namespace IPC{
}
bool Connection::platformCanSendOutgoingMessages() const
{
return !m_pendingWriteEncoder;
return true;
}
bool Connection::sendOutgoingMessage(std::unique_ptr<Encoder> encoder)
{
@@ -34,30 +34,53 @@
namespace WebKit {

SharedMemory::Handle::Handle()
{
:m_areaid(0),
m_size(0)
{fprintf(stderr,"%s \n",__PRETTY_FUNCTION__);
}

SharedMemory::Handle::~Handle()
{
clear();
}

SharedMemory::Handle::Handle(Handle&&) = default;
SharedMemory::Handle& SharedMemory::Handle::operator=(Handle&& other) = default;

void SharedMemory::Handle::clear()
{
if(!m_areaid)
return;

delete_area(m_areaid);
m_areaid = 0;
}

bool SharedMemory::Handle::isNull() const
{
return !m_areaid;
}

void SharedMemory::Handle::encode(IPC::Encoder& encoder) const
{
{fprintf(stderr,"%s \n",__PRETTY_FUNCTION__);
encoder << (uint64_t)m_size;
encoder << (int64_t)m_areaid;
}

bool SharedMemory::Handle::decode(IPC::Decoder& decoder, Handle& handle)
{
{fprintf(stderr,"%s \n",__PRETTY_FUNCTION__);
uint64_t size;
if(!decoder.decode(size))
return false;

int64_t areaid;
if(!decoder.decode(areaid))
return false;

handle.m_areaid = (area_id)areaid;
handle.m_size = size;

return true;
}

static uint32 protectionMode(SharedMemory::Protection protection)
@@ -74,36 +97,59 @@ static uint32 protectionMode(SharedMemory::Protection protection)
RefPtr<SharedMemory> SharedMemory::allocate(size_t size)
{
void* baseAddress;
fprintf(stderr,"%s %ld\n",__PRETTY_FUNCTION__,size);
//size = ROUND_UP_TO_PAGE(size); if its not a multiple of a page then do this

area_id sharedArea = create_area("WebKit-Shared-Memory",&baseAddress,B_ANY_ADDRESS,
size,B_NO_LOCK,B_READ_AREA | B_WRITE_AREA);

if(sharedArea<0)
return nullptr;

fprintf(stderr,"%s %ld\n",__PRETTY_FUNCTION__,size);
RefPtr<SharedMemory> memory = adoptRef(new SharedMemory);
memory->m_size = size;
memory->m_data = baseAddress;
memory->m_areaid = sharedArea;

return memory;
}

RefPtr<SharedMemory> SharedMemory::map(const Handle& handle, Protection protection)
{

{fprintf(stderr,"%s \n",__PRETTY_FUNCTION__);//not completed
RefPtr<SharedMemory> memory = adopt(handle.m_areaid, handle.m_size, protection);
if(!memory)
return nullptr;

handle.m_areaid = 0;
return memory;
}

RefPtr<SharedMemory> SharedMemory::adopt(area_id area, size_t size, Protection protection)
{
{fprintf(stderr,"%s \n",__PRETTY_FUNCTION__);
//not completed
if(!area)
return nullptr;

void* baseAddress;

area_id clonedArea = clone_area("WebKit-Shared-Memory",&baseAddress,B_CLONE_ADDRESS,
protectionMode(protection),area);

RefPtr<SharedMemory> memory = adoptRef(new SharedMemory);
memory->m_size = size;
memory->m_data = baseAddress;
memory->m_areaid = clonedArea;

return memory;
}

SharedMemory::~SharedMemory()
{
delete_area(m_areaid);
m_areaid = 0;
}

bool SharedMemory::createHandle(Handle& handle, Protection)
{
{fprintf(stderr,"%s \n",__PRETTY_FUNCTION__);
//todo
}

unsigned SharedMemory::systemPageSize()
@@ -83,27 +83,27 @@ bool SharedStringHashTableReadOnly::contains(SharedStringHash sharedStringHash)
}

SharedStringHash* SharedStringHashTableReadOnly::findSlot(SharedStringHash sharedStringHash) const
{
{fprintf(stderr,"\n %s place1 \n",__PRETTY_FUNCTION__);
if (!m_sharedMemory)
return nullptr;

fprintf(stderr,"\n %s place2 \n",__PRETTY_FUNCTION__);
int k = 0;
SharedStringHash* table = m_table;
int sizeMask = m_tableSizeMask;
unsigned h = static_cast<unsigned>(sharedStringHash);
int i = h & sizeMask;

SharedStringHash* entry;
fprintf(stderr,"\n %s place3 \n",__PRETTY_FUNCTION__);
SharedStringHash* entry;fprintf(stderr,"\n %s place1 \n",__PRETTY_FUNCTION__);
while (1) {
entry = table + i;

fprintf(stderr,"\n %s place4 %d %d %d\n",__PRETTY_FUNCTION__,i,h,sizeMask);
// Check if we've reached the end of the table.
if (!*entry)
return entry;

fprintf(stderr,"\n %s place5 \n",__PRETTY_FUNCTION__);
if (*entry == sharedStringHash)
return entry;

fprintf(stderr,"\n %s place6 \n",__PRETTY_FUNCTION__);
if (!k)
k = 1 | doubleHash(h);
i = (i + k) & sizeMask;
@@ -25,6 +25,7 @@

#include <Window.h>
#include <View.h>
#include <Looper.h>


#include "WKPageConfigurationRef.h"
@@ -34,10 +35,14 @@
#include "WKString.h"
#include "WKContext.h"
#include "WKPreferencesRef.h"
#include "WKPageNavigationClient.h"
#include "WKPageLoaderClient.h"

#include "wtf/RunLoop.h"

#include "WebView.h"
#include "WebViewConstants.h"

BWebView::BWebView(BRect frame,BWindow* myWindow)
{
initializeOnce();
@@ -52,8 +57,25 @@ BWebView::BWebView(BRect frame,BWindow* myWindow)
fContext = adoptWK(WKContextCreateWithConfiguration(nullptr));
WKPageConfigurationSetContext(config.get(),fContext.get());


fViewPort=adoptWK(WKViewCreate("Webkit",frame,myWindow,config.get()));
//

}

void BWebView::navigationCallbacks(BLooper* app)
{
auto page = WKViewGetPage( fViewPort.get());
WKPageNavigationClientV0 navigationClient={};

navigationClient.base.version = 0;
navigationClient.base.clientInfo = app;

navigationClient.didCommitNavigation = didCommitNavigation;
navigationClient.didFinishDocumentLoad = didFinishDocumentLoad;
navigationClient.didFailNavigation = didFailNavigation;
navigationClient.didFinishNavigation = didFinishNavigation;
navigationClient.didReceiveServerRedirectForProvisionalNavigation = didReceiveServerRedirectForProvisionalNavigation;
WKPageSetPageNavigationClient(page,&navigationClient.base);
}
void BWebView::initializeOnce()
{
@@ -67,7 +89,6 @@ void BWebView::loadHTML()
uri = adoptWK(WKURLCreateWithUTF8CString("about:blank"));
WKRetainPtr<WKStringRef> str;
str = adoptWK(WKStringCreateWithUTF8CString("<body>Hello world</body>"));
//WKPageLoadURL(page,uri.get());
WKPageLoadHTMLString(page,str.get(),uri.get());
}

@@ -77,5 +98,55 @@ void BWebView::loadURI(const char* uri)
WKRetainPtr<WKURLRef> wuri;
wuri = adoptWK(WKURLCreateWithUTF8CString(uri));
WKPageLoadURL(page,wuri.get());
fprintf(stderr,"\n %s \n",__PRETTY_FUNCTION__);
}

void BWebView::goForward()
{
auto page = WKViewGetPage(fViewPort.get());
WKPageGoForward(page);
BMessage message(URL_CHANGE);
message.AddString("url",BString(getCurrentURL()));
be_app->PostMessage(&message);
}
void BWebView::goBackward()
{
auto page = WKViewGetPage(fViewPort.get());
WKPageGoBack(page);
BMessage message(URL_CHANGE);
message.AddString("url",BString(getCurrentURL()));
be_app->PostMessage(&message);
}
void BWebView::stop()
{
auto page = WKViewGetPage(fViewPort.get());
WKPageClose(page);
}
void BWebView::didCommitNavigation(WKPageRef page, WKNavigationRef navigation, WKTypeRef userData, const void* clientInfo)
{
BMessage message(DID_COMMIT_NAVIGATION);
be_app->PostMessage(&message);
}
void BWebView::didReceiveServerRedirectForProvisionalNavigation(WKPageRef page, WKNavigationRef navigation, WKTypeRef userData, const void* clientInfo)
{
//this wont work for now as we need to make network process work
//fprintf(stderr,"\n %s %s\n",__PRETTY_FUNCTION__,((BWebView*)clientInfo)->getCurrentURL());
}
void BWebView::didFinishDocumentLoad(WKPageRef page, WKNavigationRef navigation, WKTypeRef userData, const void* clientInfo)
{
fprintf(stderr,"\n %s %s\n",__PRETTY_FUNCTION__);
}
void BWebView::didFinishNavigation(WKPageRef page, WKNavigationRef navigation, WKTypeRef userData,const void* clientInfo)
{
BMessage message(DID_FINISH_NAVIGATION);
be_app->PostMessage(&message);
}

void BWebView::didFailNavigation(WKPageRef page, WKNavigationRef navigation,WKErrorRef, WKTypeRef userData,const void* clientInfo)
{
fprintf(stderr,"\n %s \n",__PRETTY_FUNCTION__);
}

void BWebView::didFinishProgress(WKPageRef page,const void* clientInfo)
{
fprintf(stderr,"\n %s \n",__PRETTY_FUNCTION__);
}
@@ -38,10 +38,24 @@ class BWebView
void initializeOnce();
void loadHTML();
void loadURI(const char*);
void goForward();
void goBackward();
void stop();
WebViewBase* getRenderView() { return toImpl(fViewPort.get()); }
const char* getCurrentURL() { return getRenderView()->currentURL(); }

void navigationCallbacks(BLooper* app);
private:
WKRetainPtr<WKViewRef> fViewPort;
WKRetainPtr<WKContextRef> fContext;
static void didCommitNavigation(WKPageRef page, WKNavigationRef navigation, WKTypeRef userData, const void* clientInfo);
static void didReceiveServerRedirectForProvisionalNavigation(WKPageRef page, WKNavigationRef navigation, WKTypeRef userData, const void* clientInfo);
static void didFinishDocumentLoad(WKPageRef page, WKNavigationRef navigation, WKTypeRef userData, const void* clientInfo);
static void didFinishProgress(WKPageRef,const void*);
static void didFinishNavigation(WKPageRef page, WKNavigationRef navigation, WKTypeRef userData,const void* clientInfo);
static void didFailNavigation(WKPageRef page, WKNavigationRef navigation, WKErrorRef,WKTypeRef userData,const void* clientInfo);


};


@@ -40,7 +40,8 @@ const API::PageConfiguration& pageConfig)
fprintf(stderr,"Init");
auto config = pageConfig.copy();
auto* preferences = config->preferences();

SetLowColor(255,255,255,255);
SetViewColor(255,255,255,255);
if(!preferences && config->pageGroup())
{
preferences = &config->pageGroup()->preferences();
@@ -60,8 +61,6 @@ const API::PageConfiguration& pageConfig)
fPage->drawingArea()->setSize(IntSize(rect.right - rect.left,
rect.top - rect.bottom));
}
BRect p(0,0,10,20);
paint(WebCore::IntRect(p));
}

void WebViewBase::paint(const IntRect& dirtyRect)
@@ -49,7 +49,7 @@ namespace WebKit
WebPageProxy* page() const { return fPage.get(); }
BView* getView() {return this;}
void initializeOnce();

const char* currentURL() { return page()->pageLoadState().activeURL().utf8().data(); }
//hook methods
virtual void MouseMoved(BPoint,uint32,const BMessage*);
private:
@@ -0,0 +1,34 @@
/*
* Copyright (C) 2019 Haiku, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _H
#define _H

enum{
DID_COMMIT_NAVIGATION = 'dcna',
DID_FINISH_NAVIGATION = 'dfna',
URL_CHANGE = 'urlc',
};

#endif // _H
@@ -3872,7 +3872,7 @@ void WebPageProxy::didStartProgress()
}

void WebPageProxy::didChangeProgress(double value)
{
{fprintf(stderr,"!!!!!! %s %.2f !!!!!",__PRETTY_FUNCTION__,value);
PageClientProtector protector(pageClient());

auto transaction = m_pageLoadState.transaction();

0 comments on commit e5c14d2

Please sign in to comment.
You can’t perform that action at this time.