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/geolocation/geolocation_infobar_delegate.h" | 10 #include "chrome/browser/geolocation/geolocation_infobar_delegate.h" |
11 #include "chrome/browser/infobars/infobar.h" | 11 #include "chrome/browser/infobars/infobar.h" |
12 #include "chrome/browser/infobars/infobar_service.h" | 12 #include "chrome/browser/infobars/infobar_service.h" |
13 #include "chrome/browser/media/midi_permission_infobar_delegate.h" | |
13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/tab_contents/tab_util.h" | 15 #include "chrome/browser/tab_contents/tab_util.h" |
15 #include "chrome/common/content_settings.h" | 16 #include "chrome/common/content_settings.h" |
16 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
18 #include "content/public/browser/notification_details.h" | 19 #include "content/public/browser/notification_details.h" |
19 #include "content/public/browser/notification_source.h" | 20 #include "content/public/browser/notification_source.h" |
20 #include "content/public/browser/notification_types.h" | 21 #include "content/public/browser/notification_types.h" |
21 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
22 | 23 |
23 | 24 |
24 namespace { | 25 namespace { |
25 | 26 |
26 InfoBarService* GetInfoBarService(const PermissionRequestID& id) { | 27 InfoBarService* GetInfoBarService(const PermissionRequestID& id) { |
27 content::WebContents* web_contents = | 28 content::WebContents* web_contents = |
28 tab_util::GetWebContentsByID(id.render_process_id(), id.render_view_id()); | 29 tab_util::GetWebContentsByID(id.render_process_id(), id.render_view_id()); |
29 return web_contents ? InfoBarService::FromWebContents(web_contents) : NULL; | 30 return web_contents ? InfoBarService::FromWebContents(web_contents) : NULL; |
30 } | 31 } |
31 | 32 |
32 } | 33 } |
33 | 34 |
34 | 35 |
35 class PermissionQueueController::PendingInfoBarRequest { | 36 class PermissionQueueController::PendingInfoBarRequest { |
36 public: | 37 public: |
37 PendingInfoBarRequest(const PermissionRequestID& id, | 38 PendingInfoBarRequest(ContentSettingsType type, |
39 const PermissionRequestID& id, | |
38 const GURL& requesting_frame, | 40 const GURL& requesting_frame, |
39 const GURL& embedder, | 41 const GURL& embedder, |
40 PermissionDecidedCallback callback); | 42 PermissionDecidedCallback callback); |
41 ~PendingInfoBarRequest(); | 43 ~PendingInfoBarRequest(); |
42 | 44 |
43 bool IsForPair(const GURL& requesting_frame, | 45 bool IsForPair(const GURL& requesting_frame, |
44 const GURL& embedder) const; | 46 const GURL& embedder) const; |
45 | 47 |
46 const PermissionRequestID& id() const { return id_; } | 48 const PermissionRequestID& id() const { return id_; } |
47 const GURL& requesting_frame() const { return requesting_frame_; } | 49 const GURL& requesting_frame() const { return requesting_frame_; } |
48 bool has_infobar() const { return !!infobar_; } | 50 bool has_infobar() const { return !!infobar_; } |
49 InfoBarDelegate* infobar() { return infobar_; } | 51 InfoBarDelegate* infobar() { return infobar_; } |
50 | 52 |
51 void RunCallback(bool allowed); | 53 void RunCallback(bool allowed); |
52 void CreateInfoBar(PermissionQueueController* controller, | 54 void CreateInfoBar(PermissionQueueController* controller, |
53 const std::string& display_languages); | 55 const std::string& display_languages); |
54 | 56 |
55 private: | 57 private: |
58 ContentSettingsType type_; | |
56 PermissionRequestID id_; | 59 PermissionRequestID id_; |
57 GURL requesting_frame_; | 60 GURL requesting_frame_; |
58 GURL embedder_; | 61 GURL embedder_; |
59 PermissionDecidedCallback callback_; | 62 PermissionDecidedCallback callback_; |
60 InfoBarDelegate* infobar_; | 63 InfoBarDelegate* infobar_; |
61 | 64 |
62 // Purposefully do not disable copying, as this is stored in STL containers. | 65 // Purposefully do not disable copying, as this is stored in STL containers. |
63 }; | 66 }; |
64 | 67 |
65 PermissionQueueController::PendingInfoBarRequest::PendingInfoBarRequest( | 68 PermissionQueueController::PendingInfoBarRequest::PendingInfoBarRequest( |
69 ContentSettingsType type, | |
66 const PermissionRequestID& id, | 70 const PermissionRequestID& id, |
67 const GURL& requesting_frame, | 71 const GURL& requesting_frame, |
68 const GURL& embedder, | 72 const GURL& embedder, |
69 PermissionDecidedCallback callback) | 73 PermissionDecidedCallback callback) |
70 : id_(id), | 74 : type_(type), |
75 id_(id), | |
71 requesting_frame_(requesting_frame), | 76 requesting_frame_(requesting_frame), |
72 embedder_(embedder), | 77 embedder_(embedder), |
73 callback_(callback), | 78 callback_(callback), |
74 infobar_(NULL) { | 79 infobar_(NULL) { |
75 } | 80 } |
76 | 81 |
77 PermissionQueueController::PendingInfoBarRequest::~PendingInfoBarRequest() { | 82 PermissionQueueController::PendingInfoBarRequest::~PendingInfoBarRequest() { |
78 } | 83 } |
79 | 84 |
80 bool PermissionQueueController::PendingInfoBarRequest::IsForPair( | 85 bool PermissionQueueController::PendingInfoBarRequest::IsForPair( |
81 const GURL& requesting_frame, | 86 const GURL& requesting_frame, |
82 const GURL& embedder) const { | 87 const GURL& embedder) const { |
83 return (requesting_frame_ == requesting_frame) && (embedder_ == embedder); | 88 return (requesting_frame_ == requesting_frame) && (embedder_ == embedder); |
84 } | 89 } |
85 | 90 |
86 void PermissionQueueController::PendingInfoBarRequest::RunCallback( | 91 void PermissionQueueController::PendingInfoBarRequest::RunCallback( |
87 bool allowed) { | 92 bool allowed) { |
88 callback_.Run(allowed); | 93 callback_.Run(allowed); |
89 } | 94 } |
90 | 95 |
91 void PermissionQueueController::PendingInfoBarRequest::CreateInfoBar( | 96 void PermissionQueueController::PendingInfoBarRequest::CreateInfoBar( |
92 PermissionQueueController* controller, | 97 PermissionQueueController* controller, |
93 const std::string& display_languages) { | 98 const std::string& display_languages) { |
94 // TODO(toyoshim): Remove following dependency on geolocation. | 99 switch (type_) { |
scherkus (not reviewing)
2013/07/31 18:09:55
is this TODO actually fixed?
Takashi Toyoshima
2013/08/01 08:27:38
OK, I keep this TODO here and will handle later in
| |
95 infobar_ = GeolocationInfoBarDelegate::Create( | 100 case CONTENT_SETTINGS_TYPE_GEOLOCATION: |
96 GetInfoBarService(id_), controller, id_, requesting_frame_, | 101 infobar_ = GeolocationInfoBarDelegate::Create( |
97 display_languages); | 102 GetInfoBarService(id_), controller, id_, requesting_frame_, |
103 display_languages); | |
104 break; | |
105 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX: | |
106 infobar_ = MIDIPermissionInfoBarDelegate::Create( | |
107 GetInfoBarService(id_), controller, id_, requesting_frame_, | |
108 display_languages); | |
109 break; | |
110 default: | |
111 NOTREACHED(); | |
112 break; | |
113 } | |
98 } | 114 } |
99 | 115 |
100 | 116 |
101 PermissionQueueController::PermissionQueueController(Profile* profile, | 117 PermissionQueueController::PermissionQueueController(Profile* profile, |
102 ContentSettingsType type) | 118 ContentSettingsType type) |
103 : profile_(profile), | 119 : profile_(profile), |
104 type_(type), | 120 type_(type), |
105 in_shutdown_(false) { | 121 in_shutdown_(false) { |
106 } | 122 } |
107 | 123 |
(...skipping 11 matching lines...) Expand all Loading... | |
119 PermissionDecidedCallback callback) { | 135 PermissionDecidedCallback callback) { |
120 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 136 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
121 | 137 |
122 // We shouldn't get duplicate requests. | 138 // We shouldn't get duplicate requests. |
123 for (PendingInfoBarRequests::const_iterator i( | 139 for (PendingInfoBarRequests::const_iterator i( |
124 pending_infobar_requests_.begin()); | 140 pending_infobar_requests_.begin()); |
125 i != pending_infobar_requests_.end(); ++i) | 141 i != pending_infobar_requests_.end(); ++i) |
126 DCHECK(!i->id().Equals(id)); | 142 DCHECK(!i->id().Equals(id)); |
127 | 143 |
128 pending_infobar_requests_.push_back(PendingInfoBarRequest( | 144 pending_infobar_requests_.push_back(PendingInfoBarRequest( |
129 id, requesting_frame, embedder, callback)); | 145 type_, id, requesting_frame, embedder, callback)); |
130 if (!AlreadyShowingInfoBarForTab(id)) | 146 if (!AlreadyShowingInfoBarForTab(id)) |
131 ShowQueuedInfoBarForTab(id); | 147 ShowQueuedInfoBarForTab(id); |
132 } | 148 } |
133 | 149 |
134 void PermissionQueueController::CancelInfoBarRequest( | 150 void PermissionQueueController::CancelInfoBarRequest( |
135 const PermissionRequestID& id) { | 151 const PermissionRequestID& id) { |
136 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 152 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
137 | 153 |
138 for (PendingInfoBarRequests::iterator i(pending_infobar_requests_.begin()); | 154 for (PendingInfoBarRequests::iterator i(pending_infobar_requests_.begin()); |
139 i != pending_infobar_requests_.end(); ++i) { | 155 i != pending_infobar_requests_.end(); ++i) { |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
315 | 331 |
316 ContentSetting content_setting = | 332 ContentSetting content_setting = |
317 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; | 333 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
318 profile_->GetHostContentSettingsMap()->SetContentSetting( | 334 profile_->GetHostContentSettingsMap()->SetContentSetting( |
319 ContentSettingsPattern::FromURLNoWildcard(requesting_frame.GetOrigin()), | 335 ContentSettingsPattern::FromURLNoWildcard(requesting_frame.GetOrigin()), |
320 ContentSettingsPattern::FromURLNoWildcard(embedder.GetOrigin()), | 336 ContentSettingsPattern::FromURLNoWildcard(embedder.GetOrigin()), |
321 type_, | 337 type_, |
322 std::string(), | 338 std::string(), |
323 content_setting); | 339 content_setting); |
324 } | 340 } |
OLD | NEW |