Move origin url validation check to PermissionContextBase class.
[chromium-blink-merge.git] / chrome / browser / media / protected_media_identifier_permission_context.cc
blobca530c735d14197f7027a38fdf64e99ad7be1008
1 // Copyright 2013 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/media/protected_media_identifier_permission_context.h"
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/common/pref_names.h"
11 #include "components/content_settings/core/common/permission_request_id.h"
12 #include "content/public/browser/browser_thread.h"
13 #include "content/public/browser/web_contents.h"
15 #if defined(ENABLE_EXTENSIONS)
16 #include "chrome/browser/extensions/extension_service.h"
17 #include "extensions/browser/extension_system.h"
18 #include "extensions/browser/suggest_permission_util.h"
19 #include "extensions/browser/view_type_utils.h"
20 #include "extensions/common/extension.h"
22 using extensions::APIPermission;
23 #endif
25 ProtectedMediaIdentifierPermissionContext::
26 ProtectedMediaIdentifierPermissionContext(Profile* profile)
27 : PermissionContextBase(profile,
28 CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER) {
31 ProtectedMediaIdentifierPermissionContext::
32 ~ProtectedMediaIdentifierPermissionContext() {
35 void ProtectedMediaIdentifierPermissionContext::RequestPermission(
36 content::WebContents* web_contents,
37 const PermissionRequestID& id,
38 const GURL& requesting_frame_origin,
39 bool user_gesture,
40 const BrowserPermissionCallback& callback) {
41 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
43 #if defined(ENABLE_EXTENSIONS)
44 if (extensions::GetViewType(web_contents) !=
45 extensions::VIEW_TYPE_TAB_CONTENTS) {
46 // The tab may have gone away, or the request may not be from a tab at all.
47 DVLOG(1)
48 << "Attempt to use protected media identifier in tabless renderer: "
49 << id.ToString()
50 << " (can't prompt user without a visible tab)";
51 NotifyPermissionSet(id,
52 origin,
53 web_contents->GetLastCommittedURL().GetOrigin(),
54 callback, false, false);
55 return;
57 #endif
59 #if defined(OS_ANDROID)
60 // Check if the protected media identifier master switch is disabled.
61 if (!profile()->GetPrefs()->GetBoolean(
62 prefs::kProtectedMediaIdentifierEnabled)) {
63 NotifyPermissionSet(id,
64 requesting_frame_origin,
65 web_contents->GetLastCommittedURL().GetOrigin(),
66 callback, false, false);
67 return;
69 #endif
71 PermissionContextBase::RequestPermission(web_contents, id,
72 requesting_frame_origin,
73 user_gesture,
74 callback);
77 void ProtectedMediaIdentifierPermissionContext::UpdateTabContext(
78 const PermissionRequestID& id,
79 const GURL& requesting_frame,
80 bool allowed) {
81 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
83 // WebContents may have gone away.
84 TabSpecificContentSettings* content_settings =
85 TabSpecificContentSettings::Get(id.render_process_id(),
86 id.render_view_id());
87 if (content_settings) {
88 content_settings->OnProtectedMediaIdentifierPermissionSet(
89 requesting_frame.GetOrigin(), allowed);