• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_ANDROID_H_
6 #define CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_ANDROID_H_
7 
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
10 // works as follows.
11 // GeolocationPermissionContextAndroid::DecidePermission intercepts the flow in
12 // the UI thread, and posts a task to the blocking pool to CheckSystemLocation.
13 // CheckSystemLocation will in fact check several possible settings
14 //     - The global system geolocation setting
15 //     - The Google location settings on pre KK 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.
18 // If enabled, it proceeds with the per site flow via
19 // GeolocationPermissionContext (which will check per site permissions, create
20 // infobars, etc.).
21 //
22 // Otherwise the permission is already decided.
23 
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
26 // permissions are considered I/O and thus checked in the blocking thread pool.
27 
28 #include "chrome/browser/geolocation/geolocation_permission_context.h"
29 #include "components/content_settings/core/common/permission_request_id.h"
30 #include "url/gurl.h"
31 
32 namespace content {
33 class WebContents;
34 }
35 
36 class GoogleLocationSettingsHelper;
37 
38 
39 class GeolocationPermissionContextAndroid
40     : public GeolocationPermissionContext {
41  public:
42   explicit GeolocationPermissionContextAndroid(Profile* profile);
43 
44  private:
45   struct PermissionRequestInfo {
46     PermissionRequestInfo();
47 
48     PermissionRequestID id;
49     GURL requesting_frame;
50     bool user_gesture;
51     GURL embedder;
52   };
53 
54   friend class GeolocationPermissionContext;
55 
56   virtual ~GeolocationPermissionContextAndroid();
57 
58   // GeolocationPermissionContext implementation:
59   virtual void DecidePermission(content::WebContents* web_contents,
60                                 const PermissionRequestID& id,
61                                 const GURL& requesting_frame,
62                                 bool user_gesture,
63                                 const GURL& embedder,
64                                 base::Callback<void(bool)> callback) OVERRIDE;
65 
66   void ProceedDecidePermission(content::WebContents* web_contents,
67                                const PermissionRequestInfo& info,
68                                base::Callback<void(bool)> callback);
69 
70   scoped_ptr<GoogleLocationSettingsHelper> google_location_settings_helper_;
71 
72  private:
73   void CheckSystemLocation(content::WebContents* web_contents,
74                            const PermissionRequestInfo& info,
75                            base::Callback<void(bool)> callback);
76 
77   DISALLOW_COPY_AND_ASSIGN(GeolocationPermissionContextAndroid);
78 };
79 
80 #endif  // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_ANDROID_H_
81