Chromium Code Reviews| Index: android_webview/renderer/aw_content_renderer_client.cc |
| diff --git a/android_webview/renderer/aw_content_renderer_client.cc b/android_webview/renderer/aw_content_renderer_client.cc |
| index a4798b06f6e89dc611e58a221d9a262172c52ea1..62d19dae62b71b17bb050014a940d4e140cfd249 100644 |
| --- a/android_webview/renderer/aw_content_renderer_client.cc |
| +++ b/android_webview/renderer/aw_content_renderer_client.cc |
| @@ -5,6 +5,7 @@ |
| #include "android_webview/renderer/aw_content_renderer_client.h" |
| #include "android_webview/common/aw_resource.h" |
| +#include "android_webview/common/render_view_messages.h" |
| #include "android_webview/common/url_constants.h" |
| #include "android_webview/renderer/aw_render_view_ext.h" |
| #include "base/message_loop/message_loop.h" |
| @@ -12,15 +13,23 @@ |
| #include "components/autofill/content/renderer/autofill_agent.h" |
| #include "components/autofill/content/renderer/password_autofill_agent.h" |
| #include "components/visitedlink/renderer/visitedlink_slave.h" |
| +#include "content/public/common/url_constants.h" |
| +#include "content/public/renderer/document_state.h" |
| +#include "content/public/renderer/navigation_state.h" |
| #include "content/public/renderer/render_thread.h" |
| +#include "content/public/renderer/render_view.h" |
| #include "net/base/net_errors.h" |
| #include "third_party/WebKit/public/platform/WebString.h" |
| #include "third_party/WebKit/public/platform/WebURL.h" |
| #include "third_party/WebKit/public/platform/WebURLError.h" |
| #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| +#include "third_party/WebKit/public/web/WebFrame.h" |
| +#include "third_party/WebKit/public/web/WebNavigationType.h" |
| #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
| #include "url/gurl.h" |
| +using content::RenderThread; |
| + |
| namespace android_webview { |
| AwContentRendererClient::AwContentRendererClient() { |
| @@ -34,7 +43,7 @@ void AwContentRendererClient::RenderThreadStarted() { |
| ASCIIToUTF16(android_webview::kContentScheme)); |
| WebKit::WebSecurityPolicy::registerURLSchemeAsLocal(content_scheme); |
| - content::RenderThread* thread = content::RenderThread::Get(); |
| + RenderThread* thread = content::RenderThread::Get(); |
| aw_render_process_observer_.reset(new AwRenderProcessObserver); |
| thread->AddObserver(aw_render_process_observer_.get()); |
| @@ -43,6 +52,63 @@ void AwContentRendererClient::RenderThreadStarted() { |
| thread->AddObserver(visited_link_slave_.get()); |
| } |
| +bool AwContentRendererClient::HandleNavigation( |
| + content::RenderView* view, |
| + content::DocumentState* document_state, |
| + int opener_id, |
| + WebKit::WebFrame* frame, |
| + const WebKit::WebURLRequest& request, |
| + WebKit::WebNavigationType type, |
| + WebKit::WebNavigationPolicy default_policy, |
| + bool is_redirect) { |
| + |
| + // Only GETs can be overridden. |
| + if (!request.httpMethod().equals("GET")) |
| + return false; |
| + |
| + // Any navigation from loadUrl, and goBack/Forward are considered application- |
| + // initiated and hence will not yield a shouldOverrideUrlLoading() callback. |
| + // Webview classic does not consider reload application-initiated so we |
| + // continue the same behavior. |
| + // TODO(sgurun) is_content_initiated is normally false for cross-origin |
| + // navigations but since android_webview does not swap out renderers, this |
| + // works fine. This will stop working if android_webview starts swapping out |
| + // renderers on navigation. |
| + bool application_initiated = |
| + !document_state->navigation_state()->is_content_initiated() |
| + || type == WebKit::WebNavigationTypeBackForward; |
| + |
| + // Don't offer application-initiated navigations unless it's a redirect. |
| + if (application_initiated && !is_redirect) |
| + return false; |
| + |
| + const GURL& gurl = request.url(); |
| + // For HTTP schemes, only top-level navigations can be overridden. |
| + // HandleNavigation receives about:blank navigations, (for example for |
| + // empty iframes), however webview classic does not pass these to the |
| + // app using shouldoverrideurlloading, so we filter them out here. Not |
| + // adding a special test for this, since removing the filtering causes |
| + // multiple shouldoverrideurlloading aw tests to fail, anyway. |
| + // TODO(sgurun) Need to write a test for allowing about:blank for top |
|
mkosiba (inactive)
2013/10/17 10:29:28
that shouldn't be a lot of work to add to the AwCo
sgurun-gerrit only
2013/12/06 00:17:48
yep a test will be valuable.
|
| + // navigations. |
| + if (frame->parent() && (gurl.SchemeIs(content::kHttpScheme) || |
| + gurl.SchemeIs(content::kHttpsScheme) || |
| + gurl.SchemeIs(chrome::kAboutScheme))) |
| + return false; |
| + |
| + bool ignore_navigation = false; |
| + base::string16 url = request.url().string(); |
| + |
| + int routing_id = view->GetRoutingID(); |
| + // When opener_id is valid (popup case), use opener id for routing. |
| + if (opener_id != MSG_ROUTING_NONE) |
| + routing_id = opener_id; |
| + RenderThread::Get()->Send(new AwViewHostMsg_ShouldOverrideUrlLoading( |
| + routing_id, url, &ignore_navigation)); |
| + |
| + return ignore_navigation; |
| +} |
| + |
| void AwContentRendererClient::RenderViewCreated( |
| content::RenderView* render_view) { |
| AwRenderViewExt::RenderViewCreated(render_view); |