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