Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1119)

Side by Side Diff: chrome/browser/automation/automation_util.cc

Issue 8649004: Allow chromedriver to install an extension and get all installed extension IDs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ... Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/automation_util.h" 5 #include "chrome/browser/automation/automation_util.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/string_number_conversions.h"
11 #include "base/synchronization/waitable_event.h" 12 #include "base/synchronization/waitable_event.h"
12 #include "base/time.h" 13 #include "base/time.h"
13 #include "base/values.h" 14 #include "base/values.h"
14 #include "chrome/browser/automation/automation_provider.h" 15 #include "chrome/browser/automation/automation_provider.h"
15 #include "chrome/browser/automation/automation_provider_json.h" 16 #include "chrome/browser/automation/automation_provider_json.h"
17 #include "chrome/browser/extensions/extension_host.h"
18 #include "chrome/browser/extensions/extension_process_manager.h"
16 #include "chrome/browser/extensions/extension_service.h" 19 #include "chrome/browser/extensions/extension_service.h"
17 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
21 #include "chrome/browser/sessions/restore_tab_helper.h"
22 #include "chrome/browser/sessions/session_id.h"
18 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h" 23 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h"
19 #include "chrome/browser/ui/browser.h" 24 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/browser_list.h" 25 #include "chrome/browser/ui/browser_list.h"
26 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
27 #include "chrome/common/chrome_view_types.h"
28 #include "chrome/common/extensions/extension.h"
21 #include "content/browser/renderer_host/render_view_host.h" 29 #include "content/browser/renderer_host/render_view_host.h"
22 #include "content/browser/tab_contents/tab_contents.h" 30 #include "content/browser/tab_contents/tab_contents.h"
23 #include "content/public/browser/browser_thread.h" 31 #include "content/public/browser/browser_thread.h"
24 #include "net/base/cookie_monster.h" 32 #include "net/base/cookie_monster.h"
25 #include "net/base/cookie_store.h" 33 #include "net/base/cookie_store.h"
26 #include "net/url_request/url_request_context.h" 34 #include "net/url_request/url_request_context.h"
27 #include "net/url_request/url_request_context_getter.h" 35 #include "net/url_request/url_request_context_getter.h"
28 36
29 using content::BrowserThread; 37 using content::BrowserThread;
30 38
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 } // namespace 127 } // namespace
120 128
121 namespace automation_util { 129 namespace automation_util {
122 130
123 Browser* GetBrowserAt(int index) { 131 Browser* GetBrowserAt(int index) {
124 if (index < 0 || index >= static_cast<int>(BrowserList::size())) 132 if (index < 0 || index >= static_cast<int>(BrowserList::size()))
125 return NULL; 133 return NULL;
126 return *(BrowserList::begin() + index); 134 return *(BrowserList::begin() + index);
127 } 135 }
128 136
137 bool GetBrowserIndex(Browser* browser, int* found_index) {
138 BrowserList::const_iterator iter = BrowserList::begin();
139 int browser_index = 0;
140 for (; iter != BrowserList::end(); ++iter, ++browser_index) {
141 if (*iter == browser) {
142 *found_index = browser_index;
143 return true;
144 }
145 }
146 return false;
147 }
148
129 TabContents* GetTabContentsAt(int browser_index, int tab_index) { 149 TabContents* GetTabContentsAt(int browser_index, int tab_index) {
130 if (tab_index < 0) 150 if (tab_index < 0)
131 return NULL; 151 return NULL;
132 Browser* browser = GetBrowserAt(browser_index); 152 Browser* browser = GetBrowserAt(browser_index);
133 if (!browser || tab_index >= browser->tab_count()) 153 if (!browser || tab_index >= browser->tab_count())
134 return NULL; 154 return NULL;
135 return browser->GetTabContentsAt(tab_index); 155 return browser->GetTabContentsAt(tab_index);
136 } 156 }
137 157
138 net::URLRequestContextGetter* GetRequestContext(TabContents* contents) { 158 net::URLRequestContextGetter* GetRequestContext(TabContents* contents) {
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 bool SendErrorIfModalDialogActive(AutomationProvider* provider, 394 bool SendErrorIfModalDialogActive(AutomationProvider* provider,
375 IPC::Message* message) { 395 IPC::Message* message) {
376 bool active = AppModalDialogQueue::GetInstance()->HasActiveDialog(); 396 bool active = AppModalDialogQueue::GetInstance()->HasActiveDialog();
377 if (active) { 397 if (active) {
378 AutomationJSONReply(provider, message).SendError( 398 AutomationJSONReply(provider, message).SendError(
379 "Command cannot be performed because a modal dialog is active"); 399 "Command cannot be performed because a modal dialog is active");
380 } 400 }
381 return active; 401 return active;
382 } 402 }
383 403
404 AutomationId GetIdForTab(const TabContentsWrapper* tab) {
405 return AutomationId(
406 AutomationId::kTypeTab,
407 base::IntToString(tab->restore_tab_helper()->session_id().id()));
408 }
409
410 AutomationId GetIdForExtensionPopup(const Extension* extension) {
411 return AutomationId(
412 AutomationId::kTypeExtensionPopup, extension->id());
413 }
414
415 bool GetTabForId(const AutomationId& id, TabContents** tab) {
416 if (id.type() != AutomationId::kTypeTab)
417 return false;
418
419 BrowserList::const_iterator iter = BrowserList::begin();
420 for (; iter != BrowserList::end(); ++iter) {
421 Browser* browser = *iter;
422 for (int tab_index = 0; tab_index < browser->tab_count(); ++tab_index) {
423 TabContentsWrapper* wrapper = browser->GetTabContentsWrapperAt(tab_index);
424 if (base::IntToString(wrapper->restore_tab_helper()->session_id().id()) ==
425 id.id()) {
426 *tab = wrapper->tab_contents();
427 return true;
428 }
429 }
430 }
431 return false;
432 }
433
434 bool GetExtensionPopupForId(const AutomationId& id, Profile* profile, RenderView Host** rvh) {
435 if (id.type() != AutomationId::kTypeExtensionPopup)
436 return false;
437
438 ExtensionProcessManager* extension_mgr =
439 profile->GetExtensionProcessManager();
440 ExtensionProcessManager::const_iterator iter;
441 for (iter = extension_mgr->begin(); iter != extension_mgr->end();
442 ++iter) {
443 ExtensionHost* host = *iter;
444 if (host->extension()->id() == id.id() &&
445 host->extension_host_type() ==
446 chrome::VIEW_TYPE_EXTENSION_POPUP) {
447 *rvh = host->render_view_host();
448 return true;
449 }
450 }
451 return false;
452 }
453
454 bool GetRenderViewForId(
455 const AutomationId& id,
456 Profile* profile,
457 RenderViewHost** rvh) {
458 switch (id.type()) {
459 case AutomationId::kTypeTab: {
460 TabContents* tab;
461 if (!GetTabForId(id, &tab))
462 return false;
463 *rvh = tab->render_view_host();
464 break;
465 }
466 case AutomationId::kTypeExtensionPopup:
467 if (!GetExtensionPopupForId(id, profile, rvh))
468 return false;
469 break;
470 default:
471 return false;
472 }
473 return true;
474 }
475
476 bool DoesObjectWithIdExist(const AutomationId& id, Profile* profile) {
477 switch(id.type()) {
478 case AutomationId::kTypeTab: {
479 TabContents* tab;
480 return GetTabForId(id, &tab);
481 }
482 case AutomationId::kTypeExtensionPopup: {
483 RenderViewHost* rvh;
484 return GetExtensionPopupForId(id, profile, &rvh);
485 }
486 default:
487 break;
488 }
489 return false;
490 }
491
384 } // namespace automation_util 492 } // namespace automation_util
OLDNEW
« no previous file with comments | « chrome/browser/automation/automation_util.h ('k') | chrome/browser/automation/testing_automation_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698