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

Side by Side Diff: net/proxy/proxy_service.cc

Issue 6871019: Enable (optional) blocking of webrequests in case a PAC script cannot be fetched or is invalid. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 9 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 | Annotate | Revision Log
« net/proxy/proxy_config.cc ('K') | « net/proxy/proxy_service.h ('k') | no next file » | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "net/proxy/proxy_service.h" 5 #include "net/proxy/proxy_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 545
546 int ProxyService::TryToCompleteSynchronously(const GURL& url, 546 int ProxyService::TryToCompleteSynchronously(const GURL& url,
547 ProxyInfo* result) { 547 ProxyInfo* result) {
548 DCHECK_NE(STATE_NONE, current_state_); 548 DCHECK_NE(STATE_NONE, current_state_);
549 549
550 if (current_state_ != STATE_READY) 550 if (current_state_ != STATE_READY)
551 return ERR_IO_PENDING; // Still initializing. 551 return ERR_IO_PENDING; // Still initializing.
552 552
553 DCHECK_NE(config_.id(), ProxyConfig::INVALID_ID); 553 DCHECK_NE(config_.id(), ProxyConfig::INVALID_ID);
554 554
555 // If it was impossible to fetch or parse the PAC script, we cannot complete
556 // the request here and bail out.
557 if (permanent_error_ != OK)
558 return permanent_error_;
559
555 if (config_.HasAutomaticSettings()) 560 if (config_.HasAutomaticSettings())
556 return ERR_IO_PENDING; // Must submit the request to the proxy resolver. 561 return ERR_IO_PENDING; // Must submit the request to the proxy resolver.
557 562
558 // Use the manual proxy settings. 563 // Use the manual proxy settings.
559 config_.proxy_rules().Apply(url, result); 564 config_.proxy_rules().Apply(url, result);
560 result->config_id_ = config_.id(); 565 result->config_id_ = config_.id();
561 return OK; 566 return OK;
562 } 567 }
563 568
564 ProxyService::~ProxyService() { 569 ProxyService::~ProxyService() {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 OnProxyConfigChanged(config, availability); 640 OnProxyConfigChanged(config, availability);
636 } 641 }
637 642
638 void ProxyService::OnInitProxyResolverComplete(int result) { 643 void ProxyService::OnInitProxyResolverComplete(int result) {
639 DCHECK_EQ(STATE_WAITING_FOR_INIT_PROXY_RESOLVER, current_state_); 644 DCHECK_EQ(STATE_WAITING_FOR_INIT_PROXY_RESOLVER, current_state_);
640 DCHECK(init_proxy_resolver_.get()); 645 DCHECK(init_proxy_resolver_.get());
641 DCHECK(fetched_config_.HasAutomaticSettings()); 646 DCHECK(fetched_config_.HasAutomaticSettings());
642 init_proxy_resolver_.reset(); 647 init_proxy_resolver_.reset();
643 648
644 if (result != OK) { 649 if (result != OK) {
645 VLOG(1) << "Failed configuring with PAC script, falling-back to manual " 650 if (fetched_config_.pac_mandatory()) {
646 "proxy servers."; 651 VLOG(1) << "Failed configuring with mandatory PAC script, blocking all "
647 config_ = fetched_config_; 652 "traffic.";
648 config_.ClearAutomaticSettings(); 653 config_ = fetched_config_;
654 result = ERR_MANDATORY_PROXY_CONFIGURATION_FAILED;
655 } else {
656 VLOG(1) << "Failed configuring with PAC script, falling-back to manual "
657 "proxy servers.";
658 config_ = fetched_config_;
659 config_.ClearAutomaticSettings();
660 result = OK;
661 }
649 } 662 }
663 permanent_error_ = result;
650 664
651 config_.set_id(fetched_config_.id()); 665 config_.set_id(fetched_config_.id());
652 666
653 // Resume any requests which we had to defer until the PAC script was 667 // Resume any requests which we had to defer until the PAC script was
654 // downloaded. 668 // downloaded.
655 SetReady(); 669 SetReady();
656 } 670 }
657 671
658 int ProxyService::ReconsiderProxyAfterError(const GURL& url, 672 int ProxyService::ReconsiderProxyAfterError(const GURL& url,
659 ProxyInfo* result, 673 ProxyInfo* result,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 make_scoped_refptr(new NetLogStringParameter( 730 make_scoped_refptr(new NetLogStringParameter(
717 "pac_string", result->ToPacString()))); 731 "pac_string", result->ToPacString())));
718 } 732 }
719 result->DeprioritizeBadProxies(proxy_retry_info_); 733 result->DeprioritizeBadProxies(proxy_retry_info_);
720 } else { 734 } else {
721 net_log.AddEvent( 735 net_log.AddEvent(
722 NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST, 736 NetLog::TYPE_PROXY_SERVICE_RESOLVED_PROXY_LIST,
723 make_scoped_refptr(new NetLogIntegerParameter( 737 make_scoped_refptr(new NetLogIntegerParameter(
724 "net_error", result_code))); 738 "net_error", result_code)));
725 739
726 // Fall-back to direct when the proxy resolver fails. This corresponds 740 if (!config_.pac_mandatory()) {
727 // with a javascript runtime error in the PAC script. 741 // Fall-back to direct when the proxy resolver fails. This corresponds
728 // 742 // with a javascript runtime error in the PAC script.
729 // This implicit fall-back to direct matches Firefox 3.5 and 743 //
730 // Internet Explorer 8. For more information, see: 744 // This implicit fall-back to direct matches Firefox 3.5 and
731 // 745 // Internet Explorer 8. For more information, see:
732 // http://www.chromium.org/developers/design-documents/proxy-settings-fallba ck 746 //
733 result->UseDirect(); 747 // http://www.chromium.org/developers/design-documents/proxy-settings-fall back
734 result_code = OK; 748 result->UseDirect();
749 result_code = OK;
750 } else {
751 result_code = ERR_MANDATORY_PROXY_CONFIGURATION_FAILED;
752 }
735 } 753 }
736 754
737 net_log.EndEvent(NetLog::TYPE_PROXY_SERVICE, NULL); 755 net_log.EndEvent(NetLog::TYPE_PROXY_SERVICE, NULL);
738 return result_code; 756 return result_code;
739 } 757 }
740 758
741 void ProxyService::SetProxyScriptFetcher( 759 void ProxyService::SetProxyScriptFetcher(
742 ProxyScriptFetcher* proxy_script_fetcher) { 760 ProxyScriptFetcher* proxy_script_fetcher) {
743 DCHECK(CalledOnValidThread()); 761 DCHECK(CalledOnValidThread());
744 State previous_state = ResetProxyConfig(false); 762 State previous_state = ResetProxyConfig(false);
745 proxy_script_fetcher_.reset(proxy_script_fetcher); 763 proxy_script_fetcher_.reset(proxy_script_fetcher);
746 if (previous_state != STATE_NONE) 764 if (previous_state != STATE_NONE)
747 ApplyProxyConfigIfAvailable(); 765 ApplyProxyConfigIfAvailable();
748 } 766 }
749 767
750 ProxyScriptFetcher* ProxyService::GetProxyScriptFetcher() const { 768 ProxyScriptFetcher* ProxyService::GetProxyScriptFetcher() const {
751 DCHECK(CalledOnValidThread()); 769 DCHECK(CalledOnValidThread());
752 return proxy_script_fetcher_.get(); 770 return proxy_script_fetcher_.get();
753 } 771 }
754 772
755 ProxyService::State ProxyService::ResetProxyConfig(bool reset_fetched_config) { 773 ProxyService::State ProxyService::ResetProxyConfig(bool reset_fetched_config) {
756 DCHECK(CalledOnValidThread()); 774 DCHECK(CalledOnValidThread());
757 State previous_state = current_state_; 775 State previous_state = current_state_;
758 776
777 permanent_error_ = OK;
759 proxy_retry_info_.clear(); 778 proxy_retry_info_.clear();
760 init_proxy_resolver_.reset(); 779 init_proxy_resolver_.reset();
761 SuspendAllPendingRequests(); 780 SuspendAllPendingRequests();
762 config_ = ProxyConfig(); 781 config_ = ProxyConfig();
763 if (reset_fetched_config) 782 if (reset_fetched_config)
764 fetched_config_ = ProxyConfig(); 783 fetched_config_ = ProxyConfig();
765 current_state_ = STATE_NONE; 784 current_state_ = STATE_NONE;
766 785
767 return previous_state; 786 return previous_state;
768 } 787 }
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 OnCompletion(result_); 993 OnCompletion(result_);
975 } 994 }
976 } 995 }
977 996
978 void SyncProxyServiceHelper::OnCompletion(int rv) { 997 void SyncProxyServiceHelper::OnCompletion(int rv) {
979 result_ = rv; 998 result_ = rv;
980 event_.Signal(); 999 event_.Signal();
981 } 1000 }
982 1001
983 } // namespace net 1002 } // namespace net
OLDNEW
« net/proxy/proxy_config.cc ('K') | « net/proxy/proxy_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698