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

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

Issue 105733003: Move LaunchType out of ExtensionPrefs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix indenting 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
« no previous file with comments | « chrome/browser/extensions/extension_prefs.h ('k') | chrome/browser/extensions/launch_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/extension_prefs.h" 5 #include "chrome/browser/extensions/extension_prefs.h"
6 6
7 #include <iterator> 7 #include <iterator>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/prefs/pref_notifier.h" 10 #include "base/prefs/pref_notifier.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "base/value_conversions.h" 14 #include "base/value_conversions.h"
15 #include "chrome/browser/chrome_notification_types.h"
16 #include "chrome/browser/extensions/api/content_settings/content_settings_store. h" 15 #include "chrome/browser/extensions/api/content_settings/content_settings_store. h"
17 #include "chrome/browser/extensions/api/preference/preference_api.h" 16 #include "chrome/browser/extensions/api/preference/preference_api.h"
18 #include "chrome/browser/extensions/extension_pref_store.h" 17 #include "chrome/browser/extensions/extension_pref_store.h"
19 #include "chrome/browser/extensions/extension_prefs_factory.h" 18 #include "chrome/browser/extensions/extension_prefs_factory.h"
20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/ui/host_desktop.h"
22 #include "chrome/common/chrome_switches.h"
23 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h"
24 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
25 #include "chrome/common/url_constants.h"
26 #include "components/user_prefs/pref_registry_syncable.h" 20 #include "components/user_prefs/pref_registry_syncable.h"
27 #include "content/public/browser/notification_service.h"
28 #include "extensions/browser/admin_policy.h" 21 #include "extensions/browser/admin_policy.h"
29 #include "extensions/browser/app_sorting.h" 22 #include "extensions/browser/app_sorting.h"
30 #include "extensions/browser/event_router.h" 23 #include "extensions/browser/event_router.h"
31 #include "extensions/browser/pref_names.h" 24 #include "extensions/browser/pref_names.h"
32 #include "extensions/common/feature_switch.h" 25 #include "extensions/common/feature_switch.h"
33 #include "extensions/common/manifest.h" 26 #include "extensions/common/manifest.h"
34 #include "extensions/common/permissions/permission_set.h" 27 #include "extensions/common/permissions/permission_set.h"
35 #include "extensions/common/permissions/permissions_info.h" 28 #include "extensions/common/permissions/permissions_info.h"
36 #include "extensions/common/url_pattern.h" 29 #include "extensions/common/url_pattern.h"
37 #include "extensions/common/user_script.h" 30 #include "extensions/common/user_script.h"
38 #include "grit/generated_resources.h" 31 #include "grit/generated_resources.h"
39 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
40 33
41 #if defined(USE_ASH)
42 #include "ash/shell.h"
43 #endif
44 #if defined(OS_WIN)
45 #include "win8/util/win8_util.h"
46 #endif // OS_WIN
47
48 using base::Value; 34 using base::Value;
49 using base::DictionaryValue; 35 using base::DictionaryValue;
50 using base::ListValue; 36 using base::ListValue;
51 37
52 namespace extensions { 38 namespace extensions {
53 39
54 namespace { 40 namespace {
55 41
56 // Additional preferences keys, which are not needed by external clients. 42 // Additional preferences keys, which are not needed by external clients.
57 43
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 const char kPrefIncognitoEnabled[] = "incognito"; 121 const char kPrefIncognitoEnabled[] = "incognito";
136 122
137 // A preference to control whether an extension is allowed to inject script in 123 // A preference to control whether an extension is allowed to inject script in
138 // pages with file URLs. 124 // pages with file URLs.
139 const char kPrefAllowFileAccess[] = "newAllowFileAccess"; 125 const char kPrefAllowFileAccess[] = "newAllowFileAccess";
140 // TODO(jstritar): As part of fixing http://crbug.com/91577, we revoked all 126 // TODO(jstritar): As part of fixing http://crbug.com/91577, we revoked all
141 // extension file access by renaming the pref. We should eventually clean up 127 // extension file access by renaming the pref. We should eventually clean up
142 // the old flag and possibly go back to that name. 128 // the old flag and possibly go back to that name.
143 // const char kPrefAllowFileAccessOld[] = "allowFileAccess"; 129 // const char kPrefAllowFileAccessOld[] = "allowFileAccess";
144 130
145 // A preference set by the the NTP to persist the desired launch container type
146 // used for apps.
147 const char kPrefLaunchType[] = "launchType";
148
149 // A preference specifying if the user dragged the app on the NTP. 131 // A preference specifying if the user dragged the app on the NTP.
150 const char kPrefUserDraggedApp[] = "user_dragged_app_ntp"; 132 const char kPrefUserDraggedApp[] = "user_dragged_app_ntp";
151 133
152 // Preferences that hold which permissions the user has granted the extension. 134 // Preferences that hold which permissions the user has granted the extension.
153 // We explicitly keep track of these so that extensions can contain unknown 135 // We explicitly keep track of these so that extensions can contain unknown
154 // permissions, for backwards compatibility reasons, and we can still prompt 136 // permissions, for backwards compatibility reasons, and we can still prompt
155 // the user to accept them once recognized. We store the active permission 137 // the user to accept them once recognized. We store the active permission
156 // permissions because they may differ from those defined in the manifest. 138 // permissions because they may differ from those defined in the manifest.
157 const char kPrefActivePermissions[] = "active_permissions"; 139 const char kPrefActivePermissions[] = "active_permissions";
158 const char kPrefGrantedPermissions[] = "granted_permissions"; 140 const char kPrefGrantedPermissions[] = "granted_permissions";
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 UpdateExtensionPref(extension_id, kPrefAllowFileAccess, 1048 UpdateExtensionPref(extension_id, kPrefAllowFileAccess,
1067 new base::FundamentalValue(allow)); 1049 new base::FundamentalValue(allow));
1068 } 1050 }
1069 1051
1070 bool ExtensionPrefs::HasAllowFileAccessSetting( 1052 bool ExtensionPrefs::HasAllowFileAccessSetting(
1071 const std::string& extension_id) const { 1053 const std::string& extension_id) const {
1072 const DictionaryValue* ext = GetExtensionPref(extension_id); 1054 const DictionaryValue* ext = GetExtensionPref(extension_id);
1073 return ext && ext->HasKey(kPrefAllowFileAccess); 1055 return ext && ext->HasKey(kPrefAllowFileAccess);
1074 } 1056 }
1075 1057
1076 ExtensionPrefs::LaunchType ExtensionPrefs::GetLaunchType(
1077 const Extension* extension) {
1078 int value = -1;
1079 LaunchType result = LAUNCH_TYPE_DEFAULT;
1080
1081 // Launch hosted apps as windows by default for streamlined hosted apps.
1082 if (CommandLine::ForCurrentProcess()->
1083 HasSwitch(switches::kEnableStreamlinedHostedApps)) {
1084 result = LAUNCH_TYPE_WINDOW;
1085 }
1086
1087 if (ReadPrefAsInteger(extension->id(), kPrefLaunchType, &value) &&
1088 (value == LAUNCH_TYPE_PINNED ||
1089 value == LAUNCH_TYPE_REGULAR ||
1090 value == LAUNCH_TYPE_FULLSCREEN ||
1091 value == LAUNCH_TYPE_WINDOW)) {
1092 result = static_cast<LaunchType>(value);
1093 }
1094 #if defined(OS_MACOSX)
1095 // App windows are not yet supported on mac. Pref sync could make
1096 // the launch type LAUNCH_TYPE_WINDOW, even if there is no UI to set it
1097 // on mac.
1098 if (!extension->is_platform_app() && result == LAUNCH_TYPE_WINDOW)
1099 result = LAUNCH_TYPE_REGULAR;
1100 #endif
1101
1102 #if defined(OS_WIN)
1103 // We don't support app windows in Windows 8 single window Metro mode.
1104 if (win8::IsSingleWindowMetroMode() && result == LAUNCH_TYPE_WINDOW)
1105 result = LAUNCH_TYPE_REGULAR;
1106 #endif // OS_WIN
1107
1108 return result;
1109 }
1110
1111 LaunchContainer ExtensionPrefs::GetLaunchContainer(const Extension* extension) {
1112 LaunchContainer manifest_launch_container =
1113 AppLaunchInfo::GetLaunchContainer(extension);
1114
1115 const LaunchContainer kInvalidLaunchContainer =
1116 static_cast<LaunchContainer>(-1);
1117
1118 LaunchContainer result = kInvalidLaunchContainer;
1119
1120 if (manifest_launch_container == LAUNCH_PANEL) {
1121 // Apps with app.launch.container = 'panel' should always respect the
1122 // manifest setting.
1123 result = manifest_launch_container;
1124 } else if (manifest_launch_container == LAUNCH_TAB) {
1125 // Look for prefs that indicate the user's choice of launch container. The
1126 // app's menu on the NTP provides a UI to set this preference.
1127 ExtensionPrefs::LaunchType prefs_launch_type = GetLaunchType(extension);
1128
1129 if (prefs_launch_type == LAUNCH_TYPE_WINDOW) {
1130 // If the pref is set to launch a window (or no pref is set, and
1131 // window opening is the default), make the container a window.
1132 result = LAUNCH_WINDOW;
1133 #if defined(USE_ASH)
1134 } else if (prefs_launch_type == LAUNCH_TYPE_FULLSCREEN &&
1135 chrome::GetActiveDesktop() == chrome::HOST_DESKTOP_TYPE_ASH) {
1136 // LAUNCH_TYPE_FULLSCREEN launches in a maximized app window in ash.
1137 // For desktop chrome AURA on all platforms we should open the
1138 // application in full screen mode in the current tab, on the same
1139 // lines as non AURA chrome.
1140 result = LAUNCH_WINDOW;
1141 #endif
1142 } else {
1143 // All other launch types (tab, pinned, fullscreen) are
1144 // implemented as tabs in a window.
1145 result = LAUNCH_TAB;
1146 }
1147 } else {
1148 // If a new value for app.launch.container is added, logic for it should be
1149 // added here. LAUNCH_WINDOW is not present because there is no way to set
1150 // it in a manifest.
1151 NOTREACHED() << manifest_launch_container;
1152 }
1153
1154 // All paths should set |result|.
1155 if (result == kInvalidLaunchContainer) {
1156 DLOG(FATAL) << "Failed to set a launch container.";
1157 result = LAUNCH_TAB;
1158 }
1159
1160 return result;
1161 }
1162
1163 bool ExtensionPrefs::HasPreferredLaunchContainer(const Extension* extension) {
1164 int value = -1;
1165 LaunchContainer manifest_launch_container =
1166 AppLaunchInfo::GetLaunchContainer(extension);
1167 return manifest_launch_container == LAUNCH_TAB &&
1168 ReadPrefAsInteger(extension->id(), kPrefLaunchType, &value);
1169 }
1170
1171 void ExtensionPrefs::SetLaunchType(const std::string& extension_id,
1172 LaunchType launch_type) {
1173 UpdateExtensionPref(extension_id, kPrefLaunchType,
1174 new base::FundamentalValue(static_cast<int>(launch_type)));
1175 }
1176
1177 bool ExtensionPrefs::DoesExtensionHaveState( 1058 bool ExtensionPrefs::DoesExtensionHaveState(
1178 const std::string& id, Extension::State check_state) const { 1059 const std::string& id, Extension::State check_state) const {
1179 const DictionaryValue* extension = GetExtensionPref(id); 1060 const DictionaryValue* extension = GetExtensionPref(id);
1180 int state = -1; 1061 int state = -1;
1181 if (!extension || !extension->GetInteger(kPrefState, &state)) 1062 if (!extension || !extension->GetInteger(kPrefState, &state))
1182 return false; 1063 return false;
1183 1064
1184 if (state < 0 || state >= Extension::NUM_STATES) { 1065 if (state < 0 || state >= Extension::NUM_STATES) {
1185 LOG(ERROR) << "Bad pref 'state' for extension '" << id << "'"; 1066 LOG(ERROR) << "Bad pref 'state' for extension '" << id << "'";
1186 return false; 1067 return false;
(...skipping 809 matching lines...) Expand 10 before | Expand all | Expand 10 after
1996 is_enabled = initial_state == Extension::ENABLED; 1877 is_enabled = initial_state == Extension::ENABLED;
1997 } 1878 }
1998 1879
1999 extension_pref_value_map_->RegisterExtension(extension_id, install_time, 1880 extension_pref_value_map_->RegisterExtension(extension_id, install_time,
2000 is_enabled); 1881 is_enabled);
2001 content_settings_store_->RegisterExtension(extension_id, install_time, 1882 content_settings_store_->RegisterExtension(extension_id, install_time,
2002 is_enabled); 1883 is_enabled);
2003 } 1884 }
2004 1885
2005 } // namespace extensions 1886 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_prefs.h ('k') | chrome/browser/extensions/launch_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698