Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/launch_util.h" | 5 #include "chrome/browser/extensions/launch_util.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/values.h" | 8 #include "base/values.h" |
| 9 #include "chrome/browser/extensions/extension_prefs.h" | 9 #include "chrome/browser/extensions/extension_prefs.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | |
| 10 #include "chrome/browser/ui/host_desktop.h" | 11 #include "chrome/browser/ui/host_desktop.h" |
| 11 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
| 12 #include "chrome/common/extensions/extension_constants.h" | 13 #include "chrome/common/extensions/extension_constants.h" |
| 13 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 14 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
| 14 #include "extensions/common/extension.h" | 15 #include "extensions/common/extension.h" |
| 15 | 16 |
| 16 #if defined(OS_WIN) | 17 #if defined(OS_WIN) |
| 17 #include "win8/util/win8_util.h" | 18 #include "win8/util/win8_util.h" |
| 18 #endif | 19 #endif |
| 19 | 20 |
| 20 #if defined(USE_ASH) | 21 #if defined(USE_ASH) |
| 21 #include "ash/shell.h" | 22 #include "ash/shell.h" |
| 22 #endif | 23 #endif |
| 23 | 24 |
| 24 namespace extensions { | 25 namespace extensions { |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 // A preference set by the the NTP to persist the desired launch container type | 28 // A preference set by the the NTP to persist the desired launch container type |
| 28 // used for apps. | 29 // used for apps. |
| 29 const char kPrefLaunchType[] = "launchType"; | 30 const char kPrefLaunchType[] = "launchType"; |
| 30 | 31 |
| 31 } // namespace | 32 } // namespace |
| 32 | 33 |
| 33 LaunchType GetLaunchType(const ExtensionPrefs* prefs, | 34 LaunchType GetLaunchType(const ExtensionPrefs* prefs, |
| 34 const Extension* extension) { | 35 const Extension* extension) { |
| 35 int value = -1; | 36 int value = LAUNCH_TYPE_INVALID; |
| 36 LaunchType result = LAUNCH_TYPE_DEFAULT; | 37 LaunchType result = LAUNCH_TYPE_DEFAULT; |
| 37 | 38 |
| 38 // Launch hosted apps as windows by default for streamlined hosted apps. | 39 // Launch hosted apps as windows by default for streamlined hosted apps. |
| 39 if (CommandLine::ForCurrentProcess()-> | 40 if (CommandLine::ForCurrentProcess()-> |
| 40 HasSwitch(switches::kEnableStreamlinedHostedApps) && | 41 HasSwitch(switches::kEnableStreamlinedHostedApps) && |
| 41 extension->id() != extension_misc::kChromeAppId) { | 42 extension->id() != extension_misc::kChromeAppId) { |
| 42 result = LAUNCH_TYPE_WINDOW; | 43 result = LAUNCH_TYPE_WINDOW; |
| 43 } | 44 } |
| 44 | 45 |
| 45 if (prefs->ReadPrefAsInteger(extension->id(), kPrefLaunchType, &value) && | 46 if (prefs->ReadPrefAsInteger(extension->id(), kPrefLaunchType, &value) && |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 59 | 60 |
| 60 #if defined(OS_WIN) | 61 #if defined(OS_WIN) |
| 61 // We don't support app windows in Windows 8 single window Metro mode. | 62 // We don't support app windows in Windows 8 single window Metro mode. |
| 62 if (win8::IsSingleWindowMetroMode() && result == LAUNCH_TYPE_WINDOW) | 63 if (win8::IsSingleWindowMetroMode() && result == LAUNCH_TYPE_WINDOW) |
| 63 result = LAUNCH_TYPE_REGULAR; | 64 result = LAUNCH_TYPE_REGULAR; |
| 64 #endif // OS_WIN | 65 #endif // OS_WIN |
| 65 | 66 |
| 66 return result; | 67 return result; |
| 67 } | 68 } |
| 68 | 69 |
| 69 void SetLaunchType(ExtensionPrefs* prefs, | 70 void SetLaunchType(ExtensionService* service, |
| 70 const std::string& extension_id, | 71 const std::string& extension_id, |
| 71 LaunchType launch_type) { | 72 LaunchType launch_type) { |
| 72 prefs->UpdateExtensionPref(extension_id, kPrefLaunchType, | 73 DCHECK(launch_type >= LAUNCH_TYPE_FIRST && launch_type < NUM_LAUNCH_TYPES); |
| 74 | |
| 75 service->extension_prefs()->UpdateExtensionPref(extension_id, kPrefLaunchType, | |
| 73 new base::FundamentalValue(static_cast<int>(launch_type))); | 76 new base::FundamentalValue(static_cast<int>(launch_type))); |
| 77 | |
| 78 // Sync the launch type. | |
| 79 const Extension* extension = service->GetInstalledExtension(extension_id); | |
| 80 if (extension) { | |
| 81 ExtensionSyncService::Get(service->profile())-> | |
| 82 SyncExtensionChangeIfNeeded(*extension); | |
| 83 } | |
| 84 } | |
| 85 | |
| 86 bool HasPreferredLaunchType(const ExtensionPrefs* prefs, | |
| 87 const Extension* extension) { | |
| 88 int value = LAUNCH_TYPE_INVALID; | |
| 89 return extension && | |
| 90 prefs->ReadPrefAsInteger(extension->id(), kPrefLaunchType, &value); | |
|
Nicolas Zea
2013/12/18 21:14:04
Just to double check, this will return false if th
calamity
2013/12/19 06:27:52
Yep.
| |
| 74 } | 91 } |
| 75 | 92 |
| 76 LaunchContainer GetLaunchContainer(const ExtensionPrefs* prefs, | 93 LaunchContainer GetLaunchContainer(const ExtensionPrefs* prefs, |
| 77 const Extension* extension) { | 94 const Extension* extension) { |
| 78 LaunchContainer manifest_launch_container = | 95 LaunchContainer manifest_launch_container = |
| 79 AppLaunchInfo::GetLaunchContainer(extension); | 96 AppLaunchInfo::GetLaunchContainer(extension); |
| 80 | 97 |
| 81 const LaunchContainer kInvalidLaunchContainer = | 98 const LaunchContainer kInvalidLaunchContainer = |
| 82 static_cast<LaunchContainer>(-1); | 99 static_cast<LaunchContainer>(-1); |
| 83 | 100 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 bool HasPreferredLaunchContainer(const ExtensionPrefs* prefs, | 146 bool HasPreferredLaunchContainer(const ExtensionPrefs* prefs, |
| 130 const Extension* extension) { | 147 const Extension* extension) { |
| 131 int value = -1; | 148 int value = -1; |
| 132 LaunchContainer manifest_launch_container = | 149 LaunchContainer manifest_launch_container = |
| 133 AppLaunchInfo::GetLaunchContainer(extension); | 150 AppLaunchInfo::GetLaunchContainer(extension); |
| 134 return manifest_launch_container == LAUNCH_CONTAINER_TAB && | 151 return manifest_launch_container == LAUNCH_CONTAINER_TAB && |
| 135 prefs->ReadPrefAsInteger(extension->id(), kPrefLaunchType, &value); | 152 prefs->ReadPrefAsInteger(extension->id(), kPrefLaunchType, &value); |
| 136 } | 153 } |
| 137 | 154 |
| 138 } // namespace extensions | 155 } // namespace extensions |
| OLD | NEW |