1 // Copyright 2020 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/window_placement/window_placement_permission_context.h"
6 
7 #include "components/content_settings/core/common/content_settings_types.h"
8 #include "components/permissions/permission_request_id.h"
9 #include "content/public/browser/render_frame_host.h"
10 #include "third_party/blink/public/mojom/feature_policy/feature_policy.mojom.h"
11 #include "third_party/blink/public/mojom/frame/user_activation_notification_type.mojom.h"
12 
WindowPlacementPermissionContext(content::BrowserContext * browser_context)13 WindowPlacementPermissionContext::WindowPlacementPermissionContext(
14     content::BrowserContext* browser_context)
15     : permissions::PermissionContextBase(
16           browser_context,
17           ContentSettingsType::WINDOW_PLACEMENT,
18           blink::mojom::FeaturePolicyFeature::kNotFound) {}
19 
20 WindowPlacementPermissionContext::~WindowPlacementPermissionContext() = default;
21 
IsRestrictedToSecureOrigins() const22 bool WindowPlacementPermissionContext::IsRestrictedToSecureOrigins() const {
23   return true;
24 }
25 
UserMadePermissionDecision(const permissions::PermissionRequestID & id,const GURL & requesting_origin,const GURL & embedding_origin,ContentSetting content_setting)26 void WindowPlacementPermissionContext::UserMadePermissionDecision(
27     const permissions::PermissionRequestID& id,
28     const GURL& requesting_origin,
29     const GURL& embedding_origin,
30     ContentSetting content_setting) {
31   // Notify user activation on the requesting frame if permission was granted,
32   // as transient activation may have expired while the user was responding.
33   // This enables sites to prompt for permission to access multi-screen info and
34   // then immediately request fullscreen or place a window using that info.
35   if (content_setting == CONTENT_SETTING_ALLOW) {
36     if (auto* render_frame_host = content::RenderFrameHost::FromID(
37             id.render_process_id(), id.render_frame_id())) {
38       render_frame_host->NotifyUserActivation(
39           blink::mojom::UserActivationNotificationType::kInteraction);
40     }
41   }
42 
43   permissions::PermissionContextBase::UserMadePermissionDecision(
44       id, requesting_origin, embedding_origin, content_setting);
45 }
46