e10sとアプリ間通信
DESCRIPTION
@ 関西Firefox OS勉強会TRANSCRIPT
![Page 1: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/1.jpg)
e10s@makoto_kato
![Page 4: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/4.jpg)
Agenda
• Electrolysis (e10s) ?
• Firefox OS
![Page 5: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/5.jpg)
• Firefox / Gecko
![Page 6: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/6.jpg)
e10s
• Firefox Out-Of-Process Plugin• Firefox 3.6
• Firefox DRM/CDM (Content Decryption Module)• Firefox 3x ?
• Firefox Chrome Content
• (Nightly)
• Firefox OS
![Page 7: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/7.jpg)
Firefox OS
• b2g
• plugin-container
•
• APIb2g
![Page 8: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/8.jpg)
Kernel / Gonk
b2g process
Plugin-containerprocess
(Apps)
Plugin-container process
(Apps)
Hardware Access
IPC
IPC
![Page 9: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/9.jpg)
(IPC)
• Chromium IPC
• IPC IPDL• IDL
![Page 10: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/10.jpg)
IPDL
• IDL
•
• IPDL
•
•
![Page 11: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/11.jpg)
ipdl
hal/sandbox/PHal.idl
sync protocol PHal {
…
child:
NotifyBatteryChange(
BatteryInformation aBatteryInfo);
…
parent:
Vibrate(uint32_t[] pattern, uint64_t[] id,
PBrowser browser);
}
![Page 12: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/12.jpg)
( )
@OBJDIR@/ipc/ipdl/_ipdlheaders/mozilla/hal_sandbox/PHal.h
class Msg_NotifyBatteryChange :
public IPC::Message
…
}
![Page 13: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/13.jpg)
( )
@OBJDIR@/ipc/ipdl/_ipdlheaders/mozilla/hal_sandbox/PHalChild.h
class /*NS_ABSTRACT_CLASS*/ PHalParent :
public mozilla::ipc::IProtocol,
protected mozilla::ipc::IProtocolManager<mozilla::ipc::IProtocol>
{
…
virtual bool
RecvVibrate(
const nsTArray<uint32_t>& pattern,
const nsTArray<uint64_t>& id,
PBrowserParent* browser) = 0;
…
bool
SendNotifyBatteryChange(const BatteryInformation& aBatteryInfo) NS_WARN_UNUSED_RESULT;
![Page 14: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/14.jpg)
( )
@OBJDIR@/ipc/ipdl/_ipdlheaders/mozilla/hal_sandbox/PHalChild.h
class /*NS_ABSTRACT_CLASS*/ PHalChild :
public mozilla::ipc::IProtocol,
protected mozilla::ipc::IProtocolManager<mozilla::ipc::IProtocol>
{
…
virtual bool
RecvNotifyBatteryChange(const BatteryInformation& aBatteryInfo) = 0;
…
bool
SendVibrate(
const nsTArray<uint32_t>& pattern,
const nsTArray<uint64_t>& id,
PBrowserChild* browser);
![Page 15: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/15.jpg)
template<>struct ParamTraits<mozilla::WidgetGUIEvent>{typedef mozilla::WidgetGUIEvent paramType;
static void Write(Message* aMsg, const paramType& aParam){WriteParam(aMsg, static_cast<mozilla::WidgetEvent>(aParam));WriteParam(aMsg, aParam.mPluginEvent.mBuffer);
}
static bool Read(const Message* aMsg, void** aIter,paramType* aResult)
{return ReadParam(aMsg, aIter,
static_cast<mozilla::WidgetEvent*>(aResult)) &&ReadParam(aMsg, aIter, &aResult->mPluginEvent.mBuffer);
}
![Page 16: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/16.jpg)
IPC
• B2g (Chrome ) (Content )
• b2g
![Page 17: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/17.jpg)
• XMLHttpRequsest
• WebSocket
• Socket (TCP/UDP)
• Web Activity
• Inter App Communication
![Page 18: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/18.jpg)
XMLHttpRequest / WebSocket
•
![Page 19: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/19.jpg)
XMLHttpRequest / WebSocket
•
• HTTP
• Firefox OS Daemon ProcessDaemon Process• DRM
• Localhost Network Activity
![Page 20: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/20.jpg)
Socket API
• TCP or UDP Socket
•
•
![Page 21: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/21.jpg)
TCP Socket ( )
var socket = new navigator.mozTCPSocket.open(
‘127.0.0.1’, 8888, { binaryType: ‘string’ } );
socket.onopen = function() {
};
socket.ondata = function(msg) {
//
};
…
socket.send(‘hello’);
![Page 22: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/22.jpg)
TCP Server Socket
var socket = navigator.mozTCPSocket.listen(8888, { binaryType : ‘string’ });
Socket.onconnect = function() {
//
}
…
![Page 23: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/23.jpg)
UDP Socket
var socket = new UDPSocket();
socket.addEventListener(‘message’, function() {
//
})
socket.send(‘hello’, ‘127.0.0.1’, 8888);
![Page 24: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/24.jpg)
Web Activity
• Web Intent API (Google Chrome) Firefox OS Counter
Proposal
![Page 25: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/25.jpg)
“Web Activities' intent is not to be a clone of Google's Web Intents with some naming and API details changed. Web Activities aim to be a simple API trying to solve a very clear set of use cases.”
http://lists.w3.org/Archives/Public/public-web-intents/2012Jun/0061.html
![Page 26: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/26.jpg)
• MozActivity
![Page 27: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/27.jpg)
var activity = new MozActivity( {
name: “pick”,
data: {
type: “image/jpeg”
}
});
activity.onsuccess = function() {
// this.result
}
![Page 28: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/28.jpg)
••
•
![Page 29: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/29.jpg)
{
“name”: ‘<Application Name>’,
“description”: ‘<Application’s description>’,
“activities”: {
“view” : {
“filters”: {
“type” : “image/tiff”
}
}
}
}
![Page 30: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/30.jpg)
var register = navigator.mozRegisterActivityHandler({
name: “view”,
disposition: “inline”,
filters: {
type: “image/tiff”;
}
}
![Page 31: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/31.jpg)
navigator.mozSetMessageHandler(‘activity’, function(request) {
//
request.postRequest(…);
}
![Page 32: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/32.jpg)
Web Activity
•• 1:n
•
![Page 33: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/33.jpg)
Inter-App Communication (IAC)
• Firefox OS 1.2+
• Certified App only
• Web Activity
•
• – Publisher•
• - Subscriber
![Page 34: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/34.jpg)
“connections” {
“<keyword>” : {
“handler_path”: “/index.html”,
“description”: “description”,
“rules” : {
“manifestURLs”: “<url>”,
…
}
}
}
![Page 35: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/35.jpg)
navigator.mozApps.getSelf().onsuccess = function(ev) {
var app = ev.target.result;
app.connet(‘<keyword>’, rules).then(function(ports) {
// connected
ports.forEach(function(port) {
port.onmessage = function(evt) {
// received data
});
port.postMessage({ value: ‘hello’ });
}
}, function(reason) {
// reject
});
};
![Page 36: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/36.jpg)
navigator.mozSetMessageHandler(‘connection’,
function(request) {
var keyword = request.keyword;
var port = request.port;
port.onmessage = function(evt) {
var message = evt.data;
port.postMessage({ value: “Hello” });
}
});
![Page 37: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/37.jpg)
Inter App Communication
• Certified App
• Certified
• 1:1
![Page 38: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/38.jpg)
• e10s Gecko• Gecko
• Firefox OS (Web Activity / Inter-App Communication) e10s
• API Network Activity
• Gecko• XMLHttpRequest / WebSocket / Socket
API
![Page 39: e10sとアプリ間通信](https://reader034.vdocuments.net/reader034/viewer/2022052523/5562d8bbd8b42a63498b51bb/html5/thumbnails/39.jpg)
References
• mozTCPSocket• https://developer.mozilla.org/en-
US/docs/Web/API/Navigator.mozTCPSocket
• Web Activities• https://developer.mozilla.org/en-
US/docs/Web/API/Web_Activities
• Inter App Communication• https://wiki.mozilla.org/WebAPI/Inter_App_Communic
ation
• https://bugzilla.mozilla.org/show_bug.cgi?id=907068