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/host_content_settings_map.h" | 9 #include "chrome/browser/content_settings/host_content_settings_map.h" |
10 #include "chrome/browser/content_settings/permission_bubble_request_impl.h" | 10 #include "chrome/browser/content_settings/permission_bubble_request_impl.h" |
11 #include "chrome/browser/content_settings/permission_context_uma_util.h" | 11 #include "chrome/browser/content_settings/permission_context_uma_util.h" |
12 #include "chrome/browser/content_settings/permission_queue_controller.h" | 12 #include "chrome/browser/content_settings/permission_queue_controller.h" |
13 #include "chrome/browser/content_settings/permission_request_id.h" | 13 #include "chrome/browser/content_settings/permission_request_id.h" |
14 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 14 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | 16 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
17 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
20 | 20 |
21 PermissionContextBase::PermissionContextBase( | 21 PermissionContextBase::PermissionContextBase( |
22 Profile* profile, | 22 Profile* profile, |
23 const ContentSettingsType permission_type) | 23 const ContentSettingsType permission_type) |
24 : profile_(profile), | 24 : profile_(profile), |
25 permission_type_(permission_type), | 25 permission_type_(permission_type), |
26 shutting_down_(false), | |
26 weak_factory_(this) { | 27 weak_factory_(this) { |
27 permission_queue_controller_.reset( | 28 permission_queue_controller_.reset( |
28 new PermissionQueueController(profile_, permission_type_)); | 29 new PermissionQueueController(profile_, permission_type_)); |
29 } | 30 } |
30 | 31 |
31 PermissionContextBase::~PermissionContextBase() { | 32 PermissionContextBase::~PermissionContextBase() { |
32 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 33 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
33 } | 34 } |
34 | 35 |
35 void PermissionContextBase::RequestPermission( | 36 void PermissionContextBase::RequestPermission( |
36 content::WebContents* web_contents, | 37 content::WebContents* web_contents, |
37 const PermissionRequestID& id, | 38 const PermissionRequestID& id, |
38 const GURL& requesting_frame, | 39 const GURL& requesting_frame, |
39 bool user_gesture, | 40 bool user_gesture, |
40 const BrowserPermissionCallback& callback) { | 41 const BrowserPermissionCallback& callback) { |
41 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 42 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
42 | 43 |
44 if (shutting_down_) | |
45 return; | |
43 DecidePermission(web_contents, | 46 DecidePermission(web_contents, |
44 id, | 47 id, |
45 requesting_frame.GetOrigin(), | 48 requesting_frame.GetOrigin(), |
46 web_contents->GetLastCommittedURL().GetOrigin(), | 49 web_contents->GetLastCommittedURL().GetOrigin(), |
47 user_gesture, | 50 user_gesture, |
48 callback); | 51 callback); |
49 } | 52 } |
50 | 53 |
54 void PermissionContextBase::CancelPermissionRequest( | |
55 content::WebContents* web_contents, | |
56 const PermissionRequestID& id) { | |
57 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
Bernhard Bauer
2014/08/13 21:05:08
Nit: DCHECK_CURRENTLY_ON?
| |
58 if (shutting_down_) | |
59 return; | |
60 | |
61 if (PermissionBubbleManager::Enabled()) { | |
62 PermissionBubbleRequest* cancelling = | |
63 pending_bubbles_.get(id.ToString()); | |
64 if (cancelling != NULL && web_contents != NULL && | |
65 PermissionBubbleManager::FromWebContents(web_contents) != NULL) { | |
66 PermissionBubbleManager::FromWebContents(web_contents)-> | |
67 CancelRequest(cancelling); | |
68 } | |
69 return; | |
70 } | |
71 | |
72 GetQueueController()->CancelInfoBarRequest(id); | |
73 } | |
74 | |
51 void PermissionContextBase::DecidePermission( | 75 void PermissionContextBase::DecidePermission( |
52 content::WebContents* web_contents, | 76 content::WebContents* web_contents, |
53 const PermissionRequestID& id, | 77 const PermissionRequestID& id, |
54 const GURL& requesting_origin, | 78 const GURL& requesting_origin, |
55 const GURL& embedder_origin, | 79 const GURL& embedder_origin, |
56 bool user_gesture, | 80 bool user_gesture, |
57 const BrowserPermissionCallback& callback) { | 81 const BrowserPermissionCallback& callback) { |
58 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 82 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
59 | 83 |
60 ContentSetting content_setting = | 84 ContentSetting content_setting = |
61 profile_->GetHostContentSettingsMap()->GetContentSetting( | 85 profile_->GetHostContentSettingsMap() |
86 ->GetContentSettingAndMaybeUpdateLastUsage( | |
62 requesting_origin, embedder_origin, permission_type_, std::string()); | 87 requesting_origin, embedder_origin, permission_type_, std::string()); |
63 switch (content_setting) { | 88 switch (content_setting) { |
64 case CONTENT_SETTING_BLOCK: | 89 case CONTENT_SETTING_BLOCK: |
65 NotifyPermissionSet(id, requesting_origin, embedder_origin, | 90 NotifyPermissionSet(id, requesting_origin, embedder_origin, |
66 callback, false /* persist */, false /* granted */); | 91 callback, false /* persist */, false /* granted */); |
67 return; | 92 return; |
68 case CONTENT_SETTING_ALLOW: | 93 case CONTENT_SETTING_ALLOW: |
69 NotifyPermissionSet(id, requesting_origin, embedder_origin, | 94 NotifyPermissionSet(id, requesting_origin, embedder_origin, |
70 callback, false /* persist */, true /* granted */); | 95 callback, false /* persist */, true /* granted */); |
71 return; | 96 return; |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
176 DCHECK_EQ(embedder_origin, embedder_origin.GetOrigin()); | 201 DCHECK_EQ(embedder_origin, embedder_origin.GetOrigin()); |
177 ContentSetting content_setting = | 202 ContentSetting content_setting = |
178 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 203 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
179 profile_->GetHostContentSettingsMap()->SetContentSetting( | 204 profile_->GetHostContentSettingsMap()->SetContentSetting( |
180 ContentSettingsPattern::FromURLNoWildcard(requesting_origin), | 205 ContentSettingsPattern::FromURLNoWildcard(requesting_origin), |
181 ContentSettingsPattern::FromURLNoWildcard(embedder_origin), | 206 ContentSettingsPattern::FromURLNoWildcard(embedder_origin), |
182 permission_type_, | 207 permission_type_, |
183 std::string(), | 208 std::string(), |
184 content_setting); | 209 content_setting); |
185 } | 210 } |
211 | |
212 void PermissionContextBase::Shutdown() { | |
213 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
214 shutting_down_ = true; | |
215 } | |
OLD | NEW |