Java源码示例:org.xwalk.core.XWalkView

示例1
@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;
}
 
示例2
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);
    }
}
 
示例3
@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());
		}
	}
}
 
示例4
/**
 * 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);
}
 
示例5
/**
* 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);
    }
}
 
示例6
@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;
    }
}
 
示例7
@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()
        )
    );
}
}
 
示例8
@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;
    }
}
 
示例9
@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;
    }
}
 
示例10
@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;
    }
}
 
示例11
@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()
        )
    );

}
 
示例12
@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;
    }
}
 
示例13
/**
 * 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();
    }
}
 
示例14
@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();
}
 
示例15
@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;
}
 
示例16
@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;
}
 
示例17
/**
* 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);
    }
}
 
示例18
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();
    }
}
 
示例19
@Override
public void openFileChooser(XWalkView view, ValueCallback<Uri> uploadFile,
                            String acceptType, String capture) {
    ((EBrowserActivity) view.getContext()).setmUploadMessage(getCompatCallback(uploadFile));
    Intent i = new Intent(Intent.ACTION_GET_CONTENT);
    i.addCategory(Intent.CATEGORY_OPENABLE);
    i.setType("*/*");
    ((EBrowserActivity) view.getContext()).startActivityForResult(
            Intent.createChooser(i, "File Chooser"),
            EBrowserActivity.FILECHOOSER_RESULTCODE);
}
 
示例20
@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);
}
 
示例21
@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()
           )
       );
   }

}
 
示例22
@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;
    }
}
 
示例23
/**
 * 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;
}
 
示例24
@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()
        )
    );
}
 
示例25
@Override
public void onReceivedLoadError (XWalkView view, int errorCode, String description, String failingUrl) {
    eventDispatcher.dispatchEvent(
        new ErrorEvent(
            getId(),
            SystemClock.uptimeMillis(),
            errorCode,
            description,
            failingUrl
        )
    );
}
 
示例26
/**
 * 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();
    }
}
 
示例27
/**
 * 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;
}
 
示例28
@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);
}
 
示例29
@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);
}
 
示例30
@Override
public void onLoadStarted(XWalkView view, String url) {
    super.onLoadStarted(view, url);
    if(CrunchyWalkView.fromXWalkView(view).currentProgress < 100) {
        CornBrowser.applyInsideOmniText();
        WebThemeHelper.tintNow();
        CornBrowser.publicWebRender.drawWithColorMode();
    }
}