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 "chrome/browser/external_protocol/external_protocol_handler.h" | 5 #include "chrome/browser/external_protocol/external_protocol_handler.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | |
9 #include <set> | 8 #include <set> |
10 | 9 |
11 #include "base/bind.h" | 10 #include "base/bind.h" |
12 #include "base/logging.h" | 11 #include "base/logging.h" |
13 #include "base/macros.h" | 12 #include "base/macros.h" |
14 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
15 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
16 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
17 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
18 #include "build/build_config.h" | 17 #include "build/build_config.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 url, render_process_host_id, routing_id, page_transition, | 74 url, render_process_host_id, routing_id, page_transition, |
76 has_user_gesture); | 75 has_user_gesture); |
77 } | 76 } |
78 } | 77 } |
79 | 78 |
80 void LaunchUrlWithoutSecurityCheckWithDelegate( | 79 void LaunchUrlWithoutSecurityCheckWithDelegate( |
81 const GURL& url, | 80 const GURL& url, |
82 int render_process_host_id, | 81 int render_process_host_id, |
83 int tab_contents_id, | 82 int tab_contents_id, |
84 ExternalProtocolHandler::Delegate* delegate) { | 83 ExternalProtocolHandler::Delegate* delegate) { |
84 content::WebContents* web_contents = | |
85 tab_util::GetWebContentsByID(render_process_host_id, tab_contents_id); | |
86 | |
85 if (!delegate) { | 87 if (!delegate) { |
86 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck( | 88 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck(url, web_contents); |
87 url, render_process_host_id, tab_contents_id); | |
88 } else { | 89 } else { |
89 delegate->LaunchUrlWithoutSecurityCheck(url); | 90 delegate->LaunchUrlWithoutSecurityCheck(url, web_contents); |
90 } | 91 } |
91 } | 92 } |
92 | 93 |
93 // When we are about to launch a URL with the default OS level application, we | 94 // When we are about to launch a URL with the default OS level application, we |
94 // check if the external application will be us. If it is we just ignore the | 95 // check if the external application will be us. If it is we just ignore the |
95 // request. | 96 // request. |
96 void OnDefaultProtocolClientWorkerFinished( | 97 void OnDefaultProtocolClientWorkerFinished( |
97 const GURL& escaped_url, | 98 const GURL& escaped_url, |
98 int render_process_host_id, | 99 int render_process_host_id, |
99 int tab_contents_id, | 100 int tab_contents_id, |
100 bool prompt_user, | 101 bool prompt_user, |
101 ui::PageTransition page_transition, | 102 ui::PageTransition page_transition, |
102 bool has_user_gesture, | 103 bool has_user_gesture, |
103 ExternalProtocolHandler::Delegate* delegate, | 104 ExternalProtocolHandler::Delegate* delegate, |
104 shell_integration::DefaultWebClientState state) { | 105 shell_integration::DefaultWebClientState state) { |
105 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 106 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
106 | 107 |
107 if (delegate) | 108 if (delegate) |
108 delegate->FinishedProcessingCheck(); | 109 delegate->FinishedProcessingCheck(); |
109 | |
alexmos
2016/12/01 19:21:14
No need to remove the blank line, here and in a fe
davidsac (gone - try alexmos)
2016/12/12 19:15:47
Done.
| |
110 if (state == shell_integration::IS_DEFAULT) { | 110 if (state == shell_integration::IS_DEFAULT) { |
111 if (delegate) | 111 if (delegate) |
112 delegate->BlockRequest(); | 112 delegate->BlockRequest(); |
113 return; | 113 return; |
114 } | 114 } |
115 | 115 |
116 // If we get here, either we are not the default or we cannot work out | 116 // If we get here, either we are not the default or we cannot work out |
117 // what the default is, so we proceed. | 117 // what the default is, so we proceed. |
118 if (prompt_user) { | 118 if (prompt_user) { |
119 // Ask the user if they want to allow the protocol. This will call | 119 // Ask the user if they want to allow the protocol. This will call |
120 // LaunchUrlWithoutSecurityCheck if the user decides to accept the | 120 // LaunchUrlWithoutSecurityCheck if the user decides to accept the |
121 // protocol. | 121 // protocol. |
122 RunExternalProtocolDialogWithDelegate(escaped_url, render_process_host_id, | 122 RunExternalProtocolDialogWithDelegate(escaped_url, render_process_host_id, |
123 tab_contents_id, page_transition, | 123 tab_contents_id, page_transition, |
124 has_user_gesture, delegate); | 124 has_user_gesture, delegate); |
125 return; | 125 return; |
126 } | 126 } |
127 | |
128 LaunchUrlWithoutSecurityCheckWithDelegate(escaped_url, render_process_host_id, | 127 LaunchUrlWithoutSecurityCheckWithDelegate(escaped_url, render_process_host_id, |
129 tab_contents_id, delegate); | 128 tab_contents_id, delegate); |
130 } | 129 } |
131 | 130 |
132 } // namespace | 131 } // namespace |
133 | 132 |
134 // static | 133 // static |
135 ExternalProtocolHandler::BlockState ExternalProtocolHandler::GetBlockState( | 134 ExternalProtocolHandler::BlockState ExternalProtocolHandler::GetBlockState( |
136 const std::string& scheme) { | 135 const std::string& scheme) { |
137 // If we are being carpet bombed, block the request. | 136 // If we are being carpet bombed, block the request. |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
215 // Start the check process running. This will send tasks to the FILE thread | 214 // Start the check process running. This will send tasks to the FILE thread |
216 // and when the answer is known will send the result back to | 215 // and when the answer is known will send the result back to |
217 // OnDefaultProtocolClientWorkerFinished(). | 216 // OnDefaultProtocolClientWorkerFinished(). |
218 CreateShellWorker(callback, escaped_url.scheme(), delegate) | 217 CreateShellWorker(callback, escaped_url.scheme(), delegate) |
219 ->StartCheckIsDefault(); | 218 ->StartCheckIsDefault(); |
220 } | 219 } |
221 | 220 |
222 // static | 221 // static |
223 void ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck( | 222 void ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck( |
224 const GURL& url, | 223 const GURL& url, |
225 int render_process_host_id, | 224 content::WebContents* web_contents) { |
226 int tab_contents_id) { | |
227 content::WebContents* web_contents = tab_util::GetWebContentsByID( | |
228 render_process_host_id, tab_contents_id); | |
229 if (!web_contents) | 225 if (!web_contents) |
230 return; | 226 return; |
231 | |
232 platform_util::OpenExternal( | 227 platform_util::OpenExternal( |
233 Profile::FromBrowserContext(web_contents->GetBrowserContext()), url); | 228 Profile::FromBrowserContext(web_contents->GetBrowserContext()), url); |
234 } | 229 } |
235 | 230 |
236 // static | 231 // static |
237 void ExternalProtocolHandler::PermitLaunchUrl() { | 232 void ExternalProtocolHandler::PermitLaunchUrl() { |
238 DCHECK(base::MessageLoopForUI::IsCurrent()); | 233 DCHECK(base::MessageLoopForUI::IsCurrent()); |
239 g_accept_requests = true; | 234 g_accept_requests = true; |
240 } | 235 } |
241 | 236 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
293 // static | 288 // static |
294 void ExternalProtocolHandler::RecordMetrics(bool selected) { | 289 void ExternalProtocolHandler::RecordMetrics(bool selected) { |
295 UMA_HISTOGRAM_BOOLEAN("BrowserDialogs.ExternalProtocol.RememberCheckbox", | 290 UMA_HISTOGRAM_BOOLEAN("BrowserDialogs.ExternalProtocol.RememberCheckbox", |
296 selected); | 291 selected); |
297 } | 292 } |
298 | 293 |
299 // static | 294 // static |
300 void ExternalProtocolHandler::RegisterPrefs(PrefRegistrySimple* registry) { | 295 void ExternalProtocolHandler::RegisterPrefs(PrefRegistrySimple* registry) { |
301 registry->RegisterDictionaryPref(prefs::kExcludedSchemes); | 296 registry->RegisterDictionaryPref(prefs::kExcludedSchemes); |
302 } | 297 } |
OLD | NEW |