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

Side by Side Diff: chrome/browser/geolocation/chrome_geolocation_permission_context.cc

Issue 11269002: Introduce GeolocationPermissionRequestID, a wrapper struct to contain the (render process ID, rende… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/geolocation/chrome_geolocation_permission_context.h" 5 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h"
6 6
7 #include <functional> 7 #include <functional>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 21 matching lines...) Expand all
32 32
33 ChromeGeolocationPermissionContext::ChromeGeolocationPermissionContext( 33 ChromeGeolocationPermissionContext::ChromeGeolocationPermissionContext(
34 Profile* profile) 34 Profile* profile)
35 : profile_(profile) { 35 : profile_(profile) {
36 } 36 }
37 37
38 ChromeGeolocationPermissionContext::~ChromeGeolocationPermissionContext() { 38 ChromeGeolocationPermissionContext::~ChromeGeolocationPermissionContext() {
39 } 39 }
40 40
41 void ChromeGeolocationPermissionContext::RequestGeolocationPermission( 41 void ChromeGeolocationPermissionContext::RequestGeolocationPermission(
42 int render_process_id, int render_view_id, int bridge_id, 42 const content::GeolocationPermissionRequestID& id,
43 const GURL& requesting_frame, base::Callback<void(bool)> callback) { 43 const GURL& requesting_frame,
44 base::Callback<void(bool)> callback) {
44 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 45 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
45 BrowserThread::PostTask( 46 BrowserThread::PostTask(
46 BrowserThread::UI, FROM_HERE, 47 BrowserThread::UI, FROM_HERE,
47 base::Bind( 48 base::Bind(
48 &ChromeGeolocationPermissionContext::RequestGeolocationPermission, 49 &ChromeGeolocationPermissionContext::RequestGeolocationPermission,
49 this, render_process_id, render_view_id, bridge_id, 50 this, id, requesting_frame, callback));
50 requesting_frame, callback));
51 return; 51 return;
52 } 52 }
53 53
54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 54 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
55 WebContents* web_contents = 55 WebContents* web_contents =
56 tab_util::GetWebContentsByID(render_process_id, render_view_id); 56 tab_util::GetWebContentsByID(id.render_process_id, id.render_view_id);
57 if (chrome::GetViewType(web_contents) != chrome::VIEW_TYPE_TAB_CONTENTS) { 57 if (chrome::GetViewType(web_contents) != chrome::VIEW_TYPE_TAB_CONTENTS) {
58 // The tab may have gone away, or the request may not be from a tab at all. 58 // The tab may have gone away, or the request may not be from a tab at all.
59 // TODO(mpcomplete): the request could be from a background page or 59 // TODO(mpcomplete): the request could be from a background page or
60 // extension popup (tab_contents will have a different ViewType). But why do 60 // extension popup (tab_contents will have a different ViewType). But why do
61 // we care? Shouldn't we still put an infobar up in the current tab? 61 // we care? Shouldn't we still put an infobar up in the current tab?
62 LOG(WARNING) << "Attempt to use geolocation tabless renderer: " 62 LOG(WARNING) << "Attempt to use geolocation tabless renderer: "
63 << render_process_id << "," << render_view_id << "," 63 << id.ToString()
64 << bridge_id << " (can't prompt user without a visible tab)"; 64 << " (can't prompt user without a visible tab)";
65 NotifyPermissionSet(render_process_id, render_view_id, bridge_id, 65 NotifyPermissionSet(id, requesting_frame, callback, false);
66 requesting_frame, callback, false);
67 return; 66 return;
68 } 67 }
69 68
70 GURL embedder = web_contents->GetURL(); 69 GURL embedder = web_contents->GetURL();
71 if (!requesting_frame.is_valid() || !embedder.is_valid()) { 70 if (!requesting_frame.is_valid() || !embedder.is_valid()) {
72 LOG(WARNING) << "Attempt to use geolocation from an invalid URL: " 71 LOG(WARNING) << "Attempt to use geolocation from an invalid URL: "
73 << requesting_frame << "," << embedder 72 << requesting_frame << "," << embedder
74 << " (geolocation is not supported in popups)"; 73 << " (geolocation is not supported in popups)";
75 NotifyPermissionSet(render_process_id, render_view_id, bridge_id, 74 NotifyPermissionSet(id, requesting_frame, callback, false);
76 requesting_frame, callback, false);
77 return; 75 return;
78 } 76 }
79 77
80 DecidePermission(render_process_id, render_view_id, bridge_id, 78 DecidePermission(id, requesting_frame, embedder, callback);
81 requesting_frame, embedder, callback);
82 } 79 }
83 80
84 void ChromeGeolocationPermissionContext::CancelGeolocationPermissionRequest( 81 void ChromeGeolocationPermissionContext::CancelGeolocationPermissionRequest(
85 int render_process_id, 82 const content::GeolocationPermissionRequestID& id,
86 int render_view_id,
87 int bridge_id,
88 const GURL& requesting_frame) { 83 const GURL& requesting_frame) {
89 CancelPendingInfoBarRequest(render_process_id, render_view_id, bridge_id); 84 CancelPendingInfoBarRequest(id);
90 } 85 }
91 86
92 void ChromeGeolocationPermissionContext::DecidePermission( 87 void ChromeGeolocationPermissionContext::DecidePermission(
93 int render_process_id, int render_view_id, int bridge_id, 88 const content::GeolocationPermissionRequestID& id,
94 const GURL& requesting_frame, const GURL& embedder, 89 const GURL& requesting_frame,
90 const GURL& embedder,
95 base::Callback<void(bool)> callback) { 91 base::Callback<void(bool)> callback) {
96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
97 93
98 ExtensionService* extension_service = profile_->GetExtensionService(); 94 ExtensionService* extension_service = profile_->GetExtensionService();
99 if (extension_service) { 95 if (extension_service) {
100 const extensions::Extension* extension = 96 const extensions::Extension* extension =
101 extension_service->extensions()->GetExtensionOrAppByURL( 97 extension_service->extensions()->GetExtensionOrAppByURL(
102 ExtensionURLInfo( 98 ExtensionURLInfo(
103 WebSecurityOrigin::createFromString( 99 WebSecurityOrigin::createFromString(
104 UTF8ToUTF16(requesting_frame.spec())), 100 UTF8ToUTF16(requesting_frame.spec())),
105 requesting_frame)); 101 requesting_frame));
106 if (extension && 102 if (extension &&
107 extension->HasAPIPermission(extensions::APIPermission::kGeolocation)) { 103 extension->HasAPIPermission(extensions::APIPermission::kGeolocation)) {
108 // Make sure the extension is in the calling process. 104 // Make sure the extension is in the calling process.
109 if (extension_service->process_map()->Contains( 105 if (extension_service->process_map()->Contains(extension->id(),
110 extension->id(), render_process_id)) { 106 id.render_process_id)) {
111 PermissionDecided(render_process_id, render_view_id, bridge_id, 107 PermissionDecided(id, requesting_frame, embedder, callback, true);
112 requesting_frame, embedder, callback, true);
113 return; 108 return;
114 } 109 }
115 } 110 }
116 } 111 }
117 112
118 ContentSetting content_setting = 113 ContentSetting content_setting =
119 profile_->GetHostContentSettingsMap()->GetContentSetting( 114 profile_->GetHostContentSettingsMap()->GetContentSetting(
120 requesting_frame, 115 requesting_frame, embedder, CONTENT_SETTINGS_TYPE_GEOLOCATION,
121 embedder,
122 CONTENT_SETTINGS_TYPE_GEOLOCATION,
123 std::string()); 116 std::string());
124 switch (content_setting) { 117 switch (content_setting) {
125 case CONTENT_SETTING_BLOCK: 118 case CONTENT_SETTING_BLOCK:
126 PermissionDecided(render_process_id, render_view_id, bridge_id, 119 PermissionDecided(id, requesting_frame, embedder, callback, false);
127 requesting_frame, embedder, callback, false);
128 break; 120 break;
129 case CONTENT_SETTING_ALLOW: 121 case CONTENT_SETTING_ALLOW:
130 PermissionDecided(render_process_id, render_view_id, bridge_id, 122 PermissionDecided(id, requesting_frame, embedder, callback, true);
131 requesting_frame, embedder, callback, true);
132 break; 123 break;
133 default: 124 default:
134 // setting == ask. Prompt the user. 125 // setting == ask. Prompt the user.
135 QueueController()->CreateInfoBarRequest( 126 QueueController()->CreateInfoBarRequest(
136 render_process_id, render_view_id, bridge_id, requesting_frame, 127 id, requesting_frame, embedder, base::Bind(
137 embedder, base::Bind(
138 &ChromeGeolocationPermissionContext::NotifyPermissionSet, 128 &ChromeGeolocationPermissionContext::NotifyPermissionSet,
139 base::Unretained(this), 129 base::Unretained(this), id, requesting_frame, callback));
140 render_process_id, render_view_id, bridge_id, requesting_frame,
141 callback));
142 } 130 }
143 } 131 }
144 132
145 void ChromeGeolocationPermissionContext::PermissionDecided( 133 void ChromeGeolocationPermissionContext::PermissionDecided(
146 int render_process_id, 134 const content::GeolocationPermissionRequestID& id,
147 int render_view_id,
148 int bridge_id,
149 const GURL& requesting_frame, 135 const GURL& requesting_frame,
150 const GURL& embedder, 136 const GURL& embedder,
151 base::Callback<void(bool)> callback, 137 base::Callback<void(bool)> callback,
152 bool allowed) { 138 bool allowed) {
153 NotifyPermissionSet(render_process_id, render_view_id, bridge_id, 139 NotifyPermissionSet(id, requesting_frame, callback, allowed);
154 requesting_frame, callback, allowed);
155 } 140 }
156 141
157 void ChromeGeolocationPermissionContext::NotifyPermissionSet( 142 void ChromeGeolocationPermissionContext::NotifyPermissionSet(
158 int render_process_id, 143 const content::GeolocationPermissionRequestID& id,
159 int render_view_id,
160 int bridge_id,
161 const GURL& requesting_frame, 144 const GURL& requesting_frame,
162 base::Callback<void(bool)> callback, 145 base::Callback<void(bool)> callback,
163 bool allowed) { 146 bool allowed) {
164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
165 148
166 // WebContents may have gone away (or not exists for extension). 149 // WebContents may have gone away (or not exists for extension).
167 TabSpecificContentSettings* content_settings = 150 TabSpecificContentSettings* content_settings =
168 TabSpecificContentSettings::Get(render_process_id, render_view_id); 151 TabSpecificContentSettings::Get(id.render_process_id, id.render_view_id);
169 if (content_settings) { 152 if (content_settings) {
170 content_settings->OnGeolocationPermissionSet(requesting_frame.GetOrigin(), 153 content_settings->OnGeolocationPermissionSet(requesting_frame.GetOrigin(),
171 allowed); 154 allowed);
172 } 155 }
173 156
174 callback.Run(allowed); 157 callback.Run(allowed);
175 } 158 }
176 159
177 GeolocationInfoBarQueueController* 160 GeolocationInfoBarQueueController*
178 ChromeGeolocationPermissionContext::QueueController() { 161 ChromeGeolocationPermissionContext::QueueController() {
179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
180 if (!geolocation_infobar_queue_controller_) 163 if (!geolocation_infobar_queue_controller_)
181 geolocation_infobar_queue_controller_.reset(CreateQueueController()); 164 geolocation_infobar_queue_controller_.reset(CreateQueueController());
182 return geolocation_infobar_queue_controller_.get(); 165 return geolocation_infobar_queue_controller_.get();
183 } 166 }
184 167
185 GeolocationInfoBarQueueController* 168 GeolocationInfoBarQueueController*
186 ChromeGeolocationPermissionContext::CreateQueueController() { 169 ChromeGeolocationPermissionContext::CreateQueueController() {
187 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
188 return new GeolocationInfoBarQueueController(profile()); 171 return new GeolocationInfoBarQueueController(profile());
189 } 172 }
190 173
191 void ChromeGeolocationPermissionContext::CancelPendingInfoBarRequest( 174 void ChromeGeolocationPermissionContext::CancelPendingInfoBarRequest(
192 int render_process_id, 175 const content::GeolocationPermissionRequestID& id) {
193 int render_view_id,
194 int bridge_id) {
195 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) { 176 if (!BrowserThread::CurrentlyOn(BrowserThread::UI)) {
196 BrowserThread::PostTask( 177 BrowserThread::PostTask(
197 BrowserThread::UI, FROM_HERE, 178 BrowserThread::UI, FROM_HERE,
198 base::Bind( 179 base::Bind(
199 &ChromeGeolocationPermissionContext::CancelPendingInfoBarRequest, 180 &ChromeGeolocationPermissionContext::CancelPendingInfoBarRequest,
200 this, render_process_id, render_view_id, bridge_id)); 181 this, id));
201 return; 182 return;
202 } 183 }
203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
204 QueueController()->CancelInfoBarRequest( 185 QueueController()->CancelInfoBarRequest(id);
205 render_process_id,
206 render_view_id,
207 bridge_id);
208 } 186 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698