예제 #1
0
  /**
   * Add the content related headers. These headers contain user private data and is not used when
   * we are proxying an untrusted request.
   */
  private void populateHeaders() {

    if (mReferrer != null) mHeaders.put("Referer", mReferrer);
    if (mContentType != null) mHeaders.put(CONTENT_TYPE, mContentType);

    // if we have an active proxy and have proxy credentials, do pre-emptive
    // authentication to avoid an extra round-trip:
    if (mNetwork.isValidProxySet()) {
      String username;
      String password;
      /* The proxy credentials can be set in the Network thread */
      synchronized (mNetwork) {
        username = mNetwork.getProxyUsername();
        password = mNetwork.getProxyPassword();
      }
      if (username != null && password != null) {
        // we collect credentials ONLY if the proxy scheme is BASIC!!!
        String proxyHeader = RequestHandle.authorizationHeader(true);
        mHeaders.put(
            proxyHeader, "Basic " + RequestHandle.computeBasicAuthResponse(username, password));
      }
    }

    // Set cookie header
    String cookie = CookieManager.getInstance().getCookie(mListener.getWebAddress());
    if (cookie != null && cookie.length() > 0) {
      mHeaders.put("Cookie", cookie);
    }
  }
 /**
  * Store a cookie string associated with a url.
  *
  * @param url The url to be used as a key for the cookie.
  * @param value The cookie string to be stored.
  */
 @DSComment("Private Method")
 @DSBan(DSCat.PRIVATE_METHOD)
 @DSGenerator(
     tool_name = "Doppelganger",
     tool_version = "2.0",
     generated_on = "2013-12-30 12:32:41.967 -0500",
     hash_original_method = "D5A9FC7DDB356B7F9D175C82B50A2AF1",
     hash_generated_method = "24C7574FF957618A543446AAAEE4BC4D")
 private void setCookies(String url, String value) {
   if (value.contains("\r") || value.contains("\n")) {
     // for security reason, filter out '\r' and '\n' from the cookie
     int size = value.length();
     StringBuilder buffer = new StringBuilder(size);
     int i = 0;
     while (i != -1 && i < size) {
       int ir = value.indexOf('\r', i);
       int in = value.indexOf('\n', i);
       int newi = (ir == -1) ? in : (in == -1 ? ir : (ir < in ? ir : in));
       if (newi > i) {
         buffer.append(value.subSequence(i, newi));
       } else if (newi == -1) {
         buffer.append(value.subSequence(i, size));
         break;
       }
       i = newi + 1;
     }
     value = buffer.toString();
   }
   CookieManager.getInstance().setCookie(url, value);
 }
예제 #3
0
 private void syncFromRamToFlash(ArrayList<Cookie> list) {
   Iterator<Cookie> iter = list.iterator();
   while (iter.hasNext()) {
     Cookie cookie = iter.next();
     if (cookie.mode != Cookie.MODE_NORMAL) {
       if (cookie.mode != Cookie.MODE_NEW) {
         mDataBase.deleteCookies(cookie.domain, cookie.path, cookie.name);
       }
       if (cookie.mode != Cookie.MODE_DELETED) {
         mDataBase.addCookie(cookie);
         CookieManager.getInstance().syncedACookie(cookie);
       } else {
         CookieManager.getInstance().deleteACookie(cookie);
       }
     }
   }
 }
예제 #4
0
  protected void syncFromRamToFlash() {
    if (DebugFlags.COOKIE_SYNC_MANAGER) {
      Log.v(LOGTAG, "CookieSyncManager::syncFromRamToFlash STARTS");
    }

    if (!CookieManager.getInstance().acceptCookie()) {
      return;
    }

    ArrayList<Cookie> cookieList = CookieManager.getInstance().getUpdatedCookiesSince(mLastUpdate);
    mLastUpdate = System.currentTimeMillis();
    syncFromRamToFlash(cookieList);

    ArrayList<Cookie> lruList = CookieManager.getInstance().deleteLRUDomain();
    syncFromRamToFlash(lruList);

    if (DebugFlags.COOKIE_SYNC_MANAGER) {
      Log.v(LOGTAG, "CookieSyncManager::syncFromRamToFlash DONE");
    }
  }
 /** Returns whether cookies are enabled or not. */
 @DSComment("Private Method")
 @DSBan(DSCat.PRIVATE_METHOD)
 @DSGenerator(
     tool_name = "Doppelganger",
     tool_version = "2.0",
     generated_on = "2013-12-30 12:32:41.972 -0500",
     hash_original_method = "E9376C130584FE2146C1CFB7A84FB471",
     hash_generated_method = "FA6BBF0A4D9665939C38DB115FB61EFF")
 private boolean cookiesEnabled() {
   return CookieManager.getInstance().acceptCookie();
 }
 /**
  * Retrieve the cookie string for the given url.
  *
  * @param url The resource's url.
  * @return A String representing the cookies for the given resource url.
  */
 @DSComment("Private Method")
 @DSBan(DSCat.PRIVATE_METHOD)
 @DSGenerator(
     tool_name = "Doppelganger",
     tool_version = "2.0",
     generated_on = "2013-12-30 12:32:41.970 -0500",
     hash_original_method = "E3D7D6931554145E868760CB2C4A26A3",
     hash_generated_method = "EE86FFF77F12F6E87C0C4F0204A00383")
 private String cookies(String url) {
   return CookieManager.getInstance().getCookie(url);
 }
