| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/child/site_isolation_policy.h" | 5 #include "content/child/site_isolation_policy.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 // doesn't use the contents of JS/CSS with unaffected status code | 110 // doesn't use the contents of JS/CSS with unaffected status code |
| 111 // (e.g, 404). 3) the renderer is expected not to use the cross-site | 111 // (e.g, 404). 3) the renderer is expected not to use the cross-site |
| 112 // document content for purposes other than JS/CSS (e.g, XHR). | 112 // document content for purposes other than JS/CSS (e.g, XHR). |
| 113 bool renderable_status_code = | 113 bool renderable_status_code = |
| 114 IsRenderableStatusCode(resp_data->http_status_code); | 114 IsRenderableStatusCode(resp_data->http_status_code); |
| 115 | 115 |
| 116 if (renderable_status_code) { | 116 if (renderable_status_code) { |
| 117 IncrementHistogramEnum( | 117 IncrementHistogramEnum( |
| 118 bucket_prefix + block_label + ".RenderableStatusCode", | 118 bucket_prefix + block_label + ".RenderableStatusCode", |
| 119 resp_data->resource_type, | 119 resp_data->resource_type, |
| 120 ResourceType::LAST_TYPE); | 120 RESOURCE_TYPE_LAST_TYPE); |
| 121 } else { | 121 } else { |
| 122 IncrementHistogramCount(bucket_prefix + block_label + | 122 IncrementHistogramCount(bucket_prefix + block_label + |
| 123 ".NonRenderableStatusCode"); | 123 ".NonRenderableStatusCode"); |
| 124 } | 124 } |
| 125 } | 125 } |
| 126 | 126 |
| 127 void HistogramCountNotBlockedResponse(const std::string& bucket_prefix, | 127 void HistogramCountNotBlockedResponse(const std::string& bucket_prefix, |
| 128 bool sniffed_as_js) { | 128 bool sniffed_as_js) { |
| 129 IncrementHistogramCount(bucket_prefix + ".NotBlocked"); | 129 IncrementHistogramCount(bucket_prefix + ".NotBlocked"); |
| 130 if (sniffed_as_js) | 130 if (sniffed_as_js) |
| 131 IncrementHistogramCount(bucket_prefix + ".NotBlocked.MaybeJS"); | 131 IncrementHistogramCount(bucket_prefix + ".NotBlocked.MaybeJS"); |
| 132 } | 132 } |
| 133 | 133 |
| 134 } // namespace | 134 } // namespace |
| 135 | 135 |
| 136 SiteIsolationResponseMetaData::SiteIsolationResponseMetaData() {} | 136 SiteIsolationResponseMetaData::SiteIsolationResponseMetaData() {} |
| 137 | 137 |
| 138 void SiteIsolationPolicy::SetPolicyEnabled(bool enabled) { | 138 void SiteIsolationPolicy::SetPolicyEnabled(bool enabled) { |
| 139 g_policy_enabled = enabled; | 139 g_policy_enabled = enabled; |
| 140 } | 140 } |
| 141 | 141 |
| 142 linked_ptr<SiteIsolationResponseMetaData> | 142 linked_ptr<SiteIsolationResponseMetaData> |
| 143 SiteIsolationPolicy::OnReceivedResponse(const GURL& frame_origin, | 143 SiteIsolationPolicy::OnReceivedResponse(const GURL& frame_origin, |
| 144 const GURL& response_url, | 144 const GURL& response_url, |
| 145 ResourceType::Type resource_type, | 145 ResourceType resource_type, |
| 146 int origin_pid, | 146 int origin_pid, |
| 147 const ResourceResponseInfo& info) { | 147 const ResourceResponseInfo& info) { |
| 148 if (!g_policy_enabled) | 148 if (!g_policy_enabled) |
| 149 return linked_ptr<SiteIsolationResponseMetaData>(); | 149 return linked_ptr<SiteIsolationResponseMetaData>(); |
| 150 | 150 |
| 151 // if |origin_pid| is non-zero, it means that this response is for a plugin | 151 // if |origin_pid| is non-zero, it means that this response is for a plugin |
| 152 // spawned from this renderer process. We exclude responses for plugins for | 152 // spawned from this renderer process. We exclude responses for plugins for |
| 153 // now, but eventually, we're going to make plugin processes directly talk to | 153 // now, but eventually, we're going to make plugin processes directly talk to |
| 154 // the browser process so that we don't apply cross-site document blocking to | 154 // the browser process so that we don't apply cross-site document blocking to |
| 155 // them. | 155 // them. |
| 156 if (origin_pid) | 156 if (origin_pid) |
| 157 return linked_ptr<SiteIsolationResponseMetaData>(); | 157 return linked_ptr<SiteIsolationResponseMetaData>(); |
| 158 | 158 |
| 159 UMA_HISTOGRAM_COUNTS("SiteIsolation.AllResponses", 1); | 159 UMA_HISTOGRAM_COUNTS("SiteIsolation.AllResponses", 1); |
| 160 | 160 |
| 161 // See if this is for navigation. If it is, don't block it, under the | 161 // See if this is for navigation. If it is, don't block it, under the |
| 162 // assumption that we will put it in an appropriate process. | 162 // assumption that we will put it in an appropriate process. |
| 163 if (ResourceType::IsFrame(resource_type)) | 163 if (IsResourceTypeFrame(resource_type)) |
| 164 return linked_ptr<SiteIsolationResponseMetaData>(); | 164 return linked_ptr<SiteIsolationResponseMetaData>(); |
| 165 | 165 |
| 166 if (!IsBlockableScheme(response_url)) | 166 if (!IsBlockableScheme(response_url)) |
| 167 return linked_ptr<SiteIsolationResponseMetaData>(); | 167 return linked_ptr<SiteIsolationResponseMetaData>(); |
| 168 | 168 |
| 169 if (IsSameSite(frame_origin, response_url)) | 169 if (IsSameSite(frame_origin, response_url)) |
| 170 return linked_ptr<SiteIsolationResponseMetaData>(); | 170 return linked_ptr<SiteIsolationResponseMetaData>(); |
| 171 | 171 |
| 172 SiteIsolationResponseMetaData::CanonicalMimeType canonical_mime_type = | 172 SiteIsolationResponseMetaData::CanonicalMimeType canonical_mime_type = |
| 173 GetCanonicalMimeType(info.mime_type); | 173 GetCanonicalMimeType(info.mime_type); |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 // TODO(dsjang): This is a real hack. The only purpose of this function is to | 504 // TODO(dsjang): This is a real hack. The only purpose of this function is to |
| 505 // try to see if there's any possibility that this data can be JavaScript | 505 // try to see if there's any possibility that this data can be JavaScript |
| 506 // (superset of JS). This function will be removed once UMA stats are | 506 // (superset of JS). This function will be removed once UMA stats are |
| 507 // gathered. | 507 // gathered. |
| 508 | 508 |
| 509 // Search for "var " for JS detection. | 509 // Search for "var " for JS detection. |
| 510 return data.find("var ") != base::StringPiece::npos; | 510 return data.find("var ") != base::StringPiece::npos; |
| 511 } | 511 } |
| 512 | 512 |
| 513 } // namespace content | 513 } // namespace content |
| OLD | NEW |