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/metro_viewer_process_host_win.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/lifetime/application_lifetime.h" | |
10 #include "chrome/browser/ui/ash/ash_init.h" | 9 #include "chrome/browser/ui/ash/ash_init.h" |
| 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/browser_list_impl.h" |
| 12 #include "chrome/browser/ui/browser_window.h" |
| 13 #include "chrome/browser/ui/host_desktop.h" |
| 14 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
11 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
12 #include "ipc/ipc_channel_proxy.h" | 17 #include "ipc/ipc_channel_proxy.h" |
13 #include "ui/aura/remote_root_window_host_win.h" | 18 #include "ui/aura/remote_root_window_host_win.h" |
14 #include "ui/metro_viewer/metro_viewer_messages.h" | 19 #include "ui/metro_viewer/metro_viewer_messages.h" |
15 #include "ui/surface/accelerated_surface_win.h" | 20 #include "ui/surface/accelerated_surface_win.h" |
16 | 21 |
| 22 namespace { |
| 23 |
| 24 void CloseOpenAshBrowsers() { |
| 25 chrome::BrowserListImpl* browser_list = |
| 26 chrome::BrowserListImpl::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); |
| 27 if (browser_list) { |
| 28 for (chrome::BrowserListImpl::const_iterator i = browser_list->begin(); |
| 29 i != browser_list->end(); ++i) { |
| 30 Browser* browser = *i; |
| 31 browser->window()->Close(); |
| 32 // If the attempt to Close the browser fails due to unload handlers on |
| 33 // the page or in progress downloads, etc, destroy all tabs on the page. |
| 34 while (browser->tab_count()) |
| 35 delete browser->tab_strip_model()->GetTabContentsAt(0); |
| 36 } |
| 37 } |
| 38 } |
| 39 |
| 40 } // namespace |
| 41 |
| 42 |
17 MetroViewerProcessHost::MetroViewerProcessHost( | 43 MetroViewerProcessHost::MetroViewerProcessHost( |
18 const std::string& ipc_channel_name) { | 44 const std::string& ipc_channel_name) { |
19 g_browser_process->AddRefModule(); | 45 g_browser_process->AddRefModule(); |
20 channel_.reset(new IPC::ChannelProxy( | 46 channel_.reset(new IPC::ChannelProxy( |
21 ipc_channel_name.c_str(), | 47 ipc_channel_name.c_str(), |
22 IPC::Channel::MODE_NAMED_SERVER, | 48 IPC::Channel::MODE_NAMED_SERVER, |
23 this, | 49 this, |
24 content::BrowserThread::GetMessageLoopProxyForThread( | 50 content::BrowserThread::GetMessageLoopProxyForThread( |
25 content::BrowserThread::IO))); | 51 content::BrowserThread::IO))); |
26 } | 52 } |
(...skipping 20 matching lines...) Expand all Loading... |
47 IPC_MESSAGE_UNHANDLED(handled = false) | 73 IPC_MESSAGE_UNHANDLED(handled = false) |
48 IPC_END_MESSAGE_MAP() | 74 IPC_END_MESSAGE_MAP() |
49 return handled; | 75 return handled; |
50 } | 76 } |
51 | 77 |
52 void MetroViewerProcessHost::OnChannelError() { | 78 void MetroViewerProcessHost::OnChannelError() { |
53 // TODO(cpu): At some point we only close the browser. Right now this | 79 // TODO(cpu): At some point we only close the browser. Right now this |
54 // is very convenient for developing. | 80 // is very convenient for developing. |
55 DLOG(INFO) << "viewer channel error : Quitting browser"; | 81 DLOG(INFO) << "viewer channel error : Quitting browser"; |
56 g_browser_process->ReleaseModule(); | 82 g_browser_process->ReleaseModule(); |
| 83 CloseOpenAshBrowsers(); |
57 chrome::CloseAsh(); | 84 chrome::CloseAsh(); |
58 } | 85 } |
59 | 86 |
60 void MetroViewerProcessHost::OnSetTargetSurface( | 87 void MetroViewerProcessHost::OnSetTargetSurface( |
61 gfx::NativeViewId target_surface) { | 88 gfx::NativeViewId target_surface) { |
62 DLOG(INFO) << __FUNCTION__ << ", target_surface = " << target_surface; | 89 DLOG(INFO) << __FUNCTION__ << ", target_surface = " << target_surface; |
63 HWND hwnd = reinterpret_cast<HWND>(target_surface); | 90 HWND hwnd = reinterpret_cast<HWND>(target_surface); |
64 | 91 |
65 chrome::OpenAsh(); | 92 chrome::OpenAsh(); |
66 | 93 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 uint32 scan_code, | 129 uint32 scan_code, |
103 uint32 flags) { | 130 uint32 flags) { |
104 aura::RemoteRootWindowHostWin::Instance()->OnChar( | 131 aura::RemoteRootWindowHostWin::Instance()->OnChar( |
105 key_code, repeat_count, scan_code, flags); | 132 key_code, repeat_count, scan_code, flags); |
106 } | 133 } |
107 | 134 |
108 void MetroViewerProcessHost::OnVisibilityChanged(bool visible) { | 135 void MetroViewerProcessHost::OnVisibilityChanged(bool visible) { |
109 aura::RemoteRootWindowHostWin::Instance()->OnVisibilityChanged( | 136 aura::RemoteRootWindowHostWin::Instance()->OnVisibilityChanged( |
110 visible); | 137 visible); |
111 } | 138 } |
OLD | NEW |