| 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/content_settings/permission_context_base.h" | 5 #include "chrome/browser/content_settings/permission_context_base.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "chrome/browser/content_settings/permission_bubble_request_impl.h" | 9 #include "chrome/browser/content_settings/permission_bubble_request_impl.h" |
| 10 #include "chrome/browser/content_settings/permission_context_uma_util.h" | 10 #include "chrome/browser/content_settings/permission_context_uma_util.h" |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 return; | 71 return; |
| 72 } | 72 } |
| 73 | 73 |
| 74 GetQueueController()->CancelInfoBarRequest(id); | 74 GetQueueController()->CancelInfoBarRequest(id); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void PermissionContextBase::DecidePermission( | 77 void PermissionContextBase::DecidePermission( |
| 78 content::WebContents* web_contents, | 78 content::WebContents* web_contents, |
| 79 const PermissionRequestID& id, | 79 const PermissionRequestID& id, |
| 80 const GURL& requesting_origin, | 80 const GURL& requesting_origin, |
| 81 const GURL& embedder_origin, | 81 const GURL& embedding_origin, |
| 82 bool user_gesture, | 82 bool user_gesture, |
| 83 const BrowserPermissionCallback& callback) { | 83 const BrowserPermissionCallback& callback) { |
| 84 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 84 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 85 | 85 |
| 86 ContentSetting content_setting = | 86 ContentSetting content_setting = |
| 87 profile_->GetHostContentSettingsMap() | 87 profile_->GetHostContentSettingsMap() |
| 88 ->GetContentSettingAndMaybeUpdateLastUsage( | 88 ->GetContentSettingAndMaybeUpdateLastUsage( |
| 89 requesting_origin, embedder_origin, permission_type_, std::string()); | 89 requesting_origin, embedding_origin, permission_type_, |
| 90 std::string()); |
| 90 switch (content_setting) { | 91 switch (content_setting) { |
| 91 case CONTENT_SETTING_BLOCK: | 92 case CONTENT_SETTING_BLOCK: |
| 92 NotifyPermissionSet(id, requesting_origin, embedder_origin, | 93 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| 93 callback, false /* persist */, false /* granted */); | 94 false /* persist */, false /* granted */); |
| 94 return; | 95 return; |
| 95 case CONTENT_SETTING_ALLOW: | 96 case CONTENT_SETTING_ALLOW: |
| 96 NotifyPermissionSet(id, requesting_origin, embedder_origin, | 97 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| 97 callback, false /* persist */, true /* granted */); | 98 false /* persist */, true /* granted */); |
| 98 return; | 99 return; |
| 99 default: | 100 default: |
| 100 break; | 101 break; |
| 101 } | 102 } |
| 102 | 103 |
| 103 PermissionContextUmaUtil::PermissionRequested( | 104 PermissionContextUmaUtil::PermissionRequested( |
| 104 permission_type_, requesting_origin); | 105 permission_type_, requesting_origin); |
| 105 | 106 |
| 106 if (PermissionBubbleManager::Enabled()) { | 107 if (PermissionBubbleManager::Enabled()) { |
| 107 PermissionBubbleManager* bubble_manager = | 108 PermissionBubbleManager* bubble_manager = |
| 108 PermissionBubbleManager::FromWebContents(web_contents); | 109 PermissionBubbleManager::FromWebContents(web_contents); |
| 109 DCHECK(bubble_manager); | 110 DCHECK(bubble_manager); |
| 110 scoped_ptr<PermissionBubbleRequest> request_ptr( | 111 scoped_ptr<PermissionBubbleRequest> request_ptr( |
| 111 new PermissionBubbleRequestImpl( | 112 new PermissionBubbleRequestImpl( |
| 112 requesting_origin, | 113 requesting_origin, user_gesture, permission_type_, |
| 113 user_gesture, | |
| 114 permission_type_, | |
| 115 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), | 114 profile_->GetPrefs()->GetString(prefs::kAcceptLanguages), |
| 116 base::Bind(&PermissionContextBase::PermissionDecided, | 115 base::Bind(&PermissionContextBase::PermissionDecided, |
| 117 weak_factory_.GetWeakPtr(), | 116 weak_factory_.GetWeakPtr(), id, requesting_origin, |
| 118 id, | 117 embedding_origin, callback), |
| 119 requesting_origin, | |
| 120 embedder_origin, | |
| 121 callback), | |
| 122 base::Bind(&PermissionContextBase::CleanUpBubble, | 118 base::Bind(&PermissionContextBase::CleanUpBubble, |
| 123 weak_factory_.GetWeakPtr(), id))); | 119 weak_factory_.GetWeakPtr(), id))); |
| 124 PermissionBubbleRequest* request = request_ptr.get(); | 120 PermissionBubbleRequest* request = request_ptr.get(); |
| 125 | 121 |
| 126 bool inserted = pending_bubbles_.add( | 122 bool inserted = pending_bubbles_.add( |
| 127 id.ToString(), request_ptr.Pass()).second; | 123 id.ToString(), request_ptr.Pass()).second; |
| 128 DCHECK(inserted) << "Duplicate id " << id.ToString(); | 124 DCHECK(inserted) << "Duplicate id " << id.ToString(); |
| 129 bubble_manager->AddRequest(request); | 125 bubble_manager->AddRequest(request); |
| 130 return; | 126 return; |
| 131 } | 127 } |
| 132 | 128 |
| 133 // TODO(gbillock): Delete this and the infobar delegate when | 129 // TODO(gbillock): Delete this and the infobar delegate when |
| 134 // we're using only bubbles. crbug.com/337458 | 130 // we're using only bubbles. crbug.com/337458 |
| 135 GetQueueController()->CreateInfoBarRequest( | 131 GetQueueController()->CreateInfoBarRequest( |
| 136 id, | 132 id, requesting_origin, embedding_origin, |
| 137 requesting_origin, | |
| 138 embedder_origin, | |
| 139 base::Bind(&PermissionContextBase::PermissionDecided, | 133 base::Bind(&PermissionContextBase::PermissionDecided, |
| 140 weak_factory_.GetWeakPtr(), | 134 weak_factory_.GetWeakPtr(), id, requesting_origin, |
| 141 id, | 135 embedding_origin, callback, |
| 142 requesting_origin, | |
| 143 embedder_origin, | |
| 144 callback, | |
| 145 // the queue controller takes care of persisting the | 136 // the queue controller takes care of persisting the |
| 146 // permission | 137 // permission |
| 147 false)); | 138 false)); |
| 148 } | 139 } |
| 149 | 140 |
| 150 void PermissionContextBase::PermissionDecided( | 141 void PermissionContextBase::PermissionDecided( |
| 151 const PermissionRequestID& id, | 142 const PermissionRequestID& id, |
| 152 const GURL& requesting_origin, | 143 const GURL& requesting_origin, |
| 153 const GURL& embedder_origin, | 144 const GURL& embedding_origin, |
| 154 const BrowserPermissionCallback& callback, | 145 const BrowserPermissionCallback& callback, |
| 155 bool persist, | 146 bool persist, |
| 156 bool allowed) { | 147 bool allowed) { |
| 157 | |
| 158 // Infobar persistance and its related UMA is tracked on the infobar | 148 // Infobar persistance and its related UMA is tracked on the infobar |
| 159 // controller directly. | 149 // controller directly. |
| 160 if (PermissionBubbleManager::Enabled()) { | 150 if (PermissionBubbleManager::Enabled()) { |
| 161 if (persist) { | 151 if (persist) { |
| 162 if (allowed) | 152 if (allowed) |
| 163 PermissionContextUmaUtil::PermissionGranted(permission_type_, | 153 PermissionContextUmaUtil::PermissionGranted(permission_type_, |
| 164 requesting_origin); | 154 requesting_origin); |
| 165 else | 155 else |
| 166 PermissionContextUmaUtil::PermissionDenied(permission_type_, | 156 PermissionContextUmaUtil::PermissionDenied(permission_type_, |
| 167 requesting_origin); | 157 requesting_origin); |
| 168 } else { | 158 } else { |
| 169 PermissionContextUmaUtil::PermissionDismissed(permission_type_, | 159 PermissionContextUmaUtil::PermissionDismissed(permission_type_, |
| 170 requesting_origin); | 160 requesting_origin); |
| 171 } | 161 } |
| 172 } | 162 } |
| 173 | 163 |
| 174 NotifyPermissionSet( | 164 NotifyPermissionSet(id, requesting_origin, embedding_origin, callback, |
| 175 id, requesting_origin, embedder_origin, callback, persist, allowed); | 165 persist, allowed); |
| 176 } | 166 } |
| 177 | 167 |
| 178 PermissionQueueController* PermissionContextBase::GetQueueController() { | 168 PermissionQueueController* PermissionContextBase::GetQueueController() { |
| 179 return permission_queue_controller_.get(); | 169 return permission_queue_controller_.get(); |
| 180 } | 170 } |
| 181 | 171 |
| 182 void PermissionContextBase::NotifyPermissionSet( | 172 void PermissionContextBase::NotifyPermissionSet( |
| 183 const PermissionRequestID& id, | 173 const PermissionRequestID& id, |
| 184 const GURL& requesting_origin, | 174 const GURL& requesting_origin, |
| 185 const GURL& embedder_origin, | 175 const GURL& embedding_origin, |
| 186 const BrowserPermissionCallback& callback, | 176 const BrowserPermissionCallback& callback, |
| 187 bool persist, | 177 bool persist, |
| 188 bool allowed) { | 178 bool allowed) { |
| 189 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 179 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 190 if (persist) | 180 if (persist) |
| 191 UpdateContentSetting(requesting_origin, embedder_origin, allowed); | 181 UpdateContentSetting(requesting_origin, embedding_origin, allowed); |
| 192 | 182 |
| 193 UpdateTabContext(id, requesting_origin, allowed); | 183 UpdateTabContext(id, requesting_origin, allowed); |
| 194 callback.Run(allowed); | 184 callback.Run(allowed); |
| 195 } | 185 } |
| 196 | 186 |
| 197 void PermissionContextBase::CleanUpBubble(const PermissionRequestID& id) { | 187 void PermissionContextBase::CleanUpBubble(const PermissionRequestID& id) { |
| 198 size_t success = pending_bubbles_.erase(id.ToString()); | 188 size_t success = pending_bubbles_.erase(id.ToString()); |
| 199 DCHECK(success == 1) << "Missing request " << id.ToString(); | 189 DCHECK(success == 1) << "Missing request " << id.ToString(); |
| 200 } | 190 } |
| 201 | 191 |
| 202 void PermissionContextBase::UpdateContentSetting( | 192 void PermissionContextBase::UpdateContentSetting(const GURL& requesting_origin, |
| 203 const GURL& requesting_origin, | 193 const GURL& embedding_origin, |
| 204 const GURL& embedder_origin, | 194 bool allowed) { |
| 205 bool allowed) { | |
| 206 DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin()); | 195 DCHECK_EQ(requesting_origin, requesting_origin.GetOrigin()); |
| 207 DCHECK_EQ(embedder_origin, embedder_origin.GetOrigin()); | 196 DCHECK_EQ(embedding_origin, embedding_origin.GetOrigin()); |
| 208 ContentSetting content_setting = | 197 ContentSetting content_setting = |
| 209 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 198 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| 210 profile_->GetHostContentSettingsMap()->SetContentSetting( | 199 profile_->GetHostContentSettingsMap()->SetContentSetting( |
| 211 ContentSettingsPattern::FromURLNoWildcard(requesting_origin), | 200 ContentSettingsPattern::FromURLNoWildcard(requesting_origin), |
| 212 ContentSettingsPattern::FromURLNoWildcard(embedder_origin), | 201 ContentSettingsPattern::FromURLNoWildcard(embedding_origin), |
| 213 permission_type_, | 202 permission_type_, std::string(), content_setting); |
| 214 std::string(), | |
| 215 content_setting); | |
| 216 } | 203 } |
| OLD | NEW |