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

Side by Side Diff: apps/app_shim/extension_app_shim_handler_mac.cc

Issue 166573005: Rename apps::ShellWindow to apps::AppWindow (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, nits (rename) Created 6 years, 10 months 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "apps/app_shim/extension_app_shim_handler_mac.h" 5 #include "apps/app_shim/extension_app_shim_handler_mac.h"
6 6
7 #include "apps/app_lifetime_monitor_factory.h" 7 #include "apps/app_lifetime_monitor_factory.h"
8 #include "apps/app_shim/app_shim_host_manager_mac.h" 8 #include "apps/app_shim/app_shim_host_manager_mac.h"
9 #include "apps/app_shim/app_shim_messages.h" 9 #include "apps/app_shim/app_shim_messages.h"
10 #include "apps/app_window.h"
11 #include "apps/app_window_registry.h"
10 #include "apps/launcher.h" 12 #include "apps/launcher.h"
11 #include "apps/shell_window.h"
12 #include "apps/shell_window_registry.h"
13 #include "apps/ui/native_app_window.h" 13 #include "apps/ui/native_app_window.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/chrome_notification_types.h" 17 #include "chrome/browser/chrome_notification_types.h"
18 #include "chrome/browser/extensions/extension_host.h" 18 #include "chrome/browser/extensions/extension_host.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/profiles/profile_manager.h" 20 #include "chrome/browser/profiles/profile_manager.h"
21 #include "chrome/browser/ui/extensions/extension_enable_flow.h" 21 #include "chrome/browser/ui/extensions/extension_enable_flow.h"
22 #include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h" 22 #include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h"
23 #include "chrome/browser/ui/web_applications/web_app_ui.h" 23 #include "chrome/browser/ui/web_applications/web_app_ui.h"
24 #include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h" 24 #include "chrome/browser/ui/webui/ntp/core_app_launcher_handler.h"
25 #include "chrome/browser/web_applications/web_app_mac.h" 25 #include "chrome/browser/web_applications/web_app_mac.h"
26 #include "chrome/common/extensions/extension_constants.h" 26 #include "chrome/common/extensions/extension_constants.h"
27 #include "content/public/browser/notification_details.h" 27 #include "content/public/browser/notification_details.h"
28 #include "content/public/browser/notification_service.h" 28 #include "content/public/browser/notification_service.h"
29 #include "content/public/browser/notification_source.h" 29 #include "content/public/browser/notification_source.h"
30 #include "extensions/browser/extension_registry.h" 30 #include "extensions/browser/extension_registry.h"
31 #include "ui/base/cocoa/focus_window_set.h" 31 #include "ui/base/cocoa/focus_window_set.h"
32 32
33 using extensions::ExtensionRegistry; 33 using extensions::ExtensionRegistry;
34 34
35 namespace { 35 namespace {
36 36
37 typedef apps::ShellWindowRegistry::ShellWindowList ShellWindowList; 37 typedef apps::AppWindowRegistry::AppWindowList AppWindowList;
38 38
39 void ProfileLoadedCallback(base::Callback<void(Profile*)> callback, 39 void ProfileLoadedCallback(base::Callback<void(Profile*)> callback,
40 Profile* profile, 40 Profile* profile,
41 Profile::CreateStatus status) { 41 Profile::CreateStatus status) {
42 if (status == Profile::CREATE_STATUS_INITIALIZED) { 42 if (status == Profile::CREATE_STATUS_INITIALIZED) {
43 callback.Run(profile); 43 callback.Run(profile);
44 return; 44 return;
45 } 45 }
46 46
47 // This should never get an error since it only loads existing profiles. 47 // This should never get an error since it only loads existing profiles.
48 DCHECK_EQ(Profile::CREATE_STATUS_CREATED, status); 48 DCHECK_EQ(Profile::CREATE_STATUS_CREATED, status);
49 } 49 }
50 50
51 void SetAppHidden(Profile* profile, const std::string& app_id, bool hidden) { 51 void SetAppHidden(Profile* profile, const std::string& app_id, bool hidden) {
52 ShellWindowList windows = 52 AppWindowList windows =
53 apps::ShellWindowRegistry::Get(profile)->GetShellWindowsForApp(app_id); 53 apps::AppWindowRegistry::Get(profile)->GetAppWindowsForApp(app_id);
54 for (ShellWindowList::const_reverse_iterator it = windows.rbegin(); 54 for (AppWindowList::const_reverse_iterator it = windows.rbegin();
55 it != windows.rend(); ++it) { 55 it != windows.rend();
56 ++it) {
56 if (hidden) 57 if (hidden)
57 (*it)->GetBaseWindow()->HideWithApp(); 58 (*it)->GetBaseWindow()->HideWithApp();
58 else 59 else
59 (*it)->GetBaseWindow()->ShowWithApp(); 60 (*it)->GetBaseWindow()->ShowWithApp();
60 } 61 }
61 } 62 }
62 63
63 bool FocusWindows(const ShellWindowList& windows) { 64 bool FocusWindows(const AppWindowList& windows) {
64 if (windows.empty()) 65 if (windows.empty())
65 return false; 66 return false;
66 67
67 std::set<gfx::NativeWindow> native_windows; 68 std::set<gfx::NativeWindow> native_windows;
68 for (ShellWindowList::const_iterator it = windows.begin(); 69 for (AppWindowList::const_iterator it = windows.begin(); it != windows.end();
69 it != windows.end(); ++it) { 70 ++it) {
70 native_windows.insert((*it)->GetNativeWindow()); 71 native_windows.insert((*it)->GetNativeWindow());
71 } 72 }
72 // Allow workspace switching. For the browser process, we can reasonably rely 73 // Allow workspace switching. For the browser process, we can reasonably rely
73 // on OS X to switch spaces for us and honor relevant user settings. But shims 74 // on OS X to switch spaces for us and honor relevant user settings. But shims
74 // don't have windows, so we have to do it ourselves. 75 // don't have windows, so we have to do it ourselves.
75 ui::FocusWindowSet(native_windows, true); 76 ui::FocusWindowSet(native_windows, true);
76 return true; 77 return true;
77 } 78 }
78 79
79 // Attempts to launch a packaged app, prompting the user to enable it if 80 // Attempts to launch a packaged app, prompting the user to enable it if
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 const base::FilePath& path, 147 const base::FilePath& path,
147 base::Callback<void(Profile*)> callback) { 148 base::Callback<void(Profile*)> callback) {
148 ProfileManager* profile_manager = g_browser_process->profile_manager(); 149 ProfileManager* profile_manager = g_browser_process->profile_manager();
149 base::FilePath full_path = profile_manager->user_data_dir().Append(path); 150 base::FilePath full_path = profile_manager->user_data_dir().Append(path);
150 profile_manager->CreateProfileAsync( 151 profile_manager->CreateProfileAsync(
151 full_path, 152 full_path,
152 base::Bind(&ProfileLoadedCallback, callback), 153 base::Bind(&ProfileLoadedCallback, callback),
153 base::string16(), base::string16(), std::string()); 154 base::string16(), base::string16(), std::string());
154 } 155 }
155 156
156 ShellWindowList ExtensionAppShimHandler::Delegate::GetWindows( 157 AppWindowList ExtensionAppShimHandler::Delegate::GetWindows(
157 Profile* profile, 158 Profile* profile,
158 const std::string& extension_id) { 159 const std::string& extension_id) {
159 return ShellWindowRegistry::Get(profile)->GetShellWindowsForApp(extension_id); 160 return AppWindowRegistry::Get(profile)->GetAppWindowsForApp(extension_id);
160 } 161 }
161 162
162 const extensions::Extension* 163 const extensions::Extension*
163 ExtensionAppShimHandler::Delegate::GetAppExtension( 164 ExtensionAppShimHandler::Delegate::GetAppExtension(
164 Profile* profile, 165 Profile* profile,
165 const std::string& extension_id) { 166 const std::string& extension_id) {
166 ExtensionRegistry* registry = ExtensionRegistry::Get(profile); 167 ExtensionRegistry* registry = ExtensionRegistry::Get(profile);
167 const extensions::Extension* extension = 168 const extensions::Extension* extension =
168 registry->GetExtensionById(extension_id, ExtensionRegistry::ENABLED); 169 registry->GetExtensionById(extension_id, ExtensionRegistry::ENABLED);
169 return extension && extension->is_platform_app() ? extension : NULL; 170 return extension && extension->is_platform_app() ? extension : NULL;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 ExtensionAppShimHandler::~ExtensionAppShimHandler() {} 220 ExtensionAppShimHandler::~ExtensionAppShimHandler() {}
220 221
221 AppShimHandler::Host* ExtensionAppShimHandler::FindHost( 222 AppShimHandler::Host* ExtensionAppShimHandler::FindHost(
222 Profile* profile, 223 Profile* profile,
223 const std::string& app_id) { 224 const std::string& app_id) {
224 HostMap::iterator it = hosts_.find(make_pair(profile, app_id)); 225 HostMap::iterator it = hosts_.find(make_pair(profile, app_id));
225 return it == hosts_.end() ? NULL : it->second; 226 return it == hosts_.end() ? NULL : it->second;
226 } 227 }
227 228
228 // static 229 // static
229 void ExtensionAppShimHandler::QuitAppForWindow(ShellWindow* shell_window) { 230 void ExtensionAppShimHandler::QuitAppForWindow(AppWindow* app_window) {
230 ExtensionAppShimHandler* handler = 231 ExtensionAppShimHandler* handler =
231 g_browser_process->platform_part()->app_shim_host_manager()-> 232 g_browser_process->platform_part()->app_shim_host_manager()->
232 extension_app_shim_handler(); 233 extension_app_shim_handler();
233 Host* host = handler->FindHost( 234 Host* host = handler->FindHost(
234 Profile::FromBrowserContext(shell_window->browser_context()), 235 Profile::FromBrowserContext(app_window->browser_context()),
235 shell_window->extension_id()); 236 app_window->extension_id());
236 if (host) { 237 if (host) {
237 handler->OnShimQuit(host); 238 handler->OnShimQuit(host);
238 } else { 239 } else {
239 // App shims might be disabled or the shim is still starting up. 240 // App shims might be disabled or the shim is still starting up.
240 ShellWindowRegistry::Get( 241 AppWindowRegistry::Get(
241 Profile::FromBrowserContext(shell_window->browser_context())) 242 Profile::FromBrowserContext(app_window->browser_context()))
242 ->CloseAllShellWindowsForApp(shell_window->extension_id()); 243 ->CloseAllAppWindowsForApp(app_window->extension_id());
243 } 244 }
244 } 245 }
245 246
246 void ExtensionAppShimHandler::HideAppForWindow(ShellWindow* shell_window) { 247 void ExtensionAppShimHandler::HideAppForWindow(AppWindow* app_window) {
247 ExtensionAppShimHandler* handler = 248 ExtensionAppShimHandler* handler =
248 g_browser_process->platform_part()->app_shim_host_manager()-> 249 g_browser_process->platform_part()->app_shim_host_manager()->
249 extension_app_shim_handler(); 250 extension_app_shim_handler();
250 Profile* profile = 251 Profile* profile = Profile::FromBrowserContext(app_window->browser_context());
251 Profile::FromBrowserContext(shell_window->browser_context()); 252 Host* host = handler->FindHost(profile, app_window->extension_id());
252 Host* host = handler->FindHost(profile, shell_window->extension_id());
253 if (host) 253 if (host)
254 host->OnAppHide(); 254 host->OnAppHide();
255 else 255 else
256 SetAppHidden(profile, shell_window->extension_id(), true); 256 SetAppHidden(profile, app_window->extension_id(), true);
257 } 257 }
258 258
259 259 void ExtensionAppShimHandler::FocusAppForWindow(AppWindow* app_window) {
260 void ExtensionAppShimHandler::FocusAppForWindow(ShellWindow* shell_window) {
261 ExtensionAppShimHandler* handler = 260 ExtensionAppShimHandler* handler =
262 g_browser_process->platform_part()->app_shim_host_manager()-> 261 g_browser_process->platform_part()->app_shim_host_manager()->
263 extension_app_shim_handler(); 262 extension_app_shim_handler();
264 Profile* profile = 263 Profile* profile = Profile::FromBrowserContext(app_window->browser_context());
265 Profile::FromBrowserContext(shell_window->browser_context()); 264 const std::string& app_id = app_window->extension_id();
266 const std::string& app_id = shell_window->extension_id();
267 Host* host = handler->FindHost(profile, app_id); 265 Host* host = handler->FindHost(profile, app_id);
268 if (host) { 266 if (host) {
269 handler->OnShimFocus(host, 267 handler->OnShimFocus(host,
270 APP_SHIM_FOCUS_NORMAL, 268 APP_SHIM_FOCUS_NORMAL,
271 std::vector<base::FilePath>()); 269 std::vector<base::FilePath>());
272 } else { 270 } else {
273 FocusWindows( 271 FocusWindows(
274 apps::ShellWindowRegistry::Get(profile)->GetShellWindowsForApp(app_id)); 272 apps::AppWindowRegistry::Get(profile)->GetAppWindowsForApp(app_id));
275 } 273 }
276 } 274 }
277 275
278 // static 276 // static
279 bool ExtensionAppShimHandler::RequestUserAttentionForWindow( 277 bool ExtensionAppShimHandler::RequestUserAttentionForWindow(
280 ShellWindow* shell_window) { 278 AppWindow* app_window) {
281 ExtensionAppShimHandler* handler = 279 ExtensionAppShimHandler* handler =
282 g_browser_process->platform_part()->app_shim_host_manager()-> 280 g_browser_process->platform_part()->app_shim_host_manager()->
283 extension_app_shim_handler(); 281 extension_app_shim_handler();
284 Profile* profile = 282 Profile* profile = Profile::FromBrowserContext(app_window->browser_context());
285 Profile::FromBrowserContext(shell_window->browser_context()); 283 Host* host = handler->FindHost(profile, app_window->extension_id());
286 Host* host = handler->FindHost(profile, shell_window->extension_id());
287 if (host) { 284 if (host) {
288 // Bring the window to the front without showing it. 285 // Bring the window to the front without showing it.
289 ShellWindowRegistry::Get(profile)->ShellWindowActivated(shell_window); 286 AppWindowRegistry::Get(profile)->AppWindowActivated(app_window);
290 host->OnAppRequestUserAttention(); 287 host->OnAppRequestUserAttention();
291 return true; 288 return true;
292 } else { 289 } else {
293 // Just show the app. 290 // Just show the app.
294 SetAppHidden(profile, shell_window->extension_id(), false); 291 SetAppHidden(profile, app_window->extension_id(), false);
295 return false; 292 return false;
296 } 293 }
297 } 294 }
298 295
299 void ExtensionAppShimHandler::OnShimLaunch( 296 void ExtensionAppShimHandler::OnShimLaunch(
300 Host* host, 297 Host* host,
301 AppShimLaunchType launch_type, 298 AppShimLaunchType launch_type,
302 const std::vector<base::FilePath>& files) { 299 const std::vector<base::FilePath>& files) {
303 const std::string& app_id = host->GetAppId(); 300 const std::string& app_id = host->GetAppId();
304 DCHECK(extensions::Extension::IdIsValid(app_id)); 301 DCHECK(extensions::Extension::IdIsValid(app_id));
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 } 408 }
412 } 409 }
413 410
414 void ExtensionAppShimHandler::OnShimFocus( 411 void ExtensionAppShimHandler::OnShimFocus(
415 Host* host, 412 Host* host,
416 AppShimFocusType focus_type, 413 AppShimFocusType focus_type,
417 const std::vector<base::FilePath>& files) { 414 const std::vector<base::FilePath>& files) {
418 DCHECK(delegate_->ProfileExistsForPath(host->GetProfilePath())); 415 DCHECK(delegate_->ProfileExistsForPath(host->GetProfilePath()));
419 Profile* profile = delegate_->ProfileForPath(host->GetProfilePath()); 416 Profile* profile = delegate_->ProfileForPath(host->GetProfilePath());
420 417
421 const ShellWindowList windows = 418 const AppWindowList windows =
422 delegate_->GetWindows(profile, host->GetAppId()); 419 delegate_->GetWindows(profile, host->GetAppId());
423 bool windows_focused = FocusWindows(windows); 420 bool windows_focused = FocusWindows(windows);
424 421
425 if (focus_type == APP_SHIM_FOCUS_NORMAL || 422 if (focus_type == APP_SHIM_FOCUS_NORMAL ||
426 (focus_type == APP_SHIM_FOCUS_REOPEN && windows_focused)) { 423 (focus_type == APP_SHIM_FOCUS_REOPEN && windows_focused)) {
427 return; 424 return;
428 } 425 }
429 426
430 const extensions::Extension* extension = 427 const extensions::Extension* extension =
431 delegate_->GetAppExtension(profile, host->GetAppId()); 428 delegate_->GetAppExtension(profile, host->GetAppId());
(...skipping 11 matching lines...) Expand all
443 Profile* profile = delegate_->ProfileForPath(host->GetProfilePath()); 440 Profile* profile = delegate_->ProfileForPath(host->GetProfilePath());
444 441
445 SetAppHidden(profile, host->GetAppId(), hidden); 442 SetAppHidden(profile, host->GetAppId(), hidden);
446 } 443 }
447 444
448 void ExtensionAppShimHandler::OnShimQuit(Host* host) { 445 void ExtensionAppShimHandler::OnShimQuit(Host* host) {
449 DCHECK(delegate_->ProfileExistsForPath(host->GetProfilePath())); 446 DCHECK(delegate_->ProfileExistsForPath(host->GetProfilePath()));
450 Profile* profile = delegate_->ProfileForPath(host->GetProfilePath()); 447 Profile* profile = delegate_->ProfileForPath(host->GetProfilePath());
451 448
452 const std::string& app_id = host->GetAppId(); 449 const std::string& app_id = host->GetAppId();
453 const ShellWindowList windows = 450 const AppWindowList windows = delegate_->GetWindows(profile, app_id);
454 delegate_->GetWindows(profile, app_id); 451 for (AppWindowRegistry::const_iterator it = windows.begin();
455 for (ShellWindowRegistry::const_iterator it = windows.begin(); 452 it != windows.end();
456 it != windows.end(); ++it) { 453 ++it) {
457 (*it)->GetBaseWindow()->Close(); 454 (*it)->GetBaseWindow()->Close();
458 } 455 }
459 // Once the last window closes, flow will end up in OnAppDeactivated via 456 // Once the last window closes, flow will end up in OnAppDeactivated via
460 // AppLifetimeMonitor. 457 // AppLifetimeMonitor.
461 } 458 }
462 459
463 void ExtensionAppShimHandler::set_delegate(Delegate* delegate) { 460 void ExtensionAppShimHandler::set_delegate(Delegate* delegate) {
464 delegate_.reset(delegate); 461 delegate_.reset(delegate);
465 } 462 }
466 463
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 if (hosts_.empty()) 524 if (hosts_.empty())
528 delegate_->MaybeTerminate(); 525 delegate_->MaybeTerminate();
529 } 526 }
530 527
531 void ExtensionAppShimHandler::OnAppStop(Profile* profile, 528 void ExtensionAppShimHandler::OnAppStop(Profile* profile,
532 const std::string& app_id) {} 529 const std::string& app_id) {}
533 530
534 void ExtensionAppShimHandler::OnChromeTerminating() {} 531 void ExtensionAppShimHandler::OnChromeTerminating() {}
535 532
536 } // namespace apps 533 } // namespace apps
OLDNEW
« no previous file with comments | « apps/app_shim/extension_app_shim_handler_mac.h ('k') | apps/app_shim/extension_app_shim_handler_mac_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698