Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: android_webview/renderer/aw_content_renderer_client.cc

Issue 1424263003: Reland "Use resource throttle to implement shouldOverrideUrlLoading, core change" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revert unnecessary change for making XHR test thread-safe (it was safe before the change). Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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"
34 #include "content/public/renderer/render_frame.h" 32 #include "content/public/renderer/render_frame.h"
35 #include "content/public/renderer/render_thread.h" 33 #include "content/public/renderer/render_thread.h"
36 #include "content/public/renderer/render_view.h" 34 #include "content/public/renderer/render_view.h"
37 #include "net/base/escape.h" 35 #include "net/base/escape.h"
38 #include "net/base/net_errors.h" 36 #include "net/base/net_errors.h"
39 #include "third_party/WebKit/public/platform/WebString.h" 37 #include "third_party/WebKit/public/platform/WebString.h"
40 #include "third_party/WebKit/public/platform/WebURL.h" 38 #include "third_party/WebKit/public/platform/WebURL.h"
41 #include "third_party/WebKit/public/platform/WebURLError.h" 39 #include "third_party/WebKit/public/platform/WebURLError.h"
42 #include "third_party/WebKit/public/platform/WebURLRequest.h" 40 #include "third_party/WebKit/public/platform/WebURLRequest.h"
43 #include "third_party/WebKit/public/web/WebFrame.h" 41 #include "third_party/WebKit/public/web/WebFrame.h"
44 #include "third_party/WebKit/public/web/WebNavigationType.h"
45 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" 42 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
46 #include "ui/base/l10n/l10n_util.h" 43 #include "ui/base/l10n/l10n_util.h"
47 #include "ui/base/resource/resource_bundle.h" 44 #include "ui/base/resource/resource_bundle.h"
48 #include "url/gurl.h" 45 #include "url/gurl.h"
49 #include "url/url_constants.h" 46 #include "url/url_constants.h"
50 47
51 using content::RenderThread; 48 using content::RenderThread;
52 49
53 namespace android_webview { 50 namespace android_webview {
54 51
(...skipping 17 matching lines...) Expand all
72 thread->EnsureWebKitInitialized(); 69 thread->EnsureWebKitInitialized();
73 70
74 blink::WebString content_scheme(base::ASCIIToUTF16(url::kContentScheme)); 71 blink::WebString content_scheme(base::ASCIIToUTF16(url::kContentScheme));
75 blink::WebSecurityPolicy::registerURLSchemeAsLocal(content_scheme); 72 blink::WebSecurityPolicy::registerURLSchemeAsLocal(content_scheme);
76 73
77 blink::WebString aw_scheme( 74 blink::WebString aw_scheme(
78 base::ASCIIToUTF16(android_webview::kAndroidWebViewVideoPosterScheme)); 75 base::ASCIIToUTF16(android_webview::kAndroidWebViewVideoPosterScheme));
79 blink::WebSecurityPolicy::registerURLSchemeAsSecure(aw_scheme); 76 blink::WebSecurityPolicy::registerURLSchemeAsSecure(aw_scheme);
80 } 77 }
81 78
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
137 void AwContentRendererClient::RenderFrameCreated( 79 void AwContentRendererClient::RenderFrameCreated(
138 content::RenderFrame* render_frame) { 80 content::RenderFrame* render_frame) {
139 new AwContentSettingsClient(render_frame); 81 new AwContentSettingsClient(render_frame);
140 new PrintRenderFrameObserver(render_frame); 82 new PrintRenderFrameObserver(render_frame);
141 new AwRenderFrameExt(render_frame); 83 new AwRenderFrameExt(render_frame);
142 new AwMessagePortClient(render_frame); 84 new AwMessagePortClient(render_frame);
143 85
144 // TODO(jam): when the frame tree moves into content and parent() works at 86 // TODO(jam): when the frame tree moves into content and parent() works at
145 // RenderFrame construction, simplify this by just checking parent(). 87 // RenderFrame construction, simplify this by just checking parent().
146 content::RenderFrame* parent_frame = 88 content::RenderFrame* parent_frame =
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 blink::WebPageVisibilityState* override_state) { 178 blink::WebPageVisibilityState* override_state) {
237 if (disable_page_visibility_) { 179 if (disable_page_visibility_) {
238 *override_state = blink::WebPageVisibilityStateVisible; 180 *override_state = blink::WebPageVisibilityStateVisible;
239 return true; 181 return true;
240 } 182 }
241 183
242 return false; 184 return false;
243 } 185 }
244 186
245 } // namespace android_webview 187 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698