| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/metro_viewer/metro_viewer_process_host_win.h" | 5 #include "chrome/browser/metro_viewer/chrome_metro_viewer_process_host_aurawin.h
" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/ref_counted.h" |
| 8 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/browser_process_platform_part_aurawin.h" | 10 #include "chrome/browser/browser_process_platform_part_aurawin.h" |
| 10 #include "chrome/browser/ui/ash/ash_init.h" | 11 #include "chrome/browser/ui/ash/ash_init.h" |
| 11 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/browser_list.h" | 13 #include "chrome/browser/ui/browser_list.h" |
| 13 #include "chrome/browser/ui/browser_window.h" | 14 #include "chrome/browser/ui/browser_window.h" |
| 14 #include "chrome/browser/ui/host_desktop.h" | 15 #include "chrome/browser/ui/host_desktop.h" |
| 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 16 #include "chrome/common/chrome_notification_types.h" | 17 #include "chrome/common/chrome_notification_types.h" |
| 17 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
| 19 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 20 #include "ipc/ipc_channel_proxy.h" | |
| 21 #include "ui/aura/remote_root_window_host_win.h" | 21 #include "ui/aura/remote_root_window_host_win.h" |
| 22 #include "ui/metro_viewer/metro_viewer_messages.h" | |
| 23 #include "ui/surface/accelerated_surface_win.h" | 22 #include "ui/surface/accelerated_surface_win.h" |
| 24 | 23 |
| 25 namespace { | 24 namespace { |
| 26 | 25 |
| 27 void CloseOpenAshBrowsers() { | 26 void CloseOpenAshBrowsers() { |
| 28 BrowserList* browser_list = | 27 BrowserList* browser_list = |
| 29 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); | 28 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); |
| 30 if (browser_list) { | 29 if (browser_list) { |
| 31 for (BrowserList::const_iterator i = browser_list->begin(); | 30 for (BrowserList::const_iterator i = browser_list->begin(); |
| 32 i != browser_list->end(); ++i) { | 31 i != browser_list->end(); ++i) { |
| 33 Browser* browser = *i; | 32 Browser* browser = *i; |
| 34 browser->window()->Close(); | 33 browser->window()->Close(); |
| 35 // If the attempt to Close the browser fails due to unload handlers on | 34 // If the attempt to Close the browser fails due to unload handlers on |
| 36 // the page or in progress downloads, etc, destroy all tabs on the page. | 35 // the page or in progress downloads, etc, destroy all tabs on the page. |
| 37 while (browser->tab_strip_model()->count()) | 36 while (browser->tab_strip_model()->count()) |
| 38 delete browser->tab_strip_model()->GetWebContentsAt(0); | 37 delete browser->tab_strip_model()->GetWebContentsAt(0); |
| 39 } | 38 } |
| 40 } | 39 } |
| 41 } | 40 } |
| 42 | 41 |
| 43 } // namespace | 42 } // namespace |
| 44 | 43 |
| 45 | 44 ChromeMetroViewerProcessHost::ChromeMetroViewerProcessHost( |
| 46 MetroViewerProcessHost::MetroViewerProcessHost( | 45 const std::string& ipc_channel_name) |
| 47 const std::string& ipc_channel_name) { | 46 : MetroViewerProcessHost( |
| 47 ipc_channel_name, |
| 48 content::BrowserThread::GetMessageLoopProxyForThread( |
| 49 content::BrowserThread::IO)) { |
| 48 g_browser_process->AddRefModule(); | 50 g_browser_process->AddRefModule(); |
| 49 channel_.reset(new IPC::ChannelProxy( | |
| 50 ipc_channel_name.c_str(), | |
| 51 IPC::Channel::MODE_NAMED_SERVER, | |
| 52 this, | |
| 53 content::BrowserThread::GetMessageLoopProxyForThread( | |
| 54 content::BrowserThread::IO))); | |
| 55 } | 51 } |
| 56 | 52 |
| 57 MetroViewerProcessHost::~MetroViewerProcessHost() { | 53 void ChromeMetroViewerProcessHost::OnChannelError() { |
| 58 } | |
| 59 | |
| 60 base::ProcessId MetroViewerProcessHost::GetViewerProcessId() { | |
| 61 if (channel_) | |
| 62 return channel_->peer_pid(); | |
| 63 return base::kNullProcessId; | |
| 64 } | |
| 65 | |
| 66 bool MetroViewerProcessHost::Send(IPC::Message* msg) { | |
| 67 return channel_->Send(msg); | |
| 68 } | |
| 69 | |
| 70 bool MetroViewerProcessHost::OnMessageReceived(const IPC::Message& message) { | |
| 71 DCHECK(CalledOnValidThread()); | |
| 72 bool handled = true; | |
| 73 IPC_BEGIN_MESSAGE_MAP(MetroViewerProcessHost, message) | |
| 74 IPC_MESSAGE_HANDLER(MetroViewerHostMsg_SetTargetSurface, OnSetTargetSurface) | |
| 75 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 76 IPC_END_MESSAGE_MAP() | |
| 77 return handled ? true : | |
| 78 aura::RemoteRootWindowHostWin::Instance()->OnMessageReceived(message); | |
| 79 } | |
| 80 | |
| 81 void MetroViewerProcessHost::OnChannelError() { | |
| 82 // TODO(cpu): At some point we only close the browser. Right now this | 54 // TODO(cpu): At some point we only close the browser. Right now this |
| 83 // is very convenient for developing. | 55 // is very convenient for developing. |
| 84 DLOG(INFO) << "viewer channel error : Quitting browser"; | 56 DLOG(INFO) << "viewer channel error : Quitting browser"; |
| 85 aura::RemoteRootWindowHostWin::Instance()->Disconnected(); | 57 aura::RemoteRootWindowHostWin::Instance()->Disconnected(); |
| 86 g_browser_process->ReleaseModule(); | 58 g_browser_process->ReleaseModule(); |
| 87 CloseOpenAshBrowsers(); | 59 CloseOpenAshBrowsers(); |
| 88 chrome::CloseAsh(); | 60 chrome::CloseAsh(); |
| 89 // Tell the rest of Chrome about it. | 61 // Tell the rest of Chrome about it. |
| 90 content::NotificationService::current()->Notify( | 62 content::NotificationService::current()->Notify( |
| 91 chrome::NOTIFICATION_ASH_SESSION_ENDED, | 63 chrome::NOTIFICATION_ASH_SESSION_ENDED, |
| 92 content::NotificationService::AllSources(), | 64 content::NotificationService::AllSources(), |
| 93 content::NotificationService::NoDetails()); | 65 content::NotificationService::NoDetails()); |
| 94 | 66 |
| 95 // This will delete the MetroViewerProcessHost object. Don't access member | 67 // This will delete the MetroViewerProcessHost object. Don't access member |
| 96 // variables/functions after this call. | 68 // variables/functions after this call. |
| 97 g_browser_process->platform_part()->OnMetroViewerProcessTerminated(); | 69 g_browser_process->platform_part()->OnMetroViewerProcessTerminated(); |
| 98 } | 70 } |
| 99 | 71 |
| 100 void MetroViewerProcessHost::OnSetTargetSurface( | 72 void ChromeMetroViewerProcessHost::OnSetTargetSurface( |
| 101 gfx::NativeViewId target_surface) { | 73 gfx::NativeViewId target_surface) { |
| 102 DLOG(INFO) << __FUNCTION__ << ", target_surface = " << target_surface; | 74 DLOG(INFO) << __FUNCTION__ << ", target_surface = " << target_surface; |
| 103 HWND hwnd = reinterpret_cast<HWND>(target_surface); | 75 HWND hwnd = reinterpret_cast<HWND>(target_surface); |
| 104 chrome::OpenAsh(); | 76 chrome::OpenAsh(); |
| 105 scoped_refptr<AcceleratedPresenter> any_window = | 77 scoped_refptr<AcceleratedPresenter> any_window = |
| 106 AcceleratedPresenter::GetForWindow(NULL); | 78 AcceleratedPresenter::GetForWindow(NULL); |
| 107 any_window->SetNewTargetWindow(hwnd); | 79 any_window->SetNewTargetWindow(hwnd); |
| 108 aura::RemoteRootWindowHostWin::Instance()->Connected(this); | 80 aura::RemoteRootWindowHostWin::Instance()->Connected(this); |
| 109 // Tell the rest of Chrome that Ash is running. | 81 // Tell the rest of Chrome that Ash is running. |
| 110 content::NotificationService::current()->Notify( | 82 content::NotificationService::current()->Notify( |
| 111 chrome::NOTIFICATION_ASH_SESSION_STARTED, | 83 chrome::NOTIFICATION_ASH_SESSION_STARTED, |
| 112 content::NotificationService::AllSources(), | 84 content::NotificationService::AllSources(), |
| 113 content::NotificationService::NoDetails()); | 85 content::NotificationService::NoDetails()); |
| 114 } | 86 } |
| OLD | NEW |