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/testing_automation_provider.h" | 5 #include "chrome/browser/automation/testing_automation_provider.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 #include "chrome/browser/ui/find_bar/find_bar.h" | 106 #include "chrome/browser/ui/find_bar/find_bar.h" |
107 #include "chrome/browser/ui/fullscreen_controller.h" | 107 #include "chrome/browser/ui/fullscreen_controller.h" |
108 #include "chrome/browser/ui/fullscreen_exit_bubble_type.h" | 108 #include "chrome/browser/ui/fullscreen_exit_bubble_type.h" |
109 #include "chrome/browser/ui/login/login_prompt.h" | 109 #include "chrome/browser/ui/login/login_prompt.h" |
110 #include "chrome/browser/ui/media_stream_infobar_delegate.h" | 110 #include "chrome/browser/ui/media_stream_infobar_delegate.h" |
111 #include "chrome/browser/ui/omnibox/location_bar.h" | 111 #include "chrome/browser/ui/omnibox/location_bar.h" |
112 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 112 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
113 #include "chrome/browser/ui/search_engines/keyword_editor_controller.h" | 113 #include "chrome/browser/ui/search_engines/keyword_editor_controller.h" |
114 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 114 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
115 #include "chrome/browser/view_type_utils.h" | 115 #include "chrome/browser/view_type_utils.h" |
| 116 #include "chrome/common/automation_constants.h" |
| 117 #include "chrome/common/automation_events.h" |
116 #include "chrome/common/automation_id.h" | 118 #include "chrome/common/automation_id.h" |
117 #include "chrome/common/automation_messages.h" | 119 #include "chrome/common/automation_messages.h" |
118 #include "chrome/common/chrome_constants.h" | 120 #include "chrome/common/chrome_constants.h" |
119 #include "chrome/common/chrome_notification_types.h" | 121 #include "chrome/common/chrome_notification_types.h" |
120 #include "chrome/common/chrome_paths.h" | 122 #include "chrome/common/chrome_paths.h" |
121 #include "chrome/common/chrome_switches.h" | 123 #include "chrome/common/chrome_switches.h" |
122 #include "chrome/common/extensions/extension.h" | 124 #include "chrome/common/extensions/extension.h" |
123 #include "chrome/common/extensions/extension_action.h" | 125 #include "chrome/common/extensions/extension_action.h" |
124 #include "chrome/common/extensions/url_pattern.h" | 126 #include "chrome/common/extensions/url_pattern.h" |
125 #include "chrome/common/extensions/url_pattern_set.h" | 127 #include "chrome/common/extensions/url_pattern_set.h" |
(...skipping 5289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5415 bool meta = !!(modifiers & automation::kMetaKeyMask); | 5417 bool meta = !!(modifiers & automation::kMetaKeyMask); |
5416 if (!ui_controls::SendKeyPressNotifyWhenDone( | 5418 if (!ui_controls::SendKeyPressNotifyWhenDone( |
5417 window, static_cast<ui::KeyboardCode>(keycode), | 5419 window, static_cast<ui::KeyboardCode>(keycode), |
5418 control, shift, alt, meta, | 5420 control, shift, alt, meta, |
5419 base::Bind(SendSuccessReply, AsWeakPtr(), reply_message))) { | 5421 base::Bind(SendSuccessReply, AsWeakPtr(), reply_message))) { |
5420 AutomationJSONReply(this, reply_message) | 5422 AutomationJSONReply(this, reply_message) |
5421 .SendError("Could not send the native key event"); | 5423 .SendError("Could not send the native key event"); |
5422 } | 5424 } |
5423 } | 5425 } |
5424 | 5426 |
| 5427 namespace { |
| 5428 |
| 5429 bool ReadScriptEvaluationRequestList( |
| 5430 base::Value* value, |
| 5431 std::vector<ScriptEvaluationRequest>* list, |
| 5432 std::string* error_msg) { |
| 5433 ListValue* request_list; |
| 5434 if (!value->GetAsList(&request_list)) |
| 5435 return false; |
| 5436 |
| 5437 for (size_t i = 0; i < request_list->GetSize(); ++i) { |
| 5438 DictionaryValue* request_dict; |
| 5439 if (!request_list->GetDictionary(i, &request_dict)) { |
| 5440 *error_msg = "Script evaluation request was not a dictionary"; |
| 5441 return false; |
| 5442 } |
| 5443 ScriptEvaluationRequest request; |
| 5444 if (!request_dict->GetString("script", &request.script) || |
| 5445 !request_dict->GetString("frame_xpath", &request.frame_xpath)) { |
| 5446 *error_msg = "Script evaluation request was invalid"; |
| 5447 return false; |
| 5448 } |
| 5449 list->push_back(request); |
| 5450 } |
| 5451 return true; |
| 5452 } |
| 5453 |
| 5454 void SendPointIfAlive( |
| 5455 base::WeakPtr<AutomationProvider> provider, |
| 5456 IPC::Message* reply_message, |
| 5457 const gfx::Point& point) { |
| 5458 if (provider) { |
| 5459 DictionaryValue dict; |
| 5460 dict.SetInteger("x", point.x()); |
| 5461 dict.SetInteger("y", point.y()); |
| 5462 AutomationJSONReply(provider.get(), reply_message).SendSuccess(&dict); |
| 5463 } |
| 5464 } |
| 5465 |
| 5466 void SendErrorIfAlive( |
| 5467 base::WeakPtr<AutomationProvider> provider, |
| 5468 IPC::Message* reply_message, |
| 5469 const automation::Error& error) { |
| 5470 if (provider) { |
| 5471 AutomationJSONReply(provider.get(), reply_message).SendError(error); |
| 5472 } |
| 5473 } |
| 5474 |
| 5475 } // namespace |
| 5476 |
5425 void TestingAutomationProvider::ProcessWebMouseEvent( | 5477 void TestingAutomationProvider::ProcessWebMouseEvent( |
5426 DictionaryValue* args, | 5478 DictionaryValue* args, |
5427 IPC::Message* reply_message) { | 5479 IPC::Message* reply_message) { |
5428 if (SendErrorIfModalDialogActive(this, reply_message)) | 5480 if (SendErrorIfModalDialogActive(this, reply_message)) |
5429 return; | 5481 return; |
5430 | 5482 |
5431 RenderViewHost* view; | 5483 RenderViewHost* view; |
5432 std::string error; | 5484 std::string error; |
5433 if (!GetRenderViewFromJSONArgs(args, profile(), &view, &error)) { | 5485 if (!GetRenderViewFromJSONArgs(args, profile(), &view, &error)) { |
5434 AutomationJSONReply(this, reply_message).SendError(error); | 5486 AutomationJSONReply(this, reply_message).SendError(error); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5482 event.modifiers = 0; | 5534 event.modifiers = 0; |
5483 if (modifiers & automation::kShiftKeyMask) | 5535 if (modifiers & automation::kShiftKeyMask) |
5484 event.modifiers |= WebKit::WebInputEvent::ShiftKey; | 5536 event.modifiers |= WebKit::WebInputEvent::ShiftKey; |
5485 if (modifiers & automation::kControlKeyMask) | 5537 if (modifiers & automation::kControlKeyMask) |
5486 event.modifiers |= WebKit::WebInputEvent::ControlKey; | 5538 event.modifiers |= WebKit::WebInputEvent::ControlKey; |
5487 if (modifiers & automation::kAltKeyMask) | 5539 if (modifiers & automation::kAltKeyMask) |
5488 event.modifiers |= WebKit::WebInputEvent::AltKey; | 5540 event.modifiers |= WebKit::WebInputEvent::AltKey; |
5489 if (modifiers & automation::kMetaKeyMask) | 5541 if (modifiers & automation::kMetaKeyMask) |
5490 event.modifiers |= WebKit::WebInputEvent::MetaKey; | 5542 event.modifiers |= WebKit::WebInputEvent::MetaKey; |
5491 | 5543 |
5492 view->ForwardMouseEvent(event); | 5544 AutomationMouseEvent automation_event; |
5493 new InputEventAckNotificationObserver(this, reply_message, event.type, | 5545 automation_event.mouse_event = event; |
5494 1); | 5546 Value* location_script_chain_value; |
| 5547 if (args->Get("location_script_chain", &location_script_chain_value)) { |
| 5548 if (!ReadScriptEvaluationRequestList( |
| 5549 location_script_chain_value, |
| 5550 &automation_event.location_script_chain, |
| 5551 &error)) { |
| 5552 AutomationJSONReply(this, reply_message).SendError(error); |
| 5553 return; |
| 5554 } |
| 5555 } |
| 5556 |
| 5557 new AutomationMouseEventProcessor( |
| 5558 view, |
| 5559 automation_event, |
| 5560 base::Bind(&SendPointIfAlive, AsWeakPtr(), reply_message), |
| 5561 base::Bind(&SendErrorIfAlive, AsWeakPtr(), reply_message)); |
5495 } | 5562 } |
5496 | 5563 |
5497 namespace { | 5564 namespace { |
5498 | 5565 |
5499 // Gets the active JavaScript modal dialog, or NULL if none. | 5566 // Gets the active JavaScript modal dialog, or NULL if none. |
5500 JavaScriptAppModalDialog* GetActiveJavaScriptModalDialog( | 5567 JavaScriptAppModalDialog* GetActiveJavaScriptModalDialog( |
5501 ErrorCode* error_code) { | 5568 ErrorCode* error_code) { |
5502 AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance(); | 5569 AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance(); |
5503 if (!dialog_queue->HasActiveDialog() || | 5570 if (!dialog_queue->HasActiveDialog() || |
5504 !dialog_queue->active_dialog()->IsJavaScriptModalDialog()) { | 5571 !dialog_queue->active_dialog()->IsJavaScriptModalDialog()) { |
(...skipping 1074 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6579 | 6646 |
6580 void TestingAutomationProvider::WaitForProcessLauncherThreadToGoIdle( | 6647 void TestingAutomationProvider::WaitForProcessLauncherThreadToGoIdle( |
6581 IPC::Message* reply_message) { | 6648 IPC::Message* reply_message) { |
6582 new WaitForProcessLauncherThreadToGoIdleObserver(this, reply_message); | 6649 new WaitForProcessLauncherThreadToGoIdleObserver(this, reply_message); |
6583 } | 6650 } |
6584 | 6651 |
6585 void TestingAutomationProvider::OnRemoveProvider() { | 6652 void TestingAutomationProvider::OnRemoveProvider() { |
6586 if (g_browser_process) | 6653 if (g_browser_process) |
6587 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); | 6654 g_browser_process->GetAutomationProviderList()->RemoveProvider(this); |
6588 } | 6655 } |
OLD | NEW |