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

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: 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 GURL& 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 PermissionDecided(const PermissionRequestID& id,
76 const GURL& requesting_origin,
77 const GURL& embedding_origin,
78 bool user_gesture,
79 const BrowserPermissionCallback& callback,
80 bool persist,
81 ContentSetting content_setting) override;
68 void NotifyPermissionSet(const PermissionRequestID& id, 82 void NotifyPermissionSet(const PermissionRequestID& id,
69 const GURL& requesting_origin, 83 const GURL& requesting_origin,
70 const GURL& embedding_origin, 84 const GURL& embedding_origin,
71 const BrowserPermissionCallback& callback, 85 const BrowserPermissionCallback& callback,
72 bool persist, 86 bool persist,
73 ContentSetting content_setting) override; 87 ContentSetting content_setting) override;
74 PermissionResult UpdatePermissionStatusWithDeviceStatus( 88 PermissionResult UpdatePermissionStatusWithDeviceStatus(
75 PermissionResult result, 89 PermissionResult result,
76 const GURL& requesting_origin, 90 const GURL& requesting_origin,
77 const GURL& embedding_origin) const override; 91 const GURL& embedding_origin) const override;
78 92
93 // Functions to handle back off for showing the Location Settings Dialog.
94 std::string LocationSettingsBackOffLevelPref(
95 const GURL& requesting_origin) const;
96 std::string LocationSettingsNextShowPref(const GURL& requesting_origin) const;
97 bool IsInLocationSettingsBackOff(const GURL& requesting_origin) const;
98 void ResetLocationSettingsBackOff(const GURL& requesting_origin);
99 void SetLocationSettingsBackOff(const GURL& requesting_origin);
100
79 bool IsLocationAccessPossible(content::WebContents* web_contents, 101 bool IsLocationAccessPossible(content::WebContents* web_contents,
raymes 2017/03/15 04:28:25 nit: We might want to explain in a comment somewhe
benwells 2017/03/15 23:10:49 Done.
80 const GURL& requesting_origin, 102 const GURL& requesting_origin,
81 bool user_gesture); 103 bool user_gesture);
82 104
83 LocationSettingsDialogContext GetLocationSettingsDialogContext( 105 LocationSettingsDialogContext GetLocationSettingsDialogContext(
84 const GURL& requesting_origin) const; 106 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
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698