org.xwalk.core.XWalkView Java Examples

The following examples show how to use org.xwalk.core.XWalkView. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CrosswalkWebViewGroupManager.java    From react-native-crosswalk-webview-plus with MIT License 6 votes vote down vote up
@Override
public void receiveCommand (CrosswalkWebView view, int commandId, @Nullable ReadableArray args) {
    switch (commandId) {
        case GO_BACK:
            view.getNavigationHistory().navigate(XWalkNavigationHistory.Direction.BACKWARD, 1);
            break;
        case GO_FORWARD:
            view.getNavigationHistory().navigate(XWalkNavigationHistory.Direction.FORWARD, 1);
            break;
        case RELOAD:
            view.reload(XWalkView.RELOAD_NORMAL);
            break;
        case LOAD:
            view.load(args.getString(0),null);
            break;
        case POST_MESSAGE:
            try {
                JSONObject eventInitDict = new JSONObject();
                eventInitDict.put("data", args.getString(0));
                view.evaluateJavascript("document.dispatchEvent(new MessageEvent('message', " + eventInitDict.toString() + "))", null);
            } catch (JSONException e) {
                throw new RuntimeException(e);
            }
            break;
    }
}
 
Example #2
Source File: CornUIClient.java    From Cornowser with MIT License 6 votes vote down vote up
@Override
public boolean onJsPrompt(XWalkView view, String url, String message, String defaultValue, XWalkJavascriptResult result) {
    final XWalkJavascriptResult fResult = result;
    final EditTextDialog d = new EditTextDialog(CornBrowser.getContext(),
            (XquidCompatActivity) CornBrowser.getActivity(),
            message,
            defaultValue);
    d.setOnClickListener(new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            fResult.confirmWithResult(d.getEnteredText());
            dialog.dismiss();
        }
    });
    d.showDialog();


    return true;
}
 
Example #3
Source File: MainActivity.java    From ello-android with MIT License 6 votes vote down vote up
@Override
public void openFileChooser(
        XWalkView view,
        ValueCallback<Uri> uploadMsg,
        String acceptType,
        String capture)
{
    boolean hasPermission = checkPermissions();
    if(hasPermission) {
        super.openFileChooser(view, uploadMsg, acceptType, capture);
    }
    else {
        this.view = view;
        this.uploadMsg = uploadMsg;
        this.acceptType = acceptType;
        this.capture = capture;
    }
}
 
Example #4
Source File: XWalkCordovaResourceClient.java    From cordova-crosswalk-engine with Apache License 2.0 6 votes vote down vote up
/**
* Notify the host application that an SSL error occurred while loading a
* resource. The host application must call either callback.onReceiveValue(true)
* or callback.onReceiveValue(false). Note that the decision may be
* retained for use in response to future SSL errors. The default behavior
* is to pop up a dialog.
*/
@Override
public void onReceivedSslError(XWalkView view, ValueCallback<Boolean> callback, SslError error) {
    final String packageName = parentEngine.cordova.getActivity().getPackageName();
    final PackageManager pm = parentEngine.cordova.getActivity().getPackageManager();

    ApplicationInfo appInfo;
    try {
        appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
        if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
            // debug = true
            callback.onReceiveValue(true);
        } else {
            // debug = false
            callback.onReceiveValue(false);
        }
    } catch (PackageManager.NameNotFoundException e) {
        // When it doubt, lock it out!
        callback.onReceiveValue(false);
    }
}
 
Example #5
Source File: CordovaChromeClient.java    From crosswalk-cordova-android with Apache License 2.0 6 votes vote down vote up
/**
 * Notify the host application that a page has started loading.
 * This method is called once for each main frame load so a page with iframes or framesets will call onPageStarted
 * one time for the main frame. This also means that onPageStarted will not be called when the contents of an
 * embedded frame changes, i.e. clicking a link whose target is an iframe.
 *
 * @param view          The webview initiating the callback.
 * @param url           The url of the page.
 */
@Override
public void onPageLoadStarted(XWalkView view, String url) {
    isCurrentlyLoading = true;

    // Flush stale messages.
    this.appView.bridge.reset(url);

    // Broadcast message that page has loaded
    this.appView.postMessage("onPageStarted", url);

    // Notify all plugins of the navigation, so they can clean up if necessary.
    if (this.appView.pluginManager != null) {
        this.appView.pluginManager.onReset();
    }
}
 
