Search in sources :

Example 1 with WebChromeClient

use of android.webkit.WebChromeClient in project android by cSploit.

the class HijackerWebView method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    SharedPreferences themePrefs = getSharedPreferences("THEME", 0);
    Boolean isDark = themePrefs.getBoolean("isDark", false);
    if (isDark)
        setTheme(R.style.DarkTheme);
    else
        setTheme(R.style.AppTheme);
    super.onCreate(savedInstanceState);
    supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    supportRequestWindowFeature(Window.FEATURE_PROGRESS);
    setTitle(System.getCurrentTarget() + " > MITM > Session Hijacker");
    setContentView(R.layout.plugin_mitm_hijacker_webview);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    mWebView = (WebView) findViewById(R.id.webView);
    mWebView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    mProgressBar = (ProgressBar) findViewById(R.id.webprogress);
    mURLet = (EditText) findViewById(R.id.url);
    mProgressBar.setVisibility(View.GONE);
    mProgressBar.setMax(100);
    mSettings = mWebView.getSettings();
    mSettings.setJavaScriptEnabled(true);
    mSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    mSettings.setBuiltInZoomControls(true);
    mSettings.setAppCacheEnabled(false);
    mSettings.setUserAgentString(DEFAULT_USER_AGENT);
    mSettings.setUseWideViewPort(true);
    mURLet.setOnEditorActionListener(new EditText.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_ACTION_NEXT) {
                mWebView.loadUrl(mURLet.getText().toString());
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(mWebView.getWindowToken(), 0);
                mWebView.requestFocus();
                return true;
            }
            return false;
        }
    });
    mURLet.setOnKeyListener(new EditText.OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
                mWebView.loadUrl(mURLet.getText().toString());
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(mWebView.getWindowToken(), 0);
                mWebView.requestFocus();
                return true;
            }
            return false;
        }
    });
    mWebView.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            mURLet.setText(url);
            return true;
        }
    });
    mWebView.setWebChromeClient(new WebChromeClient() {

        public void onProgressChanged(WebView view, int progress) {
            if ((mWebView != null) && (mURLet != null) && (progress == 0))
                ;
            {
                getSupportActionBar().setSubtitle(mWebView.getUrl());
                mURLet.setText(mWebView.getUrl());
            }
            if (mProgressBar != null) {
                mProgressBar.setVisibility(View.VISIBLE);
                // Normalize our progress along the progress bar's scale
                mProgressBar.setProgress(progress);
                if (progress == 100) {
                    mProgressBar.setVisibility(View.GONE);
                }
            }
        }
    });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        CookieManager cm = CookieManager.getInstance();
        cm.flush();
    } else {
        CookieSyncManager.createInstance(this);
        CookieManager.getInstance().removeAllCookie();
    }
    Session session = (Session) System.getCustomData();
    if (session != null) {
        String domain = null, rawcookie = null;
        for (HttpCookie cookie : session.mCookies.values()) {
            domain = cookie.getDomain();
            rawcookie = cookie.getName() + "=" + cookie.getValue() + "; domain=" + domain + "; path=/" + (session.mHTTPS ? ";secure" : "");
            CookieManager.getInstance().setCookie(domain, rawcookie);
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            CookieManager cm = CookieManager.getInstance();
            cm.flush();
        } else {
            CookieSyncManager.getInstance().startSync();
        }
        if (session.mUserAgent != null && session.mUserAgent.isEmpty() == false)
            mSettings.setUserAgentString(session.mUserAgent);
        String url = (session.mHTTPS ? "https" : "http") + "://";
        if (domain != null && !Patterns.IP_ADDRESS.matcher(domain).matches())
            url += "www.";
        url += domain;
        mWebView.loadUrl(url);
        mWebView.requestFocus();
    }
}
Also used : EditText(android.widget.EditText) SharedPreferences(android.content.SharedPreferences) InputMethodManager(android.view.inputmethod.InputMethodManager) View(android.view.View) WebView(android.webkit.WebView) TextView(android.widget.TextView) KeyEvent(android.view.KeyEvent) WebChromeClient(android.webkit.WebChromeClient) TextView(android.widget.TextView) WebView(android.webkit.WebView) HttpCookie(java.net.HttpCookie) CookieManager(android.webkit.CookieManager) WebViewClient(android.webkit.WebViewClient)

Example 2 with WebChromeClient

use of android.webkit.WebChromeClient in project robotium by RobotiumTech.

the class WebUtils method getCurrentWebChromeClient.

/**
	 * Returns the current WebChromeClient through reflection
	 * 
	 * @return the current WebChromeClient
	 * 
	 */
