| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "apps/launcher.h" | 9 #include "apps/launcher.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 params.container, | 202 params.container, |
| 203 extension); | 203 extension); |
| 204 | 204 |
| 205 Browser* browser = new Browser(browser_params); | 205 Browser* browser = new Browser(browser_params); |
| 206 | 206 |
| 207 WebContents* web_contents = chrome::AddSelectedTabWithURL( | 207 WebContents* web_contents = chrome::AddSelectedTabWithURL( |
| 208 browser, url, ui::PAGE_TRANSITION_AUTO_TOPLEVEL); | 208 browser, url, ui::PAGE_TRANSITION_AUTO_TOPLEVEL); |
| 209 web_contents->GetMutableRendererPrefs()->can_accept_load_drops = false; | 209 web_contents->GetMutableRendererPrefs()->can_accept_load_drops = false; |
| 210 web_contents->GetRenderViewHost()->SyncRendererPrefs(); | 210 web_contents->GetRenderViewHost()->SyncRendererPrefs(); |
| 211 | 211 |
| 212 browser->window()->Show(); | 212 // TODO(johnme): Can we sometimes be certain this was for a user gesture? |
| 213 browser->window()->Show(false /* user_gesture */); |
| 213 | 214 |
| 214 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial | 215 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial |
| 215 // focus explicitly. | 216 // focus explicitly. |
| 216 web_contents->SetInitialFocus(); | 217 web_contents->SetInitialFocus(); |
| 217 return web_contents; | 218 return web_contents; |
| 218 } | 219 } |
| 219 | 220 |
| 220 WebContents* OpenApplicationTab(const AppLaunchParams& launch_params, | 221 WebContents* OpenApplicationTab(const AppLaunchParams& launch_params, |
| 221 const GURL& url) { | 222 const GURL& url) { |
| 222 const Extension* extension = GetExtension(launch_params); | 223 const Extension* extension = GetExtension(launch_params); |
| 223 CHECK(extension); | 224 CHECK(extension); |
| 224 Profile* const profile = launch_params.profile; | 225 Profile* const profile = launch_params.profile; |
| 225 WindowOpenDisposition disposition = launch_params.disposition; | 226 WindowOpenDisposition disposition = launch_params.disposition; |
| 227 // TODO(johnme): Can we sometimes be certain this was for a user gesture? |
| 228 bool user_gesture = false; |
| 226 | 229 |
| 227 Browser* browser = chrome::FindTabbedBrowser(profile, | 230 Browser* browser = chrome::FindTabbedBrowser(profile, |
| 228 false, | 231 false, |
| 229 launch_params.desktop_type); | 232 launch_params.desktop_type); |
| 230 WebContents* contents = NULL; | 233 WebContents* contents = NULL; |
| 231 if (!browser) { | 234 if (!browser) { |
| 232 // No browser for this profile, need to open a new one. | 235 // No browser for this profile, need to open a new one. |
| 233 browser = new Browser(Browser::CreateParams(Browser::TYPE_TABBED, | 236 browser = new Browser(Browser::CreateParams(Browser::TYPE_TABBED, |
| 234 profile, | 237 profile, |
| 235 launch_params.desktop_type)); | 238 launch_params.desktop_type)); |
| 236 browser->window()->Show(); | 239 browser->window()->Show(user_gesture); |
| 237 // There's no current tab in this browser window, so add a new one. | 240 // There's no current tab in this browser window, so add a new one. |
| 238 disposition = NEW_FOREGROUND_TAB; | 241 disposition = NEW_FOREGROUND_TAB; |
| 239 } else { | 242 } else { |
| 240 // For existing browser, ensure its window is shown and activated. | 243 // For existing browser, ensure its window is shown and activated. |
| 241 browser->window()->Show(); | 244 browser->window()->Show(user_gesture); |
| 242 // TODO(johnme): Can we sometimes be certain this was for a user gesture? | 245 browser->window()->Activate(user_gesture); |
| 243 browser->window()->Activate(false /* user_gesture */); | |
| 244 } | 246 } |
| 245 | 247 |
| 246 extensions::LaunchType launch_type = | 248 extensions::LaunchType launch_type = |
| 247 extensions::GetLaunchType(ExtensionPrefs::Get(profile), extension); | 249 extensions::GetLaunchType(ExtensionPrefs::Get(profile), extension); |
| 248 UMA_HISTOGRAM_ENUMERATION("Extensions.AppTabLaunchType", launch_type, 100); | 250 UMA_HISTOGRAM_ENUMERATION("Extensions.AppTabLaunchType", launch_type, 100); |
| 249 | 251 |
| 250 int add_type = TabStripModel::ADD_ACTIVE; | 252 int add_type = TabStripModel::ADD_ACTIVE; |
| 251 if (launch_type == extensions::LAUNCH_TYPE_PINNED) | 253 if (launch_type == extensions::LAUNCH_TYPE_PINNED) |
| 252 add_type |= TabStripModel::ADD_PINNED; | 254 add_type |= TabStripModel::ADD_PINNED; |
| 253 | 255 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 extensions::TabHelper::FromWebContents(tab)->UpdateShortcutOnLoadComplete(); | 409 extensions::TabHelper::FromWebContents(tab)->UpdateShortcutOnLoadComplete(); |
| 408 | 410 |
| 409 return tab; | 411 return tab; |
| 410 } | 412 } |
| 411 | 413 |
| 412 bool CanLaunchViaEvent(const extensions::Extension* extension) { | 414 bool CanLaunchViaEvent(const extensions::Extension* extension) { |
| 413 const extensions::Feature* feature = | 415 const extensions::Feature* feature = |
| 414 extensions::FeatureProvider::GetAPIFeature("app.runtime"); | 416 extensions::FeatureProvider::GetAPIFeature("app.runtime"); |
| 415 return feature->IsAvailableToExtension(extension).is_available(); | 417 return feature->IsAvailableToExtension(extension).is_available(); |
| 416 } | 418 } |
| OLD | NEW |