| OLD | NEW |
| 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/ui/ash/launcher/launcher_controller_helper.h" | 5 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "chrome/browser/ui/extensions/extension_enable_flow.h" | 24 #include "chrome/browser/ui/extensions/extension_enable_flow.h" |
| 25 #include "chrome/browser/web_applications/web_app.h" | 25 #include "chrome/browser/web_applications/web_app.h" |
| 26 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 26 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
| 27 #include "content/public/browser/navigation_entry.h" | 27 #include "content/public/browser/navigation_entry.h" |
| 28 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 29 #include "extensions/browser/extension_registry.h" | 29 #include "extensions/browser/extension_registry.h" |
| 30 #include "extensions/browser/extension_system.h" | 30 #include "extensions/browser/extension_system.h" |
| 31 #include "extensions/common/extension.h" | 31 #include "extensions/common/extension.h" |
| 32 #include "extensions/common/extension_set.h" | 32 #include "extensions/common/extension_set.h" |
| 33 #include "net/base/url_util.h" | 33 #include "net/base/url_util.h" |
| 34 #include "ui/display/types/display_constants.h" |
| 34 #include "ui/events/event_constants.h" | 35 #include "ui/events/event_constants.h" |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| 38 const extensions::Extension* GetExtensionForTab(Profile* profile, | 39 const extensions::Extension* GetExtensionForTab(Profile* profile, |
| 39 content::WebContents* tab) { | 40 content::WebContents* tab) { |
| 40 ExtensionService* extension_service = | 41 ExtensionService* extension_service = |
| 41 extensions::ExtensionSystem::Get(profile)->extension_service(); | 42 extensions::ExtensionSystem::Get(profile)->extension_service(); |
| 42 if (!extension_service || !extension_service->extensions_enabled()) | 43 if (!extension_service || !extension_service->extensions_enabled()) |
| 43 return nullptr; | 44 return nullptr; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 if (!arc::IsArcPlayStoreEnabledForProfile(profile()) && | 162 if (!arc::IsArcPlayStoreEnabledForProfile(profile()) && |
| 162 arc::IsArcPlayStoreEnabledPreferenceManagedForProfile(profile())) | 163 arc::IsArcPlayStoreEnabledPreferenceManagedForProfile(profile())) |
| 163 return false; | 164 return false; |
| 164 } | 165 } |
| 165 | 166 |
| 166 return true; | 167 return true; |
| 167 } | 168 } |
| 168 | 169 |
| 169 void LauncherControllerHelper::LaunchApp(const ash::ShelfID& id, | 170 void LauncherControllerHelper::LaunchApp(const ash::ShelfID& id, |
| 170 ash::ShelfLaunchSource source, | 171 ash::ShelfLaunchSource source, |
| 171 int event_flags) { | 172 int event_flags, |
| 173 int64_t display_id) { |
| 172 const std::string& app_id = id.app_id; | 174 const std::string& app_id = id.app_id; |
| 173 const ArcAppListPrefs* arc_prefs = GetArcAppListPrefs(); | 175 const ArcAppListPrefs* arc_prefs = GetArcAppListPrefs(); |
| 174 if (arc_prefs && arc_prefs->IsRegistered(app_id)) { | 176 if (arc_prefs && arc_prefs->IsRegistered(app_id)) { |
| 175 arc::LaunchApp(profile_, app_id, event_flags); | 177 arc::LaunchApp(profile_, app_id, event_flags); |
| 176 return; | 178 return; |
| 177 } | 179 } |
| 178 | 180 |
| 179 // |extension| could be null when it is being unloaded for updating. | 181 // |extension| could be null when it is being unloaded for updating. |
| 180 const extensions::Extension* extension = GetExtensionByID(profile_, app_id); | 182 const extensions::Extension* extension = GetExtensionByID(profile_, app_id); |
| 181 if (!extension) | 183 if (!extension) |
| 182 return; | 184 return; |
| 183 | 185 |
| 184 if (!extensions::util::IsAppLaunchableWithoutEnabling(app_id, profile_)) { | 186 if (!extensions::util::IsAppLaunchableWithoutEnabling(app_id, profile_)) { |
| 185 // Do nothing if there is already a running enable flow. | 187 // Do nothing if there is already a running enable flow. |
| 186 if (extension_enable_flow_) | 188 if (extension_enable_flow_) |
| 187 return; | 189 return; |
| 188 | 190 |
| 189 extension_enable_flow_.reset( | 191 extension_enable_flow_.reset( |
| 190 new ExtensionEnableFlow(profile_, app_id, this)); | 192 new ExtensionEnableFlow(profile_, app_id, this)); |
| 191 extension_enable_flow_->StartForNativeWindow(nullptr); | 193 extension_enable_flow_->StartForNativeWindow(nullptr); |
| 192 return; | 194 return; |
| 193 } | 195 } |
| 194 | 196 |
| 195 // The app will be created for the currently active profile. | 197 // The app will be created for the currently active profile. |
| 196 AppLaunchParams params = CreateAppLaunchParamsWithEventFlags( | 198 AppLaunchParams params = CreateAppLaunchParamsWithEventFlags( |
| 197 profile_, extension, event_flags, extensions::SOURCE_APP_LAUNCHER); | 199 profile_, extension, event_flags, extensions::SOURCE_APP_LAUNCHER, |
| 200 display_id); |
| 198 if (source != ash::LAUNCH_FROM_UNKNOWN && | 201 if (source != ash::LAUNCH_FROM_UNKNOWN && |
| 199 app_id == extensions::kWebStoreAppId) { | 202 app_id == extensions::kWebStoreAppId) { |
| 200 // Get the corresponding source string. | 203 // Get the corresponding source string. |
| 201 std::string source_value = GetSourceFromAppListSource(source); | 204 std::string source_value = GetSourceFromAppListSource(source); |
| 202 | 205 |
| 203 // Set an override URL to include the source. | 206 // Set an override URL to include the source. |
| 204 GURL extension_url = extensions::AppLaunchInfo::GetFullLaunchURL(extension); | 207 GURL extension_url = extensions::AppLaunchInfo::GetFullLaunchURL(extension); |
| 205 params.override_url = net::AppendQueryParameter( | 208 params.override_url = net::AppendQueryParameter( |
| 206 extension_url, extension_urls::kWebstoreSourceField, source_value); | 209 extension_url, extension_urls::kWebstoreSourceField, source_value); |
| 207 } | 210 } |
| 208 params.launch_id = id.launch_id; | 211 params.launch_id = id.launch_id; |
| 209 | 212 |
| 210 OpenApplication(params); | 213 OpenApplication(params); |
| 211 } | 214 } |
| 212 | 215 |
| 213 ArcAppListPrefs* LauncherControllerHelper::GetArcAppListPrefs() const { | 216 ArcAppListPrefs* LauncherControllerHelper::GetArcAppListPrefs() const { |
| 214 return ArcAppListPrefs::Get(profile_); | 217 return ArcAppListPrefs::Get(profile_); |
| 215 } | 218 } |
| 216 | 219 |
| 217 void LauncherControllerHelper::ExtensionEnableFlowFinished() { | 220 void LauncherControllerHelper::ExtensionEnableFlowFinished() { |
| 218 LaunchApp(ash::ShelfID(extension_enable_flow_->extension_id()), | 221 LaunchApp(ash::ShelfID(extension_enable_flow_->extension_id()), |
| 219 ash::LAUNCH_FROM_UNKNOWN, ui::EF_NONE); | 222 ash::LAUNCH_FROM_UNKNOWN, ui::EF_NONE, display::kInvalidDisplayId); |
| 220 extension_enable_flow_.reset(); | 223 extension_enable_flow_.reset(); |
| 221 } | 224 } |
| 222 | 225 |
| 223 void LauncherControllerHelper::ExtensionEnableFlowAborted(bool user_initiated) { | 226 void LauncherControllerHelper::ExtensionEnableFlowAborted(bool user_initiated) { |
| 224 extension_enable_flow_.reset(); | 227 extension_enable_flow_.reset(); |
| 225 } | 228 } |
| OLD | NEW |