Chromium Code Reviews| Index: chrome/browser/services/gcm/permission_context_base.cc |
| diff --git a/chrome/browser/services/gcm/permission_context_base.cc b/chrome/browser/services/gcm/permission_context_base.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8978350a64fe92440850e3e38bd16d32dbc7bd84 |
| --- /dev/null |
| +++ b/chrome/browser/services/gcm/permission_context_base.cc |
| @@ -0,0 +1,110 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/services/gcm/permission_context_base.h" |
| + |
| +#include "chrome/browser/content_settings/host_content_settings_map.h" |
| +#include "chrome/browser/content_settings/permission_queue_controller.h" |
| +#include "chrome/browser/content_settings/permission_request_id.h" |
| +#include "chrome/browser/content_settings/tab_specific_content_settings.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "content/public/browser/web_contents.h" |
| + |
| +namespace gcm { |
| + |
| +PermissionContextBase::PermissionContextBase( |
| + Profile* profile, |
| + const ContentSettingsType permission_type) |
| + : profile_(profile), permission_type_(permission_type) { |
| +} |
| + |
| +PermissionContextBase::~PermissionContextBase() { |
| + DCHECK(!permission_queue_controller_); |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| +} |
| + |
| +void PermissionContextBase::RequestPermission( |
|
Michael van Ouwerkerk
2014/06/19 10:16:11
Let's add a TODO for doing full UMA instrumentatio
Miguel Garcia
2014/06/19 17:49:28
It's actually a pretty neat idea to do it here, th
|
| + content::WebContents* web_contents, |
| + const PermissionRequestID& id, |
| + const GURL& requesting_frame, |
| + bool user_gesture, |
| + const base::Callback<void(bool)> callback) { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + |
| + DecidePermission(web_contents, |
| + id, |
| + requesting_frame, |
| + requesting_frame, |
| + user_gesture, |
| + callback); |
| +} |
| + |
| +void PermissionContextBase::DecidePermission( |
| + content::WebContents* web_contents, |
| + const PermissionRequestID& id, |
| + const GURL& requesting_frame, |
| + const GURL& embedder, |
| + bool user_gesture, |
| + const BrowserPermissionCallback& callback) { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + |
| + ContentSetting content_setting = |
| + profile_->GetHostContentSettingsMap()->GetContentSetting( |
| + requesting_frame, embedder, permission_type_, std::string()); |
| + switch (content_setting) { |
| + case CONTENT_SETTING_BLOCK: |
| + PermissionDecided(id, requesting_frame, embedder, callback, false); |
| + break; |
| + case CONTENT_SETTING_ALLOW: |
| + PermissionDecided(id, requesting_frame, embedder, callback, true); |
| + break; |
| + default: |
| + // TODO(miguelg) implement bubble support |
| + |
| + // TODO(gbillock): Delete this and the infobar delegate when |
| + // we're using only bubbles. crbug.com/337458 |
| + GetQueueController()->CreateInfoBarRequest( |
| + id, |
| + requesting_frame, |
| + embedder, |
| + std::string(), |
| + base::Bind(&PermissionContextBase::NotifyPermissionSet, |
| + base::Unretained(this), |
| + id, |
| + requesting_frame, |
| + callback)); |
| + } |
| +} |
| + |
| +void PermissionContextBase::PermissionDecided( |
| + const PermissionRequestID& id, |
| + const GURL& requesting_frame, |
| + const GURL& embedder, |
| + const BrowserPermissionCallback& callback, |
| + bool allowed) { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + NotifyPermissionSet(id, requesting_frame, callback, allowed); |
| +} |
| + |
| +PermissionQueueController* PermissionContextBase::GetQueueController() { |
| + if (!permission_queue_controller_) { |
| + permission_queue_controller_.reset( |
| + new PermissionQueueController(profile_, permission_type_)); |
| + } |
| + return permission_queue_controller_.get(); |
| +} |
| + |
| +void PermissionContextBase::NotifyPermissionSet( |
| + const PermissionRequestID& id, |
| + const GURL& requesting_frame, |
| + const BrowserPermissionCallback& callback, |
| + bool allowed) { |
| + DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| + UpdateTabContext(id, requesting_frame, allowed); |
| + |
| + callback.Run(allowed); |
| +} |
| + |
| +} // namespace gcm |