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

Side by Side Diff: chrome/browser/extensions/launch_util.cc

Issue 105733003: Move LaunchType out of ExtensionPrefs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add missing extension.h include for windows Created 7 years 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 (c) 2013 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/extensions/launch_util.h"
6
7 #include "base/command_line.h"
8 #include "base/values.h"
9 #include "chrome/browser/extensions/extension_prefs.h"
10 #include "chrome/browser/ui/host_desktop.h"
11 #include "chrome/common/chrome_switches.h"
12 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
13 #include "extensions/common/extension.h"
14
15 #if defined(OS_WIN)
16 #include "win8/util/win8_util.h"
17 #endif
18
19 #if defined(USE_ASH)
20 #include "ash/shell.h"
21 #endif
22
23 namespace extensions {
24 namespace {
25
26 // A preference set by the the NTP to persist the desired launch container type
27 // used for apps.
28 const char kPrefLaunchType[] = "launchType";
29
30 } // namespace
31
32 LaunchType GetLaunchType(const ExtensionPrefs* prefs,
33 const Extension* extension) {
34 int value = -1;
35 LaunchType result = LAUNCH_TYPE_DEFAULT;
36
37 // Launch hosted apps as windows by default for streamlined hosted apps.
38 if (CommandLine::ForCurrentProcess()->
39 HasSwitch(switches::kEnableStreamlinedHostedApps)) {
40 result = LAUNCH_TYPE_WINDOW;
41 }
42
43 if (prefs->ReadPrefAsInteger(extension->id(), kPrefLaunchType, &value) &&
44 (value == LAUNCH_TYPE_PINNED ||
45 value == LAUNCH_TYPE_REGULAR ||
46 value == LAUNCH_TYPE_FULLSCREEN ||
47 value == LAUNCH_TYPE_WINDOW)) {
48 result = static_cast<LaunchType>(value);
49 }
50 #if defined(OS_MACOSX)
51 // App windows are not yet supported on mac. Pref sync could make
52 // the launch type LAUNCH_TYPE_WINDOW, even if there is no UI to set it
53 // on mac.
54 if (!extension->is_platform_app() && result == LAUNCH_TYPE_WINDOW)
55 result = LAUNCH_TYPE_REGULAR;
56 #endif
57
58 #if defined(OS_WIN)
59 // We don't support app windows in Windows 8 single window Metro mode.
60 if (win8::IsSingleWindowMetroMode() && result == LAUNCH_TYPE_WINDOW)
61 result = LAUNCH_TYPE_REGULAR;
62 #endif // OS_WIN
63
64 return result;
65 }
66
67 void SetLaunchType(ExtensionPrefs* prefs,
68 const std::string& extension_id,
69 LaunchType launch_type) {
70 prefs->UpdateExtensionPref(extension_id, kPrefLaunchType,
71 new base::FundamentalValue(static_cast<int>(launch_type)));
72 }
73
74 LaunchContainer GetLaunchContainer(const ExtensionPrefs* prefs,
75 const Extension* extension) {
76 LaunchContainer manifest_launch_container =
77 AppLaunchInfo::GetLaunchContainer(extension);
78
79 const LaunchContainer kInvalidLaunchContainer =
80 static_cast<LaunchContainer>(-1);
81
82 LaunchContainer result = kInvalidLaunchContainer;
83
84 if (manifest_launch_container == LAUNCH_PANEL) {
85 // Apps with app.launch.container = 'panel' should always respect the
86 // manifest setting.
87 result = manifest_launch_container;
88 } else if (manifest_launch_container == LAUNCH_TAB) {
89 // Look for prefs that indicate the user's choice of launch container. The
90 // app's menu on the NTP provides a UI to set this preference.
91 LaunchType prefs_launch_type = GetLaunchType(prefs, extension);
92
93 if (prefs_launch_type == LAUNCH_TYPE_WINDOW) {
94 // If the pref is set to launch a window (or no pref is set, and
95 // window opening is the default), make the container a window.
96 result = LAUNCH_WINDOW;
97 #if defined(USE_ASH)
98 } else if (prefs_launch_type == LAUNCH_TYPE_FULLSCREEN &&
99 chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH) {
100 // LAUNCH_TYPE_FULLSCREEN launches in a maximized app window in ash.
101 // For desktop chrome AURA on all platforms we should open the
102 // application in full screen mode in the current tab, on the same
103 // lines as non AURA chrome.
104 result = LAUNCH_WINDOW;
105 #endif
106 } else {
107 // All other launch types (tab, pinned, fullscreen) are
108 // implemented as tabs in a window.
109 result = LAUNCH_TAB;
110 }
111 } else {
112 // If a new value for app.launch.container is added, logic for it should be
113 // added here. LAUNCH_WINDOW is not present because there is no way to set
114 // it in a manifest.
115 NOTREACHED() << manifest_launch_container;
116 }
117
118 // All paths should set |result|.
119 if (result == kInvalidLaunchContainer) {
120 DLOG(FATAL) << "Failed to set a launch container.";
121 result = LAUNCH_TAB;
122 }
123
124 return result;
125 }
126
127 bool HasPreferredLaunchContainer(const ExtensionPrefs* prefs,
128 const Extension* extension) {
129 int value = -1;
130 LaunchContainer manifest_launch_container =
131 AppLaunchInfo::GetLaunchContainer(extension);
132 return manifest_launch_container == LAUNCH_TAB &&
133 prefs->ReadPrefAsInteger(extension->id(), kPrefLaunchType, &value);
134 }
135
136 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698