[Android] Allow multiple --install in bb_device_steps.py.
[chromium-blink-merge.git] / chrome / browser / geolocation / geolocation_permission_context.cc
blobb5fc960d3d48c740c58f9cdc88d3b8ee98a93d80
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.h"
7 #include "base/bind.h"
8 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "components/content_settings/core/common/permission_request_id.h"
11 #include "content/public/browser/browser_thread.h"
12 #include "content/public/browser/geolocation_provider.h"
13 #include "content/public/browser/web_contents.h"
16 GeolocationPermissionContext::GeolocationPermissionContext(
17 Profile* profile)
18 : PermissionContextBase(profile, CONTENT_SETTINGS_TYPE_GEOLOCATION),
19 extensions_context_(profile) {
22 GeolocationPermissionContext::~GeolocationPermissionContext() {
25 void GeolocationPermissionContext::RequestPermission(
26 content::WebContents* web_contents,
27 const PermissionRequestID& id,
28 const GURL& requesting_frame_origin,
29 bool user_gesture,
30 const BrowserPermissionCallback& callback) {
31 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
32 GURL embedder_origin = web_contents->GetLastCommittedURL().GetOrigin();
34 bool permission_set;
35 bool new_permission;
36 if (extensions_context_.RequestPermission(
37 web_contents, id, id.bridge_id(), requesting_frame_origin, user_gesture,
38 callback, &permission_set, &new_permission)) {
39 if (permission_set) {
40 NotifyPermissionSet(id, requesting_frame_origin, embedder_origin,
41 callback, true, new_permission);
43 return;
46 if (!requesting_frame_origin.is_valid() || !embedder_origin.is_valid()) {
47 LOG(WARNING) << "Attempt to use geolocation from an invalid URL: "
48 << requesting_frame_origin << "," << embedder_origin
49 << " (geolocation is not supported in popups)";
50 NotifyPermissionSet(id, requesting_frame_origin, embedder_origin,
51 callback, false /* persist */, false /* allowed */);
52 return;
55 PermissionContextBase::RequestPermission(web_contents, id,
56 requesting_frame_origin,
57 user_gesture,
58 callback);
61 void GeolocationPermissionContext::CancelPermissionRequest(
62 content::WebContents* web_contents,
63 const PermissionRequestID& id) {
65 if (extensions_context_.CancelPermissionRequest(
66 web_contents, id.bridge_id()))
67 return;
68 PermissionContextBase::CancelPermissionRequest(web_contents, id);
71 void GeolocationPermissionContext::UpdateTabContext(
72 const PermissionRequestID& id,
73 const GURL& requesting_frame,
74 bool allowed) {
75 // WebContents may have gone away (or not exists for extension).
76 TabSpecificContentSettings* content_settings =
77 TabSpecificContentSettings::Get(id.render_process_id(),
78 id.render_view_id());
79 if (content_settings)
80 content_settings->OnGeolocationPermissionSet(
81 requesting_frame.GetOrigin(), allowed);
83 if (allowed) {
84 content::GeolocationProvider::GetInstance()
85 ->UserDidOptIntoLocationServices();