OLD | NEW |
---|---|
(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_helper.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "base/prefs/pref_service.h" | |
9 #include "base/values.h" | |
10 #include "chrome/browser/profiles/profile.h" | |
11 #include "chrome/common/chrome_switches.h" | |
12 #include "chrome/common/content_settings_pattern.h" | |
13 #include "content/public/browser/browser_thread.h" | |
14 | |
15 #if defined(OS_CHROMEOS) | |
16 #include "components/user_manager/user_manager.h" | |
17 #endif | |
18 | |
19 namespace { | |
20 | |
21 bool IsInKioskMode() { | |
22 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) | |
23 return true; | |
24 | |
25 #if defined(OS_CHROMEOS) | |
26 const user_manager::UserManager* user_manager = | |
27 user_manager::UserManager::Get(); | |
28 return user_manager && user_manager->IsLoggedInAsKioskApp(); | |
29 #else | |
30 return false; | |
31 #endif | |
32 } | |
33 | |
34 } // namespace | |
35 | |
36 MediaStreamDevicePolicy GetDevicePolicy(Profile* profile, | |
37 GURL security_origin, | |
tommi (sloooow) - chröme
2014/08/22 19:42:56
const GURL&
| |
38 const char* policy_name, | |
39 const char* whitelist_policy_name) { | |
40 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | |
41 | |
42 // If the security origin policy matches a value in the whitelist, allow it. | |
43 // Otherwise, check the |policy_name| master switch for the default behavior. | |
44 | |
45 PrefService* prefs = profile->GetPrefs(); | |
46 | |
47 // TODO(tommi): Remove the kiosk mode check when the whitelist below | |
48 // is visible in the media exceptions UI. | |
49 // See discussion here: https://codereview.chromium.org/15738004/ | |
50 if (IsInKioskMode()) { | |
51 const base::ListValue* list = prefs->GetList(whitelist_policy_name); | |
52 std::string value; | |
53 for (size_t i = 0; i < list->GetSize(); ++i) { | |
54 if (list->GetString(i, &value)) { | |
55 ContentSettingsPattern pattern = | |
56 ContentSettingsPattern::FromString(value); | |
57 if (pattern == ContentSettingsPattern::Wildcard()) { | |
58 DLOG(WARNING) << "Ignoring wildcard URL pattern: " << value; | |
59 continue; | |
60 } | |
61 DLOG_IF(ERROR, !pattern.IsValid()) << "Invalid URL pattern: " << value; | |
62 if (pattern.IsValid() && pattern.Matches(security_origin)) | |
63 return ALWAYS_ALLOW; | |
64 } | |
65 } | |
66 } | |
67 | |
68 // If a match was not found, check if audio capture is otherwise disallowed | |
69 // or if the user should be prompted. Setting the policy value to "true" | |
70 // is equal to not setting it at all, so from hereon out, we will return | |
71 // either POLICY_NOT_SET (prompt) or ALWAYS_DENY (no prompt, no access). | |
72 if (!prefs->GetBoolean(policy_name)) | |
73 return ALWAYS_DENY; | |
74 | |
75 return POLICY_NOT_SET; | |
76 } | |
OLD | NEW |