Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #import <Cocoa/Cocoa.h> | |
| 8 | |
| 7 #include "apps/app_shim/app_shim_messages.h" | 9 #include "apps/app_shim/app_shim_messages.h" |
| 8 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 9 #include "base/logging.h" | 11 #include "base/logging.h" |
| 10 #include "chrome/browser/extensions/extension_host.h" | 12 #include "chrome/browser/extensions/extension_host.h" |
| 11 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
| 12 #include "chrome/browser/extensions/extension_system.h" | 14 #include "chrome/browser/extensions/extension_system.h" |
| 13 #include "chrome/browser/extensions/shell_window_registry.h" | 15 #include "chrome/browser/extensions/shell_window_registry.h" |
| 14 #include "chrome/browser/ui/extensions/application_launch.h" | 16 #include "chrome/browser/ui/extensions/application_launch.h" |
| 15 #include "chrome/browser/ui/extensions/shell_window.h" | 17 #include "chrome/browser/ui/extensions/shell_window.h" |
| 18 #include "content/public/browser/web_contents.h" | |
| 16 #include "ui/base/cocoa/focus_window_set.h" | 19 #include "ui/base/cocoa/focus_window_set.h" |
| 17 | 20 |
| 18 namespace apps { | 21 namespace apps { |
| 19 | 22 |
| 20 ExtensionAppShimHandler::ExtensionAppShimHandler() {} | 23 ExtensionAppShimHandler::ExtensionAppShimHandler() {} |
| 21 | 24 |
| 22 ExtensionAppShimHandler::~ExtensionAppShimHandler() { | 25 ExtensionAppShimHandler::~ExtensionAppShimHandler() { |
| 23 for (HostMap::iterator it = hosts_.begin(); it != hosts_.end(); ) { | 26 for (HostMap::iterator it = hosts_.begin(); it != hosts_.end(); ) { |
| 24 // Increment the iterator first as OnAppClosed may call back to OnShimClose | 27 // Increment the iterator first as OnAppClosed may call back to OnShimClose |
| 25 // and invalidate the iterator. | 28 // and invalidate the iterator. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 | 69 |
| 67 void ExtensionAppShimHandler::OnShimFocus(Host* host) { | 70 void ExtensionAppShimHandler::OnShimFocus(Host* host) { |
| 68 if (!host->GetProfile()) | 71 if (!host->GetProfile()) |
| 69 return; | 72 return; |
| 70 | 73 |
| 71 extensions::ShellWindowRegistry* registry = | 74 extensions::ShellWindowRegistry* registry = |
| 72 extensions::ShellWindowRegistry::Get(host->GetProfile()); | 75 extensions::ShellWindowRegistry::Get(host->GetProfile()); |
| 73 const extensions::ShellWindowRegistry::ShellWindowList windows = | 76 const extensions::ShellWindowRegistry::ShellWindowList windows = |
| 74 registry->GetShellWindowsForApp(host->GetAppId()); | 77 registry->GetShellWindowsForApp(host->GetAppId()); |
| 75 std::set<gfx::NativeWindow> native_windows; | 78 std::set<gfx::NativeWindow> native_windows; |
| 76 for (extensions::ShellWindowRegistry::const_iterator i = windows.begin(); | 79 for (extensions::ShellWindowRegistry::const_iterator i = windows.begin(); |
|
tapted
2013/05/24 08:43:51
perhaps name this iterator `it` to be consistent (
jackhou1
2013/05/27 01:02:47
Done.
| |
| 77 i != windows.end(); ++i) { | 80 i != windows.end(); ++i) { |
| 78 native_windows.insert((*i)->GetNativeWindow()); | 81 native_windows.insert((*i)->GetNativeWindow()); |
| 79 } | 82 } |
| 80 ui::FocusWindowSet(native_windows); | 83 ui::FocusWindowSet(native_windows); |
| 81 } | 84 } |
| 82 | 85 |
| 86 void ExtensionAppShimHandler::OnShimQuit(Host* host) { | |
| 87 if (!host->GetProfile()) | |
| 88 return; | |
| 89 | |
| 90 extensions::ShellWindowRegistry::ShellWindowList windows = | |
| 91 extensions::ShellWindowRegistry::Get(host->GetProfile())-> | |
| 92 GetShellWindowsForApp(host->GetAppId()); | |
| 93 for (extensions::ShellWindowRegistry::const_iterator it = windows.begin(); | |
| 94 it != windows.end(); ++it) { | |
| 95 NSWindow* window = (*it)->GetNativeWindow(); | |
|
tapted
2013/05/24 08:43:51
What about (*it)->GetBaseWindow()->Close();
That
jackhou1
2013/05/27 01:02:47
Close() is not available on the NativeAppWindow in
tapted
2013/05/27 01:13:56
Sure it is! -- should be inherited from ui::BaseWi
jackhou1
2013/05/27 05:04:51
Done.
| |
| 96 [window performClose:nil]; | |
| 97 } | |
| 98 } | |
| 99 | |
| 83 bool ExtensionAppShimHandler::LaunchApp(Profile* profile, | 100 bool ExtensionAppShimHandler::LaunchApp(Profile* profile, |
| 84 const std::string& app_id) { | 101 const std::string& app_id) { |
| 85 extensions::ExtensionSystem* extension_system = | 102 extensions::ExtensionSystem* extension_system = |
| 86 extensions::ExtensionSystem::Get(profile); | 103 extensions::ExtensionSystem::Get(profile); |
| 87 ExtensionServiceInterface* extension_service = | 104 ExtensionServiceInterface* extension_service = |
| 88 extension_system->extension_service(); | 105 extension_system->extension_service(); |
| 89 const extensions::Extension* extension = | 106 const extensions::Extension* extension = |
| 90 extension_service->GetExtensionById(app_id, false); | 107 extension_service->GetExtensionById(app_id, false); |
| 91 if (!extension) { | 108 if (!extension) { |
| 92 LOG(ERROR) << "Attempted to launch nonexistent app with id '" | 109 LOG(ERROR) << "Attempted to launch nonexistent app with id '" |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 121 } | 138 } |
| 122 | 139 |
| 123 void ExtensionAppShimHandler::CloseShim(Profile* profile, | 140 void ExtensionAppShimHandler::CloseShim(Profile* profile, |
| 124 const std::string& app_id) { | 141 const std::string& app_id) { |
| 125 HostMap::const_iterator it = hosts_.find(make_pair(profile, app_id)); | 142 HostMap::const_iterator it = hosts_.find(make_pair(profile, app_id)); |
| 126 if (it != hosts_.end()) | 143 if (it != hosts_.end()) |
| 127 it->second->OnAppClosed(); | 144 it->second->OnAppClosed(); |
| 128 } | 145 } |
| 129 | 146 |
| 130 } // namespace apps | 147 } // namespace apps |
| OLD | NEW |