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/app_shim_host_mac.h" | 5 #include "apps/app_shim/app_shim_host_mac.h" |
6 | 6 |
7 #include "apps/app_shim/app_shim_messages.h" | 7 #include "apps/app_shim/app_shim_messages.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/extensions/extension_host.h" | 12 #include "chrome/browser/extensions/extension_host.h" |
13 #include "chrome/browser/extensions/extension_service.h" | 13 #include "chrome/browser/extensions/extension_service.h" |
14 #include "chrome/browser/extensions/extension_system.h" | 14 #include "chrome/browser/extensions/extension_system.h" |
15 #include "chrome/browser/extensions/shell_window_registry.h" | 15 #include "chrome/browser/extensions/shell_window_registry.h" |
16 #include "chrome/browser/profiles/profile_manager.h" | 16 #include "chrome/browser/profiles/profile_manager.h" |
17 #include "chrome/browser/ui/extensions/application_launch.h" | 17 #include "chrome/browser/ui/extensions/application_launch.h" |
18 #include "chrome/browser/ui/extensions/shell_window.h" | |
18 #include "chrome/common/extensions/extension_constants.h" | 19 #include "chrome/common/extensions/extension_constants.h" |
19 #include "ipc/ipc_channel_proxy.h" | 20 #include "ipc/ipc_channel_proxy.h" |
21 #include "ui/base/cocoa/focus_window_set.h" | |
20 | 22 |
21 AppShimHost::AppShimHost() | 23 AppShimHost::AppShimHost() |
22 : channel_(NULL), profile_(NULL) { | 24 : channel_(NULL), profile_(NULL) { |
23 } | 25 } |
24 | 26 |
25 AppShimHost::~AppShimHost() { | 27 AppShimHost::~AppShimHost() { |
26 DCHECK(CalledOnValidThread()); | 28 DCHECK(CalledOnValidThread()); |
27 } | 29 } |
28 | 30 |
29 void AppShimHost::ServeChannel(const IPC::ChannelHandle& handle) { | 31 void AppShimHost::ServeChannel(const IPC::ChannelHandle& handle) { |
30 DCHECK(CalledOnValidThread()); | 32 DCHECK(CalledOnValidThread()); |
31 DCHECK(!channel_.get()); | 33 DCHECK(!channel_.get()); |
32 channel_.reset(new IPC::ChannelProxy(handle, IPC::Channel::MODE_SERVER, this, | 34 channel_.reset(new IPC::ChannelProxy(handle, IPC::Channel::MODE_SERVER, this, |
33 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); | 35 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); |
34 } | 36 } |
35 | 37 |
36 bool AppShimHost::OnMessageReceived(const IPC::Message& message) { | 38 bool AppShimHost::OnMessageReceived(const IPC::Message& message) { |
37 DCHECK(CalledOnValidThread()); | 39 DCHECK(CalledOnValidThread()); |
38 bool handled = true; | 40 bool handled = true; |
39 IPC_BEGIN_MESSAGE_MAP(AppShimHost, message) | 41 IPC_BEGIN_MESSAGE_MAP(AppShimHost, message) |
40 IPC_MESSAGE_HANDLER(AppShimHostMsg_LaunchApp, OnLaunchApp) | 42 IPC_MESSAGE_HANDLER(AppShimHostMsg_LaunchApp, OnLaunchApp) |
43 IPC_MESSAGE_HANDLER(AppShimHostMsg_FocusApp, OnFocus) | |
41 IPC_MESSAGE_UNHANDLED(handled = false) | 44 IPC_MESSAGE_UNHANDLED(handled = false) |
42 IPC_END_MESSAGE_MAP() | 45 IPC_END_MESSAGE_MAP() |
43 | 46 |
44 return handled; | 47 return handled; |
45 } | 48 } |
46 | 49 |
47 bool AppShimHost::Send(IPC::Message* message) { | 50 bool AppShimHost::Send(IPC::Message* message) { |
48 DCHECK(channel_.get()); | 51 DCHECK(channel_.get()); |
49 return channel_->Send(message); | 52 return channel_->Send(message); |
50 } | 53 } |
51 | 54 |
52 void AppShimHost::OnLaunchApp(std::string profile_dir, std::string app_id) { | 55 void AppShimHost::OnLaunchApp(std::string profile_dir, std::string app_id) { |
53 DCHECK(CalledOnValidThread()); | 56 DCHECK(CalledOnValidThread()); |
54 bool success = LaunchAppImpl(profile_dir, app_id); | 57 bool success = LaunchAppImpl(profile_dir, app_id); |
55 Send(new AppShimMsg_LaunchApp_Done(success)); | 58 Send(new AppShimMsg_LaunchApp_Done(success)); |
56 } | 59 } |
57 | 60 |
61 void AppShimHost::OnFocus() { | |
koz (OOO until 15th September)
2013/03/18 03:33:12
DCHECK(CalledOnValidThread())
jeremya
2013/03/18 04:54:05
Done.
| |
62 // TODO move | |
koz (OOO until 15th September)
2013/03/18 03:33:12
Move to where?
jeremya
2013/03/18 04:54:05
Oops, this was left over from when the FocusWindow
| |
63 if (!profile_) | |
64 return; | |
65 extensions::ShellWindowRegistry* registry = | |
66 extensions::ShellWindowRegistry::Get(profile_); | |
67 const std::set<ShellWindow*> windows = | |
68 registry->GetShellWindowsForApp(app_id_); | |
69 std::set<gfx::NativeWindow> native_windows; | |
70 for (std::set<ShellWindow*>::const_iterator i = windows.begin(); | |
71 i != windows.end(); | |
72 ++i) { | |
73 native_windows.insert((*i)->GetNativeWindow()); | |
74 } | |
75 ui::FocusWindowSet(native_windows); | |
76 } | |
77 | |
58 bool AppShimHost::LaunchAppImpl(const std::string& profile_dir, | 78 bool AppShimHost::LaunchAppImpl(const std::string& profile_dir, |
59 const std::string& app_id) { | 79 const std::string& app_id) { |
60 DCHECK(CalledOnValidThread()); | 80 DCHECK(CalledOnValidThread()); |
61 if (profile_) { | 81 if (profile_) { |
62 // Only one app launch message per channel. | 82 // Only one app launch message per channel. |
63 return false; | 83 return false; |
64 } | 84 } |
65 if (!extensions::Extension::IdIsValid(app_id)) { | 85 if (!extensions::Extension::IdIsValid(app_id)) { |
66 LOG(ERROR) << "Bad app ID from app shim launch message."; | 86 LOG(ERROR) << "Bad app ID from app shim launch message."; |
67 return false; | 87 return false; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 default: | 164 default: |
145 NOTREACHED() << "Unexpected notification sent."; | 165 NOTREACHED() << "Unexpected notification sent."; |
146 break; | 166 break; |
147 } | 167 } |
148 } | 168 } |
149 | 169 |
150 void AppShimHost::Close() { | 170 void AppShimHost::Close() { |
151 DCHECK(CalledOnValidThread()); | 171 DCHECK(CalledOnValidThread()); |
152 delete this; | 172 delete this; |
153 } | 173 } |
OLD | NEW |