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

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

Issue 14514003: Make OSX App Launcher Launchable from the Dock. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebase off cl14603002 Created 7 years, 7 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
« no previous file with comments | « apps/app_shim/app_shim_host_mac.h ('k') | apps/app_shim/app_shim_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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/app_list/app_list_service.h"
18 #include "chrome/browser/ui/app_list/app_list_service_mac.h"
17 #include "chrome/browser/ui/extensions/application_launch.h" 19 #include "chrome/browser/ui/extensions/application_launch.h"
18 #include "chrome/browser/ui/extensions/shell_window.h" 20 #include "chrome/browser/ui/extensions/shell_window.h"
19 #include "chrome/common/extensions/extension_constants.h" 21 #include "chrome/common/extensions/extension_constants.h"
20 #include "ipc/ipc_channel_proxy.h" 22 #include "ipc/ipc_channel_proxy.h"
21 #include "ui/base/cocoa/focus_window_set.h" 23 #include "ui/base/cocoa/focus_window_set.h"
22 24
23 AppShimHost::AppShimHost() 25 AppShimHost::AppShimHost()
24 : channel_(NULL), profile_(NULL) { 26 : channel_(NULL), profile_(NULL), is_app_list_(false) {
25 } 27 }
26 28
27 AppShimHost::~AppShimHost() { 29 AppShimHost::~AppShimHost() {
28 DCHECK(CalledOnValidThread()); 30 DCHECK(CalledOnValidThread());
31 if (is_app_list_) {
32 chrome::RemoveAppListDismissObserver(this);
33 AppListService::Get()->DismissAppList();
34 }
29 } 35 }
30 36
31 void AppShimHost::ServeChannel(const IPC::ChannelHandle& handle) { 37 void AppShimHost::ServeChannel(const IPC::ChannelHandle& handle) {
32 DCHECK(CalledOnValidThread()); 38 DCHECK(CalledOnValidThread());
33 DCHECK(!channel_.get()); 39 DCHECK(!channel_.get());
34 channel_.reset(new IPC::ChannelProxy(handle, IPC::Channel::MODE_SERVER, this, 40 channel_.reset(new IPC::ChannelProxy(handle, IPC::Channel::MODE_SERVER, this,
35 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO))); 41 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO)));
36 } 42 }
37 43
38 bool AppShimHost::OnMessageReceived(const IPC::Message& message) { 44 bool AppShimHost::OnMessageReceived(const IPC::Message& message) {
39 DCHECK(CalledOnValidThread()); 45 DCHECK(CalledOnValidThread());
40 bool handled = true; 46 bool handled = true;
41 IPC_BEGIN_MESSAGE_MAP(AppShimHost, message) 47 IPC_BEGIN_MESSAGE_MAP(AppShimHost, message)
42 IPC_MESSAGE_HANDLER(AppShimHostMsg_LaunchApp, OnLaunchApp) 48 IPC_MESSAGE_HANDLER(AppShimHostMsg_LaunchApp, OnLaunchApp)
49 IPC_MESSAGE_HANDLER(AppShimHostMsg_LaunchAppList, OnLaunchAppList)
43 IPC_MESSAGE_HANDLER(AppShimHostMsg_FocusApp, OnFocus) 50 IPC_MESSAGE_HANDLER(AppShimHostMsg_FocusApp, OnFocus)
44 IPC_MESSAGE_UNHANDLED(handled = false) 51 IPC_MESSAGE_UNHANDLED(handled = false)
45 IPC_END_MESSAGE_MAP() 52 IPC_END_MESSAGE_MAP()
46 53
47 return handled; 54 return handled;
48 } 55 }
49 56
57 void AppShimHost::OnChannelError() {
58 Close();
59 }
60
50 bool AppShimHost::Send(IPC::Message* message) { 61 bool AppShimHost::Send(IPC::Message* message) {
51 DCHECK(channel_.get()); 62 DCHECK(channel_.get());
52 return channel_->Send(message); 63 return channel_->Send(message);
53 } 64 }
54 65
55 void AppShimHost::OnLaunchApp(std::string profile_dir, std::string app_id) { 66 void AppShimHost::OnLaunchApp(std::string profile_dir, std::string app_id) {
56 DCHECK(CalledOnValidThread()); 67 DCHECK(CalledOnValidThread());
57 bool success = LaunchAppImpl(profile_dir, app_id); 68 bool success = LaunchAppImpl(profile_dir, app_id);
58 Send(new AppShimMsg_LaunchApp_Done(success)); 69 Send(new AppShimMsg_LaunchApp_Done(success));
59 } 70 }
60 71
72 void AppShimHost::OnLaunchAppList() {
73 DCHECK(CalledOnValidThread());
74 is_app_list_ = true;
75 AppListService::Get()->ShowForSavedProfile();
76 chrome::AddAppListDismissObserver(this);
77 Send(new AppShimMsg_LaunchApp_Done(true));
78 }
79
61 void AppShimHost::OnFocus() { 80 void AppShimHost::OnFocus() {
62 DCHECK(CalledOnValidThread()); 81 DCHECK(CalledOnValidThread());
82 if (is_app_list_)
83 AppListService::Get()->DismissAppList();
84
63 if (!profile_) 85 if (!profile_)
64 return; 86 return;
65 extensions::ShellWindowRegistry* registry = 87 extensions::ShellWindowRegistry* registry =
66 extensions::ShellWindowRegistry::Get(profile_); 88 extensions::ShellWindowRegistry::Get(profile_);
67 const std::set<ShellWindow*> windows = 89 const std::set<ShellWindow*> windows =
68 registry->GetShellWindowsForApp(app_id_); 90 registry->GetShellWindowsForApp(app_id_);
69 std::set<gfx::NativeWindow> native_windows; 91 std::set<gfx::NativeWindow> native_windows;
70 for (std::set<ShellWindow*>::const_iterator i = windows.begin(); 92 for (std::set<ShellWindow*>::const_iterator i = windows.begin();
71 i != windows.end(); 93 i != windows.end();
72 ++i) { 94 ++i) {
73 native_windows.insert((*i)->GetNativeWindow()); 95 native_windows.insert((*i)->GetNativeWindow());
74 } 96 }
75 ui::FocusWindowSet(native_windows); 97 ui::FocusWindowSet(native_windows);
76 } 98 }
77 99
78 bool AppShimHost::LaunchAppImpl(const std::string& profile_dir, 100 bool AppShimHost::LaunchAppImpl(const std::string& profile_dir,
79 const std::string& app_id) { 101 const std::string& app_id) {
80 DCHECK(CalledOnValidThread()); 102 DCHECK(CalledOnValidThread());
81 if (profile_) { 103 if (profile_) {
82 // Only one app launch message per channel. 104 // Only one app launch message per channel.
83 return false; 105 return false;
84 } 106 }
107
85 if (!extensions::Extension::IdIsValid(app_id)) { 108 if (!extensions::Extension::IdIsValid(app_id)) {
86 LOG(ERROR) << "Bad app ID from app shim launch message."; 109 LOG(ERROR) << "Bad app ID from app shim launch message.";
87 return false; 110 return false;
88 } 111 }
89 Profile* profile = FetchProfileForDirectory(profile_dir); 112 Profile* profile = FetchProfileForDirectory(profile_dir);
90 if (!profile) 113 if (!profile)
91 return false; 114 return false;
92 115
93 if (!LaunchApp(profile, app_id)) 116 if (!LaunchApp(profile, app_id))
94 return false; 117 return false;
(...skipping 10 matching lines...) Expand all
105 ProfileManager* profileManager = g_browser_process->profile_manager(); 128 ProfileManager* profileManager = g_browser_process->profile_manager();
106 // Even though the name of this function is "unsafe", there's no security 129 // Even though the name of this function is "unsafe", there's no security
107 // issue here -- the check for the profile name in the profile info cache 130 // issue here -- the check for the profile name in the profile info cache
108 // ensures that we never access any directory that isn't a known profile. 131 // ensures that we never access any directory that isn't a known profile.
109 base::FilePath path = base::FilePath::FromUTF8Unsafe(profile_dir); 132 base::FilePath path = base::FilePath::FromUTF8Unsafe(profile_dir);
110 path = profileManager->user_data_dir().Append(path); 133 path = profileManager->user_data_dir().Append(path);
111 ProfileInfoCache& cache = profileManager->GetProfileInfoCache(); 134 ProfileInfoCache& cache = profileManager->GetProfileInfoCache();
112 // This ensures that the given profile path is acutally a profile that we 135 // This ensures that the given profile path is acutally a profile that we
113 // already know about. 136 // already know about.
114 if (cache.GetIndexOfProfileWithPath(path) == std::string::npos) { 137 if (cache.GetIndexOfProfileWithPath(path) == std::string::npos) {
115 LOG(ERROR) << "Requested directory is not a known profile."; 138 LOG(ERROR) << "Requested directory is not a known profile '"
139 << profile_dir << "'.";
116 return NULL; 140 return NULL;
117 } 141 }
118 Profile* profile = profileManager->GetProfile(path); 142 Profile* profile = profileManager->GetProfile(path);
119 if (!profile) { 143 if (!profile) {
120 LOG(ERROR) << "Couldn't get profile for directory '" << profile_dir << "'."; 144 LOG(ERROR) << "Couldn't get profile for directory '" << profile_dir << "'.";
121 return NULL; 145 return NULL;
122 } 146 }
123 return profile; 147 return profile;
124 } 148 }
125 149
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 if (app_id_ == extension_host->extension_id()) 184 if (app_id_ == extension_host->extension_id())
161 Close(); 185 Close();
162 break; 186 break;
163 } 187 }
164 default: 188 default:
165 NOTREACHED() << "Unexpected notification sent."; 189 NOTREACHED() << "Unexpected notification sent.";
166 break; 190 break;
167 } 191 }
168 } 192 }
169 193
194 void AppShimHost::OnAppListDismissed() {
195 DCHECK(is_app_list_);
196 Send(new AppShimMsg_AppListDismissed());
197 Close();
198 }
199
170 void AppShimHost::Close() { 200 void AppShimHost::Close() {
171 DCHECK(CalledOnValidThread()); 201 DCHECK(CalledOnValidThread());
172 delete this; 202 delete this;
173 } 203 }
OLDNEW
« no previous file with comments | « apps/app_shim/app_shim_host_mac.h ('k') | apps/app_shim/app_shim_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698