| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/chrome_process_manager_delegate.h" | 5 #include "chrome/browser/extensions/chrome_process_manager_delegate.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/browser/extensions/extension_management.h" |
| 12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/profiles/profile_manager.h" | 14 #include "chrome/browser/profiles/profile_manager.h" |
| 14 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_finder.h" | 16 #include "chrome/browser/ui/browser_finder.h" |
| 16 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 17 #include "components/user_manager/user_manager.h" | 18 #include "components/user_manager/user_manager.h" |
| 18 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
| 19 #include "extensions/browser/extension_system.h" | 20 #include "extensions/browser/extension_system.h" |
| 20 #include "extensions/browser/process_manager.h" | 21 #include "extensions/browser/process_manager.h" |
| 21 #include "extensions/browser/process_manager_factory.h" | 22 #include "extensions/browser/process_manager_factory.h" |
| 23 #include "extensions/common/extension.h" |
| 22 #include "extensions/common/one_shot_event.h" | 24 #include "extensions/common/one_shot_event.h" |
| 23 | 25 |
| 26 #if defined(OS_CHROMEOS) |
| 27 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 28 #endif |
| 29 |
| 24 namespace extensions { | 30 namespace extensions { |
| 25 | 31 |
| 26 ChromeProcessManagerDelegate::ChromeProcessManagerDelegate() { | 32 ChromeProcessManagerDelegate::ChromeProcessManagerDelegate() { |
| 27 registrar_.Add(this, | 33 registrar_.Add(this, |
| 28 chrome::NOTIFICATION_BROWSER_WINDOW_READY, | 34 chrome::NOTIFICATION_BROWSER_WINDOW_READY, |
| 29 content::NotificationService::AllSources()); | 35 content::NotificationService::AllSources()); |
| 30 registrar_.Add(this, | 36 registrar_.Add(this, |
| 31 chrome::NOTIFICATION_PROFILE_CREATED, | 37 chrome::NOTIFICATION_PROFILE_CREATED, |
| 32 content::NotificationService::AllSources()); | 38 content::NotificationService::AllSources()); |
| 33 registrar_.Add(this, | 39 registrar_.Add(this, |
| 34 chrome::NOTIFICATION_PROFILE_DESTROYED, | 40 chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 35 content::NotificationService::AllSources()); | 41 content::NotificationService::AllSources()); |
| 36 } | 42 } |
| 37 | 43 |
| 38 ChromeProcessManagerDelegate::~ChromeProcessManagerDelegate() { | 44 ChromeProcessManagerDelegate::~ChromeProcessManagerDelegate() { |
| 39 } | 45 } |
| 40 | 46 |
| 41 bool ChromeProcessManagerDelegate::IsBackgroundPageAllowed( | 47 bool ChromeProcessManagerDelegate::IsBackgroundPageAllowed( |
| 42 content::BrowserContext* context) const { | 48 content::BrowserContext* context, |
| 49 const Extension* extension) const { |
| 43 Profile* profile = static_cast<Profile*>(context); | 50 Profile* profile = static_cast<Profile*>(context); |
| 44 | 51 |
| 45 bool is_normal_session = !profile->IsGuestSession() && | 52 bool is_normal_session = !profile->IsGuestSession() && |
| 46 !profile->IsSystemProfile(); | 53 !profile->IsSystemProfile(); |
| 54 |
| 47 #if defined(OS_CHROMEOS) | 55 #if defined(OS_CHROMEOS) |
| 48 is_normal_session = is_normal_session && | 56 const bool is_signin_profile = |
| 49 user_manager::UserManager::Get()->IsUserLoggedIn(); | 57 chromeos::ProfileHelper::IsSigninProfile(profile) && |
| 58 !profile->IsOffTheRecord(); |
| 59 |
| 60 if (is_signin_profile) { |
| 61 // If an extension is specified, allow background pages only if that |
| 62 // extension is in the login screen app list. Otherwise allow |
| 63 // background pages. |
| 64 if (!extension) |
| 65 return true; |
| 66 |
| 67 // Check for flag. |
| 68 const bool login_screen_apps_enabled = |
| 69 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 70 switches::kEnableLoginScreenApps); |
| 71 |
| 72 // Get login screen apps installed by policy. |
| 73 std::unique_ptr<base::DictionaryValue> login_screen_apps_list = |
| 74 ExtensionManagementFactory::GetForBrowserContext(context) |
| 75 ->GetForceInstallList(); |
| 76 |
| 77 return login_screen_apps_enabled && |
| 78 login_screen_apps_list->HasKey(extension->id()); |
| 79 } |
| 80 |
| 81 is_normal_session = |
| 82 is_normal_session && user_manager::UserManager::Get()->IsUserLoggedIn(); |
| 50 #endif | 83 #endif |
| 51 | 84 |
| 52 // Disallow if the current session is a Guest mode session or login screen but | 85 // Disallow if the current session is a Guest mode session or login screen but |
| 53 // the current browser context is *not* off-the-record. Such context is | 86 // the current browser context is *not* off-the-record. Such context is |
| 54 // artificial and background page shouldn't be created in it. | 87 // artificial and background page shouldn't be created in it. |
| 55 // http://crbug.com/329498 | 88 // http://crbug.com/329498 |
| 56 return is_normal_session || profile->IsOffTheRecord(); | 89 return is_normal_session || profile->IsOffTheRecord(); |
| 57 } | 90 } |
| 58 | 91 |
| 59 bool ChromeProcessManagerDelegate::DeferCreatingStartupBackgroundHosts( | 92 bool ChromeProcessManagerDelegate::DeferCreatingStartupBackgroundHosts( |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 ProcessManager* incognito_manager = | 197 ProcessManager* incognito_manager = |
| 165 ProcessManagerFactory::GetForBrowserContextIfExists( | 198 ProcessManagerFactory::GetForBrowserContextIfExists( |
| 166 profile->GetOffTheRecordProfile()); | 199 profile->GetOffTheRecordProfile()); |
| 167 if (incognito_manager) { | 200 if (incognito_manager) { |
| 168 incognito_manager->CloseBackgroundHosts(); | 201 incognito_manager->CloseBackgroundHosts(); |
| 169 } | 202 } |
| 170 } | 203 } |
| 171 } | 204 } |
| 172 | 205 |
| 173 } // namespace extensions | 206 } // namespace extensions |
| OLD | NEW |