OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/net/chrome_url_request_context.h" | 5 #include "chrome/browser/net/chrome_url_request_context.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/chrome_thread.h" | 10 #include "chrome/browser/chrome_thread.h" |
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 ExtensionInfoMap::iterator iter = extension_info_.find(id); | 741 ExtensionInfoMap::iterator iter = extension_info_.find(id); |
742 std::string result; | 742 std::string result; |
743 if (iter != extension_info_.end()) | 743 if (iter != extension_info_.end()) |
744 result = iter->second->default_locale; | 744 result = iter->second->default_locale; |
745 | 745 |
746 return result; | 746 return result; |
747 } | 747 } |
748 | 748 |
749 bool ChromeURLRequestContext::CheckURLAccessToExtensionPermission( | 749 bool ChromeURLRequestContext::CheckURLAccessToExtensionPermission( |
750 const GURL& url, | 750 const GURL& url, |
751 const std::string& application_id, | |
752 const char* permission_name) { | 751 const char* permission_name) { |
753 DCHECK(!application_id.empty()); | 752 ExtensionInfoMap::iterator info; |
| 753 if (url.SchemeIs(chrome::kExtensionScheme)) { |
| 754 // If the url is an extension scheme, we just look it up by extension id. |
| 755 std::string id = url.host(); |
| 756 info = extension_info_.find(id); |
| 757 } else { |
| 758 // Otherwise, we scan for a matching extent. Overlapping extents are |
| 759 // disallowed, so only one will match. |
| 760 info = extension_info_.begin(); |
| 761 while (info != extension_info_.end() && |
| 762 !info->second->extent.ContainsURL(url)) |
| 763 ++info; |
| 764 } |
754 | 765 |
755 // Get the information about the specified extension. If the extension isn't | |
756 // installed, then permission is not granted. | |
757 ExtensionInfoMap::iterator info = extension_info_.find(application_id); | |
758 if (info == extension_info_.end()) | 766 if (info == extension_info_.end()) |
759 return false; | 767 return false; |
760 | 768 |
761 // Check that the extension declares the required permission. | 769 std::vector<std::string>& api_permissions = info->second->api_permissions; |
762 std::vector<std::string>& permissions = info->second->api_permissions; | 770 return std::find(api_permissions.begin(), |
763 if (permissions.end() == std::find(permissions.begin(), permissions.end(), | 771 api_permissions.end(), |
764 permission_name)) { | 772 permission_name) != api_permissions.end(); |
765 return false; | |
766 } | |
767 | |
768 // Check that the extension declares the source URL in its extent. | |
769 Extension::URLPatternList& extent = info->second->extent; | |
770 for (Extension::URLPatternList::iterator pattern = extent.begin(); | |
771 pattern != extent.end(); ++pattern) { | |
772 if (pattern->MatchesUrl(url)) | |
773 return true; | |
774 } | |
775 | |
776 return false; | |
777 } | 773 } |
778 | 774 |
779 const std::string& ChromeURLRequestContext::GetUserAgent( | 775 const std::string& ChromeURLRequestContext::GetUserAgent( |
780 const GURL& url) const { | 776 const GURL& url) const { |
781 return webkit_glue::GetUserAgent(url); | 777 return webkit_glue::GetUserAgent(url); |
782 } | 778 } |
783 | 779 |
784 bool ChromeURLRequestContext::InterceptRequestCookies( | 780 bool ChromeURLRequestContext::InterceptRequestCookies( |
785 const URLRequest* request, const std::string& cookies) const { | 781 const URLRequest* request, const std::string& cookies) const { |
786 return InterceptCookie(request, cookies); | 782 return InterceptCookie(request, cookies); |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
938 if (profile->GetExtensionsService()) { | 934 if (profile->GetExtensionsService()) { |
939 const ExtensionList* extensions = | 935 const ExtensionList* extensions = |
940 profile->GetExtensionsService()->extensions(); | 936 profile->GetExtensionsService()->extensions(); |
941 for (ExtensionList::const_iterator iter = extensions->begin(); | 937 for (ExtensionList::const_iterator iter = extensions->begin(); |
942 iter != extensions->end(); ++iter) { | 938 iter != extensions->end(); ++iter) { |
943 extension_info_[(*iter)->id()] = | 939 extension_info_[(*iter)->id()] = |
944 linked_ptr<ChromeURLRequestContext::ExtensionInfo>( | 940 linked_ptr<ChromeURLRequestContext::ExtensionInfo>( |
945 new ChromeURLRequestContext::ExtensionInfo( | 941 new ChromeURLRequestContext::ExtensionInfo( |
946 (*iter)->path(), | 942 (*iter)->path(), |
947 (*iter)->default_locale(), | 943 (*iter)->default_locale(), |
948 std::vector<URLPattern>(), | 944 (*iter)->web_extent(), |
949 (*iter)->api_permissions())); | 945 (*iter)->api_permissions())); |
950 } | 946 } |
951 } | 947 } |
952 | 948 |
953 if (profile->GetUserScriptMaster()) | 949 if (profile->GetUserScriptMaster()) |
954 user_script_dir_path_ = profile->GetUserScriptMaster()->user_script_dir(); | 950 user_script_dir_path_ = profile->GetUserScriptMaster()->user_script_dir(); |
955 | 951 |
956 ssl_config_service_ = profile->GetSSLConfigService(); | 952 ssl_config_service_ = profile->GetSSLConfigService(); |
957 | 953 |
958 profile_dir_path_ = profile->GetPath(); | 954 profile_dir_path_ = profile->GetPath(); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 } | 1031 } |
1036 | 1032 |
1037 if (command_line.HasSwitch(switches::kProxyBypassList)) { | 1033 if (command_line.HasSwitch(switches::kProxyBypassList)) { |
1038 proxy_config->proxy_rules().bypass_rules.ParseFromString( | 1034 proxy_config->proxy_rules().bypass_rules.ParseFromString( |
1039 WideToASCII(command_line.GetSwitchValue( | 1035 WideToASCII(command_line.GetSwitchValue( |
1040 switches::kProxyBypassList))); | 1036 switches::kProxyBypassList))); |
1041 } | 1037 } |
1042 | 1038 |
1043 return proxy_config; | 1039 return proxy_config; |
1044 } | 1040 } |
OLD | NEW |