Search in sources :

Example 91 with WebViewClient

use of android.webkit.WebViewClient in project robolectric by robolectric.

the class ShadowWebViewTest method shouldRecordWebViewClient.

@Test
public void shouldRecordWebViewClient() {
    WebViewClient webViewClient = new WebViewClient();
    assertThat(shadowOf(webView).getWebViewClient()).isNull();
    webView.setWebViewClient(webViewClient);
    assertThat(shadowOf(webView).getWebViewClient()).isSameInstanceAs(webViewClient);
}
Also used : WebViewClient(android.webkit.WebViewClient) Test(org.junit.Test)

Example 92 with WebViewClient

use of android.webkit.WebViewClient in project robolectric by robolectric.

the class ShadowWebViewTest method shouldPerformPageLoadCallbacksOnLoadUrl.

@Test
@Config(minSdk = O)
public void shouldPerformPageLoadCallbacksOnLoadUrl() {
    WebChromeClient mockWebChromeClient = mock(WebChromeClient.class);
    WebViewClient mockWebViewClient = mock(WebViewClient.class);
    webView.setWebChromeClient(mockWebChromeClient);
    webView.setWebViewClient(mockWebViewClient);
    String url = "http://example.com";
    webView.loadUrl(url);
    shadowOf(getMainLooper()).idle();
    verifyNoMoreInteractions(mockWebChromeClient);
    verifyNoMoreInteractions(mockWebViewClient);
    shadowOf(webView).performSuccessfulPageLoadClientCallbacks();
    webView.loadUrl(url);
    shadowOf(getMainLooper()).idle();
    InOrder inOrder = inOrder(mockWebViewClient, mockWebChromeClient);
    inOrder.verify(mockWebViewClient).onPageStarted(webView, url, null);
    inOrder.verify(mockWebViewClient).onPageCommitVisible(webView, url);
    inOrder.verify(mockWebChromeClient).onReceivedTitle(webView, url);
    inOrder.verify(mockWebChromeClient).onProgressChanged(webView, 100);
    inOrder.verify(mockWebViewClient).onPageFinished(webView, url);
}
Also used : InOrder(org.mockito.InOrder) WebChromeClient(android.webkit.WebChromeClient) WebViewClient(android.webkit.WebViewClient) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 93 with WebViewClient

use of android.webkit.WebViewClient in project android-testing by googlesamples.

the class WebViewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_web_view);
    mWebView = (WebView) findViewById(R.id.web_view);
    mWebView.getSettings().setJavaScriptEnabled(true);
    mWebView.loadUrl(urlFromIntent(getIntent()));
    mWebView.requestFocus();
    mWebView.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return false;
        }
    });
}
Also used : WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient)

Example 94 with WebViewClient

use of android.webkit.WebViewClient 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 95 with WebViewClient

use of android.webkit.WebViewClient in project baker-android by bakerframework.

the class InfoActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_info);
    // Here we allow the user to rotate the screen.
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
    Intent intent = getIntent();
    String url = intent.getStringExtra(MagazineActivity.MODAL_URL);
    // Click on the CLOSE button.
    findViewById(R.id.btnCloseInfo).setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            InfoActivity.this.finish();
        }
    });
    WebView webView = (WebView) this.findViewById(R.id.infoWebView);
    webView.getSettings().setJavaScriptEnabled(true);
    // Set zoom enabled/disabled
    webView.getSettings().setSupportZoom(true);
    // Support zoom like normal browsers
    webView.getSettings().setUseWideViewPort(true);
    // Disable zoom buttons
    webView.getSettings().setDisplayZoomControls(false);
    // Add zoom controls
    webView.getSettings().setBuiltInZoomControls(true);
    // Load the page on the maximum zoom out available.
    webView.getSettings().setLoadWithOverviewMode(true);
    webView.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    });
    webView.loadUrl(url);
}
Also used : Intent(android.content.Intent) WebView(android.webkit.WebView) View(android.view.View) WebView(android.webkit.WebView) WebViewClient(android.webkit.WebViewClient)

Aggregations

WebViewClient (android.webkit.WebViewClient)247 WebView (android.webkit.WebView)229 WebSettings (android.webkit.WebSettings)77 View (android.view.View)71 WebChromeClient (android.webkit.WebChromeClient)69 SuppressLint (android.annotation.SuppressLint)61 Intent (android.content.Intent)60 Bitmap (android.graphics.Bitmap)59 WebResourceRequest (android.webkit.WebResourceRequest)35 TextView (android.widget.TextView)26 LinearLayout (android.widget.LinearLayout)22 WebResourceError (android.webkit.WebResourceError)21 WebResourceResponse (android.webkit.WebResourceResponse)16 Uri (android.net.Uri)15 SslError (android.net.http.SslError)13 Bundle (android.os.Bundle)13 Toolbar (android.support.v7.widget.Toolbar)13 KeyEvent (android.view.KeyEvent)13 SslErrorHandler (android.webkit.SslErrorHandler)13 TargetApi (android.annotation.TargetApi)12