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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "android_webview/common/aw_resource.h" | 9 #include "android_webview/common/aw_resource.h" |
10 #include "android_webview/common/aw_switches.h" | 10 #include "android_webview/common/aw_switches.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "base/command_line.h" | 22 #include "base/command_line.h" |
23 #include "base/i18n/rtl.h" | 23 #include "base/i18n/rtl.h" |
24 #include "base/message_loop/message_loop.h" | 24 #include "base/message_loop/message_loop.h" |
25 #include "base/strings/string_util.h" | 25 #include "base/strings/string_util.h" |
26 #include "base/strings/utf_string_conversions.h" | 26 #include "base/strings/utf_string_conversions.h" |
27 #include "components/autofill/content/renderer/autofill_agent.h" | 27 #include "components/autofill/content/renderer/autofill_agent.h" |
28 #include "components/autofill/content/renderer/password_autofill_agent.h" | 28 #include "components/autofill/content/renderer/password_autofill_agent.h" |
29 #include "components/printing/renderer/print_web_view_helper.h" | 29 #include "components/printing/renderer/print_web_view_helper.h" |
30 #include "components/visitedlink/renderer/visitedlink_slave.h" | 30 #include "components/visitedlink/renderer/visitedlink_slave.h" |
31 #include "content/public/common/url_constants.h" | 31 #include "content/public/common/url_constants.h" |
| 32 #include "content/public/renderer/document_state.h" |
| 33 #include "content/public/renderer/navigation_state.h" |
32 #include "content/public/renderer/render_frame.h" | 34 #include "content/public/renderer/render_frame.h" |
33 #include "content/public/renderer/render_thread.h" | 35 #include "content/public/renderer/render_thread.h" |
34 #include "content/public/renderer/render_view.h" | 36 #include "content/public/renderer/render_view.h" |
35 #include "net/base/escape.h" | 37 #include "net/base/escape.h" |
36 #include "net/base/net_errors.h" | 38 #include "net/base/net_errors.h" |
37 #include "third_party/WebKit/public/platform/WebString.h" | 39 #include "third_party/WebKit/public/platform/WebString.h" |
38 #include "third_party/WebKit/public/platform/WebURL.h" | 40 #include "third_party/WebKit/public/platform/WebURL.h" |
39 #include "third_party/WebKit/public/platform/WebURLError.h" | 41 #include "third_party/WebKit/public/platform/WebURLError.h" |
40 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 42 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
41 #include "third_party/WebKit/public/web/WebFrame.h" | 43 #include "third_party/WebKit/public/web/WebFrame.h" |
| 44 #include "third_party/WebKit/public/web/WebNavigationType.h" |
42 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" | 45 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
43 #include "ui/base/l10n/l10n_util.h" | 46 #include "ui/base/l10n/l10n_util.h" |
44 #include "ui/base/resource/resource_bundle.h" | 47 #include "ui/base/resource/resource_bundle.h" |
45 #include "url/gurl.h" | 48 #include "url/gurl.h" |
46 #include "url/url_constants.h" | 49 #include "url/url_constants.h" |
47 | 50 |
48 using content::RenderThread; | 51 using content::RenderThread; |
49 | 52 |
50 namespace android_webview { | 53 namespace android_webview { |
51 | 54 |
(...skipping 17 matching lines...) Expand all Loading... |
69 thread->EnsureWebKitInitialized(); | 72 thread->EnsureWebKitInitialized(); |
70 | 73 |
71 blink::WebString content_scheme(base::ASCIIToUTF16(url::kContentScheme)); | 74 blink::WebString content_scheme(base::ASCIIToUTF16(url::kContentScheme)); |
72 blink::WebSecurityPolicy::registerURLSchemeAsLocal(content_scheme); | 75 blink::WebSecurityPolicy::registerURLSchemeAsLocal(content_scheme); |
73 | 76 |
74 blink::WebString aw_scheme( | 77 blink::WebString aw_scheme( |
75 base::ASCIIToUTF16(android_webview::kAndroidWebViewVideoPosterScheme)); | 78 base::ASCIIToUTF16(android_webview::kAndroidWebViewVideoPosterScheme)); |
76 blink::WebSecurityPolicy::registerURLSchemeAsSecure(aw_scheme); | 79 blink::WebSecurityPolicy::registerURLSchemeAsSecure(aw_scheme); |
77 } | 80 } |
78 | 81 |
| 82 bool AwContentRendererClient::HandleNavigation( |
| 83 content::RenderFrame* render_frame, |
| 84 bool is_content_initiated, |
| 85 int opener_id, |
| 86 blink::WebFrame* frame, |
| 87 const blink::WebURLRequest& request, |
| 88 blink::WebNavigationType type, |
| 89 blink::WebNavigationPolicy default_policy, |
| 90 bool is_redirect) { |
| 91 // Only GETs can be overridden. |
| 92 if (!request.httpMethod().equals("GET")) |
| 93 return false; |
| 94 |
| 95 // Any navigation from loadUrl, and goBack/Forward are considered application- |
| 96 // initiated and hence will not yield a shouldOverrideUrlLoading() callback. |
| 97 // Webview classic does not consider reload application-initiated so we |
| 98 // continue the same behavior. |
| 99 // TODO(sgurun) is_content_initiated is normally false for cross-origin |
| 100 // navigations but since android_webview does not swap out renderers, this |
| 101 // works fine. This will stop working if android_webview starts swapping out |
| 102 // renderers on navigation. |
| 103 bool application_initiated = |
| 104 !is_content_initiated || type == blink::WebNavigationTypeBackForward; |
| 105 |
| 106 // Don't offer application-initiated navigations unless it's a redirect. |
| 107 if (application_initiated && !is_redirect) |
| 108 return false; |
| 109 |
| 110 bool is_main_frame = !frame->parent(); |
| 111 const GURL& gurl = request.url(); |
| 112 // For HTTP schemes, only top-level navigations can be overridden. Similarly, |
| 113 // WebView Classic lets app override only top level about:blank navigations. |
| 114 // So we filter out non-top about:blank navigations here. |
| 115 if (!is_main_frame && |
| 116 (gurl.SchemeIs(url::kHttpScheme) || gurl.SchemeIs(url::kHttpsScheme) || |
| 117 gurl.SchemeIs(url::kAboutScheme))) |
| 118 return false; |
| 119 |
| 120 // use NavigationInterception throttle to handle the call as that can |
| 121 // be deferred until after the java side has been constructed. |
| 122 if (opener_id != MSG_ROUTING_NONE) { |
| 123 return false; |
| 124 } |
| 125 |
| 126 bool ignore_navigation = false; |
| 127 base::string16 url = request.url().string(); |
| 128 bool has_user_gesture = request.hasUserGesture(); |
| 129 |
| 130 int render_frame_id = render_frame->GetRoutingID(); |
| 131 RenderThread::Get()->Send(new AwViewHostMsg_ShouldOverrideUrlLoading( |
| 132 render_frame_id, url, has_user_gesture, is_redirect, is_main_frame, |
| 133 &ignore_navigation)); |
| 134 return ignore_navigation; |
| 135 } |
| 136 |
79 void AwContentRendererClient::RenderFrameCreated( | 137 void AwContentRendererClient::RenderFrameCreated( |
80 content::RenderFrame* render_frame) { | 138 content::RenderFrame* render_frame) { |
81 new AwContentSettingsClient(render_frame); | 139 new AwContentSettingsClient(render_frame); |
82 new PrintRenderFrameObserver(render_frame); | 140 new PrintRenderFrameObserver(render_frame); |
83 new AwRenderFrameExt(render_frame); | 141 new AwRenderFrameExt(render_frame); |
84 new AwMessagePortClient(render_frame); | 142 new AwMessagePortClient(render_frame); |
85 | 143 |
86 // TODO(jam): when the frame tree moves into content and parent() works at | 144 // TODO(jam): when the frame tree moves into content and parent() works at |
87 // RenderFrame construction, simplify this by just checking parent(). | 145 // RenderFrame construction, simplify this by just checking parent(). |
88 content::RenderFrame* parent_frame = | 146 content::RenderFrame* parent_frame = |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 blink::WebPageVisibilityState* override_state) { | 236 blink::WebPageVisibilityState* override_state) { |
179 if (disable_page_visibility_) { | 237 if (disable_page_visibility_) { |
180 *override_state = blink::WebPageVisibilityStateVisible; | 238 *override_state = blink::WebPageVisibilityStateVisible; |
181 return true; | 239 return true; |
182 } | 240 } |
183 | 241 |
184 return false; | 242 return false; |
185 } | 243 } |
186 | 244 |
187 } // namespace android_webview | 245 } // namespace android_webview |
OLD | NEW |