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

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

Issue 1031083004: favor DCHECK_CURRENTLY_ON for better logs in chrome/browser/custom_handlers/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase on master Created 5 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
« no previous file with comments | « no previous file | chrome/browser/custom_handlers/protocol_handler_registry_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 108
109 DISALLOW_COPY_AND_ASSIGN(IOThreadDelegate); 109 DISALLOW_COPY_AND_ASSIGN(IOThreadDelegate);
110 }; 110 };
111 111
112 ProtocolHandlerRegistry::IOThreadDelegate::IOThreadDelegate(bool) 112 ProtocolHandlerRegistry::IOThreadDelegate::IOThreadDelegate(bool)
113 : enabled_(true) {} 113 : enabled_(true) {}
114 ProtocolHandlerRegistry::IOThreadDelegate::~IOThreadDelegate() {} 114 ProtocolHandlerRegistry::IOThreadDelegate::~IOThreadDelegate() {}
115 115
116 bool ProtocolHandlerRegistry::IOThreadDelegate::IsHandledProtocol( 116 bool ProtocolHandlerRegistry::IOThreadDelegate::IsHandledProtocol(
117 const std::string& scheme) const { 117 const std::string& scheme) const {
118 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 118 DCHECK_CURRENTLY_ON(BrowserThread::IO);
119 return enabled_ && !LookupHandler(default_handlers_, scheme).IsEmpty(); 119 return enabled_ && !LookupHandler(default_handlers_, scheme).IsEmpty();
120 } 120 }
121 121
122 void ProtocolHandlerRegistry::IOThreadDelegate::ClearDefault( 122 void ProtocolHandlerRegistry::IOThreadDelegate::ClearDefault(
123 const std::string& scheme) { 123 const std::string& scheme) {
124 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 124 DCHECK_CURRENTLY_ON(BrowserThread::IO);
125 default_handlers_.erase(scheme); 125 default_handlers_.erase(scheme);
126 } 126 }
127 127
128 void ProtocolHandlerRegistry::IOThreadDelegate::SetDefault( 128 void ProtocolHandlerRegistry::IOThreadDelegate::SetDefault(
129 const ProtocolHandler& handler) { 129 const ProtocolHandler& handler) {
130 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 130 DCHECK_CURRENTLY_ON(BrowserThread::IO);
131 ClearDefault(handler.protocol()); 131 ClearDefault(handler.protocol());
132 default_handlers_.insert(std::make_pair(handler.protocol(), handler)); 132 default_handlers_.insert(std::make_pair(handler.protocol(), handler));
133 } 133 }
134 134
135 // Create a new job for the supplied |URLRequest| if a default handler 135 // Create a new job for the supplied |URLRequest| if a default handler
136 // is registered and the associated handler is able to interpret 136 // is registered and the associated handler is able to interpret
137 // the url from |request|. 137 // the url from |request|.
138 net::URLRequestJob* ProtocolHandlerRegistry::IOThreadDelegate::MaybeCreateJob( 138 net::URLRequestJob* ProtocolHandlerRegistry::IOThreadDelegate::MaybeCreateJob(
139 net::URLRequest* request, net::NetworkDelegate* network_delegate) const { 139 net::URLRequest* request, net::NetworkDelegate* network_delegate) const {
140 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 140 DCHECK_CURRENTLY_ON(BrowserThread::IO);
141 141
142 ProtocolHandler handler = LookupHandler(default_handlers_, 142 ProtocolHandler handler = LookupHandler(default_handlers_,
143 request->url().scheme()); 143 request->url().scheme());
144 if (handler.IsEmpty()) 144 if (handler.IsEmpty())
145 return NULL; 145 return NULL;
146 146
147 GURL translated_url(handler.TranslateUrl(request->url())); 147 GURL translated_url(handler.TranslateUrl(request->url()));
148 if (!translated_url.is_valid()) 148 if (!translated_url.is_valid())
149 return NULL; 149 return NULL;
150 150
(...skipping 23 matching lines...) Expand all
174 scoped_ptr<net::URLRequestJobFactory> job_factory) { 174 scoped_ptr<net::URLRequestJobFactory> job_factory) {
175 job_factory_ = job_factory.Pass(); 175 job_factory_ = job_factory.Pass();
176 } 176 }
177 177
178 net::URLRequestJob* 178 net::URLRequestJob*
179 ProtocolHandlerRegistry::JobInterceptorFactory:: 179 ProtocolHandlerRegistry::JobInterceptorFactory::
180 MaybeCreateJobWithProtocolHandler( 180 MaybeCreateJobWithProtocolHandler(
181 const std::string& scheme, 181 const std::string& scheme,
182 net::URLRequest* request, 182 net::URLRequest* request,
183 net::NetworkDelegate* network_delegate) const { 183 net::NetworkDelegate* network_delegate) const {
184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 184 DCHECK_CURRENTLY_ON(BrowserThread::IO);
185 net::URLRequestJob* job = io_thread_delegate_->MaybeCreateJob( 185 net::URLRequestJob* job = io_thread_delegate_->MaybeCreateJob(
186 request, network_delegate); 186 request, network_delegate);
187 if (job) 187 if (job)
188 return job; 188 return job;
189 return job_factory_->MaybeCreateJobWithProtocolHandler( 189 return job_factory_->MaybeCreateJobWithProtocolHandler(
190 scheme, request, network_delegate); 190 scheme, request, network_delegate);
191 } 191 }
192 192
193 net::URLRequestJob* 193 net::URLRequestJob*
194 ProtocolHandlerRegistry::JobInterceptorFactory::MaybeInterceptRedirect( 194 ProtocolHandlerRegistry::JobInterceptorFactory::MaybeInterceptRedirect(
195 net::URLRequest* request, 195 net::URLRequest* request,
196 net::NetworkDelegate* network_delegate, 196 net::NetworkDelegate* network_delegate,
197 const GURL& location) const { 197 const GURL& location) const {
198 return job_factory_->MaybeInterceptRedirect( 198 return job_factory_->MaybeInterceptRedirect(
199 request, network_delegate, location); 199 request, network_delegate, location);
200 } 200 }
201 201
202 net::URLRequestJob* 202 net::URLRequestJob*
203 ProtocolHandlerRegistry::JobInterceptorFactory::MaybeInterceptResponse( 203 ProtocolHandlerRegistry::JobInterceptorFactory::MaybeInterceptResponse(
204 net::URLRequest* request, 204 net::URLRequest* request,
205 net::NetworkDelegate* network_delegate) const { 205 net::NetworkDelegate* network_delegate) const {
206 return job_factory_->MaybeInterceptResponse(request, network_delegate); 206 return job_factory_->MaybeInterceptResponse(request, network_delegate);
207 } 207 }
208 208
209 bool ProtocolHandlerRegistry::JobInterceptorFactory::IsHandledProtocol( 209 bool ProtocolHandlerRegistry::JobInterceptorFactory::IsHandledProtocol(
210 const std::string& scheme) const { 210 const std::string& scheme) const {
211 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 211 DCHECK_CURRENTLY_ON(BrowserThread::IO);
212 return io_thread_delegate_->IsHandledProtocol(scheme) || 212 return io_thread_delegate_->IsHandledProtocol(scheme) ||
213 job_factory_->IsHandledProtocol(scheme); 213 job_factory_->IsHandledProtocol(scheme);
214 } 214 }
215 215
216 bool ProtocolHandlerRegistry::JobInterceptorFactory::IsHandledURL( 216 bool ProtocolHandlerRegistry::JobInterceptorFactory::IsHandledURL(
217 const GURL& url) const { 217 const GURL& url) const {
218 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 218 DCHECK_CURRENTLY_ON(BrowserThread::IO);
219 return (url.is_valid() && 219 return (url.is_valid() &&
220 io_thread_delegate_->IsHandledProtocol(url.scheme())) || 220 io_thread_delegate_->IsHandledProtocol(url.scheme())) ||
221 job_factory_->IsHandledURL(url); 221 job_factory_->IsHandledURL(url);
222 } 222 }
223 223
224 bool ProtocolHandlerRegistry::JobInterceptorFactory::IsSafeRedirectTarget( 224 bool ProtocolHandlerRegistry::JobInterceptorFactory::IsSafeRedirectTarget(
225 const GURL& location) const { 225 const GURL& location) const {
226 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 226 DCHECK_CURRENTLY_ON(BrowserThread::IO);
227 return job_factory_->IsSafeRedirectTarget(location); 227 return job_factory_->IsSafeRedirectTarget(location);
228 } 228 }
229 229
230 // DefaultClientObserver ------------------------------------------------------ 230 // DefaultClientObserver ------------------------------------------------------
231 231
232 ProtocolHandlerRegistry::DefaultClientObserver::DefaultClientObserver( 232 ProtocolHandlerRegistry::DefaultClientObserver::DefaultClientObserver(
233 ProtocolHandlerRegistry* registry) 233 ProtocolHandlerRegistry* registry)
234 : worker_(NULL), 234 : worker_(NULL),
235 registry_(registry) { 235 registry_(registry) {
236 DCHECK(registry_); 236 DCHECK(registry_);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
343 return true; 343 return true;
344 344
345 if (AttemptReplace(handler)) 345 if (AttemptReplace(handler))
346 return true; 346 return true;
347 347
348 return false; 348 return false;
349 } 349 }
350 350
351 void ProtocolHandlerRegistry::OnAcceptRegisterProtocolHandler( 351 void ProtocolHandlerRegistry::OnAcceptRegisterProtocolHandler(
352 const ProtocolHandler& handler) { 352 const ProtocolHandler& handler) {
353 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 353 DCHECK_CURRENTLY_ON(BrowserThread::UI);
354 RegisterProtocolHandler(handler, USER); 354 RegisterProtocolHandler(handler, USER);
355 SetDefault(handler); 355 SetDefault(handler);
356 Save(); 356 Save();
357 NotifyChanged(); 357 NotifyChanged();
358 } 358 }
359 359
360 void ProtocolHandlerRegistry::OnDenyRegisterProtocolHandler( 360 void ProtocolHandlerRegistry::OnDenyRegisterProtocolHandler(
361 const ProtocolHandler& handler) { 361 const ProtocolHandler& handler) {
362 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 362 DCHECK_CURRENTLY_ON(BrowserThread::UI);
363 RegisterProtocolHandler(handler, USER); 363 RegisterProtocolHandler(handler, USER);
364 Save(); 364 Save();
365 NotifyChanged(); 365 NotifyChanged();
366 } 366 }
367 367
368 void ProtocolHandlerRegistry::OnIgnoreRegisterProtocolHandler( 368 void ProtocolHandlerRegistry::OnIgnoreRegisterProtocolHandler(
369 const ProtocolHandler& handler) { 369 const ProtocolHandler& handler) {
370 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 370 DCHECK_CURRENTLY_ON(BrowserThread::UI);
371 IgnoreProtocolHandler(handler, USER); 371 IgnoreProtocolHandler(handler, USER);
372 Save(); 372 Save();
373 NotifyChanged(); 373 NotifyChanged();
374 } 374 }
375 375
376 bool ProtocolHandlerRegistry::AttemptReplace(const ProtocolHandler& handler) { 376 bool ProtocolHandlerRegistry::AttemptReplace(const ProtocolHandler& handler) {
377 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 377 DCHECK_CURRENTLY_ON(BrowserThread::UI);
378 ProtocolHandler old_default = GetHandlerFor(handler.protocol()); 378 ProtocolHandler old_default = GetHandlerFor(handler.protocol());
379 bool make_new_handler_default = handler.IsSameOrigin(old_default); 379 bool make_new_handler_default = handler.IsSameOrigin(old_default);
380 ProtocolHandlerList to_replace(GetReplacedHandlers(handler)); 380 ProtocolHandlerList to_replace(GetReplacedHandlers(handler));
381 if (to_replace.empty()) 381 if (to_replace.empty())
382 return false; 382 return false;
383 for (ProtocolHandlerList::iterator p = to_replace.begin(); 383 for (ProtocolHandlerList::iterator p = to_replace.begin();
384 p != to_replace.end(); ++p) { 384 p != to_replace.end(); ++p) {
385 RemoveHandler(*p); 385 RemoveHandler(*p);
386 } 386 }
387 if (make_new_handler_default) { 387 if (make_new_handler_default) {
(...skipping 15 matching lines...) Expand all
403 for (ProtocolHandlerList::const_iterator p = handlers->begin(); 403 for (ProtocolHandlerList::const_iterator p = handlers->begin();
404 p != handlers->end(); p++) { 404 p != handlers->end(); p++) {
405 if (handler.IsSameOrigin(*p)) { 405 if (handler.IsSameOrigin(*p)) {
406 replaced_handlers.push_back(*p); 406 replaced_handlers.push_back(*p);
407 } 407 }
408 } 408 }
409 return replaced_handlers; 409 return replaced_handlers;
410 } 410 }
411 411
412 void ProtocolHandlerRegistry::ClearDefault(const std::string& scheme) { 412 void ProtocolHandlerRegistry::ClearDefault(const std::string& scheme) {
413 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 413 DCHECK_CURRENTLY_ON(BrowserThread::UI);
414 414
415 default_handlers_.erase(scheme); 415 default_handlers_.erase(scheme);
416 BrowserThread::PostTask( 416 BrowserThread::PostTask(
417 BrowserThread::IO, 417 BrowserThread::IO,
418 FROM_HERE, 418 FROM_HERE,
419 base::Bind(&IOThreadDelegate::ClearDefault, io_thread_delegate_, scheme)); 419 base::Bind(&IOThreadDelegate::ClearDefault, io_thread_delegate_, scheme));
420 Save(); 420 Save();
421 NotifyChanged(); 421 NotifyChanged();
422 } 422 }
423 423
424 bool ProtocolHandlerRegistry::IsDefault( 424 bool ProtocolHandlerRegistry::IsDefault(
425 const ProtocolHandler& handler) const { 425 const ProtocolHandler& handler) const {
426 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 426 DCHECK_CURRENTLY_ON(BrowserThread::UI);
427 return GetHandlerFor(handler.protocol()) == handler; 427 return GetHandlerFor(handler.protocol()) == handler;
428 } 428 }
429 429
430 void ProtocolHandlerRegistry::InstallDefaultsForChromeOS() { 430 void ProtocolHandlerRegistry::InstallDefaultsForChromeOS() {
431 #if defined(OS_CHROMEOS) 431 #if defined(OS_CHROMEOS)
432 // Only chromeos has default protocol handlers at this point. 432 // Only chromeos has default protocol handlers at this point.
433 AddPredefinedHandler( 433 AddPredefinedHandler(
434 ProtocolHandler::CreateProtocolHandler( 434 ProtocolHandler::CreateProtocolHandler(
435 "mailto", 435 "mailto",
436 GURL(l10n_util::GetStringUTF8(IDS_GOOGLE_MAILTO_HANDLER_URL)))); 436 GURL(l10n_util::GetStringUTF8(IDS_GOOGLE_MAILTO_HANDLER_URL))));
437 AddPredefinedHandler( 437 AddPredefinedHandler(
438 ProtocolHandler::CreateProtocolHandler( 438 ProtocolHandler::CreateProtocolHandler(
439 "webcal", 439 "webcal",
440 GURL(l10n_util::GetStringUTF8(IDS_GOOGLE_WEBCAL_HANDLER_URL)))); 440 GURL(l10n_util::GetStringUTF8(IDS_GOOGLE_WEBCAL_HANDLER_URL))));
441 #else 441 #else
442 NOTREACHED(); // this method should only ever be called in chromeos. 442 NOTREACHED(); // this method should only ever be called in chromeos.
443 #endif 443 #endif
444 } 444 }
445 445
446 void ProtocolHandlerRegistry::InitProtocolSettings() { 446 void ProtocolHandlerRegistry::InitProtocolSettings() {
447 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 447 DCHECK_CURRENTLY_ON(BrowserThread::UI);
448 448
449 // Any further default additions to the table will get rejected from now on. 449 // Any further default additions to the table will get rejected from now on.
450 is_loaded_ = true; 450 is_loaded_ = true;
451 is_loading_ = true; 451 is_loading_ = true;
452 452
453 PrefService* prefs = user_prefs::UserPrefs::Get(context_); 453 PrefService* prefs = user_prefs::UserPrefs::Get(context_);
454 if (prefs->HasPrefPath(prefs::kCustomHandlersEnabled)) { 454 if (prefs->HasPrefPath(prefs::kCustomHandlersEnabled)) {
455 if (prefs->GetBoolean(prefs::kCustomHandlersEnabled)) { 455 if (prefs->GetBoolean(prefs::kCustomHandlersEnabled)) {
456 Enable(); 456 Enable();
457 } else { 457 } else {
(...skipping 19 matching lines...) Expand all
477 scoped_refptr<ShellIntegration::DefaultProtocolClientWorker> worker; 477 scoped_refptr<ShellIntegration::DefaultProtocolClientWorker> worker;
478 worker = delegate_->CreateShellWorker(observer, handler.protocol()); 478 worker = delegate_->CreateShellWorker(observer, handler.protocol());
479 observer->SetWorker(worker.get()); 479 observer->SetWorker(worker.get());
480 default_client_observers_.push_back(observer); 480 default_client_observers_.push_back(observer);
481 worker->StartCheckIsDefault(); 481 worker->StartCheckIsDefault();
482 } 482 }
483 } 483 }
484 } 484 }
485 485
486 int ProtocolHandlerRegistry::GetHandlerIndex(const std::string& scheme) const { 486 int ProtocolHandlerRegistry::GetHandlerIndex(const std::string& scheme) const {
487 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 487 DCHECK_CURRENTLY_ON(BrowserThread::UI);
488 const ProtocolHandler& handler = GetHandlerFor(scheme); 488 const ProtocolHandler& handler = GetHandlerFor(scheme);
489 if (handler.IsEmpty()) 489 if (handler.IsEmpty())
490 return -1; 490 return -1;
491 const ProtocolHandlerList* handlers = GetHandlerList(scheme); 491 const ProtocolHandlerList* handlers = GetHandlerList(scheme);
492 if (!handlers) 492 if (!handlers)
493 return -1; 493 return -1;
494 494
495 ProtocolHandlerList::const_iterator p; 495 ProtocolHandlerList::const_iterator p;
496 int i; 496 int i;
497 for (i = 0, p = handlers->begin(); p != handlers->end(); ++p, ++i) { 497 for (i = 0, p = handlers->begin(); p != handlers->end(); ++p, ++i) {
498 if (*p == handler) 498 if (*p == handler)
499 return i; 499 return i;
500 } 500 }
501 return -1; 501 return -1;
502 } 502 }
503 503
504 ProtocolHandlerRegistry::ProtocolHandlerList 504 ProtocolHandlerRegistry::ProtocolHandlerList
505 ProtocolHandlerRegistry::GetHandlersFor( 505 ProtocolHandlerRegistry::GetHandlersFor(
506 const std::string& scheme) const { 506 const std::string& scheme) const {
507 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 507 DCHECK_CURRENTLY_ON(BrowserThread::UI);
508 ProtocolHandlerMultiMap::const_iterator p = protocol_handlers_.find(scheme); 508 ProtocolHandlerMultiMap::const_iterator p = protocol_handlers_.find(scheme);
509 if (p == protocol_handlers_.end()) { 509 if (p == protocol_handlers_.end()) {
510 return ProtocolHandlerList(); 510 return ProtocolHandlerList();
511 } 511 }
512 return p->second; 512 return p->second;
513 } 513 }
514 514
515 ProtocolHandlerRegistry::ProtocolHandlerList 515 ProtocolHandlerRegistry::ProtocolHandlerList
516 ProtocolHandlerRegistry::GetIgnoredHandlers() { 516 ProtocolHandlerRegistry::GetIgnoredHandlers() {
517 return ignored_protocol_handlers_; 517 return ignored_protocol_handlers_;
518 } 518 }
519 519
520 void ProtocolHandlerRegistry::GetRegisteredProtocols( 520 void ProtocolHandlerRegistry::GetRegisteredProtocols(
521 std::vector<std::string>* output) const { 521 std::vector<std::string>* output) const {
522 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 522 DCHECK_CURRENTLY_ON(BrowserThread::UI);
523 ProtocolHandlerMultiMap::const_iterator p; 523 ProtocolHandlerMultiMap::const_iterator p;
524 for (p = protocol_handlers_.begin(); p != protocol_handlers_.end(); ++p) { 524 for (p = protocol_handlers_.begin(); p != protocol_handlers_.end(); ++p) {
525 if (!p->second.empty()) 525 if (!p->second.empty())
526 output->push_back(p->first); 526 output->push_back(p->first);
527 } 527 }
528 } 528 }
529 529
530 bool ProtocolHandlerRegistry::CanSchemeBeOverridden( 530 bool ProtocolHandlerRegistry::CanSchemeBeOverridden(
531 const std::string& scheme) const { 531 const std::string& scheme) const {
532 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 532 DCHECK_CURRENTLY_ON(BrowserThread::UI);
533 const ProtocolHandlerList* handlers = GetHandlerList(scheme); 533 const ProtocolHandlerList* handlers = GetHandlerList(scheme);
534 // If we already have a handler for this scheme, we can add more. 534 // If we already have a handler for this scheme, we can add more.
535 if (handlers != NULL && !handlers->empty()) 535 if (handlers != NULL && !handlers->empty())
536 return true; 536 return true;
537 // Don't override a scheme if it already has an external handler. 537 // Don't override a scheme if it already has an external handler.
538 return !delegate_->IsExternalHandlerRegistered(scheme); 538 return !delegate_->IsExternalHandlerRegistered(scheme);
539 } 539 }
540 540
541 bool ProtocolHandlerRegistry::IsRegistered( 541 bool ProtocolHandlerRegistry::IsRegistered(
542 const ProtocolHandler& handler) const { 542 const ProtocolHandler& handler) const {
543 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 543 DCHECK_CURRENTLY_ON(BrowserThread::UI);
544 const ProtocolHandlerList* handlers = GetHandlerList(handler.protocol()); 544 const ProtocolHandlerList* handlers = GetHandlerList(handler.protocol());
545 if (!handlers) { 545 if (!handlers) {
546 return false; 546 return false;
547 } 547 }
548 return std::find(handlers->begin(), handlers->end(), handler) != 548 return std::find(handlers->begin(), handlers->end(), handler) !=
549 handlers->end(); 549 handlers->end();
550 } 550 }
551 551
552 bool ProtocolHandlerRegistry::IsRegisteredByUser( 552 bool ProtocolHandlerRegistry::IsRegisteredByUser(
553 const ProtocolHandler& handler) { 553 const ProtocolHandler& handler) {
554 return HandlerExists(handler, &user_protocol_handlers_); 554 return HandlerExists(handler, &user_protocol_handlers_);
555 } 555 }
556 556
557 bool ProtocolHandlerRegistry::HasPolicyRegisteredHandler( 557 bool ProtocolHandlerRegistry::HasPolicyRegisteredHandler(
558 const std::string& scheme) { 558 const std::string& scheme) {
559 return (policy_protocol_handlers_.find(scheme) != 559 return (policy_protocol_handlers_.find(scheme) !=
560 policy_protocol_handlers_.end()); 560 policy_protocol_handlers_.end());
561 } 561 }
562 562
563 bool ProtocolHandlerRegistry::IsIgnored(const ProtocolHandler& handler) const { 563 bool ProtocolHandlerRegistry::IsIgnored(const ProtocolHandler& handler) const {
564 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 564 DCHECK_CURRENTLY_ON(BrowserThread::UI);
565 ProtocolHandlerList::const_iterator i; 565 ProtocolHandlerList::const_iterator i;
566 for (i = ignored_protocol_handlers_.begin(); 566 for (i = ignored_protocol_handlers_.begin();
567 i != ignored_protocol_handlers_.end(); ++i) { 567 i != ignored_protocol_handlers_.end(); ++i) {
568 if (*i == handler) { 568 if (*i == handler) {
569 return true; 569 return true;
570 } 570 }
571 } 571 }
572 return false; 572 return false;
573 } 573 }
574 574
575 bool ProtocolHandlerRegistry::HasRegisteredEquivalent( 575 bool ProtocolHandlerRegistry::HasRegisteredEquivalent(
576 const ProtocolHandler& handler) const { 576 const ProtocolHandler& handler) const {
577 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 577 DCHECK_CURRENTLY_ON(BrowserThread::UI);
578 const ProtocolHandlerList* handlers = GetHandlerList(handler.protocol()); 578 const ProtocolHandlerList* handlers = GetHandlerList(handler.protocol());
579 if (!handlers) { 579 if (!handlers) {
580 return false; 580 return false;
581 } 581 }
582 ProtocolHandlerList::const_iterator i; 582 ProtocolHandlerList::const_iterator i;
583 for (i = handlers->begin(); i != handlers->end(); ++i) { 583 for (i = handlers->begin(); i != handlers->end(); ++i) {
584 if (handler.IsEquivalent(*i)) { 584 if (handler.IsEquivalent(*i)) {
585 return true; 585 return true;
586 } 586 }
587 } 587 }
588 return false; 588 return false;
589 } 589 }
590 590
591 bool ProtocolHandlerRegistry::HasIgnoredEquivalent( 591 bool ProtocolHandlerRegistry::HasIgnoredEquivalent(
592 const ProtocolHandler& handler) const { 592 const ProtocolHandler& handler) const {
593 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 593 DCHECK_CURRENTLY_ON(BrowserThread::UI);
594 ProtocolHandlerList::const_iterator i; 594 ProtocolHandlerList::const_iterator i;
595 for (i = ignored_protocol_handlers_.begin(); 595 for (i = ignored_protocol_handlers_.begin();
596 i != ignored_protocol_handlers_.end(); ++i) { 596 i != ignored_protocol_handlers_.end(); ++i) {
597 if (handler.IsEquivalent(*i)) { 597 if (handler.IsEquivalent(*i)) {
598 return true; 598 return true;
599 } 599 }
600 } 600 }
601 return false; 601 return false;
602 } 602 }
603 603
604 void ProtocolHandlerRegistry::RemoveIgnoredHandler( 604 void ProtocolHandlerRegistry::RemoveIgnoredHandler(
605 const ProtocolHandler& handler) { 605 const ProtocolHandler& handler) {
606 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 606 DCHECK_CURRENTLY_ON(BrowserThread::UI);
607 bool should_notify = false; 607 bool should_notify = false;
608 if (HandlerExists(handler, ignored_protocol_handlers_) && 608 if (HandlerExists(handler, ignored_protocol_handlers_) &&
609 HandlerExists(handler, user_ignored_protocol_handlers_)) { 609 HandlerExists(handler, user_ignored_protocol_handlers_)) {
610 EraseHandler(handler, &user_ignored_protocol_handlers_); 610 EraseHandler(handler, &user_ignored_protocol_handlers_);
611 Save(); 611 Save();
612 if (!HandlerExists(handler, policy_ignored_protocol_handlers_)) { 612 if (!HandlerExists(handler, policy_ignored_protocol_handlers_)) {
613 EraseHandler(handler, &ignored_protocol_handlers_); 613 EraseHandler(handler, &ignored_protocol_handlers_);
614 should_notify = true; 614 should_notify = true;
615 } 615 }
616 } 616 }
617 if (should_notify) 617 if (should_notify)
618 NotifyChanged(); 618 NotifyChanged();
619 } 619 }
620 620
621 bool ProtocolHandlerRegistry::IsHandledProtocol( 621 bool ProtocolHandlerRegistry::IsHandledProtocol(
622 const std::string& scheme) const { 622 const std::string& scheme) const {
623 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 623 DCHECK_CURRENTLY_ON(BrowserThread::UI);
624 return enabled_ && !GetHandlerFor(scheme).IsEmpty(); 624 return enabled_ && !GetHandlerFor(scheme).IsEmpty();
625 } 625 }
626 626
627 void ProtocolHandlerRegistry::RemoveHandler( 627 void ProtocolHandlerRegistry::RemoveHandler(
628 const ProtocolHandler& handler) { 628 const ProtocolHandler& handler) {
629 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 629 DCHECK_CURRENTLY_ON(BrowserThread::UI);
630 ProtocolHandlerList& handlers = protocol_handlers_[handler.protocol()]; 630 ProtocolHandlerList& handlers = protocol_handlers_[handler.protocol()];
631 bool erase_success = false; 631 bool erase_success = false;
632 if (HandlerExists(handler, handlers) && 632 if (HandlerExists(handler, handlers) &&
633 HandlerExists(handler, &user_protocol_handlers_)) { 633 HandlerExists(handler, &user_protocol_handlers_)) {
634 EraseHandler(handler, &user_protocol_handlers_); 634 EraseHandler(handler, &user_protocol_handlers_);
635 erase_success = true; 635 erase_success = true;
636 if (!HandlerExists(handler, &policy_protocol_handlers_)) 636 if (!HandlerExists(handler, &policy_protocol_handlers_))
637 EraseHandler(handler, &protocol_handlers_); 637 EraseHandler(handler, &protocol_handlers_);
638 } 638 }
639 ProtocolHandlerMap::iterator q = default_handlers_.find(handler.protocol()); 639 ProtocolHandlerMap::iterator q = default_handlers_.find(handler.protocol());
(...skipping 14 matching lines...) Expand all
654 654
655 if (erase_success && !IsHandledProtocol(handler.protocol())) { 655 if (erase_success && !IsHandledProtocol(handler.protocol())) {
656 delegate_->DeregisterExternalHandler(handler.protocol()); 656 delegate_->DeregisterExternalHandler(handler.protocol());
657 } 657 }
658 Save(); 658 Save();
659 if (erase_success) 659 if (erase_success)
660 NotifyChanged(); 660 NotifyChanged();
661 } 661 }
662 662
663 void ProtocolHandlerRegistry::RemoveDefaultHandler(const std::string& scheme) { 663 void ProtocolHandlerRegistry::RemoveDefaultHandler(const std::string& scheme) {
664 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 664 DCHECK_CURRENTLY_ON(BrowserThread::UI);
665 ProtocolHandler current_default = GetHandlerFor(scheme); 665 ProtocolHandler current_default = GetHandlerFor(scheme);
666 if (!current_default.IsEmpty()) 666 if (!current_default.IsEmpty())
667 RemoveHandler(current_default); 667 RemoveHandler(current_default);
668 } 668 }
669 669
670 const ProtocolHandler& ProtocolHandlerRegistry::GetHandlerFor( 670 const ProtocolHandler& ProtocolHandlerRegistry::GetHandlerFor(
671 const std::string& scheme) const { 671 const std::string& scheme) const {
672 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 672 DCHECK_CURRENTLY_ON(BrowserThread::UI);
673 return LookupHandler(default_handlers_, scheme); 673 return LookupHandler(default_handlers_, scheme);
674 } 674 }
675 675
676 void ProtocolHandlerRegistry::Enable() { 676 void ProtocolHandlerRegistry::Enable() {
677 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 677 DCHECK_CURRENTLY_ON(BrowserThread::UI);
678 if (enabled_) { 678 if (enabled_) {
679 return; 679 return;
680 } 680 }
681 enabled_ = true; 681 enabled_ = true;
682 BrowserThread::PostTask( 682 BrowserThread::PostTask(
683 BrowserThread::IO, 683 BrowserThread::IO,
684 FROM_HERE, 684 FROM_HERE,
685 base::Bind(&IOThreadDelegate::Enable, io_thread_delegate_)); 685 base::Bind(&IOThreadDelegate::Enable, io_thread_delegate_));
686 686
687 ProtocolHandlerMap::const_iterator p; 687 ProtocolHandlerMap::const_iterator p;
688 for (p = default_handlers_.begin(); p != default_handlers_.end(); ++p) { 688 for (p = default_handlers_.begin(); p != default_handlers_.end(); ++p) {
689 delegate_->RegisterExternalHandler(p->first); 689 delegate_->RegisterExternalHandler(p->first);
690 } 690 }
691 Save(); 691 Save();
692 NotifyChanged(); 692 NotifyChanged();
693 } 693 }
694 694
695 void ProtocolHandlerRegistry::Disable() { 695 void ProtocolHandlerRegistry::Disable() {
696 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 696 DCHECK_CURRENTLY_ON(BrowserThread::UI);
697 if (!enabled_) { 697 if (!enabled_) {
698 return; 698 return;
699 } 699 }
700 enabled_ = false; 700 enabled_ = false;
701 BrowserThread::PostTask( 701 BrowserThread::PostTask(
702 BrowserThread::IO, 702 BrowserThread::IO,
703 FROM_HERE, 703 FROM_HERE,
704 base::Bind(&IOThreadDelegate::Disable, io_thread_delegate_)); 704 base::Bind(&IOThreadDelegate::Disable, io_thread_delegate_));
705 705
706 ProtocolHandlerMap::const_iterator p; 706 ProtocolHandlerMap::const_iterator p;
707 for (p = default_handlers_.begin(); p != default_handlers_.end(); ++p) { 707 for (p = default_handlers_.begin(); p != default_handlers_.end(); ++p) {
708 delegate_->DeregisterExternalHandler(p->first); 708 delegate_->DeregisterExternalHandler(p->first);
709 } 709 }
710 Save(); 710 Save();
711 NotifyChanged(); 711 NotifyChanged();
712 } 712 }
713 713
714 void ProtocolHandlerRegistry::Shutdown() { 714 void ProtocolHandlerRegistry::Shutdown() {
715 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 715 DCHECK_CURRENTLY_ON(BrowserThread::UI);
716 delegate_.reset(NULL); 716 delegate_.reset(NULL);
717 // We free these now in case there are any outstanding workers running. If 717 // We free these now in case there are any outstanding workers running. If
718 // we didn't free them they could respond to workers and try to update the 718 // we didn't free them they could respond to workers and try to update the
719 // protocol handler registry after it was deleted. 719 // protocol handler registry after it was deleted.
720 // Observers remove themselves from this list when they are deleted; so 720 // Observers remove themselves from this list when they are deleted; so
721 // we delete the last item until none are left in the list. 721 // we delete the last item until none are left in the list.
722 while (!default_client_observers_.empty()) { 722 while (!default_client_observers_.empty()) {
723 delete default_client_observers_.back(); 723 delete default_client_observers_.back();
724 } 724 }
725 } 725 }
726 726
727 // static 727 // static
728 void ProtocolHandlerRegistry::RegisterProfilePrefs( 728 void ProtocolHandlerRegistry::RegisterProfilePrefs(
729 user_prefs::PrefRegistrySyncable* registry) { 729 user_prefs::PrefRegistrySyncable* registry) {
730 registry->RegisterListPref(prefs::kRegisteredProtocolHandlers, 730 registry->RegisterListPref(prefs::kRegisteredProtocolHandlers,
731 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 731 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
732 registry->RegisterListPref(prefs::kIgnoredProtocolHandlers, 732 registry->RegisterListPref(prefs::kIgnoredProtocolHandlers,
733 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 733 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
734 registry->RegisterListPref(prefs::kPolicyRegisteredProtocolHandlers, 734 registry->RegisterListPref(prefs::kPolicyRegisteredProtocolHandlers,
735 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 735 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
736 registry->RegisterListPref(prefs::kPolicyIgnoredProtocolHandlers, 736 registry->RegisterListPref(prefs::kPolicyIgnoredProtocolHandlers,
737 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 737 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
738 registry->RegisterBooleanPref( 738 registry->RegisterBooleanPref(
739 prefs::kCustomHandlersEnabled, 739 prefs::kCustomHandlersEnabled,
740 true, 740 true,
741 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); 741 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
742 } 742 }
743 743
744 ProtocolHandlerRegistry::~ProtocolHandlerRegistry() { 744 ProtocolHandlerRegistry::~ProtocolHandlerRegistry() {
745 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 745 DCHECK_CURRENTLY_ON(BrowserThread::UI);
746 DCHECK(default_client_observers_.empty()); 746 DCHECK(default_client_observers_.empty());
747 } 747 }
748 748
749 void ProtocolHandlerRegistry::PromoteHandler(const ProtocolHandler& handler) { 749 void ProtocolHandlerRegistry::PromoteHandler(const ProtocolHandler& handler) {
750 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 750 DCHECK_CURRENTLY_ON(BrowserThread::UI);
751 DCHECK(IsRegistered(handler)); 751 DCHECK(IsRegistered(handler));
752 ProtocolHandlerMultiMap::iterator p = 752 ProtocolHandlerMultiMap::iterator p =
753 protocol_handlers_.find(handler.protocol()); 753 protocol_handlers_.find(handler.protocol());
754 ProtocolHandlerList& list = p->second; 754 ProtocolHandlerList& list = p->second;
755 list.erase(std::find(list.begin(), list.end(), handler)); 755 list.erase(std::find(list.begin(), list.end(), handler));
756 list.insert(list.begin(), handler); 756 list.insert(list.begin(), handler);
757 } 757 }
758 758
759 void ProtocolHandlerRegistry::Save() { 759 void ProtocolHandlerRegistry::Save() {
760 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 760 DCHECK_CURRENTLY_ON(BrowserThread::UI);
761 if (is_loading_) { 761 if (is_loading_) {
762 return; 762 return;
763 } 763 }
764 scoped_ptr<base::Value> registered_protocol_handlers( 764 scoped_ptr<base::Value> registered_protocol_handlers(
765 EncodeRegisteredHandlers()); 765 EncodeRegisteredHandlers());
766 scoped_ptr<base::Value> ignored_protocol_handlers(EncodeIgnoredHandlers()); 766 scoped_ptr<base::Value> ignored_protocol_handlers(EncodeIgnoredHandlers());
767 PrefService* prefs = user_prefs::UserPrefs::Get(context_); 767 PrefService* prefs = user_prefs::UserPrefs::Get(context_);
768 768
769 prefs->Set(prefs::kRegisteredProtocolHandlers, 769 prefs->Set(prefs::kRegisteredProtocolHandlers,
770 *registered_protocol_handlers); 770 *registered_protocol_handlers);
771 prefs->Set(prefs::kIgnoredProtocolHandlers, 771 prefs->Set(prefs::kIgnoredProtocolHandlers,
772 *ignored_protocol_handlers); 772 *ignored_protocol_handlers);
773 prefs->SetBoolean(prefs::kCustomHandlersEnabled, enabled_); 773 prefs->SetBoolean(prefs::kCustomHandlersEnabled, enabled_);
774 } 774 }
775 775
776 const ProtocolHandlerRegistry::ProtocolHandlerList* 776 const ProtocolHandlerRegistry::ProtocolHandlerList*
777 ProtocolHandlerRegistry::GetHandlerList( 777 ProtocolHandlerRegistry::GetHandlerList(
778 const std::string& scheme) const { 778 const std::string& scheme) const {
779 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 779 DCHECK_CURRENTLY_ON(BrowserThread::UI);
780 ProtocolHandlerMultiMap::const_iterator p = protocol_handlers_.find(scheme); 780 ProtocolHandlerMultiMap::const_iterator p = protocol_handlers_.find(scheme);
781 if (p == protocol_handlers_.end()) { 781 if (p == protocol_handlers_.end()) {
782 return NULL; 782 return NULL;
783 } 783 }
784 return &p->second; 784 return &p->second;
785 } 785 }
786 786
787 void ProtocolHandlerRegistry::SetDefault(const ProtocolHandler& handler) { 787 void ProtocolHandlerRegistry::SetDefault(const ProtocolHandler& handler) {
788 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 788 DCHECK_CURRENTLY_ON(BrowserThread::UI);
789 ProtocolHandlerMap::const_iterator p = default_handlers_.find( 789 ProtocolHandlerMap::const_iterator p = default_handlers_.find(
790 handler.protocol()); 790 handler.protocol());
791 // If we're not loading, and we are setting a default for a new protocol, 791 // If we're not loading, and we are setting a default for a new protocol,
792 // register with the OS. 792 // register with the OS.
793 if (!is_loading_ && p == default_handlers_.end()) 793 if (!is_loading_ && p == default_handlers_.end())
794 delegate_->RegisterWithOSAsDefaultClient(handler.protocol(), this); 794 delegate_->RegisterWithOSAsDefaultClient(handler.protocol(), this);
795 default_handlers_.erase(handler.protocol()); 795 default_handlers_.erase(handler.protocol());
796 default_handlers_.insert(std::make_pair(handler.protocol(), handler)); 796 default_handlers_.insert(std::make_pair(handler.protocol(), handler));
797 PromoteHandler(handler); 797 PromoteHandler(handler);
798 BrowserThread::PostTask( 798 BrowserThread::PostTask(
799 BrowserThread::IO, 799 BrowserThread::IO,
800 FROM_HERE, 800 FROM_HERE,
801 base::Bind(&IOThreadDelegate::SetDefault, io_thread_delegate_, handler)); 801 base::Bind(&IOThreadDelegate::SetDefault, io_thread_delegate_, handler));
802 } 802 }
803 803
804 void ProtocolHandlerRegistry::InsertHandler(const ProtocolHandler& handler) { 804 void ProtocolHandlerRegistry::InsertHandler(const ProtocolHandler& handler) {
805 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 805 DCHECK_CURRENTLY_ON(BrowserThread::UI);
806 ProtocolHandlerMultiMap::iterator p = 806 ProtocolHandlerMultiMap::iterator p =
807 protocol_handlers_.find(handler.protocol()); 807 protocol_handlers_.find(handler.protocol());
808 808
809 if (p != protocol_handlers_.end()) { 809 if (p != protocol_handlers_.end()) {
810 p->second.push_back(handler); 810 p->second.push_back(handler);
811 return; 811 return;
812 } 812 }
813 813
814 ProtocolHandlerList new_list; 814 ProtocolHandlerList new_list;
815 new_list.push_back(handler); 815 new_list.push_back(handler);
816 protocol_handlers_[handler.protocol()] = new_list; 816 protocol_handlers_[handler.protocol()] = new_list;
817 } 817 }
818 818
819 base::Value* ProtocolHandlerRegistry::EncodeRegisteredHandlers() { 819 base::Value* ProtocolHandlerRegistry::EncodeRegisteredHandlers() {
820 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 820 DCHECK_CURRENTLY_ON(BrowserThread::UI);
821 base::ListValue* protocol_handlers = new base::ListValue(); 821 base::ListValue* protocol_handlers = new base::ListValue();
822 for (ProtocolHandlerMultiMap::iterator i = user_protocol_handlers_.begin(); 822 for (ProtocolHandlerMultiMap::iterator i = user_protocol_handlers_.begin();
823 i != user_protocol_handlers_.end(); 823 i != user_protocol_handlers_.end();
824 ++i) { 824 ++i) {
825 for (ProtocolHandlerList::iterator j = i->second.begin(); 825 for (ProtocolHandlerList::iterator j = i->second.begin();
826 j != i->second.end(); ++j) { 826 j != i->second.end(); ++j) {
827 base::DictionaryValue* encoded = j->Encode(); 827 base::DictionaryValue* encoded = j->Encode();
828 if (IsDefault(*j)) { 828 if (IsDefault(*j)) {
829 encoded->Set("default", new base::FundamentalValue(true)); 829 encoded->Set("default", new base::FundamentalValue(true));
830 } 830 }
831 protocol_handlers->Append(encoded); 831 protocol_handlers->Append(encoded);
832 } 832 }
833 } 833 }
834 return protocol_handlers; 834 return protocol_handlers;
835 } 835 }
836 836
837 base::Value* ProtocolHandlerRegistry::EncodeIgnoredHandlers() { 837 base::Value* ProtocolHandlerRegistry::EncodeIgnoredHandlers() {
838 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 838 DCHECK_CURRENTLY_ON(BrowserThread::UI);
839 base::ListValue* handlers = new base::ListValue(); 839 base::ListValue* handlers = new base::ListValue();
840 for (ProtocolHandlerList::iterator i = 840 for (ProtocolHandlerList::iterator i =
841 user_ignored_protocol_handlers_.begin(); 841 user_ignored_protocol_handlers_.begin();
842 i != user_ignored_protocol_handlers_.end(); 842 i != user_ignored_protocol_handlers_.end();
843 ++i) { 843 ++i) {
844 handlers->Append(i->Encode()); 844 handlers->Append(i->Encode());
845 } 845 }
846 return handlers; 846 return handlers;
847 } 847 }
848 848
849 void ProtocolHandlerRegistry::NotifyChanged() { 849 void ProtocolHandlerRegistry::NotifyChanged() {
850 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 850 DCHECK_CURRENTLY_ON(BrowserThread::UI);
851 content::NotificationService::current()->Notify( 851 content::NotificationService::current()->Notify(
852 chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED, 852 chrome::NOTIFICATION_PROTOCOL_HANDLER_REGISTRY_CHANGED,
853 content::Source<content::BrowserContext>(context_), 853 content::Source<content::BrowserContext>(context_),
854 content::NotificationService::NoDetails()); 854 content::NotificationService::NoDetails());
855 } 855 }
856 856
857 void ProtocolHandlerRegistry::RegisterProtocolHandler( 857 void ProtocolHandlerRegistry::RegisterProtocolHandler(
858 const ProtocolHandler& handler, 858 const ProtocolHandler& handler,
859 const HandlerSource source) { 859 const HandlerSource source) {
860 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 860 DCHECK_CURRENTLY_ON(BrowserThread::UI);
861 DCHECK(CanSchemeBeOverridden(handler.protocol())); 861 DCHECK(CanSchemeBeOverridden(handler.protocol()));
862 DCHECK(!handler.IsEmpty()); 862 DCHECK(!handler.IsEmpty());
863 ProtocolHandlerMultiMap& map = 863 ProtocolHandlerMultiMap& map =
864 (source == POLICY) ? policy_protocol_handlers_ : user_protocol_handlers_; 864 (source == POLICY) ? policy_protocol_handlers_ : user_protocol_handlers_;
865 ProtocolHandlerList& list = map[handler.protocol()]; 865 ProtocolHandlerList& list = map[handler.protocol()];
866 if (!HandlerExists(handler, list)) 866 if (!HandlerExists(handler, list))
867 list.push_back(handler); 867 list.push_back(handler);
868 if (IsRegistered(handler)) { 868 if (IsRegistered(handler)) {
869 return; 869 return;
870 } 870 }
871 if (enabled_ && !delegate_->IsExternalHandlerRegistered(handler.protocol())) 871 if (enabled_ && !delegate_->IsExternalHandlerRegistered(handler.protocol()))
872 delegate_->RegisterExternalHandler(handler.protocol()); 872 delegate_->RegisterExternalHandler(handler.protocol());
873 InsertHandler(handler); 873 InsertHandler(handler);
874 } 874 }
875 875
876 std::vector<const base::DictionaryValue*> 876 std::vector<const base::DictionaryValue*>
877 ProtocolHandlerRegistry::GetHandlersFromPref(const char* pref_name) const { 877 ProtocolHandlerRegistry::GetHandlersFromPref(const char* pref_name) const {
878 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 878 DCHECK_CURRENTLY_ON(BrowserThread::UI);
879 std::vector<const base::DictionaryValue*> result; 879 std::vector<const base::DictionaryValue*> result;
880 PrefService* prefs = user_prefs::UserPrefs::Get(context_); 880 PrefService* prefs = user_prefs::UserPrefs::Get(context_);
881 if (!prefs->HasPrefPath(pref_name)) { 881 if (!prefs->HasPrefPath(pref_name)) {
882 return result; 882 return result;
883 } 883 }
884 884
885 const base::ListValue* handlers = prefs->GetList(pref_name); 885 const base::ListValue* handlers = prefs->GetList(pref_name);
886 if (handlers) { 886 if (handlers) {
887 for (size_t i = 0; i < handlers->GetSize(); ++i) { 887 for (size_t i = 0; i < handlers->GetSize(); ++i) {
888 const base::DictionaryValue* dict; 888 const base::DictionaryValue* dict;
(...skipping 21 matching lines...) Expand all
910 bool is_default = false; 910 bool is_default = false;
911 if ((*p)->GetBoolean("default", &is_default) && is_default) { 911 if ((*p)->GetBoolean("default", &is_default) && is_default) {
912 SetDefault(handler); 912 SetDefault(handler);
913 } 913 }
914 } 914 }
915 } 915 }
916 916
917 void ProtocolHandlerRegistry::IgnoreProtocolHandler( 917 void ProtocolHandlerRegistry::IgnoreProtocolHandler(
918 const ProtocolHandler& handler, 918 const ProtocolHandler& handler,
919 const HandlerSource source) { 919 const HandlerSource source) {
920 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 920 DCHECK_CURRENTLY_ON(BrowserThread::UI);
921 ProtocolHandlerList& list = (source == POLICY) 921 ProtocolHandlerList& list = (source == POLICY)
922 ? policy_ignored_protocol_handlers_ 922 ? policy_ignored_protocol_handlers_
923 : user_ignored_protocol_handlers_; 923 : user_ignored_protocol_handlers_;
924 if (!HandlerExists(handler, list)) 924 if (!HandlerExists(handler, list))
925 list.push_back(handler); 925 list.push_back(handler);
926 if (HandlerExists(handler, ignored_protocol_handlers_)) 926 if (HandlerExists(handler, ignored_protocol_handlers_))
927 return; 927 return;
928 ignored_protocol_handlers_.push_back(handler); 928 ignored_protocol_handlers_.push_back(handler);
929 } 929 }
930 930
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 963
964 void ProtocolHandlerRegistry::AddPredefinedHandler( 964 void ProtocolHandlerRegistry::AddPredefinedHandler(
965 const ProtocolHandler& handler) { 965 const ProtocolHandler& handler) {
966 DCHECK(!is_loaded_); // Must be called prior InitProtocolSettings. 966 DCHECK(!is_loaded_); // Must be called prior InitProtocolSettings.
967 RegisterProtocolHandler(handler, USER); 967 RegisterProtocolHandler(handler, USER);
968 SetDefault(handler); 968 SetDefault(handler);
969 } 969 }
970 970
971 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory> 971 scoped_ptr<ProtocolHandlerRegistry::JobInterceptorFactory>
972 ProtocolHandlerRegistry::CreateJobInterceptorFactory() { 972 ProtocolHandlerRegistry::CreateJobInterceptorFactory() {
973 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 973 DCHECK_CURRENTLY_ON(BrowserThread::UI);
974 // this is always created on the UI thread (in profile_io's 974 // this is always created on the UI thread (in profile_io's
975 // InitializeOnUIThread. Any method calls must be done 975 // InitializeOnUIThread. Any method calls must be done
976 // on the IO thread (this is checked). 976 // on the IO thread (this is checked).
977 return scoped_ptr<JobInterceptorFactory>( 977 return scoped_ptr<JobInterceptorFactory>(
978 new JobInterceptorFactory(io_thread_delegate_.get())); 978 new JobInterceptorFactory(io_thread_delegate_.get()));
979 } 979 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/custom_handlers/protocol_handler_registry_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698