| 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 "chrome/browser/safe_browsing/permission_reporter.h" | 6 #include "chrome/browser/safe_browsing/permission_reporter.h" |
| 6 #include "chrome/common/safe_browsing/permission_report.pb.h" | 7 #include "chrome/common/safe_browsing/permission_report.pb.h" |
| 7 #include "content/public/browser/permission_type.h" | 8 #include "content/public/browser/permission_type.h" |
| 9 #include "net/url_request/report_sender.h" |
| 8 | 10 |
| 9 using content::PermissionType; | 11 using content::PermissionType; |
| 10 | 12 |
| 11 namespace safe_browsing { | 13 namespace safe_browsing { |
| 12 | 14 |
| 13 namespace { | 15 namespace { |
| 14 // URL to upload permission action reports. | 16 // URL to upload permission action reports. |
| 15 const char kPermissionActionReportingUploadUrl[] = | 17 const char kPermissionActionReportingUploadUrl[] = |
| 16 "http://safebrowsing.googleusercontent.com/safebrowsing/clientreport/" | 18 "http://safebrowsing.googleusercontent.com/safebrowsing/clientreport/" |
| 17 "permission-action"; | 19 "permission-action"; |
| 20 |
| 21 PermissionReport::PermissionType PermissionTypeForReport( |
| 22 PermissionType permission) { |
| 23 switch (permission) { |
| 24 case PermissionType::MIDI_SYSEX: |
| 25 return PermissionReport::MIDI_SYSEX; |
| 26 case PermissionType::PUSH_MESSAGING: |
| 27 return PermissionReport::PUSH_MESSAGING; |
| 28 case PermissionType::NOTIFICATIONS: |
| 29 return PermissionReport::NOTIFICATIONS; |
| 30 case PermissionType::GEOLOCATION: |
| 31 return PermissionReport::GEOLOCATION; |
| 32 case PermissionType::PROTECTED_MEDIA_IDENTIFIER: |
| 33 return PermissionReport::PROTECTED_MEDIA_IDENTIFIER; |
| 34 case PermissionType::MIDI: |
| 35 return PermissionReport::MIDI; |
| 36 case PermissionType::DURABLE_STORAGE: |
| 37 return PermissionReport::DURABLE_STORAGE; |
| 38 case PermissionType::AUDIO_CAPTURE: |
| 39 return PermissionReport::AUDIO_CAPTURE; |
| 40 case PermissionType::VIDEO_CAPTURE: |
| 41 return PermissionReport::VIDEO_CAPTURE; |
| 42 case PermissionType::BACKGROUND_SYNC: |
| 43 return PermissionReport::UNKNOWN_PERMISSION; |
| 44 case PermissionType::NUM: |
| 45 break; |
| 46 } |
| 47 |
| 48 NOTREACHED(); |
| 49 return PermissionReport::UNKNOWN_PERMISSION; |
| 50 } |
| 51 |
| 52 PermissionReport::Action PermissionActionForReport(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 : PermissionReporter(base::WrapUnique(new net::ReportSender( |
| 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(PermissionTypeForReport(permission)); |
| 105 report.set_action(PermissionActionForReport(action)); |
| 106 // TODO(stefanocs): Collect field trials and platform type from global |
| 107 // variables to the permission report. |
| 108 return report.SerializeToString(output); |
| 39 } | 109 } |
| 40 | 110 |
| 41 } // namespace safe_browsing | 111 } // namespace safe_browsing |
| OLD | NEW |