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

Side by Side Diff: chrome/browser/geolocation/geolocation_permission_context_android.h

Issue 2742373003: Limit the amount the Location Settings Dialog will be shown to users. (Closed)
Patch Set: Nit Created 3 years, 9 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
OLDNEW
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 LocationSettingsBackOffLevelPref(
Bernhard Bauer 2017/03/16 16:19:35 Nit: From the name it's not totally clear to me wh
benwells 2017/03/22 06:17:25 Done.
92 const GURL& requesting_origin) const;
93 std::string LocationSettingsNextShowPref(const GURL& requesting_origin) const;
94 bool IsInLocationSettingsBackOff(const GURL& requesting_origin) const;
95 void ResetLocationSettingsBackOff(const GURL& requesting_origin);
96 void UpdateLocationSettingsBackOff(const GURL& requesting_origin);
97
98 // Returns whether location access is possible for the given origin. Ignores
99 // Location Settings Dialog backoff, as the backoff is ignored if the user
100 // will be prompted for permission.
79 bool IsLocationAccessPossible(content::WebContents* web_contents, 101 bool IsLocationAccessPossible(content::WebContents* web_contents,
80 const GURL& requesting_origin, 102 const GURL& requesting_origin,
81 bool user_gesture); 103 bool user_gesture);
82 104
83 LocationSettingsDialogContext GetLocationSettingsDialogContext( 105 bool IsRequestingOriginDSE(const GURL& requesting_origin) const;
84 const GURL& requesting_origin) const;
85 106
86 void HandleUpdateAndroidPermissions(const PermissionRequestID& id, 107 void HandleUpdateAndroidPermissions(const PermissionRequestID& id,
87 const GURL& requesting_frame_origin, 108 const GURL& requesting_frame_origin,
88 const GURL& embedding_origin, 109 const GURL& embedding_origin,
89 const BrowserPermissionCallback& callback, 110 const BrowserPermissionCallback& callback,
90 bool permissions_updated); 111 bool permissions_updated);
91 112
92 // Will return true if the location settings dialog will be shown for the 113 // 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 114 // 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 115 // be shown, any gesture requirements for the origin are met, and the dialog
95 // is not being suppressed for backoff. 116 // is not being suppressed for backoff.
96 bool CanShowLocationSettingsDialog(const GURL& requesting_origin, 117 bool CanShowLocationSettingsDialog(const GURL& requesting_origin,
97 bool user_gesture) const; 118 bool user_gesture,
119 bool ignore_backoff) const;
98 120
99 void OnLocationSettingsDialogShown( 121 void OnLocationSettingsDialogShown(
100 const PermissionRequestID& id, 122 const PermissionRequestID& id,
101 const GURL& requesting_origin, 123 const GURL& requesting_origin,
102 const GURL& embedding_origin, 124 const GURL& embedding_origin,
103 const BrowserPermissionCallback& callback, 125 const BrowserPermissionCallback& callback,
104 bool persist, 126 bool persist,
105 ContentSetting content_setting, 127 ContentSetting content_setting,
106 LocationSettingsDialogOutcome prompt_outcome); 128 LocationSettingsDialogOutcome prompt_outcome);
107 129
(...skipping 15 matching lines...) Expand all
123 infobars::InfoBar* permission_update_infobar_; 145 infobars::InfoBar* permission_update_infobar_;
124 146
125 // Must be the last member, to ensure that it will be destroyed first, which 147 // Must be the last member, to ensure that it will be destroyed first, which
126 // will invalidate weak pointers. 148 // will invalidate weak pointers.
127 base::WeakPtrFactory<GeolocationPermissionContextAndroid> weak_factory_; 149 base::WeakPtrFactory<GeolocationPermissionContextAndroid> weak_factory_;
128 150
129 DISALLOW_COPY_AND_ASSIGN(GeolocationPermissionContextAndroid); 151 DISALLOW_COPY_AND_ASSIGN(GeolocationPermissionContextAndroid);
130 }; 152 };
131 153
132 #endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_ANDROID_H_ 154 #endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698