private WebChromeClient getCurrentWebChromeClient() {
    WebChromeClient currentWebChromeClient = null;
    Object currentWebView = viewFetcher.getFreshestView(viewFetcher.getCurrentViews(WebView.class, true));
    if (android.os.Build.VERSION.SDK_INT >= 16) {
        try {
            currentWebView = new Reflect(currentWebView).field("mProvider").out(Object.class);
        } catch (IllegalArgumentException ignored) {
        }
    }
    try {
        if (android.os.Build.VERSION.SDK_INT >= 19) {
            Object mClientAdapter = new Reflect(currentWebView).field("mContentsClientAdapter").out(Object.class);
            currentWebChromeClient = new Reflect(mClientAdapter).field("mWebChromeClient").out(WebChromeClient.class);
        } else {
            Object mCallbackProxy = new Reflect(currentWebView).field("mCallbackProxy").out(Object.class);
            currentWebChromeClient = new Reflect(mCallbackProxy).field("mWebChromeClient").out(WebChromeClient.class);
        }
    } catch (Exception ignored) {
    }
    return currentWebChromeClient;
}
Also used : WebChromeClient(android.webkit.WebChromeClient) WebView(android.webkit.WebView) IOException(java.io.IOException)

Example 3 with WebChromeClient

use of android.webkit.WebChromeClient in project Reader by TheKeeperOfPie.

the class FragmentWeb method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_web, container, false);
    layoutRoot = (RelativeLayout) view;
    toolbar = (Toolbar) view.findViewById(R.id.toolbar);
    toolbar.setTitle(getString(R.string.loading_web_page));
    toolbar.setTitleTextColor(themer.getColorFilterPrimary().getColor());
    toolbar.setOnClickListener(this);
    toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
    toolbar.getNavigationIcon().mutate().setColorFilter(themer.getColorFilterPrimary());
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            hasExited = true;
            mListener.onNavigationBackClick();
        }
    });
    setUpOptionsMenu();
    progressBar = (ProgressBar) view.findViewById(R.id.progress_web);
    webView = (WebView) view.findViewById(R.id.web);
    webView.setBackgroundColor(getResources().getColor(R.color.darkThemeBackground));
    webView.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            toolbar.setTitle(url);
            progressBar.setIndeterminate(true);
            progressBar.setVisibility(View.VISIBLE);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            progressBar.setVisibility(View.GONE);
            toolbar.setTitle(view.getTitle());
        }

        //            @Override
        //            public boolean shouldOverrideUrlLoading(WebView view, String url) {
        //                Log.d(TAG, "shouldOverrideUrlLoading: " + url);
        //
        //                Intent intent = new Intent(Intent.ACTION_VIEW);
        //                intent.setData(Uri.parse(url));
        //                PackageManager packageManager = view.getContext().getPackageManager();
        //                List<ResolveInfo> listResolveInfo = packageManager.queryIntentActivities(intent, 0);
        //
        //                Log.d(TAG, "listResolveInfo: " + listResolveInfo);
        //
        //                boolean containsAll = true;
        //
        //                for (ResolveInfo info : listResolveInfo) {
        //
        //                    boolean contains = false;
        //                    for (ResolveInfo infoDefault : listDefaultWebResolveInfo) {
        //                        if (infoDefault.activityInfo.name.equals(info.activityInfo.name) &&
        //                                infoDefault.activityInfo.targetActivity.equals(info.activityInfo.targetActivity)) {
        //                            contains = true;
        //                            break;
        //                        }
        //                    }
        //                    if (!contains) {
        //                        containsAll = false;
        //                        break;
        //                    }
        //                }
        //
        //                if (!containsAll) {
        //                    Iterator<ResolveInfo> iterator = listResolveInfo.iterator();
        //                    while (iterator.hasNext()) {
        //                        ResolveInfo info = iterator.next();
        //                        boolean contains = false;
        //                        for (ResolveInfo infoDefault : listDefaultWebResolveInfo) {
        //                            if (infoDefault.activityInfo.name.equals(info.activityInfo.name) &&
        //                                    infoDefault.activityInfo.targetActivity.equals(info.activityInfo.targetActivity)) {
        //                                contains = true;
        //                                break;
        //                            }
        //                        }
        //                        if (contains) {
        //                            iterator.remove();
        //                        }
        //                    }
        //
        //                    listResolveInfo.removeAll(listDefaultWebResolveInfo);
        //                    Collections.sort(listResolveInfo, new ResolveInfo.DisplayNameComparator(packageManager));
        //                    listResolveInfo.addAll(listDefaultWebResolveInfo);
        //                    showExternalLaunchDialog(url, listResolveInfo, packageManager);
        //                    return true;
        //                }
        //                return false;
        //            }
        @Override
        public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
            super.onReceivedError(view, request, error);
            Log.e(TAG, "WebView error: " + error);
        }
    });
    webView.setWebChromeClient(new WebChromeClient() {

        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
            progressBar.setIndeterminate(false);
            progressBar.setProgress(newProgress);
        }

        @Override
        public void onShowCustomView(View view, CustomViewCallback callback) {
            viewWebFullscreen = view;
            viewWebFullscreen.setBackgroundColor(0xFF000000);
            customViewCallback = callback;
            layoutRoot.addView(viewWebFullscreen, ViewGroup.LayoutParams.MATCH_PARENT);
            viewWebFullscreen.bringToFront();
        }

        @Override
        public void onHideCustomView() {
            super.onHideCustomView();
            layoutRoot.removeView(viewWebFullscreen);
            viewWebFullscreen = null;
        }
    });
    webView.getSettings().setUseWideViewPort(true);
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.getSettings().setBuiltInZoomControls(true);
    webView.getSettings().setDisplayZoomControls(false);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setDomStorageEnabled(true);
    webView.getSettings().setDatabaseEnabled(true);
    webView.getSettings().setAppCacheEnabled(true);
    webView.getSettings().setSupportMultipleWindows(false);
    webView.setBackgroundColor(0xFFFFFFFF);
    webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    Log.d(TAG, "savedInstanceState: " + savedInstanceState);
    if (savedInstanceState == null) {
        webView.loadUrl(url);
    } else {
        webView.restoreState(savedInstanceState);
    }
    toolbarActions = (Toolbar) view.findViewById(R.id.toolbar_actions);
    toolbarActions.inflateMenu(R.menu.menu_web_search);
    toolbarActions.setOnMenuItemClickListener(this);
    Menu menuActions = toolbarActions.getMenu();
    for (int index = 0; index < menuActions.size(); index++) {
        menuActions.getItem(index).getIcon().mutate().setColorFilter(themer.getColorFilterIcon());
    }
    return view;
}
Also used : WebResourceRequest(android.webkit.WebResourceRequest) SearchView(android.support.v7.widget.SearchView) View(android.view.View) WebView(android.webkit.WebView) Bitmap(android.graphics.Bitmap) WebChromeClient(android.webkit.WebChromeClient) WebResourceError(android.webkit.WebResourceError) Menu(android.view.Menu) WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient)

