Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / geolocation / geolocation_permission_context_android.cc
blob3fd4ad1fcc585febe6924345529a7b0fe3e2bd8c
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.
5 #include "chrome/browser/geolocation/geolocation_permission_context_android.h"
7 #include <vector>
9 #include "base/bind.h"
10 #include "chrome/browser/android/location_settings.h"
11 #include "chrome/browser/android/location_settings_impl.h"
12 #include "chrome/browser/permissions/permission_request_id.h"
13 #include "chrome/browser/permissions/permission_update_infobar_delegate_android.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "content/public/browser/web_contents.h"
16 #include "url/gurl.h"
18 GeolocationPermissionContextAndroid::
19 GeolocationPermissionContextAndroid(Profile* profile)
20 : GeolocationPermissionContext(profile),
21 location_settings_(new LocationSettingsImpl()),
22 weak_factory_(this) {
25 GeolocationPermissionContextAndroid::~GeolocationPermissionContextAndroid() {
28 void GeolocationPermissionContextAndroid::RequestPermission(
29 content::WebContents* web_contents,
30 const PermissionRequestID& id,
31 const GURL& requesting_frame_origin,
32 bool user_gesture,
33 const BrowserPermissionCallback& callback) {
34 if (!location_settings_->CanSitesRequestLocationPermission(web_contents)) {
35 PermissionDecided(id, requesting_frame_origin,
36 web_contents->GetLastCommittedURL().GetOrigin(),
37 callback, false /* persist */, CONTENT_SETTING_BLOCK);
38 return;
41 GURL embedding_origin = web_contents->GetLastCommittedURL().GetOrigin();
42 ContentSetting content_setting =
43 GeolocationPermissionContext::GetPermissionStatus(requesting_frame_origin,
44 embedding_origin);
45 std::vector<ContentSettingsType> content_settings_types;
46 content_settings_types.push_back(CONTENT_SETTINGS_TYPE_GEOLOCATION);
47 if (content_setting == CONTENT_SETTING_ALLOW &&
48 PermissionUpdateInfoBarDelegate::ShouldShowPermissionInfobar(
49 web_contents, content_settings_types)) {
50 PermissionUpdateInfoBarDelegate::Create(
51 web_contents, content_settings_types,
52 base::Bind(
53 &GeolocationPermissionContextAndroid
54 ::HandleUpdateAndroidPermissions,
55 weak_factory_.GetWeakPtr(), id, requesting_frame_origin,
56 embedding_origin, callback));
57 return;
60 GeolocationPermissionContext::RequestPermission(
61 web_contents, id, requesting_frame_origin, user_gesture, callback);
64 void GeolocationPermissionContextAndroid::HandleUpdateAndroidPermissions(
65 const PermissionRequestID& id,
66 const GURL& requesting_frame_origin,
67 const GURL& embedding_origin,
68 const BrowserPermissionCallback& callback,
69 bool permissions_updated) {
70 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
71 ContentSetting new_setting = permissions_updated
72 ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK;
74 NotifyPermissionSet(id, requesting_frame_origin, embedding_origin, callback,
75 false /* persist */, new_setting);
78 void GeolocationPermissionContextAndroid::SetLocationSettingsForTesting(
79 scoped_ptr<LocationSettings> settings) {
80 location_settings_ = settings.Pass();