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 <set> | 7 #include <set> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 if (!delegate) | 53 if (!delegate) |
54 return ExternalProtocolHandler::GetBlockState(scheme); | 54 return ExternalProtocolHandler::GetBlockState(scheme); |
55 | 55 |
56 return delegate->GetBlockState(scheme); | 56 return delegate->GetBlockState(scheme); |
57 } | 57 } |
58 | 58 |
59 void RunExternalProtocolDialogWithDelegate( | 59 void RunExternalProtocolDialogWithDelegate( |
60 const GURL& url, | 60 const GURL& url, |
61 int render_process_host_id, | 61 int render_process_host_id, |
62 int routing_id, | 62 int routing_id, |
| 63 ui::PageTransition page_transition, |
| 64 bool has_user_gesture, |
63 ExternalProtocolHandler::Delegate* delegate) { | 65 ExternalProtocolHandler::Delegate* delegate) { |
64 if (!delegate) { | 66 if (!delegate) { |
65 ExternalProtocolHandler::RunExternalProtocolDialog(url, | 67 ExternalProtocolHandler::RunExternalProtocolDialog( |
66 render_process_host_id, | 68 url, render_process_host_id, routing_id, page_transition, |
67 routing_id); | 69 has_user_gesture); |
68 } else { | 70 } else { |
69 delegate->RunExternalProtocolDialog(url, render_process_host_id, | 71 delegate->RunExternalProtocolDialog( |
70 routing_id); | 72 url, render_process_host_id, routing_id, page_transition, |
| 73 has_user_gesture); |
71 } | 74 } |
72 } | 75 } |
73 | 76 |
74 void LaunchUrlWithoutSecurityCheckWithDelegate( | 77 void LaunchUrlWithoutSecurityCheckWithDelegate( |
75 const GURL& url, | 78 const GURL& url, |
76 int render_process_host_id, | 79 int render_process_host_id, |
77 int tab_contents_id, | 80 int tab_contents_id, |
78 ExternalProtocolHandler::Delegate* delegate) { | 81 ExternalProtocolHandler::Delegate* delegate) { |
79 if (!delegate) { | 82 if (!delegate) { |
80 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck( | 83 ExternalProtocolHandler::LaunchUrlWithoutSecurityCheck( |
81 url, render_process_host_id, tab_contents_id); | 84 url, render_process_host_id, tab_contents_id); |
82 } else { | 85 } else { |
83 delegate->LaunchUrlWithoutSecurityCheck(url); | 86 delegate->LaunchUrlWithoutSecurityCheck(url); |
84 } | 87 } |
85 } | 88 } |
86 | 89 |
87 // When we are about to launch a URL with the default OS level application, | 90 // When we are about to launch a URL with the default OS level application, |
88 // we check if that external application will be us. If it is we just ignore | 91 // we check if that external application will be us. If it is we just ignore |
89 // the request. | 92 // the request. |
90 class ExternalDefaultProtocolObserver | 93 class ExternalDefaultProtocolObserver |
91 : public ShellIntegration::DefaultWebClientObserver { | 94 : public ShellIntegration::DefaultWebClientObserver { |
92 public: | 95 public: |
93 ExternalDefaultProtocolObserver(const GURL& escaped_url, | 96 ExternalDefaultProtocolObserver(const GURL& escaped_url, |
94 int render_process_host_id, | 97 int render_process_host_id, |
95 int tab_contents_id, | 98 int tab_contents_id, |
96 bool prompt_user, | 99 bool prompt_user, |
| 100 ui::PageTransition page_transition, |
| 101 bool has_user_gesture, |
97 ExternalProtocolHandler::Delegate* delegate) | 102 ExternalProtocolHandler::Delegate* delegate) |
98 : delegate_(delegate), | 103 : delegate_(delegate), |
99 escaped_url_(escaped_url), | 104 escaped_url_(escaped_url), |
100 render_process_host_id_(render_process_host_id), | 105 render_process_host_id_(render_process_host_id), |
101 tab_contents_id_(tab_contents_id), | 106 tab_contents_id_(tab_contents_id), |
102 prompt_user_(prompt_user) {} | 107 prompt_user_(prompt_user), |
| 108 page_transition_(page_transition), |
| 109 has_user_gesture_(has_user_gesture) {} |
103 | 110 |
104 void SetDefaultWebClientUIState( | 111 void SetDefaultWebClientUIState( |
105 ShellIntegration::DefaultWebClientUIState state) override { | 112 ShellIntegration::DefaultWebClientUIState state) override { |
106 DCHECK(base::MessageLoopForUI::IsCurrent()); | 113 DCHECK(base::MessageLoopForUI::IsCurrent()); |
107 | 114 |
108 // If we are still working out if we're the default, or we've found | 115 // If we are still working out if we're the default, or we've found |
109 // out we definately are the default, we end here. | 116 // out we definately are the default, we end here. |
110 if (state == ShellIntegration::STATE_PROCESSING) { | 117 if (state == ShellIntegration::STATE_PROCESSING) { |
111 return; | 118 return; |
112 } | 119 } |
113 | 120 |
114 if (delegate_) | 121 if (delegate_) |
115 delegate_->FinishedProcessingCheck(); | 122 delegate_->FinishedProcessingCheck(); |
116 | 123 |
117 if (state == ShellIntegration::STATE_IS_DEFAULT) { | 124 if (state == ShellIntegration::STATE_IS_DEFAULT) { |
118 if (delegate_) | 125 if (delegate_) |
119 delegate_->BlockRequest(); | 126 delegate_->BlockRequest(); |
120 return; | 127 return; |
121 } | 128 } |
122 | 129 |
123 // If we get here, either we are not the default or we cannot work out | 130 // If we get here, either we are not the default or we cannot work out |
124 // what the default is, so we proceed. | 131 // what the default is, so we proceed. |
125 if (prompt_user_) { | 132 if (prompt_user_) { |
126 // Ask the user if they want to allow the protocol. This will call | 133 // Ask the user if they want to allow the protocol. This will call |
127 // LaunchUrlWithoutSecurityCheck if the user decides to accept the | 134 // LaunchUrlWithoutSecurityCheck if the user decides to accept the |
128 // protocol. | 135 // protocol. |
129 RunExternalProtocolDialogWithDelegate(escaped_url_, | 136 RunExternalProtocolDialogWithDelegate( |
130 render_process_host_id_, tab_contents_id_, delegate_); | 137 escaped_url_, render_process_host_id_, tab_contents_id_, |
| 138 page_transition_, has_user_gesture_, delegate_); |
131 return; | 139 return; |
132 } | 140 } |
133 | 141 |
134 LaunchUrlWithoutSecurityCheckWithDelegate( | 142 LaunchUrlWithoutSecurityCheckWithDelegate( |
135 escaped_url_, render_process_host_id_, tab_contents_id_, delegate_); | 143 escaped_url_, render_process_host_id_, tab_contents_id_, delegate_); |
136 } | 144 } |
137 | 145 |
138 bool IsOwnedByWorker() override { return true; } | 146 bool IsOwnedByWorker() override { return true; } |
139 | 147 |
140 private: | 148 private: |
141 ExternalProtocolHandler::Delegate* delegate_; | 149 ExternalProtocolHandler::Delegate* delegate_; |
142 GURL escaped_url_; | 150 const GURL escaped_url_; |
143 int render_process_host_id_; | 151 const int render_process_host_id_; |
144 int tab_contents_id_; | 152 const int tab_contents_id_; |
145 bool prompt_user_; | 153 const bool prompt_user_; |
| 154 const ui::PageTransition page_transition_; |
| 155 const bool has_user_gesture_; |
146 }; | 156 }; |
147 | 157 |
148 } // namespace | 158 } // namespace |
149 | 159 |
150 // static | 160 // static |
151 void ExternalProtocolHandler::PrepopulateDictionary( | 161 void ExternalProtocolHandler::PrepopulateDictionary( |
152 base::DictionaryValue* win_pref) { | 162 base::DictionaryValue* win_pref) { |
153 static bool is_warm = false; | 163 static bool is_warm = false; |
154 if (is_warm) | 164 if (is_warm) |
155 return; | 165 return; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 | 255 |
246 if (state == UNKNOWN) { | 256 if (state == UNKNOWN) { |
247 update_excluded_schemas->Remove(scheme, NULL); | 257 update_excluded_schemas->Remove(scheme, NULL); |
248 } else { | 258 } else { |
249 update_excluded_schemas->SetBoolean(scheme, (state == BLOCK)); | 259 update_excluded_schemas->SetBoolean(scheme, (state == BLOCK)); |
250 } | 260 } |
251 } | 261 } |
252 } | 262 } |
253 | 263 |
254 // static | 264 // static |
255 void ExternalProtocolHandler::LaunchUrlWithDelegate(const GURL& url, | 265 void ExternalProtocolHandler::LaunchUrlWithDelegate( |
256 int render_process_host_id, | 266 const GURL& url, |
257 int tab_contents_id, | 267 int render_process_host_id, |
258 Delegate* delegate) { | 268 int tab_contents_id, |
| 269 ui::PageTransition page_transition, |
| 270 bool has_user_gesture, |
| 271 Delegate* delegate) { |
259 DCHECK(base::MessageLoopForUI::IsCurrent()); | 272 DCHECK(base::MessageLoopForUI::IsCurrent()); |
260 | 273 |
261 // Escape the input scheme to be sure that the command does not | 274 // Escape the input scheme to be sure that the command does not |
262 // have parameters unexpected by the external program. | 275 // have parameters unexpected by the external program. |
263 std::string escaped_url_string = net::EscapeExternalHandlerValue(url.spec()); | 276 std::string escaped_url_string = net::EscapeExternalHandlerValue(url.spec()); |
264 GURL escaped_url(escaped_url_string); | 277 GURL escaped_url(escaped_url_string); |
265 BlockState block_state = | 278 BlockState block_state = |
266 GetBlockStateWithDelegate(escaped_url.scheme(), delegate); | 279 GetBlockStateWithDelegate(escaped_url.scheme(), delegate); |
267 if (block_state == BLOCK) { | 280 if (block_state == BLOCK) { |
268 if (delegate) | 281 if (delegate) |
269 delegate->BlockRequest(); | 282 delegate->BlockRequest(); |
270 return; | 283 return; |
271 } | 284 } |
272 | 285 |
273 g_accept_requests = false; | 286 g_accept_requests = false; |
274 | 287 |
275 // The worker creates tasks with references to itself and puts them into | 288 // The worker creates tasks with references to itself and puts them into |
276 // message loops. When no tasks are left it will delete the observer and | 289 // message loops. When no tasks are left it will delete the observer and |
277 // eventually be deleted itself. | 290 // eventually be deleted itself. |
278 ShellIntegration::DefaultWebClientObserver* observer = | 291 ShellIntegration::DefaultWebClientObserver* observer = |
279 new ExternalDefaultProtocolObserver(url, | 292 new ExternalDefaultProtocolObserver(url, |
280 render_process_host_id, | 293 render_process_host_id, |
281 tab_contents_id, | 294 tab_contents_id, |
282 block_state == UNKNOWN, | 295 block_state == UNKNOWN, |
| 296 page_transition, |
| 297 has_user_gesture, |
283 delegate); | 298 delegate); |
284 scoped_refptr<ShellIntegration::DefaultProtocolClientWorker> worker = | 299 scoped_refptr<ShellIntegration::DefaultProtocolClientWorker> worker = |
285 CreateShellWorker(observer, escaped_url.scheme(), delegate); | 300 CreateShellWorker(observer, escaped_url.scheme(), delegate); |
286 | 301 |
287 // Start the check process running. This will send tasks to the FILE thread | 302 // Start the check process running. This will send tasks to the FILE thread |
288 // and when the answer is known will send the result back to the observer on | 303 // and when the answer is known will send the result back to the observer on |
289 // the UI thread. | 304 // the UI thread. |
290 worker->StartCheckIsDefault(); | 305 worker->StartCheckIsDefault(); |
291 } | 306 } |
292 | 307 |
(...skipping 14 matching lines...) Expand all Loading... |
307 // static | 322 // static |
308 void ExternalProtocolHandler::RegisterPrefs(PrefRegistrySimple* registry) { | 323 void ExternalProtocolHandler::RegisterPrefs(PrefRegistrySimple* registry) { |
309 registry->RegisterDictionaryPref(prefs::kExcludedSchemes); | 324 registry->RegisterDictionaryPref(prefs::kExcludedSchemes); |
310 } | 325 } |
311 | 326 |
312 // static | 327 // static |
313 void ExternalProtocolHandler::PermitLaunchUrl() { | 328 void ExternalProtocolHandler::PermitLaunchUrl() { |
314 DCHECK(base::MessageLoopForUI::IsCurrent()); | 329 DCHECK(base::MessageLoopForUI::IsCurrent()); |
315 g_accept_requests = true; | 330 g_accept_requests = true; |
316 } | 331 } |
OLD | NEW |