|
31 | 31 | #include "content/public/browser/render_process_host.h" |
32 | 32 |
|
33 | 33 | namespace api { |
| 34 | + |
| 35 | +namespace { |
| 36 | + |
| 37 | +// Get render process host. |
| 38 | +content::RenderProcessHost* GetRenderProcessHost() { |
| 39 | + content::RenderProcessHost* render_process_host = NULL; |
| 40 | + std::vector<content::Shell*> windows = content::Shell::windows(); |
| 41 | + for (size_t i = 0; i < windows.size(); ++i) { |
| 42 | + if (!windows[i]->is_devtools()) { |
| 43 | + render_process_host = windows[i]->web_contents()->GetRenderProcessHost(); |
| 44 | + break; |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + return render_process_host; |
| 49 | +} |
| 50 | + |
| 51 | +} // namespace |
34 | 52 |
|
35 | 53 | // static |
36 | 54 | void App::Call(const std::string& method, |
37 | 55 | const base::ListValue& arguments) { |
38 | 56 | if (method == "Quit") { |
39 | | - Quit(); |
| 57 | + Quit(GetRenderProcessHost()); |
40 | 58 | return; |
41 | 59 | } else if (method == "CloseAllWindows") { |
42 | 60 | CloseAllWindows(); |
@@ -82,23 +100,20 @@ void App::CloseAllWindows() { |
82 | 100 | } |
83 | 101 |
|
84 | 102 | // static |
85 | | -void App::Quit() { |
| 103 | +void App::Quit(content::RenderProcessHost* render_process_host) { |
| 104 | + // Send the quit message. |
| 105 | + render_process_host->Send(new ShellViewMsg_WillQuit()); |
| 106 | + |
| 107 | + // Then quit. |
86 | 108 | MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
87 | 109 | } |
88 | 110 |
|
89 | 111 | // static |
90 | 112 | void App::EmitOpenEvent(const std::string& path) { |
91 | 113 | // Get the app's renderer process. |
92 | | - content::RenderProcessHost* render_process_host = NULL; |
93 | | - std::vector<content::Shell*> windows = content::Shell::windows(); |
94 | | - for (size_t i = 0; i < windows.size(); ++i) { |
95 | | - if (!windows[i]->is_devtools()) { |
96 | | - render_process_host = windows[i]->web_contents()->GetRenderProcessHost(); |
97 | | - break; |
98 | | - } |
99 | | - } |
100 | | - |
| 114 | + content::RenderProcessHost* render_process_host = GetRenderProcessHost(); |
101 | 115 | DCHECK(render_process_host != NULL); |
| 116 | + |
102 | 117 | render_process_host->Send(new ShellViewMsg_Open(path)); |
103 | 118 | } |
104 | 119 |
|
|
0 commit comments