Skip to content

Commit

Permalink
Revert of Move onReceivedError and onReceivedHttpError out of AwConte…
Browse files Browse the repository at this point in the history
…ntsIoThreadClientImpl (patchset chromium#7 id:120001 of https://codereview.chromium.org/2558223002/ )

Reason for revert:
BUG=673736

Original issue's description:
> Move onReceivedError and onReceivedHttpError out of AwContentsIoThreadClientImpl
>
> Move onReceivedError and onReceivedHttpError out of AwContentsIoThreadClientImpl to AwContentsClientBridge. This is a continuation of the work started in
> https://codereview.chromium.org/2425423004/ and is the third patch.
>
> BUG=645983
>
> Committed: https://crrev.com/f199141ef70d76697647830f498b25706c0b0d0a
> Cr-Commit-Position: refs/heads/master@{#437688}

TBR=sgurun@chromium.org
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=645983

Review-Url: https://codereview.chromium.org/2567043003
Cr-Commit-Position: refs/heads/master@{#438221}
  • Loading branch information
boliu authored and Commit bot committed Dec 13, 2016
1 parent 689d562 commit 0781d31
Show file tree
Hide file tree
Showing 15 changed files with 272 additions and 354 deletions.
2 changes: 0 additions & 2 deletions android_webview/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,6 @@ source_set("common") {
"browser/net/aw_url_request_context_getter.h",
"browser/net/aw_url_request_job_factory.cc",
"browser/net/aw_url_request_job_factory.h",
"browser/net/aw_web_resource_request.cc",
"browser/net/aw_web_resource_request.h",
"browser/net/aw_web_resource_response.h",
"browser/net/init_native_callback.h",
"browser/net/input_stream_reader.cc",
Expand Down
13 changes: 0 additions & 13 deletions android_webview/browser/aw_contents_client_bridge_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@

#include <memory>

#include "android_webview/browser/net/aw_web_resource_request.h"
#include "base/supports_user_data.h"
#include "content/public/browser/certificate_request_result_type.h"
#include "content/public/browser/javascript_dialog_manager.h"
#include "content/public/browser/resource_request_info.h"
#include "net/http/http_response_headers.h"

class GURL;

Expand Down Expand Up @@ -89,17 +87,6 @@ class AwContentsClientBridgeBase {
virtual void NewLoginRequest(const std::string& realm,
const std::string& account,
const std::string& args) = 0;

// Called when a resource loading error has occured (e.g. an I/O error,
// host name lookup failure etc.)
virtual void OnReceivedError(const AwWebResourceRequest& request,
int error_code) = 0;

// Called when a response from the server is received with status code >= 400.
virtual void OnReceivedHttpError(
const AwWebResourceRequest& request,
const scoped_refptr<const net::HttpResponseHeaders>&
response_headers) = 0;
};

} // namespace android_webview
Expand Down
10 changes: 10 additions & 0 deletions android_webview/browser/aw_contents_io_thread_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "base/callback_forward.h"

namespace net {
class HttpResponseHeaders;
class URLRequest;
}

Expand Down Expand Up @@ -94,6 +95,15 @@ class AwContentsIoThreadClient {

// Retrieve the AcceptThirdPartyCookies setting value of this AwContents.
virtual bool ShouldAcceptThirdPartyCookies() const = 0;

// Called when a resource loading error has occured (e.g. an I/O error,
// host name lookup failure etc.)
virtual void OnReceivedError(const net::URLRequest* request) = 0;

// Called when a response from the server is received with status code >= 400.
virtual void OnReceivedHttpError(
const net::URLRequest* request,
const net::HttpResponseHeaders* response_headers) = 0;
};

} // namespace android_webview
Expand Down
37 changes: 9 additions & 28 deletions android_webview/browser/net/aw_network_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
#include "android_webview/browser/net/aw_network_delegate.h"

#include "android_webview/browser/aw_browser_context.h"
#include "android_webview/browser/aw_contents_client_bridge_base.h"
#include "android_webview/browser/aw_contents_io_thread_client.h"
#include "android_webview/browser/aw_cookie_access_policy.h"
#include "android_webview/browser/net/aw_web_resource_request.h"
#include "base/android/build_info.h"
#include "components/policy/core/browser/url_blacklist_manager.h"
#include "content/public/browser/browser_thread.h"
Expand All @@ -24,21 +22,6 @@ using content::BrowserThread;

namespace android_webview {

namespace {

void OnReceivedHttpErrorOnUiThread(
const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter,
const AwWebResourceRequest& request,
scoped_refptr<const net::HttpResponseHeaders> original_response_headers) {
AwContentsClientBridgeBase* client =
AwContentsClientBridgeBase::FromWebContentsGetter(web_contents_getter);
if (!client)
return;
client->OnReceivedHttpError(request, original_response_headers);
}

} // namespace

AwNetworkDelegate::AwNetworkDelegate() : url_blacklist_manager_(nullptr) {
}

Expand Down Expand Up @@ -81,17 +64,15 @@ int AwNetworkDelegate::OnHeadersReceived(
scoped_refptr<net::HttpResponseHeaders>* override_response_headers,
GURL* allowed_unsafe_redirect_url) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
if (original_response_headers->response_code() >= 400) {
const content::ResourceRequestInfo* request_info =
content::ResourceRequestInfo::ForRequest(request);
// keep a ref before binding and posting to UI thread.
scoped_refptr<const net::HttpResponseHeaders> response_headers(
original_response_headers);
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&OnReceivedHttpErrorOnUiThread,
request_info->GetWebContentsGetterForRequest(),
AwWebResourceRequest(*request), response_headers));
int render_process_id, render_frame_id;
if (original_response_headers->response_code() >= 400 &&
content::ResourceRequestInfo::GetRenderFrameForRequest(
request, &render_process_id, &render_frame_id)) {
std::unique_ptr<AwContentsIoThreadClient> io_thread_client =
AwContentsIoThreadClient::FromID(render_process_id, render_frame_id);
if (io_thread_client.get()) {
io_thread_client->OnReceivedHttpError(request, original_response_headers);
}
}
return net::OK;
}
Expand Down
58 changes: 0 additions & 58 deletions android_webview/browser/net/aw_web_resource_request.cc

This file was deleted.

57 changes: 0 additions & 57 deletions android_webview/browser/net/aw_web_resource_request.h

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "android_webview/browser/aw_contents_io_thread_client.h"
#include "android_webview/browser/aw_login_delegate.h"
#include "android_webview/browser/aw_resource_context.h"
#include "android_webview/browser/net/aw_web_resource_request.h"
#include "android_webview/browser/renderer_host/auto_login_parser.h"
#include "android_webview/common/url_constants.h"
#include "base/memory/scoped_vector.h"
Expand All @@ -33,7 +32,6 @@

using android_webview::AwContentsIoThreadClient;
using android_webview::AwContentsClientBridgeBase;
using android_webview::AwWebResourceRequest;
using content::BrowserThread;
using content::ResourceType;
using content::WebContents;
Expand Down Expand Up @@ -86,20 +84,6 @@ void NewLoginRequestOnUIThread(
client->NewLoginRequest(realm, account, args);
}

void OnReceivedErrorOnUiThread(
const content::ResourceRequestInfo::WebContentsGetter& web_contents_getter,
const AwWebResourceRequest& request,
int error_code) {
AwContentsClientBridgeBase* client =
AwContentsClientBridgeBase::FromWebContentsGetter(web_contents_getter);
if (!client) {
DLOG(WARNING) << "io_client is null, onReceivedError dropped for "
<< request.url;
return;
}
client->OnReceivedError(request, error_code);
}

} // namespace

