| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "android_webview/renderer/aw_content_renderer_client.h" | 5 #include "android_webview/renderer/aw_content_renderer_client.h" |
| 6 | 6 |
| 7 #include "android_webview/common/aw_resource.h" | 7 #include "android_webview/common/aw_resource.h" |
| 8 #include "android_webview/common/render_view_messages.h" |
| 8 #include "android_webview/common/url_constants.h" | 9 #include "android_webview/common/url_constants.h" |
| 9 #include "android_webview/renderer/aw_key_systems.h" | 10 #include "android_webview/renderer/aw_key_systems.h" |
| 10 #include "android_webview/renderer/aw_render_view_ext.h" | 11 #include "android_webview/renderer/aw_render_view_ext.h" |
| 11 #include "android_webview/renderer/print_web_view_helper.h" | 12 #include "android_webview/renderer/print_web_view_helper.h" |
| 12 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "components/autofill/content/renderer/autofill_agent.h" | 15 #include "components/autofill/content/renderer/autofill_agent.h" |
| 15 #include "components/autofill/content/renderer/password_autofill_agent.h" | 16 #include "components/autofill/content/renderer/password_autofill_agent.h" |
| 16 #include "components/visitedlink/renderer/visitedlink_slave.h" | 17 #include "components/visitedlink/renderer/visitedlink_slave.h" |
| 18 #include "content/public/common/url_constants.h" |
| 19 #include "content/public/renderer/document_state.h" |
| 20 #include "content/public/renderer/navigation_state.h" |
| 17 #include "content/public/renderer/render_thread.h" | 21 #include "content/public/renderer/render_thread.h" |
| 22 #include "content/public/renderer/render_view.h" |
| 18 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
| 19 #include "third_party/WebKit/public/platform/WebString.h" | 24 #include "third_party/WebKit/public/platform/WebString.h" |
| 20 #include "third_party/WebKit/public/platform/WebURL.h" | 25 #include "third_party/WebKit/public/platform/WebURL.h" |
| 21 #include "third_party/WebKit/public/platform/WebURLError.h" | 26 #include "third_party/WebKit/public/platform/WebURLError.h" |
| 22 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 27 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 28 #include "third_party/WebKit/public/web/WebFrame.h" |
| 29 #include "third_party/WebKit/public/web/WebNavigationType.h" |
| 23 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" | 30 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
| 24 #include "url/gurl.h" | 31 #include "url/gurl.h" |
| 25 | 32 |
| 33 using content::RenderThread; |
| 34 |
| 26 namespace android_webview { | 35 namespace android_webview { |
| 27 | 36 |
| 28 AwContentRendererClient::AwContentRendererClient() { | 37 AwContentRendererClient::AwContentRendererClient() { |
| 29 } | 38 } |
| 30 | 39 |
| 31 AwContentRendererClient::~AwContentRendererClient() { | 40 AwContentRendererClient::~AwContentRendererClient() { |
| 32 } | 41 } |
| 33 | 42 |
| 34 void AwContentRendererClient::RenderThreadStarted() { | 43 void AwContentRendererClient::RenderThreadStarted() { |
| 35 blink::WebString content_scheme( | 44 blink::WebString content_scheme( |
| 36 ASCIIToUTF16(android_webview::kContentScheme)); | 45 ASCIIToUTF16(android_webview::kContentScheme)); |
| 37 blink::WebSecurityPolicy::registerURLSchemeAsLocal(content_scheme); | 46 blink::WebSecurityPolicy::registerURLSchemeAsLocal(content_scheme); |
| 38 | 47 |
| 39 blink::WebString aw_scheme( | 48 blink::WebString aw_scheme( |
| 40 ASCIIToUTF16(android_webview::kAndroidWebViewVideoPosterScheme)); | 49 ASCIIToUTF16(android_webview::kAndroidWebViewVideoPosterScheme)); |
| 41 blink::WebSecurityPolicy::registerURLSchemeAsSecure(aw_scheme); | 50 blink::WebSecurityPolicy::registerURLSchemeAsSecure(aw_scheme); |
| 42 | 51 |
| 43 content::RenderThread* thread = content::RenderThread::Get(); | 52 RenderThread* thread = RenderThread::Get(); |
| 44 | 53 |
| 45 aw_render_process_observer_.reset(new AwRenderProcessObserver); | 54 aw_render_process_observer_.reset(new AwRenderProcessObserver); |
| 46 thread->AddObserver(aw_render_process_observer_.get()); | 55 thread->AddObserver(aw_render_process_observer_.get()); |
| 47 | 56 |
| 48 visited_link_slave_.reset(new visitedlink::VisitedLinkSlave); | 57 visited_link_slave_.reset(new visitedlink::VisitedLinkSlave); |
| 49 thread->AddObserver(visited_link_slave_.get()); | 58 thread->AddObserver(visited_link_slave_.get()); |
| 50 } | 59 } |
| 51 | 60 |
| 61 bool AwContentRendererClient::HandleNavigation( |
| 62 content::RenderView* view, |
| 63 content::DocumentState* document_state, |
| 64 int opener_id, |
| 65 blink::WebFrame* frame, |
| 66 const blink::WebURLRequest& request, |
| 67 blink::WebNavigationType type, |
| 68 blink::WebNavigationPolicy default_policy, |
| 69 bool is_redirect) { |
| 70 |
| 71 // Only GETs can be overridden. |
| 72 if (!request.httpMethod().equals("GET")) |
| 73 return false; |
| 74 |
| 75 // Any navigation from loadUrl, and goBack/Forward are considered application- |
| 76 // initiated and hence will not yield a shouldOverrideUrlLoading() callback. |
| 77 // Webview classic does not consider reload application-initiated so we |
| 78 // continue the same behavior. |
| 79 // TODO(sgurun) is_content_initiated is normally false for cross-origin |
| 80 // navigations but since android_webview does not swap out renderers, this |
| 81 // works fine. This will stop working if android_webview starts swapping out |
| 82 // renderers on navigation. |
| 83 bool application_initiated = |
| 84 !document_state->navigation_state()->is_content_initiated() |
| 85 || type == blink::WebNavigationTypeBackForward; |
| 86 |
| 87 // Don't offer application-initiated navigations unless it's a redirect. |
| 88 if (application_initiated && !is_redirect) |
| 89 return false; |
| 90 |
| 91 const GURL& gurl = request.url(); |
| 92 // For HTTP schemes, only top-level navigations can be overridden. Similarly, |
| 93 // WebView Classic lets app override only top level about:blank navigations. |
| 94 // So we filter out non-top about:blank navigations here. |
| 95 if (frame->parent() && (gurl.SchemeIs(content::kHttpScheme) || |
| 96 gurl.SchemeIs(content::kHttpsScheme) || |
| 97 gurl.SchemeIs(chrome::kAboutScheme))) |
| 98 return false; |
| 99 |
| 100 // use NavigationInterception throttle to handle the call as that can |
| 101 // be deferred until after the java side has been constructed. |
| 102 if (opener_id != MSG_ROUTING_NONE) { |
| 103 return false; |
| 104 } |
| 105 |
| 106 bool ignore_navigation = false; |
| 107 base::string16 url = request.url().string(); |
| 108 |
| 109 int routing_id = view->GetRoutingID(); |
| 110 RenderThread::Get()->Send(new AwViewHostMsg_ShouldOverrideUrlLoading( |
| 111 routing_id, url, &ignore_navigation)); |
| 112 return ignore_navigation; |
| 113 } |
| 114 |
| 52 void AwContentRendererClient::RenderViewCreated( | 115 void AwContentRendererClient::RenderViewCreated( |
| 53 content::RenderView* render_view) { | 116 content::RenderView* render_view) { |
| 54 AwRenderViewExt::RenderViewCreated(render_view); | 117 AwRenderViewExt::RenderViewCreated(render_view); |
| 55 | 118 |
| 56 new printing::PrintWebViewHelper(render_view); | 119 new printing::PrintWebViewHelper(render_view); |
| 57 // TODO(sgurun) do not create a password autofill agent (change | 120 // TODO(sgurun) do not create a password autofill agent (change |
| 58 // autofill agent to store a weakptr). | 121 // autofill agent to store a weakptr). |
| 59 autofill::PasswordAutofillAgent* password_autofill_agent = | 122 autofill::PasswordAutofillAgent* password_autofill_agent = |
| 60 new autofill::PasswordAutofillAgent(render_view); | 123 new autofill::PasswordAutofillAgent(render_view); |
| 61 new autofill::AutofillAgent(render_view, password_autofill_agent); | 124 new autofill::AutofillAgent(render_view, password_autofill_agent); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 bool AwContentRendererClient::IsLinkVisited(unsigned long long link_hash) { | 172 bool AwContentRendererClient::IsLinkVisited(unsigned long long link_hash) { |
| 110 return visited_link_slave_->IsVisited(link_hash); | 173 return visited_link_slave_->IsVisited(link_hash); |
| 111 } | 174 } |
| 112 | 175 |
| 113 void AwContentRendererClient::AddKeySystems( | 176 void AwContentRendererClient::AddKeySystems( |
| 114 std::vector<content::KeySystemInfo>* key_systems) { | 177 std::vector<content::KeySystemInfo>* key_systems) { |
| 115 AwAddKeySystems(key_systems); | 178 AwAddKeySystems(key_systems); |
| 116 } | 179 } |
| 117 | 180 |
| 118 } // namespace android_webview | 181 } // namespace android_webview |
| OLD | NEW |