OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/string_number_conversions.h" |
12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
13 #include "base/synchronization/waitable_event.h" | 13 #include "base/synchronization/waitable_event.h" |
14 #include "base/time.h" | 14 #include "base/time.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "chrome/browser/automation/automation_provider.h" | 16 #include "chrome/browser/automation/automation_provider.h" |
17 #include "chrome/browser/automation/automation_provider_json.h" | 17 #include "chrome/browser/automation/automation_provider_json.h" |
18 #include "chrome/browser/extensions/extension_host.h" | |
19 #include "chrome/browser/extensions/extension_process_manager.h" | 18 #include "chrome/browser/extensions/extension_process_manager.h" |
20 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
21 #include "chrome/browser/printing/print_preview_tab_controller.h" | 20 #include "chrome/browser/printing/print_preview_tab_controller.h" |
22 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/sessions/restore_tab_helper.h" | 22 #include "chrome/browser/sessions/restore_tab_helper.h" |
24 #include "chrome/browser/sessions/session_id.h" | 23 #include "chrome/browser/sessions/session_id.h" |
25 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h" | 24 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h" |
26 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
27 #include "chrome/browser/ui/browser_list.h" | 26 #include "chrome/browser/ui/browser_list.h" |
28 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 27 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
29 #include "chrome/common/automation_id.h" | 28 #include "chrome/common/automation_id.h" |
30 #include "chrome/common/chrome_view_type.h" | 29 #include "chrome/common/chrome_view_type.h" |
31 #include "chrome/common/extensions/extension.h" | 30 #include "chrome/common/extensions/extension.h" |
32 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
33 #include "content/public/browser/render_process_host.h" | 32 #include "content/public/browser/render_process_host.h" |
34 #include "content/public/browser/render_view_host.h" | 33 #include "content/public/browser/render_view_host.h" |
| 34 #include "content/public/browser/render_view_host_delegate.h" |
35 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
36 #include "net/cookies/cookie_monster.h" | 36 #include "net/cookies/cookie_monster.h" |
37 #include "net/cookies/cookie_store.h" | 37 #include "net/cookies/cookie_store.h" |
38 #include "net/url_request/url_request_context.h" | 38 #include "net/url_request/url_request_context.h" |
39 #include "net/url_request/url_request_context_getter.h" | 39 #include "net/url_request/url_request_context_getter.h" |
40 | 40 |
41 using content::BrowserThread; | 41 using content::BrowserThread; |
42 using content::RenderViewHost; | 42 using content::RenderViewHost; |
43 using content::WebContents; | 43 using content::WebContents; |
44 | 44 |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 } | 406 } |
407 return active; | 407 return active; |
408 } | 408 } |
409 | 409 |
410 AutomationId GetIdForTab(const TabContentsWrapper* tab) { | 410 AutomationId GetIdForTab(const TabContentsWrapper* tab) { |
411 return AutomationId( | 411 return AutomationId( |
412 AutomationId::kTypeTab, | 412 AutomationId::kTypeTab, |
413 base::IntToString(tab->restore_tab_helper()->session_id().id())); | 413 base::IntToString(tab->restore_tab_helper()->session_id().id())); |
414 } | 414 } |
415 | 415 |
416 AutomationId GetIdForExtensionView(const ExtensionHost* ext_host) { | 416 AutomationId GetIdForExtensionView( |
| 417 const content::RenderViewHost* render_view_host) { |
417 AutomationId::Type type; | 418 AutomationId::Type type; |
418 switch (ext_host->extension_host_type()) { | 419 switch (render_view_host->GetDelegate()->GetRenderViewType()) { |
419 case chrome::VIEW_TYPE_EXTENSION_POPUP: | 420 case chrome::VIEW_TYPE_EXTENSION_POPUP: |
420 type = AutomationId::kTypeExtensionPopup; | 421 type = AutomationId::kTypeExtensionPopup; |
421 break; | 422 break; |
422 case chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE: | 423 case chrome::VIEW_TYPE_EXTENSION_BACKGROUND_PAGE: |
423 type = AutomationId::kTypeExtensionBgPage; | 424 type = AutomationId::kTypeExtensionBgPage; |
424 break; | 425 break; |
425 case chrome::VIEW_TYPE_EXTENSION_INFOBAR: | 426 case chrome::VIEW_TYPE_EXTENSION_INFOBAR: |
426 type = AutomationId::kTypeExtensionInfobar; | 427 type = AutomationId::kTypeExtensionInfobar; |
427 break; | 428 break; |
428 default: | 429 default: |
429 type = AutomationId::kTypeInvalid; | 430 type = AutomationId::kTypeInvalid; |
430 break; | 431 break; |
431 } | 432 } |
432 // Since these extension views do not permit navigation, using the | 433 // Since these extension views do not permit navigation, using the |
433 // renderer process and view ID should suffice. | 434 // renderer process and view ID should suffice. |
434 std::string id = base::StringPrintf("%d|%d", | 435 std::string id = base::StringPrintf("%d|%d", |
435 ext_host->render_view_host()->GetRoutingID(), | 436 render_view_host->GetRoutingID(), |
436 ext_host->render_process_host()->GetID()); | 437 render_view_host->GetProcess()->GetID()); |
437 return AutomationId(type, id); | 438 return AutomationId(type, id); |
438 } | 439 } |
439 | 440 |
440 AutomationId GetIdForExtension(const Extension* extension) { | 441 AutomationId GetIdForExtension(const Extension* extension) { |
441 return AutomationId(AutomationId::kTypeExtension, extension->id()); | 442 return AutomationId(AutomationId::kTypeExtension, extension->id()); |
442 } | 443 } |
443 | 444 |
444 bool GetTabForId(const AutomationId& id, WebContents** tab) { | 445 bool GetTabForId(const AutomationId& id, WebContents** tab) { |
445 if (id.type() != AutomationId::kTypeTab) | 446 if (id.type() != AutomationId::kTypeTab) |
446 return false; | 447 return false; |
(...skipping 28 matching lines...) Expand all Loading... |
475 } | 476 } |
476 | 477 |
477 namespace { | 478 namespace { |
478 | 479 |
479 bool GetExtensionRenderViewForId( | 480 bool GetExtensionRenderViewForId( |
480 const AutomationId& id, | 481 const AutomationId& id, |
481 Profile* profile, | 482 Profile* profile, |
482 RenderViewHost** rvh) { | 483 RenderViewHost** rvh) { |
483 ExtensionProcessManager* extension_mgr = | 484 ExtensionProcessManager* extension_mgr = |
484 profile->GetExtensionProcessManager(); | 485 profile->GetExtensionProcessManager(); |
485 ExtensionProcessManager::const_iterator iter; | 486 const ExtensionProcessManager::ViewSet view_set = |
486 for (iter = extension_mgr->begin(); iter != extension_mgr->end(); | 487 extension_mgr->GetAllViews(); |
487 ++iter) { | 488 for (ExtensionProcessManager::ViewSet::const_iterator iter = view_set.begin(); |
488 ExtensionHost* host = *iter; | 489 iter != view_set.end(); ++iter) { |
| 490 content::RenderViewHost* host = *iter; |
489 AutomationId this_id = GetIdForExtensionView(host); | 491 AutomationId this_id = GetIdForExtensionView(host); |
490 if (id == this_id) { | 492 if (id == this_id) { |
491 *rvh = host->render_view_host(); | 493 *rvh = host; |
492 return true; | 494 return true; |
493 } | 495 } |
494 } | 496 } |
495 return false; | 497 return false; |
496 } | 498 } |
497 | 499 |
498 } // namespace | 500 } // namespace |
499 | 501 |
500 bool GetRenderViewForId( | 502 bool GetRenderViewForId( |
501 const AutomationId& id, | 503 const AutomationId& id, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 const Extension* extension; | 553 const Extension* extension; |
552 return GetExtensionForId(id, profile, &extension); | 554 return GetExtensionForId(id, profile, &extension); |
553 } | 555 } |
554 default: | 556 default: |
555 break; | 557 break; |
556 } | 558 } |
557 return false; | 559 return false; |
558 } | 560 } |
559 | 561 |
560 } // namespace automation_util | 562 } // namespace automation_util |
OLD | NEW |