// Copyright (c) 2015 Intel Corporation. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

package org.xwalk.extensions.realsense.enhancedphotography;

import android.app.Activity;
import android.util.Log;

import org.xwalk.app.runtime.extension.XWalkExtensionClient;
import org.xwalk.app.runtime.extension.XWalkExtensionContextClient;
import org.xwalk.extensions.common.*;

public class EnhancedPhotographyExtension extends XWalkExtensionClient {
    private static final String TAG = "EnhancedPhotographyExtension";
    protected XWalkExtensionContextClient mExtensionContextClient = null;
    private BindingObjectStore mBindingObjectStore;
    private FunctionHandler mHandler;

    public EnhancedPhotographyExtension(
            String name, String jsApiContent, XWalkExtensionContextClient xwalkContext) {
        super(name, jsApiContent, xwalkContext);
        mExtensionContextClient = xwalkContext;
        mHandler = new FunctionHandler();
        mBindingObjectStore = new BindingObjectStore(mHandler);

        mHandler.register("enhancedPhotographyConstructor", this);
    }

    private void handleMessage(int instanceID, String message) {
        FunctionInfo info = new FunctionInfo(this, instanceID, message);
        mHandler.handleFunction(info);
    }

    public void onEnhancedPhotographyConstructor(FunctionInfo info) {
        EnhancedPhotographyObject ep = new EnhancedPhotographyObject(mExtensionContextClient);
        mBindingObjectStore.addBindingObject(info.getObjectId(), ep);
    }

    @Override
    public void onMessage(int instanceID, String message) {
        if (!message.isEmpty()) handleMessage(instanceID, message);
    }

    @Override
    public String onSyncMessage(int instanceID, String message) {
        return null;
    }

    @Override
    public void onStart() {
        mBindingObjectStore.onStart();
        super.onStart();
    }

    @Override
    public void onResume() {
        mBindingObjectStore.onResume();
        super.onResume();
    }

    @Override
    public void onPause() {
        mBindingObjectStore.onPause();
        super.onPause();
    }

    @Override
    public void onStop() {
        mBindingObjectStore.onStop();
        super.onStop();
    }

    @Override
    public void onDestroy() {
        mBindingObjectStore.onDestroy();
        super.onDestroy();
    }
}

@@ -1341,24 +1341,214 @@
 fo);%0A    %7D%0A%0A
+    private void handleBinaryMessage(int instanceID, byte%5B%5D message) %7B%0A        FunctionInfo info = new FunctionInfo(this, instanceID, message);%0A        mHandler.handleFunction(info);%0A    %7D%0A%0A
     public v
@@ -1918,32 +1918,190 @@
 essage);%0A    %7D%0A%0A
+    @Override%0A    public void onBinaryMessage(int instanceID, byte%5B%5D message) %7B%0A        if (message != null) handleBinaryMessage(instanceID, message);%0A    %7D%0A%0A
     @Override%0A  

Add handleBinaryMessage interface