OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "base/memory/ptr_util.h" | 5 #include "base/memory/ptr_util.h" |
6 #include "chrome/browser/safe_browsing/permission_reporter.h" | 6 #include "chrome/browser/safe_browsing/permission_reporter.h" |
7 #include "chrome/common/safe_browsing/permission_report.pb.h" | 7 #include "chrome/common/safe_browsing/permission_report.pb.h" |
8 #include "components/variations/active_field_trials.h" | 8 #include "components/variations/active_field_trials.h" |
9 #include "content/public/browser/permission_type.h" | 9 #include "content/public/browser/permission_type.h" |
10 #include "net/url_request/report_sender.h" | 10 #include "net/url_request/report_sender.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 case REQUESTED: | 66 case REQUESTED: |
67 return PermissionReport::ACTION_UNSPECIFIED; | 67 return PermissionReport::ACTION_UNSPECIFIED; |
68 case PERMISSION_ACTION_NUM: | 68 case PERMISSION_ACTION_NUM: |
69 break; | 69 break; |
70 } | 70 } |
71 | 71 |
72 NOTREACHED(); | 72 NOTREACHED(); |
73 return PermissionReport::ACTION_UNSPECIFIED; | 73 return PermissionReport::ACTION_UNSPECIFIED; |
74 } | 74 } |
75 | 75 |
| 76 PermissionReport::SourceUI SourceUIToPermissionReportSourceUI( |
| 77 SourceUI source_ui) { |
| 78 switch (source_ui) { |
| 79 case PROMPT: |
| 80 return PermissionReport::PROMPT; |
| 81 case OIB: |
| 82 return PermissionReport::OIB; |
| 83 case SITE_SETTINGS: |
| 84 return PermissionReport::SITE_SETTINGS; |
| 85 case PAGE_ACTION: |
| 86 return PermissionReport::PAGE_ACTION; |
| 87 case SOURCE_UI_NUM: |
| 88 break; |
| 89 } |
| 90 |
| 91 NOTREACHED(); |
| 92 return PermissionReport::SOURCE_UI_UNSPECIFIED; |
| 93 } |
| 94 |
76 } // namespace | 95 } // namespace |
77 | 96 |
78 PermissionReporter::PermissionReporter(net::URLRequestContext* request_context) | 97 PermissionReporter::PermissionReporter(net::URLRequestContext* request_context) |
79 : PermissionReporter(base::WrapUnique(new net::ReportSender( | 98 : PermissionReporter(base::WrapUnique(new net::ReportSender( |
80 request_context, | 99 request_context, |
81 net::ReportSender::CookiesPreference::DO_NOT_SEND_COOKIES))) {} | 100 net::ReportSender::CookiesPreference::DO_NOT_SEND_COOKIES))) {} |
82 | 101 |
83 PermissionReporter::PermissionReporter( | 102 PermissionReporter::PermissionReporter( |
84 std::unique_ptr<net::ReportSender> report_sender) | 103 std::unique_ptr<net::ReportSender> report_sender) |
85 : permission_report_sender_(std::move(report_sender)) {} | 104 : permission_report_sender_(std::move(report_sender)) {} |
86 | 105 |
87 PermissionReporter::~PermissionReporter() {} | 106 PermissionReporter::~PermissionReporter() {} |
88 | 107 |
89 void PermissionReporter::SendReport(const GURL& origin, | 108 void PermissionReporter::SendReport(const GURL& origin, |
90 content::PermissionType permission, | 109 content::PermissionType permission, |
91 PermissionAction action) { | 110 PermissionAction action, |
| 111 SourceUI source_ui) { |
92 std::string serialized_report; | 112 std::string serialized_report; |
93 BuildReport(origin, permission, action, &serialized_report); | 113 BuildReport(origin, permission, action, source_ui, &serialized_report); |
94 permission_report_sender_->Send(GURL(kPermissionActionReportingUploadUrl), | 114 permission_report_sender_->Send(GURL(kPermissionActionReportingUploadUrl), |
95 serialized_report); | 115 serialized_report); |
96 } | 116 } |
97 | 117 |
98 // static | 118 // static |
99 bool PermissionReporter::BuildReport(const GURL& origin, | 119 bool PermissionReporter::BuildReport(const GURL& origin, |
100 PermissionType permission, | 120 PermissionType permission, |
101 PermissionAction action, | 121 PermissionAction action, |
| 122 SourceUI source_ui, |
102 std::string* output) { | 123 std::string* output) { |
103 PermissionReport report; | 124 PermissionReport report; |
104 report.set_origin(origin.spec()); | 125 report.set_origin(origin.spec()); |
105 report.set_permission(PermissionTypeForReport(permission)); | 126 report.set_permission(PermissionTypeForReport(permission)); |
106 report.set_action(PermissionActionForReport(action)); | 127 report.set_action(PermissionActionForReport(action)); |
| 128 report.set_source_ui(SourceUIToPermissionReportSourceUI(source_ui)); |
107 | 129 |
108 // Collect platform data. | 130 // Collect platform data. |
109 #if defined(OS_ANDROID) | 131 #if defined(OS_ANDROID) |
110 report.set_platform_type(PermissionReport::ANDROID_PLATFORM); | 132 report.set_platform_type(PermissionReport::ANDROID_PLATFORM); |
111 #elif defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_CHROMEOS) || \ | 133 #elif defined(OS_MACOSX) || defined(OS_WIN) || defined(OS_CHROMEOS) || \ |
112 defined(OS_LINUX) | 134 defined(OS_LINUX) |
113 report.set_platform_type(PermissionReport::DESKTOP_PLATFORM); | 135 report.set_platform_type(PermissionReport::DESKTOP_PLATFORM); |
114 #else | 136 #else |
115 #error Unsupported platform. | 137 #error Unsupported platform. |
116 #endif | 138 #endif |
117 | 139 |
118 // Collect field trial data. | 140 // Collect field trial data. |
119 std::vector<variations::ActiveGroupId> active_group_ids; | 141 std::vector<variations::ActiveGroupId> active_group_ids; |
120 variations::GetFieldTrialActiveGroupIds(&active_group_ids); | 142 variations::GetFieldTrialActiveGroupIds(&active_group_ids); |
121 for (auto active_group_id : active_group_ids) { | 143 for (auto active_group_id : active_group_ids) { |
122 PermissionReport::FieldTrial* field_trial = report.add_field_trials(); | 144 PermissionReport::FieldTrial* field_trial = report.add_field_trials(); |
123 field_trial->set_name_id(active_group_id.name); | 145 field_trial->set_name_id(active_group_id.name); |
124 field_trial->set_group_id(active_group_id.group); | 146 field_trial->set_group_id(active_group_id.group); |
125 } | 147 } |
126 return report.SerializeToString(output); | 148 return report.SerializeToString(output); |
127 } | 149 } |
128 | 150 |
129 } // namespace safe_browsing | 151 } // namespace safe_browsing |
OLD | NEW |