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

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: Addressing fifth review Created 8 years, 7 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"
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 is_loaded_(false) {
39 } 41 }
40 42
41 ProtocolHandlerRegistry::~ProtocolHandlerRegistry() { 43 ProtocolHandlerRegistry::~ProtocolHandlerRegistry() {
42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
43 DCHECK(default_client_observers_.empty()); 45 DCHECK(default_client_observers_.empty());
44 } 46 }
45 47
46 void ProtocolHandlerRegistry::Finalize() { 48 void ProtocolHandlerRegistry::Finalize() {
47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
48 delegate_.reset(NULL); 50 delegate_.reset(NULL);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 // difference (http://crbug.com/88255). 190 // difference (http://crbug.com/88255).
189 return false; 191 return false;
190 #else 192 #else
191 return ShellIntegration::CanSetAsDefaultProtocolClient(); 193 return ShellIntegration::CanSetAsDefaultProtocolClient();
192 #endif 194 #endif
193 } 195 }
194 196
195 } // namespace 197 } // namespace
196 198
197 void ProtocolHandlerRegistry::Load() { 199 void ProtocolHandlerRegistry::Load() {
200 // Any further default additions to the table will get rejected from now on.
201 is_loaded_ = true;
198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 202 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
199 is_loading_ = true; 203 is_loading_ = true;
200 PrefService* prefs = profile_->GetPrefs(); 204 PrefService* prefs = profile_->GetPrefs();
201 if (prefs->HasPrefPath(prefs::kCustomHandlersEnabled)) { 205 if (prefs->HasPrefPath(prefs::kCustomHandlersEnabled)) {
202 enabled_ = prefs->GetBoolean(prefs::kCustomHandlersEnabled); 206 enabled_ = prefs->GetBoolean(prefs::kCustomHandlersEnabled);
203 BrowserThread::PostTask( 207 BrowserThread::PostTask(
204 BrowserThread::IO, 208 BrowserThread::IO,
205 FROM_HERE, 209 FROM_HERE,
206 base::Bind(enabled_ ? &ProtocolHandlerRegistry::EnableIO : 210 base::Bind(enabled_ ? &ProtocolHandlerRegistry::EnableIO :
207 &ProtocolHandlerRegistry::DisableIO, this)); 211 &ProtocolHandlerRegistry::DisableIO, this));
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 } 588 }
585 589
586 void ProtocolHandlerRegistry::NotifyChanged() { 590 void ProtocolHandlerRegistry::NotifyChanged() {
587 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 591 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
588 content::NotificationService::current()->Notify( 592 content::NotificationService::current()->Notify(
589 chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED, 593 chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED,
590 content::Source<Profile>(profile_), 594 content::Source<Profile>(profile_),
591 content::NotificationService::NoDetails()); 595 content::NotificationService::NoDetails());
592 } 596 }
593 597
598 void ProtocolHandlerRegistry::AddFixedHandler(const ProtocolHandler& handler) {
DaveMoore 2012/04/26 14:45:50 The name "Fixed" handler seems wrong. Isn't it a D
Mr4D (OOO till 08-26) 2012/04/26 16:34:37 Done. In deed. The meaning of this has changed due
koz (OOO until 15th September) 2012/04/30 02:11:26 No, fixed handler is right. "Default handler" is a
599 // If called after the load command was issued this function will fail.
600 DCHECK(!is_loaded_);
601 RegisterProtocolHandler(handler);
602 SetDefault(handler);
603 }
604
594 // IO thread methods ----------------------------------------------------------- 605 // IO thread methods -----------------------------------------------------------
595 606
596 void ProtocolHandlerRegistry::ClearDefaultIO(const std::string& scheme) { 607 void ProtocolHandlerRegistry::ClearDefaultIO(const std::string& scheme) {
597 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 608 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
598 default_handlers_io_.erase(scheme); 609 default_handlers_io_.erase(scheme);
599 } 610 }
600 611
601 void ProtocolHandlerRegistry::SetDefaultIO(const ProtocolHandler& handler) { 612 void ProtocolHandlerRegistry::SetDefaultIO(const ProtocolHandler& handler) {
602 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 613 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
603 ClearDefaultIO(handler.protocol()); 614 ClearDefaultIO(handler.protocol());
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 } 715 }
705 } else { 716 } else {
706 NOTREACHED(); 717 NOTREACHED();
707 } 718 }
708 } 719 }
709 720
710 void ProtocolHandlerRegistry::DefaultClientObserver::SetWorker( 721 void ProtocolHandlerRegistry::DefaultClientObserver::SetWorker(
711 ShellIntegration::DefaultProtocolClientWorker* worker) { 722 ShellIntegration::DefaultProtocolClientWorker* worker) {
712 worker_ = worker; 723 worker_ = worker;
713 } 724 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698