OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/browser/aw_content_browser_client.h" | 5 #include "android_webview/browser/aw_content_browser_client.h" |
6 | 6 |
7 #include "android_webview/browser/aw_browser_context.h" | 7 #include "android_webview/browser/aw_browser_context.h" |
8 #include "android_webview/browser/aw_browser_main_parts.h" | 8 #include "android_webview/browser/aw_browser_main_parts.h" |
9 #include "android_webview/browser/aw_contents_client_bridge_base.h" | 9 #include "android_webview/browser/aw_contents_client_bridge_base.h" |
10 #include "android_webview/browser/aw_contents_io_thread_client.h" | 10 #include "android_webview/browser/aw_contents_io_thread_client.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "android_webview/common/render_view_messages.h" | 22 #include "android_webview/common/render_view_messages.h" |
23 #include "android_webview/common/url_constants.h" | 23 #include "android_webview/common/url_constants.h" |
24 #include "base/android/locale_utils.h" | 24 #include "base/android/locale_utils.h" |
25 #include "base/base_paths_android.h" | 25 #include "base/base_paths_android.h" |
26 #include "base/command_line.h" | 26 #include "base/command_line.h" |
27 #include "base/path_service.h" | 27 #include "base/path_service.h" |
28 #include "components/cdm/browser/cdm_message_filter_android.h" | 28 #include "components/cdm/browser/cdm_message_filter_android.h" |
29 #include "components/navigation_interception/intercept_navigation_delegate.h" | 29 #include "components/navigation_interception/intercept_navigation_delegate.h" |
30 #include "content/public/browser/access_token_store.h" | 30 #include "content/public/browser/access_token_store.h" |
31 #include "content/public/browser/browser_message_filter.h" | 31 #include "content/public/browser/browser_message_filter.h" |
32 #include "content/public/browser/browser_thread.h" | |
33 #include "content/public/browser/child_process_security_policy.h" | 32 #include "content/public/browser/child_process_security_policy.h" |
34 #include "content/public/browser/client_certificate_delegate.h" | 33 #include "content/public/browser/client_certificate_delegate.h" |
35 #include "content/public/browser/navigation_handle.h" | 34 #include "content/public/browser/navigation_handle.h" |
36 #include "content/public/browser/navigation_throttle.h" | 35 #include "content/public/browser/navigation_throttle.h" |
37 #include "content/public/browser/render_frame_host.h" | 36 #include "content/public/browser/render_frame_host.h" |
38 #include "content/public/browser/render_process_host.h" | 37 #include "content/public/browser/render_process_host.h" |
39 #include "content/public/browser/render_view_host.h" | 38 #include "content/public/browser/render_view_host.h" |
40 #include "content/public/browser/web_contents.h" | 39 #include "content/public/browser/web_contents.h" |
41 #include "content/public/common/content_switches.h" | 40 #include "content/public/common/content_switches.h" |
42 #include "content/public/common/url_constants.h" | 41 #include "content/public/common/url_constants.h" |
43 #include "content/public/common/web_preferences.h" | 42 #include "content/public/common/web_preferences.h" |
44 #include "net/android/network_library.h" | 43 #include "net/android/network_library.h" |
45 #include "net/ssl/ssl_cert_request_info.h" | 44 #include "net/ssl/ssl_cert_request_info.h" |
46 #include "net/ssl/ssl_info.h" | 45 #include "net/ssl/ssl_info.h" |
47 #include "ui/base/resource/resource_bundle.h" | 46 #include "ui/base/resource/resource_bundle.h" |
48 #include "ui/base/resource/resource_bundle_android.h" | 47 #include "ui/base/resource/resource_bundle_android.h" |
49 #include "ui/resources/grit/ui_resources.h" | 48 #include "ui/resources/grit/ui_resources.h" |
50 | 49 |
51 using content::BrowserThread; | |
52 using content::ResourceType; | 50 using content::ResourceType; |
53 | 51 |
54 namespace android_webview { | 52 namespace android_webview { |
55 namespace { | 53 namespace { |
56 | 54 |
57 // TODO(sgurun) move this to its own file. | 55 // TODO(sgurun) move this to its own file. |
58 // This class filters out incoming aw_contents related IPC messages for the | 56 // This class filters out incoming aw_contents related IPC messages for the |
59 // renderer process on the IPC thread. | 57 // renderer process on the IPC thread. |
60 class AwContentsMessageFilter : public content::BrowserMessageFilter { | 58 class AwContentsMessageFilter : public content::BrowserMessageFilter { |
61 public: | 59 public: |
62 explicit AwContentsMessageFilter(int process_id); | 60 explicit AwContentsMessageFilter(int process_id); |
63 | 61 |
64 // BrowserMessageFilter methods. | 62 // BrowserMessageFilter methods. |
65 void OverrideThreadForMessage(const IPC::Message& message, | |
66 BrowserThread::ID* thread) override; | |
67 bool OnMessageReceived(const IPC::Message& message) override; | 63 bool OnMessageReceived(const IPC::Message& message) override; |
68 | 64 |
69 void OnShouldOverrideUrlLoading(int routing_id, | |
70 const base::string16& url, | |
71 bool has_user_gesture, | |
72 bool is_redirect, | |
73 bool is_main_frame, | |
74 bool* ignore_navigation); | |
75 void OnSubFrameCreated(int parent_render_frame_id, int child_render_frame_id); | 65 void OnSubFrameCreated(int parent_render_frame_id, int child_render_frame_id); |
76 | 66 |
77 private: | 67 private: |
78 ~AwContentsMessageFilter() override; | 68 ~AwContentsMessageFilter() override; |
79 | 69 |
80 int process_id_; | 70 int process_id_; |
81 | 71 |
82 DISALLOW_COPY_AND_ASSIGN(AwContentsMessageFilter); | 72 DISALLOW_COPY_AND_ASSIGN(AwContentsMessageFilter); |
83 }; | 73 }; |
84 | 74 |
85 AwContentsMessageFilter::AwContentsMessageFilter(int process_id) | 75 AwContentsMessageFilter::AwContentsMessageFilter(int process_id) |
86 : BrowserMessageFilter(AndroidWebViewMsgStart), | 76 : BrowserMessageFilter(AndroidWebViewMsgStart), |
87 process_id_(process_id) { | 77 process_id_(process_id) { |
88 } | 78 } |
89 | 79 |
90 AwContentsMessageFilter::~AwContentsMessageFilter() { | 80 AwContentsMessageFilter::~AwContentsMessageFilter() { |
91 } | 81 } |
92 | 82 |
93 void AwContentsMessageFilter::OverrideThreadForMessage( | |
94 const IPC::Message& message, | |
95 BrowserThread::ID* thread) { | |
96 if (message.type() == AwViewHostMsg_ShouldOverrideUrlLoading::ID) { | |
97 *thread = BrowserThread::UI; | |
98 } | |
99 } | |
100 | |
101 bool AwContentsMessageFilter::OnMessageReceived(const IPC::Message& message) { | 83 bool AwContentsMessageFilter::OnMessageReceived(const IPC::Message& message) { |
102 bool handled = true; | 84 bool handled = true; |
103 IPC_BEGIN_MESSAGE_MAP(AwContentsMessageFilter, message) | 85 IPC_BEGIN_MESSAGE_MAP(AwContentsMessageFilter, message) |
104 IPC_MESSAGE_HANDLER(AwViewHostMsg_ShouldOverrideUrlLoading, | |
105 OnShouldOverrideUrlLoading) | |
106 IPC_MESSAGE_HANDLER(AwViewHostMsg_SubFrameCreated, OnSubFrameCreated) | 86 IPC_MESSAGE_HANDLER(AwViewHostMsg_SubFrameCreated, OnSubFrameCreated) |
107 IPC_MESSAGE_UNHANDLED(handled = false) | 87 IPC_MESSAGE_UNHANDLED(handled = false) |
108 IPC_END_MESSAGE_MAP() | 88 IPC_END_MESSAGE_MAP() |
109 return handled; | 89 return handled; |
110 } | 90 } |
111 | 91 |
112 void AwContentsMessageFilter::OnShouldOverrideUrlLoading( | |
113 int render_frame_id, | |
114 const base::string16& url, | |
115 bool has_user_gesture, | |
116 bool is_redirect, | |
117 bool is_main_frame, | |
118 bool* ignore_navigation) { | |
119 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
120 *ignore_navigation = false; | |
121 AwContentsClientBridgeBase* client = | |
122 AwContentsClientBridgeBase::FromID(process_id_, render_frame_id); | |
123 if (client) { | |
124 *ignore_navigation = client->ShouldOverrideUrlLoading( | |
125 url, has_user_gesture, is_redirect, is_main_frame); | |
126 } else { | |
127 LOG(WARNING) << "Failed to find the associated render view host for url: " | |
128 << url; | |
129 } | |
130 } | |
131 | |
132 void AwContentsMessageFilter::OnSubFrameCreated(int parent_render_frame_id, | 92 void AwContentsMessageFilter::OnSubFrameCreated(int parent_render_frame_id, |
133 int child_render_frame_id) { | 93 int child_render_frame_id) { |
134 AwContentsIoThreadClient::SubFrameCreated( | 94 AwContentsIoThreadClient::SubFrameCreated( |
135 process_id_, parent_render_frame_id, child_render_frame_id); | 95 process_id_, parent_render_frame_id, child_render_frame_id); |
136 } | 96 } |
137 | 97 |
138 class AwAccessTokenStore : public content::AccessTokenStore { | 98 class AwAccessTokenStore : public content::AccessTokenStore { |
139 public: | 99 public: |
140 AwAccessTokenStore() { } | 100 AwAccessTokenStore() { } |
141 | 101 |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 CreateWebPreferencesPopulater()); | 496 CreateWebPreferencesPopulater()); |
537 } | 497 } |
538 preferences_populater_->PopulateFor( | 498 preferences_populater_->PopulateFor( |
539 content::WebContents::FromRenderViewHost(rvh), web_prefs); | 499 content::WebContents::FromRenderViewHost(rvh), web_prefs); |
540 } | 500 } |
541 | 501 |
542 ScopedVector<content::NavigationThrottle> | 502 ScopedVector<content::NavigationThrottle> |
543 AwContentBrowserClient::CreateThrottlesForNavigation( | 503 AwContentBrowserClient::CreateThrottlesForNavigation( |
544 content::NavigationHandle* navigation_handle) { | 504 content::NavigationHandle* navigation_handle) { |
545 ScopedVector<content::NavigationThrottle> throttles; | 505 ScopedVector<content::NavigationThrottle> throttles; |
546 // We allow intercepting only navigations within main frames. This | 506 if (navigation_handle->IsInMainFrame() || |
547 // is used to post onPageStarted. We handle shouldOverrideUrlLoading | 507 (!navigation_handle->GetURL().SchemeIs(url::kHttpScheme) && |
548 // via a sync IPC. | 508 !navigation_handle->GetURL().SchemeIs(url::kHttpsScheme) && |
549 if (navigation_handle->IsInMainFrame()) { | 509 !navigation_handle->GetURL().SchemeIs(url::kAboutScheme))) { |
550 throttles.push_back( | 510 throttles.push_back( |
551 navigation_interception::InterceptNavigationDelegate::CreateThrottleFor( | 511 navigation_interception::InterceptNavigationDelegate::CreateThrottleFor( |
552 navigation_handle) | 512 navigation_handle) |
553 .Pass()); | 513 .Pass()); |
554 } | 514 } |
555 return throttles.Pass(); | 515 return throttles.Pass(); |
556 } | 516 } |
557 | 517 |
558 #if defined(VIDEO_HOLE) | 518 #if defined(VIDEO_HOLE) |
559 content::ExternalVideoSurfaceContainer* | 519 content::ExternalVideoSurfaceContainer* |
560 AwContentBrowserClient::OverrideCreateExternalVideoSurfaceContainer( | 520 AwContentBrowserClient::OverrideCreateExternalVideoSurfaceContainer( |
561 content::WebContents* web_contents) { | 521 content::WebContents* web_contents) { |
562 return native_factory_->CreateExternalVideoSurfaceContainer(web_contents); | 522 return native_factory_->CreateExternalVideoSurfaceContainer(web_contents); |
563 } | 523 } |
564 #endif | 524 #endif |
565 | 525 |
566 } // namespace android_webview | 526 } // namespace android_webview |
OLD | NEW |