Search in sources :

Example 21 with CookieManager

use of android.webkit.CookieManager in project LiveSDK-for-Android by liveservices.

the class LiveAuthClient method logout.

/**
     * Logs out the given user.
     *
     * Also, this method clears the previously created {@link LiveConnectSession}.
     * {@link LiveAuthListener#onAuthComplete(LiveStatus, LiveConnectSession, Object)} will be
     * called on completion. Otherwise,
     * {@link LiveAuthListener#onAuthError(LiveAuthException, Object)} will be called.
     *
     * @param listener called on either completion or error during the logout process.
     * @param userState arbitrary object that is used to determine the caller of the method.
     */
public void logout(LiveAuthListener listener, Object userState) {
    if (listener == null) {
        listener = NULL_LISTENER;
    }
    session.setAccessToken(null);
    session.setAuthenticationToken(null);
    session.setRefreshToken(null);
    session.setScopes(null);
    session.setTokenType(null);
    clearRefreshTokenFromPreferences();
    CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(this.applicationContext);
    CookieManager manager = CookieManager.getInstance();
    Uri logoutUri = Config.INSTANCE.getOAuthLogoutUri();
    String url = logoutUri.toString();
    String domain = logoutUri.getHost();
    List<String> cookieKeys = this.getCookieKeysFromPreferences();
    for (String cookieKey : cookieKeys) {
        String value = TextUtils.join("", new String[] { cookieKey, "=; expires=Thu, 30-Oct-1980 16:00:00 GMT;domain=", domain, ";path=/;version=1" });
        manager.setCookie(url, value);
    }
    cookieSyncManager.sync();
    listener.onAuthComplete(LiveStatus.UNKNOWN, null, userState);
}
Also used : CookieSyncManager(android.webkit.CookieSyncManager) Uri(android.net.Uri) CookieManager(android.webkit.CookieManager)

Example 22 with CookieManager

use of android.webkit.CookieManager in project android by owncloud.

the class SsoWebViewClient method onPageFinished.

@Override
public void onPageFinished(WebView view, String url) {
    Log_OC.d(TAG, "onPageFinished : " + url);
    mLastReloadedUrlAtError = null;
    if (url.startsWith(mTargetUrl)) {
        view.setVisibility(View.GONE);
        CookieManager cookieManager = CookieManager.getInstance();
        final String cookies = cookieManager.getCookie(url);
        //Log_OC.d(TAG, "Cookies: " + cookies);
        if (mListenerHandler != null && mListenerRef != null) {
            // this is good idea because onPageFinished is not running in the UI thread
            mListenerHandler.post(new Runnable() {

                @Override
                public void run() {
                    SsoWebViewClientListener listener = mListenerRef.get();
                    if (listener != null) {
                        // Send Cookies to the listener
                        listener.onSsoFinished(cookies);
                    }
                }
            });
        }
    }
}
Also used : CookieManager(android.webkit.CookieManager)

Example 23 with CookieManager

use of android.webkit.CookieManager in project android by owncloud.

the class SamlWebViewDialog method onCreateView.

@SuppressWarnings("deprecation")
@SuppressLint("SetJavaScriptEnabled")
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log_OC.v(TAG, "onCreateView, savedInsanceState is " + savedInstanceState);
    // Inflate layout of the dialog  
    RelativeLayout ssoRootView = (RelativeLayout) inflater.inflate(R.layout.sso_dialog, container, // null parent view because it will go in the dialog layout
    false);
    if (mSsoWebView == null) {
        // initialize the WebView
        mSsoWebView = new SsoWebView(getActivity().getApplicationContext());
        mSsoWebView.setFocusable(true);
        mSsoWebView.setFocusableInTouchMode(true);
        mSsoWebView.setClickable(true);
        WebSettings webSettings = mSsoWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setSavePassword(false);
        webSettings.setUserAgentString(MainApp.getUserAgent());
        webSettings.setSaveFormData(false);
        // next two settings grant that non-responsive webs are zoomed out when loaded
        webSettings.setUseWideViewPort(true);
        webSettings.setLoadWithOverviewMode(true);
        // next three settings allow the user use pinch gesture to zoom in / out
        webSettings.setSupportZoom(true);
        webSettings.setBuiltInZoomControls(true);
        webSettings.setDisplayZoomControls(false);
        webSettings.setAllowFileAccess(false);
        CookieManager cookieManager = CookieManager.getInstance();
        cookieManager.setAcceptCookie(true);
        cookieManager.removeAllCookie();
        mSsoWebView.loadUrl(mInitialUrl);
    }
    mWebViewClient.setTargetUrl(mTargetUrl);
    mSsoWebView.setWebViewClient(mWebViewClient);
    // add the webview into the layout
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
    ssoRootView.addView(mSsoWebView, layoutParams);
    ssoRootView.requestLayout();
    return ssoRootView;
}
Also used : WebSettings(android.webkit.WebSettings) RelativeLayout(android.widget.RelativeLayout) CookieManager(android.webkit.CookieManager) SuppressLint(android.annotation.SuppressLint)

