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" |
11 #include "chrome/browser/extensions/extension_prefs.h" | 11 #include "chrome/browser/extensions/extension_prefs.h" |
12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
13 #include "chrome/browser/extensions/platform_app_launcher.h" | 13 #include "chrome/browser/extensions/platform_app_launcher.h" |
14 #include "chrome/browser/extensions/tab_helper.h" | 14 #include "chrome/browser/extensions/tab_helper.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
17 #include "chrome/browser/ui/browser_commands.h" | 17 #include "chrome/browser/ui/browser_commands.h" |
18 #include "chrome/browser/ui/browser_finder.h" | 18 #include "chrome/browser/ui/browser_finder.h" |
19 #include "chrome/browser/ui/browser_tabstrip.h" | 19 #include "chrome/browser/ui/browser_tabstrip.h" |
20 #include "chrome/browser/ui/browser_window.h" | 20 #include "chrome/browser/ui/browser_window.h" |
21 #include "chrome/browser/ui/panels/panel_manager.h" | |
22 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 21 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
23 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
24 #include "chrome/browser/web_applications/web_app.h" | 23 #include "chrome/browser/web_applications/web_app.h" |
25 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/common/extensions/extension.h" | 25 #include "chrome/common/extensions/extension.h" |
27 #include "chrome/common/extensions/extension_constants.h" | 26 #include "chrome/common/extensions/extension_constants.h" |
28 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
29 #include "content/public/browser/render_view_host.h" | 28 #include "content/public/browser/render_view_host.h" |
30 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
31 #include "content/public/browser/web_contents_view.h" | 30 #include "content/public/browser/web_contents_view.h" |
32 #include "content/public/common/renderer_preferences.h" | 31 #include "content/public/common/renderer_preferences.h" |
33 | 32 |
34 #if defined(USE_ASH) | |
35 #include "ash/ash_switches.h" | |
36 #include "chrome/browser/ui/views/ash/panel_view_aura.h" | |
37 #endif | |
38 | |
39 using content::WebContents; | 33 using content::WebContents; |
40 using extensions::Extension; | 34 using extensions::Extension; |
41 using extensions::ExtensionPrefs; | 35 using extensions::ExtensionPrefs; |
42 | 36 |
43 namespace { | 37 namespace { |
44 | 38 |
45 // Get the launch URL for a given extension, with optional override/fallback. | 39 // Get the launch URL for a given extension, with optional override/fallback. |
46 // |override_url|, if non-empty, will be preferred over the extension's | 40 // |override_url|, if non-empty, will be preferred over the extension's |
47 // launch url. | 41 // launch url. |
48 GURL UrlForExtension(const Extension* extension, | 42 GURL UrlForExtension(const Extension* extension, |
(...skipping 13 matching lines...) Expand all Loading... |
62 // For extensions lacking launch urls, determine a reasonable fallback. | 56 // For extensions lacking launch urls, determine a reasonable fallback. |
63 if (!url.is_valid()) { | 57 if (!url.is_valid()) { |
64 url = extension->options_url(); | 58 url = extension->options_url(); |
65 if (!url.is_valid()) | 59 if (!url.is_valid()) |
66 url = GURL(chrome::kChromeUIExtensionsURL); | 60 url = GURL(chrome::kChromeUIExtensionsURL); |
67 } | 61 } |
68 | 62 |
69 return url; | 63 return url; |
70 } | 64 } |
71 | 65 |
72 bool AllowPanels(const std::string& app_name) { | |
73 return PanelManager::ShouldUsePanels( | |
74 web_app::GetExtensionIdFromApplicationName(app_name)); | |
75 } | |
76 | |
77 WebContents* OpenApplicationWindow( | 66 WebContents* OpenApplicationWindow( |
78 Profile* profile, | 67 Profile* profile, |
79 const Extension* extension, | 68 const Extension* extension, |
80 extension_misc::LaunchContainer container, | 69 extension_misc::LaunchContainer container, |
81 const GURL& url_input, | 70 const GURL& url_input, |
82 Browser** app_browser) { | 71 Browser** app_browser) { |
83 DCHECK(!url_input.is_empty() || extension); | 72 DCHECK(!url_input.is_empty() || extension); |
84 GURL url = UrlForExtension(extension, url_input); | 73 GURL url = UrlForExtension(extension, url_input); |
85 | 74 |
86 std::string app_name; | 75 std::string app_name; |
87 app_name = extension ? | 76 app_name = extension ? |
88 web_app::GenerateApplicationNameFromExtensionId(extension->id()) : | 77 web_app::GenerateApplicationNameFromExtensionId(extension->id()) : |
89 web_app::GenerateApplicationNameFromURL(url); | 78 web_app::GenerateApplicationNameFromURL(url); |
90 | 79 |
91 Browser::Type type = Browser::TYPE_POPUP; | 80 Browser::Type type = Browser::TYPE_POPUP; |
92 if (extension && | |
93 container == extension_misc::LAUNCH_PANEL && | |
94 AllowPanels(app_name)) { | |
95 type = Browser::TYPE_PANEL; | |
96 } | |
97 | 81 |
98 gfx::Rect window_bounds; | 82 gfx::Rect window_bounds; |
99 if (extension) { | 83 if (extension) { |
100 window_bounds.set_width(extension->launch_width()); | 84 window_bounds.set_width(extension->launch_width()); |
101 window_bounds.set_height(extension->launch_height()); | 85 window_bounds.set_height(extension->launch_height()); |
102 } | 86 } |
103 | 87 |
104 Browser::CreateParams params(type, profile); | 88 Browser::CreateParams params(type, profile); |
105 params.app_name = app_name; | 89 params.app_name = app_name; |
106 params.initial_bounds = window_bounds; | 90 params.initial_bounds = window_bounds; |
(...skipping 16 matching lines...) Expand all Loading... |
123 Browser* browser = new Browser(params); | 107 Browser* browser = new Browser(params); |
124 | 108 |
125 if (app_browser) | 109 if (app_browser) |
126 *app_browser = browser; | 110 *app_browser = browser; |
127 | 111 |
128 TabContents* tab_contents = chrome::AddSelectedTabWithURL( | 112 TabContents* tab_contents = chrome::AddSelectedTabWithURL( |
129 browser, url, content::PAGE_TRANSITION_START_PAGE); | 113 browser, url, content::PAGE_TRANSITION_START_PAGE); |
130 WebContents* contents = tab_contents->web_contents(); | 114 WebContents* contents = tab_contents->web_contents(); |
131 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; | 115 contents->GetMutableRendererPrefs()->can_accept_load_drops = false; |
132 contents->GetRenderViewHost()->SyncRendererPrefs(); | 116 contents->GetRenderViewHost()->SyncRendererPrefs(); |
133 // TODO(stevenjb): Find the right centralized place to do this. Currently it | |
134 // is only done for app tabs in normal browsers through SetExtensionAppById. | |
135 if (extension && type == Browser::TYPE_PANEL) { | |
136 tab_contents->extension_tab_helper()-> | |
137 SetExtensionAppIconById(extension->id()); | |
138 } | |
139 | 117 |
140 browser->window()->Show(); | 118 browser->window()->Show(); |
141 | 119 |
142 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial | 120 // TODO(jcampan): http://crbug.com/8123 we should not need to set the initial |
143 // focus explicitly. | 121 // focus explicitly. |
144 contents->GetView()->SetInitialFocus(); | 122 contents->GetView()->SetInitialFocus(); |
145 return contents; | 123 return contents; |
146 } | 124 } |
147 | 125 |
148 WebContents* OpenApplicationTab(Profile* profile, | 126 WebContents* OpenApplicationTab(Profile* profile, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 // full screen mode in this case? | 207 // full screen mode in this case? |
230 if (launch_type == ExtensionPrefs::LAUNCH_FULLSCREEN && | 208 if (launch_type == ExtensionPrefs::LAUNCH_FULLSCREEN && |
231 !browser->window()->IsFullscreen()) { | 209 !browser->window()->IsFullscreen()) { |
232 chrome::ToggleFullscreenMode(browser); | 210 chrome::ToggleFullscreenMode(browser); |
233 } | 211 } |
234 #endif | 212 #endif |
235 | 213 |
236 return contents; | 214 return contents; |
237 } | 215 } |
238 | 216 |
239 WebContents* OpenApplicationPanel( | |
240 Profile* profile, | |
241 const Extension* extension, | |
242 const GURL& url_input) { | |
243 GURL url = UrlForExtension(extension, url_input); | |
244 std::string app_name = | |
245 web_app::GenerateApplicationNameFromExtensionId(extension->id()); | |
246 gfx::Rect panel_bounds; | |
247 panel_bounds.set_width(extension->launch_width()); | |
248 panel_bounds.set_height(extension->launch_height()); | |
249 #if defined(USE_ASH) | |
250 PanelViewAura* panel_view = new PanelViewAura(app_name); | |
251 panel_view->Init(profile, url, panel_bounds); | |
252 return panel_view->WebContents(); | |
253 #else | |
254 Panel* panel = PanelManager::GetInstance()->CreatePanel( | |
255 app_name, profile, url, panel_bounds.size()); | |
256 panel->Show(); | |
257 return panel->GetWebContents(); | |
258 #endif | |
259 } | |
260 | |
261 } // namespace | 217 } // namespace |
262 | 218 |
263 namespace application_launch { | 219 namespace application_launch { |
264 | 220 |
265 LaunchParams::LaunchParams(Profile* profile, | 221 LaunchParams::LaunchParams(Profile* profile, |
266 const extensions::Extension* extension, | 222 const extensions::Extension* extension, |
267 extension_misc::LaunchContainer container, | 223 extension_misc::LaunchContainer container, |
268 WindowOpenDisposition disposition) | 224 WindowOpenDisposition disposition) |
269 : profile(profile), | 225 : profile(profile), |
270 extension(extension), | 226 extension(extension), |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 // OnDidGetApplicationInfo, which calls | 289 // OnDidGetApplicationInfo, which calls |
334 // web_app::UpdateShortcutForTabContents when it sees UPDATE_SHORTCUT as | 290 // web_app::UpdateShortcutForTabContents when it sees UPDATE_SHORTCUT as |
335 // pending web app action. | 291 // pending web app action. |
336 tab_contents->extension_tab_helper()->set_pending_web_app_action( | 292 tab_contents->extension_tab_helper()->set_pending_web_app_action( |
337 extensions::TabHelper::UPDATE_SHORTCUT); | 293 extensions::TabHelper::UPDATE_SHORTCUT); |
338 | 294 |
339 return tab; | 295 return tab; |
340 } | 296 } |
341 | 297 |
342 } // namespace application_launch | 298 } // namespace application_launch |
OLD | NEW |