Skip to content
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

Easy API #25

Merged
merged 3 commits into from
Aug 15, 2019
Merged
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
63 changes: 6 additions & 57 deletions Source/WebKit/Shared/haiku/AuxiliaryProcessMainHaiku.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);

Expand All @@ -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);
}
};

Expand Down
106 changes: 106 additions & 0 deletions Source/WebKit/Shared/haiku/ProcessInitHaiku.h
Original file line number Diff line number Diff line change
@@ -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;

};
}
16 changes: 12 additions & 4 deletions Source/WebKit/UIProcess/API/haiku/WebView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

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

BWebView::BWebView(BRect frame,BWindow* myWindow)
:fAppLooper(NULL)
Expand Down Expand Up @@ -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()
{
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/UIProcess/API/haiku/WebView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
3 changes: 2 additions & 1 deletion Source/WebKit/UIProcess/API/haiku/WebViewConstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 5 additions & 0 deletions Source/WebKit/UIProcess/haiku/BackingStoreHaiku.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
57 changes: 3 additions & 54 deletions Tools/MiniBrowser/haiku/BrowserApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 0 additions & 4 deletions Tools/MiniBrowser/haiku/BrowserApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down