Example #6
Source File: CrosswalkWebView.java    From react-native-crosswalk-webview-plus with MIT License 6 votes vote down vote up
@Override
public boolean shouldOverrideUrlLoading (XWalkView view, String url) {
    Uri uri = Uri.parse(url);
    if (uri.getScheme().equals(CrosswalkWebViewManager.JSNavigationScheme)) {
        onLoadFinished(view, url);
        return true;
    }
    else if (getLocalhost()) {
        if (uri.getHost().equals("localhost")) {
            return false;
        }
        else {
            overrideUri(uri);
            return true;
        }
    }
    else if (uri.getScheme().equals("http") || uri.getScheme().equals("https") || uri.getScheme().equals("file")) {
        return false;
    }
    else {
        overrideUri(uri);
        return true;
    }
}
 
Example #7
Source File: XWalkCordovaUiClient.java    From cordova-crosswalk-engine with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onJavascriptModalDialog(XWalkView view, JavascriptMessageType type, String url,
                                       String message, String defaultValue, XWalkJavascriptResult result) {
    switch (type) {
        case JAVASCRIPT_ALERT:
            return onJsAlert(view, url, message, result);
        case JAVASCRIPT_CONFIRM:
            return onJsConfirm(view, url, message, result);
        case JAVASCRIPT_PROMPT:
            return onJsPrompt(view, url, message, defaultValue, result);
        case JAVASCRIPT_BEFOREUNLOAD:
            // Reuse onJsConfirm to show the dialog.
            return onJsConfirm(view, url, message, result);
        default:
            break;
    }
    assert (false);
    return false;
}
 
Example #8
Source File: CrosswalkWebViewGroupManager.java    From react-native-webview-crosswalk with MIT License 6 votes vote down vote up
@Override
public void receiveCommand (CrosswalkWebView view, int commandId, @Nullable ReadableArray args) {
    switch (commandId) {
        case GO_BACK:
            view.getNavigationHistory().navigate(XWalkNavigationHistory.Direction.BACKWARD, 1);
            break;
        case GO_FORWARD:
            view.getNavigationHistory().navigate(XWalkNavigationHistory.Direction.FORWARD, 1);
            break;
        case RELOAD:
            view.reload(XWalkView.RELOAD_NORMAL);
            break;
        case POST_MESSAGE:
            try {
                JSONObject eventInitDict = new JSONObject();
                eventInitDict.put("data", args.getString(0));
                view.evaluateJavascript("document.dispatchEvent(new MessageEvent('message', " + eventInitDict.toString() + "))", null);
            } catch (JSONException e) {
                throw new RuntimeException(e);
            }
            break;
    }
}
 
Example #9
Source File: CrosswalkWebView.java    From react-native-crosswalk-webview-plus with MIT License 6 votes vote down vote up
@Override
public void onLoadStarted (XWalkView view, String url) {
   if(!url.equals("")){
    XWalkNavigationHistory navigationHistory = view.getNavigationHistory();
    if(navigationHistory!=null)
    eventDispatcher.dispatchEvent(
        new NavigationStateChangeEvent(
            getId(),
            SystemClock.uptimeMillis(),
            view.getTitle(),
            true,
            url,
            navigationHistory.canGoBack(),
            navigationHistory.canGoForward()
        )
    );
}
}
 
Example #10
Source File: CrosswalkWebView.java    From react-native-webview-crosswalk with MIT License 6 votes vote down vote up
@Override
public void onLoadFinished (XWalkView view, String url) {
    ((CrosswalkWebView) view).linkBridge();
    ((CrosswalkWebView) view).callInjectedJavaScript();

    XWalkNavigationHistory navigationHistory = view.getNavigationHistory();
    eventDispatcher.dispatchEvent(
        new NavigationStateChangeEvent(
            getId(),
            SystemClock.uptimeMillis(),
            view.getTitle(),
            false,
            url,
            navigationHistory.canGoBack(),
            navigationHistory.canGoForward()
        )
    );

}
 
