OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/automation/automation_provider.h" | 5 #include "chrome/browser/automation/automation_provider.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
13 #include "chrome/browser/automation/automation_browser_tracker.h" | 13 #include "chrome/browser/automation/automation_browser_tracker.h" |
14 #include "chrome/browser/automation/automation_tab_tracker.h" | 14 #include "chrome/browser/automation/automation_tab_tracker.h" |
15 #include "chrome/browser/automation/automation_window_tracker.h" | 15 #include "chrome/browser/automation/automation_window_tracker.h" |
16 #include "chrome/browser/external_tab/external_tab_container.h" | 16 #include "chrome/browser/external_tab/external_tab_container.h" |
17 #include "chrome/browser/printing/print_view_manager.h" | 17 #include "chrome/browser/printing/print_view_manager.h" |
18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/sessions/session_tab_helper.h" | 19 #include "chrome/browser/sessions/session_tab_helper.h" |
20 #include "chrome/browser/ui/browser.h" | 20 #include "chrome/browser/ui/browser.h" |
21 #include "chrome/browser/ui/browser_window.h" | 21 #include "chrome/browser/ui/browser_window.h" |
22 #include "chrome/common/automation_messages.h" | 22 #include "chrome/common/automation_messages.h" |
23 #include "chrome/common/render_messages.h" | 23 #include "chrome/common/render_messages.h" |
24 #include "content/public/browser/navigation_controller.h" | 24 #include "content/public/browser/navigation_controller.h" |
25 #include "content/public/browser/render_view_host.h" | 25 #include "content/public/browser/render_view_host.h" |
26 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
27 #include "content/public/browser/web_contents_view.h" | |
28 #include "content/public/common/page_zoom.h" | 27 #include "content/public/common/page_zoom.h" |
29 #include "ui/base/keycodes/keyboard_codes.h" | 28 #include "ui/base/keycodes/keyboard_codes.h" |
30 #include "ui/views/focus/accelerator_handler.h" | 29 #include "ui/views/focus/accelerator_handler.h" |
31 #include "ui/views/widget/root_view.h" | 30 #include "ui/views/widget/root_view.h" |
32 | 31 |
33 using content::NavigationController; | 32 using content::NavigationController; |
34 using content::RenderViewHost; | 33 using content::RenderViewHost; |
35 using content::WebContents; | 34 using content::WebContents; |
36 | 35 |
37 void AutomationProvider::CreateExternalTab( | 36 void AutomationProvider::CreateExternalTab( |
38 const ExternalTabSettings& settings, | 37 const ExternalTabSettings& settings, |
39 gfx::NativeWindow* tab_container_window, gfx::NativeWindow* tab_window, | 38 HWND* tab_container_window, |
40 int* tab_handle, int* session_id) { | 39 HWND* tab_window, |
40 int* tab_handle, | |
41 int* session_id) { | |
41 TRACE_EVENT_BEGIN_ETW("AutomationProvider::CreateExternalTab", 0, ""); | 42 TRACE_EVENT_BEGIN_ETW("AutomationProvider::CreateExternalTab", 0, ""); |
42 | 43 |
43 *tab_handle = 0; | 44 *tab_handle = 0; |
44 *tab_container_window = NULL; | 45 *tab_container_window = NULL; |
45 *tab_window = NULL; | 46 *tab_window = NULL; |
46 *session_id = -1; | 47 *session_id = -1; |
47 scoped_refptr<ExternalTabContainer> external_tab_container = | 48 scoped_refptr<ExternalTabContainer> external_tab_container = |
48 ExternalTabContainer::Create(this, automation_resource_message_filter_); | 49 ExternalTabContainer::Create(this, automation_resource_message_filter_); |
49 | 50 |
50 Profile* profile = settings.is_incognito ? | 51 Profile* profile = settings.is_incognito ? |
51 profile_->GetOffTheRecordProfile() : profile_; | 52 profile_->GetOffTheRecordProfile() : profile_; |
52 | 53 |
53 // When the ExternalTabContainer window is created we grab a reference on it | 54 // When the ExternalTabContainer window is created we grab a reference on it |
54 // which is released when the window is destroyed. | 55 // which is released when the window is destroyed. |
55 external_tab_container->Init(profile, settings.parent, settings.dimensions, | 56 external_tab_container->Init(profile, settings.parent, settings.dimensions, |
56 settings.style, settings.load_requests_via_automation, | 57 settings.style, settings.load_requests_via_automation, |
57 settings.handle_top_level_requests, NULL, settings.initial_url, | 58 settings.handle_top_level_requests, NULL, settings.initial_url, |
58 settings.referrer, settings.infobars_enabled, | 59 settings.referrer, settings.infobars_enabled, |
59 settings.route_all_top_level_navigations); | 60 settings.route_all_top_level_navigations); |
60 | 61 |
61 if (AddExternalTab(external_tab_container)) { | 62 if (AddExternalTab(external_tab_container)) { |
62 WebContents* web_contents = external_tab_container->GetWebContents(); | 63 WebContents* web_contents = external_tab_container->GetWebContents(); |
63 SessionTabHelper* session_tab_helper = | 64 SessionTabHelper* session_tab_helper = |
64 SessionTabHelper::FromWebContents(web_contents); | 65 SessionTabHelper::FromWebContents(web_contents); |
65 *tab_handle = external_tab_container->GetTabHandle(); | 66 *tab_handle = external_tab_container->GetTabHandle(); |
66 *tab_container_window = external_tab_container->GetExternalTabNativeView(); | 67 *tab_container_window = external_tab_container->GetExternalTabHWND(); |
67 *tab_window = web_contents->GetView()->GetNativeView(); | 68 *tab_window = external_tab_container->GetContentHWND(); |
68 *session_id = session_tab_helper->session_id().id(); | 69 *session_id = session_tab_helper->session_id().id(); |
69 } else { | 70 } else { |
70 external_tab_container->Uninitialize(); | 71 external_tab_container->Uninitialize(); |
71 } | 72 } |
72 | 73 |
73 TRACE_EVENT_END_ETW("AutomationProvider::CreateExternalTab", 0, ""); | 74 TRACE_EVENT_END_ETW("AutomationProvider::CreateExternalTab", 0, ""); |
74 } | 75 } |
75 | 76 |
76 bool AutomationProvider::AddExternalTab(ExternalTabContainer* external_tab) { | 77 bool AutomationProvider::AddExternalTab(ExternalTabContainer* external_tab) { |
77 DCHECK(external_tab != NULL); | 78 DCHECK(external_tab != NULL); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 return; | 112 return; |
112 | 113 |
113 printing::PrintViewManager* print_view_manager = | 114 printing::PrintViewManager* print_view_manager = |
114 printing::PrintViewManager::FromWebContents(web_contents); | 115 printing::PrintViewManager::FromWebContents(web_contents); |
115 print_view_manager->PrintNow(); | 116 print_view_manager->PrintNow(); |
116 } | 117 } |
117 | 118 |
118 ExternalTabContainer* AutomationProvider::GetExternalTabForHandle(int handle) { | 119 ExternalTabContainer* AutomationProvider::GetExternalTabForHandle(int handle) { |
119 if (tab_tracker_->ContainsHandle(handle)) { | 120 if (tab_tracker_->ContainsHandle(handle)) { |
120 NavigationController* tab = tab_tracker_->GetResource(handle); | 121 NavigationController* tab = tab_tracker_->GetResource(handle); |
121 return ExternalTabContainer::GetContainerForTab( | 122 return ExternalTabContainer::GetContainerForTab(tab->GetWebContents()); |
122 tab->GetWebContents()->GetView()->GetNativeView()); | |
123 } | 123 } |
124 | 124 |
125 return NULL; | 125 return NULL; |
126 } | 126 } |
127 | 127 |
128 void AutomationProvider::OnTabReposition( | 128 void AutomationProvider::OnTabReposition( |
129 int tab_handle, const Reposition_Params& params) { | 129 int tab_handle, |
130 const Reposition_Params& params) { | |
robertshield
2013/02/27 21:15:42
nit: looks like this could be wrapped as
void Aut
grt (UTC plus 2)
2013/02/28 02:48:41
Done.
| |
130 if (!tab_tracker_->ContainsHandle(tab_handle)) | 131 if (!tab_tracker_->ContainsHandle(tab_handle)) |
131 return; | 132 return; |
132 | 133 |
133 if (!IsWindow(params.window)) | 134 if (!IsWindow(params.window)) |
134 return; | 135 return; |
135 | 136 |
136 unsigned long process_id = 0; | 137 unsigned long process_id = 0; |
137 unsigned long thread_id = 0; | 138 unsigned long thread_id = 0; |
138 | 139 |
139 thread_id = GetWindowThreadProcessId(params.window, &process_id); | 140 thread_id = GetWindowThreadProcessId(params.window, &process_id); |
(...skipping 14 matching lines...) Expand all Loading... | |
154 } | 155 } |
155 } | 156 } |
156 | 157 |
157 void AutomationProvider::OnForwardContextMenuCommandToChrome(int tab_handle, | 158 void AutomationProvider::OnForwardContextMenuCommandToChrome(int tab_handle, |
158 int command) { | 159 int command) { |
159 ExternalTabContainer* external_tab = GetExternalTabForHandle(tab_handle); | 160 ExternalTabContainer* external_tab = GetExternalTabForHandle(tab_handle); |
160 if (external_tab) | 161 if (external_tab) |
161 external_tab->ExecuteContextMenuCommand(command); | 162 external_tab->ExecuteContextMenuCommand(command); |
162 } | 163 } |
163 | 164 |
164 void AutomationProvider::ConnectExternalTab( | 165 void AutomationProvider::ConnectExternalTab(uint64 cookie, |
165 uint64 cookie, | 166 bool allow, |
166 bool allow, | 167 HWND parent_window, |
167 gfx::NativeWindow parent_window, | 168 HWND* tab_container_window, |
168 gfx::NativeWindow* tab_container_window, | 169 HWND* tab_window, |
169 gfx::NativeWindow* tab_window, | 170 int* tab_handle, |
170 int* tab_handle, | 171 int* session_id) { |
171 int* session_id) { | |
172 TRACE_EVENT_BEGIN_ETW("AutomationProvider::ConnectExternalTab", 0, ""); | 172 TRACE_EVENT_BEGIN_ETW("AutomationProvider::ConnectExternalTab", 0, ""); |
173 | 173 |
174 *tab_handle = 0; | 174 *tab_handle = 0; |
175 *tab_container_window = NULL; | 175 *tab_container_window = NULL; |
176 *tab_window = NULL; | 176 *tab_window = NULL; |
177 *session_id = -1; | 177 *session_id = -1; |
178 | 178 |
179 scoped_refptr<ExternalTabContainer> external_tab_container = | 179 scoped_refptr<ExternalTabContainer> external_tab_container = |
180 ExternalTabContainer::RemovePendingTab(static_cast<uintptr_t>(cookie)); | 180 ExternalTabContainer::RemovePendingTab(static_cast<uintptr_t>(cookie)); |
181 if (!external_tab_container.get()) { | 181 if (!external_tab_container.get()) { |
182 NOTREACHED(); | 182 NOTREACHED(); |
183 return; | 183 return; |
184 } | 184 } |
185 | 185 |
186 if (allow && AddExternalTab(external_tab_container)) { | 186 if (allow && AddExternalTab(external_tab_container)) { |
187 external_tab_container->Reinitialize(this, | 187 external_tab_container->Reinitialize(this, |
188 automation_resource_message_filter_, | 188 automation_resource_message_filter_, |
189 parent_window); | 189 parent_window); |
190 WebContents* web_contents = external_tab_container->GetWebContents(); | 190 WebContents* web_contents = external_tab_container->GetWebContents(); |
191 SessionTabHelper* session_tab_helper = | 191 SessionTabHelper* session_tab_helper = |
192 SessionTabHelper::FromWebContents(web_contents); | 192 SessionTabHelper::FromWebContents(web_contents); |
193 *tab_handle = external_tab_container->GetTabHandle(); | 193 *tab_handle = external_tab_container->GetTabHandle(); |
194 *tab_container_window = external_tab_container->GetExternalTabNativeView(); | 194 *tab_container_window = external_tab_container->GetExternalTabHWND(); |
195 *tab_window = web_contents->GetView()->GetNativeView(); | 195 *tab_window = external_tab_container->GetContentHWND(); |
196 *session_id = session_tab_helper->session_id().id(); | 196 *session_id = session_tab_helper->session_id().id(); |
197 } else { | 197 } else { |
198 external_tab_container->Uninitialize(); | 198 external_tab_container->Uninitialize(); |
199 } | 199 } |
200 | 200 |
201 TRACE_EVENT_END_ETW("AutomationProvider::ConnectExternalTab", 0, ""); | 201 TRACE_EVENT_END_ETW("AutomationProvider::ConnectExternalTab", 0, ""); |
202 } | 202 } |
203 | 203 |
204 void AutomationProvider::OnBrowserMoved(int tab_handle) { | 204 void AutomationProvider::OnBrowserMoved(int tab_handle) { |
205 ExternalTabContainer* external_tab = GetExternalTabForHandle(tab_handle); | 205 ExternalTabContainer* external_tab = GetExternalTabForHandle(tab_handle); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
259 void AutomationProvider::OnSetZoomLevel(int handle, int zoom_level) { | 259 void AutomationProvider::OnSetZoomLevel(int handle, int zoom_level) { |
260 if (tab_tracker_->ContainsHandle(handle)) { | 260 if (tab_tracker_->ContainsHandle(handle)) { |
261 NavigationController* tab = tab_tracker_->GetResource(handle); | 261 NavigationController* tab = tab_tracker_->GetResource(handle); |
262 if (tab->GetWebContents() && tab->GetWebContents()->GetRenderViewHost()) { | 262 if (tab->GetWebContents() && tab->GetWebContents()->GetRenderViewHost()) { |
263 RenderViewHost* host = tab->GetWebContents()->GetRenderViewHost(); | 263 RenderViewHost* host = tab->GetWebContents()->GetRenderViewHost(); |
264 content::PageZoom zoom = static_cast<content::PageZoom>(zoom_level); | 264 content::PageZoom zoom = static_cast<content::PageZoom>(zoom_level); |
265 host->Zoom(zoom); | 265 host->Zoom(zoom); |
266 } | 266 } |
267 } | 267 } |
268 } | 268 } |
OLD | NEW |