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::DecidePermission intercepts the flow in | 11 // GeolocationPermissionContextAndroid::DecidePermission intercepts the flow in |
12 // the UI thread, and posts a task to the blocking pool to CheckSystemLocation. | 12 // the UI thread, and posts a task to the blocking pool to CheckSystemLocation. |
13 // CheckSystemLocation will in fact check several possible settings | 13 // CheckSystemLocation 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 | 23 |
24 // There is a bit of thread jumping since some of the permissions (like the | 24 // There is a bit of thread jumping since some of the permissions (like the |
25 // per site settings) are queried on the UI thread while the system level | 25 // per site settings) are queried on the UI thread while the system level |
26 // permissions are considered I/O and thus checked in the blocking thread pool. | 26 // permissions are considered I/O and thus checked in the blocking thread pool. |
27 | 27 |
28 // TODO(newt): investigate the comment above about threading. AFAICT, system | |
29 // level permission checks actually happen on the UI thread, though they jump | |
30 // through the IO thread unnecessarily. This should be fixed. | |
31 | |
28 #include "base/memory/scoped_ptr.h" | 32 #include "base/memory/scoped_ptr.h" |
29 #include "base/memory/weak_ptr.h" | 33 #include "base/memory/weak_ptr.h" |
30 #include "chrome/browser/geolocation/geolocation_permission_context.h" | 34 #include "chrome/browser/geolocation/geolocation_permission_context.h" |
31 #include "components/content_settings/core/common/permission_request_id.h" | 35 #include "components/content_settings/core/common/permission_request_id.h" |
32 #include "url/gurl.h" | 36 #include "url/gurl.h" |
33 | 37 |
34 namespace content { | 38 namespace content { |
35 class WebContents; | 39 class WebContents; |
36 } | 40 } |
37 | 41 |
38 class GoogleLocationSettingsHelper; | 42 class GoogleLocationSettingsHelper; |
39 | 43 |
40 class GeolocationPermissionContextAndroid | 44 class GeolocationPermissionContextAndroid |
41 : public GeolocationPermissionContext { | 45 : public GeolocationPermissionContext { |
42 public: | 46 public: |
43 explicit GeolocationPermissionContextAndroid(Profile* profile); | 47 explicit GeolocationPermissionContextAndroid(Profile* profile); |
44 virtual ~GeolocationPermissionContextAndroid(); | 48 virtual ~GeolocationPermissionContextAndroid(); |
45 | 49 |
46 private: | 50 private: |
51 friend class GeolocationPermissionContextTests; | |
52 | |
47 struct PermissionRequestInfo { | 53 struct PermissionRequestInfo { |
48 PermissionRequestInfo(); | 54 PermissionRequestInfo(); |
49 | 55 |
50 PermissionRequestID id; | 56 PermissionRequestID id; |
51 GURL requesting_origin; | 57 GURL requesting_origin; |
52 GURL embedder_origin; | 58 GURL embedder_origin; |
53 bool user_gesture; | 59 bool user_gesture; |
54 }; | 60 }; |
55 | 61 |
56 // PermissionContextBase: | 62 // PermissionContextBase: |
(...skipping 10 matching lines...) Expand all Loading... | |
67 | 73 |
68 void ProceedDecidePermission(content::WebContents* web_contents, | 74 void ProceedDecidePermission(content::WebContents* web_contents, |
69 const PermissionRequestInfo& info, | 75 const PermissionRequestInfo& info, |
70 base::Callback<void(bool)> callback); | 76 base::Callback<void(bool)> callback); |
71 | 77 |
72 // Will perform a final check on the system location settings before | 78 // Will perform a final check on the system location settings before |
73 // granting the permission. | 79 // granting the permission. |
74 void InterceptPermissionCheck(const BrowserPermissionCallback& callback, | 80 void InterceptPermissionCheck(const BrowserPermissionCallback& callback, |
75 bool granted); | 81 bool granted); |
76 | 82 |
83 // Overrides the GoogleLocationSettingsHelper used to determine whether | |
84 // system and Chrome-wide location permissions are enabled. | |
85 void SetGoogleLocationSettingsHelperForTest( | |
Michael van Ouwerkerk
2015/01/13 16:33:48
Nit: ForTesting - http://www.chromium.org/develop
newt (away)
2015/01/13 16:55:03
Done.
| |
86 scoped_ptr<GoogleLocationSettingsHelper>& helper); | |
Michael van Ouwerkerk
2015/01/13 16:33:47
scoped_ptr should not be a reference - http://www.
newt (away)
2015/01/13 16:55:03
Done.
| |
87 | |
77 scoped_ptr<GoogleLocationSettingsHelper> google_location_settings_helper_; | 88 scoped_ptr<GoogleLocationSettingsHelper> google_location_settings_helper_; |
78 base::WeakPtrFactory<GeolocationPermissionContextAndroid> weak_factory_; | 89 base::WeakPtrFactory<GeolocationPermissionContextAndroid> weak_factory_; |
79 | 90 |
80 private: | 91 private: |
81 void CheckSystemLocation(content::WebContents* web_contents, | 92 void CheckSystemLocation(content::WebContents* web_contents, |
82 const PermissionRequestInfo& info, | 93 const PermissionRequestInfo& info, |
83 base::Callback<void(bool)> callback); | 94 base::Callback<void(bool)> callback); |
84 | 95 |
85 DISALLOW_COPY_AND_ASSIGN(GeolocationPermissionContextAndroid); | 96 DISALLOW_COPY_AND_ASSIGN(GeolocationPermissionContextAndroid); |
86 }; | 97 }; |
87 | 98 |
88 #endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_ANDROID_H_ | 99 #endif // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_ANDROID_H_ |
OLD | NEW |