Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / geolocation / chrome_geolocation_permission_context_android.cc
1 // Copyright (c) 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 #include "chrome/browser/geolocation/chrome_geolocation_permission_context_android.h"
6
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/android/google_location_settings_helper.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/common/pref_names.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/web_contents.h"
13
14 ChromeGeolocationPermissionContextAndroid::
15     ChromeGeolocationPermissionContextAndroid(Profile* profile)
16     : ChromeGeolocationPermissionContext(profile),
17       google_location_settings_helper_(
18           GoogleLocationSettingsHelper::Create()) {
19 }
20
21 ChromeGeolocationPermissionContextAndroid::
22     ~ChromeGeolocationPermissionContextAndroid() {
23 }
24
25 void ChromeGeolocationPermissionContextAndroid::DecidePermission(
26     content::WebContents* web_contents,
27     const PermissionRequestID& id,
28     const GURL& requesting_frame,
29     const GURL& embedder,
30     base::Callback<void(bool)> callback) {
31   DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
32
33   // Check to see if the feature in its entirety has been disabled.
34   // This must happen before other services (e.g. tabs, extensions)
35   // get an opportunity to allow the geolocation request.
36   if (!google_location_settings_helper_->IsMasterLocationSettingEnabled()) {
37     PermissionDecided(id, requesting_frame, embedder, callback, false);
38     return;
39   }
40
41   ChromeGeolocationPermissionContext::DecidePermission(
42       web_contents, id, requesting_frame, embedder, callback);
43 }
44
45 void ChromeGeolocationPermissionContextAndroid::PermissionDecided(
46     const PermissionRequestID& id,
47     const GURL& requesting_frame,
48     const GURL& embedder,
49     base::Callback<void(bool)> callback,
50     bool allowed) {
51   DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
52   // If Google Apps Location setting is turned off then we ignore
53   // the 'allow' website setting for this site and instead show
54   // the infobar to go back to the 'settings' to turn it back on.
55   if (allowed &&
56       !google_location_settings_helper_->IsGoogleAppsLocationSettingEnabled()) {
57     QueueController()->CreateInfoBarRequest(id, requesting_frame, embedder,
58                                             callback);
59     return;
60   }
61
62   ChromeGeolocationPermissionContext::PermissionDecided(
63       id, requesting_frame, embedder, callback, allowed);
64 }