Chromium Code Reviews| 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/custom_handlers/protocol_handler_registry.h" | 5 #include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/utf_string_conversions.h" | |
| 13 #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_deleg ate.h" | 14 #include "chrome/browser/custom_handlers/register_protocol_handler_infobar_deleg ate.h" |
| 14 #include "chrome/browser/net/chrome_url_request_context.h" | 15 #include "chrome/browser/net/chrome_url_request_context.h" |
| 15 #include "chrome/browser/prefs/pref_service.h" | 16 #include "chrome/browser/prefs/pref_service.h" |
| 16 #include "chrome/browser/profiles/profile_io_data.h" | 17 #include "chrome/browser/profiles/profile_io_data.h" |
| 17 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
| 18 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/common/custom_handlers/protocol_handler.h" | 20 #include "chrome/common/custom_handlers/protocol_handler.h" |
| 20 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 21 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
| 22 #include "content/public/browser/child_process_security_policy.h" | 23 #include "content/public/browser/child_process_security_policy.h" |
| 23 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
| 24 #include "net/base/network_delegate.h" | 25 #include "net/base/network_delegate.h" |
| 25 #include "net/url_request/url_request_redirect_job.h" | 26 #include "net/url_request/url_request_redirect_job.h" |
| 26 | 27 |
| 27 using content::BrowserThread; | 28 using content::BrowserThread; |
| 28 using content::ChildProcessSecurityPolicy; | 29 using content::ChildProcessSecurityPolicy; |
| 29 | 30 |
| 30 // ProtocolHandlerRegistry ----------------------------------------------------- | 31 // ProtocolHandlerRegistry ----------------------------------------------------- |
| 31 | 32 |
| 32 ProtocolHandlerRegistry::ProtocolHandlerRegistry(Profile* profile, | 33 ProtocolHandlerRegistry::ProtocolHandlerRegistry(Profile* profile, |
| 33 Delegate* delegate) | 34 Delegate* delegate) |
| 34 : profile_(profile), | 35 : profile_(profile), |
| 35 delegate_(delegate), | 36 delegate_(delegate), |
| 36 enabled_(true), | 37 enabled_(true), |
| 37 enabled_io_(enabled_), | 38 enabled_io_(enabled_), |
| 38 is_loading_(false) { | 39 is_loading_(false), |
| 40 fixed_handlers_loaded_(false) { | |
| 41 } | |
| 42 | |
| 43 void ProtocolHandlerRegistry::InstallFixedHandlers() { | |
| 44 #if defined(OS_CHROMEOS) | |
| 45 if (NULL == GetHandlerList(std::string("mailto"))) { | |
| 46 ProtocolHandler mail_handler = ProtocolHandler::CreateProtocolHandler( | |
|
koz (OOO until 15th September)
2012/04/23 03:43:06
nit: mail_handler -> mailto_handler
Mr4D (OOO till 08-26)
2012/04/23 18:03:53
Done.
| |
| 47 std::string("mailto"), | |
|
koz (OOO until 15th September)
2012/04/23 03:55:35
Replace this with just "mailto"
Mr4D (OOO till 08-26)
2012/04/23 18:03:53
Not sure why this was done, but every other call o
| |
| 48 GURL("https://mail.google.com/mail/?extsrc=mailto&url=%s"), | |
| 49 UTF8ToUTF16(std::string("Google.com Mail"))); | |
|
koz (OOO until 15th September)
2012/04/23 03:55:35
Could you move the user-facing strings (ie: the ti
Mr4D (OOO till 08-26)
2012/04/23 18:06:21
Done.
| |
| 50 RegisterProtocolHandler(mail_handler); | |
| 51 SetDefault(mail_handler); | |
| 52 } | |
| 53 if (NULL == GetHandlerList(std::string("webcal"))) { | |
| 54 ProtocolHandler cal_handler = ProtocolHandler::CreateProtocolHandler( | |
|
koz (OOO until 15th September)
2012/04/23 03:43:06
nit: cal_handler -> webcal_handler
Mr4D (OOO till 08-26)
2012/04/23 18:03:53
Done.
| |
| 55 std::string("webcal"), | |
|
koz (OOO until 15th September)
2012/04/23 03:55:35
Replace this with just "webcal"
Mr4D (OOO till 08-26)
2012/04/23 18:03:53
Ditto
| |
| 56 GURL("https://www.google.com/calendar/render?cid=%s"), | |
| 57 UTF8ToUTF16(std::string("Google Calendar"))); | |
| 58 RegisterProtocolHandler(cal_handler); | |
| 59 SetDefault(cal_handler); | |
| 60 } | |
| 61 #endif | |
| 62 fixed_handlers_loaded_ = true; | |
| 39 } | 63 } |
| 40 | 64 |
| 41 ProtocolHandlerRegistry::~ProtocolHandlerRegistry() { | 65 ProtocolHandlerRegistry::~ProtocolHandlerRegistry() { |
| 42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 43 DCHECK(default_client_observers_.empty()); | 67 DCHECK(default_client_observers_.empty()); |
| 44 } | 68 } |
| 45 | 69 |
| 46 void ProtocolHandlerRegistry::Finalize() { | 70 void ProtocolHandlerRegistry::Finalize() { |
| 47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 48 delegate_.reset(NULL); | 72 delegate_.reset(NULL); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 // difference (http://crbug.com/88255). | 212 // difference (http://crbug.com/88255). |
| 189 return false; | 213 return false; |
| 190 #else | 214 #else |
| 191 return ShellIntegration::CanSetAsDefaultProtocolClient(); | 215 return ShellIntegration::CanSetAsDefaultProtocolClient(); |
| 192 #endif | 216 #endif |
| 193 } | 217 } |
| 194 | 218 |
| 195 } // namespace | 219 } // namespace |
| 196 | 220 |
| 197 void ProtocolHandlerRegistry::Load() { | 221 void ProtocolHandlerRegistry::Load() { |
| 222 // We add our default handlers only the first time we come here. | |
| 223 // On the next call the defaults will be locked. | |
|
koz (OOO until 15th September)
2012/04/23 03:43:06
What does "locked" mean? Could you replace "will b
Mr4D (OOO till 08-26)
2012/04/23 18:03:53
The "locked" comment was a remainder of some code
| |
| 224 if (!fixed_handlers_loaded_) | |
| 225 InstallFixedHandlers(); | |
| 226 | |
| 198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 227 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 199 is_loading_ = true; | 228 is_loading_ = true; |
| 200 PrefService* prefs = profile_->GetPrefs(); | 229 PrefService* prefs = profile_->GetPrefs(); |
| 201 if (prefs->HasPrefPath(prefs::kCustomHandlersEnabled)) { | 230 if (prefs->HasPrefPath(prefs::kCustomHandlersEnabled)) { |
| 202 enabled_ = prefs->GetBoolean(prefs::kCustomHandlersEnabled); | 231 enabled_ = prefs->GetBoolean(prefs::kCustomHandlersEnabled); |
| 203 BrowserThread::PostTask( | 232 BrowserThread::PostTask( |
| 204 BrowserThread::IO, | 233 BrowserThread::IO, |
| 205 FROM_HERE, | 234 FROM_HERE, |
| 206 base::Bind(enabled_ ? &ProtocolHandlerRegistry::EnableIO : | 235 base::Bind(enabled_ ? &ProtocolHandlerRegistry::EnableIO : |
| 207 &ProtocolHandlerRegistry::DisableIO, this)); | 236 &ProtocolHandlerRegistry::DisableIO, this)); |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 704 } | 733 } |
| 705 } else { | 734 } else { |
| 706 NOTREACHED(); | 735 NOTREACHED(); |
| 707 } | 736 } |
| 708 } | 737 } |
| 709 | 738 |
| 710 void ProtocolHandlerRegistry::DefaultClientObserver::SetWorker( | 739 void ProtocolHandlerRegistry::DefaultClientObserver::SetWorker( |
| 711 ShellIntegration::DefaultProtocolClientWorker* worker) { | 740 ShellIntegration::DefaultProtocolClientWorker* worker) { |
| 712 worker_ = worker; | 741 worker_ = worker; |
| 713 } | 742 } |
| OLD | NEW |