Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2016 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/ui/ash/launcher/chrome_launcher_controller_util.h" | |
| 6 | |
| 7 #include "ash/accelerators/accelerator_controller.h" | |
| 8 #include "ash/shell.h" | |
|
mfomitchev
2016/06/23 20:19:02
Looks like we are including too much here. Can you
StarAZ
2016/06/23 20:49:49
Done.
| |
| 9 #include "base/macros.h" | |
| 10 #include "build/build_config.h" | |
| 11 #include "chrome/browser/profiles/profile.h" | |
| 12 #include "chrome/browser/profiles/profile_manager.h" | |
| 13 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs.h" | |
| 14 #include "chrome/browser/ui/ash/ash_init.h" | |
| 15 #include "chrome/browser/ui/ash/chrome_launcher_prefs.h" | |
| 16 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | |
| 17 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" | |
| 18 #include "chrome/browser/ui/browser.h" | |
| 19 #include "chrome/common/pref_names.h" | |
| 20 #include "components/prefs/scoped_user_pref_update.h" | |
| 21 #include "extensions/browser/extension_registry.h" | |
| 22 #include "extensions/common/extension.h" | |
| 23 #include "ui/aura/window_event_dispatcher.h" | |
| 24 | |
| 25 #if defined(MOJO_SHELL_CLIENT) | |
| 26 #include "content/public/common/mojo_shell_connection.h" | |
| 27 #endif | |
| 28 | |
| 29 bool IsBrowserFromActiveUser(Browser* browser) { | |
| 30 // If running multi user mode with separate desktops, we have to check if the | |
| 31 // browser is from the active user. | |
| 32 if (chrome::MultiUserWindowManager::GetMultiProfileMode() != | |
| 33 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED) | |
| 34 return true; | |
| 35 return multi_user_util::IsProfileFromActiveUser(browser->profile()); | |
| 36 } | |
| 37 | |
| 38 const extensions::Extension* GetExtensionForAppID(const std::string& app_id, | |
| 39 Profile* profile) { | |
| 40 return extensions::ExtensionRegistry::Get(profile)->GetExtensionById( | |
| 41 app_id, extensions::ExtensionRegistry::EVERYTHING); | |
| 42 } | |
| 43 | |
| 44 AppListControllerDelegate::Pinnable GetPinnableForAppID( | |
| 45 const std::string& app_id, | |
| 46 Profile* profile) { | |
| 47 const base::ListValue* pref = | |
| 48 profile->GetPrefs()->GetList(prefs::kPolicyPinnedLauncherApps); | |
| 49 if (!pref) | |
| 50 return AppListControllerDelegate::PIN_EDITABLE; | |
| 51 // Pinned ARC apps policy defines the package name of the apps, that must | |
| 52 // be pinned. All the launch activities of any package in policy are pinned. | |
| 53 // In turn the input parameter to this function is app_id, which | |
| 54 // is 32 chars hash. In case of ARC app this is a hash of | |
| 55 // (package name + activity). This means that we must identify the package | |
| 56 // from the hash, and check if this package is pinned by policy. | |
| 57 const ArcAppListPrefs* const arc_prefs = ArcAppListPrefs::Get(profile); | |
| 58 std::string arc_app_packege_name; | |
| 59 if (arc_prefs) { | |
| 60 std::unique_ptr<ArcAppListPrefs::AppInfo> app_info = | |
| 61 arc_prefs->GetApp(app_id); | |
| 62 if (app_info) | |
| 63 arc_app_packege_name = app_info->package_name; | |
| 64 } | |
| 65 for (size_t index = 0; index < pref->GetSize(); ++index) { | |
| 66 const base::DictionaryValue* app = nullptr; | |
| 67 std::string app_id_or_package; | |
| 68 if (pref->GetDictionary(index, &app) && | |
| 69 app->GetString(ash::launcher::kPinnedAppsPrefAppIDPath, | |
| 70 &app_id_or_package) && | |
| 71 (app_id == app_id_or_package || | |
| 72 arc_app_packege_name == app_id_or_package)) { | |
| 73 return AppListControllerDelegate::PIN_FIXED; | |
| 74 } | |
| 75 } | |
| 76 return AppListControllerDelegate::PIN_EDITABLE; | |
| 77 } | |
| OLD | NEW |