OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <set> | 7 #include <set> |
8 | 8 |
9 #include "app/message_box_flags.h" | 9 #include "app/message_box_flags.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 ExtensionsService* service = profile_->GetExtensionsService(); | 327 ExtensionsService* service = profile_->GetExtensionsService(); |
328 if (extension && service && | 328 if (extension && service && |
329 service->GetExtensionById(extension->id(), true) && | 329 service->GetExtensionById(extension->id(), true) && |
330 !service->GetExtensionById(extension->id(), false)) | 330 !service->GetExtensionById(extension->id(), false)) |
331 return extension; | 331 return extension; |
332 return NULL; | 332 return NULL; |
333 } | 333 } |
334 | 334 |
335 void AutomationProvider::OnMessageReceived(const IPC::Message& message) { | 335 void AutomationProvider::OnMessageReceived(const IPC::Message& message) { |
336 IPC_BEGIN_MESSAGE_MAP(AutomationProvider, message) | 336 IPC_BEGIN_MESSAGE_MAP(AutomationProvider, message) |
337 IPC_MESSAGE_HANDLER(AutomationMsg_BrowserWindow, GetBrowserWindow) | |
338 IPC_MESSAGE_HANDLER(AutomationMsg_GetBrowserLocale, GetBrowserLocale) | |
339 IPC_MESSAGE_HANDLER(AutomationMsg_LastActiveBrowserWindow, | |
340 GetLastActiveBrowserWindow) | |
341 IPC_MESSAGE_HANDLER(AutomationMsg_ActiveWindow, GetActiveWindow) | |
342 IPC_MESSAGE_HANDLER(AutomationMsg_FindNormalBrowserWindow, | |
343 FindNormalBrowserWindow) | |
344 IPC_MESSAGE_HANDLER(AutomationMsg_IsWindowActive, IsWindowActive) | |
345 IPC_MESSAGE_HANDLER(AutomationMsg_ActivateWindow, ActivateWindow) | |
346 IPC_MESSAGE_HANDLER(AutomationMsg_IsWindowMaximized, IsWindowMaximized) | |
347 IPC_MESSAGE_HANDLER(AutomationMsg_WindowExecuteCommandAsync, | |
348 ExecuteBrowserCommandAsync) | |
349 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowExecuteCommand, | |
350 ExecuteBrowserCommand) | |
351 IPC_MESSAGE_HANDLER(AutomationMsg_TerminateSession, TerminateSession) | 337 IPC_MESSAGE_HANDLER(AutomationMsg_TerminateSession, TerminateSession) |
352 IPC_MESSAGE_HANDLER(AutomationMsg_WindowViewBounds, WindowGetViewBounds) | 338 IPC_MESSAGE_HANDLER(AutomationMsg_WindowViewBounds, WindowGetViewBounds) |
353 IPC_MESSAGE_HANDLER(AutomationMsg_GetWindowBounds, GetWindowBounds) | 339 IPC_MESSAGE_HANDLER(AutomationMsg_GetWindowBounds, GetWindowBounds) |
354 IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowBounds, SetWindowBounds) | 340 IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowBounds, SetWindowBounds) |
355 IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowVisible, SetWindowVisible) | 341 IPC_MESSAGE_HANDLER(AutomationMsg_SetWindowVisible, SetWindowVisible) |
356 IPC_MESSAGE_HANDLER(AutomationMsg_WindowClick, WindowSimulateClick) | 342 IPC_MESSAGE_HANDLER(AutomationMsg_WindowClick, WindowSimulateClick) |
357 IPC_MESSAGE_HANDLER(AutomationMsg_WindowMouseMove, WindowSimulateMouseMove) | 343 IPC_MESSAGE_HANDLER(AutomationMsg_WindowMouseMove, WindowSimulateMouseMove) |
358 IPC_MESSAGE_HANDLER(AutomationMsg_WindowKeyPress, WindowSimulateKeyPress) | 344 IPC_MESSAGE_HANDLER(AutomationMsg_WindowKeyPress, WindowSimulateKeyPress) |
359 #if !defined(OS_MACOSX) | 345 #if !defined(OS_MACOSX) |
360 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowDrag, | 346 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_WindowDrag, |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 IPC_MESSAGE_HANDLER(AutomationMsg_RunUnloadHandlers, OnRunUnloadHandlers) | 537 IPC_MESSAGE_HANDLER(AutomationMsg_RunUnloadHandlers, OnRunUnloadHandlers) |
552 IPC_MESSAGE_HANDLER(AutomationMsg_SetZoomLevel, OnSetZoomLevel) | 538 IPC_MESSAGE_HANDLER(AutomationMsg_SetZoomLevel, OnSetZoomLevel) |
553 #endif // defined(OS_WIN) | 539 #endif // defined(OS_WIN) |
554 #if defined(OS_CHROMEOS) | 540 #if defined(OS_CHROMEOS) |
555 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_LoginWithUserAndPass, | 541 IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_LoginWithUserAndPass, |
556 LoginWithUserAndPass) | 542 LoginWithUserAndPass) |
557 #endif // defined(OS_CHROMEOS) | 543 #endif // defined(OS_CHROMEOS) |
558 IPC_END_MESSAGE_MAP() | 544 IPC_END_MESSAGE_MAP() |
559 } | 545 } |
560 | 546 |
561 void AutomationProvider::GetBrowserLocale(string16* locale) { | |
562 DCHECK(g_browser_process); | |
563 *locale = ASCIIToUTF16(g_browser_process->GetApplicationLocale()); | |
564 } | |
565 | |
566 void AutomationProvider::GetShowingAppModalDialog(bool* showing_dialog, | 547 void AutomationProvider::GetShowingAppModalDialog(bool* showing_dialog, |
567 int* dialog_button) { | 548 int* dialog_button) { |
568 AppModalDialog* dialog_delegate = | 549 AppModalDialog* dialog_delegate = |
569 Singleton<AppModalDialogQueue>()->active_dialog(); | 550 Singleton<AppModalDialogQueue>()->active_dialog(); |
570 *showing_dialog = (dialog_delegate != NULL); | 551 *showing_dialog = (dialog_delegate != NULL); |
571 if (*showing_dialog) | 552 if (*showing_dialog) |
572 *dialog_button = dialog_delegate->GetDialogButtons(); | 553 *dialog_button = dialog_delegate->GetDialogButtons(); |
573 else | 554 else |
574 *dialog_button = MessageBoxFlags::DIALOGBUTTON_NONE; | 555 *dialog_button = MessageBoxFlags::DIALOGBUTTON_NONE; |
575 } | 556 } |
(...skipping 22 matching lines...) Expand all Loading... |
598 void AutomationProvider::ShutdownSessionService(int handle, bool* result) { | 579 void AutomationProvider::ShutdownSessionService(int handle, bool* result) { |
599 if (browser_tracker_->ContainsHandle(handle)) { | 580 if (browser_tracker_->ContainsHandle(handle)) { |
600 Browser* browser = browser_tracker_->GetResource(handle); | 581 Browser* browser = browser_tracker_->GetResource(handle); |
601 browser->profile()->ShutdownSessionService(); | 582 browser->profile()->ShutdownSessionService(); |
602 *result = true; | 583 *result = true; |
603 } else { | 584 } else { |
604 *result = false; | 585 *result = false; |
605 } | 586 } |
606 } | 587 } |
607 | 588 |
608 void AutomationProvider::GetBrowserWindow(int index, int* handle) { | |
609 *handle = 0; | |
610 if (index >= 0) { | |
611 BrowserList::const_iterator iter = BrowserList::begin(); | |
612 for (; (iter != BrowserList::end()) && (index > 0); ++iter, --index) {} | |
613 if (iter != BrowserList::end()) { | |
614 *handle = browser_tracker_->Add(*iter); | |
615 } | |
616 } | |
617 } | |
618 | |
619 void AutomationProvider::FindNormalBrowserWindow(int* handle) { | |
620 *handle = 0; | |
621 Browser* browser = BrowserList::FindBrowserWithType(profile_, | |
622 Browser::TYPE_NORMAL, | |
623 false); | |
624 if (browser) | |
625 *handle = browser_tracker_->Add(browser); | |
626 } | |
627 | |
628 void AutomationProvider::GetLastActiveBrowserWindow(int* handle) { | |
629 *handle = 0; | |
630 Browser* browser = BrowserList::GetLastActive(); | |
631 if (browser) | |
632 *handle = browser_tracker_->Add(browser); | |
633 } | |
634 | |
635 #if defined(OS_POSIX) | |
636 // TODO(estade): use this implementation for all platforms? | |
637 void AutomationProvider::GetActiveWindow(int* handle) { | |
638 gfx::NativeWindow window = | |
639 BrowserList::GetLastActive()->window()->GetNativeHandle(); | |
640 *handle = window_tracker_->Add(window); | |
641 } | |
642 #endif | |
643 | |
644 void AutomationProvider::ExecuteBrowserCommandAsync(int handle, int command, | |
645 bool* success) { | |
646 *success = false; | |
647 if (browser_tracker_->ContainsHandle(handle)) { | |
648 Browser* browser = browser_tracker_->GetResource(handle); | |
649 if (browser->command_updater()->SupportsCommand(command) && | |
650 browser->command_updater()->IsCommandEnabled(command)) { | |
651 browser->ExecuteCommand(command); | |
652 *success = true; | |
653 } | |
654 } | |
655 } | |
656 | |
657 void AutomationProvider::ExecuteBrowserCommand( | |
658 int handle, int command, IPC::Message* reply_message) { | |
659 // List of commands which just finish synchronously and don't require | |
660 // setting up an observer. | |
661 static const int kSynchronousCommands[] = { | |
662 IDC_HOME, | |
663 IDC_SELECT_NEXT_TAB, | |
664 IDC_SELECT_PREVIOUS_TAB, | |
665 IDC_SHOW_BOOKMARK_MANAGER, | |
666 }; | |
667 if (browser_tracker_->ContainsHandle(handle)) { | |
668 Browser* browser = browser_tracker_->GetResource(handle); | |
669 if (browser->command_updater()->SupportsCommand(command) && | |
670 browser->command_updater()->IsCommandEnabled(command)) { | |
671 // First check if we can handle the command without using an observer. | |
672 for (size_t i = 0; i < arraysize(kSynchronousCommands); i++) { | |
673 if (command == kSynchronousCommands[i]) { | |
674 browser->ExecuteCommand(command); | |
675 AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message, | |
676 true); | |
677 Send(reply_message); | |
678 return; | |
679 } | |
680 } | |
681 | |
682 // Use an observer if we have one, otherwise fail. | |
683 if (ExecuteBrowserCommandObserver::CreateAndRegisterObserver( | |
684 this, browser, command, reply_message)) { | |
685 browser->ExecuteCommand(command); | |
686 return; | |
687 } | |
688 } | |
689 } | |
690 AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message, false); | |
691 Send(reply_message); | |
692 } | |
693 | |
694 // This task just adds another task to the event queue. This is useful if | 589 // This task just adds another task to the event queue. This is useful if |
695 // you want to ensure that any tasks added to the event queue after this one | 590 // you want to ensure that any tasks added to the event queue after this one |
696 // have already been processed by the time |task| is run. | 591 // have already been processed by the time |task| is run. |
697 class InvokeTaskLaterTask : public Task { | 592 class InvokeTaskLaterTask : public Task { |
698 public: | 593 public: |
699 explicit InvokeTaskLaterTask(Task* task) : task_(task) {} | 594 explicit InvokeTaskLaterTask(Task* task) : task_(task) {} |
700 virtual ~InvokeTaskLaterTask() {} | 595 virtual ~InvokeTaskLaterTask() {} |
701 | 596 |
702 virtual void Run() { | 597 virtual void Run() { |
703 MessageLoop::current()->PostTask(FROM_HERE, task_); | 598 MessageLoop::current()->PostTask(FROM_HERE, task_); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
739 ((flags & views::Event::EF_CONTROL_DOWN) == | 634 ((flags & views::Event::EF_CONTROL_DOWN) == |
740 views::Event::EF_CONTROL_DOWN), | 635 views::Event::EF_CONTROL_DOWN), |
741 ((flags & views::Event::EF_SHIFT_DOWN) == | 636 ((flags & views::Event::EF_SHIFT_DOWN) == |
742 views::Event::EF_SHIFT_DOWN), | 637 views::Event::EF_SHIFT_DOWN), |
743 ((flags & views::Event::EF_ALT_DOWN) == | 638 ((flags & views::Event::EF_ALT_DOWN) == |
744 views::Event::EF_ALT_DOWN), | 639 views::Event::EF_ALT_DOWN), |
745 ((flags & views::Event::EF_COMMAND_DOWN) == | 640 ((flags & views::Event::EF_COMMAND_DOWN) == |
746 views::Event::EF_COMMAND_DOWN)); | 641 views::Event::EF_COMMAND_DOWN)); |
747 } | 642 } |
748 | 643 |
749 void AutomationProvider::IsWindowActive(int handle, bool* success, | |
750 bool* is_active) { | |
751 if (window_tracker_->ContainsHandle(handle)) { | |
752 *is_active = | |
753 platform_util::IsWindowActive(window_tracker_->GetResource(handle)); | |
754 *success = true; | |
755 } else { | |
756 *success = false; | |
757 *is_active = false; | |
758 } | |
759 } | |
760 | |
761 void AutomationProvider::GetTabCount(int handle, int* tab_count) { | 644 void AutomationProvider::GetTabCount(int handle, int* tab_count) { |
762 *tab_count = -1; // -1 is the error code | 645 *tab_count = -1; // -1 is the error code |
763 | 646 |
764 if (browser_tracker_->ContainsHandle(handle)) { | 647 if (browser_tracker_->ContainsHandle(handle)) { |
765 Browser* browser = browser_tracker_->GetResource(handle); | 648 Browser* browser = browser_tracker_->GetResource(handle); |
766 *tab_count = browser->tab_count(); | 649 *tab_count = browser->tab_count(); |
767 } | 650 } |
768 } | 651 } |
769 | 652 |
770 void AutomationProvider::GetType(int handle, int* type_as_int) { | 653 void AutomationProvider::GetType(int handle, int* type_as_int) { |
(...skipping 3359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4130 } | 4013 } |
4131 | 4014 |
4132 void AutomationProvider::WaitForPopupMenuToOpen(IPC::Message* reply_message) { | 4015 void AutomationProvider::WaitForPopupMenuToOpen(IPC::Message* reply_message) { |
4133 NOTIMPLEMENTED(); | 4016 NOTIMPLEMENTED(); |
4134 } | 4017 } |
4135 #endif // !defined(TOOLKIT_VIEWS) | 4018 #endif // !defined(TOOLKIT_VIEWS) |
4136 | 4019 |
4137 void AutomationProvider::ResetToDefaultTheme() { | 4020 void AutomationProvider::ResetToDefaultTheme() { |
4138 profile_->ClearTheme(); | 4021 profile_->ClearTheme(); |
4139 } | 4022 } |
OLD | NEW |