| 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/metrics/user_metrics_action.h" | 11 #include "base/metrics/user_metrics_action.h" |
| 11 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 12 #include "chrome/browser/permissions/permission_request.h" | 13 #include "chrome/browser/permissions/permission_request.h" |
| 13 #include "chrome/browser/permissions/permission_uma_util.h" | 14 #include "chrome/browser/permissions/permission_uma_util.h" |
| 15 #include "chrome/browser/ui/website_settings/permission_prompt.h" |
| 16 #include "chrome/common/chrome_features.h" |
| 14 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 15 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/navigation_details.h" | 19 #include "content/public/browser/navigation_details.h" |
| 17 #include "content/public/browser/user_metrics.h" | 20 #include "content/public/browser/user_metrics.h" |
| 18 #include "url/origin.h" | 21 #include "url/origin.h" |
| 19 | 22 |
| 20 namespace { | 23 namespace { |
| 21 | 24 |
| 22 class CancelledRequest : public PermissionRequest { | 25 class CancelledRequest : public PermissionRequest { |
| 23 public: | 26 public: |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 void PermissionRequestManager::Observer::OnBubbleAdded() { | 70 void PermissionRequestManager::Observer::OnBubbleAdded() { |
| 68 } | 71 } |
| 69 | 72 |
| 70 // PermissionRequestManager ---------------------------------------------------- | 73 // PermissionRequestManager ---------------------------------------------------- |
| 71 | 74 |
| 72 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PermissionRequestManager); | 75 DEFINE_WEB_CONTENTS_USER_DATA_KEY(PermissionRequestManager); |
| 73 | 76 |
| 74 PermissionRequestManager::PermissionRequestManager( | 77 PermissionRequestManager::PermissionRequestManager( |
| 75 content::WebContents* web_contents) | 78 content::WebContents* web_contents) |
| 76 : content::WebContentsObserver(web_contents), | 79 : content::WebContentsObserver(web_contents), |
| 77 #if !defined(OS_ANDROID) // No bubbles in android tests. | |
| 78 view_factory_(base::Bind(&PermissionPrompt::Create)), | 80 view_factory_(base::Bind(&PermissionPrompt::Create)), |
| 79 #endif | |
| 80 view_(nullptr), | 81 view_(nullptr), |
| 81 main_frame_has_fully_loaded_(false), | 82 main_frame_has_fully_loaded_(false), |
| 82 persist_(true), | 83 persist_(true), |
| 83 auto_response_for_test_(NONE), | 84 auto_response_for_test_(NONE), |
| 84 weak_factory_(this) { | 85 weak_factory_(this) {} |
| 85 } | |
| 86 | 86 |
| 87 PermissionRequestManager::~PermissionRequestManager() { | 87 PermissionRequestManager::~PermissionRequestManager() { |
| 88 if (view_ != NULL) | 88 if (view_ != NULL) |
| 89 view_->SetDelegate(NULL); | 89 view_->SetDelegate(NULL); |
| 90 | 90 |
| 91 for (PermissionRequest* request : requests_) | 91 for (PermissionRequest* request : requests_) |
| 92 request->RequestFinished(); | 92 request->RequestFinished(); |
| 93 for (PermissionRequest* request : queued_requests_) | 93 for (PermissionRequest* request : queued_requests_) |
| 94 request->RequestFinished(); | 94 request->RequestFinished(); |
| 95 for (PermissionRequest* request : queued_frame_requests_) | 95 for (PermissionRequest* request : queued_frame_requests_) |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 | 230 |
| 231 view_->SetDelegate(nullptr); | 231 view_->SetDelegate(nullptr); |
| 232 view_->Hide(); | 232 view_->Hide(); |
| 233 view_.reset(); | 233 view_.reset(); |
| 234 } | 234 } |
| 235 | 235 |
| 236 void PermissionRequestManager::DisplayPendingRequests() { | 236 void PermissionRequestManager::DisplayPendingRequests() { |
| 237 if (IsBubbleVisible()) | 237 if (IsBubbleVisible()) |
| 238 return; | 238 return; |
| 239 | 239 |
| 240 #if defined(OS_ANDROID) | |
| 241 NOTREACHED(); | |
| 242 return; | |
| 243 #else | |
| 244 view_ = view_factory_.Run(web_contents()); | 240 view_ = view_factory_.Run(web_contents()); |
| 245 view_->SetDelegate(this); | 241 view_->SetDelegate(this); |
| 246 #endif | |
| 247 | 242 |
| 248 TriggerShowBubble(); | 243 TriggerShowBubble(); |
| 249 } | 244 } |
| 250 | 245 |
| 251 void PermissionRequestManager::UpdateAnchorPosition() { | 246 void PermissionRequestManager::UpdateAnchorPosition() { |
| 252 if (view_) | 247 if (view_) |
| 253 view_->UpdateAnchorPosition(); | 248 view_->UpdateAnchorPosition(); |
| 254 } | 249 } |
| 255 | 250 |
| 256 bool PermissionRequestManager::IsBubbleVisible() { | 251 bool PermissionRequestManager::IsBubbleVisible() { |
| 257 return view_ && view_->IsVisible(); | 252 return view_ && view_->IsVisible(); |
| 258 } | 253 } |
| 259 | 254 |
| 255 // static |
| 256 bool PermissionRequestManager::IsEnabled() { |
| 257 #if defined(OS_ANDROID) |
| 258 return base::FeatureList::IsEnabled(features::kUseGroupedPermissionInfobars); |
| 259 #else |
| 260 return true; |
| 261 #endif |
| 262 } |
| 263 |
| 260 gfx::NativeWindow PermissionRequestManager::GetBubbleWindow() { | 264 gfx::NativeWindow PermissionRequestManager::GetBubbleWindow() { |
| 261 if (view_) | 265 if (view_) |
| 262 return view_->GetNativeWindow(); | 266 return view_->GetNativeWindow(); |
| 263 return nullptr; | 267 return nullptr; |
| 264 } | 268 } |
| 265 | 269 |
| 266 void PermissionRequestManager::DidNavigateMainFrame( | 270 void PermissionRequestManager::DidNavigateMainFrame( |
| 267 const content::LoadCommittedDetails& details, | 271 const content::LoadCommittedDetails& details, |
| 268 const content::FrameNavigateParams& params) { | 272 const content::FrameNavigateParams& params) { |
| 269 if (details.is_in_page) | 273 if (details.is_in_page) |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 case DENY_ALL: | 518 case DENY_ALL: |
| 515 Deny(); | 519 Deny(); |
| 516 break; | 520 break; |
| 517 case DISMISS: | 521 case DISMISS: |
| 518 Closing(); | 522 Closing(); |
| 519 break; | 523 break; |
| 520 case NONE: | 524 case NONE: |
| 521 NOTREACHED(); | 525 NOTREACHED(); |
| 522 } | 526 } |
| 523 } | 527 } |
| OLD | NEW |