Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/permissions/permission_request_manager.h" | 5 #include "chrome/browser/permissions/permission_request_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/feature_list.h" | 10 #include "base/feature_list.h" |
| 11 #include "base/metrics/user_metrics.h" | 11 #include "base/metrics/user_metrics.h" |
| 12 #include "base/metrics/user_metrics_action.h" | 12 #include "base/metrics/user_metrics_action.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "chrome/browser/permissions/permission_request.h" | 14 #include "chrome/browser/permissions/permission_request.h" |
| 15 #include "chrome/browser/permissions/permission_uma_util.h" | 15 #include "chrome/browser/permissions/permission_uma_util.h" |
| 16 #include "chrome/browser/ui/permission_bubble/permission_prompt.h" | 16 #include "chrome/browser/ui/permission_bubble/permission_prompt.h" |
| 17 #include "chrome/common/chrome_features.h" | 17 #include "chrome/common/chrome_features.h" |
| 18 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/navigation_handle.h" | 20 #include "content/public/browser/navigation_handle.h" |
| 21 #include "device/vr/features/features.h" | |
| 21 #include "url/origin.h" | 22 #include "url/origin.h" |
| 22 | 23 |
| 24 #if BUILDFLAG(ENABLE_VR) && defined(OS_ANDROID) | |
| 25 #include "chrome/browser/android/vr_shell/vr_tab_helper.h" | |
| 26 #endif // BUILDFLAG(ENABLE_VR) && defined(OS_ANDROID) | |
| 27 | |
| 23 namespace { | 28 namespace { |
| 24 | 29 |
| 25 class CancelledRequest : public PermissionRequest { | 30 class CancelledRequest : public PermissionRequest { |
| 26 public: | 31 public: |
| 27 explicit CancelledRequest(PermissionRequest* cancelled) | 32 explicit CancelledRequest(PermissionRequest* cancelled) |
| 28 : icon_(cancelled->GetIconId()), | 33 : icon_(cancelled->GetIconId()), |
| 29 #if defined(OS_ANDROID) | 34 #if defined(OS_ANDROID) |
| 30 message_(cancelled->GetMessageText()), | 35 message_(cancelled->GetMessageText()), |
| 31 #endif | 36 #endif |
| 32 message_fragment_(cancelled->GetMessageTextFragment()), | 37 message_fragment_(cancelled->GetMessageTextFragment()), |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 for (PermissionRequest* request : queued_requests_) | 134 for (PermissionRequest* request : queued_requests_) |
| 130 request->RequestFinished(); | 135 request->RequestFinished(); |
| 131 for (const auto& entry : duplicate_requests_) | 136 for (const auto& entry : duplicate_requests_) |
| 132 entry.second->RequestFinished(); | 137 entry.second->RequestFinished(); |
| 133 } | 138 } |
| 134 | 139 |
| 135 void PermissionRequestManager::AddRequest(PermissionRequest* request) { | 140 void PermissionRequestManager::AddRequest(PermissionRequest* request) { |
| 136 // TODO(tsergeant): change the UMA to no longer mention bubbles. | 141 // TODO(tsergeant): change the UMA to no longer mention bubbles. |
| 137 base::RecordAction(base::UserMetricsAction("PermissionBubbleRequest")); | 142 base::RecordAction(base::UserMetricsAction("PermissionBubbleRequest")); |
| 138 | 143 |
| 144 if (PermissionRequestsDisabled()) { | |
| 145 request->PermissionDenied(); | |
|
raymes
2017/07/11 01:43:23
nit: you may want to change this to Cancelled() si
raymes
2017/07/11 01:44:37
Ignore this - after I thought through it more I th
| |
| 146 request->RequestFinished(); | |
| 147 return; | |
| 148 } | |
| 149 | |
| 139 // TODO(gbillock): is there a race between an early request on a | 150 // TODO(gbillock): is there a race between an early request on a |
| 140 // newly-navigated page and the to-be-cleaned-up requests on the previous | 151 // newly-navigated page and the to-be-cleaned-up requests on the previous |
| 141 // page? We should maybe listen to DidStartNavigationToPendingEntry (and | 152 // page? We should maybe listen to DidStartNavigationToPendingEntry (and |
| 142 // any other renderer-side nav initiations?). Double-check this for | 153 // any other renderer-side nav initiations?). Double-check this for |
| 143 // correct behavior on interstitials -- we probably want to basically queue | 154 // correct behavior on interstitials -- we probably want to basically queue |
| 144 // any request for which GetVisibleURL != GetLastCommittedURL. | 155 // any request for which GetVisibleURL != GetLastCommittedURL. |
| 145 const GURL& request_url_ = web_contents()->GetLastCommittedURL(); | 156 const GURL& request_url_ = web_contents()->GetLastCommittedURL(); |
| 146 bool is_main_frame = url::Origin(request_url_) | 157 bool is_main_frame = url::Origin(request_url_) |
| 147 .IsSameOriginWith(url::Origin(request->GetOrigin())); | 158 .IsSameOriginWith(url::Origin(request->GetOrigin())); |
| 148 | 159 |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 526 case DENY_ALL: | 537 case DENY_ALL: |
| 527 Deny(); | 538 Deny(); |
| 528 break; | 539 break; |
| 529 case DISMISS: | 540 case DISMISS: |
| 530 Closing(); | 541 Closing(); |
| 531 break; | 542 break; |
| 532 case NONE: | 543 case NONE: |
| 533 NOTREACHED(); | 544 NOTREACHED(); |
| 534 } | 545 } |
| 535 } | 546 } |
| 547 | |
| 548 bool PermissionRequestManager::PermissionRequestsDisabled() const { | |
| 549 #if BUILDFLAG(ENABLE_VR) && defined(OS_ANDROID) | |
| 550 return vr_shell::VrTabHelper::IsInVr(web_contents()); | |
| 551 #else | |
| 552 return false; | |
| 553 #endif | |
| 554 } | |
| OLD | NEW |