Example 4 with WebChromeClient

use of android.webkit.WebChromeClient in project Reader by TheKeeperOfPie.

the class ActivityLogin method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    CustomApplication.getComponentMain().inject(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }
    layoutRoot = (ViewGroup) findViewById(R.id.layout_root);
    Themer themer = new Themer(this);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitleTextColor(themer.getColorFilterPrimary().getColor());
    progressAuth = (ProgressBar) findViewById(R.id.progress_auth);
    webAuth = (WebView) findViewById(R.id.web_auth);
    webAuth.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            Log.d(TAG, "onPageStarted() called with: " + "view = [" + view + "], url = [" + url + "], favicon = [" + favicon + "]");
            progressAuth.setIndeterminate(true);
            progressAuth.setVisibility(View.VISIBLE);
            Uri uri = Uri.parse(url);
            if (uri.getHost().equals(Reddit.REDIRECT_URI.replaceFirst("https://", ""))) {
                String error = uri.getQueryParameter("error");
                String returnedState = uri.getQueryParameter("state");
                if (!TextUtils.isEmpty(error) || !state.equals(returnedState)) {
                    Toast.makeText(ActivityLogin.this, error, Toast.LENGTH_LONG).show();
                    webAuth.loadUrl(Reddit.getUserAuthUrl(state));
                    return;
                }
                // TODO: Failsafe with error and state
                String code = uri.getQueryParameter("code");
                fetchTokens(code);
            }
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            progressAuth.setVisibility(View.GONE);
            toolbar.setTitle(view.getTitle());
        }

        @Override
        public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
            super.onReceivedError(view, request, error);
            Log.e(TAG, "WebView error: " + error);
        }
    });
    webAuth.setWebChromeClient(new WebChromeClient() {

        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
            progressAuth.setIndeterminate(false);
            progressAuth.setProgress(newProgress);
        }
    });
    webAuth.loadUrl(Reddit.getUserAuthUrl(state));
}
Also used : Bitmap(android.graphics.Bitmap) WebResourceRequest(android.webkit.WebResourceRequest) WebChromeClient(android.webkit.WebChromeClient) WebResourceError(android.webkit.WebResourceError) Themer(com.winsonchiu.reader.theme.Themer) WebView(android.webkit.WebView) Uri(android.net.Uri) WebViewClient(android.webkit.WebViewClient)

