Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: chrome/browser/content_settings/permission_queue_controller.cc

Issue 20990005: Web MIDI: implement permission infobar (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review #2 and #10 Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // TODO(toyoshim): Remove following ContentType dependent code.
95 infobar_ = GeolocationInfoBarDelegate::Create( 100 // Also these InfoBarDelegate can share much more code each other.
96 GetInfoBarService(id_), controller, id_, requesting_frame_, 101 // http://crbug.com/266743
97 display_languages); 102 switch (type_) {
103 case CONTENT_SETTINGS_TYPE_GEOLOCATION:
104 infobar_ = GeolocationInfoBarDelegate::Create(
105 GetInfoBarService(id_), controller, id_, requesting_frame_,
106 display_languages);
107 break;
108 case CONTENT_SETTINGS_TYPE_MIDI_SYSEX:
109 infobar_ = MIDIPermissionInfoBarDelegate::Create(
110 GetInfoBarService(id_), controller, id_, requesting_frame_,
111 display_languages);
112 break;
113 default:
114 NOTREACHED();
115 break;
116 }
98 } 117 }
99 118
100 119
101 PermissionQueueController::PermissionQueueController(Profile* profile, 120 PermissionQueueController::PermissionQueueController(Profile* profile,
102 ContentSettingsType type) 121 ContentSettingsType type)
103 : profile_(profile), 122 : profile_(profile),
104 type_(type), 123 type_(type),
105 in_shutdown_(false) { 124 in_shutdown_(false) {
106 } 125 }
107 126
(...skipping 11 matching lines...) Expand all
119 PermissionDecidedCallback callback) { 138 PermissionDecidedCallback callback) {
120 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 139 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
121 140
122 // We shouldn't get duplicate requests. 141 // We shouldn't get duplicate requests.
123 for (PendingInfoBarRequests::const_iterator i( 142 for (PendingInfoBarRequests::const_iterator i(
124 pending_infobar_requests_.begin()); 143 pending_infobar_requests_.begin());
125 i != pending_infobar_requests_.end(); ++i) 144 i != pending_infobar_requests_.end(); ++i)
126 DCHECK(!i->id().Equals(id)); 145 DCHECK(!i->id().Equals(id));
127 146
128 pending_infobar_requests_.push_back(PendingInfoBarRequest( 147 pending_infobar_requests_.push_back(PendingInfoBarRequest(
129 id, requesting_frame, embedder, callback)); 148 type_, id, requesting_frame, embedder, callback));
130 if (!AlreadyShowingInfoBarForTab(id)) 149 if (!AlreadyShowingInfoBarForTab(id))
131 ShowQueuedInfoBarForTab(id); 150 ShowQueuedInfoBarForTab(id);
132 } 151 }
133 152
134 void PermissionQueueController::CancelInfoBarRequest( 153 void PermissionQueueController::CancelInfoBarRequest(
135 const PermissionRequestID& id) { 154 const PermissionRequestID& id) {
136 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 155 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
137 156
138 for (PendingInfoBarRequests::iterator i(pending_infobar_requests_.begin()); 157 for (PendingInfoBarRequests::iterator i(pending_infobar_requests_.begin());
139 i != pending_infobar_requests_.end(); ++i) { 158 i != pending_infobar_requests_.end(); ++i) {
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 334
316 ContentSetting content_setting = 335 ContentSetting content_setting =
317 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; 336 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK;
318 profile_->GetHostContentSettingsMap()->SetContentSetting( 337 profile_->GetHostContentSettingsMap()->SetContentSetting(
319 ContentSettingsPattern::FromURLNoWildcard(requesting_frame.GetOrigin()), 338 ContentSettingsPattern::FromURLNoWildcard(requesting_frame.GetOrigin()),
320 ContentSettingsPattern::FromURLNoWildcard(embedder.GetOrigin()), 339 ContentSettingsPattern::FromURLNoWildcard(embedder.GetOrigin()),
321 type_, 340 type_,
322 std::string(), 341 std::string(),
323 content_setting); 342 content_setting);
324 } 343 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698