예제 #7
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.oauthactivity_layout);
    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(false);
    actionBar.setTitle(getString(R.string.login));
    webView = (WebView) findViewById(R.id.webView);
    webView.setWebViewClient(new WeiboWebViewClient());

    WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setSaveFormData(false);
    settings.setSavePassword(false);
    settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
    settings.setRenderPriority(WebSettings.RenderPriority.HIGH);

    CookieSyncManager.createInstance(this);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();
  }
  /**
   * Parse the headers sent from the server.
   *
   * @param headers gives up the HeaderGroup IMPORTANT: as this is called from network thread, can't
   *     call native directly
   */
  public void headers(Headers headers) {
    if (Config.LOGV) Log.v(LOGTAG, "LoadListener.headers");
    if (mCancelled) return;
    mHeaders = headers;
    mMimeType = "";
    mEncoding = "";

    ArrayList<String> cookies = headers.getSetCookie();
    for (int i = 0; i < cookies.size(); ++i) {
      CookieManager.getInstance().setCookie(mUri, cookies.get(i));
    }

    long contentLength = headers.getContentLength();
    if (contentLength != Headers.NO_CONTENT_LENGTH) {
      mContentLength = contentLength;
    } else {
      mContentLength = 0;
    }

    String contentType = headers.getContentType();
    if (contentType != null) {
      parseContentTypeHeader(contentType);

      // If we have one of "generic" MIME types, try to deduce
      // the right MIME type from the file extension (if any):
      if (mMimeType.equalsIgnoreCase("text/plain")
          || mMimeType.equalsIgnoreCase("application/octet-stream")) {

        String newMimeType = guessMimeTypeFromExtension();
        if (newMimeType != null) {
          mMimeType = newMimeType;
        }
      } else if (mMimeType.equalsIgnoreCase("text/vnd.wap.wml")) {
        // As we don't support wml, render it as plain text
        mMimeType = "text/plain";
      } else {
        // XXX: Until the servers send us either correct xhtml or
        // text/html, treat application/xhtml+xml as text/html.
        // It seems that xhtml+xml and vnd.wap.xhtml+xml mime
        // subtypes are used interchangeably. So treat them the same.
        if (mMimeType.equalsIgnoreCase("application/xhtml+xml")
            || mMimeType.equals("application/vnd.wap.xhtml+xml")) {
          mMimeType = "text/html";
        }
      }
    } else {
      /* Often when servers respond with 304 Not Modified or a
      Redirect, then they don't specify a MIMEType. When this
      occurs, the function below is called.  In the case of
      304 Not Modified, the cached headers are used rather
      than the headers that are returned from the server. */
      guessMimeType();
    }

    // is it an authentication request?
    boolean mustAuthenticate = (mStatusCode == HTTP_AUTH || mStatusCode == HTTP_PROXY_AUTH);
    // is it a proxy authentication request?
    boolean isProxyAuthRequest = (mStatusCode == HTTP_PROXY_AUTH);
    // is this authentication request due to a failed attempt to
    // authenticate ealier?
    mAuthFailed = false;

    // if we tried to authenticate ourselves last time
    if (mAuthHeader != null) {
      // we failed, if we must to authenticate again now and
      // we have a proxy-ness match
      mAuthFailed = (mustAuthenticate && isProxyAuthRequest == mAuthHeader.isProxy());

      // if we did NOT fail and last authentication request was a
      // proxy-authentication request
      if (!mAuthFailed && mAuthHeader.isProxy()) {
        Network network = Network.getInstance(mContext);
        // if we have a valid proxy set
        if (network.isValidProxySet()) {
          /* The proxy credentials can be read in the WebCore thread
           */
          synchronized (network) {
            // save authentication credentials for pre-emptive proxy
            // authentication
            network.setProxyUsername(mAuthHeader.getUsername());
            network.setProxyPassword(mAuthHeader.getPassword());
          }
        }
      }
    }
    // it is only here that we can reset the last mAuthHeader object
    // (if existed) and start a new one!!!
    mAuthHeader = null;
    if (mustAuthenticate) {
      if (mStatusCode == HTTP_AUTH) {
        mAuthHeader = parseAuthHeader(headers.getWwwAuthenticate());
      } else {
        mAuthHeader = parseAuthHeader(headers.getProxyAuthenticate());
        // if successfully parsed the header
        if (mAuthHeader != null) {
          // mark the auth-header object as a proxy
          mAuthHeader.setProxy();
        }
      }
    }

    // Only create a cache file if the server has responded positively.
    if ((mStatusCode == HTTP_OK
            || mStatusCode == HTTP_FOUND
            || mStatusCode == HTTP_MOVED_PERMANENTLY
            || mStatusCode == HTTP_TEMPORARY_REDIRECT)
        && mNativeLoader != 0) {
      // Content arriving from a StreamLoader (eg File, Cache or Data)
      // will not be cached as they have the header:
      // cache-control: no-store
      mCacheResult = CacheManager.createCacheFile(mUrl, mStatusCode, headers, mMimeType, false);
      if (mCacheResult != null) {
        mCacheResult.encoding = mEncoding;
      }
    }
    sendMessageInternal(obtainMessage(MSG_CONTENT_HEADERS));
  }