Skip to content
Permalink
Browse files

Easy API

1) Moved handhskaing as a part of internal WebView API

2) Placed Invalidation right after backing store changes
i think this is the best place to invalidate- now paints without having to switch workspaces
  • Loading branch information...
RAJAGOPALAN-GANGADHARAN authored and pulkomandy committed Aug 10, 2019
1 parent b09ee1f commit f1a711a70db81705c9df6cdaaef53599daf2326f
@@ -29,11 +29,11 @@
#include "AuxiliaryProcess.h"
#include "WebKit2Initialize.h"
#include <wtf/RunLoop.h>
#include "ProcessInitHaiku.h"

#include <Application.h>
#include <Looper.h>
#include <MessageQueue.h>
#include <String.h>
#include <map>

using namespace std;

@@ -53,70 +53,15 @@ class AuxiliaryProcessMainBase {

class ProcessApp : public BApplication
{
/* one time relying we could resuse this if connection is last*/
map<string,BLooper*> looperMapping;
map<string,BMessage*> messengerMapping;
public:

ProcessApp(char* signature):BApplication(signature)
{
}
void LocalMessage(BMessage* message)
{
const char* idTempStr;
BLooper* looperTemp;
message->FindString("identifier",&idTempStr);
message->FindPointer("looper",(void**)&looperTemp);
string id(idTempStr);
message = DetachCurrentMessage();
if(messengerMapping[id])
{
/*
We have recieved the other process's BMessenger data just send it to our workqueue
*/
looperTemp->PostMessage(messengerMapping[id],looperTemp->PreferredHandler());
}
else
{
/*
Messenger is not yet known save it for later use
*/
looperMapping[id] = looperTemp;
}

}
void GlobalMessage(BMessage* message)
{
const char* idTempStr;
message->FindString("identifier",&idTempStr);
string id(idTempStr);
message = DetachCurrentMessage();
if(looperMapping[id])
{
/*
We know about the looper so send the message directly then
*/
BLooper* temp = looperMapping[id];
temp->PostMessage(message,temp->PreferredHandler());
}
else
{
/*
We dont know about the looper yet so put in the mapping of messengers
*/
messengerMapping[id] = message;
}
}
void MessageReceived(BMessage* message)
{
switch(message->what)
{
case 'inil':
LocalMessage(message);
break;
case 'inig':
GlobalMessage(message);
break;
default:
BApplication::MessageReceived(message);

@@ -125,6 +70,10 @@ class ProcessApp : public BApplication
void ReadyToRun()
{
RunLoop::run();
BHandler* handle = new ProcessInitHaiku();
BLooper* looper = BLooper::LooperForThread(find_thread(NULL));
looper->AddHandler(handle);
looper->SetNextHandler(handle);
}
};

@@ -0,0 +1,106 @@
/*
* 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.
*/

#include <Handler.h>
#include <Looper.h>
#include <Message.h>
#include <map>

using namespace std;
namespace WebKit{
class ProcessInitHaiku: public BHandler
{
public:
ProcessInitHaiku()
:BHandler("process-init")
{
}
void MessageReceived(BMessage* message)
{
switch(message->what)
{
case 'inil':
LocalMessage(message);
break;
case 'inig':
GlobalMessage(message);
break;
default:
BHandler::MessageReceived(message);
}
}

private:
void LocalMessage(BMessage* message)
{
const char* idTempStr;
BLooper* looperTemp;
message->FindString("identifier",&idTempStr);
message->FindPointer("looper",(void**)&looperTemp);
string id(idTempStr);
message = Looper()->DetachCurrentMessage();
if(messengerMapping[id])
{
/*
We have recieved the other process's BMessenger data just send it to our workqueue
*/
looperTemp->PostMessage(messengerMapping[id],looperTemp->PreferredHandler());
}
else
{
/*
Messenger is not yet known save it for later use
*/
looperMapping[id] = looperTemp;
}

}
void GlobalMessage(BMessage* message)
{
const char* idTempStr;
message->FindString("identifier",&idTempStr);
string id(idTempStr);
message = Looper()->DetachCurrentMessage();
if(looperMapping[id])
{
/*
We know about the looper so send the message directly then
*/
BLooper* temp = looperMapping[id];
temp->PostMessage(message,temp->PreferredHandler());
}
else
{
/*
We dont know about the looper yet so put in the mapping of messengers
*/
messengerMapping[id] = message;
}
}
map<string,BLooper*> looperMapping;
map<string,BMessage*> messengerMapping;

};
}
@@ -42,6 +42,7 @@

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

BWebView::BWebView(BRect frame,BWindow* myWindow)
:fAppLooper(NULL)
@@ -84,6 +85,10 @@ void BWebView::initializeOnce()
{
WTF::RunLoop::initializeMainRunLoop();
WTF::RunLoop::run();
BHandler* handle = new ProcessInitHaiku();
BLooper* looper = BLooper::LooperForThread(find_thread(NULL));
looper->AddHandler(handle);
looper->SetNextHandler(handle);
}
void BWebView::loadHTML()
{
@@ -102,6 +107,13 @@ void BWebView::loadURIRequest(const char* uri)
message.AddString("url",uri);
be_app->PostMessage(&message);
}

void BWebView::paintContent()
{
getRenderView()->LockLooper();
getRenderView()->Invalidate();
getRenderView()->UnlockLooper();
}

void BWebView::loadURI(BMessage* message)
{
@@ -135,10 +147,6 @@ void BWebView::stop()
}
void BWebView::didCommitNavigation(WKPageRef page, WKNavigationRef navigation, WKTypeRef userData, const void* clientInfo)
{
BView* view = ((BWebView*)clientInfo)->getRenderView();
view->LockLooper();
view->Invalidate();
view->UnlockLooper();
BLooper* looper = ((BWebView*)clientInfo)->getAppLooper();
BMessage message(DID_COMMIT_NAVIGATION);
looper->PostMessage(&message);
@@ -44,6 +44,7 @@ class BWebView
void goForward();
void goBackward();
void stop();
void paintContent();
WebViewBase* getRenderView() { return toImpl(fViewPort.get()); }
const char* getCurrentURL() { return getRenderView()->currentURL(); }
BLooper* getAppLooper() { return fAppLooper; }
@@ -31,7 +31,8 @@ enum{
URL_CHANGE = 'urlc',
DID_CHANGE_PROGRESS = 'dcpr',
DID_CHANGE_TITLE = 'dctt',
URL_LOAD_HANDLE = 'urlh'
URL_LOAD_HANDLE = 'urlh',
READY_TO_PAINT = 'retp'
};

#endif // _H
@@ -26,13 +26,16 @@
#include "config.h"
#include "BackingStore.h"
#include "ShareableBitmap.h"
#include "WebViewConstants.h"

#include <WebCore/IntRect.h>
#include <WebCore/GraphicsContext.h>
#include "UpdateInfo.h"

#include <Bitmap.h>
#include <View.h>
#include <Application.h>
#include <Message.h>
using namespace WebCore;

namespace WebKit {
@@ -60,6 +63,8 @@ void BackingStore::incorporateUpdate(ShareableBitmap* bitmap, const UpdateInfo&
bitmap->paint(graphicsContext,updateRect.location(),srcRect);
}

BMessage sig(READY_TO_PAINT);
be_app->PostMessage(&sig);
}

void BackingStore::paint(BView* context,const IntRect& rect)
@@ -21,69 +21,18 @@ BrowserApp::BrowserApp(void)
webView = new BWebView(BRect(100,100,800,800),fWindow);
}

void BrowserApp::LocalMessage(BMessage* message)
{
const char* idTempStr;
BLooper* looperTemp;
message->FindString("identifier",&idTempStr);
message->FindPointer("looper",(void**)&looperTemp);
string id(idTempStr);
message = DetachCurrentMessage();
if(messengerMapping[id])
{
/*
We have recieved the other process's BMessenger data just send it to our workqueue
*/
looperTemp->PostMessage(messengerMapping[id],looperTemp->PreferredHandler());
}
else
{
/*
Messenger is not yet known save it for later use
*/
looperMapping[id] = looperTemp;
}

}
void BrowserApp::GlobalMessage(BMessage* message)
{
const char* idTempStr;
message->FindString("identifier",&idTempStr);
string id(idTempStr);
message = DetachCurrentMessage();
if(looperMapping[id])
{
/*
We know about the looper so send the message directly then
*/
BLooper* temp = looperMapping[id];
temp->PostMessage(message,temp->PreferredHandler());
}
else
{
/*
We dont know about the looper yet so put in the mapping of messengers
*/
messengerMapping[id] = message;
}
}

void BrowserApp::MessageReceived(BMessage *message)
{
switch(message->what)
{
case 'inil':
LocalMessage(message);
break;
case 'inig':
GlobalMessage(message);
case READY_TO_PAINT:
webView->paintContent();
break;
case URL_LOAD_HANDLE:
webView->loadURI(message);
break;
default:
BApplication::MessageReceived(message);

BApplication::MessageReceived(message);
}
}
void BrowserApp::ReadyToRun()
@@ -21,12 +21,8 @@ class BrowserApp : public BApplication
void MessageReceived(BMessage *message);
void ReadyToRun();
private:
void LocalMessage(BMessage*);
void GlobalMessage(BMessage*);
BWebView* webView;
status_t result;
map<string,BLooper*> looperMapping;
map<string,BMessage*> messengerMapping;
BrowserWindow* fWindow;
};

0 comments on commit f1a711a

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