| Index: chrome/browser/automation/automation_util.cc
|
| diff --git a/chrome/browser/automation/automation_util.cc b/chrome/browser/automation/automation_util.cc
|
| index 079b9404279e2da11cdef0d85927e2f79b6e7210..51d5366e184c909d70198dd57b199a01da1caf07 100644
|
| --- a/chrome/browser/automation/automation_util.cc
|
| +++ b/chrome/browser/automation/automation_util.cc
|
| @@ -8,16 +8,24 @@
|
|
|
| #include "base/bind.h"
|
| #include "base/memory/scoped_ptr.h"
|
| +#include "base/string_number_conversions.h"
|
| #include "base/synchronization/waitable_event.h"
|
| #include "base/time.h"
|
| #include "base/values.h"
|
| #include "chrome/browser/automation/automation_provider.h"
|
| #include "chrome/browser/automation/automation_provider_json.h"
|
| +#include "chrome/browser/extensions/extension_host.h"
|
| +#include "chrome/browser/extensions/extension_process_manager.h"
|
| #include "chrome/browser/extensions/extension_service.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| +#include "chrome/browser/sessions/restore_tab_helper.h"
|
| +#include "chrome/browser/sessions/session_id.h"
|
| #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h"
|
| #include "chrome/browser/ui/browser.h"
|
| #include "chrome/browser/ui/browser_list.h"
|
| +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
|
| +#include "chrome/common/chrome_view_types.h"
|
| +#include "chrome/common/extensions/extension.h"
|
| #include "content/browser/renderer_host/render_view_host.h"
|
| #include "content/browser/tab_contents/tab_contents.h"
|
| #include "content/public/browser/browser_thread.h"
|
| @@ -126,6 +134,18 @@ Browser* GetBrowserAt(int index) {
|
| return *(BrowserList::begin() + index);
|
| }
|
|
|
| +bool GetBrowserIndex(Browser* browser, int* found_index) {
|
| + BrowserList::const_iterator iter = BrowserList::begin();
|
| + int browser_index = 0;
|
| + for (; iter != BrowserList::end(); ++iter, ++browser_index) {
|
| + if (*iter == browser) {
|
| + *found_index = browser_index;
|
| + return true;
|
| + }
|
| + }
|
| + return false;
|
| +}
|
| +
|
| TabContents* GetTabContentsAt(int browser_index, int tab_index) {
|
| if (tab_index < 0)
|
| return NULL;
|
| @@ -381,4 +401,92 @@ bool SendErrorIfModalDialogActive(AutomationProvider* provider,
|
| return active;
|
| }
|
|
|
| +AutomationId GetIdForTab(const TabContentsWrapper* tab) {
|
| + return AutomationId(
|
| + AutomationId::kTypeTab,
|
| + base::IntToString(tab->restore_tab_helper()->session_id().id()));
|
| +}
|
| +
|
| +AutomationId GetIdForExtensionPopup(const Extension* extension) {
|
| + return AutomationId(
|
| + AutomationId::kTypeExtensionPopup, extension->id());
|
| +}
|
| +
|
| +bool GetTabForId(const AutomationId& id, TabContents** tab) {
|
| + if (id.type() != AutomationId::kTypeTab)
|
| + return false;
|
| +
|
| + BrowserList::const_iterator iter = BrowserList::begin();
|
| + for (; iter != BrowserList::end(); ++iter) {
|
| + Browser* browser = *iter;
|
| + for (int tab_index = 0; tab_index < browser->tab_count(); ++tab_index) {
|
| + TabContentsWrapper* wrapper = browser->GetTabContentsWrapperAt(tab_index);
|
| + if (base::IntToString(wrapper->restore_tab_helper()->session_id().id()) ==
|
| + id.id()) {
|
| + *tab = wrapper->tab_contents();
|
| + return true;
|
| + }
|
| + }
|
| + }
|
| + return false;
|
| +}
|
| +
|
| +bool GetExtensionPopupForId(const AutomationId& id, Profile* profile, RenderViewHost** rvh) {
|
| + if (id.type() != AutomationId::kTypeExtensionPopup)
|
| + return false;
|
| +
|
| + ExtensionProcessManager* extension_mgr =
|
| + profile->GetExtensionProcessManager();
|
| + ExtensionProcessManager::const_iterator iter;
|
| + for (iter = extension_mgr->begin(); iter != extension_mgr->end();
|
| + ++iter) {
|
| + ExtensionHost* host = *iter;
|
| + if (host->extension()->id() == id.id() &&
|
| + host->extension_host_type() ==
|
| + chrome::VIEW_TYPE_EXTENSION_POPUP) {
|
| + *rvh = host->render_view_host();
|
| + return true;
|
| + }
|
| + }
|
| + return false;
|
| +}
|
| +
|
| +bool GetRenderViewForId(
|
| + const AutomationId& id,
|
| + Profile* profile,
|
| + RenderViewHost** rvh) {
|
| + switch (id.type()) {
|
| + case AutomationId::kTypeTab: {
|
| + TabContents* tab;
|
| + if (!GetTabForId(id, &tab))
|
| + return false;
|
| + *rvh = tab->render_view_host();
|
| + break;
|
| + }
|
| + case AutomationId::kTypeExtensionPopup:
|
| + if (!GetExtensionPopupForId(id, profile, rvh))
|
| + return false;
|
| + break;
|
| + default:
|
| + return false;
|
| + }
|
| + return true;
|
| +}
|
| +
|
| +bool DoesObjectWithIdExist(const AutomationId& id, Profile* profile) {
|
| + switch(id.type()) {
|
| + case AutomationId::kTypeTab: {
|
| + TabContents* tab;
|
| + return GetTabForId(id, &tab);
|
| + }
|
| + case AutomationId::kTypeExtensionPopup: {
|
| + RenderViewHost* rvh;
|
| + return GetExtensionPopupForId(id, profile, &rvh);
|
| + }
|
| + default:
|
| + break;
|
| + }
|
| + return false;
|
| +}
|
| +
|
| } // namespace automation_util
|
|
|