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_); | |
|
jianli
2014/06/20 17:19:29
Please include logging.h.
Since permission_queue_
Miguel Garcia
2014/06/20 20:50:12
Actually let's create permission_queue_controller
| |
| 25 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 26 } | |
| 27 | |
| 28 void PermissionContextBase::RequestPermission( | |
| 29 content::WebContents* web_contents, | |
| 30 const PermissionRequestID& id, | |
| 31 const GURL& requesting_frame, | |
| 32 bool user_gesture, | |
| 33 const BrowserPermissionCallback& callback) { | |
| 34 // TODO(miguelg) Add UMA instrumentation | |
|
jianli
2014/06/20 17:19:29
nit: add ':' after ')' and end the sentence with p
Miguel Garcia
2014/06/20 20:50:12
Done.
| |
| 35 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 36 | |
| 37 DecidePermission(web_contents, | |
| 38 id, | |
| 39 requesting_frame, | |
| 40 requesting_frame, | |
| 41 user_gesture, | |
| 42 callback); | |
| 43 } | |
| 44 | |
| 45 void PermissionContextBase::DecidePermission( | |
| 46 content::WebContents* web_contents, | |
| 47 const PermissionRequestID& id, | |
| 48 const GURL& requesting_frame, | |
| 49 const GURL& embedder, | |
| 50 bool user_gesture, | |
| 51 const BrowserPermissionCallback& callback) { | |
| 52 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 53 | |
| 54 ContentSetting content_setting = | |
| 55 profile_->GetHostContentSettingsMap()->GetContentSetting( | |
| 56 requesting_frame, embedder, permission_type_, std::string()); | |
| 57 switch (content_setting) { | |
| 58 case CONTENT_SETTING_BLOCK: | |
| 59 PermissionDecided(id, requesting_frame, embedder, callback, false); | |
| 60 break; | |
| 61 case CONTENT_SETTING_ALLOW: | |
| 62 PermissionDecided(id, requesting_frame, embedder, callback, true); | |
| 63 break; | |
| 64 default: | |
| 65 // TODO(miguelg) implement bubble support | |
|
jianli
2014/06/20 17:19:29
ditto
Miguel Garcia
2014/06/20 20:50:12
Done.
| |
| 66 | |
| 67 // TODO(gbillock): Delete this and the infobar delegate when | |
| 68 // we're using only bubbles. crbug.com/337458 | |
| 69 GetQueueController()->CreateInfoBarRequest( | |
| 70 id, | |
| 71 requesting_frame, | |
| 72 embedder, | |
| 73 std::string(), | |
| 74 base::Bind(&PermissionContextBase::NotifyPermissionSet, | |
| 75 base::Unretained(this), | |
|
fgorski
2014/06/20 14:14:15
Will this callback be passed somewhere outside of
Miguel Garcia
2014/06/20 20:50:12
Once we implement bubbles it will be passed to the
| |
| 76 id, | |
| 77 requesting_frame, | |
| 78 callback)); | |
| 79 } | |
| 80 } | |
| 81 | |
| 82 void PermissionContextBase::PermissionDecided( | |
| 83 const PermissionRequestID& id, | |
| 84 const GURL& requesting_frame, | |
| 85 const GURL& embedder, | |
| 86 const BrowserPermissionCallback& callback, | |
| 87 bool allowed) { | |
| 88 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 89 NotifyPermissionSet(id, requesting_frame, callback, allowed); | |
| 90 } | |
| 91 | |
| 92 PermissionQueueController* PermissionContextBase::GetQueueController() { | |
| 93 if (!permission_queue_controller_) { | |
| 94 permission_queue_controller_.reset( | |
| 95 new PermissionQueueController(profile_, permission_type_)); | |
| 96 } | |
| 97 return permission_queue_controller_.get(); | |
| 98 } | |
| 99 | |
| 100 void PermissionContextBase::NotifyPermissionSet( | |
| 101 const PermissionRequestID& id, | |
| 102 const GURL& requesting_frame, | |
| 103 const BrowserPermissionCallback& callback, | |
| 104 bool allowed) { | |
| 105 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 106 UpdateTabContext(id, requesting_frame, allowed); | |
| 107 | |
| 108 callback.Run(allowed); | |
| 109 } | |
| 110 | |
| 111 } // namespace gcm | |
| OLD | NEW |