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

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

Issue 24228003: Upstream ShouldOverrideUrlLoading changes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed code review Created 7 years, 2 months 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 "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_render_view_ext.h" 10 #include "android_webview/renderer/aw_render_view_ext.h"
10 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
11 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
12 #include "components/autofill/content/renderer/autofill_agent.h" 13 #include "components/autofill/content/renderer/autofill_agent.h"
13 #include "components/autofill/content/renderer/password_autofill_agent.h" 14 #include "components/autofill/content/renderer/password_autofill_agent.h"
14 #include "components/visitedlink/renderer/visitedlink_slave.h" 15 #include "components/visitedlink/renderer/visitedlink_slave.h"
16 #include "content/public/common/url_constants.h"
17 #include "content/public/renderer/document_state.h"
18 #include "content/public/renderer/navigation_state.h"
15 #include "content/public/renderer/render_thread.h" 19 #include "content/public/renderer/render_thread.h"
20 #include "content/public/renderer/render_view.h"
16 #include "net/base/net_errors.h" 21 #include "net/base/net_errors.h"
17 #include "third_party/WebKit/public/platform/WebString.h" 22 #include "third_party/WebKit/public/platform/WebString.h"
18 #include "third_party/WebKit/public/platform/WebURL.h" 23 #include "third_party/WebKit/public/platform/WebURL.h"
19 #include "third_party/WebKit/public/platform/WebURLError.h" 24 #include "third_party/WebKit/public/platform/WebURLError.h"
20 #include "third_party/WebKit/public/platform/WebURLRequest.h" 25 #include "third_party/WebKit/public/platform/WebURLRequest.h"
26 #include "third_party/WebKit/public/web/WebFrame.h"
27 #include "third_party/WebKit/public/web/WebNavigationType.h"
21 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" 28 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
22 #include "url/gurl.h" 29 #include "url/gurl.h"
23 30
31 using content::RenderThread;
32
24 namespace android_webview { 33 namespace android_webview {
25 34
26 AwContentRendererClient::AwContentRendererClient() { 35 AwContentRendererClient::AwContentRendererClient() {
27 } 36 }
28 37
29 AwContentRendererClient::~AwContentRendererClient() { 38 AwContentRendererClient::~AwContentRendererClient() {
30 } 39 }
31 40
32 void AwContentRendererClient::RenderThreadStarted() { 41 void AwContentRendererClient::RenderThreadStarted() {
33 WebKit::WebString content_scheme( 42 WebKit::WebString content_scheme(
34 ASCIIToUTF16(android_webview::kContentScheme)); 43 ASCIIToUTF16(android_webview::kContentScheme));
35 WebKit::WebSecurityPolicy::registerURLSchemeAsLocal(content_scheme); 44 WebKit::WebSecurityPolicy::registerURLSchemeAsLocal(content_scheme);
36 45
37 content::RenderThread* thread = content::RenderThread::Get(); 46 RenderThread* thread = content::RenderThread::Get();
38 47
39 aw_render_process_observer_.reset(new AwRenderProcessObserver); 48 aw_render_process_observer_.reset(new AwRenderProcessObserver);
40 thread->AddObserver(aw_render_process_observer_.get()); 49 thread->AddObserver(aw_render_process_observer_.get());
41 50
42 visited_link_slave_.reset(new visitedlink::VisitedLinkSlave); 51 visited_link_slave_.reset(new visitedlink::VisitedLinkSlave);
43 thread->AddObserver(visited_link_slave_.get()); 52 thread->AddObserver(visited_link_slave_.get());
44 } 53 }
45 54
55 bool AwContentRendererClient::HandleNavigation(
56 content::RenderView* view,
57 content::DocumentState* document_state,
58 int opener_id,
59 WebKit::WebFrame* frame,
60 const WebKit::WebURLRequest& request,
61 WebKit::WebNavigationType type,
62 WebKit::WebNavigationPolicy default_policy,
63 bool is_redirect) {
64
65 // Only GETs can be overridden.
66 if (!request.httpMethod().equals("GET"))
67 return false;
68
69 // Any navigation from loadUrl, and goBack/Forward are considered application-
70 // initiated and hence will not yield a shouldOverrideUrlLoading() callback.
71 // Webview classic does not consider reload application-initiated so we
72 // continue the same behavior.
73 // TODO(sgurun) is_content_initiated is normally false for cross-origin
74 // navigations but since android_webview does not swap out renderers, this
75 // works fine. This will stop working if android_webview starts swapping out
76 // renderers on navigation.
77 bool application_initiated =
78 !document_state->navigation_state()->is_content_initiated()
79 || type == WebKit::WebNavigationTypeBackForward;
80
81 // Don't offer application-initiated navigations unless it's a redirect.
82 if (application_initiated && !is_redirect)
83 return false;
84
85 const GURL& gurl = request.url();
86 // For HTTP schemes, only top-level navigations can be overridden.
87 // HandleNavigation receives about:blank navigations, (for example for
88 // empty iframes), however webview classic does not pass these to the
89 // app using shouldoverrideurlloading, so we filter them out here. Not
90 // adding a special test for this, since removing the filtering causes
91 // multiple shouldoverrideurlloading aw tests to fail, anyway.
92 // 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.
93 // navigations.
94 if (frame->parent() && (gurl.SchemeIs(content::kHttpScheme) ||
95 gurl.SchemeIs(content::kHttpsScheme) ||
96 gurl.SchemeIs(chrome::kAboutScheme)))
97 return false;
98
99 bool ignore_navigation = false;
100 base::string16 url = request.url().string();
101
102 int routing_id = view->GetRoutingID();
103 // When opener_id is valid (popup case), use opener id for routing.
104 if (opener_id != MSG_ROUTING_NONE)
105 routing_id = opener_id;
106 RenderThread::Get()->Send(new AwViewHostMsg_ShouldOverrideUrlLoading(
107 routing_id, url, &ignore_navigation));
108
109 return ignore_navigation;
110 }
111
46 void AwContentRendererClient::RenderViewCreated( 112 void AwContentRendererClient::RenderViewCreated(
47 content::RenderView* render_view) { 113 content::RenderView* render_view) {
48 AwRenderViewExt::RenderViewCreated(render_view); 114 AwRenderViewExt::RenderViewCreated(render_view);
49 115
50 // TODO(sgurun) do not create a password autofill agent (change 116 // TODO(sgurun) do not create a password autofill agent (change
51 // autofill agent to store a weakptr). 117 // autofill agent to store a weakptr).
52 autofill::PasswordAutofillAgent* password_autofill_agent = 118 autofill::PasswordAutofillAgent* password_autofill_agent =
53 new autofill::PasswordAutofillAgent(render_view); 119 new autofill::PasswordAutofillAgent(render_view);
54 new autofill::AutofillAgent(render_view, password_autofill_agent); 120 new autofill::AutofillAgent(render_view, password_autofill_agent);
55 } 121 }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 const char* canonical_url, 163 const char* canonical_url,
98 size_t length) { 164 size_t length) {
99 return visited_link_slave_->ComputeURLFingerprint(canonical_url, length); 165 return visited_link_slave_->ComputeURLFingerprint(canonical_url, length);
100 } 166 }
101 167
102 bool AwContentRendererClient::IsLinkVisited(unsigned long long link_hash) { 168 bool AwContentRendererClient::IsLinkVisited(unsigned long long link_hash) {
103 return visited_link_slave_->IsVisited(link_hash); 169 return visited_link_slave_->IsVisited(link_hash);
104 } 170 }
105 171
106 } // namespace android_webview 172 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698