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

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: Added a few more comments 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"
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 locking_defaults_(false) {
41 }
42
43 void ProtocolHandlerRegistry::InstallSystemDefaultHandlers() {
44 #if defined(OS_CHROMEOS)
45 ProtocolHandler mail_handler = ProtocolHandler::CreateProtocolHandler(
46 std::string("mailto"),
47 GURL("https://mail.google.com/mail/?extsrc=mailto&url=%s"),
48 UTF8ToUTF16(std::string("Google.com Mail")));
49 RegisterProtocolHandler(mail_handler);
50 SetDefault(mail_handler);
51 ProtocolHandler cal_handler = ProtocolHandler::CreateProtocolHandler(
52 std::string("webcal"),
53 GURL("https://www.google.com/calendar/render?cid=%s"),
54 UTF8ToUTF16(std::string("Google Calendar")));
55 RegisterProtocolHandler(cal_handler);
56 SetDefault(cal_handler);
57 #endif
58 locking_defaults_ = true;
59 }
60
61 bool ProtocolHandlerRegistry::IsFixedHandler(
62 const std::string& scheme) const {
63 #if defined (OS_CHROMEOS)
64 return (locking_defaults_ && (scheme == "mailto" || scheme == "webcal"));
65 #else
66 return false;
67 #endif
39 } 68 }
40 69
41 ProtocolHandlerRegistry::~ProtocolHandlerRegistry() { 70 ProtocolHandlerRegistry::~ProtocolHandlerRegistry() {
42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 71 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
43 DCHECK(default_client_observers_.empty()); 72 DCHECK(default_client_observers_.empty());
44 } 73 }
45 74
46 void ProtocolHandlerRegistry::Finalize() { 75 void ProtocolHandlerRegistry::Finalize() {
47 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 76 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
48 delegate_.reset(NULL); 77 delegate_.reset(NULL);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 // difference (http://crbug.com/88255). 217 // difference (http://crbug.com/88255).
189 return false; 218 return false;
190 #else 219 #else
191 return ShellIntegration::CanSetAsDefaultProtocolClient(); 220 return ShellIntegration::CanSetAsDefaultProtocolClient();
192 #endif 221 #endif
193 } 222 }
194 223
195 } // namespace 224 } // namespace
196 225
197 void ProtocolHandlerRegistry::Load() { 226 void ProtocolHandlerRegistry::Load() {
227 // We add our default handlers only the first time we come here.
228 // On the next call the defaults will be locked.
229 if (!locking_defaults_)
230 InstallSystemDefaultHandlers();
231
198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
199 is_loading_ = true; 233 is_loading_ = true;
200 PrefService* prefs = profile_->GetPrefs(); 234 PrefService* prefs = profile_->GetPrefs();
201 if (prefs->HasPrefPath(prefs::kCustomHandlersEnabled)) { 235 if (prefs->HasPrefPath(prefs::kCustomHandlersEnabled)) {
202 enabled_ = prefs->GetBoolean(prefs::kCustomHandlersEnabled); 236 enabled_ = prefs->GetBoolean(prefs::kCustomHandlersEnabled);
203 BrowserThread::PostTask( 237 BrowserThread::PostTask(
204 BrowserThread::IO, 238 BrowserThread::IO,
205 FROM_HERE, 239 FROM_HERE,
206 base::Bind(enabled_ ? &ProtocolHandlerRegistry::EnableIO : 240 base::Bind(enabled_ ? &ProtocolHandlerRegistry::EnableIO :
207 &ProtocolHandlerRegistry::DisableIO, this)); 241 &ProtocolHandlerRegistry::DisableIO, this));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 scoped_ptr<Value> enabled(Value::CreateBooleanValue(enabled_)); 287 scoped_ptr<Value> enabled(Value::CreateBooleanValue(enabled_));
254 profile_->GetPrefs()->Set(prefs::kRegisteredProtocolHandlers, 288 profile_->GetPrefs()->Set(prefs::kRegisteredProtocolHandlers,
255 *registered_protocol_handlers); 289 *registered_protocol_handlers);
256 profile_->GetPrefs()->Set(prefs::kIgnoredProtocolHandlers, 290 profile_->GetPrefs()->Set(prefs::kIgnoredProtocolHandlers,
257 *ignored_protocol_handlers); 291 *ignored_protocol_handlers);
258 profile_->GetPrefs()->Set(prefs::kCustomHandlersEnabled, *enabled); 292 profile_->GetPrefs()->Set(prefs::kCustomHandlersEnabled, *enabled);
259 } 293 }
260 294
261 bool ProtocolHandlerRegistry::CanSchemeBeOverridden( 295 bool ProtocolHandlerRegistry::CanSchemeBeOverridden(
262 const std::string& scheme) const { 296 const std::string& scheme) const {
297 if (IsFixedHandler(scheme))
benwells 2012/04/20 00:25:05 If I understand this change correctly, ChromeOS us
Mr4D (OOO till 08-26) 2012/04/20 13:44:41 There are no 'apps' which can do these things. As
benwells 2012/04/20 21:55:10 registerProtocolHandler is a web standard, and can
Mr4D (OOO till 08-26) 2012/04/21 00:27:28 Okay, fine. I will remove it then. :) (Who am I me
298 return false;
263 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 299 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
264 const ProtocolHandlerList* handlers = GetHandlerList(scheme); 300 const ProtocolHandlerList* handlers = GetHandlerList(scheme);
265 // If we already have a handler for this scheme, we can add more. 301 // If we already have a handler for this scheme, we can add more.
266 if (handlers != NULL && !handlers->empty()) 302 if (handlers != NULL && !handlers->empty())
267 return true; 303 return true;
268 // Don't override a scheme if it already has an external handler. 304 // Don't override a scheme if it already has an external handler.
269 return !delegate_->IsExternalHandlerRegistered(scheme); 305 return !delegate_->IsExternalHandlerRegistered(scheme);
270 } 306 }
271 307
272 void ProtocolHandlerRegistry::GetRegisteredProtocols( 308 void ProtocolHandlerRegistry::GetRegisteredProtocols(
273 std::vector<std::string>* output) const { 309 std::vector<std::string>* output) const {
274 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 310 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
275 ProtocolHandlerMultiMap::const_iterator p; 311 ProtocolHandlerMultiMap::const_iterator p;
276 for (p = protocol_handlers_.begin(); p != protocol_handlers_.end(); ++p) { 312 for (p = protocol_handlers_.begin(); p != protocol_handlers_.end(); ++p) {
277 if (!p->second.empty()) 313 // We don't want the settings dialog to show 'internal defaults'.
314 if (!p->second.empty() && !IsFixedHandler(p->first))
278 output->push_back(p->first); 315 output->push_back(p->first);
279 } 316 }
280 } 317 }
281 318
282 void ProtocolHandlerRegistry::RemoveIgnoredHandler( 319 void ProtocolHandlerRegistry::RemoveIgnoredHandler(
283 const ProtocolHandler& handler) { 320 const ProtocolHandler& handler) {
284 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 321 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
285 bool should_notify = false; 322 bool should_notify = false;
286 ProtocolHandlerList::iterator p = std::find( 323 ProtocolHandlerList::iterator p = std::find(
287 ignored_protocol_handlers_.begin(), ignored_protocol_handlers_.end(), 324 ignored_protocol_handlers_.begin(), ignored_protocol_handlers_.end(),
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 } 741 }
705 } else { 742 } else {
706 NOTREACHED(); 743 NOTREACHED();
707 } 744 }
708 } 745 }
709 746
710 void ProtocolHandlerRegistry::DefaultClientObserver::SetWorker( 747 void ProtocolHandlerRegistry::DefaultClientObserver::SetWorker(
711 ShellIntegration::DefaultProtocolClientWorker* worker) { 748 ShellIntegration::DefaultProtocolClientWorker* worker) {
712 worker_ = worker; 749 worker_ = worker;
713 } 750 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698