OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/metro_viewer/metro_viewer_process_host_win.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "chrome/browser/browser_process.h" | |
9 #include "chrome/browser/browser_process_platform_part_aurawin.h" | |
10 #include "chrome/browser/ui/ash/ash_init.h" | |
11 #include "chrome/browser/ui/browser.h" | |
12 #include "chrome/browser/ui/browser_list.h" | |
13 #include "chrome/browser/ui/browser_window.h" | |
14 #include "chrome/browser/ui/host_desktop.h" | |
15 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
16 #include "chrome/common/chrome_notification_types.h" | |
17 #include "content/public/browser/browser_thread.h" | |
18 #include "content/public/browser/notification_service.h" | |
19 #include "content/public/browser/web_contents.h" | |
20 #include "ipc/ipc_channel_proxy.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" | |
24 | |
25 namespace { | |
26 | |
27 void CloseOpenAshBrowsers() { | |
28 BrowserList* browser_list = | |
29 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); | |
30 if (browser_list) { | |
31 for (BrowserList::const_iterator i = browser_list->begin(); | |
32 i != browser_list->end(); ++i) { | |
33 Browser* browser = *i; | |
34 browser->window()->Close(); | |
35 // 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. | |
37 while (browser->tab_strip_model()->count()) | |
38 delete browser->tab_strip_model()->GetWebContentsAt(0); | |
39 } | |
40 } | |
41 } | |
42 | |
43 } // namespace | |
44 | |
45 | |
46 MetroViewerProcessHost::MetroViewerProcessHost( | |
47 const std::string& ipc_channel_name) { | |
48 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 } | |
56 | |
57 MetroViewerProcessHost::~MetroViewerProcessHost() { | |
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 | |
83 // is very convenient for developing. | |
84 DLOG(INFO) << "viewer channel error : Quitting browser"; | |
85 aura::RemoteRootWindowHostWin::Instance()->Disconnected(); | |
86 g_browser_process->ReleaseModule(); | |
87 CloseOpenAshBrowsers(); | |
88 chrome::CloseAsh(); | |
89 // Tell the rest of Chrome about it. | |
90 content::NotificationService::current()->Notify( | |
91 chrome::NOTIFICATION_ASH_SESSION_ENDED, | |
92 content::NotificationService::AllSources(), | |
93 content::NotificationService::NoDetails()); | |
94 | |
95 // This will delete the MetroViewerProcessHost object. Don't access member | |
96 // variables/functions after this call. | |
97 g_browser_process->platform_part()->OnMetroViewerProcessTerminated(); | |
98 } | |
99 | |
100 void MetroViewerProcessHost::OnSetTargetSurface( | |
101 gfx::NativeViewId target_surface) { | |
102 DLOG(INFO) << __FUNCTION__ << ", target_surface = " << target_surface; | |
103 HWND hwnd = reinterpret_cast<HWND>(target_surface); | |
104 chrome::OpenAsh(); | |
105 scoped_refptr<AcceleratedPresenter> any_window = | |
106 AcceleratedPresenter::GetForWindow(NULL); | |
107 any_window->SetNewTargetWindow(hwnd); | |
108 aura::RemoteRootWindowHostWin::Instance()->Connected(this); | |
109 // Tell the rest of Chrome that Ash is running. | |
110 content::NotificationService::current()->Notify( | |
111 chrome::NOTIFICATION_ASH_SESSION_STARTED, | |
112 content::NotificationService::AllSources(), | |
113 content::NotificationService::NoDetails()); | |
114 } | |
OLD | NEW |