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_process_manager.h" | 18 #include "chrome/browser/extensions/extension_process_manager.h" |
19 #include "chrome/browser/extensions/extension_service.h" | 19 #include "chrome/browser/extensions/extension_service.h" |
20 #include "chrome/browser/printing/print_preview_tab_controller.h" | 20 #include "chrome/browser/printing/print_preview_tab_controller.h" |
21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
22 #include "chrome/browser/sessions/restore_tab_helper.h" | 22 #include "chrome/browser/sessions/restore_tab_helper.h" |
23 #include "chrome/browser/sessions/session_id.h" | 23 #include "chrome/browser/sessions/session_id.h" |
24 #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" |
25 #include "chrome/browser/ui/browser.h" | 25 #include "chrome/browser/ui/browser.h" |
26 #include "chrome/browser/ui/browser_list.h" | 26 #include "chrome/browser/ui/browser_list.h" |
| 27 #include "chrome/browser/ui/browser_tabstrip.h" |
27 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 28 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
28 #include "chrome/browser/view_type_utils.h" | 29 #include "chrome/browser/view_type_utils.h" |
29 #include "chrome/common/automation_id.h" | 30 #include "chrome/common/automation_id.h" |
30 #include "chrome/common/extensions/extension.h" | 31 #include "chrome/common/extensions/extension.h" |
31 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
32 #include "content/public/browser/render_process_host.h" | 33 #include "content/public/browser/render_process_host.h" |
33 #include "content/public/browser/render_view_host.h" | 34 #include "content/public/browser/render_view_host.h" |
34 #include "content/public/browser/web_contents.h" | 35 #include "content/public/browser/web_contents.h" |
35 #include "net/cookies/cookie_monster.h" | 36 #include "net/cookies/cookie_monster.h" |
36 #include "net/cookies/cookie_store.h" | 37 #include "net/cookies/cookie_store.h" |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 return NULL; | 139 return NULL; |
139 return *(BrowserList::begin() + index); | 140 return *(BrowserList::begin() + index); |
140 } | 141 } |
141 | 142 |
142 WebContents* GetWebContentsAt(int browser_index, int tab_index) { | 143 WebContents* GetWebContentsAt(int browser_index, int tab_index) { |
143 if (tab_index < 0) | 144 if (tab_index < 0) |
144 return NULL; | 145 return NULL; |
145 Browser* browser = GetBrowserAt(browser_index); | 146 Browser* browser = GetBrowserAt(browser_index); |
146 if (!browser || tab_index >= browser->tab_count()) | 147 if (!browser || tab_index >= browser->tab_count()) |
147 return NULL; | 148 return NULL; |
148 return browser->GetWebContentsAt(tab_index); | 149 return chrome::GetWebContentsAt(browser, tab_index); |
149 } | 150 } |
150 | 151 |
151 Browser* GetBrowserForTab(WebContents* tab) { | 152 Browser* GetBrowserForTab(WebContents* tab) { |
152 BrowserList::const_iterator browser_iter = BrowserList::begin(); | 153 BrowserList::const_iterator browser_iter = BrowserList::begin(); |
153 for (; browser_iter != BrowserList::end(); ++browser_iter) { | 154 for (; browser_iter != BrowserList::end(); ++browser_iter) { |
154 Browser* browser = *browser_iter; | 155 Browser* browser = *browser_iter; |
155 for (int tab_index = 0; tab_index < browser->tab_count(); ++tab_index) { | 156 for (int tab_index = 0; tab_index < browser->tab_count(); ++tab_index) { |
156 if (browser->GetWebContentsAt(tab_index) == tab) | 157 if (chrome::GetWebContentsAt(browser, tab_index) == tab) |
157 return browser; | 158 return browser; |
158 } | 159 } |
159 } | 160 } |
160 return NULL; | 161 return NULL; |
161 } | 162 } |
162 | 163 |
163 net::URLRequestContextGetter* GetRequestContext(WebContents* contents) { | 164 net::URLRequestContextGetter* GetRequestContext(WebContents* contents) { |
164 // Since we may be on the UI thread don't call GetURLRequestContext(). | 165 // Since we may be on the UI thread don't call GetURLRequestContext(). |
165 // Get the request context specific to the current WebContents and app. | 166 // Get the request context specific to the current WebContents and app. |
166 return contents->GetBrowserContext()->GetRequestContextForRenderProcess( | 167 return contents->GetBrowserContext()->GetRequestContextForRenderProcess( |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 bool GetTabForId(const AutomationId& id, WebContents** tab) { | 446 bool GetTabForId(const AutomationId& id, WebContents** tab) { |
446 if (id.type() != AutomationId::kTypeTab) | 447 if (id.type() != AutomationId::kTypeTab) |
447 return false; | 448 return false; |
448 | 449 |
449 printing::PrintPreviewTabController* preview_controller = | 450 printing::PrintPreviewTabController* preview_controller = |
450 printing::PrintPreviewTabController::GetInstance(); | 451 printing::PrintPreviewTabController::GetInstance(); |
451 BrowserList::const_iterator iter = BrowserList::begin(); | 452 BrowserList::const_iterator iter = BrowserList::begin(); |
452 for (; iter != BrowserList::end(); ++iter) { | 453 for (; iter != BrowserList::end(); ++iter) { |
453 Browser* browser = *iter; | 454 Browser* browser = *iter; |
454 for (int tab_index = 0; tab_index < browser->tab_count(); ++tab_index) { | 455 for (int tab_index = 0; tab_index < browser->tab_count(); ++tab_index) { |
455 TabContents* tab_contents = browser->GetTabContentsAt(tab_index); | 456 TabContents* tab_contents = chrome::GetTabContentsAt(browser, tab_index); |
456 if (base::IntToString( | 457 if (base::IntToString( |
457 tab_contents->restore_tab_helper()->session_id().id()) == | 458 tab_contents->restore_tab_helper()->session_id().id()) == |
458 id.id()) { | 459 id.id()) { |
459 *tab = tab_contents->web_contents(); | 460 *tab = tab_contents->web_contents(); |
460 return true; | 461 return true; |
461 } | 462 } |
462 if (preview_controller) { | 463 if (preview_controller) { |
463 TabContents* preview_tab_contents = | 464 TabContents* preview_tab_contents = |
464 preview_controller->GetPrintPreviewForTab(tab_contents); | 465 preview_controller->GetPrintPreviewForTab(tab_contents); |
465 if (preview_tab_contents) { | 466 if (preview_tab_contents) { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 const extensions::Extension* extension; | 555 const extensions::Extension* extension; |
555 return GetExtensionForId(id, profile, &extension); | 556 return GetExtensionForId(id, profile, &extension); |
556 } | 557 } |
557 default: | 558 default: |
558 break; | 559 break; |
559 } | 560 } |
560 return false; | 561 return false; |
561 } | 562 } |
562 | 563 |
563 } // namespace automation_util | 564 } // namespace automation_util |
OLD | NEW |