Commit 1fb9a9bd authored by rob's avatar rob Committed by Commit bot

Remove MediaSettingChanged infobar and show the latest state of the media stream

settings in the content settings bubble.

The reload infobar is no longer displayed when the media stream content settings
change. Instead, a small hint is displayed in the bubble when it is re-opened
after changing a media stream setting.

This hint is always displayed when the camera/microphone permission changes.
When the media device preference changes, the hint is only displayed if there
was at least one active media capture.

Also added a bunch of tests for the media menu because they had no test coverage.

BUG=405522
TEST=ContentSettingBubbleModelTest.*Media*

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

Cr-Commit-Position: refs/heads/master@{#296913}
parent 7b06b610
......@@ -12966,8 +12966,8 @@ Some features may be unavailable. Please check that the profile exists and you
<message name="IDS_CAMERA_BLOCKED" desc="Camera usage status text that is used as tooltip text for the location bar icon and as status text of the media settings bubble when a page is blocked from using the camera.">
This page has been blocked from accessing your camera.
</message>
<message name="IDS_MEDIASTREAM_SETTING_CHANGED_INFOBAR_MESSAGE" desc="Infobar message for reloading when media (camera, michrophone) settings was changed by user.">
New camera and microphone settings will take effect after reloading the page.
<message name="IDS_MEDIASTREAM_SETTING_CHANGED_MESSAGE" desc="Message that is used to suggest reloading when media (camera, microphone) settings was changed by the user. These settings are immediately effective, but the web page might not know how to deal with the new settings.">
This page may need to be reloaded before the new settings take effect.
</message>
<!-- Proteced media identifier permission infobar -->
......
......@@ -45,15 +45,15 @@ class TabSpecificContentSettings
public content_settings::Observer,
public content::WebContentsUserData<TabSpecificContentSettings> {
public:
enum MicrophoneCameraState {
MICROPHONE_CAMERA_NOT_ACCESSED = 0,
MICROPHONE_ACCESSED,
CAMERA_ACCESSED,
MICROPHONE_CAMERA_ACCESSED,
MICROPHONE_BLOCKED,
CAMERA_BLOCKED,
MICROPHONE_CAMERA_BLOCKED,
};
// Fields describing the current mic/camera state. If a page has attempted to
// access a device, the XXX_ACCESSED bit will be set. If access was blocked,
// XXX_BLOCKED will be set.
typedef uint32_t MicrophoneCameraState;
static const MicrophoneCameraState MICROPHONE_CAMERA_NOT_ACCESSED = 0;
static const MicrophoneCameraState MICROPHONE_ACCESSED = 1 << 0;
static const MicrophoneCameraState MICROPHONE_BLOCKED = 1 << 1;
static const MicrophoneCameraState CAMERA_ACCESSED = 1 << 2;
static const MicrophoneCameraState CAMERA_BLOCKED = 1 << 3;
// Classes that want to be notified about site data events must implement
// this abstract class and add themselves as observer to the
......@@ -211,9 +211,21 @@ class TabSpecificContentSettings
return media_stream_requested_video_device_;
}
const std::string& media_stream_selected_audio_device() const {
return media_stream_selected_audio_device_;
}
const std::string& media_stream_selected_video_device() const {
return media_stream_selected_video_device_;
}
// Returns the state of the camera and microphone usage.
MicrophoneCameraState GetMicrophoneCameraState() const;
// Returns whether the state of the camera and microphone usage or device has
// changed.
bool IsMicrophoneCameraStateChanged() const;
// Returns the ContentSettingsUsagesState that controls the
// geolocation API usage on this page.
const ContentSettingsUsagesState& geolocation_usages_state() const {
......@@ -413,6 +425,13 @@ class TabSpecificContentSettings
// stored here. http://crbug.com/259794
GURL media_stream_access_origin_;
// The microphone and camera state at the last media stream request.
// This value is composed of MicrophoneCameraState values.
MicrophoneCameraState microphone_camera_state_;
// The selected devices at the last media stream request.
std::string media_stream_selected_audio_device_;
std::string media_stream_selected_video_device_;
// The devices to be displayed in the media bubble when the media stream
// request is requesting certain specific devices.
std::string media_stream_requested_audio_device_;
......
......@@ -74,8 +74,13 @@ TEST_F(TabSpecificContentSettingsTest, BlockedContent) {
false);
content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES);
content_settings->SetPopupsBlocked(true);
content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC);
content_settings->OnContentBlocked(CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA);
MediaStreamDevicesController::MediaStreamTypeSettingsMap request_permissions;
request_permissions[content::MEDIA_DEVICE_AUDIO_CAPTURE].permission =
MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER;
request_permissions[content::MEDIA_DEVICE_VIDEO_CAPTURE].permission =
MediaStreamDevicesController::MEDIA_BLOCKED_BY_USER;
content_settings->OnMediaStreamPermissionSet(GURL("http://google.com"),
request_permissions);
// Check that only the respective content types are affected.
EXPECT_TRUE(content_settings->IsContentBlocked(CONTENT_SETTINGS_TYPE_IMAGES));
......@@ -226,7 +231,12 @@ TEST_F(TabSpecificContentSettingsTest, AllowedBlockedMediaContent) {
CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
ASSERT_FALSE(content_settings->IsContentBlocked(
CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
ASSERT_EQ(TabSpecificContentSettings::MICROPHONE_CAMERA_ACCESSED,
// cam request should not affect previous mic settings.
ASSERT_TRUE(content_settings->IsContentAllowed(
CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC));
ASSERT_FALSE(content_settings->IsContentBlocked(
CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC));
ASSERT_EQ(TabSpecificContentSettings::CAMERA_ACCESSED,
content_settings->GetMicrophoneCameraState());
// Request and block microphone access.
......@@ -239,7 +249,13 @@ TEST_F(TabSpecificContentSettingsTest, AllowedBlockedMediaContent) {
CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC));
ASSERT_TRUE(content_settings->IsContentBlocked(
CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC));
ASSERT_EQ(TabSpecificContentSettings::CAMERA_ACCESSED,
// mic request should not affect previous cam settings.
ASSERT_TRUE(content_settings->IsContentAllowed(
CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
ASSERT_FALSE(content_settings->IsContentBlocked(
CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
ASSERT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED |
TabSpecificContentSettings::MICROPHONE_BLOCKED,
content_settings->GetMicrophoneCameraState());
// Request and block camera access.
......@@ -252,7 +268,13 @@ TEST_F(TabSpecificContentSettingsTest, AllowedBlockedMediaContent) {
CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
ASSERT_TRUE(content_settings->IsContentBlocked(
CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
ASSERT_EQ(TabSpecificContentSettings::MICROPHONE_CAMERA_BLOCKED,
// cam request should not affect previous mic settings.
ASSERT_FALSE(content_settings->IsContentAllowed(
CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC));
ASSERT_TRUE(content_settings->IsContentBlocked(
CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC));
ASSERT_EQ(TabSpecificContentSettings::CAMERA_ACCESSED |
TabSpecificContentSettings::CAMERA_BLOCKED,
content_settings->GetMicrophoneCameraState());
// Request and allow microphone and camera access.
......@@ -270,7 +292,8 @@ TEST_F(TabSpecificContentSettingsTest, AllowedBlockedMediaContent) {
CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
ASSERT_FALSE(content_settings->IsContentBlocked(
CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
ASSERT_EQ(TabSpecificContentSettings::MICROPHONE_CAMERA_ACCESSED,
ASSERT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED |
TabSpecificContentSettings::CAMERA_ACCESSED,
content_settings->GetMicrophoneCameraState());
// Request and block microphone and camera access.
......@@ -288,7 +311,10 @@ TEST_F(TabSpecificContentSettingsTest, AllowedBlockedMediaContent) {
CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
ASSERT_TRUE(content_settings->IsContentBlocked(
CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
ASSERT_EQ(TabSpecificContentSettings::MICROPHONE_CAMERA_BLOCKED,
ASSERT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED |
TabSpecificContentSettings::MICROPHONE_BLOCKED |
TabSpecificContentSettings::CAMERA_ACCESSED |
TabSpecificContentSettings::CAMERA_BLOCKED,
content_settings->GetMicrophoneCameraState());
// Request microphone and camera access. Allow microphone, block camera.
......@@ -304,7 +330,9 @@ TEST_F(TabSpecificContentSettingsTest, AllowedBlockedMediaContent) {
CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
ASSERT_TRUE(content_settings->IsContentBlocked(
CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
ASSERT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED,
ASSERT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED |
TabSpecificContentSettings::CAMERA_ACCESSED |
TabSpecificContentSettings::CAMERA_BLOCKED,
content_settings->GetMicrophoneCameraState());
// Request microphone and camera access. Block microphone, allow camera.
......@@ -322,7 +350,9 @@ TEST_F(TabSpecificContentSettingsTest, AllowedBlockedMediaContent) {
CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
ASSERT_FALSE(content_settings->IsContentBlocked(
CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA));
ASSERT_EQ(TabSpecificContentSettings::CAMERA_ACCESSED,
ASSERT_EQ(TabSpecificContentSettings::MICROPHONE_ACCESSED |
TabSpecificContentSettings::MICROPHONE_BLOCKED |
TabSpecificContentSettings::CAMERA_ACCESSED,
content_settings->GetMicrophoneCameraState());
}
......
......@@ -248,36 +248,28 @@ void ContentSettingMediaImageModel::UpdateFromWebContents(
TabSpecificContentSettings::MicrophoneCameraState state =
content_settings->GetMicrophoneCameraState();
switch (state) {
case TabSpecificContentSettings::MICROPHONE_CAMERA_NOT_ACCESSED:
// If neither the microphone nor the camera stream was accessed then no
// icon is displayed in the omnibox.
return;
case TabSpecificContentSettings::MICROPHONE_ACCESSED:
set_icon(IDR_ASK_MEDIA);
set_tooltip(l10n_util::GetStringUTF8(IDS_MICROPHONE_ACCESSED));
break;
case TabSpecificContentSettings::CAMERA_ACCESSED:
set_icon(IDR_ASK_MEDIA);
set_tooltip(l10n_util::GetStringUTF8(IDS_CAMERA_ACCESSED));
break;
case TabSpecificContentSettings::MICROPHONE_CAMERA_ACCESSED:
set_icon(IDR_ASK_MEDIA);
set_tooltip(l10n_util::GetStringUTF8(IDS_MICROPHONE_CAMERA_ALLOWED));
break;
case TabSpecificContentSettings::MICROPHONE_BLOCKED:
set_icon(IDR_BLOCKED_MEDIA);
set_tooltip(l10n_util::GetStringUTF8(IDS_MICROPHONE_BLOCKED));
break;
case TabSpecificContentSettings::CAMERA_BLOCKED:
set_icon(IDR_BLOCKED_MEDIA);
set_tooltip(l10n_util::GetStringUTF8(IDS_CAMERA_BLOCKED));
break;
case TabSpecificContentSettings::MICROPHONE_CAMERA_BLOCKED:
set_icon(IDR_BLOCKED_MEDIA);
set_tooltip(l10n_util::GetStringUTF8(IDS_MICROPHONE_CAMERA_BLOCKED));
break;
// If neither the microphone nor the camera stream was accessed then no icon
// is displayed in the omnibox.
if (state == TabSpecificContentSettings::MICROPHONE_CAMERA_NOT_ACCESSED)
return;
bool is_mic = (state & TabSpecificContentSettings::MICROPHONE_ACCESSED) != 0;
bool is_cam = (state & TabSpecificContentSettings::CAMERA_ACCESSED) != 0;
DCHECK(is_mic || is_cam);
int id = IDS_CAMERA_BLOCKED;
if (state & (TabSpecificContentSettings::MICROPHONE_BLOCKED |
TabSpecificContentSettings::CAMERA_BLOCKED)) {
set_icon(IDR_BLOCKED_MEDIA);
if (is_mic)
id = is_cam ? IDS_MICROPHONE_CAMERA_BLOCKED : IDS_MICROPHONE_BLOCKED;
} else {
set_icon(IDR_ASK_MEDIA);
id = IDS_CAMERA_ACCESSED;
if (is_mic)
id = is_cam ? IDS_MICROPHONE_CAMERA_ALLOWED : IDS_MICROPHONE_ACCESSED;
}
set_tooltip(l10n_util::GetStringUTF8(id));
set_visible(true);
}
......
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/content_settings/media_setting_changed_infobar_delegate.h"
#include "base/logging.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/grit/generated_resources.h"
#include "components/infobars/core/infobar.h"
#include "content/public/browser/web_contents.h"
#include "grit/theme_resources.h"
#include "ui/base/l10n/l10n_util.h"
// static
void MediaSettingChangedInfoBarDelegate::Create(
InfoBarService* infobar_service) {
infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar(
scoped_ptr<ConfirmInfoBarDelegate>(
new MediaSettingChangedInfoBarDelegate())));
}
MediaSettingChangedInfoBarDelegate::MediaSettingChangedInfoBarDelegate()
: ConfirmInfoBarDelegate() {
}
MediaSettingChangedInfoBarDelegate::~MediaSettingChangedInfoBarDelegate() {
}
int MediaSettingChangedInfoBarDelegate::GetIconID() const {
return IDR_INFOBAR_MEDIA_STREAM_CAMERA;
}
infobars::InfoBarDelegate::Type
MediaSettingChangedInfoBarDelegate::GetInfoBarType() const {
return PAGE_ACTION_TYPE;
}
base::string16 MediaSettingChangedInfoBarDelegate::GetMessageText() const {
return l10n_util::GetStringUTF16(
IDS_MEDIASTREAM_SETTING_CHANGED_INFOBAR_MESSAGE);
}
int MediaSettingChangedInfoBarDelegate::GetButtons() const {
return BUTTON_OK;
}
base::string16 MediaSettingChangedInfoBarDelegate::GetButtonLabel(
InfoBarButton button) const {
DCHECK_EQ(BUTTON_OK, button);
return l10n_util::GetStringUTF16(IDS_CONTENT_SETTING_CHANGED_INFOBAR_BUTTON);
}
bool MediaSettingChangedInfoBarDelegate::Accept() {
content::WebContents* web_contents =
InfoBarService::WebContentsFromInfoBar(infobar());
web_contents->GetController().Reload(true);
return true;
}
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_CONTENT_SETTINGS_MEDIA_SETTING_CHANGED_INFOBAR_DELEGATE_H_
#define CHROME_BROWSER_UI_CONTENT_SETTINGS_MEDIA_SETTING_CHANGED_INFOBAR_DELEGATE_H_
#include "components/infobars/core/confirm_infobar_delegate.h"
class InfoBarService;
// An infobar that tells the user a reload is required after changing media
// settings, and allows a reload via a button on the infobar.
class MediaSettingChangedInfoBarDelegate : public ConfirmInfoBarDelegate {
public:
// Creates a media setting changed infobar and delegate and adds the infobar
// to |infobar_service|.
static void Create(InfoBarService* infobar_service);
private:
MediaSettingChangedInfoBarDelegate();
virtual ~MediaSettingChangedInfoBarDelegate();
// ConfirmInfoBarDelegate:
virtual int GetIconID() const OVERRIDE;
virtual Type GetInfoBarType() const OVERRIDE;
virtual base::string16 GetMessageText() const OVERRIDE;
virtual int GetButtons() const OVERRIDE;
virtual base::string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
virtual bool Accept() OVERRIDE;
DISALLOW_COPY_AND_ASSIGN(MediaSettingChangedInfoBarDelegate);
};
#endif // CHROME_BROWSER_UI_CONTENT_SETTINGS_MEDIA_SETTING_CHANGED_INFOBAR_DELEGATE_H_
......@@ -1413,8 +1413,6 @@
'browser/ui/content_settings/content_setting_image_model.h',
'browser/ui/content_settings/content_setting_media_menu_model.cc',
'browser/ui/content_settings/content_setting_media_menu_model.h',
'browser/ui/content_settings/media_setting_changed_infobar_delegate.cc',
'browser/ui/content_settings/media_setting_changed_infobar_delegate.h',
'browser/ui/elide_url.cc',
'browser/ui/elide_url.h',
'browser/ui/extensions/application_launch.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