Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/services/gcm/permission_context_base.h" | |
| 6 | |
| 7 #include "chrome/browser/content_settings/host_content_settings_map.h" | |
| 8 #include "chrome/browser/content_settings/permission_queue_controller.h" | |
| 9 #include "chrome/browser/content_settings/permission_request_id.h" | |
| 10 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | |
| 11 #include "chrome/browser/profiles/profile.h" | |
| 12 #include "content/public/browser/browser_thread.h" | |
| 13 #include "content/public/browser/web_contents.h" | |
| 14 | |
| 15 namespace gcm { | |
| 16 | |
| 17 PermissionContextBase::PermissionContextBase( | |
| 18 Profile* profile, | |
| 19 const ContentSettingsType permission_type) | |
| 20 : profile_(profile), permission_type_(permission_type) { | |
| 21 } | |
| 22 | |
| 23 PermissionContextBase::~PermissionContextBase() { | |
| 24 DCHECK(!permission_queue_controller_); | |
| 25 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 26 } | |
| 27 | |
| 28 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
| |
| 29 content::WebContents* web_contents, | |
| 30 const PermissionRequestID& id, | |
| 31 const GURL& requesting_frame, | |
| 32 bool user_gesture, | |
| 33 const base::Callback<void(bool)> callback) { | |
| 34 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 35 | |
| 36 DecidePermission(web_contents, | |
| 37 id, | |
| 38 requesting_frame, | |
| 39 requesting_frame, | |
| 40 user_gesture, | |
| 41 callback); | |
| 42 } | |
| 43 | |
| 44 void PermissionContextBase::DecidePermission( | |
| 45 content::WebContents* web_contents, | |
| 46 const PermissionRequestID& id, | |
| 47 const GURL& requesting_frame, | |
| 48 const GURL& embedder, | |
| 49 bool user_gesture, | |
| 50 const BrowserPermissionCallback& callback) { | |
| 51 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 52 | |
| 53 ContentSetting content_setting = | |
| 54 profile_->GetHostContentSettingsMap()->GetContentSetting( | |
| 55 requesting_frame, embedder, permission_type_, std::string()); | |
| 56 switch (content_setting) { | |
| 57 case CONTENT_SETTING_BLOCK: | |
| 58 PermissionDecided(id, requesting_frame, embedder, callback, false); | |
| 59 break; | |
| 60 case CONTENT_SETTING_ALLOW: | |
| 61 PermissionDecided(id, requesting_frame, embedder, callback, true); | |
| 62 break; | |
| 63 default: | |
| 64 // TODO(miguelg) implement bubble support | |
| 65 | |
| 66 // TODO(gbillock): Delete this and the infobar delegate when | |
| 67 // we're using only bubbles. crbug.com/337458 | |
| 68 GetQueueController()->CreateInfoBarRequest( | |
| 69 id, | |
| 70 requesting_frame, | |
| 71 embedder, | |
| 72 std::string(), | |
| 73 base::Bind(&PermissionContextBase::NotifyPermissionSet, | |
| 74 base::Unretained(this), | |
| 75 id, | |
| 76 requesting_frame, | |
| 77 callback)); | |
| 78 } | |
| 79 } | |
| 80 | |
| 81 void PermissionContextBase::PermissionDecided( | |
| 82 const PermissionRequestID& id, | |
| 83 const GURL& requesting_frame, | |
| 84 const GURL& embedder, | |
| 85 const BrowserPermissionCallback& callback, | |
| 86 bool allowed) { | |
| 87 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 88 NotifyPermissionSet(id, requesting_frame, callback, allowed); | |
| 89 } | |
| 90 | |
| 91 PermissionQueueController* PermissionContextBase::GetQueueController() { | |
| 92 if (!permission_queue_controller_) { | |
| 93 permission_queue_controller_.reset( | |
| 94 new PermissionQueueController(profile_, permission_type_)); | |
| 95 } | |
| 96 return permission_queue_controller_.get(); | |
| 97 } | |
| 98 | |
| 99 void PermissionContextBase::NotifyPermissionSet( | |
| 100 const PermissionRequestID& id, | |
| 101 const GURL& requesting_frame, | |
| 102 const BrowserPermissionCallback& callback, | |
| 103 bool allowed) { | |
| 104 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 105 UpdateTabContext(id, requesting_frame, allowed); | |
| 106 | |
| 107 callback.Run(allowed); | |
| 108 } | |
| 109 | |
| 110 } // namespace gcm | |
| OLD | NEW |