Uniform message names.
Messages sent to browser should be prefixed with ATOM_BROWSER_, and messages sent to renderer should be prefixed with ATOM_RENDERER_.
This commit is contained in:
parent
f1e15b49a9
commit
af57d3be08
2 changed files with 23 additions and 22 deletions
|
@ -12,9 +12,9 @@ argsToValues = (processId, routingId, metas) ->
|
||||||
# Create a delegate function to do asynchronous RPC call.
|
# Create a delegate function to do asynchronous RPC call.
|
||||||
ret = ->
|
ret = ->
|
||||||
args = new Meta(processId, routingId, arguments)
|
args = new Meta(processId, routingId, arguments)
|
||||||
ipc.sendChannel processId, routingId, 'ATOM_INTERNAL_FUNCTION_CALL', meta.id, args
|
ipc.sendChannel processId, routingId, 'ATOM_RENDERER_FUNCTION_CALL', meta.id, args
|
||||||
v8_util.setDestructor ret, ->
|
v8_util.setDestructor ret, ->
|
||||||
ipc.sendChannel processId, routingId, 'ATOM_INTERNAL_DEREFERENCE', meta.id
|
ipc.sendChannel processId, routingId, 'ATOM_RENDERER_DEREFERENCE', meta.id
|
||||||
ret
|
ret
|
||||||
|
|
||||||
constructCallback meta for meta in metas
|
constructCallback meta for meta in metas
|
||||||
|
@ -48,13 +48,13 @@ class Meta
|
||||||
@type = 'value'
|
@type = 'value'
|
||||||
@value = value
|
@value = value
|
||||||
|
|
||||||
ipc.on 'ATOM_INTERNAL_REQUIRE', (event, processId, routingId, module) ->
|
ipc.on 'ATOM_BROWSER_REQUIRE', (event, processId, routingId, module) ->
|
||||||
try
|
try
|
||||||
event.result = new Meta(processId, routingId, require(module))
|
event.result = new Meta(processId, routingId, require(module))
|
||||||
catch e
|
catch e
|
||||||
event.result = type: 'error', value: e.message
|
event.result = type: 'error', value: e.message
|
||||||
|
|
||||||
ipc.on 'ATOM_INTERNAL_CURRENT_WINDOW', (event, processId, routingId) ->
|
ipc.on 'ATOM_BROWSER_CURRENT_WINDOW', (event, processId, routingId) ->
|
||||||
try
|
try
|
||||||
windows = objectsRegistry.getAllWindows()
|
windows = objectsRegistry.getAllWindows()
|
||||||
for window in windows
|
for window in windows
|
||||||
|
@ -64,7 +64,7 @@ ipc.on 'ATOM_INTERNAL_CURRENT_WINDOW', (event, processId, routingId) ->
|
||||||
catch e
|
catch e
|
||||||
event.result = type: 'error', value: e.message
|
event.result = type: 'error', value: e.message
|
||||||
|
|
||||||
ipc.on 'ATOM_INTERNAL_CONSTRUCTOR', (event, processId, routingId, id, args) ->
|
ipc.on 'ATOM_BROWSER_CONSTRUCTOR', (event, processId, routingId, id, args) ->
|
||||||
try
|
try
|
||||||
args = argsToValues processId, routingId, args
|
args = argsToValues processId, routingId, args
|
||||||
constructor = objectsRegistry.get id
|
constructor = objectsRegistry.get id
|
||||||
|
@ -75,7 +75,7 @@ ipc.on 'ATOM_INTERNAL_CONSTRUCTOR', (event, processId, routingId, id, args) ->
|
||||||
catch e
|
catch e
|
||||||
event.result = type: 'error', value: e.message
|
event.result = type: 'error', value: e.message
|
||||||
|
|
||||||
ipc.on 'ATOM_INTERNAL_FUNCTION_CALL', (event, processId, routingId, id, args) ->
|
ipc.on 'ATOM_BROWSER_FUNCTION_CALL', (event, processId, routingId, id, args) ->
|
||||||
try
|
try
|
||||||
args = argsToValues processId, routingId, args
|
args = argsToValues processId, routingId, args
|
||||||
func = objectsRegistry.get id
|
func = objectsRegistry.get id
|
||||||
|
@ -84,7 +84,7 @@ ipc.on 'ATOM_INTERNAL_FUNCTION_CALL', (event, processId, routingId, id, args) ->
|
||||||
catch e
|
catch e
|
||||||
event.result = type: 'error', value: e.message
|
event.result = type: 'error', value: e.message
|
||||||
|
|
||||||
ipc.on 'ATOM_INTERNAL_MEMBER_CALL', (event, processId, routingId, id, method, args) ->
|
ipc.on 'ATOM_BROWSER_MEMBER_CALL', (event, processId, routingId, id, method, args) ->
|
||||||
try
|
try
|
||||||
args = argsToValues processId, routingId, args
|
args = argsToValues processId, routingId, args
|
||||||
obj = objectsRegistry.get id
|
obj = objectsRegistry.get id
|
||||||
|
@ -93,26 +93,26 @@ ipc.on 'ATOM_INTERNAL_MEMBER_CALL', (event, processId, routingId, id, method, ar
|
||||||
catch e
|
catch e
|
||||||
event.result = type: 'error', value: e.message
|
event.result = type: 'error', value: e.message
|
||||||
|
|
||||||
ipc.on 'ATOM_INTERNAL_MEMBER_SET', (event, processId, routingId, id, name, value) ->
|
ipc.on 'ATOM_BROWSER_MEMBER_SET', (event, processId, routingId, id, name, value) ->
|
||||||
try
|
try
|
||||||
obj = objectsRegistry.get id
|
obj = objectsRegistry.get id
|
||||||
obj[name] = value
|
obj[name] = value
|
||||||
catch e
|
catch e
|
||||||
event.result = type: 'error', value: e.message
|
event.result = type: 'error', value: e.message
|
||||||
|
|
||||||
ipc.on 'ATOM_INTERNAL_MEMBER_GET', (event, processId, routingId, id, name) ->
|
ipc.on 'ATOM_BROWSER_MEMBER_GET', (event, processId, routingId, id, name) ->
|
||||||
try
|
try
|
||||||
obj = objectsRegistry.get id
|
obj = objectsRegistry.get id
|
||||||
event.result = new Meta(processId, routingId, obj[name])
|
event.result = new Meta(processId, routingId, obj[name])
|
||||||
catch e
|
catch e
|
||||||
event.result = type: 'error', value: e.message
|
event.result = type: 'error', value: e.message
|
||||||
|
|
||||||
ipc.on 'ATOM_INTERNAL_REFERENCE', (event, processId, routingId, id) ->
|
ipc.on 'ATOM_BROWSER_REFERENCE', (event, processId, routingId, id) ->
|
||||||
try
|
try
|
||||||
obj = objectsRegistry.get id
|
obj = objectsRegistry.get id
|
||||||
event.result = new Meta(processId, routingId, obj)
|
event.result = new Meta(processId, routingId, obj)
|
||||||
catch e
|
catch e
|
||||||
event.result = type: 'error', value: e.message
|
event.result = type: 'error', value: e.message
|
||||||
|
|
||||||
ipc.on 'ATOM_INTERNAL_DEREFERENCE', (processId, routingId, storeId) ->
|
ipc.on 'ATOM_BROWSER_DEREFERENCE', (processId, routingId, storeId) ->
|
||||||
objectsRegistry.remove processId, routingId, storeId
|
objectsRegistry.remove processId, routingId, storeId
|
||||||
|
|
|
@ -42,7 +42,7 @@ metaToValue = (meta) ->
|
||||||
constructor: ->
|
constructor: ->
|
||||||
if @constructor == RemoteFunction
|
if @constructor == RemoteFunction
|
||||||
# Constructor call.
|
# Constructor call.
|
||||||
obj = ipc.sendChannelSync 'ATOM_INTERNAL_CONSTRUCTOR', meta.id, argumentsToMetaList(arguments)
|
obj = ipc.sendChannelSync 'ATOM_BROWSER_CONSTRUCTOR', meta.id, argumentsToMetaList(arguments)
|
||||||
|
|
||||||
# Returning object in constructor will replace constructed object
|
# Returning object in constructor will replace constructed object
|
||||||
# with the returned object.
|
# with the returned object.
|
||||||
|
@ -50,7 +50,7 @@ metaToValue = (meta) ->
|
||||||
return metaToValue obj
|
return metaToValue obj
|
||||||
else
|
else
|
||||||
# Function call.
|
# Function call.
|
||||||
ret = ipc.sendChannelSync 'ATOM_INTERNAL_FUNCTION_CALL', meta.id, argumentsToMetaList(arguments)
|
ret = ipc.sendChannelSync 'ATOM_BROWSER_FUNCTION_CALL', meta.id, argumentsToMetaList(arguments)
|
||||||
return metaToValue ret
|
return metaToValue ret
|
||||||
else
|
else
|
||||||
ret = v8_util.createObjectWithName meta.name
|
ret = v8_util.createObjectWithName meta.name
|
||||||
|
@ -61,45 +61,46 @@ metaToValue = (meta) ->
|
||||||
if member.type is 'function'
|
if member.type is 'function'
|
||||||
ret[member.name] = ->
|
ret[member.name] = ->
|
||||||
# Call member function.
|
# Call member function.
|
||||||
ret = ipc.sendChannelSync 'ATOM_INTERNAL_MEMBER_CALL', meta.id, member.name, argumentsToMetaList(arguments)
|
ret = ipc.sendChannelSync 'ATOM_BROWSER_MEMBER_CALL', meta.id, member.name, argumentsToMetaList(arguments)
|
||||||
metaToValue ret
|
metaToValue ret
|
||||||
else
|
else
|
||||||
ret.__defineSetter__ member.name, (value) ->
|
ret.__defineSetter__ member.name, (value) ->
|
||||||
# Set member data.
|
# Set member data.
|
||||||
ipc.sendChannelSync 'ATOM_INTERNAL_MEMBER_SET', meta.id, member.name, value
|
ipc.sendChannelSync 'ATOM_BROWSER_MEMBER_SET', meta.id, member.name, value
|
||||||
|
|
||||||
ret.__defineGetter__ member.name, ->
|
ret.__defineGetter__ member.name, ->
|
||||||
# Get member data.
|
# Get member data.
|
||||||
ret = ipc.sendChannelSync 'ATOM_INTERNAL_MEMBER_GET', meta.id, member.name
|
ret = ipc.sendChannelSync 'ATOM_BROWSER_MEMBER_GET', meta.id, member.name
|
||||||
metaToValue ret
|
metaToValue ret
|
||||||
|
|
||||||
# Track delegate object's life time, and tell the browser to clean up
|
# Track delegate object's life time, and tell the browser to clean up
|
||||||
# when the object is GCed.
|
# when the object is GCed.
|
||||||
v8_util.setDestructor ret, ->
|
v8_util.setDestructor ret, ->
|
||||||
ipc.sendChannel 'ATOM_INTERNAL_DEREFERENCE', meta.storeId
|
ipc.sendChannel 'ATOM_BROWSER_DEREFERENCE', meta.storeId
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
# Browser calls a callback in renderer.
|
# Browser calls a callback in renderer.
|
||||||
ipc.on 'ATOM_INTERNAL_FUNCTION_CALL', (callbackId, args) ->
|
ipc.on 'ATOM_RENDERER_FUNCTION_CALL', (callbackId, args) ->
|
||||||
callback = callbacksRegistry.get callbackId
|
callback = callbacksRegistry.get callbackId
|
||||||
callback.apply global, metaToValue(args)
|
callback.apply global, metaToValue(args)
|
||||||
|
|
||||||
# Browser releases a callback in renderer.
|
# Browser releases a callback in renderer.
|
||||||
ipc.on 'ATOM_INTERNAL_DEREFERENCE', (callbackId) ->
|
ipc.on 'ATOM_RENDERER_DEREFERENCE', (callbackId) ->
|
||||||
|
console.log callbackId
|
||||||
callbacksRegistry.remove callbackId
|
callbacksRegistry.remove callbackId
|
||||||
|
|
||||||
# Get remote module.
|
# Get remote module.
|
||||||
exports.require = (module) ->
|
exports.require = (module) ->
|
||||||
meta = ipc.sendChannelSync 'ATOM_INTERNAL_REQUIRE', module
|
meta = ipc.sendChannelSync 'ATOM_BROWSER_REQUIRE', module
|
||||||
metaToValue meta
|
metaToValue meta
|
||||||
|
|
||||||
# Get object with specified id.
|
# Get object with specified id.
|
||||||
exports.getObject = (id) ->
|
exports.getObject = (id) ->
|
||||||
meta = ipc.sendChannelSync 'ATOM_INTERNAL_REFERENCE', id
|
meta = ipc.sendChannelSync 'ATOM_BROWSER_REFERENCE', id
|
||||||
metaToValue meta
|
metaToValue meta
|
||||||
|
|
||||||
# Get current window object.
|
# Get current window object.
|
||||||
exports.getCurrentWindow = ->
|
exports.getCurrentWindow = ->
|
||||||
meta = ipc.sendChannelSync 'ATOM_INTERNAL_CURRENT_WINDOW'
|
meta = ipc.sendChannelSync 'ATOM_BROWSER_CURRENT_WINDOW'
|
||||||
metaToValue meta
|
metaToValue meta
|
||||||
|
|
Loading…
Add table
Reference in a new issue