LoadListener( Context context, BrowserFrame frame, String url, int nativeLoader, boolean synchronous, boolean isMainPageLoader) { if (Config.LOGV) { Log.v(LOGTAG, "LoadListener constructor url=" + url); } mContext = context; mBrowserFrame = frame; setUrl(url); mNativeLoader = nativeLoader; mMimeType = ""; mEncoding = ""; mSynchronous = synchronous; if (synchronous) { mMessageQueue = new Vector<Message>(); } mIsMainPageLoader = isMainPageLoader; }
/* * Perform the actual redirection. This involves setting up the new URL, * informing WebCore and then telling the Network to start loading again. */ private void doRedirect() { // as cancel() can cancel the load before doRedirect() is // called through handleMessage, needs to check to see if we // are canceled before proceed if (mCancelled) { return; } String redirectTo = mHeaders.getLocation(); if (redirectTo != null) { int nativeResponse = createNativeResponse(); redirectTo = nativeRedirectedToUrl(mUrl, redirectTo, nativeResponse); // nativeRedirectedToUrl() may call cancel(), e.g. when redirect // from a https site to a http site, check mCancelled again if (mCancelled) { return; } if (redirectTo == null) { Log.d(LOGTAG, "Redirection failed for " + mHeaders.getLocation()); cancel(); return; } else if (!URLUtil.isNetworkUrl(redirectTo)) { final String text = mContext.getString(com.android.internal.R.string.open_permission_deny) + "\n" + redirectTo; nativeAddData(text.getBytes(), text.length()); nativeFinished(); clearNativeLoader(); return; } if (mOriginalUrl == null) { mOriginalUrl = mUrl; } // Cache the redirect response if (mCacheResult != null) { if (getErrorID() == OK) { CacheManager.saveCacheFile(mUrl, mCacheResult); } mCacheResult = null; } setUrl(redirectTo); // Redirect may be in the cache if (mRequestHeaders == null) { mRequestHeaders = new HashMap<String, String>(); } if (!checkCache(mRequestHeaders)) { // mRequestHandle can be null when the request was satisfied // by the cache, and the cache returned a redirect if (mRequestHandle != null) { mRequestHandle.setupRedirect(redirectTo, mStatusCode, mRequestHeaders); } else { String method = mMethod; if (method == null) { return; } Network network = Network.getInstance(getContext()); network.requestURL(method, mRequestHeaders, mPostData, this, mIsHighPriority); } } } else { cancel(); } if (Config.LOGV) { Log.v(LOGTAG, "LoadListener.onRedirect(): redirect to: " + redirectTo); } }