OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/external_tab_container.h" | 5 #include "chrome/browser/external_tab_container.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
10 #include "app/win_util.h" | 10 #include "app/win_util.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/win_util.h" | 12 #include "base/win_util.h" |
13 #include "chrome/browser/automation/automation_provider.h" | 13 #include "chrome/browser/automation/automation_provider.h" |
| 14 #include "chrome/browser/automation/automation_extension_function.h" |
14 #include "chrome/browser/browser_window.h" | 15 #include "chrome/browser/browser_window.h" |
15 #include "chrome/browser/debugger/devtools_manager.h" | 16 #include "chrome/browser/debugger/devtools_manager.h" |
16 #include "chrome/browser/load_notification_details.h" | 17 #include "chrome/browser/load_notification_details.h" |
17 #include "chrome/browser/page_info_window.h" | 18 #include "chrome/browser/page_info_window.h" |
18 #include "chrome/browser/profile.h" | 19 #include "chrome/browser/profile.h" |
19 #include "chrome/browser/renderer_host/render_process_host.h" | 20 #include "chrome/browser/renderer_host/render_process_host.h" |
20 #include "chrome/browser/tab_contents/provisional_load_details.h" | 21 #include "chrome/browser/tab_contents/provisional_load_details.h" |
21 #include "chrome/browser/views/tab_contents/render_view_context_menu_external_wi
n.h" | 22 #include "chrome/browser/views/tab_contents/render_view_context_menu_external_wi
n.h" |
22 #include "chrome/browser/tab_contents/tab_contents.h" | 23 #include "chrome/browser/tab_contents/tab_contents.h" |
23 #include "chrome/browser/views/tab_contents/tab_contents_container.h" | 24 #include "chrome/browser/views/tab_contents/tab_contents_container.h" |
(...skipping 11 matching lines...) Expand all Loading... |
35 ExternalTabContainer::ExternalTabContainer( | 36 ExternalTabContainer::ExternalTabContainer( |
36 AutomationProvider* automation, AutomationResourceMessageFilter* filter) | 37 AutomationProvider* automation, AutomationResourceMessageFilter* filter) |
37 : automation_(automation), | 38 : automation_(automation), |
38 tab_contents_(NULL), | 39 tab_contents_(NULL), |
39 tab_contents_container_(NULL), | 40 tab_contents_container_(NULL), |
40 tab_handle_(0), | 41 tab_handle_(0), |
41 ignore_next_load_notification_(false), | 42 ignore_next_load_notification_(false), |
42 automation_resource_message_filter_(filter), | 43 automation_resource_message_filter_(filter), |
43 load_requests_via_automation_(false), | 44 load_requests_via_automation_(false), |
44 handle_top_level_requests_(false), | 45 handle_top_level_requests_(false), |
45 external_method_factory_(this) { | 46 external_method_factory_(this), |
| 47 enabled_extension_automation_(false) { |
46 } | 48 } |
47 | 49 |
48 ExternalTabContainer::~ExternalTabContainer() { | 50 ExternalTabContainer::~ExternalTabContainer() { |
49 Uninitialize(); | 51 Uninitialize(); |
50 } | 52 } |
51 | 53 |
52 bool ExternalTabContainer::Init(Profile* profile, | 54 bool ExternalTabContainer::Init(Profile* profile, |
53 HWND parent, | 55 HWND parent, |
54 const gfx::Rect& bounds, | 56 const gfx::Rect& bounds, |
55 DWORD style, | 57 DWORD style, |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 SetParent(GetNativeView(), parent); | 155 SetParent(GetNativeView(), parent); |
154 | 156 |
155 ::ShowWindow(tab_contents_->GetNativeView(), SW_SHOWNA); | 157 ::ShowWindow(tab_contents_->GetNativeView(), SW_SHOWNA); |
156 | 158 |
157 disabled_context_menu_ids_.push_back( | 159 disabled_context_menu_ids_.push_back( |
158 IDS_CONTENT_CONTEXT_OPENLINKOFFTHERECORD); | 160 IDS_CONTENT_CONTEXT_OPENLINKOFFTHERECORD); |
159 return true; | 161 return true; |
160 } | 162 } |
161 | 163 |
162 void ExternalTabContainer::Uninitialize() { | 164 void ExternalTabContainer::Uninitialize() { |
| 165 if (enabled_extension_automation_) { |
| 166 AutomationExtensionFunction::Disable(); |
| 167 } |
| 168 |
163 registrar_.RemoveAll(); | 169 registrar_.RemoveAll(); |
164 if (tab_contents_) { | 170 if (tab_contents_) { |
165 RenderViewHost* rvh = tab_contents_->render_view_host(); | 171 RenderViewHost* rvh = tab_contents_->render_view_host(); |
166 if (rvh && DevToolsManager::GetInstance()) { | 172 if (rvh && DevToolsManager::GetInstance()) { |
167 DevToolsManager::GetInstance()->UnregisterDevToolsClientHostFor(rvh); | 173 DevToolsManager::GetInstance()->UnregisterDevToolsClientHostFor(rvh); |
168 } | 174 } |
169 | 175 |
170 NotificationService::current()->Notify( | 176 NotificationService::current()->Notify( |
171 NotificationType::EXTERNAL_TAB_CLOSED, | 177 NotificationType::EXTERNAL_TAB_CLOSED, |
172 Source<NavigationController>(&tab_contents_->controller()), | 178 Source<NavigationController>(&tab_contents_->controller()), |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 scoped_refptr<ExternalTabContainer> container = (*index).second; | 641 scoped_refptr<ExternalTabContainer> container = (*index).second; |
636 pending_tabs_.erase(index); | 642 pending_tabs_.erase(index); |
637 return container.release(); | 643 return container.release(); |
638 } | 644 } |
639 | 645 |
640 NOTREACHED() << "Failed to find ExternalTabContainer for cookie: " | 646 NOTREACHED() << "Failed to find ExternalTabContainer for cookie: " |
641 << cookie; | 647 << cookie; |
642 return NULL; | 648 return NULL; |
643 } | 649 } |
644 | 650 |
| 651 void ExternalTabContainer::SetEnableExtensionAutomation( |
| 652 const std::vector<std::string>& functions_enabled) { |
| 653 if (functions_enabled.size() > 0) { |
| 654 if (!tab_contents_) { |
| 655 NOTREACHED() << "Being invoked via tab so should have TabContents"; |
| 656 return; |
| 657 } |
| 658 |
| 659 AutomationExtensionFunction::Enable(tab_contents_, functions_enabled); |
| 660 enabled_extension_automation_ = true; |
| 661 } else { |
| 662 AutomationExtensionFunction::Disable(); |
| 663 enabled_extension_automation_ = false; |
| 664 } |
| 665 } |
| 666 |
645 void ExternalTabContainer::Navigate(const GURL& url, const GURL& referrer) { | 667 void ExternalTabContainer::Navigate(const GURL& url, const GURL& referrer) { |
646 if (!tab_contents_) { | 668 if (!tab_contents_) { |
647 NOTREACHED(); | 669 NOTREACHED(); |
648 return; | 670 return; |
649 } | 671 } |
650 | 672 |
651 tab_contents_->controller().LoadURL(url, referrer, | 673 tab_contents_->controller().LoadURL(url, referrer, |
652 PageTransition::START_PAGE); | 674 PageTransition::START_PAGE); |
653 } | 675 } |
654 | 676 |
655 bool ExternalTabContainer::OnGoToEntryOffset(int offset) { | 677 bool ExternalTabContainer::OnGoToEntryOffset(int offset) { |
656 if (load_requests_via_automation_) { | 678 if (load_requests_via_automation_) { |
657 automation_->Send(new AutomationMsg_RequestGoToHistoryEntryOffset( | 679 automation_->Send(new AutomationMsg_RequestGoToHistoryEntryOffset( |
658 0, tab_handle_, offset)); | 680 0, tab_handle_, offset)); |
659 return false; | 681 return false; |
660 } | 682 } |
661 | 683 |
662 return true; | 684 return true; |
663 } | 685 } |
OLD | NEW |