{"action":"created","comment":{"url":"https://api.github.com/repos/crosswalk-project/crosswalk/pulls/comments/45956359","id":45956359,"diff_hunk":"@@ -0,0 +1,160 @@\n+// Copyright (c) 2015 Intel Corporation. All rights reserved.\n+// Use of this source code is governed by a BSD-style license that can be\n+// found in the LICENSE file.\n+\n+package org.xwalk.app.runtime.extension;\n+\n+import android.util.Log;\n+\n+import java.lang.Byte;\n+import java.lang.Integer;\n+import java.nio.ByteBuffer;\n+import java.nio.ByteOrder;\n+import java.util.HashMap;\n+import java.util.Map;\n+\n+import org.json.JSONArray;\n+import org.json.JSONException;\n+import org.json.JSONObject;\n+\n+public class BindingObjectStore {\n+    private String TAG = \"BindingObjectStore\";\n+    private Map<String, BindingObject> mBindingObjects;\n+    private ExtensionInstanceHelper mInstance;\n+\n+    public BindingObjectStore(MessageHandler handler,\n+            ExtensionInstanceHelper instance) {\n+        mBindingObjects = new HashMap<String, BindingObject>();\n+        mInstance = instance;\n+        handler.register(\"JSObjectCollected\", \"onJSObjectCollected\", this);\n+        handler.register(\"postMessageToObject\", \"onPostMessageToObject\", this);\n+        handler.register(\"postMessageToClass\", \"onPostMessageToClass\", this);\n+    }\n+\n+    public boolean addBindingObject(String objectId, BindingObject obj) {\n+        if (mBindingObjects.containsKey(objectId)) {\n+            Log.w(TAG, \"Existing binding object:\\n\" + objectId);\n+            return false;\n+        }\n+\n+        obj.initBindingInfo(objectId, mInstance);\n+        mBindingObjects.put(objectId, obj);\n+        obj.onJsBinded();\n+        return true;\n+    }\n+\n+    public BindingObject getBindingObject(String objectId) {\n+       return mBindingObjects.get(objectId);\n+    }\n+\n+    public BindingObject removeBindingObject(String objectId) {\n+       BindingObject obj = mBindingObjects.remove(objectId);\n+       if (obj != null) obj.onJsDestroyed();\n+\n+       return obj;\n+    }\n+\n+    public void onJSObjectCollected(MessageInfo info) {\n+        removeBindingObject(info.getObjectId());\n+    }\n+\n+    public Object onPostMessageToClass(MessageInfo info) {\n+        Object result = null;\n+        JSONArray args = info.getArgs();\n+        try {\n+            // args format:\n+            // [memberName, [constructorJsName, memberArgs]]\n+            MessageInfo newInfo = new MessageInfo(info);\n+            String memberName = args.getString(0);\n+            JSONArray originArgs = args.getJSONArray(1);\n+            String cName = originArgs.getString(0);\n+            JSONArray memberArgs = originArgs.getJSONArray(1);\n+\n+            newInfo.setJsName(memberName);\n+            newInfo.setArgs(memberArgs);\n+\n+            ReflectionHelper reflection =\n+                info.getExtension().getTargetReflect(cName);\n+            // TODO(Donna): check the args with cName in [0].\n+            result = reflection.handleMessage(newInfo, null);\n+        } catch (JSONException e) {\n+            Log.e(TAG, e.toString());\n+        } catch (ReflectiveOperationException e) {\n+            Log.e(TAG, e.toString());\n+        }\n+        return result;\n+    }\n+\n+    public Object onPostMessageToObject(MessageInfo info) {\n+        Object result = null;\n+        try {\n+            BindingObject obj = getBindingObject(info.getObjectId());\n+\n+            MessageInfo newInfo = new MessageInfo(info);\n+            if (info.getArgs() != null) {\n+                JSONArray args = info.getArgs();\n+                String objectMethodName = args.getString(0);\n+                JSONArray objectMethodArgs = args.getJSONArray(1);\n+                newInfo.setJsName(objectMethodName);\n+                newInfo.setArgs(objectMethodArgs);\n+            } else {\n+                ByteBuffer args = info.getBinaryArgs();\n+                args.order(ByteOrder.LITTLE_ENDIAN);\n+                int byteOffset = args.position();\n+                int methodNameLen = args.getInt(byteOffset);\n+                byteOffset += Integer.SIZE / Byte.SIZE;\n+                int alignedMethodNameLen = methodNameLen + (4 - methodNameLen % 4);\n+                String objectMethodName = new String(args.array(), byteOffset, methodNameLen);\n+                byteOffset += alignedMethodNameLen;\n+                int len = args.array().length - byteOffset;\n+                ByteBuffer objectMethodArgs = ByteBuffer.wrap(args.array(), byteOffset, len);\n+                newInfo.setJsName(objectMethodName);\n+                newInfo.setBinaryArgs(objectMethodArgs);\n+            }\n+            if (obj != null)\n+                result = obj.handleMessage(newInfo);\n+        } catch (JSONException e) {\n+            Log.e(TAG, e.toString());\n+        } catch (IndexOutOfBoundsException e) {\n+            Log.e(TAG, e.toString());\n+        } catch (NullPointerException e) {\n+            Log.e(TAG, e.toString());","path":"app/android/runtime_client/src/org/xwalk/app/runtime/extension/BindingObjectStore.java","position":121,"original_position":121,"commit_id":"748137b83ee2e145236b915b0da92e2dea93950d","original_commit_id":"748137b83ee2e145236b915b0da92e2dea93950d","user":{"login":"halton","id":433218,"avatar_url":"https://avatars.githubusercontent.com/u/433218?v=3","gravatar_id":"","url":"https://api.github.com/users/halton","html_url":"https://github.com/halton","followers_url":"https://api.github.com/users/halton/followers","following_url":"https://api.github.com/users/halton/following{/other_user}","gists_url":"https://api.github.com/users/halton/gists{/gist_id}","starred_url":"https://api.github.com/users/halton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/halton/subscriptions","organizations_url":"https://api.github.com/users/halton/orgs","repos_url":"https://api.github.com/users/halton/repos","events_url":"https://api.github.com/users/halton/events{/privacy}","received_events_url":"https://api.github.com/users/halton/received_events","type":"User","site_admin":false},"body":"use || for above exceptions, I think current android sdk support that already.","created_at":"2015-11-26T09:12:10Z","updated_at":"2015-11-26T09:12:10Z","html_url":"https://github.com/crosswalk-project/crosswalk/pull/3420#discussion_r45956359","pull_request_url":"https://api.github.com/repos/crosswalk-project/crosswalk/pulls/3420","_links":{"self":{"href":"https://api.github.com/repos/crosswalk-project/crosswalk/pulls/comments/45956359"},"html":{"href":"https://github.com/crosswalk-project/crosswalk/pull/3420#discussion_r45956359"},"pull_request":{"href":"https://api.github.com/repos/crosswalk-project/crosswalk/pulls/3420"}}},"pull_request":{"url":"https://api.github.com/repos/crosswalk-project/crosswalk/pulls/3420","id":51611824,"html_url":"https://github.com/crosswalk-project/crosswalk/pull/3420","diff_url":"https://github.com/crosswalk-project/crosswalk/pull/3420.diff","patch_url":"https://github.com/crosswalk-project/crosswalk/pull/3420.patch","issue_url":"https://api.github.com/repos/crosswalk-project/crosswalk/issues/3420","number":3420,"state":"open","locked":false,"title":"[Android] BMI support on Java external extension infrastructure.","user":{"login":"DonnaWuDongxia","id":1028905,"avatar_url":"https://avatars.githubusercontent.com/u/1028905?v=3","gravatar_id":"","url":"https://api.github.com/users/DonnaWuDongxia","html_url":"https://github.com/DonnaWuDongxia","followers_url":"https://api.github.com/users/DonnaWuDongxia/followers","following_url":"https://api.github.com/users/DonnaWuDongxia/following{/other_user}","gists_url":"https://api.github.com/users/DonnaWuDongxia/gists{/gist_id}","starred_url":"https://api.github.com/users/DonnaWuDongxia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DonnaWuDongxia/subscriptions","organizations_url":"https://api.github.com/users/DonnaWuDongxia/orgs","repos_url":"https://api.github.com/users/DonnaWuDongxia/repos","events_url":"https://api.github.com/users/DonnaWuDongxia/events{/privacy}","received_events_url":"https://api.github.com/users/DonnaWuDongxia/received_events","type":"User","site_admin":false},"body":"This commit aimed to add BMI support to the external Java extension\r\ninfrastructure, including underline modules refining.\r\nDetails listed as follows:\r\n1. Refine the BindingObject and EventTarget implmentation.\r\n2. Add MessageHandler and MessageInfo to keep the compatibility\r\n   with customized extension JS code based on 'jsStub' module.\r\n   It means, registering the exposed API to MessageHandler instead\r\n   of annotating them.\r\n3. BMI support on both the 'jsStub' module and the Java side.\r\n4. A invert color sample to test the BMI support feature.\r\n\r\nBUG=XWALK-5602","created_at":"2015-11-24T03:05:00Z","updated_at":"2015-11-26T09:12:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d3ea413777a6e5074dec00df82f09b79095abdb2","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/crosswalk-project/crosswalk/pulls/3420/commits","review_comments_url":"https://api.github.com/repos/crosswalk-project/crosswalk/pulls/3420/comments","review_comment_url":"https://api.github.com/repos/crosswalk-project/crosswalk/pulls/comments{/number}","comments_url":"https://api.github.com/repos/crosswalk-project/crosswalk/issues/3420/comments","statuses_url":"https://api.github.com/repos/crosswalk-project/crosswalk/statuses/748137b83ee2e145236b915b0da92e2dea93950d","head":{"label":"DonnaWuDongxia:bmi","ref":"bmi","sha":"748137b83ee2e145236b915b0da92e2dea93950d","user":{"login":"DonnaWuDongxia","id":1028905,"avatar_url":"https://avatars.githubusercontent.com/u/1028905?v=3","gravatar_id":"","url":"https://api.github.com/users/DonnaWuDongxia","html_url":"https://github.com/DonnaWuDongxia","followers_url":"https://api.github.com/users/DonnaWuDongxia/followers","following_url":"https://api.github.com/users/DonnaWuDongxia/following{/other_user}","gists_url":"https://api.github.com/users/DonnaWuDongxia/gists{/gist_id}","starred_url":"https://api.github.com/users/DonnaWuDongxia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DonnaWuDongxia/subscriptions","organizations_url":"https://api.github.com/users/DonnaWuDongxia/orgs","repos_url":"https://api.github.com/users/DonnaWuDongxia/repos","events_url":"https://api.github.com/users/DonnaWuDongxia/events{/privacy}","received_events_url":"https://api.github.com/users/DonnaWuDongxia/received_events","type":"User","site_admin":false},"repo":{"id":12153023,"name":"crosswalk","full_name":"DonnaWuDongxia/crosswalk","owner":{"login":"DonnaWuDongxia","id":1028905,"avatar_url":"https://avatars.githubusercontent.com/u/1028905?v=3","gravatar_id":"","url":"https://api.github.com/users/DonnaWuDongxia","html_url":"https://github.com/DonnaWuDongxia","followers_url":"https://api.github.com/users/DonnaWuDongxia/followers","following_url":"https://api.github.com/users/DonnaWuDongxia/following{/other_user}","gists_url":"https://api.github.com/users/DonnaWuDongxia/gists{/gist_id}","starred_url":"https://api.github.com/users/DonnaWuDongxia/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DonnaWuDongxia/subscriptions","organizations_url":"https://api.github.com/users/DonnaWuDongxia/orgs","repos_url":"https://api.github.com/users/DonnaWuDongxia/repos","events_url":"https://api.github.com/users/DonnaWuDongxia/events{/privacy}","received_events_url":"https://api.github.com/users/DonnaWuDongxia/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/DonnaWuDongxia/crosswalk","description":"potential Tizen web runtime","fork":true,"url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk","forks_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/forks","keys_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/teams","hooks_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/hooks","issue_events_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/issues/events{/number}","events_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/events","assignees_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/assignees{/user}","branches_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/branches{/branch}","tags_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/tags","blobs_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/git/refs{/sha}","trees_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/statuses/{sha}","languages_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/languages","stargazers_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/stargazers","contributors_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/contributors","subscribers_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/subscribers","subscription_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/subscription","commits_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/commits{/sha}","git_commits_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/git/commits{/sha}","comments_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/comments{/number}","issue_comment_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/issues/comments{/number}","contents_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/contents/{+path}","compare_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/merges","archive_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/downloads","issues_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/issues{/number}","pulls_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/pulls{/number}","milestones_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/milestones{/number}","notifications_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/labels{/name}","releases_url":"https://api.github.com/repos/DonnaWuDongxia/crosswalk/releases{/id}","created_at":"2013-08-16T07:14:01Z","updated_at":"2015-05-05T10:30:54Z","pushed_at":"2015-11-25T07:39:45Z","git_url":"git://github.com/DonnaWuDongxia/crosswalk.git","ssh_url":"git@github.com:DonnaWuDongxia/crosswalk.git","clone_url":"https://github.com/DonnaWuDongxia/crosswalk.git","svn_url":"https://github.com/DonnaWuDongxia/crosswalk","homepage":"","size":14074,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"crosswalk-project:master","ref":"master","sha":"fcfdac08767bf84ac8c70dec3b1388ee282ed576","user":{"login":"crosswalk-project","id":4867377,"avatar_url":"https://avatars.githubusercontent.com/u/4867377?v=3","gravatar_id":"","url":"https://api.github.com/users/crosswalk-project","html_url":"https://github.com/crosswalk-project","followers_url":"https://api.github.com/users/crosswalk-project/followers","following_url":"https://api.github.com/users/crosswalk-project/following{/other_user}","gists_url":"https://api.github.com/users/crosswalk-project/gists{/gist_id}","starred_url":"https://api.github.com/users/crosswalk-project/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crosswalk-project/subscriptions","organizations_url":"https://api.github.com/users/crosswalk-project/orgs","repos_url":"https://api.github.com/users/crosswalk-project/repos","events_url":"https://api.github.com/users/crosswalk-project/events{/privacy}","received_events_url":"https://api.github.com/users/crosswalk-project/received_events","type":"Organization","site_admin":false},"repo":{"id":9207280,"name":"crosswalk","full_name":"crosswalk-project/crosswalk","owner":{"login":"crosswalk-project","id":4867377,"avatar_url":"https://avatars.githubusercontent.com/u/4867377?v=3","gravatar_id":"","url":"https://api.github.com/users/crosswalk-project","html_url":"https://github.com/crosswalk-project","followers_url":"https://api.github.com/users/crosswalk-project/followers","following_url":"https://api.github.com/users/crosswalk-project/following{/other_user}","gists_url":"https://api.github.com/users/crosswalk-project/gists{/gist_id}","starred_url":"https://api.github.com/users/crosswalk-project/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/crosswalk-project/subscriptions","organizations_url":"https://api.github.com/users/crosswalk-project/orgs","repos_url":"https://api.github.com/users/crosswalk-project/repos","events_url":"https://api.github.com/users/crosswalk-project/events{/privacy}","received_events_url":"https://api.github.com/users/crosswalk-project/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/crosswalk-project/crosswalk","description":"","fork":false,"url":"https://api.github.com/repos/crosswalk-project/crosswalk","forks_url":"https://api.github.com/repos/crosswalk-project/crosswalk/forks","keys_url":"https://api.github.com/repos/crosswalk-project/crosswalk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/crosswalk-project/crosswalk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/crosswalk-project/crosswalk/teams","hooks_url":"https://api.github.com/repos/crosswalk-project/crosswalk/hooks","issue_events_url":"https://api.github.com/repos/crosswalk-project/crosswalk/issues/events{/number}","events_url":"https://api.github.com/repos/crosswalk-project/crosswalk/events","assignees_url":"https://api.github.com/repos/crosswalk-project/crosswalk/assignees{/user}","branches_url":"https://api.github.com/repos/crosswalk-project/crosswalk/branches{/branch}","tags_url":"https://api.github.com/repos/crosswalk-project/crosswalk/tags","blobs_url":"https://api.github.com/repos/crosswalk-project/crosswalk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/crosswalk-project/crosswalk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/crosswalk-project/crosswalk/git/refs{/sha}","trees_url":"https://api.github.com/repos/crosswalk-project/crosswalk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/crosswalk-project/crosswalk/statuses/{sha}","languages_url":"https://api.github.com/repos/crosswalk-project/crosswalk/languages","stargazers_url":"https://api.github.com/repos/crosswalk-project/crosswalk/stargazers","contributors_url":"https://api.github.com/repos/crosswalk-project/crosswalk/contributors","subscribers_url":"https://api.github.com/repos/crosswalk-project/crosswalk/subscribers","subscription_url":"https://api.github.com/repos/crosswalk-project/crosswalk/subscription","commits_url":"https://api.github.com/repos/crosswalk-project/crosswalk/commits{/sha}","git_commits_url":"https://api.github.com/repos/crosswalk-project/crosswalk/git/commits{/sha}","comments_url":"https://api.github.com/repos/crosswalk-project/crosswalk/comments{/number}","issue_comment_url":"https://api.github.com/repos/crosswalk-project/crosswalk/issues/comments{/number}","contents_url":"https://api.github.com/repos/crosswalk-project/crosswalk/contents/{+path}","compare_url":"https://api.github.com/repos/crosswalk-project/crosswalk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/crosswalk-project/crosswalk/merges","archive_url":"https://api.github.com/repos/crosswalk-project/crosswalk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/crosswalk-project/crosswalk/downloads","issues_url":"https://api.github.com/repos/crosswalk-project/crosswalk/issues{/number}","pulls_url":"https://api.github.com/repos/crosswalk-project/crosswalk/pulls{/number}","milestones_url":"https://api.github.com/repos/crosswalk-project/crosswalk/milestones{/number}","notifications_url":"https://api.github.com/repos/crosswalk-project/crosswalk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/crosswalk-project/crosswalk/labels{/name}","releases_url":"https://api.github.com/repos/crosswalk-project/crosswalk/releases{/id}","created_at":"2013-04-03T23:30:12Z","updated_at":"2015-11-26T08:15:09Z","pushed_at":"2015-11-26T09:05:54Z","git_url":"git://github.com/crosswalk-project/crosswalk.git","ssh_url":"git@github.com:crosswalk-project/crosswalk.git","clone_url":"https://github.com/crosswalk-project/crosswalk.git","svn_url":"https://github.com/crosswalk-project/crosswalk","homepage":"https://crosswalk-project.org/","size":116787,"stargazers_count":1140,"watchers_count":1140,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":317,"mirror_url":null,"open_issues_count":108,"forks":317,"open_issues":108,"watchers":1140,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/crosswalk-project/crosswalk/pulls/3420"},"html":{"href":"https://github.com/crosswalk-project/crosswalk/pull/3420"},"issue":{"href":"https://api.github.com/repos/crosswalk-project/crosswalk/issues/3420"},"comments":{"href":"https://api.github.com/repos/crosswalk-project/crosswalk/issues/3420/comments"},"review_comments":{"href":"https://api.github.com/repos/crosswalk-project/crosswalk/pulls/3420/comments"},"review_comment":{"href":"https://api.github.com/repos/crosswalk-project/crosswalk/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/crosswalk-project/crosswalk/pulls/3420/commits"},"statuses":{"href":"https://api.github.com/repos/crosswalk-project/crosswalk/statuses/748137b83ee2e145236b915b0da92e2dea93950d"}}}}