Chromium Code Reviews| 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 "chrome/browser/safe_browsing/permission_reporter.h" | 5 #include "chrome/browser/safe_browsing/permission_reporter.h" |
| 6 #include "chrome/common/safe_browsing/permission_report.pb.h" | 6 #include "chrome/common/safe_browsing/permission_report.pb.h" |
| 7 #include "content/public/browser/permission_type.h" | 7 #include "content/public/browser/permission_type.h" |
| 8 #include "net/url_request/report_sender.h" | |
| 8 | 9 |
| 9 using content::PermissionType; | 10 using content::PermissionType; |
| 10 | 11 |
| 11 namespace safe_browsing { | 12 namespace safe_browsing { |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 // URL to upload permission action reports. | 15 // URL to upload permission action reports. |
| 15 const char kPermissionActionReportingUploadUrl[] = | 16 const char kPermissionActionReportingUploadUrl[] = |
| 16 "http://safebrowsing.googleusercontent.com/safebrowsing/clientreport/" | 17 "http://safebrowsing.googleusercontent.com/safebrowsing/clientreport/" |
| 17 "permission-action"; | 18 "permission-action"; |
| 19 | |
| 20 PermissionReport::PermissionType PermissionTypeToPermissionReportPermission( | |
|
Nathan Parker
2016/06/20 16:10:09
wholey smokes that's a lot of Permissions. Could t
stefanocs
2016/06/21 03:26:53
Done.
| |
| 21 PermissionType permission) { | |
| 22 switch (permission) { | |
| 23 case PermissionType::MIDI_SYSEX: | |
| 24 return PermissionReport::MIDI_SYSEX; | |
| 25 case PermissionType::PUSH_MESSAGING: | |
| 26 return PermissionReport::PUSH_MESSAGING; | |
| 27 case PermissionType::NOTIFICATIONS: | |
| 28 return PermissionReport::NOTIFICATIONS; | |
| 29 case PermissionType::GEOLOCATION: | |
| 30 return PermissionReport::GEOLOCATION; | |
| 31 case PermissionType::PROTECTED_MEDIA_IDENTIFIER: | |
| 32 return PermissionReport::PROTECTED_MEDIA_IDENTIFIER; | |
| 33 case PermissionType::MIDI: | |
| 34 return PermissionReport::MIDI; | |
| 35 case PermissionType::DURABLE_STORAGE: | |
| 36 return PermissionReport::DURABLE_STORAGE; | |
| 37 case PermissionType::AUDIO_CAPTURE: | |
| 38 return PermissionReport::AUDIO_CAPTURE; | |
| 39 case PermissionType::VIDEO_CAPTURE: | |
| 40 return PermissionReport::VIDEO_CAPTURE; | |
| 41 case PermissionType::BACKGROUND_SYNC: | |
| 42 return PermissionReport::UNKNOWN_PERMISSION; | |
| 43 case PermissionType::NUM: | |
| 44 break; | |
| 45 } | |
| 46 | |
| 47 NOTREACHED(); | |
| 48 return PermissionReport::UNKNOWN_PERMISSION; | |
| 49 } | |
| 50 | |
| 51 PermissionReport::Action PermissionActionToPermissionReportAction( | |
| 52 PermissionAction action) { | |
| 53 switch (action) { | |
| 54 case GRANTED: | |
| 55 return PermissionReport::GRANTED; | |
| 56 case DENIED: | |
| 57 return PermissionReport::DENIED; | |
| 58 case DISMISSED: | |
| 59 return PermissionReport::DISMISSED; | |
| 60 case IGNORED: | |
| 61 return PermissionReport::IGNORED; | |
| 62 case REVOKED: | |
| 63 return PermissionReport::REVOKED; | |
| 64 case REENABLED: | |
| 65 case REQUESTED: | |
| 66 return PermissionReport::ACTION_UNSPECIFIED; | |
| 67 case PERMISSION_ACTION_NUM: | |
| 68 break; | |
| 69 } | |
| 70 | |
| 71 NOTREACHED(); | |
| 72 return PermissionReport::ACTION_UNSPECIFIED; | |
| 73 } | |
| 74 | |
| 18 } // namespace | 75 } // namespace |
| 19 | 76 |
| 77 PermissionReporter::PermissionReporter(net::URLRequestContext* request_context) | |
| 78 : permission_report_sender_(new net::ReportSender( | |
|
Nathan Parker
2016/06/20 16:10:09
nit: This could call the constructor below. That
stefanocs
2016/06/21 03:26:53
Done.
| |
| 79 request_context, | |
| 80 net::ReportSender::CookiesPreference::DO_NOT_SEND_COOKIES)) {} | |
| 81 | |
| 20 PermissionReporter::PermissionReporter( | 82 PermissionReporter::PermissionReporter( |
| 21 net::URLRequestContext* request_context) {} | 83 std::unique_ptr<net::ReportSender> report_sender) |
| 84 : permission_report_sender_(std::move(report_sender)) {} | |
| 22 | 85 |
| 23 PermissionReporter::~PermissionReporter() {} | 86 PermissionReporter::~PermissionReporter() {} |
| 24 | 87 |
| 25 void PermissionReporter::SendReport(const GURL& origin, | 88 void PermissionReporter::SendReport(const GURL& origin, |
| 26 content::PermissionType permission, | 89 content::PermissionType permission, |
| 27 PermissionAction action) { | 90 PermissionAction action) { |
| 28 // TODO(stefanocs): Implement SendReport function. | 91 std::string serialized_report; |
| 29 ALLOW_UNUSED_LOCAL(kPermissionActionReportingUploadUrl); | 92 BuildReport(origin, permission, action, &serialized_report); |
| 93 permission_report_sender_->Send(GURL(kPermissionActionReportingUploadUrl), | |
| 94 serialized_report); | |
| 30 } | 95 } |
| 31 | 96 |
| 32 // static | 97 // static |
| 33 bool PermissionReporter::BuildReport(const GURL& origin, | 98 bool PermissionReporter::BuildReport(const GURL& origin, |
| 34 PermissionType permission, | 99 PermissionType permission, |
| 35 PermissionAction action, | 100 PermissionAction action, |
| 36 std::string* output) { | 101 std::string* output) { |
| 37 // TODO(stefanocs): Implement BuildReport function. | 102 PermissionReport report; |
| 38 return true; | 103 report.set_origin(origin.spec()); |
| 104 report.set_permission(PermissionTypeToPermissionReportPermission(permission)); | |
| 105 report.set_action(PermissionActionToPermissionReportAction(action)); | |
| 106 // TODO(stefanocs): Collect other data for the report from global variables. | |
|
Nathan Parker
2016/06/20 16:10:09
What other data do you need? You could list them
stefanocs
2016/06/21 03:26:53
Done.
| |
| 107 return report.SerializeToString(output); | |
| 39 } | 108 } |
| 40 | 109 |
| 41 } // namespace safe_browsing | 110 } // namespace safe_browsing |
| OLD | NEW |