Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / geolocation / geolocation_permission_context_android.h
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 "base/memory/scoped_ptr.h"
29 #include "base/memory/weak_ptr.h"
30 #include "chrome/browser/geolocation/geolocation_permission_context.h"
31 #include "components/content_settings/core/common/permission_request_id.h"
32 #include "url/gurl.h"
33
34 namespace content {
35 class WebContents;
36 }
37
38 class GoogleLocationSettingsHelper;
39
40 class GeolocationPermissionContextAndroid
41     : public GeolocationPermissionContext {
42  public:
43   explicit GeolocationPermissionContextAndroid(Profile* profile);
44   virtual ~GeolocationPermissionContextAndroid();
45
46  private:
47   struct PermissionRequestInfo {
48     PermissionRequestInfo();
49
50     PermissionRequestID id;
51     GURL requesting_origin;
52     GURL embedder_origin;
53     bool user_gesture;
54   };
55
56   // PermissionContextBase:
57   virtual void RequestPermission(
58       content::WebContents* web_contents,
59        const PermissionRequestID& id,
60        const GURL& requesting_frame_origin,
61        bool user_gesture,
62        const BrowserPermissionCallback& callback) override;
63
64   void CheckMasterLocation(content::WebContents* web_contents,
65                            const PermissionRequestInfo& info,
66                            const BrowserPermissionCallback& callback);
67
68   void ProceedDecidePermission(content::WebContents* web_contents,
69                                const PermissionRequestInfo& info,
70                                base::Callback<void(bool)> callback);
71
72   // Will perform a final check on the system location settings before
73   // granting the permission.
74   void InterceptPermissionCheck(const BrowserPermissionCallback& callback,
75                                 bool granted);
76
77   scoped_ptr<GoogleLocationSettingsHelper> google_location_settings_helper_;
78   base::WeakPtrFactory<GeolocationPermissionContextAndroid> weak_factory_;
79
80  private:
81   void CheckSystemLocation(content::WebContents* web_contents,
82                            const PermissionRequestInfo& info,
83                            base::Callback<void(bool)> callback);
84
85   DISALLOW_COPY_AND_ASSIGN(GeolocationPermissionContextAndroid);
86 };
87
88 #endif  // CHROME_BROWSER_GEOLOCATION_GEOLOCATION_PERMISSION_CONTEXT_ANDROID_H_