Example #11
Source File: CordovaWebViewClient.java    From crosswalk-cordova-android with Apache License 2.0 6 votes vote down vote up
/**
* Notify the host application that an SSL error occurred while loading a
* resource. The host application must call either callback.onReceiveValue(true)
* or callback.onReceiveValue(false). Note that the decision may be
* retained for use in response to future SSL errors. The default behavior
* is to pop up a dialog.
*/
public void onReceivedSslError(XWalkView view, ValueCallback<Boolean> callback, SslError error) {
    final String packageName = this.cordova.getActivity().getPackageName();
    final PackageManager pm = this.cordova.getActivity().getPackageManager();

    ApplicationInfo appInfo;
    try {
        appInfo = pm.getApplicationInfo(packageName, PackageManager.GET_META_DATA);
        if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
            // debug = true
            callback.onReceiveValue(true);
            return;
        } else {
            // debug = false
            callback.onReceiveValue(false);
        }
    } catch (NameNotFoundException e) {
        // When it doubt, lock it out!
        callback.onReceiveValue(false);
    }
}
 
Example #12
Source File: CrosswalkWebView.java    From react-native-webview-crosswalk with MIT License 6 votes vote down vote up
@Override
public boolean shouldOverrideUrlLoading (XWalkView view, String url) {
    Uri uri = Uri.parse(url);
    if (uri.getScheme().equals(CrosswalkWebViewManager.JSNavigationScheme)) {
        onLoadFinished(view, url);
        return true;
    }
    else if (getLocalhost()) {
        if (uri.getHost().equals("localhost")) {
            return false;
        }
        else {
            overrideUri(uri);
            return true;
        }
    }
    else if (uri.getScheme().equals("http") || uri.getScheme().equals("https") || uri.getScheme().equals("file")) {
        return false;
    }
    else {
        overrideUri(uri);
        return true;
    }
}
 
Example #13
Source File: CornUIClient.java    From Cornowser with MIT License 6 votes vote down vote up
@Override
public void onIconAvailable(XWalkView view, String url, Message startDownload) {
    final CrunchyWalkView fView = CrunchyWalkView.fromXWalkView(view);
    final String fUrl = url;
    final Handler handler = new Handler();
    final Runnable tintNowRunnable = new Runnable() {
        @Override
        public void run() {
            WebThemeHelper.tintNow();
        }
    };
    Thread downIcon = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                InputStream inputStream = DownloadUtils.getInputStreamForConnection(fUrl);
                fView.favicon = BitmapFactory.decodeStream(inputStream);
                handler.post(tintNowRunnable);
            } catch(Exception ex) {
                StackTraceParser.logStackTrace(ex);
            }
        }
    });
    downIcon.start();
}
 
Example #14
Source File: CordovaChromeClient.java    From crosswalk-cordova-android with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onJavascriptModalDialog(XWalkView view, JavascriptMessageType type, String url,
        String message, String defaultValue, XWalkJavascriptResult result) {
    switch(type) {
        case JAVASCRIPT_ALERT:
            return onJsAlert(view, url, message, result);
        case JAVASCRIPT_CONFIRM:
            return onJsConfirm(view, url, message, result);
        case JAVASCRIPT_PROMPT:
            return onJsPrompt(view, url, message, defaultValue, result);
        case JAVASCRIPT_BEFOREUNLOAD:
            // Reuse onJsConfirm to show the dialog.
            return onJsConfirm(view, url, message, result);
        default:
            break;
    }
    assert(false);
    return false;
}
 
Example #15
Source File: CordovaWebViewClient.java    From crosswalk-cordova-android with Apache License 2.0 6 votes vote down vote up
/**
 * Report an error to the host application. These errors are unrecoverable (i.e. the main resource is unavailable).
 * The errorCode parameter corresponds to one of the ERROR_* constants.
 *
 * @param view          The WebView that is initiating the callback.
 * @param errorCode     The error code corresponding to an ERROR_* value.
 * @param description   A String describing the error.
 * @param failingUrl    The url that failed to load.
 */
