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 "chrome/browser/chrome_notification_types.h" | 7 #include "chrome/browser/chrome_notification_types.h" |
8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 8 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
9 #include "chrome/browser/geolocation/geolocation_infobar_delegate_android.h" | 9 #include "chrome/browser/geolocation/geolocation_infobar_delegate_android.h" |
10 #include "chrome/browser/infobars/infobar_service.h" | 10 #include "chrome/browser/infobars/infobar_service.h" |
11 #include "chrome/browser/media/midi_permission_infobar_delegate_android.h" | 11 #include "chrome/browser/media/midi_permission_infobar_delegate_android.h" |
12 #include "chrome/browser/media/protected_media_identifier_infobar_delegate_andro
id.h" | 12 #include "chrome/browser/media/protected_media_identifier_infobar_delegate_andro
id.h" |
13 #include "chrome/browser/notifications/notification_permission_infobar_delegate.
h" | 13 #include "chrome/browser/notifications/notification_permission_infobar_delegate.
h" |
14 #include "chrome/browser/permissions/permission_request_id.h" | 14 #include "chrome/browser/permissions/permission_request_id.h" |
15 #include "chrome/browser/permissions/permission_uma_util.h" | 15 #include "chrome/browser/permissions/permission_uma_util.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/tab_contents/tab_util.h" | 17 #include "chrome/browser/tab_contents/tab_util.h" |
18 #include "chrome/common/pref_names.h" | |
19 #include "components/content_settings/core/browser/host_content_settings_map.h" | 18 #include "components/content_settings/core/browser/host_content_settings_map.h" |
20 #include "components/content_settings/core/common/content_settings.h" | 19 #include "components/content_settings/core/common/content_settings.h" |
21 #include "components/infobars/core/infobar.h" | 20 #include "components/infobars/core/infobar.h" |
22 #include "components/prefs/pref_service.h" | |
23 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
24 #include "content/public/browser/notification_details.h" | 22 #include "content/public/browser/notification_details.h" |
25 #include "content/public/browser/notification_source.h" | 23 #include "content/public/browser/notification_source.h" |
26 #include "content/public/browser/notification_types.h" | 24 #include "content/public/browser/notification_types.h" |
27 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
28 #include "content/public/common/url_constants.h" | 26 #include "content/public/common/url_constants.h" |
29 | 27 |
30 namespace { | 28 namespace { |
31 | 29 |
32 InfoBarService* GetInfoBarService(const PermissionRequestID& id) { | 30 InfoBarService* GetInfoBarService(const PermissionRequestID& id) { |
(...skipping 26 matching lines...) Expand all Loading... |
59 | 57 |
60 bool IsForPair(const GURL& requesting_frame, | 58 bool IsForPair(const GURL& requesting_frame, |
61 const GURL& embedder) const; | 59 const GURL& embedder) const; |
62 | 60 |
63 const PermissionRequestID& id() const { return id_; } | 61 const PermissionRequestID& id() const { return id_; } |
64 const GURL& requesting_frame() const { return requesting_frame_; } | 62 const GURL& requesting_frame() const { return requesting_frame_; } |
65 bool has_infobar() const { return !!infobar_; } | 63 bool has_infobar() const { return !!infobar_; } |
66 infobars::InfoBar* infobar() { return infobar_; } | 64 infobars::InfoBar* infobar() { return infobar_; } |
67 | 65 |
68 void RunCallback(ContentSetting content_setting); | 66 void RunCallback(ContentSetting content_setting); |
69 void CreateInfoBar(PermissionQueueController* controller, | 67 void CreateInfoBar(PermissionQueueController* controller); |
70 const std::string& display_languages); | |
71 | 68 |
72 private: | 69 private: |
73 content::PermissionType type_; | 70 content::PermissionType type_; |
74 PermissionRequestID id_; | 71 PermissionRequestID id_; |
75 GURL requesting_frame_; | 72 GURL requesting_frame_; |
76 GURL embedder_; | 73 GURL embedder_; |
77 PermissionDecidedCallback callback_; | 74 PermissionDecidedCallback callback_; |
78 infobars::InfoBar* infobar_; | 75 infobars::InfoBar* infobar_; |
79 | 76 |
80 // Purposefully do not disable copying, as this is stored in STL containers. | 77 // Purposefully do not disable copying, as this is stored in STL containers. |
(...skipping 20 matching lines...) Expand all Loading... |
101 const GURL& embedder) const { | 98 const GURL& embedder) const { |
102 return (requesting_frame_ == requesting_frame) && (embedder_ == embedder); | 99 return (requesting_frame_ == requesting_frame) && (embedder_ == embedder); |
103 } | 100 } |
104 | 101 |
105 void PermissionQueueController::PendingInfobarRequest::RunCallback( | 102 void PermissionQueueController::PendingInfobarRequest::RunCallback( |
106 ContentSetting content_setting) { | 103 ContentSetting content_setting) { |
107 callback_.Run(content_setting); | 104 callback_.Run(content_setting); |
108 } | 105 } |
109 | 106 |
110 void PermissionQueueController::PendingInfobarRequest::CreateInfoBar( | 107 void PermissionQueueController::PendingInfobarRequest::CreateInfoBar( |
111 PermissionQueueController* controller, | 108 PermissionQueueController* controller) { |
112 const std::string& display_languages) { | |
113 // Controller can be Unretained because the lifetime of the infobar | 109 // Controller can be Unretained because the lifetime of the infobar |
114 // is tied to that of the queue controller. Before QueueController | 110 // is tied to that of the queue controller. Before QueueController |
115 // is destroyed, all requests will be cancelled and so all delegates | 111 // is destroyed, all requests will be cancelled and so all delegates |
116 // will be destroyed. | 112 // will be destroyed. |
117 PermissionInfobarDelegate::PermissionSetCallback callback = | 113 PermissionInfobarDelegate::PermissionSetCallback callback = |
118 base::Bind(&PermissionQueueController::OnPermissionSet, | 114 base::Bind(&PermissionQueueController::OnPermissionSet, |
119 base::Unretained(controller), | 115 base::Unretained(controller), |
120 id_, | 116 id_, |
121 requesting_frame_, | 117 requesting_frame_, |
122 embedder_); | 118 embedder_); |
123 switch (type_) { | 119 switch (type_) { |
124 case content::PermissionType::GEOLOCATION: | 120 case content::PermissionType::GEOLOCATION: |
125 infobar_ = GeolocationInfoBarDelegateAndroid::Create( | 121 infobar_ = GeolocationInfoBarDelegateAndroid::Create( |
126 GetInfoBarService(id_), requesting_frame_, display_languages, | 122 GetInfoBarService(id_), requesting_frame_, callback); |
127 callback); | |
128 break; | 123 break; |
129 #if defined(ENABLE_NOTIFICATIONS) | 124 #if defined(ENABLE_NOTIFICATIONS) |
130 case content::PermissionType::NOTIFICATIONS: | 125 case content::PermissionType::NOTIFICATIONS: |
131 infobar_ = NotificationPermissionInfobarDelegate::Create( | 126 infobar_ = NotificationPermissionInfobarDelegate::Create( |
132 GetInfoBarService(id_), requesting_frame_, | 127 GetInfoBarService(id_), requesting_frame_, callback); |
133 display_languages, callback); | |
134 break; | 128 break; |
135 #endif // ENABLE_NOTIFICATIONS | 129 #endif // ENABLE_NOTIFICATIONS |
136 case content::PermissionType::MIDI_SYSEX: | 130 case content::PermissionType::MIDI_SYSEX: |
137 infobar_ = MidiPermissionInfoBarDelegateAndroid::Create( | 131 infobar_ = MidiPermissionInfoBarDelegateAndroid::Create( |
138 GetInfoBarService(id_), requesting_frame_, display_languages, | 132 GetInfoBarService(id_), requesting_frame_, callback); |
139 callback); | |
140 break; | 133 break; |
141 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER: | 134 case content::PermissionType::PROTECTED_MEDIA_IDENTIFIER: |
142 infobar_ = ProtectedMediaIdentifierInfoBarDelegateAndroid::Create( | 135 infobar_ = ProtectedMediaIdentifierInfoBarDelegateAndroid::Create( |
143 GetInfoBarService(id_), requesting_frame_, display_languages, | 136 GetInfoBarService(id_), requesting_frame_, callback); |
144 callback); | |
145 break; | 137 break; |
146 default: | 138 default: |
147 NOTREACHED(); | 139 NOTREACHED(); |
148 break; | 140 break; |
149 } | 141 } |
150 } | 142 } |
151 | 143 |
152 PermissionQueueController::PermissionQueueController( | 144 PermissionQueueController::PermissionQueueController( |
153 Profile* profile, | 145 Profile* profile, |
154 content::PermissionType permission_type, | 146 content::PermissionType permission_type, |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 InfoBarService* infobar_service = GetInfoBarService(id); | 320 InfoBarService* infobar_service = GetInfoBarService(id); |
329 if (!infobar_service || in_shutdown_) { | 321 if (!infobar_service || in_shutdown_) { |
330 ClearPendingInfobarRequestsForTab(id); | 322 ClearPendingInfobarRequestsForTab(id); |
331 return; | 323 return; |
332 } | 324 } |
333 | 325 |
334 for (PendingInfobarRequests::iterator i = pending_infobar_requests_.begin(); | 326 for (PendingInfobarRequests::iterator i = pending_infobar_requests_.begin(); |
335 i != pending_infobar_requests_.end(); ++i) { | 327 i != pending_infobar_requests_.end(); ++i) { |
336 if (ArePermissionRequestsForSameTab(i->id(), id) && !i->has_infobar()) { | 328 if (ArePermissionRequestsForSameTab(i->id(), id) && !i->has_infobar()) { |
337 RegisterForInfoBarNotifications(infobar_service); | 329 RegisterForInfoBarNotifications(infobar_service); |
338 i->CreateInfoBar( | 330 i->CreateInfoBar(this); |
339 this, profile_->GetPrefs()->GetString(prefs::kAcceptLanguages)); | |
340 return; | 331 return; |
341 } | 332 } |
342 } | 333 } |
343 | 334 |
344 UnregisterForInfoBarNotifications(infobar_service); | 335 UnregisterForInfoBarNotifications(infobar_service); |
345 } | 336 } |
346 | 337 |
347 void PermissionQueueController::ClearPendingInfobarRequestsForTab( | 338 void PermissionQueueController::ClearPendingInfobarRequestsForTab( |
348 const PermissionRequestID& id) { | 339 const PermissionRequestID& id) { |
349 for (PendingInfobarRequests::iterator i = pending_infobar_requests_.begin(); | 340 for (PendingInfobarRequests::iterator i = pending_infobar_requests_.begin(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 } | 382 } |
392 | 383 |
393 ContentSetting content_setting = | 384 ContentSetting content_setting = |
394 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 385 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
395 | 386 |
396 HostContentSettingsMapFactory::GetForProfile(profile_) | 387 HostContentSettingsMapFactory::GetForProfile(profile_) |
397 ->SetContentSettingDefaultScope( | 388 ->SetContentSettingDefaultScope( |
398 requesting_frame.GetOrigin(), embedder.GetOrigin(), | 389 requesting_frame.GetOrigin(), embedder.GetOrigin(), |
399 content_settings_type_, std::string(), content_setting); | 390 content_settings_type_, std::string(), content_setting); |
400 } | 391 } |
OLD | NEW |