Commit 08fe85a7 authored by xhwang's avatar xhwang Committed by Commit bot

media: Enable ProtectedMediaIdentifierPermissionContext on ChromeOS.

Previously ProtectedMediaIdentifierPermissionContext is only used on Android.

In this CL:
- ChromeOS is using the stanand infobar/bubble permission UI.
- ChromeOS is using the same strings as Android. This should be fixed or
  reevaluated. See below.

Follow up work:
1. Make sure the infobar/bubble UI (including strings) is good for ChromeOS.
2. Fix the icon for the infobar/bubble on ChromeOS.
3. If we cannot get (1) and (2) done, use the current ChromeOS UI (see
   PlatformVerificationDialog) for ProtectedMediaIdentifierPermissionContext.

TBR=cpu@chromium.org
BUG=446263
TEST=Tested on ChromeOS build.

Review URL: https://codereview.chromium.org/863263007

Cr-Commit-Position: refs/heads/master@{#314292}
parent 2e71a490
......@@ -13345,7 +13345,10 @@ Some features may be unavailable. Please check that the profile exists and you
</message>
<!-- Proteced media identifier permission infobar -->
<if expr="is_android">
<if expr="is_android or chromeos">
<message name="IDS_PROTECTED_MEDIA_IDENTIFIER_PERMISSION_FRAGMENT" desc="Permission fragment shown in the permissions bubble when a web page requests access to the computer's protected media identifier.">
Protected content identifier.
</message>
<message name="IDS_PROTECTED_MEDIA_IDENTIFIER_INFOBAR_QUESTION" desc="Question asked on the infobar whenever URL wants to access protected media identifier. It shows the origin of the URL.">
<ph name="URL">$1<ex>https://www.youtube.com</ex></ph> needs to uniquely identify your device to play premium content.
</message>
......
......@@ -438,7 +438,7 @@
<structure type="chrome_scaled_image" name="IDR_INFOBAR_MULTIPLE_DOWNLOADS" file="common/infobar_multiple_downloads.png" />
<structure type="chrome_scaled_image" name="IDR_INFOBAR_PLUGIN_CRASHED" file="common/infobar_plugin_crashed.png" />
<structure type="chrome_scaled_image" name="IDR_INFOBAR_PLUGIN_INSTALL" file="common/infobar_plugin_install.png" />
<if expr="is_android">
<if expr="is_android or chromeos">
<!-- The actual image here is not used; this line only exists to
reserve a valid ID, so the Android code can map it to the
appropriate Android resource. So we just refer to a random
......
......@@ -39,7 +39,6 @@
#include "chrome/browser/media/media_capture_devices_dispatcher.h"
#include "chrome/browser/media/midi_permission_context.h"
#include "chrome/browser/media/midi_permission_context_factory.h"
#include "chrome/browser/media/protected_media_identifier_permission_context_factory.h"
#include "chrome/browser/metrics/chrome_browser_main_extra_parts_metrics.h"
#include "chrome/browser/nacl_host/nacl_browser_delegate_impl.h"
#include "chrome/browser/net/chrome_net_log.h"
......@@ -159,14 +158,17 @@
#include "chrome/browser/android/new_tab_page_url_handler.h"
#include "chrome/browser/android/webapps/single_tab_mode_tab_helper.h"
#include "chrome/browser/chrome_browser_main_android.h"
#include "chrome/browser/media/protected_media_identifier_permission_context.h"
#include "chrome/browser/media/protected_media_identifier_permission_context_factory.h"
#include "chrome/common/descriptors_android.h"
#include "components/crash/browser/crash_dump_manager_android.h"
#elif defined(OS_POSIX)
#include "chrome/browser/chrome_browser_main_posix.h"
#endif
#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
#include "chrome/browser/media/protected_media_identifier_permission_context.h"
#include "chrome/browser/media/protected_media_identifier_permission_context_factory.h"
#endif
#if defined(OS_POSIX) && !defined(OS_MACOSX)
#include "base/debug/leak_annotations.h"
#include "components/crash/app/breakpad_linux.h"
......@@ -634,7 +636,7 @@ PermissionContextBase* GetPermissionContext(Profile* profile,
case content::PERMISSION_GEOLOCATION:
return GeolocationPermissionContextFactory::GetForProfile(profile);
case content::PERMISSION_PROTECTED_MEDIA_IDENTIFIER:
#if defined(OS_ANDROID)
#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
return ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(
profile);
#else
......@@ -1944,7 +1946,7 @@ void ChromeContentBrowserClient::RequestPermission(
result_callback);
break;
case content::PERMISSION_PROTECTED_MEDIA_IDENTIFIER:
#if defined(OS_ANDROID)
#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(profile)
->RequestPermission(web_contents,
request_id,
......@@ -2034,7 +2036,7 @@ void ChromeContentBrowserClient::CancelPermissionRequest(
->CancelPermissionRequest(web_contents, request_id);
break;
case content::PERMISSION_PROTECTED_MEDIA_IDENTIFIER:
#if defined(OS_ANDROID)
#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
ProtectedMediaIdentifierPermissionContextFactory::GetForProfile(profile)
->CancelPermissionRequest(web_contents, request_id);
#else
......
......@@ -51,6 +51,11 @@ int PermissionBubbleRequestImpl::GetIconID() const {
case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
icon_id = IDR_INFOBAR_WARNING;
break;
#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER:
icon_id = IDR_INFOBAR_PROTECTED_MEDIA_IDENTIFIER;
break;
#endif
default:
NOTREACHED();
return IDR_INFOBAR_WARNING;
......@@ -75,6 +80,11 @@ base::string16 PermissionBubbleRequestImpl::GetMessageText() const {
case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
message_id = IDS_PUSH_MESSAGES_PERMISSION_QUESTION;
break;
#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER:
message_id = IDS_PROTECTED_MEDIA_IDENTIFIER_INFOBAR_QUESTION;
break;
#endif
default:
NOTREACHED();
return base::string16();
......@@ -104,6 +114,11 @@ base::string16 PermissionBubbleRequestImpl::GetMessageTextFragment() const {
case CONTENT_SETTINGS_TYPE_PUSH_MESSAGING:
message_id = IDS_PUSH_MESSAGES_BUBBLE_FRAGMENT;
break;
#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER:
message_id = IDS_PROTECTED_MEDIA_IDENTIFIER_PERMISSION_FRAGMENT;
break;
#endif
default:
NOTREACHED();
return base::string16();
......
......@@ -24,7 +24,7 @@
#include "content/public/browser/web_contents.h"
#include "content/public/common/url_constants.h"
#if defined(OS_ANDROID)
#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
#include "chrome/browser/media/protected_media_identifier_infobar_delegate.h"
#endif
......@@ -120,7 +120,7 @@ void PermissionQueueController::PendingInfobarRequest::CreateInfoBar(
GetInfoBarService(id_), controller, id_, requesting_frame_,
display_languages, type_);
break;
#if defined(OS_ANDROID)
#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
case CONTENT_SETTINGS_TYPE_PROTECTED_MEDIA_IDENTIFIER:
infobar_ = ProtectedMediaIdentifierInfoBarDelegate::Create(
GetInfoBarService(id_), controller, id_, requesting_frame_,
......
......@@ -526,7 +526,7 @@ void TabSpecificContentSettings::OnGeolocationPermissionSet(
content::NotificationService::NoDetails());
}
#if defined(OS_ANDROID)
#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
void TabSpecificContentSettings::OnProtectedMediaIdentifierPermissionSet(
const GURL& requesting_origin,
bool allowed) {
......
......@@ -325,7 +325,7 @@ class TabSpecificContentSettings
bool blocked_by_policy);
void OnGeolocationPermissionSet(const GURL& requesting_frame,
bool allowed);
#if defined(OS_ANDROID)
#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
void OnProtectedMediaIdentifierPermissionSet(const GURL& requesting_frame,
bool allowed);
#endif
......
......@@ -9,6 +9,7 @@
#include "chrome/grit/generated_resources.h"
#include "components/infobars/core/infobar.h"
#include "content/public/browser/navigation_entry.h"
#include "grit/components_strings.h"
#include "grit/theme_resources.h"
#include "net/base/net_util.h"
#include "ui/base/l10n/l10n_util.h"
......@@ -17,6 +18,10 @@
#include "chrome/browser/android/chromium_application.h"
#endif
#if defined(OS_CHROMEOS)
#include "chrome/common/url_constants.h"
#endif
// static
infobars::InfoBar* ProtectedMediaIdentifierInfoBarDelegate::Create(
InfoBarService* infobar_service,
......@@ -113,8 +118,7 @@ base::string16 ProtectedMediaIdentifierInfoBarDelegate::GetLinkText() const {
return l10n_util::GetStringUTF16(
IDS_PROTECTED_MEDIA_IDENTIFIER_SETTINGS_LINK);
#else
NOTIMPLEMENTED();
return base::string16();
return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
#endif
}
......@@ -122,6 +126,13 @@ bool ProtectedMediaIdentifierInfoBarDelegate::LinkClicked(
WindowOpenDisposition disposition) {
#if defined(OS_ANDROID)
chrome::android::ChromiumApplication::OpenProtectedContentSettings();
#elif defined(OS_CHROMEOS)
const GURL learn_more_url(chrome::kEnhancedPlaybackNotificationLearnMoreURL);
InfoBarService::WebContentsFromInfoBar(infobar())
->OpenURL(content::OpenURLParams(
learn_more_url, content::Referrer(),
(disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition,
ui::PAGE_TRANSITION_LINK, false));
#else
NOTIMPLEMENTED();
#endif
......
......@@ -12,6 +12,11 @@
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/web_contents.h"
#if defined(OS_CHROMEOS)
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chromeos/settings/cros_settings_names.h"
#endif
ProtectedMediaIdentifierPermissionContext::
ProtectedMediaIdentifierPermissionContext(Profile* profile)
: PermissionContextBase(profile,
......@@ -30,17 +35,13 @@ void ProtectedMediaIdentifierPermissionContext::RequestPermission(
const BrowserPermissionCallback& callback) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
#if defined(OS_ANDROID)
// Check if the protected media identifier master switch is disabled.
if (!profile()->GetPrefs()->GetBoolean(
prefs::kProtectedMediaIdentifierEnabled)) {
if (!IsProtectedMediaIdentifierEnabled()) {
NotifyPermissionSet(id,
requesting_frame_origin,
web_contents->GetLastCommittedURL().GetOrigin(),
callback, false, false);
return;
}
#endif
PermissionContextBase::RequestPermission(web_contents, id,
requesting_frame_origin,
......@@ -48,6 +49,16 @@ void ProtectedMediaIdentifierPermissionContext::RequestPermission(
callback);
}
ContentSetting ProtectedMediaIdentifierPermissionContext::GetPermissionStatus(
const GURL& requesting_origin,
const GURL& embedding_origin) const {
if (!IsProtectedMediaIdentifierEnabled())
return CONTENT_SETTING_BLOCK;
return PermissionContextBase::GetPermissionStatus(requesting_origin,
embedding_origin);
}
void ProtectedMediaIdentifierPermissionContext::UpdateTabContext(
const PermissionRequestID& id,
const GURL& requesting_frame,
......@@ -64,3 +75,29 @@ void ProtectedMediaIdentifierPermissionContext::UpdateTabContext(
}
}
// TODO(xhwang): We should consolidate the "protected content" related pref
// across platforms.
bool ProtectedMediaIdentifierPermissionContext::
IsProtectedMediaIdentifierEnabled() const {
bool enabled = false;
#if defined(OS_ANDROID)
enabled = profile()->GetPrefs()->GetBoolean(
prefs::kProtectedMediaIdentifierEnabled);
#endif
#if defined(OS_CHROMEOS)
// This could be disabled by the device policy.
bool enabled_for_device = false;
enabled = chromeos::CrosSettings::Get()->GetBoolean(
chromeos::kAttestationForContentProtectionEnabled,
&enabled_for_device) &&
enabled_for_device &&
profile()->GetPrefs()->GetBoolean(prefs::kEnableDRM);
#endif
DVLOG_IF(1, !enabled)
<< "Protected media identifier disabled by the user or by device policy.";
return enabled;
}
......@@ -29,6 +29,9 @@ class ProtectedMediaIdentifierPermissionContext
const GURL& requesting_frame_origin,
bool user_gesture,
const BrowserPermissionCallback& callback) override;
ContentSetting GetPermissionStatus(
const GURL& requesting_origin,
const GURL& embedding_origin) const override;
private:
~ProtectedMediaIdentifierPermissionContext() override;
......@@ -37,6 +40,10 @@ class ProtectedMediaIdentifierPermissionContext
const GURL& requesting_frame,
bool allowed) override;
// Returns whether "Protected content" is enabled. It can be disabled by a
// user in the master switch in content settings, or by the device policy.
bool IsProtectedMediaIdentifierEnabled() const;
DISALLOW_COPY_AND_ASSIGN(ProtectedMediaIdentifierPermissionContext);
};
......
......@@ -47,10 +47,12 @@ ProtectedMediaIdentifierPermissionContextFactory::BuildServiceInstanceFor(
void
ProtectedMediaIdentifierPermissionContextFactory::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) {
#if defined(OS_ANDROID)
registry->RegisterBooleanPref(
prefs::kProtectedMediaIdentifierEnabled,
true,
user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF);
#endif
}
content::BrowserContext*
......
......@@ -104,9 +104,11 @@
#include "chrome/browser/ui/gesture_prefs_observer_factory_aura.h"
#endif
#if defined(OS_ANDROID)
#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
#include "chrome/browser/media/protected_media_identifier_permission_context_factory.h"
#else
#endif
#if !defined(OS_ANDROID)
#include "chrome/browser/profile_resetter/automatic_profile_resetter_factory.h"
#endif
......@@ -173,7 +175,7 @@ EnsureBrowserContextKeyedServiceFactoriesBuilt() {
CaptivePortalServiceFactory::GetInstance();
#endif
GeolocationPermissionContextFactory::GetInstance();
#if defined(OS_ANDROID)
#if defined(OS_ANDROID) || defined(OS_CHROMEOS)
ProtectedMediaIdentifierPermissionContextFactory::GetInstance();
#endif
#if defined(ENABLE_PRINT_PREVIEW)
......
......@@ -723,6 +723,12 @@
# ChromeOS-sources not ending in _chromeos (which would be included in
# other sections and filtered out for non-ChromeOS platforms.
'chrome_browser_chromeos_sources': [
'browser/media/protected_media_identifier_infobar_delegate.cc',
'browser/media/protected_media_identifier_infobar_delegate.h',
'browser/media/protected_media_identifier_permission_context.cc',
'browser/media/protected_media_identifier_permission_context.h',
'browser/media/protected_media_identifier_permission_context_factory.cc',
'browser/media/protected_media_identifier_permission_context_factory.h',
'browser/metrics/chromeos_metrics_provider.cc',
'browser/metrics/chromeos_metrics_provider.h',
'browser/renderer_host/offline_resource_throttle.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment