From af57d3be085589a3e43e3d8801b0dd8a8d48859d Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 29 Apr 2013 18:59:34 +0800 Subject: [PATCH] Uniform message names. Messages sent to browser should be prefixed with ATOM_BROWSER_, and messages sent to renderer should be prefixed with ATOM_RENDERER_. --- browser/atom/rpc_server.coffee | 22 +++++++++++----------- renderer/api/lib/remote.coffee | 23 ++++++++++++----------- 2 files changed, 23 insertions(+), 22 deletions(-) diff --git a/browser/atom/rpc_server.coffee b/browser/atom/rpc_server.coffee index deae80d..3cb9f74 100644 --- a/browser/atom/rpc_server.coffee +++ b/browser/atom/rpc_server.coffee @@ -12,9 +12,9 @@ argsToValues = (processId, routingId, metas) -> # Create a delegate function to do asynchronous RPC call. ret = -> 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, -> - ipc.sendChannel processId, routingId, 'ATOM_INTERNAL_DEREFERENCE', meta.id + ipc.sendChannel processId, routingId, 'ATOM_RENDERER_DEREFERENCE', meta.id ret constructCallback meta for meta in metas @@ -48,13 +48,13 @@ class Meta @type = 'value' @value = value -ipc.on 'ATOM_INTERNAL_REQUIRE', (event, processId, routingId, module) -> +ipc.on 'ATOM_BROWSER_REQUIRE', (event, processId, routingId, module) -> try event.result = new Meta(processId, routingId, require(module)) catch e 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 windows = objectsRegistry.getAllWindows() for window in windows @@ -64,7 +64,7 @@ ipc.on 'ATOM_INTERNAL_CURRENT_WINDOW', (event, processId, routingId) -> catch e 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 args = argsToValues processId, routingId, args constructor = objectsRegistry.get id @@ -75,7 +75,7 @@ ipc.on 'ATOM_INTERNAL_CONSTRUCTOR', (event, processId, routingId, id, args) -> catch e 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 args = argsToValues processId, routingId, args func = objectsRegistry.get id @@ -84,7 +84,7 @@ ipc.on 'ATOM_INTERNAL_FUNCTION_CALL', (event, processId, routingId, id, args) -> catch e 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 args = argsToValues processId, routingId, args obj = objectsRegistry.get id @@ -93,26 +93,26 @@ ipc.on 'ATOM_INTERNAL_MEMBER_CALL', (event, processId, routingId, id, method, ar catch e 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 obj = objectsRegistry.get id obj[name] = value catch e 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 obj = objectsRegistry.get id event.result = new Meta(processId, routingId, obj[name]) catch e 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 obj = objectsRegistry.get id event.result = new Meta(processId, routingId, obj) catch e 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 diff --git a/renderer/api/lib/remote.coffee b/renderer/api/lib/remote.coffee index 54fdfd1..7acbf76 100644 --- a/renderer/api/lib/remote.coffee +++ b/renderer/api/lib/remote.coffee @@ -42,7 +42,7 @@ metaToValue = (meta) -> constructor: -> if @constructor == RemoteFunction # 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 # with the returned object. @@ -50,7 +50,7 @@ metaToValue = (meta) -> return metaToValue obj else # 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 else ret = v8_util.createObjectWithName meta.name @@ -61,45 +61,46 @@ metaToValue = (meta) -> if member.type is 'function' ret[member.name] = -> # 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 else ret.__defineSetter__ member.name, (value) -> # 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, -> # 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 # Track delegate object's life time, and tell the browser to clean up # when the object is GCed. v8_util.setDestructor ret, -> - ipc.sendChannel 'ATOM_INTERNAL_DEREFERENCE', meta.storeId + ipc.sendChannel 'ATOM_BROWSER_DEREFERENCE', meta.storeId ret # 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.apply global, metaToValue(args) # Browser releases a callback in renderer. -ipc.on 'ATOM_INTERNAL_DEREFERENCE', (callbackId) -> +ipc.on 'ATOM_RENDERER_DEREFERENCE', (callbackId) -> + console.log callbackId callbacksRegistry.remove callbackId # Get remote module. exports.require = (module) -> - meta = ipc.sendChannelSync 'ATOM_INTERNAL_REQUIRE', module + meta = ipc.sendChannelSync 'ATOM_BROWSER_REQUIRE', module metaToValue meta # Get object with specified id. exports.getObject = (id) -> - meta = ipc.sendChannelSync 'ATOM_INTERNAL_REFERENCE', id + meta = ipc.sendChannelSync 'ATOM_BROWSER_REFERENCE', id metaToValue meta # Get current window object. exports.getCurrentWindow = -> - meta = ipc.sendChannelSync 'ATOM_INTERNAL_CURRENT_WINDOW' + meta = ipc.sendChannelSync 'ATOM_BROWSER_CURRENT_WINDOW' metaToValue meta -- 2.7.4