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

Side by Side Diff: chrome/browser/media/media_stream_devices_util.cc

Issue 483523006: Check all settings when checking mic and camera access (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Created 6 years, 3 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/media/media_stream_devices_util.h"
6
7 #include "base/command_line.h"
8 #include "base/prefs/pref_service.h"
9 #include "base/values.h"
10 #include "chrome/browser/content_settings/host_content_settings_map.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/common/content_settings_pattern.h"
14 #include "content/public/browser/browser_thread.h"
15 #include "url/gurl.h"
16
17 #if defined(OS_CHROMEOS)
18 #include "components/user_manager/user_manager.h"
19 #endif
20
21 namespace {
22
23 bool IsInKioskMode() {
24 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode))
25 return true;
26
27 #if defined(OS_CHROMEOS)
28 const user_manager::UserManager* user_manager =
29 user_manager::UserManager::Get();
30 return user_manager && user_manager->IsLoggedInAsKioskApp();
31 #else
32 return false;
33 #endif
34 }
35
36 } // namespace
37
38 bool ShouldAlwaysAllowOrigin(Profile* profile, const GURL& security_origin) {
39 // TODO(markusheintz): Replace CONTENT_SETTINGS_TYPE_MEDIA_STREAM with the
40 // appropriate new CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC and
41 // CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA.
42 return profile->GetHostContentSettingsMap()->ShouldAllowAllContent(
43 security_origin, security_origin, CONTENT_SETTINGS_TYPE_MEDIASTREAM);
44 }
45
46 MediaStreamDevicePolicy GetDevicePolicy(Profile* profile,
47 const GURL& security_origin,
48 const char* policy_name,
49 const char* whitelist_policy_name) {
50 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
51
52 // If the security origin policy matches a value in the whitelist, allow it.
53 // Otherwise, check the |policy_name| master switch for the default behavior.
54
55 PrefService* prefs = profile->GetPrefs();
56
57 // TODO(tommi): Remove the kiosk mode check when the whitelist below
58 // is visible in the media exceptions UI.
59 // See discussion here: https://codereview.chromium.org/15738004/
60 if (IsInKioskMode()) {
61 const base::ListValue* list = prefs->GetList(whitelist_policy_name);
62 std::string value;
63 for (size_t i = 0; i < list->GetSize(); ++i) {
64 if (list->GetString(i, &value)) {
65 ContentSettingsPattern pattern =
66 ContentSettingsPattern::FromString(value);
67 if (pattern == ContentSettingsPattern::Wildcard()) {
68 DLOG(WARNING) << "Ignoring wildcard URL pattern: " << value;
69 continue;
70 }
71 DLOG_IF(ERROR, !pattern.IsValid()) << "Invalid URL pattern: " << value;
72 if (pattern.IsValid() && pattern.Matches(security_origin))
73 return ALWAYS_ALLOW;
74 }
75 }
76 }
77
78 // If a match was not found, check if audio capture is otherwise disallowed
79 // or if the user should be prompted. Setting the policy value to "true"
80 // is equal to not setting it at all, so from hereon out, we will return
81 // either POLICY_NOT_SET (prompt) or ALWAYS_DENY (no prompt, no access).
82 if (!prefs->GetBoolean(policy_name))
83 return ALWAYS_DENY;
84
85 return POLICY_NOT_SET;
86 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698