| 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 "chrome/browser/apps/app_shim/app_shim_host_mac.h" | 5 #include "chrome/browser/apps/app_shim/app_shim_host_mac.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "chrome/browser/apps/app_shim/app_shim_handler_mac.h" | 12 #include "chrome/browser/apps/app_shim/app_shim_handler_mac.h" |
| 13 #include "chrome/common/mac/app_shim_messages.h" | 13 #include "chrome/common/mac/app_shim_messages.h" |
| 14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "ipc/ipc_channel_mojo.h" | 15 #include "ipc/ipc_channel_mojo.h" |
| 16 #include "ipc/ipc_channel_proxy.h" | 16 #include "ipc/ipc_channel_proxy.h" |
| 17 #include "mojo/edk/embedder/embedder.h" | 17 #include "mojo/edk/embedder/embedder.h" |
| 18 | 18 |
| 19 AppShimHost::AppShimHost() : initial_launch_finished_(false) {} | 19 AppShimHost::AppShimHost() : initial_launch_finished_(false) {} |
| 20 | 20 |
| 21 AppShimHost::~AppShimHost() { | 21 AppShimHost::~AppShimHost() { |
| 22 DCHECK(CalledOnValidThread()); | 22 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 23 apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_); | 23 apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_); |
| 24 if (handler) | 24 if (handler) |
| 25 handler->OnShimClose(this); | 25 handler->OnShimClose(this); |
| 26 } | 26 } |
| 27 | 27 |
| 28 void AppShimHost::ServeChannel(mojo::edk::ScopedPlatformHandle handle) { | 28 void AppShimHost::ServeChannel(mojo::edk::ScopedPlatformHandle handle) { |
| 29 DCHECK(CalledOnValidThread()); | 29 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 30 DCHECK(!channel_.get()); | 30 DCHECK(!channel_.get()); |
| 31 channel_ = IPC::ChannelProxy::Create( | 31 channel_ = IPC::ChannelProxy::Create( |
| 32 IPC::ChannelMojo::CreateServerFactory( | 32 IPC::ChannelMojo::CreateServerFactory( |
| 33 peer_connection_.Connect(mojo::edk::ConnectionParams( | 33 peer_connection_.Connect(mojo::edk::ConnectionParams( |
| 34 mojo::edk::TransportProtocol::kLegacy, std::move(handle))), | 34 mojo::edk::TransportProtocol::kLegacy, std::move(handle))), |
| 35 content::BrowserThread::GetTaskRunnerForThread( | 35 content::BrowserThread::GetTaskRunnerForThread( |
| 36 content::BrowserThread::IO) | 36 content::BrowserThread::IO) |
| 37 .get()), | 37 .get()), |
| 38 this, | 38 this, |
| 39 content::BrowserThread::GetTaskRunnerForThread(content::BrowserThread::IO) | 39 content::BrowserThread::GetTaskRunnerForThread(content::BrowserThread::IO) |
| 40 .get()); | 40 .get()); |
| 41 } | 41 } |
| 42 | 42 |
| 43 base::FilePath AppShimHost::GetProfilePath() const { | 43 base::FilePath AppShimHost::GetProfilePath() const { |
| 44 return profile_path_; | 44 return profile_path_; |
| 45 } | 45 } |
| 46 | 46 |
| 47 std::string AppShimHost::GetAppId() const { | 47 std::string AppShimHost::GetAppId() const { |
| 48 return app_id_; | 48 return app_id_; |
| 49 } | 49 } |
| 50 | 50 |
| 51 bool AppShimHost::OnMessageReceived(const IPC::Message& message) { | 51 bool AppShimHost::OnMessageReceived(const IPC::Message& message) { |
| 52 DCHECK(CalledOnValidThread()); | 52 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 53 bool handled = true; | 53 bool handled = true; |
| 54 IPC_BEGIN_MESSAGE_MAP(AppShimHost, message) | 54 IPC_BEGIN_MESSAGE_MAP(AppShimHost, message) |
| 55 IPC_MESSAGE_HANDLER(AppShimHostMsg_LaunchApp, OnLaunchApp) | 55 IPC_MESSAGE_HANDLER(AppShimHostMsg_LaunchApp, OnLaunchApp) |
| 56 IPC_MESSAGE_HANDLER(AppShimHostMsg_FocusApp, OnFocus) | 56 IPC_MESSAGE_HANDLER(AppShimHostMsg_FocusApp, OnFocus) |
| 57 IPC_MESSAGE_HANDLER(AppShimHostMsg_SetAppHidden, OnSetHidden) | 57 IPC_MESSAGE_HANDLER(AppShimHostMsg_SetAppHidden, OnSetHidden) |
| 58 IPC_MESSAGE_HANDLER(AppShimHostMsg_QuitApp, OnQuit) | 58 IPC_MESSAGE_HANDLER(AppShimHostMsg_QuitApp, OnQuit) |
| 59 IPC_MESSAGE_UNHANDLED(handled = false) | 59 IPC_MESSAGE_UNHANDLED(handled = false) |
| 60 IPC_END_MESSAGE_MAP() | 60 IPC_END_MESSAGE_MAP() |
| 61 | 61 |
| 62 return handled; | 62 return handled; |
| 63 } | 63 } |
| 64 | 64 |
| 65 void AppShimHost::OnChannelError() { | 65 void AppShimHost::OnChannelError() { |
| 66 Close(); | 66 Close(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 bool AppShimHost::Send(IPC::Message* message) { | 69 bool AppShimHost::Send(IPC::Message* message) { |
| 70 DCHECK(channel_.get()); | 70 DCHECK(channel_.get()); |
| 71 return channel_->Send(message); | 71 return channel_->Send(message); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void AppShimHost::OnLaunchApp(const base::FilePath& profile_dir, | 74 void AppShimHost::OnLaunchApp(const base::FilePath& profile_dir, |
| 75 const std::string& app_id, | 75 const std::string& app_id, |
| 76 apps::AppShimLaunchType launch_type, | 76 apps::AppShimLaunchType launch_type, |
| 77 const std::vector<base::FilePath>& files) { | 77 const std::vector<base::FilePath>& files) { |
| 78 DCHECK(CalledOnValidThread()); | 78 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 79 DCHECK(profile_path_.empty()); | 79 DCHECK(profile_path_.empty()); |
| 80 // Only one app launch message per channel. | 80 // Only one app launch message per channel. |
| 81 if (!profile_path_.empty()) | 81 if (!profile_path_.empty()) |
| 82 return; | 82 return; |
| 83 | 83 |
| 84 profile_path_ = profile_dir; | 84 profile_path_ = profile_dir; |
| 85 app_id_ = app_id; | 85 app_id_ = app_id; |
| 86 | 86 |
| 87 apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_); | 87 apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_); |
| 88 if (handler) | 88 if (handler) |
| 89 handler->OnShimLaunch(this, launch_type, files); | 89 handler->OnShimLaunch(this, launch_type, files); |
| 90 // |handler| can only be NULL after AppShimHostManager is destroyed. Since | 90 // |handler| can only be NULL after AppShimHostManager is destroyed. Since |
| 91 // this only happens at shutdown, do nothing here. | 91 // this only happens at shutdown, do nothing here. |
| 92 } | 92 } |
| 93 | 93 |
| 94 void AppShimHost::OnFocus(apps::AppShimFocusType focus_type, | 94 void AppShimHost::OnFocus(apps::AppShimFocusType focus_type, |
| 95 const std::vector<base::FilePath>& files) { | 95 const std::vector<base::FilePath>& files) { |
| 96 DCHECK(CalledOnValidThread()); | 96 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 97 apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_); | 97 apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_); |
| 98 if (handler) | 98 if (handler) |
| 99 handler->OnShimFocus(this, focus_type, files); | 99 handler->OnShimFocus(this, focus_type, files); |
| 100 } | 100 } |
| 101 | 101 |
| 102 void AppShimHost::OnSetHidden(bool hidden) { | 102 void AppShimHost::OnSetHidden(bool hidden) { |
| 103 DCHECK(CalledOnValidThread()); | 103 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 104 apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_); | 104 apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_); |
| 105 if (handler) | 105 if (handler) |
| 106 handler->OnShimSetHidden(this, hidden); | 106 handler->OnShimSetHidden(this, hidden); |
| 107 } | 107 } |
| 108 | 108 |
| 109 void AppShimHost::OnQuit() { | 109 void AppShimHost::OnQuit() { |
| 110 DCHECK(CalledOnValidThread()); | 110 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 111 apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_); | 111 apps::AppShimHandler* handler = apps::AppShimHandler::GetForAppMode(app_id_); |
| 112 if (handler) | 112 if (handler) |
| 113 handler->OnShimQuit(this); | 113 handler->OnShimQuit(this); |
| 114 } | 114 } |
| 115 | 115 |
| 116 void AppShimHost::OnAppLaunchComplete(apps::AppShimLaunchResult result) { | 116 void AppShimHost::OnAppLaunchComplete(apps::AppShimLaunchResult result) { |
| 117 if (!initial_launch_finished_) { | 117 if (!initial_launch_finished_) { |
| 118 Send(new AppShimMsg_LaunchApp_Done(result)); | 118 Send(new AppShimMsg_LaunchApp_Done(result)); |
| 119 initial_launch_finished_ = true; | 119 initial_launch_finished_ = true; |
| 120 } | 120 } |
| 121 } | 121 } |
| 122 | 122 |
| 123 void AppShimHost::OnAppClosed() { | 123 void AppShimHost::OnAppClosed() { |
| 124 Close(); | 124 Close(); |
| 125 } | 125 } |
| 126 | 126 |
| 127 void AppShimHost::OnAppHide() { | 127 void AppShimHost::OnAppHide() { |
| 128 Send(new AppShimMsg_Hide); | 128 Send(new AppShimMsg_Hide); |
| 129 } | 129 } |
| 130 | 130 |
| 131 void AppShimHost::OnAppUnhideWithoutActivation() { | 131 void AppShimHost::OnAppUnhideWithoutActivation() { |
| 132 Send(new AppShimMsg_UnhideWithoutActivation); | 132 Send(new AppShimMsg_UnhideWithoutActivation); |
| 133 } | 133 } |
| 134 | 134 |
| 135 void AppShimHost::OnAppRequestUserAttention(apps::AppShimAttentionType type) { | 135 void AppShimHost::OnAppRequestUserAttention(apps::AppShimAttentionType type) { |
| 136 Send(new AppShimMsg_SetUserAttention(type)); | 136 Send(new AppShimMsg_SetUserAttention(type)); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void AppShimHost::Close() { | 139 void AppShimHost::Close() { |
| 140 DCHECK(CalledOnValidThread()); | 140 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); |
| 141 delete this; | 141 delete this; |
| 142 } | 142 } |
| OLD | NEW |