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/extensions/application_launch.h" | 5 #include "chrome/browser/ui/extensions/application_launch.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "chrome/browser/extensions/default_apps_trial.h" | 10 #include "chrome/browser/extensions/default_apps_trial.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 } | 72 } |
73 | 73 |
74 return url; | 74 return url; |
75 } | 75 } |
76 | 76 |
77 bool AllowPanels(const std::string& app_name) { | 77 bool AllowPanels(const std::string& app_name) { |
78 return PanelManager::ShouldUsePanels( | 78 return PanelManager::ShouldUsePanels( |
79 web_app::GetExtensionIdFromApplicationName(app_name)); | 79 web_app::GetExtensionIdFromApplicationName(app_name)); |
80 } | 80 } |
81 | 81 |
82 } // namespace | |
83 | |
84 namespace application_launch { | |
85 | |
86 WebContents* OpenApplication(Profile* profile, | |
87 const Extension* extension, | |
88 extension_misc::LaunchContainer container, | |
89 const GURL& override_url, | |
90 WindowOpenDisposition disposition, | |
91 const CommandLine* command_line) { | |
92 WebContents* tab = NULL; | |
93 ExtensionPrefs* prefs = profile->GetExtensionService()->extension_prefs(); | |
94 prefs->SetActiveBit(extension->id(), true); | |
95 | |
96 UMA_HISTOGRAM_ENUMERATION("Extensions.AppLaunchContainer", container, 100); | |
97 #if defined(OS_CHROMEOS) | |
98 if (chromeos::KioskModeSettings::Get()->IsKioskModeEnabled()) | |
99 chromeos::KioskModeMetrics::Get()->UserOpenedApp(); | |
100 #endif | |
101 | |
102 if (extension->is_platform_app()) { | |
103 extensions::LaunchPlatformApp(profile, extension, command_line); | |
104 return NULL; | |
105 } | |
106 | |
107 switch (container) { | |
108 case extension_misc::LAUNCH_NONE: { | |
109 NOTREACHED(); | |
110 break; | |
111 } | |
112 case extension_misc::LAUNCH_PANEL: | |
113 case extension_misc::LAUNCH_WINDOW: | |
114 tab = OpenApplicationWindow(profile, extension, container, | |
115 override_url, NULL); | |
116 break; | |
117 case extension_misc::LAUNCH_TAB: { | |
118 tab = OpenApplicationTab(profile, extension, override_url, | |
119 disposition); | |
120 break; | |
121 } | |
122 default: | |
123 NOTREACHED(); | |
124 break; | |
125 } | |
126 return tab; | |
127 } | |
128 | |
129 WebContents* OpenApplicationWindow( | 82 WebContents* OpenApplicationWindow( |
130 Profile* profile, | 83 Profile* profile, |
131 const Extension* extension, | 84 const Extension* extension, |
132 extension_misc::LaunchContainer container, | 85 extension_misc::LaunchContainer container, |
133 const GURL& url_input, | 86 const GURL& url_input, |
134 Browser** app_browser) { | 87 Browser** app_browser) { |
135 DCHECK(!url_input.is_empty() || extension); | 88 DCHECK(!url_input.is_empty() || extension); |
136 GURL url = UrlForExtension(extension, url_input); | 89 GURL url = UrlForExtension(extension, url_input); |
137 | 90 |
138 std::string app_name; | 91 std::string app_name; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 } | 143 } |
191 | 144 |
192 browser->window()->Show(); | 145 browser->window()->Show(); |
193 | 146 |
194 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial | 147 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial |
195 // focus explicitly. | 148 // focus explicitly. |
196 contents->GetView()->SetInitialFocus(); | 149 contents->GetView()->SetInitialFocus(); |
197 return contents; | 150 return contents; |
198 } | 151 } |
199 | 152 |
200 WebContents* OpenAppShortcutWindow(Profile* profile, | |
201 const GURL& url, | |
202 bool update_shortcut) { | |
203 Browser* app_browser; | |
204 WebContents* tab = OpenApplicationWindow( | |
205 profile, | |
206 NULL, // this is a URL app. No extension. | |
207 extension_misc::LAUNCH_WINDOW, | |
208 url, | |
209 &app_browser); | |
210 | |
211 if (!tab) | |
212 return NULL; | |
213 | |
214 if (update_shortcut) { | |
215 TabContents* tab_contents = TabContents::FromWebContents(tab); | |
216 // Set UPDATE_SHORTCUT as the pending web app action. This action is picked | |
217 // up in LoadingStateChanged to schedule a GetApplicationInfo. And when | |
218 // the web app info is available, ExtensionTabHelper notifies Browser via | |
219 // OnDidGetApplicationInfo, which calls | |
220 // web_app::UpdateShortcutForTabContents when it sees UPDATE_SHORTCUT as | |
221 // pending web app action. | |
222 tab_contents->extension_tab_helper()->set_pending_web_app_action( | |
223 ExtensionTabHelper::UPDATE_SHORTCUT); | |
224 } | |
225 return tab; | |
226 } | |
227 | |
228 WebContents* OpenApplicationTab(Profile* profile, | 153 WebContents* OpenApplicationTab(Profile* profile, |
229 const Extension* extension, | 154 const Extension* extension, |
230 const GURL& override_url, | 155 const GURL& override_url, |
231 WindowOpenDisposition disposition) { | 156 WindowOpenDisposition disposition) { |
232 Browser* browser = browser::FindTabbedBrowser(profile, false); | 157 Browser* browser = browser::FindTabbedBrowser(profile, false); |
233 WebContents* contents = NULL; | 158 WebContents* contents = NULL; |
234 if (!browser) { | 159 if (!browser) { |
235 // No browser for this profile, need to open a new one. | 160 // No browser for this profile, need to open a new one. |
236 browser = Browser::Create(profile); | 161 browser = Browser::Create(profile); |
237 browser->window()->Show(); | 162 browser->window()->Show(); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 // full screen mode in this case? | 234 // full screen mode in this case? |
310 if (launch_type == ExtensionPrefs::LAUNCH_FULLSCREEN && | 235 if (launch_type == ExtensionPrefs::LAUNCH_FULLSCREEN && |
311 !browser->window()->IsFullscreen()) { | 236 !browser->window()->IsFullscreen()) { |
312 chrome::ToggleFullscreenMode(browser); | 237 chrome::ToggleFullscreenMode(browser); |
313 } | 238 } |
314 #endif | 239 #endif |
315 | 240 |
316 return contents; | 241 return contents; |
317 } | 242 } |
318 | 243 |
| 244 WebContents* OpenApplicationPanel( |
| 245 Profile* profile, |
| 246 const Extension* extension, |
| 247 const GURL& url_input) { |
| 248 GURL url = UrlForExtension(extension, url_input); |
| 249 std::string app_name = |
| 250 web_app::GenerateApplicationNameFromExtensionId(extension->id()); |
| 251 gfx::Rect panel_bounds; |
| 252 panel_bounds.set_width(extension->launch_width()); |
| 253 panel_bounds.set_height(extension->launch_height()); |
| 254 #if defined(USE_ASH) |
| 255 PanelViewAura* panel_view = new PanelViewAura(app_name); |
| 256 panel_view->Init(profile, url, panel_bounds); |
| 257 return panel_view->WebContents(); |
| 258 #else |
| 259 Panel* panel = PanelManager::GetInstance()->CreatePanel( |
| 260 app_name, profile, url, panel_bounds.size()); |
| 261 panel->Show(); |
| 262 return panel->GetWebContents(); |
| 263 #endif |
| 264 } |
| 265 |
| 266 } // namespace |
| 267 |
| 268 namespace application_launch { |
| 269 |
| 270 LaunchParams::LaunchParams(Profile* profile, |
| 271 const extensions::Extension* extension, |
| 272 extension_misc::LaunchContainer container, |
| 273 WindowOpenDisposition disposition) |
| 274 : profile(profile), |
| 275 extension(extension), |
| 276 container(container), |
| 277 disposition(disposition), |
| 278 override_url(), |
| 279 command_line(NULL) {} |
| 280 |
| 281 WebContents* OpenApplication(const LaunchParams& params) { |
| 282 Profile* profile = params.profile; |
| 283 const extensions::Extension* extension = params.extension; |
| 284 extension_misc::LaunchContainer container = params.container; |
| 285 const GURL& override_url = params.override_url; |
| 286 |
| 287 WebContents* tab = NULL; |
| 288 ExtensionPrefs* prefs = profile->GetExtensionService()->extension_prefs(); |
| 289 prefs->SetActiveBit(extension->id(), true); |
| 290 |
| 291 UMA_HISTOGRAM_ENUMERATION("Extensions.AppLaunchContainer", container, 100); |
| 292 #if defined(OS_CHROMEOS) |
| 293 if (chromeos::KioskModeSettings::Get()->IsKioskModeEnabled()) |
| 294 chromeos::KioskModeMetrics::Get()->UserOpenedApp(); |
| 295 #endif |
| 296 |
| 297 if (extension->is_platform_app()) { |
| 298 extensions::LaunchPlatformApp(profile, extension, params.command_line); |
| 299 return NULL; |
| 300 } |
| 301 |
| 302 switch (container) { |
| 303 case extension_misc::LAUNCH_NONE: { |
| 304 NOTREACHED(); |
| 305 break; |
| 306 } |
| 307 case extension_misc::LAUNCH_PANEL: |
| 308 case extension_misc::LAUNCH_WINDOW: |
| 309 tab = OpenApplicationWindow(profile, extension, container, |
| 310 override_url, NULL); |
| 311 break; |
| 312 case extension_misc::LAUNCH_TAB: { |
| 313 tab = OpenApplicationTab(profile, extension, override_url, |
| 314 params.disposition); |
| 315 break; |
| 316 } |
| 317 default: |
| 318 NOTREACHED(); |
| 319 break; |
| 320 } |
| 321 return tab; |
| 322 } |
| 323 |
| 324 WebContents* OpenAppShortcutWindow(Profile* profile, |
| 325 const GURL& url) { |
| 326 Browser* app_browser; |
| 327 WebContents* tab = OpenApplicationWindow( |
| 328 profile, |
| 329 NULL, // this is a URL app. No extension. |
| 330 extension_misc::LAUNCH_WINDOW, |
| 331 url, |
| 332 &app_browser); |
| 333 |
| 334 if (!tab) |
| 335 return NULL; |
| 336 |
| 337 TabContents* tab_contents = TabContents::FromWebContents(tab); |
| 338 // Set UPDATE_SHORTCUT as the pending web app action. This action is picked |
| 339 // up in LoadingStateChanged to schedule a GetApplicationInfo. And when |
| 340 // the web app info is available, ExtensionTabHelper notifies Browser via |
| 341 // OnDidGetApplicationInfo, which calls |
| 342 // web_app::UpdateShortcutForTabContents when it sees UPDATE_SHORTCUT as |
| 343 // pending web app action. |
| 344 tab_contents->extension_tab_helper()->set_pending_web_app_action( |
| 345 ExtensionTabHelper::UPDATE_SHORTCUT); |
| 346 |
| 347 return tab; |
| 348 } |
| 349 |
319 } // namespace application_launch | 350 } // namespace application_launch |
OLD | NEW |