| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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/geolocation_permission_context_android.h" | 5 #include "chrome/browser/geolocation/geolocation_permission_context_android.h" |
| 6 | 6 |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "chrome/browser/android/google_location_settings_helper.h" | 8 #include "chrome/browser/android/google_location_settings_helper.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/common/pref_names.h" | 10 #include "chrome/common/pref_names.h" |
| 11 #include "content/public/browser/browser_thread.h" | 11 #include "content/public/browser/browser_thread.h" |
| 12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 13 | 13 |
| 14 GeolocationPermissionContextAndroid:: | 14 GeolocationPermissionContextAndroid:: |
| 15 PermissionRequestInfo::PermissionRequestInfo() | 15 PermissionRequestInfo::PermissionRequestInfo() |
| 16 : id(0, 0, 0, GURL()), | 16 : id(0, 0, 0, GURL()), |
| 17 user_gesture(false) {} | 17 user_gesture(false) { |
| 18 } |
| 18 | 19 |
| 19 GeolocationPermissionContextAndroid:: | 20 GeolocationPermissionContextAndroid:: |
| 20 GeolocationPermissionContextAndroid(Profile* profile) | 21 GeolocationPermissionContextAndroid(Profile* profile) |
| 21 : GeolocationPermissionContext(profile), | 22 : GeolocationPermissionContext(profile), |
| 22 google_location_settings_helper_( | 23 google_location_settings_helper_( |
| 23 GoogleLocationSettingsHelper::Create()) { | 24 GoogleLocationSettingsHelper::Create()), |
| 25 weak_factory_(this) { |
| 24 } | 26 } |
| 25 | 27 |
| 26 GeolocationPermissionContextAndroid::~GeolocationPermissionContextAndroid() { | 28 GeolocationPermissionContextAndroid::~GeolocationPermissionContextAndroid() { |
| 27 } | 29 } |
| 28 | 30 |
| 29 void GeolocationPermissionContextAndroid::ProceedDecidePermission( | 31 void GeolocationPermissionContextAndroid::ProceedDecidePermission( |
| 30 content::WebContents* web_contents, | 32 content::WebContents* web_contents, |
| 31 const PermissionRequestInfo& info, | 33 const PermissionRequestInfo& info, |
| 32 base::Callback<void(bool)> callback) { | 34 base::Callback<void(bool)> callback) { |
| 33 // Super class implementation expects everything in UI thread instead. | 35 |
| 34 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 36 // The super class implementation expects everything in UI thread. |
| 35 GeolocationPermissionContext::DecidePermission( | 37 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 36 web_contents, info.id, info.requesting_frame, info.user_gesture, | 38 GeolocationPermissionContext::RequestPermission( |
| 37 info.embedder, callback); | 39 web_contents, info.id, |
| 40 info.requesting_origin, |
| 41 info.user_gesture, |
| 42 callback); |
| 38 } | 43 } |
| 39 | 44 |
| 40 void GeolocationPermissionContextAndroid::CheckSystemLocation( | 45 |
| 46 // UI thread |
| 47 void GeolocationPermissionContextAndroid::RequestPermission( |
| 48 content::WebContents* web_contents, |
| 49 const PermissionRequestID& id, |
| 50 const GURL& requesting_frame_origin, |
| 51 bool user_gesture, |
| 52 const BrowserPermissionCallback& callback) { |
| 53 PermissionRequestInfo info; |
| 54 info.id = id; |
| 55 info.requesting_origin = requesting_frame_origin; |
| 56 info.embedder_origin = web_contents->GetLastCommittedURL().GetOrigin(); |
| 57 info.user_gesture = user_gesture; |
| 58 |
| 59 // Called on the UI thread. However, do the work on a separate thread |
| 60 // to avoid strict mode violation. |
| 61 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 62 content::BrowserThread::PostBlockingPoolTask(FROM_HERE, |
| 63 base::Bind( |
| 64 &GeolocationPermissionContextAndroid::CheckMasterLocation, |
| 65 weak_factory_.GetWeakPtr(), web_contents, info, callback)); |
| 66 } |
| 67 |
| 68 // Blocking pool thread |
| 69 void GeolocationPermissionContextAndroid::CheckMasterLocation( |
| 41 content::WebContents* web_contents, | 70 content::WebContents* web_contents, |
| 42 const PermissionRequestInfo& info, | 71 const PermissionRequestInfo& info, |
| 43 base::Callback<void(bool)> callback) { | 72 const BrowserPermissionCallback& callback) { |
| 44 // Check to see if the feature in its entirety has been disabled. | 73 // Check to see if the feature in its entirety has been disabled. |
| 45 // This must happen before other services (e.g. tabs, extensions) | 74 // This must happen before other services (e.g. tabs, extensions) |
| 46 // get an opportunity to allow the geolocation request. | 75 // get an opportunity to allow the geolocation request. |
| 47 bool enabled = google_location_settings_helper_->IsSystemLocationEnabled(); | 76 bool enabled = |
| 77 google_location_settings_helper_->IsSystemLocationEnabled(); |
| 48 | 78 |
| 49 base::Closure ui_closure; | 79 base::Closure ui_closure; |
| 50 if (enabled) { | 80 if (enabled) { |
| 51 ui_closure = base::Bind( | 81 ui_closure = base::Bind( |
| 52 &GeolocationPermissionContextAndroid::ProceedDecidePermission, | 82 &GeolocationPermissionContextAndroid::ProceedDecidePermission, |
| 53 this, web_contents, info, callback); | 83 base::Unretained(this), web_contents, info, callback); |
| 54 } else { | 84 } else { |
| 55 ui_closure = base::Bind( | 85 ui_closure = base::Bind( |
| 56 &GeolocationPermissionContextAndroid::PermissionDecided, | 86 &GeolocationPermissionContextAndroid::PermissionDecided, |
| 57 this, info.id, info.requesting_frame, info.embedder, callback, false); | 87 base::Unretained(this), info.id, info.requesting_origin, |
| 88 info.embedder_origin, callback, false, false); |
| 58 } | 89 } |
| 59 | 90 |
| 60 // This method is executed from the BlockingPool, post the result | 91 // This method is executed from the BlockingPool, post the result |
| 61 // back to the UI thread. | 92 // back to the UI thread. |
| 62 content::BrowserThread::PostTask( | 93 content::BrowserThread::PostTask( |
| 63 content::BrowserThread::UI, FROM_HERE, ui_closure); | 94 content::BrowserThread::UI, FROM_HERE, ui_closure); |
| 64 } | 95 } |
| 65 | 96 |
| 66 void GeolocationPermissionContextAndroid::DecidePermission( | |
| 67 content::WebContents* web_contents, | |
| 68 const PermissionRequestID& id, | |
| 69 const GURL& requesting_frame, | |
| 70 bool user_gesture, | |
| 71 const GURL& embedder, | |
| 72 base::Callback<void(bool)> callback) { | |
| 73 | 97 |
| 74 PermissionRequestInfo info; | 98 void GeolocationPermissionContextAndroid::InterceptPermissionCheck( |
| 75 info.id = id; | 99 const BrowserPermissionCallback& callback, bool granted) { |
| 76 info.requesting_frame = requesting_frame; | 100 callback.Run(granted); |
| 77 info.user_gesture = user_gesture; | |
| 78 info.embedder = embedder; | |
| 79 | |
| 80 // Called on the UI thread. However, do the work on a separate thread | |
| 81 // to avoid strict mode violation. | |
| 82 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
| 83 content::BrowserThread::PostBlockingPoolTask(FROM_HERE, | |
| 84 base::Bind( | |
| 85 &GeolocationPermissionContextAndroid::CheckSystemLocation, | |
| 86 this, web_contents, info, callback)); | |
| 87 } | 101 } |
| OLD | NEW |