| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "app/message_box_flags.h" | 10 #include "app/message_box_flags.h" |
| (...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 if (browser->command_updater()->SupportsCommand(command) && | 754 if (browser->command_updater()->SupportsCommand(command) && |
| 755 browser->command_updater()->IsCommandEnabled(command)) { | 755 browser->command_updater()->IsCommandEnabled(command)) { |
| 756 browser->ExecuteCommand(command); | 756 browser->ExecuteCommand(command); |
| 757 *success = true; | 757 *success = true; |
| 758 } | 758 } |
| 759 } | 759 } |
| 760 } | 760 } |
| 761 | 761 |
| 762 void AutomationProvider::ExecuteBrowserCommand( | 762 void AutomationProvider::ExecuteBrowserCommand( |
| 763 int handle, int command, IPC::Message* reply_message) { | 763 int handle, int command, IPC::Message* reply_message) { |
| 764 // List of commands which just finish synchronously and don't require |
| 765 // setting up an observer. |
| 766 static const int kSynchronousCommands[] = { |
| 767 IDC_HOME, |
| 768 IDC_SELECT_NEXT_TAB, |
| 769 IDC_SELECT_PREVIOUS_TAB, |
| 770 IDC_SHOW_DOWNLOADS, |
| 771 IDC_SHOW_HISTORY, |
| 772 }; |
| 764 if (browser_tracker_->ContainsHandle(handle)) { | 773 if (browser_tracker_->ContainsHandle(handle)) { |
| 765 Browser* browser = browser_tracker_->GetResource(handle); | 774 Browser* browser = browser_tracker_->GetResource(handle); |
| 766 if (browser->command_updater()->SupportsCommand(command) && | 775 if (browser->command_updater()->SupportsCommand(command) && |
| 767 browser->command_updater()->IsCommandEnabled(command)) { | 776 browser->command_updater()->IsCommandEnabled(command)) { |
| 777 // First check if we can handle the command without using an observer. |
| 778 for (size_t i = 0; i < arraysize(kSynchronousCommands); i++) { |
| 779 if (command == kSynchronousCommands[i]) { |
| 780 browser->ExecuteCommand(command); |
| 781 AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message, |
| 782 true); |
| 783 Send(reply_message); |
| 784 return; |
| 785 } |
| 786 } |
| 787 |
| 788 // Use an observer if we have one, otherwise fail. |
| 768 if (ExecuteBrowserCommandObserver::CreateAndRegisterObserver( | 789 if (ExecuteBrowserCommandObserver::CreateAndRegisterObserver( |
| 769 this, browser, command, reply_message)) { | 790 this, browser, command, reply_message)) { |
| 770 browser->ExecuteCommand(command); | 791 browser->ExecuteCommand(command); |
| 771 return; | 792 return; |
| 772 } | 793 } |
| 773 } | 794 } |
| 774 } | 795 } |
| 775 AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message, false); | 796 AutomationMsg_WindowExecuteCommand::WriteReplyParams(reply_message, false); |
| 776 Send(reply_message); | 797 Send(reply_message); |
| 777 } | 798 } |
| (...skipping 1285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2063 for (;iter != BrowserList::end(); ++iter) { | 2084 for (;iter != BrowserList::end(); ++iter) { |
| 2064 gfx::NativeWindow this_window = (*iter)->window()->GetNativeHandle(); | 2085 gfx::NativeWindow this_window = (*iter)->window()->GetNativeHandle(); |
| 2065 if (window == this_window) { | 2086 if (window == this_window) { |
| 2066 // Add() returns the existing handle for the resource if any. | 2087 // Add() returns the existing handle for the resource if any. |
| 2067 *browser_handle = browser_tracker_->Add(*iter); | 2088 *browser_handle = browser_tracker_->Add(*iter); |
| 2068 *success = true; | 2089 *success = true; |
| 2069 return; | 2090 return; |
| 2070 } | 2091 } |
| 2071 } | 2092 } |
| 2072 } | 2093 } |
| OLD | NEW |