OLD | NEW |
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 "content/browser/child_process_security_policy_impl.h" | 5 #include "content/browser/child_process_security_policy_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/debug/dump_without_crashing.h" | 11 #include "base/debug/dump_without_crashing.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
16 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
17 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 20 #include "content/browser/isolated_origin_util.h" |
20 #include "content/browser/site_instance_impl.h" | 21 #include "content/browser/site_instance_impl.h" |
21 #include "content/common/resource_request_body_impl.h" | 22 #include "content/common/resource_request_body_impl.h" |
22 #include "content/common/site_isolation_policy.h" | 23 #include "content/common/site_isolation_policy.h" |
23 #include "content/public/browser/browser_context.h" | 24 #include "content/public/browser/browser_context.h" |
24 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
25 #include "content/public/browser/child_process_data.h" | 26 #include "content/public/browser/child_process_data.h" |
26 #include "content/public/browser/content_browser_client.h" | 27 #include "content/public/browser/content_browser_client.h" |
27 #include "content/public/browser/render_process_host.h" | 28 #include "content/public/browser/render_process_host.h" |
28 #include "content/public/browser/storage_partition.h" | 29 #include "content/public/browser/storage_partition.h" |
29 #include "content/public/common/bindings_policy.h" | 30 #include "content/public/common/bindings_policy.h" |
(...skipping 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1063 if (state == security_state_.end()) | 1064 if (state == security_state_.end()) |
1064 return false; | 1065 return false; |
1065 | 1066 |
1066 return state->second->can_send_midi_sysex(); | 1067 return state->second->can_send_midi_sysex(); |
1067 } | 1068 } |
1068 | 1069 |
1069 void ChildProcessSecurityPolicyImpl::AddIsolatedOrigin( | 1070 void ChildProcessSecurityPolicyImpl::AddIsolatedOrigin( |
1070 const url::Origin& origin) { | 1071 const url::Origin& origin) { |
1071 CHECK(!origin.unique()) | 1072 CHECK(!origin.unique()) |
1072 << "Cannot register a unique origin as an isolated origin."; | 1073 << "Cannot register a unique origin as an isolated origin."; |
1073 CHECK(!IsIsolatedOrigin(origin)) | 1074 |
| 1075 base::AutoLock lock(lock_); |
| 1076 CHECK(!isolated_origins_.count(origin)) |
1074 << "Duplicate isolated origin: " << origin.Serialize(); | 1077 << "Duplicate isolated origin: " << origin.Serialize(); |
1075 | 1078 |
1076 base::AutoLock lock(lock_); | |
1077 isolated_origins_.insert(origin); | 1079 isolated_origins_.insert(origin); |
1078 } | 1080 } |
1079 | 1081 |
1080 void ChildProcessSecurityPolicyImpl::AddIsolatedOriginsFromCommandLine( | 1082 void ChildProcessSecurityPolicyImpl::AddIsolatedOriginsFromCommandLine( |
1081 const std::string& origin_list) { | 1083 const std::string& origin_list) { |
1082 for (const base::StringPiece& origin_piece : | 1084 for (const base::StringPiece& origin_piece : |
1083 base::SplitStringPiece(origin_list, ",", base::TRIM_WHITESPACE, | 1085 base::SplitStringPiece(origin_list, ",", base::TRIM_WHITESPACE, |
1084 base::SPLIT_WANT_NONEMPTY)) { | 1086 base::SPLIT_WANT_NONEMPTY)) { |
1085 url::Origin origin((GURL(origin_piece))); | 1087 url::Origin origin((GURL(origin_piece))); |
1086 if (!origin.unique()) | 1088 if (!origin.unique()) |
1087 AddIsolatedOrigin(origin); | 1089 AddIsolatedOrigin(origin); |
1088 } | 1090 } |
1089 } | 1091 } |
1090 | 1092 |
1091 bool ChildProcessSecurityPolicyImpl::IsIsolatedOrigin( | 1093 bool ChildProcessSecurityPolicyImpl::IsIsolatedOrigin( |
1092 const url::Origin& origin) { | 1094 const url::Origin& origin) { |
| 1095 url::Origin unused_result; |
| 1096 return GetMatchingIsolatedOrigin(origin, &unused_result); |
| 1097 } |
| 1098 |
| 1099 bool ChildProcessSecurityPolicyImpl::GetMatchingIsolatedOrigin( |
| 1100 const url::Origin& origin, |
| 1101 url::Origin* result) { |
| 1102 *result = url::Origin(); |
1093 base::AutoLock lock(lock_); | 1103 base::AutoLock lock(lock_); |
1094 return isolated_origins_.find(origin) != isolated_origins_.end(); | 1104 |
| 1105 // If multiple isolated origins are registered with a common domain suffix, |
| 1106 // return the most specific one. For example, if foo.isolated.com and |
| 1107 // isolated.com are both isolated origins, bar.foo.isolated.com should return |
| 1108 // foo.isolated.com. |
| 1109 bool found = false; |
| 1110 for (auto isolated_origin : isolated_origins_) { |
| 1111 if (IsolatedOriginUtil::DoesOriginMatchIsolatedOrigin(origin, |
| 1112 isolated_origin)) { |
| 1113 if (!found || result->host().length() < isolated_origin.host().length()) { |
| 1114 *result = isolated_origin; |
| 1115 found = true; |
| 1116 } |
| 1117 } |
| 1118 } |
| 1119 |
| 1120 return found; |
| 1121 } |
| 1122 |
| 1123 void ChildProcessSecurityPolicyImpl::RemoveIsolatedOriginForTesting( |
| 1124 const url::Origin& origin) { |
| 1125 base::AutoLock lock(lock_); |
| 1126 isolated_origins_.erase(origin); |
1095 } | 1127 } |
1096 | 1128 |
1097 } // namespace content | 1129 } // namespace content |
OLD | NEW |