Skip to content

Commit

Permalink
[Autoplay] Add new flags to WebUI
Browse files Browse the repository at this point in the history
Add new flags and pref state to chrome://media-engagement
for debugging. We should also use the autoplay policy
from WebPreferences.

BUG=865548

Change-Id: I02bd462fbc58070f6bd2f4ab44bfd9311fad8aed
Reviewed-on: https://chromium-review.googlesource.com/1157270
Commit-Queue: Becca Hughes <beccahughes@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Mounir Lamouri <mlamouri@chromium.org>
Cr-Commit-Position: refs/heads/master@{#581453}
  • Loading branch information
beccahughes authored and Commit Bot committed Aug 8, 2018
1 parent c79d548 commit 0403932
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 6 deletions.
3 changes: 3 additions & 0 deletions chrome/browser/media/media_engagement_score_details.mojom
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ struct MediaEngagementConfig {
bool feature_record_data;
bool feature_bypass_autoplay;
bool feature_preload_data;
bool feature_autoplay_sound_settings;
bool pref_unified_autoplay;
bool has_custom_autoplay_policy;
string autoplay_policy;

// The current version of any preloaded component.
Expand Down
9 changes: 9 additions & 0 deletions chrome/browser/resources/media/media_engagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ function renderConfigTable(config) {
formatFeatureFlag(config.featureBypassAutoplay)));
configTableBody.appendChild(createConfigRow(
'Preload MEI data', formatFeatureFlag(config.featurePreloadData)));
configTableBody.appendChild(createConfigRow(
'Autoplay sound settings',
formatFeatureFlag(config.featureAutoplaySoundSettings)));
configTableBody.appendChild(createConfigRow(
'Unified autoplay (preference)',
formatFeatureFlag(config.prefUnifiedAutoplay)));
configTableBody.appendChild(createConfigRow(
'Custom autoplay policy',
formatFeatureFlag(config.hasCustomAutoplayPolicy)));
configTableBody.appendChild(
createConfigRow('Autoplay Policy', config.autoplayPolicy));
configTableBody.appendChild(createConfigRow(
Expand Down
53 changes: 47 additions & 6 deletions chrome/browser/ui/webui/media/media_engagement_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,28 @@
#include "base/command_line.h"
#include "base/feature_list.h"
#include "base/macros.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/media/media_engagement_score.h"
#include "chrome/browser/media/media_engagement_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/url_constants.h"
#include "chrome/grit/browser_resources.h"
#include "components/component_updater/component_updater_service.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_ui.h"
#include "content/public/browser/web_ui_controller.h"
#include "content/public/browser/web_ui_data_source.h"
#include "content/public/common/web_preferences.h"
#include "media/base/media_switches.h"
#include "mojo/public/cpp/bindings/binding.h"

#if !defined(OS_ANDROID)
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h"
#endif

namespace {

namespace {
Expand All @@ -37,10 +46,13 @@ class MediaEngagementScoreDetailsProviderImpl
: public media::mojom::MediaEngagementScoreDetailsProvider {
public:
MediaEngagementScoreDetailsProviderImpl(
Profile* profile,
content::WebUI* web_ui,
mojo::InterfaceRequest<media::mojom::MediaEngagementScoreDetailsProvider>
request)
: profile_(profile), binding_(this, std::move(request)) {
: web_ui_(web_ui),
profile_(Profile::FromWebUI(web_ui)),
binding_(this, std::move(request)) {
DCHECK(web_ui_);
DCHECK(profile_);
service_ = MediaEngagementService::Get(profile_);
}
Expand All @@ -65,12 +77,30 @@ class MediaEngagementScoreDetailsProviderImpl
base::FeatureList::IsEnabled(
media::kMediaEngagementBypassAutoplayPolicies),
base::FeatureList::IsEnabled(media::kPreloadMediaEngagementData),
media::GetEffectiveAutoplayPolicy(
*base::CommandLine::ForCurrentProcess()),
GetPreloadVersion()));
base::FeatureList::IsEnabled(media::kAutoplaySoundSettings),
GetBlockAutoplayPref(),
base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kAutoplayPolicy),
GetAppliedAutoplayPolicy(), GetPreloadVersion()));
}

private:
const std::string GetAppliedAutoplayPolicy() {
switch (web_ui_->GetWebContents()
->GetRenderViewHost()
->GetWebkitPreferences()
.autoplay_policy) {
case content::AutoplayPolicy::kNoUserGestureRequired:
return "no-user-gesture-required";
case content::AutoplayPolicy::kUserGestureRequired:
return "user-gesture-required";
case content::AutoplayPolicy::kUserGestureRequiredForCrossOrigin:
return "user-gesture-required-for-cross-origin";
case content::AutoplayPolicy::kDocumentUserActivationRequired:
return "document-user-activation-required";
}
}

const std::string GetPreloadVersion() {
component_updater::ComponentUpdateService* cus =
g_browser_process->component_updater();
Expand All @@ -84,6 +114,17 @@ class MediaEngagementScoreDetailsProviderImpl
return std::string();
}

// Pref is not available on Android.
bool GetBlockAutoplayPref() {
#if defined(OS_ANDROID)
return false;
#else
return profile_->GetPrefs()->GetBoolean(prefs::kBlockAutoplayEnabled);
#endif
}

content::WebUI* web_ui_;

Profile* profile_;

MediaEngagementService* service_;
Expand Down Expand Up @@ -118,5 +159,5 @@ MediaEngagementUI::~MediaEngagementUI() = default;
void MediaEngagementUI::BindMediaEngagementScoreDetailsProvider(
media::mojom::MediaEngagementScoreDetailsProviderRequest request) {
ui_handler_ = std::make_unique<MediaEngagementScoreDetailsProviderImpl>(
Profile::FromWebUI(web_ui()), std::move(request));
web_ui(), std::move(request));
}

0 comments on commit 0403932

Please sign in to comment.