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/content_settings/permission_queue_controller.h" | 5 #include "chrome/browser/content_settings/permission_queue_controller.h" |
6 | 6 |
7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.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.h" | 9 #include "chrome/browser/content_settings/host_content_settings_map.h" |
10 #include "chrome/browser/content_settings/permission_context_uma_util.h" | 10 #include "chrome/browser/content_settings/permission_context_uma_util.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 | 39 |
40 } | 40 } |
41 | 41 |
42 | 42 |
43 class PermissionQueueController::PendingInfobarRequest { | 43 class PermissionQueueController::PendingInfobarRequest { |
44 public: | 44 public: |
45 PendingInfobarRequest(ContentSettingsType type, | 45 PendingInfobarRequest(ContentSettingsType type, |
46 const PermissionRequestID& id, | 46 const PermissionRequestID& id, |
47 const GURL& requesting_frame, | 47 const GURL& requesting_frame, |
48 const GURL& embedder, | 48 const GURL& embedder, |
49 const std::string& accept_button_label, | |
50 PermissionDecidedCallback callback); | 49 PermissionDecidedCallback callback); |
51 ~PendingInfobarRequest(); | 50 ~PendingInfobarRequest(); |
52 | 51 |
53 bool IsForPair(const GURL& requesting_frame, | 52 bool IsForPair(const GURL& requesting_frame, |
54 const GURL& embedder) const; | 53 const GURL& embedder) const; |
55 | 54 |
56 const PermissionRequestID& id() const { return id_; } | 55 const PermissionRequestID& id() const { return id_; } |
57 const GURL& requesting_frame() const { return requesting_frame_; } | 56 const GURL& requesting_frame() const { return requesting_frame_; } |
58 bool has_infobar() const { return !!infobar_; } | 57 bool has_infobar() const { return !!infobar_; } |
59 infobars::InfoBar* infobar() { return infobar_; } | 58 infobars::InfoBar* infobar() { return infobar_; } |
60 | 59 |
61 void RunCallback(bool allowed); | 60 void RunCallback(bool allowed); |
62 void CreateInfoBar(PermissionQueueController* controller, | 61 void CreateInfoBar(PermissionQueueController* controller, |
63 const std::string& display_languages); | 62 const std::string& display_languages); |
64 | 63 |
65 private: | 64 private: |
66 ContentSettingsType type_; | 65 ContentSettingsType type_; |
67 PermissionRequestID id_; | 66 PermissionRequestID id_; |
68 GURL requesting_frame_; | 67 GURL requesting_frame_; |
69 GURL embedder_; | 68 GURL embedder_; |
70 std::string accept_button_label_; | |
71 PermissionDecidedCallback callback_; | 69 PermissionDecidedCallback callback_; |
72 infobars::InfoBar* infobar_; | 70 infobars::InfoBar* infobar_; |
73 | 71 |
74 // Purposefully do not disable copying, as this is stored in STL containers. | 72 // Purposefully do not disable copying, as this is stored in STL containers. |
75 }; | 73 }; |
76 | 74 |
77 PermissionQueueController::PendingInfobarRequest::PendingInfobarRequest( | 75 PermissionQueueController::PendingInfobarRequest::PendingInfobarRequest( |
78 ContentSettingsType type, | 76 ContentSettingsType type, |
79 const PermissionRequestID& id, | 77 const PermissionRequestID& id, |
80 const GURL& requesting_frame, | 78 const GURL& requesting_frame, |
81 const GURL& embedder, | 79 const GURL& embedder, |
82 const std::string& accept_button_label, | |
83 PermissionDecidedCallback callback) | 80 PermissionDecidedCallback callback) |
84 : type_(type), | 81 : type_(type), |
85 id_(id), | 82 id_(id), |
86 requesting_frame_(requesting_frame), | 83 requesting_frame_(requesting_frame), |
87 embedder_(embedder), | 84 embedder_(embedder), |
88 accept_button_label_(accept_button_label), | |
89 callback_(callback), | 85 callback_(callback), |
90 infobar_(NULL) { | 86 infobar_(NULL) { |
91 } | 87 } |
92 | 88 |
93 PermissionQueueController::PendingInfobarRequest::~PendingInfobarRequest() { | 89 PermissionQueueController::PendingInfobarRequest::~PendingInfobarRequest() { |
94 } | 90 } |
95 | 91 |
96 bool PermissionQueueController::PendingInfobarRequest::IsForPair( | 92 bool PermissionQueueController::PendingInfobarRequest::IsForPair( |
97 const GURL& requesting_frame, | 93 const GURL& requesting_frame, |
98 const GURL& embedder) const { | 94 const GURL& embedder) const { |
99 return (requesting_frame_ == requesting_frame) && (embedder_ == embedder); | 95 return (requesting_frame_ == requesting_frame) && (embedder_ == embedder); |
100 } | 96 } |
101 | 97 |
102 void PermissionQueueController::PendingInfobarRequest::RunCallback( | 98 void PermissionQueueController::PendingInfobarRequest::RunCallback( |
103 bool allowed) { | 99 bool allowed) { |
104 callback_.Run(allowed); | 100 callback_.Run(allowed); |
105 } | 101 } |
106 | 102 |
107 void PermissionQueueController::PendingInfobarRequest::CreateInfoBar( | 103 void PermissionQueueController::PendingInfobarRequest::CreateInfoBar( |
108 PermissionQueueController* controller, | 104 PermissionQueueController* controller, |
109 const std::string& display_languages) { | 105 const std::string& display_languages) { |
110 switch (type_) { | 106 switch (type_) { |
111 case CONTENT_SETTINGS_TYPE_GEOLOCATION: | 107 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
112 infobar_ = GeolocationInfoBarDelegate::Create( | 108 infobar_ = GeolocationInfoBarDelegate::Create( |
113 GetInfoBarService(id_), controller, id_, requesting_frame_, | 109 GetInfoBarService(id_), controller, id_, requesting_frame_, |
114 display_languages, accept_button_label_); | 110 display_languages); |
115 break; | 111 break; |
116 #if defined(ENABLE_NOTIFICATIONS) | 112 #if defined(ENABLE_NOTIFICATIONS) |
117 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: | 113 case CONTENT_SETTINGS_TYPE_NOTIFICATIONS: |
118 infobar_ = DesktopNotificationInfoBarDelegate::Create( | 114 infobar_ = DesktopNotificationInfoBarDelegate::Create( |
119 GetInfoBarService(id_), controller, id_, requesting_frame_, | 115 GetInfoBarService(id_), controller, id_, requesting_frame_, |
120 display_languages); | 116 display_languages); |
121 break; | 117 break; |
122 #endif // ENABLE_NOTIFICATIONS | 118 #endif // ENABLE_NOTIFICATIONS |
123 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: | 119 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: |
124 infobar_ = MidiPermissionInfoBarDelegate::Create( | 120 infobar_ = MidiPermissionInfoBarDelegate::Create( |
(...skipping 30 matching lines...) Expand all Loading... |
155 // Cancel all outstanding requests. | 151 // Cancel all outstanding requests. |
156 in_shutdown_ = true; | 152 in_shutdown_ = true; |
157 while (!pending_infobar_requests_.empty()) | 153 while (!pending_infobar_requests_.empty()) |
158 CancelInfoBarRequest(pending_infobar_requests_.front().id()); | 154 CancelInfoBarRequest(pending_infobar_requests_.front().id()); |
159 } | 155 } |
160 | 156 |
161 void PermissionQueueController::CreateInfoBarRequest( | 157 void PermissionQueueController::CreateInfoBarRequest( |
162 const PermissionRequestID& id, | 158 const PermissionRequestID& id, |
163 const GURL& requesting_frame, | 159 const GURL& requesting_frame, |
164 const GURL& embedder, | 160 const GURL& embedder, |
165 const std::string& accept_button_label, | |
166 PermissionDecidedCallback callback) { | 161 PermissionDecidedCallback callback) { |
167 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 162 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
168 | 163 |
169 if (requesting_frame.SchemeIs(content::kChromeUIScheme) || | 164 if (requesting_frame.SchemeIs(content::kChromeUIScheme) || |
170 embedder.SchemeIs(content::kChromeUIScheme)) | 165 embedder.SchemeIs(content::kChromeUIScheme)) |
171 return; | 166 return; |
172 | 167 |
173 pending_infobar_requests_.push_back(PendingInfobarRequest( | 168 pending_infobar_requests_.push_back(PendingInfobarRequest( |
174 type_, id, requesting_frame, embedder, | 169 type_, id, requesting_frame, embedder, callback)); |
175 accept_button_label, callback)); | |
176 if (!AlreadyShowingInfoBarForTab(id)) | 170 if (!AlreadyShowingInfoBarForTab(id)) |
177 ShowQueuedInfoBarForTab(id); | 171 ShowQueuedInfoBarForTab(id); |
178 } | 172 } |
179 | 173 |
180 void PermissionQueueController::CancelInfoBarRequest( | 174 void PermissionQueueController::CancelInfoBarRequest( |
181 const PermissionRequestID& id) { | 175 const PermissionRequestID& id) { |
182 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 176 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
183 | 177 |
184 for (PendingInfobarRequests::iterator i(pending_infobar_requests_.begin()); | 178 for (PendingInfobarRequests::iterator i(pending_infobar_requests_.begin()); |
185 i != pending_infobar_requests_.end(); ++i) { | 179 i != pending_infobar_requests_.end(); ++i) { |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 | 369 |
376 ContentSetting content_setting = | 370 ContentSetting content_setting = |
377 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 371 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
378 profile_->GetHostContentSettingsMap()->SetContentSetting( | 372 profile_->GetHostContentSettingsMap()->SetContentSetting( |
379 ContentSettingsPattern::FromURLNoWildcard(requesting_frame.GetOrigin()), | 373 ContentSettingsPattern::FromURLNoWildcard(requesting_frame.GetOrigin()), |
380 ContentSettingsPattern::FromURLNoWildcard(embedder.GetOrigin()), | 374 ContentSettingsPattern::FromURLNoWildcard(embedder.GetOrigin()), |
381 type_, | 375 type_, |
382 std::string(), | 376 std::string(), |
383 content_setting); | 377 content_setting); |
384 } | 378 } |
OLD | NEW |