| 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 #ifndef CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_ANDROID_H_ | 5 #ifndef CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_ANDROID_H_ |
| 6 #define CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_ANDROID_H_ | 6 #define CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_ANDROID_H_ |
| 7 | 7 |
| 8 // The flow for geolocation permissions on Android needs to take into account | 8 // The flow for geolocation permissions on Android needs to take into account |
| 9 // the global geolocation settings so it differs from the desktop one. It | 9 // the global geolocation settings so it differs from the desktop one. It |
| 10 // works as follows. | 10 // works as follows. |
| 11 // GeolocationPermissionContextAndroid::RequestPermission intercepts the flow | 11 // GeolocationPermissionContextAndroid::RequestPermission intercepts the flow |
| 12 // and proceeds to check the system location. | 12 // and proceeds to check the system location. |
| 13 // This will in fact check several possible settings | 13 // This will in fact check several possible settings |
| 14 // - The global system geolocation setting | 14 // - The global system geolocation setting |
| 15 // - The Google location settings on pre KK devices | 15 // - The Google location settings on pre KK devices |
| 16 // - An old internal Chrome setting on pre-JB MR1 devices | 16 // - An old internal Chrome setting on pre-JB MR1 devices |
| 17 // With all that information it will decide if system location is enabled. | 17 // With all that information it will decide if system location is enabled. |
| 18 // If enabled, it proceeds with the per site flow via | 18 // If enabled, it proceeds with the per site flow via |
| 19 // GeolocationPermissionContext (which will check per site permissions, create | 19 // GeolocationPermissionContext (which will check per site permissions, create |
| 20 // infobars, etc.). | 20 // infobars, etc.). |
| 21 // | 21 // |
| 22 // Otherwise the permission is already decided. | 22 // Otherwise the permission is already decided. |
| 23 #include <memory> | 23 #include <memory> |
| 24 | 24 |
| 25 #include "base/macros.h" | 25 #include "base/macros.h" |
| 26 #include "base/memory/weak_ptr.h" | 26 #include "base/memory/weak_ptr.h" |
| 27 #include "base/time/time.h" |
| 27 #include "chrome/browser/android/location_settings.h" | 28 #include "chrome/browser/android/location_settings.h" |
| 28 #include "chrome/browser/geolocation/geolocation_permission_context.h" | 29 #include "chrome/browser/geolocation/geolocation_permission_context.h" |
| 29 #include "components/location/android/location_settings_dialog_context.h" | 30 #include "components/location/android/location_settings_dialog_context.h" |
| 30 #include "components/location/android/location_settings_dialog_outcome.h" | 31 #include "components/location/android/location_settings_dialog_outcome.h" |
| 31 | 32 |
| 32 namespace content { | 33 namespace content { |
| 33 class WebContents; | 34 class WebContents; |
| 34 } | 35 } |
| 35 | 36 |
| 36 namespace infobars { | 37 namespace infobars { |
| 37 class InfoBar; | 38 class InfoBar; |
| 38 } | 39 } |
| 39 | 40 |
| 40 class GURL; | 41 class GURL; |
| 41 class PermissionRequestID; | 42 class PermissionRequestID; |
| 43 class PrefRegistrySimple; |
| 42 | 44 |
| 43 class GeolocationPermissionContextAndroid | 45 class GeolocationPermissionContextAndroid |
| 44 : public GeolocationPermissionContext { | 46 : public GeolocationPermissionContext { |
| 45 public: | 47 public: |
| 48 static void RegisterProfilePrefs(PrefRegistrySimple* registry); |
| 49 |
| 46 explicit GeolocationPermissionContextAndroid(Profile* profile); | 50 explicit GeolocationPermissionContextAndroid(Profile* profile); |
| 47 ~GeolocationPermissionContextAndroid() override; | 51 ~GeolocationPermissionContextAndroid() override; |
| 48 | 52 |
| 49 protected: | 53 protected: |
| 50 // GeolocationPermissionContext: | 54 // GeolocationPermissionContext: |
| 51 ContentSetting GetPermissionStatusInternal( | 55 ContentSetting GetPermissionStatusInternal( |
| 52 content::RenderFrameHost* render_frame_host, | 56 content::RenderFrameHost* render_frame_host, |
| 53 const GURL& requesting_origin, | 57 const GURL& requesting_origin, |
| 54 const GURL& embedding_origin) const override; | 58 const GURL& embedding_origin) const override; |
| 55 | 59 |
| 56 private: | 60 private: |
| 57 friend class GeolocationPermissionContextTests; | 61 friend class GeolocationPermissionContextTests; |
| 58 | 62 |
| 63 static void AddDayOffsetForTesting(int days); |
| 64 static void SetDSEOriginForTesting(const char* dse_origin); |
| 65 |
| 59 // GeolocationPermissionContext: | 66 // GeolocationPermissionContext: |
| 60 void RequestPermission( | 67 void RequestPermission( |
| 61 content::WebContents* web_contents, | 68 content::WebContents* web_contents, |
| 62 const PermissionRequestID& id, | 69 const PermissionRequestID& id, |
| 63 const GURL& requesting_frame_origin, | 70 const GURL& requesting_frame_origin, |
| 64 bool user_gesture, | 71 bool user_gesture, |
| 65 const BrowserPermissionCallback& callback) override; | 72 const BrowserPermissionCallback& callback) override; |
| 66 void CancelPermissionRequest(content::WebContents* web_contents, | 73 void CancelPermissionRequest(content::WebContents* web_contents, |
| 67 const PermissionRequestID& id) override; | 74 const PermissionRequestID& id) override; |
| 75 void UserMadePermissionDecision(const PermissionRequestID& id, |
| 76 const GURL& requesting_origin, |
| 77 const GURL& embedding_origin, |
| 78 ContentSetting content_setting) override; |
| 68 void NotifyPermissionSet(const PermissionRequestID& id, | 79 void NotifyPermissionSet(const PermissionRequestID& id, |
| 69 const GURL& requesting_origin, | 80 const GURL& requesting_origin, |
| 70 const GURL& embedding_origin, | 81 const GURL& embedding_origin, |
| 71 const BrowserPermissionCallback& callback, | 82 const BrowserPermissionCallback& callback, |
| 72 bool persist, | 83 bool persist, |
| 73 ContentSetting content_setting) override; | 84 ContentSetting content_setting) override; |
| 74 PermissionResult UpdatePermissionStatusWithDeviceStatus( | 85 PermissionResult UpdatePermissionStatusWithDeviceStatus( |
| 75 PermissionResult result, | 86 PermissionResult result, |
| 76 const GURL& requesting_origin, | 87 const GURL& requesting_origin, |
| 77 const GURL& embedding_origin) const override; | 88 const GURL& embedding_origin) const override; |
| 78 | 89 |
| 90 // Functions to handle back off for showing the Location Settings Dialog. |
| 91 std::string GetLocationSettingsBackOffLevelPref( |
| 92 const GURL& requesting_origin) const; |
| 93 std::string GetLocationSettingsNextShowPref( |
| 94 const GURL& requesting_origin) const; |
| 95 bool IsInLocationSettingsBackOff(const GURL& requesting_origin) const; |
| 96 void ResetLocationSettingsBackOff(const GURL& requesting_origin); |
| 97 void UpdateLocationSettingsBackOff(const GURL& requesting_origin); |
| 98 |
| 99 // Returns whether location access is possible for the given origin. Ignores |
| 100 // Location Settings Dialog backoff, as the backoff is ignored if the user |
| 101 // will be prompted for permission. |
| 79 bool IsLocationAccessPossible(content::WebContents* web_contents, | 102 bool IsLocationAccessPossible(content::WebContents* web_contents, |
| 80 const GURL& requesting_origin, | 103 const GURL& requesting_origin, |
| 81 bool user_gesture); | 104 bool user_gesture); |
| 82 | 105 |
| 83 LocationSettingsDialogContext GetLocationSettingsDialogContext( | 106 bool IsRequestingOriginDSE(const GURL& requesting_origin) const; |
| 84 const GURL& requesting_origin) const; | |
| 85 | 107 |
| 86 void HandleUpdateAndroidPermissions(const PermissionRequestID& id, | 108 void HandleUpdateAndroidPermissions(const PermissionRequestID& id, |
| 87 const GURL& requesting_frame_origin, | 109 const GURL& requesting_frame_origin, |
| 88 const GURL& embedding_origin, | 110 const GURL& embedding_origin, |
| 89 const BrowserPermissionCallback& callback, | 111 const BrowserPermissionCallback& callback, |
| 90 bool permissions_updated); | 112 bool permissions_updated); |
| 91 | 113 |
| 92 // Will return true if the location settings dialog will be shown for the | 114 // Will return true if the location settings dialog will be shown for the |
| 93 // given origins. This is true if the location setting is off, the dialog can | 115 // given origins. This is true if the location setting is off, the dialog can |
| 94 // be shown, any gesture requirements for the origin are met, and the dialog | 116 // be shown, any gesture requirements for the origin are met, and the dialog |
| 95 // is not being suppressed for backoff. | 117 // is not being suppressed for backoff. |
| 96 bool CanShowLocationSettingsDialog(const GURL& requesting_origin, | 118 bool CanShowLocationSettingsDialog(const GURL& requesting_origin, |
| 97 bool user_gesture) const; | 119 bool user_gesture, |
| 120 bool ignore_backoff) const; |
| 98 | 121 |
| 99 void OnLocationSettingsDialogShown( | 122 void OnLocationSettingsDialogShown( |
| 100 const PermissionRequestID& id, | 123 const PermissionRequestID& id, |
| 101 const GURL& requesting_origin, | 124 const GURL& requesting_origin, |
| 102 const GURL& embedding_origin, | 125 const GURL& embedding_origin, |
| 103 const BrowserPermissionCallback& callback, | 126 const BrowserPermissionCallback& callback, |
| 104 bool persist, | 127 bool persist, |
| 105 ContentSetting content_setting, | 128 ContentSetting content_setting, |
| 106 LocationSettingsDialogOutcome prompt_outcome); | 129 LocationSettingsDialogOutcome prompt_outcome); |
| 107 | 130 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 123 infobars::InfoBar* permission_update_infobar_; | 146 infobars::InfoBar* permission_update_infobar_; |
| 124 | 147 |
| 125 // Must be the last member, to ensure that it will be destroyed first, which | 148 // Must be the last member, to ensure that it will be destroyed first, which |
| 126 // will invalidate weak pointers. | 149 // will invalidate weak pointers. |
| 127 base::WeakPtrFactory<GeolocationPermissionContextAndroid> weak_factory_; | 150 base::WeakPtrFactory<GeolocationPermissionContextAndroid> weak_factory_; |
| 128 | 151 |
| 129 DISALLOW_COPY_AND_ASSIGN(GeolocationPermissionContextAndroid); | 152 DISALLOW_COPY_AND_ASSIGN(GeolocationPermissionContextAndroid); |
| 130 }; | 153 }; |
| 131 | 154 |
| 132 #endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_ANDROID_H_ | 155 #endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_ANDROID_H_ |
| OLD | NEW |