namespace android_webview {
Expand Down Expand Up @@ -301,15 +285,19 @@ void AwResourceDispatcherHostDelegate::RequestComplete(
if (request && !request->status().is_success()) {
const content::ResourceRequestInfo* request_info =
content::ResourceRequestInfo::ForRequest(request);

BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(&OnReceivedErrorOnUiThread,
request_info->GetWebContentsGetterForRequest(),
AwWebResourceRequest(*request), request->status().error()));
std::unique_ptr<AwContentsIoThreadClient> io_client =
AwContentsIoThreadClient::FromID(request_info->GetChildID(),
request_info->GetRenderFrameID());
if (io_client) {
io_client->OnReceivedError(request);
} else {
DLOG(WARNING) << "io_client is null, onReceivedError dropped for " <<
request->url();
}
}
}


void AwResourceDispatcherHostDelegate::DownloadStarting(
net::URLRequest* request,
content::ResourceContext* resource_context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import org.chromium.content_public.browser.navigation_controller.LoadURLType;
import org.chromium.content_public.browser.navigation_controller.UserAgentOverrideOption;
import org.chromium.content_public.common.Referrer;
import org.chromium.net.NetError;
import org.chromium.net.NetworkChangeNotifier;
import org.chromium.ui.base.ActivityWindowAndroid;
import org.chromium.ui.base.PageTransition;
Expand Down Expand Up @@ -470,6 +471,37 @@ public boolean shouldBlockNetworkLoads() {
public boolean shouldAcceptThirdPartyCookies() {
return mSettings.getAcceptThirdPartyCookies();
}

@Override
public void onReceivedError(AwContentsClient.AwWebResourceRequest request,
AwContentsClient.AwWebResourceError error) {
String unreachableWebDataUrl = AwContentsStatics.getUnreachableWebDataUrl();
boolean isErrorUrl =
unreachableWebDataUrl != null && unreachableWebDataUrl.equals(request.url);
if (!isErrorUrl && error.errorCode != NetError.ERR_ABORTED) {
// NetError.ERR_ABORTED error code is generated for the following reasons:
// - WebView.stopLoading is called;
// - the navigation is intercepted by the embedder via shouldOverrideUrlLoading;
// - server returned 204 status (no content).
//
// Android WebView does not notify the embedder of these situations using
// this error code with the WebViewClient.onReceivedError callback.
error.errorCode = ErrorCodeConversionHelper.convertErrorCode(error.errorCode);
mContentsClient.getCallbackHelper().postOnReceivedError(request, error);
if (request.isMainFrame) {
// Need to call onPageFinished after onReceivedError for backwards compatibility
// with the classic webview. See also AwWebContentsObserver.didFailLoad which is
// used when we want to send onPageFinished alone.
mContentsClient.getCallbackHelper().postOnPageFinished(request.url);
}
}
}

@Override
public void onReceivedHttpError(AwContentsClient.AwWebResourceRequest request,
AwWebResourceResponse response) {
mContentsClient.getCallbackHelper().postOnReceivedHttpError(request, response);
}
}

private class BackgroundThreadClientImpl extends AwContentsBackgroundThreadClient {
Expand Down
Loading

0 comments on commit 0781d31

Please sign in to comment.