1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_CHILD_SITE_ISOLATION_STATS_GATHERER_H_
6 #define CONTENT_CHILD_SITE_ISOLATION_STATS_GATHERER_H_
10 #include "base/gtest_prod_util.h"
11 #include "base/memory/linked_ptr.h"
12 #include "base/strings/string_piece.h"
13 #include "content/common/content_export.h"
14 #include "content/common/cross_site_document_classifier.h"
15 #include "content/public/common/resource_type.h"
20 struct ResourceResponseInfo
;
22 // SiteIsolationStatsGatherer monitors responses to gather various UMA stats to
23 // see the compatibility impact of actual deployment of the policy. The UMA stat
24 // categories SiteIsolationStatsGatherer gathers are as follows:
26 // SiteIsolation.AllResponses : # of all network responses.
27 // SiteIsolation.XSD.DataLength : the length of the first packet of a response.
28 // SiteIsolation.XSD.MimeType (enum):
29 // # of responses from other sites, tagged with a document mime type.
30 // 0:HTML, 1:XML, 2:JSON, 3:Plain, 4:Others
31 // SiteIsolation.XSD.[%MIMETYPE].Blocked :
32 // blocked # of cross-site document responses grouped by sniffed MIME type.
33 // SiteIsolation.XSD.[%MIMETYPE].Blocked.RenderableStatusCode :
34 // # of responses with renderable status code,
35 // out of SiteIsolation.XSD.[%MIMETYPE].Blocked.
36 // SiteIsolation.XSD.[%MIMETYPE].Blocked.NonRenderableStatusCode :
37 // # of responses with non-renderable status code,
38 // out of SiteIsolation.XSD.[%MIMETYPE].Blocked.
39 // SiteIsolation.XSD.[%MIMETYPE].NoSniffBlocked.RenderableStatusCode :
40 // # of responses failed to be sniffed for its MIME type, but blocked by
41 // "X-Content-Type-Options: nosniff" header, and with renderable status code
42 // out of SiteIsolation.XSD.[%MIMETYPE].Blocked.
43 // SiteIsolation.XSD.[%MIMETYPE].NoSniffBlocked.NonRenderableStatusCode :
44 // # of responses failed to be sniffed for its MIME type, but blocked by
45 // "X-Content-Type-Options: nosniff" header, and with non-renderable status
46 // code out of SiteIsolation.XSD.[%MIMETYPE].Blocked.
47 // SiteIsolation.XSD.[%MIMETYPE].NotBlocked :
48 // # of responses, but not blocked due to failure of mime sniffing.
49 // SiteIsolation.XSD.[%MIMETYPE].NotBlocked.MaybeJS :
50 // # of responses that are plausibly sniffed to be JavaScript.
52 struct SiteIsolationResponseMetaData
{
53 SiteIsolationResponseMetaData();
55 std::string frame_origin
;
57 ResourceType resource_type
;
58 CrossSiteDocumentMimeType canonical_mime_type
;
63 class CONTENT_EXPORT SiteIsolationStatsGatherer
{
65 // Set activation flag for the UMA data collection for this renderer process.
66 static void SetEnabled(bool enabled
);
68 // Returns any bookkeeping data about the HTTP header information for the
69 // request identified by |request_id|. Any data returned should then be
70 // passed to OnReceivedFirstChunk() with the first data chunk.
71 static linked_ptr
<SiteIsolationResponseMetaData
> OnReceivedResponse(
72 const GURL
& frame_origin
,
73 const GURL
& response_url
,
74 ResourceType resource_type
,
76 const ResourceResponseInfo
& info
);
78 // Examines the first chunk of network data in case response_url is registered
79 // as a cross-site document by OnReceivedResponse(). This records various
80 // kinds of UMA data stats. This function is called only if the length of
81 // received data is non-zero.
82 static bool OnReceivedFirstChunk(
83 const linked_ptr
<SiteIsolationResponseMetaData
>& resp_data
,
88 FRIEND_TEST_ALL_PREFIXES(SiteIsolationStatsGathererTest
, SniffForJS
);
90 SiteIsolationStatsGatherer(); // Not instantiable.
92 // Imprecise JS sniffing; only appropriate for collecting UMA stat.
93 static bool SniffForJS(base::StringPiece data
);
95 DISALLOW_COPY_AND_ASSIGN(SiteIsolationStatsGatherer
);
98 } // namespace content
100 #endif // CONTENT_CHILD_SITE_ISOLATION_STATS_GATHERER_H_