OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/permissions/permission_queue_controller.h" | 5 #include "chrome/browser/permissions/permission_queue_controller.h" |
6 | 6 |
7 #include "build/build_config.h" | 7 #include "build/build_config.h" |
8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
10 #include "chrome/browser/infobars/infobar_service.h" | 10 #include "chrome/browser/infobars/infobar_service.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
46 content::WebContents* other_web_contents = tab_util::GetWebContentsByFrameID( | 46 content::WebContents* other_web_contents = tab_util::GetWebContentsByFrameID( |
47 other_request.render_process_id(), other_request.render_frame_id()); | 47 other_request.render_process_id(), other_request.render_frame_id()); |
48 | 48 |
49 return web_contents == other_web_contents; | 49 return web_contents == other_web_contents; |
50 } | 50 } |
51 | 51 |
52 } // anonymous namespace | 52 } // anonymous namespace |
53 | 53 |
54 class PermissionQueueController::PendingInfobarRequest { | 54 class PermissionQueueController::PendingInfobarRequest { |
55 public: | 55 public: |
56 PendingInfobarRequest(content::PermissionType type, | 56 PendingInfobarRequest(ContentSettingsType type, |
57 const PermissionRequestID& id, | 57 const PermissionRequestID& id, |
58 const GURL& requesting_frame, | 58 const GURL& requesting_frame, |
59 const GURL& embedder, | 59 const GURL& embedder, |
60 bool user_gesture, | 60 bool user_gesture, |
61 Profile* profile, | 61 Profile* profile, |
62 const PermissionDecidedCallback& callback); | 62 const PermissionDecidedCallback& callback); |
63 ~PendingInfobarRequest(); | 63 ~PendingInfobarRequest(); |
64 | 64 |
65 bool IsForPair(const GURL& requesting_frame, | 65 bool IsForPair(const GURL& requesting_frame, |
66 const GURL& embedder) const; | 66 const GURL& embedder) const; |
(...skipping 10 matching lines...) Expand all Loading... | |
77 const GURL& requesting_frame() const { return requesting_frame_; } | 77 const GURL& requesting_frame() const { return requesting_frame_; } |
78 bool has_gesture() const { return user_gesture_; } | 78 bool has_gesture() const { return user_gesture_; } |
79 bool has_infobar() const { return !!infobar_; } | 79 bool has_infobar() const { return !!infobar_; } |
80 bool has_dialog() const { return has_dialog_; } | 80 bool has_dialog() const { return has_dialog_; } |
81 infobars::InfoBar* infobar() { return infobar_; } | 81 infobars::InfoBar* infobar() { return infobar_; } |
82 | 82 |
83 void RunCallback(ContentSetting content_setting); | 83 void RunCallback(ContentSetting content_setting); |
84 void CreatePrompt(PermissionQueueController* controller, bool show_dialog); | 84 void CreatePrompt(PermissionQueueController* controller, bool show_dialog); |
85 | 85 |
86 private: | 86 private: |
87 content::PermissionType type_; | 87 ContentSettingsType type_; |
88 PermissionRequestID id_; | 88 PermissionRequestID id_; |
89 GURL requesting_frame_; | 89 GURL requesting_frame_; |
90 GURL embedder_; | 90 GURL embedder_; |
91 bool user_gesture_; | 91 bool user_gesture_; |
92 Profile* profile_; | 92 Profile* profile_; |
93 PermissionDecidedCallback callback_; | 93 PermissionDecidedCallback callback_; |
94 infobars::InfoBar* infobar_; | 94 infobars::InfoBar* infobar_; |
95 bool has_dialog_; | 95 bool has_dialog_; |
96 | 96 |
97 // Purposefully do not disable copying, as this is stored in STL containers. | 97 // Purposefully do not disable copying, as this is stored in STL containers. |
98 }; | 98 }; |
99 | 99 |
100 PermissionQueueController::PendingInfobarRequest::PendingInfobarRequest( | 100 PermissionQueueController::PendingInfobarRequest::PendingInfobarRequest( |
101 content::PermissionType type, | 101 ContentSettingsType type, |
102 const PermissionRequestID& id, | 102 const PermissionRequestID& id, |
103 const GURL& requesting_frame, | 103 const GURL& requesting_frame, |
104 const GURL& embedder, | 104 const GURL& embedder, |
105 bool user_gesture, | 105 bool user_gesture, |
106 Profile* profile, | 106 Profile* profile, |
107 const PermissionDecidedCallback& callback) | 107 const PermissionDecidedCallback& callback) |
108 : type_(type), | 108 : type_(type), |
109 id_(id), | 109 id_(id), |
110 requesting_frame_(requesting_frame), | 110 requesting_frame_(requesting_frame), |
111 embedder_(embedder), | 111 embedder_(embedder), |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 callback); | 152 callback); |
153 } else { | 153 } else { |
154 infobar_ = PermissionInfoBarDelegate::Create( | 154 infobar_ = PermissionInfoBarDelegate::Create( |
155 GetInfoBarService(id_), type_, requesting_frame_, user_gesture_, | 155 GetInfoBarService(id_), type_, requesting_frame_, user_gesture_, |
156 profile_, callback); | 156 profile_, callback); |
157 } | 157 } |
158 } | 158 } |
159 | 159 |
160 PermissionQueueController::PermissionQueueController( | 160 PermissionQueueController::PermissionQueueController( |
161 Profile* profile, | 161 Profile* profile, |
162 content::PermissionType permission_type, | |
163 ContentSettingsType content_settings_type) | 162 ContentSettingsType content_settings_type) |
164 : profile_(profile), | 163 : profile_(profile), |
165 permission_type_(permission_type), | |
166 content_settings_type_(content_settings_type), | 164 content_settings_type_(content_settings_type), |
167 in_shutdown_(false) {} | 165 in_shutdown_(false) {} |
168 | 166 |
169 PermissionQueueController::~PermissionQueueController() { | 167 PermissionQueueController::~PermissionQueueController() { |
170 // Cancel all outstanding requests. | 168 // Cancel all outstanding requests. |
171 in_shutdown_ = true; | 169 in_shutdown_ = true; |
172 while (!pending_infobar_requests_.empty()) | 170 while (!pending_infobar_requests_.empty()) |
173 CancelInfoBarRequest(pending_infobar_requests_.front().id()); | 171 CancelInfoBarRequest(pending_infobar_requests_.front().id()); |
174 } | 172 } |
175 | 173 |
176 void PermissionQueueController::CreateInfoBarRequest( | 174 void PermissionQueueController::CreateInfoBarRequest( |
177 const PermissionRequestID& id, | 175 const PermissionRequestID& id, |
178 const GURL& requesting_frame, | 176 const GURL& requesting_frame, |
179 const GURL& embedder, | 177 const GURL& embedder, |
180 bool user_gesture, | 178 bool user_gesture, |
181 const PermissionDecidedCallback& callback) { | 179 const PermissionDecidedCallback& callback) { |
182 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 180 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
183 | 181 |
184 if (requesting_frame.SchemeIs(content::kChromeUIScheme) || | 182 if (requesting_frame.SchemeIs(content::kChromeUIScheme) || |
185 embedder.SchemeIs(content::kChromeUIScheme)) | 183 embedder.SchemeIs(content::kChromeUIScheme)) |
186 return; | 184 return; |
187 | 185 |
188 pending_infobar_requests_.push_back( | 186 pending_infobar_requests_.push_back( |
189 PendingInfobarRequest(permission_type_, id, requesting_frame, embedder, | 187 PendingInfobarRequest(content_settings_type_, id, requesting_frame, |
190 user_gesture, profile_, callback)); | 188 embedder, user_gesture, profile_, callback)); |
191 if (!AlreadyShowingInfoBarForTab(id)) | 189 if (!AlreadyShowingInfoBarForTab(id)) |
192 ShowQueuedInfoBarForTab(id); | 190 ShowQueuedInfoBarForTab(id); |
193 } | 191 } |
194 | 192 |
195 void PermissionQueueController::CancelInfoBarRequest( | 193 void PermissionQueueController::CancelInfoBarRequest( |
196 const PermissionRequestID& id) { | 194 const PermissionRequestID& id) { |
197 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 195 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
198 | 196 |
199 for (PendingInfobarRequests::iterator i(pending_infobar_requests_.begin()); | 197 for (PendingInfobarRequests::iterator i(pending_infobar_requests_.begin()); |
200 i != pending_infobar_requests_.end(); ++i) { | 198 i != pending_infobar_requests_.end(); ++i) { |
(...skipping 11 matching lines...) Expand all Loading... | |
212 | 210 |
213 void PermissionQueueController::OnPermissionSet(const PermissionRequestID& id, | 211 void PermissionQueueController::OnPermissionSet(const PermissionRequestID& id, |
214 const GURL& requesting_frame, | 212 const GURL& requesting_frame, |
215 const GURL& embedder, | 213 const GURL& embedder, |
216 bool user_gesture, | 214 bool user_gesture, |
217 bool update_content_setting, | 215 bool update_content_setting, |
218 PermissionAction decision) { | 216 PermissionAction decision) { |
219 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 217 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
220 | 218 |
221 PermissionRequestType request_type = | 219 PermissionRequestType request_type = |
222 PermissionUtil::GetRequestType(permission_type_); | 220 PermissionUtil::GetRequestType(content_settings_type_); |
223 PermissionRequestGestureType gesture_type = | 221 PermissionRequestGestureType gesture_type = |
224 PermissionUtil::GetGestureType(user_gesture); | 222 PermissionUtil::GetGestureType(user_gesture); |
225 switch (decision) { | 223 switch (decision) { |
226 case GRANTED: | 224 case GRANTED: |
227 PermissionUmaUtil::PermissionGranted(permission_type_, gesture_type, | 225 PermissionUmaUtil::PermissionGranted(content_settings_type_, gesture_type, |
228 requesting_frame, profile_); | 226 requesting_frame, profile_); |
229 PermissionUmaUtil::RecordPermissionPromptAccepted(request_type, | 227 PermissionUmaUtil::RecordPermissionPromptAccepted(request_type, |
230 gesture_type); | 228 gesture_type); |
231 break; | 229 break; |
232 case DENIED: | 230 case DENIED: |
233 PermissionUmaUtil::PermissionDenied(permission_type_, gesture_type, | 231 PermissionUmaUtil::PermissionDenied(content_settings_type_, gesture_type, |
234 requesting_frame, profile_); | 232 requesting_frame, profile_); |
235 PermissionUmaUtil::RecordPermissionPromptDenied(request_type, | 233 PermissionUmaUtil::RecordPermissionPromptDenied(request_type, |
236 gesture_type); | 234 gesture_type); |
237 break; | 235 break; |
238 case DISMISSED: | 236 case DISMISSED: |
239 PermissionUmaUtil::PermissionDismissed(permission_type_, gesture_type, | 237 PermissionUmaUtil::PermissionDismissed( |
240 requesting_frame, profile_); | 238 content_settings_type_, gesture_type, requesting_frame, profile_); |
241 break; | 239 break; |
242 default: | 240 default: |
243 NOTREACHED(); | 241 NOTREACHED(); |
244 } | 242 } |
245 | 243 |
246 // TODO(miguelg): move the permission persistence to | 244 // TODO(miguelg): move the permission persistence to |
247 // PermissionContextBase once all the types are moved there. | 245 // PermissionContextBase once all the types are moved there. |
248 if (update_content_setting) | 246 if (update_content_setting) |
249 UpdateContentSetting(requesting_frame, embedder, decision); | 247 UpdateContentSetting(requesting_frame, embedder, decision); |
250 | 248 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
428 if (requesting_frame.GetOrigin().SchemeIsFile()) { | 426 if (requesting_frame.GetOrigin().SchemeIsFile()) { |
429 // Chrome can be launched with --disable-web-security which allows | 427 // Chrome can be launched with --disable-web-security which allows |
430 // geolocation requests from file:// URLs. We don't want to store these | 428 // geolocation requests from file:// URLs. We don't want to store these |
431 // in the host content settings map. | 429 // in the host content settings map. |
432 return; | 430 return; |
433 } | 431 } |
434 | 432 |
435 ContentSetting content_setting = | 433 ContentSetting content_setting = |
436 (decision == GRANTED) ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 434 (decision == GRANTED) ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
437 | 435 |
436 // TODO(timloh): Remove this logic when push and notification permissions | |
437 // are reconciled. | |
raymes
2017/02/09 00:39:57
nit: you can add that bug here too
| |
438 ContentSettingsType type_for_map = content_settings_type_; | |
439 if (type_for_map == CONTENT_SETTINGS_TYPE_PUSH_MESSAGING) | |
440 type_for_map = CONTENT_SETTINGS_TYPE_NOTIFICATIONS; | |
438 HostContentSettingsMapFactory::GetForProfile(profile_) | 441 HostContentSettingsMapFactory::GetForProfile(profile_) |
439 ->SetContentSettingDefaultScope( | 442 ->SetContentSettingDefaultScope( |
440 requesting_frame.GetOrigin(), embedder.GetOrigin(), | 443 requesting_frame.GetOrigin(), embedder.GetOrigin(), |
441 content_settings_type_, std::string(), content_setting); | 444 type_for_map, std::string(), content_setting); |
442 } | 445 } |
OLD | NEW |