Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4533)

Unified Diff: chrome/browser/media/media_stream_device_permissions.cc

Issue 483523006: Check all settings when checking mic and camera access (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Build fix for Android. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/media/media_stream_device_permissions.cc
diff --git a/chrome/browser/media/media_stream_device_permissions.cc b/chrome/browser/media/media_stream_device_permissions.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8594b3d7efbecf8887d8e53470b9d813a0942057
--- /dev/null
+++ b/chrome/browser/media/media_stream_device_permissions.cc
@@ -0,0 +1,87 @@
+// Copyright 2014 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/media/media_stream_device_permissions.h"
+
+#include "base/command_line.h"
+#include "base/prefs/pref_service.h"
+#include "base/values.h"
+#include "chrome/browser/content_settings/host_content_settings_map.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/content_settings_pattern.h"
+#include "content/public/browser/browser_thread.h"
+#include "url/gurl.h"
+
+#if defined(OS_CHROMEOS)
+#include "components/user_manager/user_manager.h"
+#endif
+
+namespace {
+
+bool IsInKioskMode() {
+ if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode))
+ return true;
+
+#if defined(OS_CHROMEOS)
+ const user_manager::UserManager* user_manager =
+ user_manager::UserManager::Get();
+ return user_manager && user_manager->IsLoggedInAsKioskApp();
+#else
+ return false;
+#endif
+}
+
+} // namespace
+
+bool CheckAllowAllMediaStreamContentForOrigin(Profile* profile,
+ const GURL& security_origin) {
+ // TODO(markusheintz): Replace CONTENT_SETTINGS_TYPE_MEDIA_STREAM with the
+ // appropriate new CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC and
+ // CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA.
+ return profile->GetHostContentSettingsMap()->ShouldAllowAllContent(
+ security_origin, security_origin, CONTENT_SETTINGS_TYPE_MEDIASTREAM);
+}
+
+MediaStreamDevicePolicy GetDevicePolicy(Profile* profile,
+ const GURL& security_origin,
+ const char* policy_name,
+ const char* whitelist_policy_name) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+
+ // If the security origin policy matches a value in the whitelist, allow it.
+ // Otherwise, check the |policy_name| master switch for the default behavior.
+
+ PrefService* prefs = profile->GetPrefs();
+
+ // TODO(tommi): Remove the kiosk mode check when the whitelist below
+ // is visible in the media exceptions UI.
+ // See discussion here: https://codereview.chromium.org/15738004/
+ if (IsInKioskMode()) {
+ const base::ListValue* list = prefs->GetList(whitelist_policy_name);
+ std::string value;
+ for (size_t i = 0; i < list->GetSize(); ++i) {
+ if (list->GetString(i, &value)) {
+ ContentSettingsPattern pattern =
+ ContentSettingsPattern::FromString(value);
+ if (pattern == ContentSettingsPattern::Wildcard()) {
+ DLOG(WARNING) << "Ignoring wildcard URL pattern: " << value;
+ continue;
+ }
+ DLOG_IF(ERROR, !pattern.IsValid()) << "Invalid URL pattern: " << value;
+ if (pattern.IsValid() && pattern.Matches(security_origin))
+ return ALWAYS_ALLOW;
+ }
+ }
+ }
+
+ // If a match was not found, check if audio capture is otherwise disallowed
+ // or if the user should be prompted. Setting the policy value to "true"
+ // is equal to not setting it at all, so from hereon out, we will return
+ // either POLICY_NOT_SET (prompt) or ALWAYS_DENY (no prompt, no access).
+ if (!prefs->GetBoolean(policy_name))
+ return ALWAYS_DENY;
+
+ return POLICY_NOT_SET;
+}

Powered by Google App Engine
This is Rietveld 408576698