@Override
public void onReceivedLoadError(XWalkView view, int errorCode, String description,
        String failingUrl) {
    LOG.d(TAG, "CordovaWebViewClient.onReceivedError: Error code=%s Description=%s URL=%s", errorCode, description, failingUrl);

    // Clear timeout flag
    this.appView.loadUrlTimeout++;

    // Handle error
    JSONObject data = new JSONObject();
    try {
        data.put("errorCode", errorCode);
        data.put("description", description);
        data.put("url", failingUrl);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    this.appView.postMessage("onReceivedError", data);
}
 
Example #16
Source File: CBrowserWindow.java    From appcan-android with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onProgressChanged(XWalkView view, int progressInPercent) {
	if (view != null && view instanceof EBrowserView) {
		EBrowserView target = (EBrowserView)view;
		EBrowserWindow bWindow = target.getBrowserWindow();
		if (bWindow != null) {
			bWindow.setGlobalProgress(progressInPercent);
			if (100 == progressInPercent) {
				bWindow.hiddenProgress();
			}
		}
	}else{
		if (view!=null) {
			BDebug.i("CBrowserWindow onProgressChanged: view is not instanceof EBrowserView,type is",
					view.getClass().getName());
		}
	}
}
 
Example #17
Source File: GameXWalkView.java    From kcanotify_h5-master with GNU General Public License v3.0 6 votes vote down vote up
private void detectAndHandleLoginError(XWalkView view, SharedPreferences prefs) {
    // For DMM only
    if(view.getUrl() != null && view.getUrl().equals("http://www.dmm.com/top/-/error/area/") && prefs.getBoolean("change_cookie_start", false) && changeCookieCnt++ < 5) {
        Log.i("KCVA", "Change Cookie");

        new Handler().postDelayed(new Runnable(){
            public void run() {
                Set<Map.Entry<String, String>> dmmCookieMapSet = gameActivity.dmmCookieMap.entrySet();
                for (Map.Entry<String, String> dmmCookieMapEntry : dmmCookieMapSet) {
                    view.evaluateJavascript("javascript:document.cookie = '" + dmmCookieMapEntry.getKey() + "';", new ValueCallback<String>() {
                        @Override
                        public void onReceiveValue(String value) {
                            Log.i("KCVA", value);
                        }
                    });
                }
                view.loadUrl(GameConnection.DMM_START_URL);
            }
        }, 5000);
    }
}
 
Example #18
Source File: BridgeHelper.java    From freeiot-android with MIT License 5 votes vote down vote up
@Override
public void onLoadStarted(XWalkView view, String url) {
	super.onLoadStarted(view, url);
          LogUtils.e("onPageStarted=>" + url);
	if (mLoadingListener != null) {
		mLoadingListener.onPageStart();
	}
}
 
Example #19
Source File: CrosswalkWebView.java    From react-native-crosswalk-webview-plus with MIT License 5 votes vote down vote up
@Override
public void onLoadFinished (XWalkView view, String url) {
   if(!url.equals("")){
       ((CrosswalkWebView) view).linkBridge();
       ((CrosswalkWebView) view).callInjectedJavaScript();

       XWalkNavigationHistory navigationHistory = view.getNavigationHistory();
       eventDispatcher.dispatchEvent(
           new LoadFinishedEvent(
               getId(),
               SystemClock.uptimeMillis()
           )
       );
       if(navigationHistory!=null)
       eventDispatcher.dispatchEvent(
           new NavigationStateChangeEvent(
               getId(),
               SystemClock.uptimeMillis(),
               view.getTitle(),
               false,
               url,
               navigationHistory.canGoBack(),
               navigationHistory.canGoForward()
           )
       );
   }

}
 
Example #20
Source File: MainActivity.java    From ello-android with MIT License 5 votes vote down vote up
@Override
public boolean shouldOverrideUrlLoading(XWalkView view, String url) {
    if (ElloURI.shouldLoadInApp(url)) {
        return false;
    }
    else {
        MainActivity.this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
        return true;
    }
}
 
Example #21
Source File: CBrowserMainFrame.java    From appcan-android with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean onConsoleMessage(XWalkView view, String message,
                                int lineNumber, String sourceId, ConsoleMessageType messageType) {
    if (WDataManager.sRootWgt!=null&&WDataManager.sRootWgt.m_appdebug==1 && !TextUtils.isEmpty(WDataManager.sRootWgt.m_logServerIp)) {
        if (messageType !=ConsoleMessageType.WARNING) {//过滤掉warning
            BDebug.sendUDPLog(formatConsole(message,lineNumber,sourceId,messageType));
        }
    }
    return super.onConsoleMessage(view, message, lineNumber, sourceId,
            messageType);
}
 
Example #22
Source File: CornResourceClient.java    From Cornowser with MIT License 5 votes vote down vote up
@Override
public void onProgressChanged(XWalkView view, int percentage) {
    super.onProgressChanged(view, percentage);
    Logging.logd("Actual loading progress: " + percentage);
    CrunchyWalkView.fromXWalkView(view).currentProgress = percentage;
    CornBrowser.updateWebProgress();
    if(percentage > 40)
        CornBrowser.getOmniPtrLayout().setRefreshing(false);
}
 
Example #23
Source File: XWalkCordovaUiClient.java    From cordova-crosswalk-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Tell the client to display a javascript alert dialog.
 */
public boolean onJsAlert(XWalkView view, String url, String message,
                          final XWalkJavascriptResult result) {
    dialogsHelper.showAlert(message, new CordovaDialogsHelper.Result() {
        @Override
        public void gotResult(boolean success, String value) {
            if (success) {
                result.confirm();
            } else {
                result.cancel();
            }
        }
    });
    return true;
}
 
Example #24
Source File: GameXWalkView.java    From kcanotify_h5-master with GNU General Public License v3.0 5 votes vote down vote up
private void detectGameStartAndFit(XWalkView view) {
    if (view.getUrl() != null && view.getUrl().contains(hostNameOoi)) {
        fitGameLayout();
    }
    if (view.getUrl() != null && view.getUrl().equals(GameConnection.DMM_START_URL)) {
        fitGameLayout();
    }
}
 
Example #25
Source File: CornResourceClient.java    From Cornowser with MIT License 5 votes vote down vote up
@Override
public boolean shouldOverrideUrlLoading(XWalkView view, String url) {
    if(url.toLowerCase().startsWith("cornhandler://")) {
        CornHandler.handleRequest(
                url,
                CornBrowser.getActivity(),
                CrunchyWalkView.fromXWalkView(view),
                view.getUrl(),
                this);
        return true;
    }
    CornBrowser.resetOmniPositionState(true);
    Logging.logd("Starting url loading '" + url + "'");
    return super.shouldOverrideUrlLoading(view, url);
}
 
Example #26
Source File: CrosswalkWebView.java    From react-native-webview-crosswalk with MIT License 5 votes vote down vote up
@Override
public void onLoadStarted (XWalkView view, String url) {
    XWalkNavigationHistory navigationHistory = view.getNavigationHistory();
    eventDispatcher.dispatchEvent(
        new NavigationStateChangeEvent(
            getId(),
            SystemClock.uptimeMillis(),
            view.getTitle(),
            true,
            url,
            navigationHistory.canGoBack(),
            navigationHistory.canGoForward()
        )
    );
}
 
Example #27
Source File: CrosswalkWebView.java    From react-native-webview-crosswalk with MIT License 5 votes vote down vote up
@Override
public void onReceivedLoadError (XWalkView view, int errorCode, String description, String failingUrl) {
    eventDispatcher.dispatchEvent(
        new ErrorEvent(
            getId(),
            SystemClock.uptimeMillis(),
            errorCode,
            description,
            failingUrl
        )
    );
}
 
Example #28
Source File: XWalkCordovaUiClient.java    From cordova-crosswalk-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Notify the host application that a page has started loading.
 * This method is called once for each main frame load so a page with iframes or framesets will call onPageLoadStarted
 * one time for the main frame. This also means that onPageLoadStarted will not be called when the contents of an
 * embedded frame changes, i.e. clicking a link whose target is an iframe.
 *
 * @param view The webView initiating the callback.
 * @param url  The url of the page.
 */
@Override
public void onPageLoadStarted(XWalkView view, String url) {
    LOG.d(TAG, "onPageLoadStarted(" + url + ")");
    if (view.getUrl() != null) {
        // Flush stale messages.
        parentEngine.client.onPageStarted(url);
        parentEngine.bridge.reset();
    }
}
 
Example #29
Source File: XWalkCordovaResourceClient.java    From cordova-crosswalk-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceivedHttpAuthRequest(XWalkView view, XWalkHttpAuthHandler handler,
        String host, String realm) {
    // Check if there is some plugin which can resolve this auth challenge
    PluginManager pluginManager = parentEngine.pluginManager;
    if (pluginManager != null && pluginManager.onReceivedHttpAuthRequest(
            parentEngine.parentWebView,
            new XWalkCordovaHttpAuthHandler(handler), host, realm)) {
        parentEngine.client.clearLoadTimeoutTimer();
        return;
    }

    // By default handle 401 like we'd normally do!
    super.onReceivedHttpAuthRequest(view, handler, host, realm);
}
 
Example #30
Source File: XWalkCordovaUiClient.java    From cordova-crosswalk-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Tell the client to display a confirm dialog to the user.
 */
public boolean onJsConfirm(XWalkView view, String url, String message,
                            final XWalkJavascriptResult result) {
    dialogsHelper.showConfirm(message, new CordovaDialogsHelper.Result() {
        @Override
        public void gotResult(boolean success, String value) {
            if (success) {
                result.confirm();
            } else {
                result.cancel();
            }
        }
    });
    return true;
}