| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 #include "chrome/common/automation_messages.h" | 24 #include "chrome/common/automation_messages.h" |
| 25 #include "chrome/common/render_messages.h" | 25 #include "chrome/common/render_messages.h" |
| 26 #include "content/browser/renderer_host/render_view_host.h" | 26 #include "content/browser/renderer_host/render_view_host.h" |
| 27 #include "content/public/browser/navigation_controller.h" | 27 #include "content/public/browser/navigation_controller.h" |
| 28 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
| 29 #include "content/public/common/page_zoom.h" | 29 #include "content/public/common/page_zoom.h" |
| 30 #include "ui/base/keycodes/keyboard_codes.h" | 30 #include "ui/base/keycodes/keyboard_codes.h" |
| 31 #include "ui/views/focus/accelerator_handler.h" | 31 #include "ui/views/focus/accelerator_handler.h" |
| 32 #include "ui/views/widget/root_view.h" | 32 #include "ui/views/widget/root_view.h" |
| 33 | 33 |
| 34 using content::NavigationController; |
| 34 using content::WebContents; | 35 using content::WebContents; |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| 38 // This callback just adds another callback to the event queue. This is useful | 39 // This callback just adds another callback to the event queue. This is useful |
| 39 // if you want to ensure that any callbacks added to the event queue after this | 40 // if you want to ensure that any callbacks added to the event queue after this |
| 40 // one have already been processed by the time |callback| is run. | 41 // one have already been processed by the time |callback| is run. |
| 41 void InvokeCallbackLater(const base::Closure& callback) { | 42 void InvokeCallbackLater(const base::Closure& callback) { |
| 42 MessageLoop::current()->PostTask(FROM_HERE, callback); | 43 MessageLoop::current()->PostTask(FROM_HERE, callback); |
| 43 } | 44 } |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 if (!web_contents) | 243 if (!web_contents) |
| 243 return; | 244 return; |
| 244 | 245 |
| 245 TabContentsWrapper* wrapper = | 246 TabContentsWrapper* wrapper = |
| 246 TabContentsWrapper::GetCurrentWrapperForContents(web_contents); | 247 TabContentsWrapper::GetCurrentWrapperForContents(web_contents); |
| 247 wrapper->print_view_manager()->PrintNow(); | 248 wrapper->print_view_manager()->PrintNow(); |
| 248 } | 249 } |
| 249 | 250 |
| 250 ExternalTabContainer* AutomationProvider::GetExternalTabForHandle(int handle) { | 251 ExternalTabContainer* AutomationProvider::GetExternalTabForHandle(int handle) { |
| 251 if (tab_tracker_->ContainsHandle(handle)) { | 252 if (tab_tracker_->ContainsHandle(handle)) { |
| 252 content::NavigationController* tab = tab_tracker_->GetResource(handle); | 253 NavigationController* tab = tab_tracker_->GetResource(handle); |
| 253 return ExternalTabContainer::GetContainerForTab( | 254 return ExternalTabContainer::GetContainerForTab( |
| 254 tab->GetWebContents()->GetNativeView()); | 255 tab->GetWebContents()->GetNativeView()); |
| 255 } | 256 } |
| 256 | 257 |
| 257 return NULL; | 258 return NULL; |
| 258 } | 259 } |
| 259 | 260 |
| 260 void AutomationProvider::OnTabReposition( | 261 void AutomationProvider::OnTabReposition( |
| 261 int tab_handle, const Reposition_Params& params) { | 262 int tab_handle, const Reposition_Params& params) { |
| 262 if (!tab_tracker_->ContainsHandle(tab_handle)) | 263 if (!tab_tracker_->ContainsHandle(tab_handle)) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 284 DLOG(WARNING) << "SetParent failed. Error 0x%x" << GetLastError(); | 285 DLOG(WARNING) << "SetParent failed. Error 0x%x" << GetLastError(); |
| 285 } | 286 } |
| 286 } | 287 } |
| 287 } | 288 } |
| 288 | 289 |
| 289 void AutomationProvider::OnForwardContextMenuCommandToChrome(int tab_handle, | 290 void AutomationProvider::OnForwardContextMenuCommandToChrome(int tab_handle, |
| 290 int command) { | 291 int command) { |
| 291 if (!tab_tracker_->ContainsHandle(tab_handle)) | 292 if (!tab_tracker_->ContainsHandle(tab_handle)) |
| 292 return; | 293 return; |
| 293 | 294 |
| 294 content::NavigationController* tab = tab_tracker_->GetResource(tab_handle); | 295 NavigationController* tab = tab_tracker_->GetResource(tab_handle); |
| 295 if (!tab) { | 296 if (!tab) { |
| 296 NOTREACHED(); | 297 NOTREACHED(); |
| 297 return; | 298 return; |
| 298 } | 299 } |
| 299 | 300 |
| 300 WebContents* web_contents = tab->GetWebContents(); | 301 WebContents* web_contents = tab->GetWebContents(); |
| 301 if (!web_contents || !web_contents->GetDelegate()) { | 302 if (!web_contents || !web_contents->GetDelegate()) { |
| 302 NOTREACHED(); | 303 NOTREACHED(); |
| 303 return; | 304 return; |
| 304 } | 305 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 view_host->Send(new ChromeViewMsg_HandleMessageFromExternalHost( | 365 view_host->Send(new ChromeViewMsg_HandleMessageFromExternalHost( |
| 365 view_host->routing_id(), message, origin, target)); | 366 view_host->routing_id(), message, origin, target)); |
| 366 } | 367 } |
| 367 | 368 |
| 368 void AutomationProvider::NavigateInExternalTab( | 369 void AutomationProvider::NavigateInExternalTab( |
| 369 int handle, const GURL& url, const GURL& referrer, | 370 int handle, const GURL& url, const GURL& referrer, |
| 370 AutomationMsg_NavigationResponseValues* status) { | 371 AutomationMsg_NavigationResponseValues* status) { |
| 371 *status = AUTOMATION_MSG_NAVIGATION_ERROR; | 372 *status = AUTOMATION_MSG_NAVIGATION_ERROR; |
| 372 | 373 |
| 373 if (tab_tracker_->ContainsHandle(handle)) { | 374 if (tab_tracker_->ContainsHandle(handle)) { |
| 374 content::NavigationController* tab = tab_tracker_->GetResource(handle); | 375 NavigationController* tab = tab_tracker_->GetResource(handle); |
| 375 tab->LoadURL( | 376 tab->LoadURL( |
| 376 url, | 377 url, |
| 377 content::Referrer(referrer, WebKit::WebReferrerPolicyDefault), | 378 content::Referrer(referrer, WebKit::WebReferrerPolicyDefault), |
| 378 content::PAGE_TRANSITION_TYPED, std::string()); | 379 content::PAGE_TRANSITION_TYPED, std::string()); |
| 379 *status = AUTOMATION_MSG_NAVIGATION_SUCCESS; | 380 *status = AUTOMATION_MSG_NAVIGATION_SUCCESS; |
| 380 } | 381 } |
| 381 } | 382 } |
| 382 | 383 |
| 383 void AutomationProvider::NavigateExternalTabAtIndex( | 384 void AutomationProvider::NavigateExternalTabAtIndex( |
| 384 int handle, int navigation_index, | 385 int handle, int navigation_index, |
| 385 AutomationMsg_NavigationResponseValues* status) { | 386 AutomationMsg_NavigationResponseValues* status) { |
| 386 *status = AUTOMATION_MSG_NAVIGATION_ERROR; | 387 *status = AUTOMATION_MSG_NAVIGATION_ERROR; |
| 387 | 388 |
| 388 if (tab_tracker_->ContainsHandle(handle)) { | 389 if (tab_tracker_->ContainsHandle(handle)) { |
| 389 content::NavigationController* tab = tab_tracker_->GetResource(handle); | 390 NavigationController* tab = tab_tracker_->GetResource(handle); |
| 390 tab->GoToIndex(navigation_index); | 391 tab->GoToIndex(navigation_index); |
| 391 *status = AUTOMATION_MSG_NAVIGATION_SUCCESS; | 392 *status = AUTOMATION_MSG_NAVIGATION_SUCCESS; |
| 392 } | 393 } |
| 393 } | 394 } |
| 394 | 395 |
| 395 void AutomationProvider::OnRunUnloadHandlers( | 396 void AutomationProvider::OnRunUnloadHandlers( |
| 396 int handle, IPC::Message* reply_message) { | 397 int handle, IPC::Message* reply_message) { |
| 397 ExternalTabContainer* external_tab = GetExternalTabForHandle(handle); | 398 ExternalTabContainer* external_tab = GetExternalTabForHandle(handle); |
| 398 if (external_tab) { | 399 if (external_tab) { |
| 399 external_tab->RunUnloadHandlers(reply_message); | 400 external_tab->RunUnloadHandlers(reply_message); |
| 400 } | 401 } |
| 401 } | 402 } |
| 402 | 403 |
| 403 void AutomationProvider::OnSetZoomLevel(int handle, int zoom_level) { | 404 void AutomationProvider::OnSetZoomLevel(int handle, int zoom_level) { |
| 404 if (tab_tracker_->ContainsHandle(handle)) { | 405 if (tab_tracker_->ContainsHandle(handle)) { |
| 405 content::NavigationController* tab = tab_tracker_->GetResource(handle); | 406 NavigationController* tab = tab_tracker_->GetResource(handle); |
| 406 if (tab->GetWebContents() && tab->GetWebContents()->GetRenderViewHost()) { | 407 if (tab->GetWebContents() && tab->GetWebContents()->GetRenderViewHost()) { |
| 407 RenderViewHost* host = tab->GetWebContents()->GetRenderViewHost(); | 408 RenderViewHost* host = tab->GetWebContents()->GetRenderViewHost(); |
| 408 content::PageZoom zoom = static_cast<content::PageZoom>(zoom_level); | 409 content::PageZoom zoom = static_cast<content::PageZoom>(zoom_level); |
| 409 host->Zoom(zoom); | 410 host->Zoom(zoom); |
| 410 } | 411 } |
| 411 } | 412 } |
| 412 } | 413 } |
| OLD | NEW |