+ All Categories
Home > Technology > e10sとアプリ間通信

e10sとアプリ間通信

Date post: 25-May-2015
Category:
Upload: makoto-kato
View: 474 times
Download: 1 times
Share this document with a friend
Description:
@ 関西Firefox OS勉強会
Popular Tags:
39
e10s @makoto_kato
Transcript
Page 1: e10sとアプリ間通信

e10s@makoto_kato

Page 2: e10sとアプリ間通信

about:me

••

Page 3: e10sとアプリ間通信

• Rust Samurai #4 - https://atnd.org/events/54657

Page 4: e10sとアプリ間通信

Agenda

• Electrolysis (e10s) ?

• Firefox OS

Page 5: e10sとアプリ間通信

• Firefox / Gecko

Page 6: e10sとアプリ間通信

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とアプリ間通信

Firefox OS

• b2g

• plugin-container

• APIb2g

Page 8: e10sとアプリ間通信

Kernel / Gonk

b2g process

Plugin-containerprocess

(Apps)

Plugin-container process

(Apps)

Hardware Access

IPC

IPC

Page 9: e10sとアプリ間通信

(IPC)

• Chromium IPC

• IPC IPDL• IDL

Page 10: e10sとアプリ間通信

IPDL

• IDL

• IPDL

Page 11: e10sとアプリ間通信

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とアプリ間通信

( )

@OBJDIR@/ipc/ipdl/_ipdlheaders/mozilla/hal_sandbox/PHal.h

class Msg_NotifyBatteryChange :

public IPC::Message

}

Page 13: e10sとアプリ間通信

( )

@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とアプリ間通信

( )

@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とアプリ間通信

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とアプリ間通信

IPC

• B2g (Chrome ) (Content )

• b2g

Page 17: e10sとアプリ間通信

• XMLHttpRequsest

• WebSocket

• Socket (TCP/UDP)

• Web Activity

• Inter App Communication

Page 18: e10sとアプリ間通信

XMLHttpRequest / WebSocket

Page 19: e10sとアプリ間通信

XMLHttpRequest / WebSocket

• HTTP

• Firefox OS Daemon ProcessDaemon Process• DRM

• Localhost Network Activity

Page 20: e10sとアプリ間通信

Socket API

• TCP or UDP Socket

Page 21: e10sとアプリ間通信

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とアプリ間通信

TCP Server Socket

var socket = navigator.mozTCPSocket.listen(8888, { binaryType : ‘string’ });

Socket.onconnect = function() {

//

}

Page 23: e10sとアプリ間通信

UDP Socket

var socket = new UDPSocket();

socket.addEventListener(‘message’, function() {

//

})

socket.send(‘hello’, ‘127.0.0.1’, 8888);

Page 24: e10sとアプリ間通信

Web Activity

• Web Intent API (Google Chrome) Firefox OS Counter

Proposal

Page 25: e10sとアプリ間通信

“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とアプリ間通信

• MozActivity

Page 27: e10sとアプリ間通信

var activity = new MozActivity( {

name: “pick”,

data: {

type: “image/jpeg”

}

});

activity.onsuccess = function() {

// this.result

}

Page 28: e10sとアプリ間通信

••

Page 29: e10sとアプリ間通信

{

“name”: ‘<Application Name>’,

“description”: ‘<Application’s description>’,

“activities”: {

“view” : {

“filters”: {

“type” : “image/tiff”

}

}

}

}

Page 30: e10sとアプリ間通信

var register = navigator.mozRegisterActivityHandler({

name: “view”,

disposition: “inline”,

filters: {

type: “image/tiff”;

}

}

Page 31: e10sとアプリ間通信

navigator.mozSetMessageHandler(‘activity’, function(request) {

//

request.postRequest(…);

}

Page 32: e10sとアプリ間通信

Web Activity

•• 1:n

Page 33: e10sとアプリ間通信

Inter-App Communication (IAC)

• Firefox OS 1.2+

• Certified App only

• Web Activity

• – Publisher•

• - Subscriber

Page 34: e10sとアプリ間通信

“connections” {

“<keyword>” : {

“handler_path”: “/index.html”,

“description”: “description”,

“rules” : {

“manifestURLs”: “<url>”,

}

}

}

Page 35: e10sとアプリ間通信

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とアプリ間通信

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とアプリ間通信

Inter App Communication

• Certified App

• Certified

• 1:1

Page 38: e10sとアプリ間通信

• e10s Gecko• Gecko

• Firefox OS (Web Activity / Inter-App Communication) e10s

• API Network Activity

• Gecko• XMLHttpRequest / WebSocket / Socket

API

Page 39: e10sとアプリ間通信

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


Recommended