Chromium Code Reviews| 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/testing_automation_provider.h" | 5 #include "chrome/browser/automation/testing_automation_provider.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 4637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4648 if (modifiers & automation::kControlKeyMask) | 4648 if (modifiers & automation::kControlKeyMask) |
| 4649 event.modifiers |= WebKit::WebInputEvent::ControlKey; | 4649 event.modifiers |= WebKit::WebInputEvent::ControlKey; |
| 4650 if (modifiers & automation::kAltKeyMask) | 4650 if (modifiers & automation::kAltKeyMask) |
| 4651 event.modifiers |= WebKit::WebInputEvent::AltKey; | 4651 event.modifiers |= WebKit::WebInputEvent::AltKey; |
| 4652 if (modifiers & automation::kMetaKeyMask) | 4652 if (modifiers & automation::kMetaKeyMask) |
| 4653 event.modifiers |= WebKit::WebInputEvent::MetaKey; | 4653 event.modifiers |= WebKit::WebInputEvent::MetaKey; |
| 4654 | 4654 |
| 4655 event.isSystemKey = is_system_key; | 4655 event.isSystemKey = is_system_key; |
| 4656 event.timeStampSeconds = base::Time::Now().ToDoubleT(); | 4656 event.timeStampSeconds = base::Time::Now().ToDoubleT(); |
| 4657 event.skip_in_browser = true; | 4657 event.skip_in_browser = true; |
| 4658 new InputEventAckNotificationObserver(this, reply_message, event.type); | 4658 bool use_native_events = false; |
| 4659 browser->GetSelectedTabContents()->render_view_host()-> | 4659 // If useNativeEvents is true, this funciton will call |
| 4660 ForwardKeyboardEvent(event); | 4660 // ui_controls::endKeyPress to the native window handle of the browser, |
| 4661 // allowing events to be catched higher up; if false it will send an | |
| 4662 // event directly to webkit. | |
| 4663 if (args->GetBoolean("useNativeEvents", &use_native_events) | |
| 4664 && use_native_events) { | |
|
Hironori Bono
2011/03/04 06:25:17
nit: This operator should be the end of the previo
timothe faudot
2011/03/04 06:47:35
Done.
| |
| 4665 // The ui_controls::SendKeyPress function will generate up and down events | |
| 4666 // from one keycode for us so we only need to send one event to it. | |
| 4667 // Filtering is done via the RawKeyDown type because it is the one sent by | |
| 4668 // the current webdriver implementation of WebElement.SendKeys(...). | |
| 4669 if (event.type == WebKit::WebInputEvent::RawKeyDown) { | |
| 4670 BrowserWindow* browser_window = browser->window(); | |
| 4671 if (browser_window == NULL) { | |
|
Hironori Bono
2011/03/04 06:25:17
nit: browser_window == NULL -> !browser_window
timothe faudot
2011/03/04 06:47:35
Done.
| |
| 4672 AutomationJSONReply reply(this, reply_message); | |
| 4673 reply.SendError("Could not get the browser window"); | |
| 4674 return; | |
| 4675 } | |
| 4676 gfx::NativeWindow window = browser_window->GetNativeHandle(); | |
| 4677 if (window == NULL) { | |
|
Hironori Bono
2011/03/04 06:25:17
nit: window == NULL -> !window
timothe faudot
2011/03/04 06:47:35
Done.
| |
| 4678 AutomationJSONReply reply(this, reply_message); | |
| 4679 reply.SendError("Could not get the browser window handle"); | |
| 4680 return; | |
| 4681 } | |
| 4682 if (!ui_controls::SendKeyPress( | |
| 4683 window, static_cast<ui::KeyboardCode>(event.nativeKeyCode), | |
| 4684 ((event.modifiers & WebKit::WebInputEvent::ControlKey) == | |
| 4685 WebKit::WebInputEvent::ControlKey), | |
|
Hironori Bono
2011/03/04 06:25:17
nit: I prefer using a local variable as listed in
timothe faudot
2011/03/04 06:47:35
Done.
| |
| 4686 ((event.modifiers & WebKit::WebInputEvent::ShiftKey) == | |
| 4687 WebKit::WebInputEvent::ShiftKey), | |
| 4688 ((event.modifiers & WebKit::WebInputEvent::AltKey) == | |
| 4689 WebKit::WebInputEvent::AltKey), | |
| 4690 ((event.modifiers & WebKit::WebInputEvent::MetaKey) == | |
| 4691 WebKit::WebInputEvent::MetaKey))) { | |
| 4692 AutomationJSONReply reply(this, reply_message); | |
| 4693 reply.SendError("Could not send the native key event"); | |
| 4694 return; | |
| 4695 } else { | |
| 4696 AutomationJSONReply reply(this, reply_message); | |
| 4697 reply.SendSuccess(NULL); | |
| 4698 } | |
| 4699 } else { | |
| 4700 // Skip this event by acknowledging it without doing nothing. | |
| 4701 AutomationJSONReply reply(this, reply_message); | |
| 4702 reply.SendSuccess(NULL); | |
| 4703 } | |
| 4704 } else { | |
| 4705 new InputEventAckNotificationObserver(this, reply_message, event.type); | |
| 4706 browser->GetSelectedTabContents()->render_view_host()-> | |
| 4707 ForwardKeyboardEvent(event); | |
|
Hironori Bono
2011/03/04 06:25:17
nit: I prefer using an early exit as listed in the
timothe faudot
2011/03/04 06:47:35
Down, also added an early return statement up.
| |
| 4708 } | |
| 4661 } | 4709 } |
| 4662 | 4710 |
| 4663 // Sample JSON input: { "command": "GetNTPThumbnailMode" } | 4711 // Sample JSON input: { "command": "GetNTPThumbnailMode" } |
| 4664 // For output, refer to GetNTPThumbnailMode() in | 4712 // For output, refer to GetNTPThumbnailMode() in |
| 4665 // chrome/test/pyautolib/pyauto.py. | 4713 // chrome/test/pyautolib/pyauto.py. |
| 4666 void TestingAutomationProvider::GetNTPThumbnailMode( | 4714 void TestingAutomationProvider::GetNTPThumbnailMode( |
| 4667 Browser* browser, | 4715 Browser* browser, |
| 4668 DictionaryValue* args, | 4716 DictionaryValue* args, |
| 4669 IPC::Message* reply_message) { | 4717 IPC::Message* reply_message) { |
| 4670 const int shown_sections = ShownSectionsHandler::GetShownSections( | 4718 const int shown_sections = ShownSectionsHandler::GetShownSections( |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4765 } | 4813 } |
| 4766 | 4814 |
| 4767 PrefService* prefs = browser->profile()->GetPrefs(); | 4815 PrefService* prefs = browser->profile()->GetPrefs(); |
| 4768 Section section; | 4816 Section section; |
| 4769 if (section_name.compare("apps") == 0) { | 4817 if (section_name.compare("apps") == 0) { |
| 4770 section = MENU_APPS; | 4818 section = MENU_APPS; |
| 4771 } else if (section_name.compare("most_visited") == 0) { | 4819 } else if (section_name.compare("most_visited") == 0) { |
| 4772 section = MENU_THUMB; | 4820 section = MENU_THUMB; |
| 4773 } else if (section_name.compare("recently_closed") == 0) { | 4821 } else if (section_name.compare("recently_closed") == 0) { |
| 4774 section = MENU_RECENT; | 4822 section = MENU_RECENT; |
| 4775 } | 4823 } else { |
| 4776 else { | |
| 4777 reply.SendError(StringPrintf("Unexpected section name: '%s'", | 4824 reply.SendError(StringPrintf("Unexpected section name: '%s'", |
| 4778 section_name.c_str())); | 4825 section_name.c_str())); |
| 4779 return; | 4826 return; |
| 4780 } | 4827 } |
| 4781 | 4828 |
| 4782 int shown_sections = ShownSectionsHandler::GetShownSections(prefs); | 4829 int shown_sections = ShownSectionsHandler::GetShownSections(prefs); |
| 4783 if (turn_on) { | 4830 if (turn_on) { |
| 4784 // Change the bit for the relevant section in the bitmask to 1. | 4831 // Change the bit for the relevant section in the bitmask to 1. |
| 4785 shown_sections |= section; | 4832 shown_sections |= section; |
| 4786 } else { | 4833 } else { |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5023 // If you change this, update Observer for NotificationType::SESSION_END | 5070 // If you change this, update Observer for NotificationType::SESSION_END |
| 5024 // below. | 5071 // below. |
| 5025 MessageLoop::current()->PostTask(FROM_HERE, | 5072 MessageLoop::current()->PostTask(FROM_HERE, |
| 5026 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); | 5073 NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); |
| 5027 } | 5074 } |
| 5028 } | 5075 } |
| 5029 | 5076 |
| 5030 void TestingAutomationProvider::OnRemoveProvider() { | 5077 void TestingAutomationProvider::OnRemoveProvider() { |
| 5031 AutomationProviderList::GetInstance()->RemoveProvider(this); | 5078 AutomationProviderList::GetInstance()->RemoveProvider(this); |
| 5032 } | 5079 } |
| OLD | NEW |