Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(527)

Side by Side Diff: chrome/browser/custom_handlers/protocol_handler_registry.cc

Issue 10139002: Preventing our default handlers for ChromeOS to show up or confuse the user (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Addressed third review Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
25 #include "grit/generated_resources.h"
24 #include "net/base/network_delegate.h" 26 #include "net/base/network_delegate.h"
25 #include "net/url_request/url_request_redirect_job.h" 27 #include "net/url_request/url_request_redirect_job.h"
28 #include "ui/base/l10n/l10n_util.h"
26 29
27 using content::BrowserThread; 30 using content::BrowserThread;
28 using content::ChildProcessSecurityPolicy; 31 using content::ChildProcessSecurityPolicy;
29 32
30 // ProtocolHandlerRegistry ----------------------------------------------------- 33 // ProtocolHandlerRegistry -----------------------------------------------------
31 34
32 ProtocolHandlerRegistry::ProtocolHandlerRegistry(Profile* profile, 35 ProtocolHandlerRegistry::ProtocolHandlerRegistry(Profile* profile,
33 Delegate* delegate) 36 Delegate* delegate)
34 : profile_(profile), 37 : profile_(profile),
35 delegate_(delegate), 38 delegate_(delegate),
36 enabled_(true), 39 enabled_(true),
37 enabled_io_(enabled_), 40 enabled_io_(enabled_),
38 is_loading_(false) { 41 is_loading_(false) {
39 } 42 }
40 43
44 void ProtocolHandlerRegistry::InstallFixedHandlers() {
45 #if defined(OS_CHROMEOS)
46 if (NULL == GetHandlerList(std::string("mailto"))) {
47 ProtocolHandler mailto_handler = ProtocolHandler::CreateProtocolHandler(
48 "mailto",
49 GURL(l10n_util::GetStringUTF8(IDS_GOOGLE_MAILTO_HANDLER_URL)),
50 l10n_util::GetStringUTF16(IDS_GOOGLE_MAILTO_HANDLER_NAME));
51 RegisterProtocolHandler(mailto_handler);
52 SetDefault(mailto_handler);
53 }
54 if (NULL == GetHandlerList(std::string("webcal"))) {
55 ProtocolHandler webcal_handler = ProtocolHandler::CreateProtocolHandler(
56 "webcal",
57 GURL(l10n_util::GetStringUTF8(IDS_GOOGLE_WEBCAL_HANDLER_URL)),
58 l10n_util::GetStringUTF16(IDS_GOOGLE_WEBCAL_HANDLER_NAME));
59 RegisterProtocolHandler(webcal_handler);
60 SetDefault(webcal_handler);
61 }
62 #endif
63 }
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);
49 // We free these now in case there are any outstanding workers running. If 73 // We free these now in case there are any outstanding workers running. If
50 // we didn't free them they could respond to workers and try to update the 74 // we didn't free them they could respond to workers and try to update the
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
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. Since we assume that this gets only called
223 // once, we can call this every time.
224 InstallFixedHandlers();
225
198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
199 is_loading_ = true; 227 is_loading_ = true;
200 PrefService* prefs = profile_->GetPrefs(); 228 PrefService* prefs = profile_->GetPrefs();
201 if (prefs->HasPrefPath(prefs::kCustomHandlersEnabled)) { 229 if (prefs->HasPrefPath(prefs::kCustomHandlersEnabled)) {
202 enabled_ = prefs->GetBoolean(prefs::kCustomHandlersEnabled); 230 enabled_ = prefs->GetBoolean(prefs::kCustomHandlersEnabled);
203 BrowserThread::PostTask( 231 BrowserThread::PostTask(
204 BrowserThread::IO, 232 BrowserThread::IO,
205 FROM_HERE, 233 FROM_HERE,
206 base::Bind(enabled_ ? &ProtocolHandlerRegistry::EnableIO : 234 base::Bind(enabled_ ? &ProtocolHandlerRegistry::EnableIO :
207 &ProtocolHandlerRegistry::DisableIO, this)); 235 &ProtocolHandlerRegistry::DisableIO, this));
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 } 732 }
705 } else { 733 } else {
706 NOTREACHED(); 734 NOTREACHED();
707 } 735 }
708 } 736 }
709 737
710 void ProtocolHandlerRegistry::DefaultClientObserver::SetWorker( 738 void ProtocolHandlerRegistry::DefaultClientObserver::SetWorker(
711 ShellIntegration::DefaultProtocolClientWorker* worker) { 739 ShellIntegration::DefaultProtocolClientWorker* worker) {
712 worker_ = worker; 740 worker_ = worker;
713 } 741 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698