Example 24 with CookieManager

use of android.webkit.CookieManager in project openkit-android by OpenKit.

the class Utility method clearCookiesForDomain.

private static void clearCookiesForDomain(Context context, String domain) {
    // This is to work around a bug where CookieManager may fail to instantiate if CookieSyncManager
    // has never been created.
    CookieSyncManager syncManager = CookieSyncManager.createInstance(context);
    syncManager.sync();
    CookieManager cookieManager = CookieManager.getInstance();
    String cookies = cookieManager.getCookie(domain);
    if (cookies == null) {
        return;
    }
    String[] splitCookies = cookies.split(";");
    for (String cookie : splitCookies) {
        String[] cookieParts = cookie.split("=");
        if (cookieParts.length > 0) {
            String newCookie = cookieParts[0].trim() + "=;expires=Sat, 1 Jan 2000 00:00:01 UTC;";
            cookieManager.setCookie(domain, newCookie);
        }
    }
    cookieManager.removeExpiredCookie();
}
Also used : CookieSyncManager(android.webkit.CookieSyncManager) CookieManager(android.webkit.CookieManager)

Example 25 with CookieManager

use of android.webkit.CookieManager in project NewPipe by TeamNewPipe.

the class ReCaptchaActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_recaptcha);
    // Set return to Cancel by default
    setResult(RESULT_CANCELED);
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setTitle(R.string.reCaptcha_title);
    actionBar.setDisplayShowTitleEnabled(true);
    WebView myWebView = (WebView) findViewById(R.id.reCaptchaWebView);
    // Enable Javascript
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    ReCaptchaWebViewClient webClient = new ReCaptchaWebViewClient(this);
    myWebView.setWebViewClient(webClient);
    // Cleaning cache, history and cookies from webView
    myWebView.clearCache(true);
    myWebView.clearHistory();
    android.webkit.CookieManager cookieManager = CookieManager.getInstance();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        cookieManager.removeAllCookies(new ValueCallback<Boolean>() {

            @Override
            public void onReceiveValue(Boolean aBoolean) {
            }
        });
    } else {
        cookieManager.removeAllCookie();
    }
    myWebView.loadUrl(YT_URL);
}
Also used : WebSettings(android.webkit.WebSettings) CookieManager(android.webkit.CookieManager) WebView(android.webkit.WebView) ActionBar(android.support.v7.app.ActionBar)

Aggregations

CookieManager (android.webkit.CookieManager)36 CookieSyncManager (android.webkit.CookieSyncManager)9 Test (org.junit.Test)7 WebView (android.webkit.WebView)4 SuppressLint (android.annotation.SuppressLint)3 WebSettings (android.webkit.WebSettings)3 Context (android.content.Context)2 Intent (android.content.Intent)2 Editor (android.content.SharedPreferences.Editor)2 Uri (android.net.Uri)2 View (android.view.View)2 WebViewClient (android.webkit.WebViewClient)2 TextView (android.widget.TextView)2 TargetApi (android.annotation.TargetApi)1 ActionBar (android.app.ActionBar)1 AlarmManager (android.app.AlarmManager)1 AlertDialog (android.app.AlertDialog)1 PendingIntent (android.app.PendingIntent)1 DialogInterface (android.content.DialogInterface)1 SharedPreferences (android.content.SharedPreferences)1