infil00p / cordova-crosswalk-engine

(UNMAINTAINED) Proof of Concept Third Party Web Engine using Crosswalk
Apache License 2.0
46 stars 440 forks source link

Override XWalkCordovaResourceClient#onReceivedLoadError in onCreate #49

Closed aroth closed 8 years ago

aroth commented 8 years ago

Is it possible to override onReceivedLoadError in MainActivity#onCreate? With the cordova crosswalk plugin, onReceivedLoadError is defined in XWalkCordovaResourceClient, but I'd like to define my own functionality without having to edit that file.

I had something that almost worked ---- but my custom Cordova plugins were no longer called. I suspect I was overriding an existing hook incorrectly:

public class MainActivity extends CordovaActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.init();
        XWalkView webView = ((XWalkView) this.appView.getEngine().getView());
        initializeXWalkViewClients(webView);
        loadUrl(launchUrl);
    }

    private void initializeXWalkViewClients(XWalkView xwalkView) {
        xwalkView.setResourceClient(new XWalkResourceClient(xwalkView) {
                @Override
                public void onReceivedLoadError(XWalkView view, int errorCode, String description,
                             String failingUrl) {
                                       // ...
                }
        });
    }

Any thoughts?

fujunwei commented 8 years ago

You can get the message like CordovaActivity.java

 /**
     * Called when a message is sent to plugin.
     *
     * @param id            The message id
     * @param data          The message data
     * @return              Object or null
     */
    public Object onMessage(String id, Object data) {
        if ("onReceivedError".equals(id)) {
            JSONObject d = (JSONObject) data;
            try {
                this.onReceivedError(d.getInt("errorCode"), d.getString("description"), d.getString("url"));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } else if ("exit".equals(id)) {
            finish();
        }
        return null;
    }
aroth commented 8 years ago

That worked -- thank you.