Adding instrumentation to locate the source of jankiness
[chromium-blink-merge.git] / chrome / browser / geolocation / geolocation_permission_context.cc
blobaf63c43a31795cb6d5cd6f5a578b0a910e06887e
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/web_contents.h"
15 GeolocationPermissionContext::GeolocationPermissionContext(
16 Profile* profile)
17 : PermissionContextBase(profile, CONTENT_SETTINGS_TYPE_GEOLOCATION),
18 extensions_context_(profile) {
21 GeolocationPermissionContext::~GeolocationPermissionContext() {
24 void GeolocationPermissionContext::RequestPermission(
25 content::WebContents* web_contents,
26 const PermissionRequestID& id,
27 const GURL& requesting_frame_origin,
28 bool user_gesture,
29 const BrowserPermissionCallback& callback) {
30 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
31 GURL embedder_origin = web_contents->GetLastCommittedURL().GetOrigin();
33 bool permission_set;
34 bool new_permission;
35 if (extensions_context_.RequestPermission(
36 web_contents, id, id.bridge_id(), requesting_frame_origin, user_gesture,
37 callback, &permission_set, &new_permission)) {
38 if (permission_set) {
39 NotifyPermissionSet(id, requesting_frame_origin, embedder_origin,
40 callback, true, new_permission);
42 return;
45 if (!requesting_frame_origin.is_valid() || !embedder_origin.is_valid()) {
46 LOG(WARNING) << "Attempt to use geolocation from an invalid URL: "
47 << requesting_frame_origin << "," << embedder_origin
48 << " (geolocation is not supported in popups)";
49 NotifyPermissionSet(id, requesting_frame_origin, embedder_origin,
50 callback, false /* persist */, false /* allowed */);
51 return;
54 PermissionContextBase::RequestPermission(web_contents, id,
55 requesting_frame_origin,
56 user_gesture,
57 callback);
60 void GeolocationPermissionContext::CancelPermissionRequest(
61 content::WebContents* web_contents,
62 const PermissionRequestID& id) {
64 if (extensions_context_.CancelPermissionRequest(
65 web_contents, id.bridge_id()))
66 return;
67 PermissionContextBase::CancelPermissionRequest(web_contents, id);
70 void GeolocationPermissionContext::UpdateTabContext(
71 const PermissionRequestID& id,
72 const GURL& requesting_frame,
73 bool allowed) {
74 // WebContents may have gone away (or not exists for extension).
75 TabSpecificContentSettings* content_settings =
76 TabSpecificContentSettings::Get(id.render_process_id(),
77 id.render_view_id());
78 if (content_settings)
79 content_settings->OnGeolocationPermissionSet(
80 requesting_frame.GetOrigin(), allowed);