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 | 8 |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 20 matching lines...) Expand all Loading... |
31 using content::BrowserThread; | 31 using content::BrowserThread; |
32 | 32 |
33 // Whether we accept requests for launching external protocols. This is set to | 33 // Whether we accept requests for launching external protocols. This is set to |
34 // false every time an external protocol is requested, and set back to true on | 34 // false every time an external protocol is requested, and set back to true on |
35 // each user gesture. This variable should only be accessed from the UI thread. | 35 // each user gesture. This variable should only be accessed from the UI thread. |
36 static bool g_accept_requests = true; | 36 static bool g_accept_requests = true; |
37 | 37 |
38 namespace { | 38 namespace { |
39 | 39 |
40 // Functions enabling unit testing. Using a NULL delegate will use the default | 40 // Functions enabling unit testing. Using a NULL delegate will use the default |
41 // behavior; if a delegate is provided it will be used instead. | 41 // behavior; if a delegate is provided it will be used instead. Also, Ownership |
| 42 // of |observer| is passed to the new worker. |
42 shell_integration::DefaultProtocolClientWorker* CreateShellWorker( | 43 shell_integration::DefaultProtocolClientWorker* CreateShellWorker( |
43 shell_integration::DefaultWebClientObserver* observer, | 44 shell_integration::DefaultWebClientObserver* observer, |
44 const std::string& protocol, | 45 const std::string& protocol, |
45 ExternalProtocolHandler::Delegate* delegate) { | 46 ExternalProtocolHandler::Delegate* delegate) { |
46 if (!delegate) | 47 if (!delegate) |
47 return new shell_integration::DefaultProtocolClientWorker(observer, | 48 return new shell_integration::DefaultProtocolClientWorker( |
48 protocol); | 49 observer, protocol, |
| 50 /*delete_observer=*/true); |
49 | 51 |
50 return delegate->CreateShellWorker(observer, protocol); | 52 return delegate->CreateShellWorker(observer, protocol); |
51 } | 53 } |
52 | 54 |
53 ExternalProtocolHandler::BlockState GetBlockStateWithDelegate( | 55 ExternalProtocolHandler::BlockState GetBlockStateWithDelegate( |
54 const std::string& scheme, | 56 const std::string& scheme, |
55 ExternalProtocolHandler::Delegate* delegate) { | 57 ExternalProtocolHandler::Delegate* delegate) { |
56 if (!delegate) | 58 if (!delegate) |
57 return ExternalProtocolHandler::GetBlockState(scheme); | 59 return ExternalProtocolHandler::GetBlockState(scheme); |
58 | 60 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 RunExternalProtocolDialogWithDelegate( | 141 RunExternalProtocolDialogWithDelegate( |
140 escaped_url_, render_process_host_id_, tab_contents_id_, | 142 escaped_url_, render_process_host_id_, tab_contents_id_, |
141 page_transition_, has_user_gesture_, delegate_); | 143 page_transition_, has_user_gesture_, delegate_); |
142 return; | 144 return; |
143 } | 145 } |
144 | 146 |
145 LaunchUrlWithoutSecurityCheckWithDelegate( | 147 LaunchUrlWithoutSecurityCheckWithDelegate( |
146 escaped_url_, render_process_host_id_, tab_contents_id_, delegate_); | 148 escaped_url_, render_process_host_id_, tab_contents_id_, delegate_); |
147 } | 149 } |
148 | 150 |
149 bool IsOwnedByWorker() override { return true; } | |
150 | |
151 private: | 151 private: |
152 ExternalProtocolHandler::Delegate* delegate_; | 152 ExternalProtocolHandler::Delegate* delegate_; |
153 const GURL escaped_url_; | 153 const GURL escaped_url_; |
154 const int render_process_host_id_; | 154 const int render_process_host_id_; |
155 const int tab_contents_id_; | 155 const int tab_contents_id_; |
156 const bool prompt_user_; | 156 const bool prompt_user_; |
157 const ui::PageTransition page_transition_; | 157 const ui::PageTransition page_transition_; |
158 const bool has_user_gesture_; | 158 const bool has_user_gesture_; |
159 }; | 159 }; |
160 | 160 |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 // static | 321 // static |
322 void ExternalProtocolHandler::RegisterPrefs(PrefRegistrySimple* registry) { | 322 void ExternalProtocolHandler::RegisterPrefs(PrefRegistrySimple* registry) { |
323 registry->RegisterDictionaryPref(prefs::kExcludedSchemes); | 323 registry->RegisterDictionaryPref(prefs::kExcludedSchemes); |
324 } | 324 } |
325 | 325 |
326 // static | 326 // static |
327 void ExternalProtocolHandler::PermitLaunchUrl() { | 327 void ExternalProtocolHandler::PermitLaunchUrl() { |
328 DCHECK(base::MessageLoopForUI::IsCurrent()); | 328 DCHECK(base::MessageLoopForUI::IsCurrent()); |
329 g_accept_requests = true; | 329 g_accept_requests = true; |
330 } | 330 } |
OLD | NEW |