Persist media device IDs across navigation and restart (fixes issue #2064)

Media device IDs will now be persisted across navigation and reload by default.
The device IDs will also be persisted across restart if --cache-path=<path> and
--persist-user-preferences settings are specified.
This commit is contained in:
Marshall Greenblatt 2020-09-14 16:26:31 -04:00
parent cc56720bd2
commit 8796d3cd95
5 changed files with 31 additions and 0 deletions

View File

@ -21,6 +21,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "chrome/browser/font_family_cache.h" #include "chrome/browser/font_family_cache.h"
#include "chrome/browser/media/media_device_id_salt.h"
#include "chrome/browser/plugins/chrome_plugin_service_filter.h" #include "chrome/browser/plugins/chrome_plugin_service_filter.h"
#include "chrome/browser/profiles/profile_key.h" #include "chrome/browser/profiles/profile_key.h"
#include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h" #include "chrome/browser/ui/zoom/chrome_zoom_level_prefs.h"
@ -168,6 +169,8 @@ void AlloyBrowserContext::Initialize() {
extension_system_->Init(); extension_system_->Init();
ChromePluginServiceFilter::GetInstance()->RegisterProfile(this); ChromePluginServiceFilter::GetInstance()->RegisterProfile(this);
media_device_id_salt_ = new MediaDeviceIDSalt(pref_service);
} }
void AlloyBrowserContext::Shutdown() { void AlloyBrowserContext::Shutdown() {
@ -397,6 +400,10 @@ AlloyBrowserContext::GetBrowsingDataRemoverDelegate() {
return nullptr; return nullptr;
} }
std::string AlloyBrowserContext::GetMediaDeviceIDSalt() {
return media_device_id_salt_->GetSalt();
}
PrefService* AlloyBrowserContext::GetPrefs() { PrefService* AlloyBrowserContext::GetPrefs() {
return pref_service_.get(); return pref_service_.get();
} }

View File

@ -18,6 +18,7 @@
class CefDownloadManagerDelegate; class CefDownloadManagerDelegate;
class CefSSLHostStateDelegate; class CefSSLHostStateDelegate;
class CefVisitedLinkListener; class CefVisitedLinkListener;
class MediaDeviceIDSalt;
class PrefService; class PrefService;
namespace extensions { namespace extensions {
@ -80,6 +81,7 @@ class AlloyBrowserContext : public ChromeProfileAlloy,
content::BackgroundSyncController* GetBackgroundSyncController() override; content::BackgroundSyncController* GetBackgroundSyncController() override;
content::BrowsingDataRemoverDelegate* GetBrowsingDataRemoverDelegate() content::BrowsingDataRemoverDelegate* GetBrowsingDataRemoverDelegate()
override; override;
std::string GetMediaDeviceIDSalt() override;
// Profile overrides. // Profile overrides.
ChromeZoomLevelPrefs* GetZoomLevelPrefs() override; ChromeZoomLevelPrefs* GetZoomLevelPrefs() override;
@ -140,6 +142,8 @@ class AlloyBrowserContext : public ChromeProfileAlloy,
std::unique_ptr<content::ResourceContext> resource_context_; std::unique_ptr<content::ResourceContext> resource_context_;
scoped_refptr<MediaDeviceIDSalt> media_device_id_salt_;
DISALLOW_COPY_AND_ASSIGN(AlloyBrowserContext); DISALLOW_COPY_AND_ASSIGN(AlloyBrowserContext);
}; };

View File

@ -51,6 +51,7 @@
#include "cef/grit/cef_resources.h" #include "cef/grit/cef_resources.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_content_browser_client.h" #include "chrome/browser/chrome_content_browser_client.h"
#include "chrome/browser/content_settings/cookie_settings_factory.h"
#include "chrome/browser/net/system_network_context_manager.h" #include "chrome/browser/net/system_network_context_manager.h"
#include "chrome/browser/plugins/plugin_info_host_impl.h" #include "chrome/browser/plugins/plugin_info_host_impl.h"
#include "chrome/browser/plugins/plugin_response_interceptor_url_loader_throttle.h" #include "chrome/browser/plugins/plugin_response_interceptor_url_loader_throttle.h"
@ -69,6 +70,7 @@
#include "chrome/grit/browser_resources.h" #include "chrome/grit/browser_resources.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "chrome/services/printing/printing_service.h" #include "chrome/services/printing/printing_service.h"
#include "components/content_settings/core/browser/cookie_settings.h"
#include "components/navigation_interception/intercept_navigation_throttle.h" #include "components/navigation_interception/intercept_navigation_throttle.h"
#include "components/navigation_interception/navigation_params.h" #include "components/navigation_interception/navigation_params.h"
#include "components/spellcheck/common/spellcheck.mojom.h" #include "components/spellcheck/common/spellcheck.mojom.h"
@ -1462,6 +1464,17 @@ AlloyContentBrowserClient::GetPluginMimeTypesWithExternalHandlers(
return mime_types; return mime_types;
} }
bool AlloyContentBrowserClient::ArePersistentMediaDeviceIDsAllowed(
content::BrowserContext* browser_context,
const GURL& url,
const GURL& site_for_cookies,
const base::Optional<url::Origin>& top_frame_origin) {
// Persistent MediaDevice IDs are allowed if cookies are allowed.
return CookieSettingsFactory::GetForProfile(
Profile::FromBrowserContext(browser_context))
->IsCookieAccessAllowed(url, site_for_cookies, top_frame_origin);
}
bool AlloyContentBrowserClient::ShouldAllowPluginCreation( bool AlloyContentBrowserClient::ShouldAllowPluginCreation(
const url::Origin& embedder_origin, const url::Origin& embedder_origin,
const content::PepperPluginInfo& plugin_info) { const content::PepperPluginInfo& plugin_info) {

View File

@ -206,6 +206,11 @@ class AlloyContentBrowserClient : public content::ContentBrowserClient {
blink::UserAgentMetadata GetUserAgentMetadata() override; blink::UserAgentMetadata GetUserAgentMetadata() override;
base::flat_set<std::string> GetPluginMimeTypesWithExternalHandlers( base::flat_set<std::string> GetPluginMimeTypesWithExternalHandlers(
content::BrowserContext* browser_context) override; content::BrowserContext* browser_context) override;
bool ArePersistentMediaDeviceIDsAllowed(
content::BrowserContext* browser_context,
const GURL& scope,
const GURL& site_for_cookies,
const base::Optional<url::Origin>& top_frame_origin) override;
bool ShouldAllowPluginCreation( bool ShouldAllowPluginCreation(
const url::Origin& embedder_origin, const url::Origin& embedder_origin,
const content::PepperPluginInfo& plugin_info) override; const content::PepperPluginInfo& plugin_info) override;

View File

@ -18,6 +18,7 @@
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/accessibility/accessibility_ui.h" #include "chrome/browser/accessibility/accessibility_ui.h"
#include "chrome/browser/download/download_prefs.h" #include "chrome/browser/download/download_prefs.h"
#include "chrome/browser/media/media_device_id_salt.h"
#include "chrome/browser/media/router/media_router_feature.h" #include "chrome/browser/media/router/media_router_feature.h"
#include "chrome/browser/net/prediction_options.h" #include "chrome/browser/net/prediction_options.h"
#include "chrome/browser/net/profile_network_context_service.h" #include "chrome/browser/net/profile_network_context_service.h"
@ -230,6 +231,7 @@ std::unique_ptr<PrefService> CreatePrefService(Profile* profile,
HostContentSettingsMap::RegisterProfilePrefs(registry.get()); HostContentSettingsMap::RegisterProfilePrefs(registry.get());
language::LanguagePrefs::RegisterProfilePrefs(registry.get()); language::LanguagePrefs::RegisterProfilePrefs(registry.get());
media_router::RegisterProfilePrefs(registry.get()); media_router::RegisterProfilePrefs(registry.get());
MediaDeviceIDSalt::RegisterProfilePrefs(registry.get());
ProfileNetworkContextService::RegisterProfilePrefs(registry.get()); ProfileNetworkContextService::RegisterProfilePrefs(registry.get());
const std::string& locale = const std::string& locale =