Example 5 with WebChromeClient

use of android.webkit.WebChromeClient in project OpenMEAP by OpenMEAP.

the class MainActivity method createDefaultWebView.

/**
	 * Sets up the window title, per the properties
	 * 
	 * private void setupWindowTitle() { if( config.getApplicationTitle()!=null
	 * ) { if( config.getApplicationTitle().equals("off") ) {
	 * requestWindowFeature(Window.FEATURE_NO_TITLE); } else {
	 * setTitle(config.getApplicationTitle()); } } else
	 * setTitle(config.getApplicationName()); }
	 */
/**
	 * Creates the default WebView where we'll run javascript and render content
	 */
public WebView createDefaultWebView() {
    WebView webView = new com.openmeap.android.WebView(this, this);
    // make sure javascript and our api is available to the webview
    JsApiCoreImpl jsApi = new JsApiCoreImpl(this, webView, updateHandler);
    webView.addJavascriptInterface(jsApi, JS_API_NAME);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.setWebViewClient(new WebViewClient() {

        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    });
    //making web database enabled.
    webView.getSettings().setDatabaseEnabled(true);
    //making Dom storage enabled.
    webView.getSettings().setDomStorageEnabled(true);
    //requesting to create directory with name "localstorage" in /data/data/.../App_localstorage, 
    //so that, localstorage related data files saved into that directory.
    String databasePath = this.getApplicationContext().getDir("localstorage", Context.MODE_PRIVATE).getPath();
    //setting local storage database path.
    webView.getSettings().setDatabasePath("/data/data/" + webView.getContext().getPackageName() + "/databases/");
    // enable navigator.geolocation
    webView.getSettings().setGeolocationEnabled(true);
    webView.getSettings().setGeolocationDatabasePath("/data/data/" + webView.getContext().getPackageName() + "/databases/");
    // removes vertical and horizontal scroll bars
    webView.setVerticalScrollBarEnabled(false);
    webView.setHorizontalScrollBarEnabled(false);
    //WebChromeClient class is set, so that the overridden methods are executed,
    //when something that might impact a browser UI happens.
    webView.setWebChromeClient(new WebChromeClient() {

        @Override
        public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) {
            callback.invoke(origin, true, false);
        }

        @Override
        public void onExceededDatabaseQuota(String url, String databaseIdentifier, long quota, long estimatedDatabaseSize, long totalQuota, QuotaUpdater quotaUpdater) {
            // TODO Auto-generated method stub
            super.onExceededDatabaseQuota(url, databaseIdentifier, quota, estimatedDatabaseSize, totalQuota, quotaUpdater);
        }
    });
    // make sure the web view fills the viewable area
    webView.setLayoutParams(new LinearLayout.LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
    return webView;
}
Also used : LoginFormCallback(com.openmeap.thinclient.LoginFormCallback) Callback(android.webkit.GeolocationPermissions.Callback) WebChromeClient(android.webkit.WebChromeClient) QuotaUpdater(android.webkit.WebStorage.QuotaUpdater) OmWebView(com.openmeap.thinclient.OmWebView) JsApiCoreImpl(com.openmeap.thinclient.javascript.JsApiCoreImpl) LinearLayout(android.widget.LinearLayout) WebViewClient(android.webkit.WebViewClient)

Aggregations

WebChromeClient (android.webkit.WebChromeClient)39 WebView (android.webkit.WebView)32 WebViewClient (android.webkit.WebViewClient)29 WebSettings (android.webkit.WebSettings)13 View (android.view.View)12 Bitmap (android.graphics.Bitmap)9 SuppressLint (android.annotation.SuppressLint)6 JsResult (android.webkit.JsResult)6 WebResourceRequest (android.webkit.WebResourceRequest)6 Intent (android.content.Intent)5 LinearLayout (android.widget.LinearLayout)5 Uri (android.net.Uri)4 KeyEvent (android.view.KeyEvent)4 JsPromptResult (android.webkit.JsPromptResult)4 WebResourceError (android.webkit.WebResourceError)4 WebResourceResponse (android.webkit.WebResourceResponse)3 InjectView (butterknife.InjectView)3 IOException (java.io.IOException)3 SharedPreferences (android.content.SharedPreferences)2 Bundle (android.os.Bundle)2