OLD | NEW |
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 13 matching lines...) Expand all Loading... |
24 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
25 #include "content/public/browser/render_view_host.h" | 25 #include "content/public/browser/render_view_host.h" |
26 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
27 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" | 27 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h" |
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebSecurityOrigin.h" |
29 | 29 |
30 using extensions::APIPermission; | 30 using extensions::APIPermission; |
31 | 31 |
32 ChromeGeolocationPermissionContext::ChromeGeolocationPermissionContext( | 32 ChromeGeolocationPermissionContext::ChromeGeolocationPermissionContext( |
33 Profile* profile) | 33 Profile* profile) |
34 : profile_(profile) { | 34 : profile_(profile), |
| 35 shutting_down_(false) { |
35 } | 36 } |
36 | 37 |
37 ChromeGeolocationPermissionContext::~ChromeGeolocationPermissionContext() { | 38 ChromeGeolocationPermissionContext::~ChromeGeolocationPermissionContext() { |
| 39 // ChromeGeolocationPermissionContext may be destroyed on either the UI thread |
| 40 // or the IO thread, but the GeolocationInfobarQueueController must have been |
| 41 // destroyed on the UI thread. |
| 42 DCHECK(!geolocation_infobar_queue_controller_.get()); |
38 } | 43 } |
39 | 44 |
40 void ChromeGeolocationPermissionContext::RequestGeolocationPermission( | 45 void ChromeGeolocationPermissionContext::RequestGeolocationPermission( |
41 int render_process_id, | 46 int render_process_id, |
42 int render_view_id, | 47 int render_view_id, |
43 int bridge_id, | 48 int bridge_id, |
44 const GURL& requesting_frame, | 49 const GURL& requesting_frame, |
45 base::Callback<void(bool)> callback) { | 50 base::Callback<void(bool)> callback) { |
46 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { | 51 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { |
47 content::BrowserThread::PostTask( | 52 content::BrowserThread::PostTask( |
48 content::BrowserThread::UI, FROM_HERE, | 53 content::BrowserThread::UI, FROM_HERE, |
49 base::Bind( | 54 base::Bind( |
50 &ChromeGeolocationPermissionContext::RequestGeolocationPermission, | 55 &ChromeGeolocationPermissionContext::RequestGeolocationPermission, |
51 this, render_process_id, render_view_id, bridge_id, | 56 this, render_process_id, render_view_id, bridge_id, |
52 requesting_frame, callback)); | 57 requesting_frame, callback)); |
53 return; | 58 return; |
54 } | 59 } |
55 | 60 |
56 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 61 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 62 if (shutting_down_) |
| 63 return; |
| 64 |
57 content::WebContents* web_contents = | 65 content::WebContents* web_contents = |
58 tab_util::GetWebContentsByID(render_process_id, render_view_id); | 66 tab_util::GetWebContentsByID(render_process_id, render_view_id); |
59 const GeolocationPermissionRequestID id(render_process_id, render_view_id, | 67 const GeolocationPermissionRequestID id(render_process_id, render_view_id, |
60 bridge_id); | 68 bridge_id); |
61 ExtensionService* extension_service = | 69 ExtensionService* extension_service = |
62 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 70 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
63 if (extension_service) { | 71 if (extension_service) { |
64 const extensions::Extension* extension = | 72 const extensions::Extension* extension = |
65 extension_service->extensions()->GetExtensionOrAppByURL( | 73 extension_service->extensions()->GetExtensionOrAppByURL( |
66 ExtensionURLInfo(WebKit::WebSecurityOrigin::createFromString( | 74 ExtensionURLInfo(WebKit::WebSecurityOrigin::createFromString( |
(...skipping 26 matching lines...) Expand all Loading... |
93 GURL embedder = web_contents->GetURL(); | 101 GURL embedder = web_contents->GetURL(); |
94 if (!requesting_frame.is_valid() || !embedder.is_valid()) { | 102 if (!requesting_frame.is_valid() || !embedder.is_valid()) { |
95 LOG(WARNING) << "Attempt to use geolocation from an invalid URL: " | 103 LOG(WARNING) << "Attempt to use geolocation from an invalid URL: " |
96 << requesting_frame << "," << embedder | 104 << requesting_frame << "," << embedder |
97 << " (geolocation is not supported in popups)"; | 105 << " (geolocation is not supported in popups)"; |
98 NotifyPermissionSet(id, requesting_frame, callback, false); | 106 NotifyPermissionSet(id, requesting_frame, callback, false); |
99 return; | 107 return; |
100 } | 108 } |
101 | 109 |
102 DecidePermission(id, requesting_frame, embedder, callback); | 110 DecidePermission(id, requesting_frame, embedder, callback); |
103 | |
104 } | 111 } |
105 | 112 |
106 void ChromeGeolocationPermissionContext::CancelGeolocationPermissionRequest( | 113 void ChromeGeolocationPermissionContext::CancelGeolocationPermissionRequest( |
107 int render_process_id, | 114 int render_process_id, |
108 int render_view_id, | 115 int render_view_id, |
109 int bridge_id, | 116 int bridge_id, |
110 const GURL& requesting_frame) { | 117 const GURL& requesting_frame) { |
111 CancelPendingInfoBarRequest(GeolocationPermissionRequestID( | 118 CancelPendingInfoBarRequest(GeolocationPermissionRequestID( |
112 render_process_id, render_view_id, bridge_id)); | 119 render_process_id, render_view_id, bridge_id)); |
113 } | 120 } |
(...skipping 18 matching lines...) Expand all Loading... |
132 break; | 139 break; |
133 default: | 140 default: |
134 // setting == ask. Prompt the user. | 141 // setting == ask. Prompt the user. |
135 QueueController()->CreateInfoBarRequest( | 142 QueueController()->CreateInfoBarRequest( |
136 id, requesting_frame, embedder, base::Bind( | 143 id, requesting_frame, embedder, base::Bind( |
137 &ChromeGeolocationPermissionContext::NotifyPermissionSet, | 144 &ChromeGeolocationPermissionContext::NotifyPermissionSet, |
138 base::Unretained(this), id, requesting_frame, callback)); | 145 base::Unretained(this), id, requesting_frame, callback)); |
139 } | 146 } |
140 } | 147 } |
141 | 148 |
| 149 void ChromeGeolocationPermissionContext::ShutdownOnUIThread() { |
| 150 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 151 geolocation_infobar_queue_controller_.reset(); |
| 152 shutting_down_ = true; |
| 153 } |
| 154 |
142 void ChromeGeolocationPermissionContext::PermissionDecided( | 155 void ChromeGeolocationPermissionContext::PermissionDecided( |
143 const GeolocationPermissionRequestID& id, | 156 const GeolocationPermissionRequestID& id, |
144 const GURL& requesting_frame, | 157 const GURL& requesting_frame, |
145 const GURL& embedder, | 158 const GURL& embedder, |
146 base::Callback<void(bool)> callback, | 159 base::Callback<void(bool)> callback, |
147 bool allowed) { | 160 bool allowed) { |
148 NotifyPermissionSet(id, requesting_frame, callback, allowed); | 161 NotifyPermissionSet(id, requesting_frame, callback, allowed); |
149 } | 162 } |
150 | 163 |
151 void ChromeGeolocationPermissionContext::NotifyPermissionSet( | 164 void ChromeGeolocationPermissionContext::NotifyPermissionSet( |
(...skipping 11 matching lines...) Expand all Loading... |
163 content_settings->OnGeolocationPermissionSet(requesting_frame.GetOrigin(), | 176 content_settings->OnGeolocationPermissionSet(requesting_frame.GetOrigin(), |
164 allowed); | 177 allowed); |
165 } | 178 } |
166 | 179 |
167 callback.Run(allowed); | 180 callback.Run(allowed); |
168 } | 181 } |
169 | 182 |
170 GeolocationInfoBarQueueController* | 183 GeolocationInfoBarQueueController* |
171 ChromeGeolocationPermissionContext::QueueController() { | 184 ChromeGeolocationPermissionContext::QueueController() { |
172 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 185 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 186 DCHECK(!shutting_down_); |
173 if (!geolocation_infobar_queue_controller_) | 187 if (!geolocation_infobar_queue_controller_) |
174 geolocation_infobar_queue_controller_.reset(CreateQueueController()); | 188 geolocation_infobar_queue_controller_.reset(CreateQueueController()); |
175 return geolocation_infobar_queue_controller_.get(); | 189 return geolocation_infobar_queue_controller_.get(); |
176 } | 190 } |
177 | 191 |
178 GeolocationInfoBarQueueController* | 192 GeolocationInfoBarQueueController* |
179 ChromeGeolocationPermissionContext::CreateQueueController() { | 193 ChromeGeolocationPermissionContext::CreateQueueController() { |
180 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 194 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
181 return new GeolocationInfoBarQueueController(profile()); | 195 return new GeolocationInfoBarQueueController(profile()); |
182 } | 196 } |
183 | 197 |
184 void ChromeGeolocationPermissionContext::CancelPendingInfoBarRequest( | 198 void ChromeGeolocationPermissionContext::CancelPendingInfoBarRequest( |
185 const GeolocationPermissionRequestID& id) { | 199 const GeolocationPermissionRequestID& id) { |
186 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { | 200 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) { |
187 content::BrowserThread::PostTask( | 201 content::BrowserThread::PostTask( |
188 content::BrowserThread::UI, FROM_HERE, | 202 content::BrowserThread::UI, FROM_HERE, |
189 base::Bind( | 203 base::Bind( |
190 &ChromeGeolocationPermissionContext::CancelPendingInfoBarRequest, | 204 &ChromeGeolocationPermissionContext::CancelPendingInfoBarRequest, |
191 this, id)); | 205 this, id)); |
192 return; | 206 return; |
193 } | 207 } |
194 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 208 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 209 if (shutting_down_) |
| 210 return; |
195 QueueController()->CancelInfoBarRequest(id); | 211 QueueController()->CancelInfoBarRequest(id); |
196 } | 212 } |
OLD | NEW |