[email protected] | 9e790bd | 2011-01-10 23:48:54 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 4bdde60 | 2010-06-16 03:17:35 | [diff] [blame] | 5 | #include "chrome/browser/external_tab_container_win.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
[email protected] | 4c540ee | 2009-07-07 17:15:55 | [diff] [blame] | 7 | #include <string> |
| 8 | |
[email protected] | 5858035 | 2010-10-26 04:07:50 | [diff] [blame] | 9 | #include "base/debug/trace_event.h" |
[email protected] | 7cf1b6ce | 2010-03-20 06:37:01 | [diff] [blame] | 10 | #include "base/i18n/rtl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 11 | #include "base/logging.h" |
[email protected] | 1f1e7cb | 2011-10-07 22:55:47 | [diff] [blame] | 12 | #include "base/memory/scoped_ptr.h" |
[email protected] | 944b421 | 2010-12-14 00:00:33 | [diff] [blame] | 13 | #include "base/utf_string_conversions.h" |
[email protected] | a8e2058 | 2010-12-31 17:18:50 | [diff] [blame] | 14 | #include "base/win/win_util.h" |
[email protected] | 1a3aba8 | 2010-11-08 23:52:54 | [diff] [blame] | 15 | #include "chrome/app/chrome_command_ids.h" |
[email protected] | 0f8df867 | 2010-11-09 00:36:32 | [diff] [blame] | 16 | #include "chrome/app/chrome_dll_resource.h" |
[email protected] | b3841c50 | 2011-03-09 01:21:31 | [diff] [blame] | 17 | #include "chrome/browser/automation/automation_provider.h" |
[email protected] | dce50276 | 2011-07-20 08:53:49 | [diff] [blame] | 18 | #include "chrome/browser/debugger/devtools_toggle_action.h" |
| 19 | #include "chrome/browser/debugger/devtools_window.h" |
[email protected] | 91a7923 | 2010-11-10 18:15:08 | [diff] [blame] | 20 | #include "chrome/browser/google/google_util.h" |
[email protected] | ec0b6c4 | 2010-08-26 03:16:58 | [diff] [blame] | 21 | #include "chrome/browser/history/history_types.h" |
[email protected] | 105bb0f | 2011-05-24 17:12:14 | [diff] [blame] | 22 | #include "chrome/browser/history/history_tab_helper.h" |
[email protected] | 7e20412 | 2011-09-01 18:56:21 | [diff] [blame] | 23 | #include "chrome/browser/infobars/infobar_tab_helper.h" |
[email protected] | 8ecad5e | 2010-12-02 21:18:33 | [diff] [blame] | 24 | #include "chrome/browser/profiles/profile.h" |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 25 | #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h" |
[email protected] | 7fbd1e9 | 2011-06-02 19:33:00 | [diff] [blame] | 26 | #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h" |
[email protected] | a8c229cc | 2011-01-13 22:31:58 | [diff] [blame] | 27 | #include "chrome/browser/ui/browser.h" |
[email protected] | 00070c73 | 2011-04-09 15:31:33 | [diff] [blame] | 28 | #include "chrome/browser/ui/browser_window.h" |
[email protected] | 7b8d4a2 | 2011-02-10 20:57:54 | [diff] [blame] | 29 | #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
[email protected] | 9e790bd | 2011-01-10 23:48:54 | [diff] [blame] | 30 | #include "chrome/browser/ui/views/browser_dialogs.h" |
[email protected] | 6c6614f1 | 2011-03-31 18:51:42 | [diff] [blame] | 31 | #include "chrome/browser/ui/views/infobars/infobar_container_view.h" |
[email protected] | 9e790bd | 2011-01-10 23:48:54 | [diff] [blame] | 32 | #include "chrome/browser/ui/views/page_info_bubble_view.h" |
| 33 | #include "chrome/browser/ui/views/tab_contents/render_view_context_menu_views.h" |
| 34 | #include "chrome/browser/ui/views/tab_contents/tab_contents_container.h" |
[email protected] | a8ba636 | 2010-11-10 20:02:25 | [diff] [blame] | 35 | #include "chrome/common/automation_messages.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 36 | #include "chrome/common/chrome_constants.h" |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 37 | #include "chrome/common/chrome_notification_types.h" |
[email protected] | 15b2c6a | 2011-05-16 23:54:40 | [diff] [blame] | 38 | #include "chrome/common/render_messages.h" |
[email protected] | 91a7923 | 2010-11-10 18:15:08 | [diff] [blame] | 39 | #include "chrome/common/url_constants.h" |
[email protected] | 35e251d | 2011-05-24 21:01:04 | [diff] [blame] | 40 | #include "content/browser/load_notification_details.h" |
[email protected] | 5de63471 | 2011-03-02 00:20:19 | [diff] [blame] | 41 | #include "content/browser/renderer_host/render_view_host.h" |
| 42 | #include "content/browser/renderer_host/resource_dispatcher_host_request_info.h" |
[email protected] | 8286f51a | 2011-05-31 17:39:13 | [diff] [blame] | 43 | #include "content/browser/tab_contents/navigation_details.h" |
[email protected] | 299425b | 2011-03-02 07:45:20 | [diff] [blame] | 44 | #include "content/browser/tab_contents/provisional_load_details.h" |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 45 | #include "content/public/browser/notification_service.h" |
[email protected] | 0aed2f5 | 2011-03-23 18:06:36 | [diff] [blame] | 46 | #include "content/common/view_messages.h" |
[email protected] | 8bc38d2 | 2011-10-14 20:39:20 | [diff] [blame] | 47 | #include "content/public/browser/native_web_keyboard_event.h" |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 48 | #include "content/public/common/bindings_policy.h" |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 49 | #include "content/public/common/page_transition_types.h" |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 50 | #include "content/public/common/page_zoom.h" |
[email protected] | e943d666 | 2009-06-12 03:50:39 | [diff] [blame] | 51 | #include "grit/generated_resources.h" |
[email protected] | 0b7a012d | 2010-10-19 23:49:26 | [diff] [blame] | 52 | #include "grit/locale_settings.h" |
[email protected] | c051a1b | 2011-01-21 23:30:17 | [diff] [blame] | 53 | #include "ui/base/l10n/l10n_util.h" |
[email protected] | 9ac174e9 | 2011-04-16 00:58:56 | [diff] [blame] | 54 | #include "ui/base/resource/resource_bundle.h" |
[email protected] | 9dd7e3d7 | 2011-01-20 18:27:06 | [diff] [blame] | 55 | #include "ui/base/view_prop.h" |
[email protected] | b516e2d | 2011-07-12 16:54:12 | [diff] [blame] | 56 | #include "ui/base/models/menu_model.h" |
[email protected] | 9ef7d4b | 2011-01-27 02:17:21 | [diff] [blame] | 57 | #include "views/layout/grid_layout.h" |
[email protected] | e943d666 | 2009-06-12 03:50:39 | [diff] [blame] | 58 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 59 | using content::BrowserThread; |
[email protected] | 9dd7e3d7 | 2011-01-20 18:27:06 | [diff] [blame] | 60 | using ui::ViewProp; |
[email protected] | 3b8a7f8e | 2010-11-21 22:44:21 | [diff] [blame] | 61 | |
| 62 | static const char kWindowObjectKey[] = "ChromeWindowObject"; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 63 | |
[email protected] | b516e2d | 2011-07-12 16:54:12 | [diff] [blame] | 64 | namespace { |
| 65 | |
| 66 | // Convert ui::MenuModel into a serializable form for Chrome Frame |
| 67 | ContextMenuModel* ConvertMenuModel(const ui::MenuModel* ui_model) { |
| 68 | ContextMenuModel* new_model = new ContextMenuModel; |
| 69 | |
| 70 | const int index_base = ui_model->GetFirstItemIndex(NULL); |
| 71 | const int item_count = ui_model->GetItemCount(); |
| 72 | new_model->items.reserve(item_count); |
| 73 | for (int i = 0; i < item_count; ++i) { |
| 74 | const int index = index_base + i; |
| 75 | if (ui_model->IsVisibleAt(index)) { |
| 76 | ContextMenuModel::Item item; |
| 77 | item.type = ui_model->GetTypeAt(index); |
| 78 | item.item_id = ui_model->GetCommandIdAt(index); |
| 79 | item.label = ui_model->GetLabelAt(index); |
| 80 | item.checked = ui_model->IsItemCheckedAt(index); |
| 81 | item.enabled = ui_model->IsEnabledAt(index); |
| 82 | if (item.type == ui::MenuModel::TYPE_SUBMENU) |
| 83 | item.submenu = ConvertMenuModel(ui_model->GetSubmenuModelAt(index)); |
| 84 | |
| 85 | new_model->items.push_back(item); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | return new_model; |
| 90 | } |
| 91 | |
| 92 | } // namespace |
| 93 | |
[email protected] | 5168c72c | 2011-04-25 17:30:23 | [diff] [blame] | 94 | // This class overrides the LinkClicked function in the PageInfoBubbleView |
[email protected] | 0b7a012d | 2010-10-19 23:49:26 | [diff] [blame] | 95 | // class and routes the help center link navigation to the host browser. |
| 96 | class ExternalTabPageInfoBubbleView : public PageInfoBubbleView { |
| 97 | public: |
| 98 | ExternalTabPageInfoBubbleView(ExternalTabContainer* container, |
| 99 | gfx::NativeWindow parent_window, |
| 100 | Profile* profile, |
| 101 | const GURL& url, |
| 102 | const NavigationEntry::SSLStatus& ssl, |
| 103 | bool show_history) |
| 104 | : PageInfoBubbleView(parent_window, profile, url, ssl, show_history), |
| 105 | container_(container) { |
[email protected] | 5044da8 | 2010-10-27 01:09:16 | [diff] [blame] | 106 | DVLOG(1) << __FUNCTION__; |
[email protected] | 0b7a012d | 2010-10-19 23:49:26 | [diff] [blame] | 107 | } |
| 108 | virtual ~ExternalTabPageInfoBubbleView() { |
[email protected] | 5044da8 | 2010-10-27 01:09:16 | [diff] [blame] | 109 | DVLOG(1) << __FUNCTION__; |
[email protected] | 0b7a012d | 2010-10-19 23:49:26 | [diff] [blame] | 110 | } |
[email protected] | 5168c72c | 2011-04-25 17:30:23 | [diff] [blame] | 111 | // LinkListener methods: |
| 112 | virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE { |
[email protected] | 91a7923 | 2010-11-10 18:15:08 | [diff] [blame] | 113 | GURL url = google_util::AppendGoogleLocaleParam( |
| 114 | GURL(chrome::kPageInfoHelpCenterURL)); |
[email protected] | 0b7a012d | 2010-10-19 23:49:26 | [diff] [blame] | 115 | container_->OpenURLFromTab(container_->tab_contents(), url, GURL(), |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 116 | NEW_FOREGROUND_TAB, |
| 117 | content::PAGE_TRANSITION_LINK); |
[email protected] | 0b7a012d | 2010-10-19 23:49:26 | [diff] [blame] | 118 | } |
| 119 | private: |
| 120 | scoped_refptr<ExternalTabContainer> container_; |
| 121 | }; |
| 122 | |
[email protected] | d0ed50d | 2010-06-22 01:01:32 | [diff] [blame] | 123 | base::LazyInstance<ExternalTabContainer::PendingTabs> |
| 124 | ExternalTabContainer::pending_tabs_(base::LINKER_INITIALIZED); |
| 125 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 126 | ExternalTabContainer::ExternalTabContainer( |
[email protected] | 2e4633c | 2009-07-09 16:58:06 | [diff] [blame] | 127 | AutomationProvider* automation, AutomationResourceMessageFilter* filter) |
[email protected] | 2fc6672 | 2011-05-19 14:43:12 | [diff] [blame] | 128 | : views::NativeWidgetWin(new views::Widget), |
[email protected] | 9a56a0d | 2011-05-13 19:03:31 | [diff] [blame] | 129 | automation_(automation), |
[email protected] | 2e39d2e | 2009-02-19 18:41:31 | [diff] [blame] | 130 | tab_contents_container_(NULL), |
[email protected] | eac83f0 | 2009-05-08 18:44:44 | [diff] [blame] | 131 | tab_handle_(0), |
[email protected] | 2e4633c | 2009-07-09 16:58:06 | [diff] [blame] | 132 | ignore_next_load_notification_(false), |
| 133 | automation_resource_message_filter_(filter), |
[email protected] | a50a490 | 2009-08-14 22:39:01 | [diff] [blame] | 134 | load_requests_via_automation_(false), |
[email protected] | 24f98bba | 2009-10-14 18:47:49 | [diff] [blame] | 135 | handle_top_level_requests_(false), |
[email protected] | 4cfc1d92 | 2009-11-08 14:02:58 | [diff] [blame] | 136 | external_method_factory_(this), |
[email protected] | f701930 | 2010-03-26 19:58:32 | [diff] [blame] | 137 | pending_(false), |
[email protected] | ba67fd8 | 2010-07-09 18:30:31 | [diff] [blame] | 138 | focus_manager_(NULL), |
[email protected] | 1f71d588 | 2010-07-15 20:39:07 | [diff] [blame] | 139 | external_tab_view_(NULL), |
[email protected] | 9eeb35e | 2010-09-30 21:38:50 | [diff] [blame] | 140 | unload_reply_message_(NULL), |
[email protected] | 326d3b7 | 2011-03-29 20:38:24 | [diff] [blame] | 141 | route_all_top_level_navigations_(false), |
| 142 | is_popup_window_(false) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | ExternalTabContainer::~ExternalTabContainer() { |
[email protected] | 632fbb1 | 2009-09-06 15:27:14 | [diff] [blame] | 146 | Uninitialize(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 147 | } |
| 148 | |
[email protected] | 7b8d4a2 | 2011-02-10 20:57:54 | [diff] [blame] | 149 | TabContents* ExternalTabContainer::tab_contents() const { |
| 150 | return tab_contents_.get() ? tab_contents_->tab_contents() : NULL; |
| 151 | } |
| 152 | |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 153 | bool ExternalTabContainer::Init(Profile* profile, |
| 154 | HWND parent, |
| 155 | const gfx::Rect& bounds, |
[email protected] | 95c3c59 | 2009-07-14 22:09:03 | [diff] [blame] | 156 | DWORD style, |
[email protected] | 5f450e5 | 2009-07-28 13:28:11 | [diff] [blame] | 157 | bool load_requests_via_automation, |
[email protected] | a50a490 | 2009-08-14 22:39:01 | [diff] [blame] | 158 | bool handle_top_level_requests, |
[email protected] | 7b8d4a2 | 2011-02-10 20:57:54 | [diff] [blame] | 159 | TabContentsWrapper* existing_contents, |
[email protected] | 7de487c | 2009-12-18 21:07:53 | [diff] [blame] | 160 | const GURL& initial_url, |
[email protected] | f701930 | 2010-03-26 19:58:32 | [diff] [blame] | 161 | const GURL& referrer, |
[email protected] | 9eeb35e | 2010-09-30 21:38:50 | [diff] [blame] | 162 | bool infobars_enabled, |
| 163 | bool route_all_top_level_navigations) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 164 | if (IsWindow()) { |
| 165 | NOTREACHED(); |
| 166 | return false; |
| 167 | } |
[email protected] | 0498f7f8 | 2009-02-24 03:04:12 | [diff] [blame] | 168 | |
[email protected] | 95c3c59 | 2009-07-14 22:09:03 | [diff] [blame] | 169 | load_requests_via_automation_ = load_requests_via_automation; |
[email protected] | a50a490 | 2009-08-14 22:39:01 | [diff] [blame] | 170 | handle_top_level_requests_ = handle_top_level_requests; |
[email protected] | 9eeb35e | 2010-09-30 21:38:50 | [diff] [blame] | 171 | route_all_top_level_navigations_ = route_all_top_level_navigations; |
[email protected] | 95c3c59 | 2009-07-14 22:09:03 | [diff] [blame] | 172 | |
[email protected] | 6603fe9 | 2009-08-05 17:05:57 | [diff] [blame] | 173 | set_window_style(WS_POPUP | WS_CLIPCHILDREN); |
[email protected] | af1fde0 | 2011-04-26 17:43:05 | [diff] [blame] | 174 | |
[email protected] | 243d16c | 2011-04-26 19:31:24 | [diff] [blame] | 175 | views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); |
[email protected] | af1fde0 | 2011-04-26 17:43:05 | [diff] [blame] | 176 | params.bounds = bounds; |
[email protected] | 9a56a0d | 2011-05-13 19:03:31 | [diff] [blame] | 177 | params.native_widget = this; |
[email protected] | af1fde0 | 2011-04-26 17:43:05 | [diff] [blame] | 178 | GetWidget()->Init(params); |
[email protected] | 08ed00a | 2009-05-28 20:48:14 | [diff] [blame] | 179 | if (!IsWindow()) { |
| 180 | NOTREACHED(); |
| 181 | return false; |
| 182 | } |
[email protected] | f5cde2b | 2009-09-11 22:33:58 | [diff] [blame] | 183 | |
[email protected] | 82166b6 | 2009-06-30 18:48:00 | [diff] [blame] | 184 | // TODO(jcampan): limit focus traversal to contents. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 185 | |
[email protected] | 3b8a7f8e | 2010-11-21 22:44:21 | [diff] [blame] | 186 | prop_.reset(new ViewProp(GetNativeView(), kWindowObjectKey, this)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 187 | |
[email protected] | 632fbb1 | 2009-09-06 15:27:14 | [diff] [blame] | 188 | if (existing_contents) { |
[email protected] | 7b8d4a2 | 2011-02-10 20:57:54 | [diff] [blame] | 189 | tab_contents_.reset(existing_contents); |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 190 | tab_contents_->controller().set_browser_context(profile); |
[email protected] | 632fbb1 | 2009-09-06 15:27:14 | [diff] [blame] | 191 | } else { |
[email protected] | 7b8d4a2 | 2011-02-10 20:57:54 | [diff] [blame] | 192 | TabContents* new_contents = new TabContents(profile, NULL, MSG_ROUTING_NONE, |
| 193 | NULL, NULL); |
| 194 | tab_contents_.reset(new TabContentsWrapper(new_contents)); |
[email protected] | 632fbb1 | 2009-09-06 15:27:14 | [diff] [blame] | 195 | } |
[email protected] | a50a490 | 2009-08-14 22:39:01 | [diff] [blame] | 196 | |
[email protected] | 7abc9529 | 2011-05-18 00:18:09 | [diff] [blame] | 197 | if (!infobars_enabled) |
[email protected] | 7e20412 | 2011-09-01 18:56:21 | [diff] [blame] | 198 | tab_contents_->infobar_tab_helper()->set_infobars_enabled(false); |
[email protected] | 7abc9529 | 2011-05-18 00:18:09 | [diff] [blame] | 199 | |
[email protected] | 7b8d4a2 | 2011-02-10 20:57:54 | [diff] [blame] | 200 | tab_contents_->tab_contents()->set_delegate(this); |
[email protected] | 632fbb1 | 2009-09-06 15:27:14 | [diff] [blame] | 201 | |
[email protected] | 7b8d4a2 | 2011-02-10 20:57:54 | [diff] [blame] | 202 | tab_contents_->tab_contents()-> |
| 203 | GetMutableRendererPrefs()->browser_handles_top_level_requests = |
| 204 | handle_top_level_requests; |
[email protected] | a50a490 | 2009-08-14 22:39:01 | [diff] [blame] | 205 | |
| 206 | if (!existing_contents) { |
| 207 | tab_contents_->render_view_host()->AllowBindings( |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 208 | content::BINDINGS_POLICY_EXTERNAL_HOST); |
[email protected] | a50a490 | 2009-08-14 22:39:01 | [diff] [blame] | 209 | } |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 210 | |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 211 | NavigationController* controller = &tab_contents_->controller(); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 212 | registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 213 | content::Source<NavigationController>(controller)); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 214 | registrar_.Add(this, content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 215 | content::Source<NavigationController>(controller)); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 216 | registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 217 | content::Source<NavigationController>(controller)); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 218 | registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 219 | content::Source<TabContents>(tab_contents_->tab_contents())); |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 220 | registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_DELETED, |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 221 | content::NotificationService::AllSources()); |
[email protected] | 867ea80 | 2011-10-28 21:14:51 | [diff] [blame] | 222 | registrar_.Add(this, content::NOTIFICATION_RENDER_VIEW_HOST_CREATED, |
| 223 | content::NotificationService::AllSources()); |
[email protected] | 2e4633c | 2009-07-09 16:58:06 | [diff] [blame] | 224 | |
[email protected] | 23bf9296 | 2011-06-03 21:04:22 | [diff] [blame] | 225 | TabContentsObserver::Observe(tab_contents_->tab_contents()); |
[email protected] | 15b2c6a | 2011-05-16 23:54:40 | [diff] [blame] | 226 | |
[email protected] | f5cde2b | 2009-09-11 22:33:58 | [diff] [blame] | 227 | // Start loading initial URL |
| 228 | if (!initial_url.is_empty()) { |
| 229 | // Navigate out of context since we don't have a 'tab_handle_' yet. |
[email protected] | 24f98bba | 2009-10-14 18:47:49 | [diff] [blame] | 230 | MessageLoop::current()->PostTask( |
| 231 | FROM_HERE, |
| 232 | external_method_factory_.NewRunnableMethod( |
[email protected] | 7de487c | 2009-12-18 21:07:53 | [diff] [blame] | 233 | &ExternalTabContainer::Navigate, initial_url, referrer)); |
[email protected] | f5cde2b | 2009-09-11 22:33:58 | [diff] [blame] | 234 | } |
| 235 | |
[email protected] | 0498f7f8 | 2009-02-24 03:04:12 | [diff] [blame] | 236 | // We need WS_POPUP to be on the window during initialization, but |
| 237 | // once initialized we apply the requested style which may or may not |
| 238 | // include the popup bit. |
| 239 | // Note that it's important to do this before we call SetParent since |
| 240 | // during the SetParent call we will otherwise get a WA_ACTIVATE call |
| 241 | // that causes us to steal the current focus. |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 242 | SetWindowLong(GWL_STYLE, (GetWindowLong(GWL_STYLE) & ~WS_POPUP) | style); |
[email protected] | 0498f7f8 | 2009-02-24 03:04:12 | [diff] [blame] | 243 | |
[email protected] | 31fb11052 | 2009-01-28 21:50:39 | [diff] [blame] | 244 | // Now apply the parenting and style |
| 245 | if (parent) |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 246 | SetParent(GetNativeView(), parent); |
[email protected] | 7e50312 | 2009-02-04 21:52:48 | [diff] [blame] | 247 | |
[email protected] | 7b8d4a2 | 2011-02-10 20:57:54 | [diff] [blame] | 248 | ::ShowWindow(tab_contents_->tab_contents()->GetNativeView(), SW_SHOWNA); |
[email protected] | e943d666 | 2009-06-12 03:50:39 | [diff] [blame] | 249 | |
[email protected] | 3f70c1e1 | 2010-01-12 20:38:49 | [diff] [blame] | 250 | LoadAccelerators(); |
[email protected] | ab861b4 | 2010-02-05 19:13:44 | [diff] [blame] | 251 | SetupExternalTabView(); |
[email protected] | 7fbd1e9 | 2011-06-02 19:33:00 | [diff] [blame] | 252 | tab_contents_->blocked_content_tab_helper()->set_delegate(this); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 253 | return true; |
| 254 | } |
| 255 | |
[email protected] | 632fbb1 | 2009-09-06 15:27:14 | [diff] [blame] | 256 | void ExternalTabContainer::Uninitialize() { |
| 257 | registrar_.RemoveAll(); |
[email protected] | 7b8d4a2 | 2011-02-10 20:57:54 | [diff] [blame] | 258 | if (tab_contents_.get()) { |
[email protected] | 39ec12f | 2011-03-25 23:02:28 | [diff] [blame] | 259 | UnregisterRenderViewHost(tab_contents_->render_view_host()); |
[email protected] | 5293384 | 2009-09-29 03:44:06 | [diff] [blame] | 260 | |
[email protected] | 9a56a0d | 2011-05-13 19:03:31 | [diff] [blame] | 261 | if (GetWidget()->GetRootView()) |
| 262 | GetWidget()->GetRootView()->RemoveAllChildViews(true); |
[email protected] | 482a2d9 | 2011-02-10 00:34:28 | [diff] [blame] | 263 | |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 264 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 265 | chrome::NOTIFICATION_EXTERNAL_TAB_CLOSED, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 266 | content::Source<NavigationController>(&tab_contents_->controller()), |
| 267 | content::Details<ExternalTabContainer>(this)); |
[email protected] | 632fbb1 | 2009-09-06 15:27:14 | [diff] [blame] | 268 | |
[email protected] | 7b8d4a2 | 2011-02-10 20:57:54 | [diff] [blame] | 269 | tab_contents_.reset(NULL); |
[email protected] | 632fbb1 | 2009-09-06 15:27:14 | [diff] [blame] | 270 | } |
[email protected] | 1a98a93 | 2009-11-17 00:12:52 | [diff] [blame] | 271 | |
[email protected] | 9368547 | 2010-04-23 00:57:50 | [diff] [blame] | 272 | if (focus_manager_) { |
| 273 | focus_manager_->UnregisterAccelerators(this); |
[email protected] | f1c74ec | 2010-05-21 22:20:37 | [diff] [blame] | 274 | focus_manager_ = NULL; |
[email protected] | 3f70c1e1 | 2010-01-12 20:38:49 | [diff] [blame] | 275 | } |
| 276 | |
[email protected] | ba67fd8 | 2010-07-09 18:30:31 | [diff] [blame] | 277 | external_tab_view_ = NULL; |
[email protected] | 13c3092 | 2009-11-19 03:43:19 | [diff] [blame] | 278 | request_context_ = NULL; |
[email protected] | ab861b4 | 2010-02-05 19:13:44 | [diff] [blame] | 279 | tab_contents_container_ = NULL; |
[email protected] | 632fbb1 | 2009-09-06 15:27:14 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | bool ExternalTabContainer::Reinitialize( |
| 283 | AutomationProvider* automation_provider, |
[email protected] | 6e47f2f | 2010-07-12 17:30:58 | [diff] [blame] | 284 | AutomationResourceMessageFilter* filter, |
| 285 | gfx::NativeWindow parent_window) { |
[email protected] | 632fbb1 | 2009-09-06 15:27:14 | [diff] [blame] | 286 | if (!automation_provider || !filter) { |
| 287 | NOTREACHED(); |
| 288 | return false; |
| 289 | } |
| 290 | |
| 291 | automation_ = automation_provider; |
| 292 | automation_resource_message_filter_ = filter; |
[email protected] | 6c2e45b | 2010-05-07 00:55:25 | [diff] [blame] | 293 | // Wait for the automation channel to be initialized before resuming pending |
| 294 | // render views and sending in the navigation state. |
[email protected] | 24f98bba | 2009-10-14 18:47:49 | [diff] [blame] | 295 | MessageLoop::current()->PostTask( |
| 296 | FROM_HERE, |
| 297 | external_method_factory_.NewRunnableMethod( |
[email protected] | 18290eb | 2010-01-30 00:47:06 | [diff] [blame] | 298 | &ExternalTabContainer::OnReinitialize)); |
[email protected] | 6e47f2f | 2010-07-12 17:30:58 | [diff] [blame] | 299 | |
| 300 | if (parent_window) |
| 301 | SetParent(GetNativeView(), parent_window); |
[email protected] | 632fbb1 | 2009-09-06 15:27:14 | [diff] [blame] | 302 | return true; |
| 303 | } |
| 304 | |
[email protected] | 1a98a93 | 2009-11-17 00:12:52 | [diff] [blame] | 305 | void ExternalTabContainer::SetTabHandle(int handle) { |
| 306 | tab_handle_ = handle; |
[email protected] | 1a98a93 | 2009-11-17 00:12:52 | [diff] [blame] | 307 | } |
| 308 | |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 309 | void ExternalTabContainer::ProcessUnhandledAccelerator(const MSG& msg) { |
[email protected] | 0b5781a | 2011-10-18 21:29:00 | [diff] [blame] | 310 | NativeWebKeyboardEvent keyboard_event(msg); |
[email protected] | 3f70c1e1 | 2010-01-12 20:38:49 | [diff] [blame] | 311 | unhandled_keyboard_event_handler_.HandleKeyboardEvent(keyboard_event, |
[email protected] | 9368547 | 2010-04-23 00:57:50 | [diff] [blame] | 312 | focus_manager_); |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 313 | } |
| 314 | |
[email protected] | 1fd4569 | 2010-04-19 21:01:18 | [diff] [blame] | 315 | void ExternalTabContainer::FocusThroughTabTraversal( |
| 316 | bool reverse, bool restore_focus_to_view) { |
[email protected] | 7b8d4a2 | 2011-02-10 20:57:54 | [diff] [blame] | 317 | DCHECK(tab_contents_.get()); |
| 318 | if (tab_contents_.get()) |
| 319 | tab_contents_->tab_contents()->Focus(); |
[email protected] | 6331e0b | 2010-02-23 19:36:10 | [diff] [blame] | 320 | |
| 321 | // The tab_contents_ member can get destroyed in the context of the call to |
[email protected] | 7e2cef5 | 2011-04-11 21:47:23 | [diff] [blame] | 322 | // TabContentsViewViews::Focus() above. This method eventually calls SetFocus |
[email protected] | 6331e0b | 2010-02-23 19:36:10 | [diff] [blame] | 323 | // on the native window, which could end up dispatching messages like |
| 324 | // WM_DESTROY for the external tab. |
[email protected] | 7b8d4a2 | 2011-02-10 20:57:54 | [diff] [blame] | 325 | if (tab_contents_.get() && restore_focus_to_view) |
| 326 | tab_contents_->tab_contents()->FocusThroughTabTraversal(reverse); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 327 | } |
| 328 | |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 329 | // static |
| 330 | bool ExternalTabContainer::IsExternalTabContainer(HWND window) { |
[email protected] | 3b8a7f8e | 2010-11-21 22:44:21 | [diff] [blame] | 331 | return ViewProp::GetValue(window, kWindowObjectKey) != NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 332 | } |
| 333 | |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 334 | // static |
| 335 | ExternalTabContainer* ExternalTabContainer::GetContainerForTab( |
| 336 | HWND tab_window) { |
| 337 | HWND parent_window = ::GetParent(tab_window); |
| 338 | if (!::IsWindow(parent_window)) { |
| 339 | return NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 340 | } |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 341 | if (!IsExternalTabContainer(parent_window)) { |
| 342 | return NULL; |
| 343 | } |
| 344 | ExternalTabContainer* container = reinterpret_cast<ExternalTabContainer*>( |
[email protected] | 3b8a7f8e | 2010-11-21 22:44:21 | [diff] [blame] | 345 | ViewProp::GetValue(parent_window, kWindowObjectKey)); |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 346 | return container; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 347 | } |
| 348 | |
[email protected] | 2b19e2fe | 2010-02-16 02:24:18 | [diff] [blame] | 349 | // static |
| 350 | ExternalTabContainer* |
| 351 | ExternalTabContainer::GetExternalContainerFromNativeWindow( |
| 352 | gfx::NativeView native_window) { |
| 353 | ExternalTabContainer* tab_container = NULL; |
| 354 | if (native_window) { |
[email protected] | 3b8a7f8e | 2010-11-21 22:44:21 | [diff] [blame] | 355 | tab_container = reinterpret_cast<ExternalTabContainer*>( |
| 356 | ViewProp::GetValue(native_window, kWindowObjectKey)); |
[email protected] | 2b19e2fe | 2010-02-16 02:24:18 | [diff] [blame] | 357 | } |
| 358 | return tab_container; |
| 359 | } |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 360 | //////////////////////////////////////////////////////////////////////////////// |
| 361 | // ExternalTabContainer, TabContentsDelegate implementation: |
[email protected] | 72baf676 | 2009-05-06 18:45:33 | [diff] [blame] | 362 | |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 363 | // TODO(adriansc): Remove this method once refactoring changed all call sites. |
[email protected] | 992e454 | 2011-07-20 23:09:25 | [diff] [blame] | 364 | TabContents* ExternalTabContainer::OpenURLFromTab( |
| 365 | TabContents* source, |
| 366 | const GURL& url, |
| 367 | const GURL& referrer, |
| 368 | WindowOpenDisposition disposition, |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 369 | content::PageTransition transition) { |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 370 | return OpenURLFromTab(source, |
[email protected] | e47ae947 | 2011-10-13 19:48:34 | [diff] [blame] | 371 | OpenURLParams(url, referrer, disposition, transition, |
| 372 | false)); |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 373 | } |
[email protected] | 18290eb | 2010-01-30 00:47:06 | [diff] [blame] | 374 | |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 375 | TabContents* ExternalTabContainer::OpenURLFromTab(TabContents* source, |
| 376 | const OpenURLParams& params) { |
| 377 | if (pending()) { |
| 378 | pending_open_url_requests_.push_back(params); |
[email protected] | 992e454 | 2011-07-20 23:09:25 | [diff] [blame] | 379 | return NULL; |
[email protected] | 18290eb | 2010-01-30 00:47:06 | [diff] [blame] | 380 | } |
| 381 | |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 382 | switch (params.disposition) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 383 | case CURRENT_TAB: |
[email protected] | fba16f5 | 2009-04-02 22:30:35 | [diff] [blame] | 384 | case SINGLETON_TAB: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 385 | case NEW_FOREGROUND_TAB: |
| 386 | case NEW_BACKGROUND_TAB: |
[email protected] | 5f450e5 | 2009-07-28 13:28:11 | [diff] [blame] | 387 | case NEW_POPUP: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 388 | case NEW_WINDOW: |
[email protected] | 5f450e5 | 2009-07-28 13:28:11 | [diff] [blame] | 389 | case SAVE_TO_DISK: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 390 | if (automation_) { |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 391 | automation_->Send(new AutomationMsg_OpenURL(tab_handle_, |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 392 | params.url, |
| 393 | params.referrer, |
| 394 | params.disposition)); |
[email protected] | 898f5921 | 2010-07-22 00:35:26 | [diff] [blame] | 395 | // TODO(ananta) |
| 396 | // We should populate other fields in the |
| 397 | // ViewHostMsg_FrameNavigate_Params structure. Another option could be |
| 398 | // to refactor the UpdateHistoryForNavigation function in TabContents. |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 399 | ViewHostMsg_FrameNavigate_Params nav_params; |
| 400 | nav_params.referrer = params.referrer; |
| 401 | nav_params.url = params.url; |
| 402 | nav_params.page_id = -1; |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 403 | nav_params.transition = content::PAGE_TRANSITION_LINK; |
[email protected] | 898f5921 | 2010-07-22 00:35:26 | [diff] [blame] | 404 | |
[email protected] | 8286f51a | 2011-05-31 17:39:13 | [diff] [blame] | 405 | content::LoadCommittedDetails details; |
[email protected] | 898f5921 | 2010-07-22 00:35:26 | [diff] [blame] | 406 | details.did_replace_entry = false; |
| 407 | |
[email protected] | ec0b6c4 | 2010-08-26 03:16:58 | [diff] [blame] | 408 | scoped_refptr<history::HistoryAddPageArgs> add_page_args( |
[email protected] | 105bb0f | 2011-05-24 17:12:14 | [diff] [blame] | 409 | tab_contents_->history_tab_helper()-> |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 410 | CreateHistoryAddPageArgs(params.url, details, nav_params)); |
[email protected] | 105bb0f | 2011-05-24 17:12:14 | [diff] [blame] | 411 | tab_contents_->history_tab_helper()-> |
[email protected] | 7b8d4a2 | 2011-02-10 20:57:54 | [diff] [blame] | 412 | UpdateHistoryForNavigation(add_page_args); |
[email protected] | 992e454 | 2011-07-20 23:09:25 | [diff] [blame] | 413 | |
| 414 | return tab_contents_->tab_contents(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 415 | } |
| 416 | break; |
| 417 | default: |
[email protected] | 5f450e5 | 2009-07-28 13:28:11 | [diff] [blame] | 418 | NOTREACHED(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 419 | break; |
[email protected] | 6dfed10 | 2009-04-28 03:09:53 | [diff] [blame] | 420 | } |
[email protected] | 992e454 | 2011-07-20 23:09:25 | [diff] [blame] | 421 | |
| 422 | return NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | void ExternalTabContainer::NavigationStateChanged(const TabContents* source, |
[email protected] | b9d22749 | 2009-02-10 15:20:27 | [diff] [blame] | 426 | unsigned changed_flags) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 427 | if (automation_) { |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 428 | NavigationInfo nav_info; |
[email protected] | 610cbb8 | 2011-10-18 16:35:08 | [diff] [blame] | 429 | if (InitNavigationInfo(&nav_info, content::NAVIGATION_TYPE_NAV_IGNORE, 0)) |
[email protected] | 6c908bb | 2009-08-21 19:03:50 | [diff] [blame] | 430 | automation_->Send(new AutomationMsg_NavigationStateChanged( |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 431 | tab_handle_, changed_flags, nav_info)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 432 | } |
| 433 | } |
| 434 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 435 | void ExternalTabContainer::AddNewContents(TabContents* source, |
| 436 | TabContents* new_contents, |
| 437 | WindowOpenDisposition disposition, |
| 438 | const gfx::Rect& initial_pos, |
| 439 | bool user_gesture) { |
[email protected] | e478e21 | 2010-07-17 00:31:29 | [diff] [blame] | 440 | if (!automation_) { |
| 441 | DCHECK(pending_); |
| 442 | LOG(ERROR) << "Invalid automation provider. Dropping new contents notify"; |
| 443 | delete new_contents; |
| 444 | return; |
| 445 | } |
[email protected] | a50a490 | 2009-08-14 22:39:01 | [diff] [blame] | 446 | |
[email protected] | 9eeb35e | 2010-09-30 21:38:50 | [diff] [blame] | 447 | scoped_refptr<ExternalTabContainer> new_container; |
| 448 | // If the host is a browser like IE8, then the URL being navigated to in the |
| 449 | // new tab contents could potentially navigate back to Chrome from a new |
| 450 | // IE process. We support full tab mode only for IE and hence we use that as |
| 451 | // a determining factor in whether the new ExternalTabContainer instance is |
| 452 | // created as pending or not. |
| 453 | if (!route_all_top_level_navigations_) { |
| 454 | new_container = new ExternalTabContainer(NULL, NULL); |
| 455 | } else { |
| 456 | // Reuse the same tab handle here as the new container instance is a dummy |
| 457 | // instance which does not have an automation client connected at the other |
| 458 | // end. |
| 459 | new_container = new TemporaryPopupExternalTabContainer( |
| 460 | automation_, automation_resource_message_filter_.get()); |
| 461 | new_container->SetTabHandle(tab_handle_); |
| 462 | } |
[email protected] | a50a490 | 2009-08-14 22:39:01 | [diff] [blame] | 463 | |
[email protected] | 6f52608 | 2010-01-28 19:36:58 | [diff] [blame] | 464 | // Make sure that ExternalTabContainer instance is initialized with |
| 465 | // an unwrapped Profile. |
[email protected] | 7b8d4a2 | 2011-02-10 20:57:54 | [diff] [blame] | 466 | scoped_ptr<TabContentsWrapper> wrapper(new TabContentsWrapper(new_contents)); |
[email protected] | 6f52608 | 2010-01-28 19:36:58 | [diff] [blame] | 467 | bool result = new_container->Init( |
[email protected] | e7013f4c | 2011-08-01 16:04:12 | [diff] [blame] | 468 | wrapper->profile()->GetOriginalProfile(), |
[email protected] | 6f52608 | 2010-01-28 19:36:58 | [diff] [blame] | 469 | NULL, |
| 470 | initial_pos, |
| 471 | WS_CHILD, |
| 472 | load_requests_via_automation_, |
| 473 | handle_top_level_requests_, |
[email protected] | 7b8d4a2 | 2011-02-10 20:57:54 | [diff] [blame] | 474 | wrapper.get(), |
[email protected] | 6f52608 | 2010-01-28 19:36:58 | [diff] [blame] | 475 | GURL(), |
[email protected] | f701930 | 2010-03-26 19:58:32 | [diff] [blame] | 476 | GURL(), |
[email protected] | 9eeb35e | 2010-09-30 21:38:50 | [diff] [blame] | 477 | true, |
| 478 | route_all_top_level_navigations_); |
[email protected] | a50a490 | 2009-08-14 22:39:01 | [diff] [blame] | 479 | |
[email protected] | 6f52608 | 2010-01-28 19:36:58 | [diff] [blame] | 480 | if (result) { |
[email protected] | e7013f4c | 2011-08-01 16:04:12 | [diff] [blame] | 481 | Profile* profile = wrapper->profile(); |
[email protected] | 7b8d4a2 | 2011-02-10 20:57:54 | [diff] [blame] | 482 | wrapper.release(); // Ownership has been transferred. |
[email protected] | 9eeb35e | 2010-09-30 21:38:50 | [diff] [blame] | 483 | if (route_all_top_level_navigations_) { |
| 484 | return; |
| 485 | } |
[email protected] | b1c5563861 | 2010-03-08 16:26:11 | [diff] [blame] | 486 | uintptr_t cookie = reinterpret_cast<uintptr_t>(new_container.get()); |
[email protected] | d0ed50d | 2010-06-22 01:01:32 | [diff] [blame] | 487 | pending_tabs_.Get()[cookie] = new_container; |
[email protected] | 18290eb | 2010-01-30 00:47:06 | [diff] [blame] | 488 | new_container->set_pending(true); |
[email protected] | 326d3b7 | 2011-03-29 20:38:24 | [diff] [blame] | 489 | new_container->set_is_popup_window(disposition == NEW_POPUP); |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 490 | AttachExternalTabParams attach_params_; |
[email protected] | b1c5563861 | 2010-03-08 16:26:11 | [diff] [blame] | 491 | attach_params_.cookie = static_cast<uint64>(cookie); |
| 492 | attach_params_.dimensions = initial_pos; |
| 493 | attach_params_.user_gesture = user_gesture; |
| 494 | attach_params_.disposition = disposition; |
[email protected] | 8103c7f | 2010-09-08 22:36:09 | [diff] [blame] | 495 | attach_params_.profile_name = WideToUTF8( |
[email protected] | e7013f4c | 2011-08-01 16:04:12 | [diff] [blame] | 496 | profile->GetPath().DirName().BaseName().value()); |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 497 | automation_->Send(new AutomationMsg_AttachExternalTab( |
[email protected] | b1c5563861 | 2010-03-08 16:26:11 | [diff] [blame] | 498 | tab_handle_, attach_params_)); |
[email protected] | 6f52608 | 2010-01-28 19:36:58 | [diff] [blame] | 499 | } else { |
| 500 | NOTREACHED(); |
[email protected] | 9f5b80a | 2009-04-08 01:26:07 | [diff] [blame] | 501 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 502 | } |
| 503 | |
[email protected] | 5951b5c1 | 2010-02-22 18:15:34 | [diff] [blame] | 504 | void ExternalTabContainer::TabContentsCreated(TabContents* new_contents) { |
| 505 | RenderViewHost* rvh = new_contents->render_view_host(); |
| 506 | DCHECK(rvh != NULL); |
[email protected] | fd571bb | 2010-03-19 01:23:54 | [diff] [blame] | 507 | |
| 508 | // Register this render view as a pending render view, i.e. any network |
| 509 | // requests initiated by this render view would be serviced when the |
| 510 | // external host connects to the new external tab instance. |
| 511 | RegisterRenderViewHostForAutomation(rvh, true); |
[email protected] | 5951b5c1 | 2010-02-22 18:15:34 | [diff] [blame] | 512 | } |
| 513 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 514 | void ExternalTabContainer::CloseContents(TabContents* source) { |
[email protected] | d9d8f0c | 2010-09-17 21:47:16 | [diff] [blame] | 515 | if (!automation_) |
| 516 | return; |
[email protected] | e56e96f8 | 2010-02-03 21:38:08 | [diff] [blame] | 517 | |
[email protected] | d9d8f0c | 2010-09-17 21:47:16 | [diff] [blame] | 518 | if (unload_reply_message_) { |
| 519 | AutomationMsg_RunUnloadHandlers::WriteReplyParams(unload_reply_message_, |
| 520 | true); |
| 521 | automation_->Send(unload_reply_message_); |
| 522 | unload_reply_message_ = NULL; |
[email protected] | e16dd167 | 2010-06-07 21:40:29 | [diff] [blame] | 523 | } else { |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 524 | automation_->Send(new AutomationMsg_CloseExternalTab(tab_handle_)); |
[email protected] | 085d9cf | 2010-01-27 01:11:02 | [diff] [blame] | 525 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 526 | } |
| 527 | |
[email protected] | b9d22749 | 2009-02-10 15:20:27 | [diff] [blame] | 528 | void ExternalTabContainer::MoveContents(TabContents* source, |
| 529 | const gfx::Rect& pos) { |
[email protected] | 326d3b7 | 2011-03-29 20:38:24 | [diff] [blame] | 530 | if (automation_ && is_popup_window_) |
| 531 | automation_->Send(new AutomationMsg_MoveWindow(tab_handle_, pos)); |
| 532 | } |
| 533 | |
[email protected] | 7fbd1e9 | 2011-06-02 19:33:00 | [diff] [blame] | 534 | TabContentsWrapper* ExternalTabContainer::GetConstrainingContentsWrapper( |
| 535 | TabContentsWrapper* source) { |
| 536 | return source; |
| 537 | } |
| 538 | |
[email protected] | 326d3b7 | 2011-03-29 20:38:24 | [diff] [blame] | 539 | bool ExternalTabContainer::IsPopup(const TabContents* source) const { |
| 540 | return is_popup_window_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 541 | } |
| 542 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 543 | void ExternalTabContainer::UpdateTargetURL(TabContents* source, |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 544 | int32 page_id, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 545 | const GURL& url) { |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 546 | Browser::UpdateTargetURLHelper(source, page_id, url); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 547 | if (automation_) { |
| 548 | std::wstring url_string = CA2W(url.spec().c_str()); |
| 549 | automation_->Send( |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 550 | new AutomationMsg_UpdateTargetUrl(tab_handle_, url_string)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 551 | } |
| 552 | } |
| 553 | |
| 554 | void ExternalTabContainer::ContentsZoomChange(bool zoom_in) { |
| 555 | } |
| 556 | |
[email protected] | a95631cb | 2009-12-10 01:59:11 | [diff] [blame] | 557 | gfx::NativeWindow ExternalTabContainer::GetFrameNativeWindow() { |
| 558 | return hwnd(); |
| 559 | } |
| 560 | |
[email protected] | 1e0a02d6 | 2009-04-23 22:55:56 | [diff] [blame] | 561 | bool ExternalTabContainer::TakeFocus(bool reverse) { |
| 562 | if (automation_) { |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 563 | automation_->Send(new AutomationMsg_TabbedOut(tab_handle_, |
[email protected] | a8e2058 | 2010-12-31 17:18:50 | [diff] [blame] | 564 | base::win::IsShiftPressed())); |
[email protected] | 1e0a02d6 | 2009-04-23 22:55:56 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | return true; |
| 568 | } |
| 569 | |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 570 | bool ExternalTabContainer::CanDownload(TabContents* source, int request_id) { |
| 571 | if (load_requests_via_automation_) { |
| 572 | if (automation_) { |
| 573 | // In case the host needs to show UI that needs to take the focus. |
| 574 | ::AllowSetForegroundWindow(ASFW_ANY); |
| 575 | |
| 576 | BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 577 | NewRunnableMethod(automation_resource_message_filter_.get(), |
| 578 | &AutomationResourceMessageFilter::SendDownloadRequestToHost, |
| 579 | 0, tab_handle_, request_id)); |
| 580 | } |
| 581 | } else { |
| 582 | DLOG(WARNING) << "Downloads are only supported with host browser network " |
| 583 | "stack enabled."; |
| 584 | } |
| 585 | |
| 586 | // Never allow downloads. |
| 587 | return false; |
| 588 | } |
| 589 | |
[email protected] | 21e302e | 2009-09-12 23:10:41 | [diff] [blame] | 590 | void ExternalTabContainer::ShowPageInfo(Profile* profile, |
| 591 | const GURL& url, |
| 592 | const NavigationEntry::SSLStatus& ssl, |
| 593 | bool show_history) { |
[email protected] | 0b7a012d | 2010-10-19 23:49:26 | [diff] [blame] | 594 | POINT cursor_pos = {0}; |
| 595 | GetCursorPos(&cursor_pos); |
| 596 | |
| 597 | gfx::Rect bounds; |
| 598 | bounds.set_origin(gfx::Point(cursor_pos)); |
| 599 | |
| 600 | PageInfoBubbleView* page_info_bubble = |
| 601 | new ExternalTabPageInfoBubbleView(this, NULL, profile, url, |
| 602 | ssl, show_history); |
[email protected] | 05a3a86 | 2011-08-24 19:50:30 | [diff] [blame] | 603 | Bubble* bubble = Bubble::Show(GetWidget(), bounds, |
| 604 | views::BubbleBorder::TOP_LEFT, |
[email protected] | 41939cf | 2011-11-03 20:36:06 | [diff] [blame] | 605 | views::BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR, |
[email protected] | cb7f12f | 2011-04-14 15:10:23 | [diff] [blame] | 606 | page_info_bubble, page_info_bubble); |
| 607 | page_info_bubble->set_bubble(bubble); |
[email protected] | 21e302e | 2009-09-12 23:10:41 | [diff] [blame] | 608 | } |
| 609 | |
[email protected] | fd571bb | 2010-03-19 01:23:54 | [diff] [blame] | 610 | void ExternalTabContainer::RegisterRenderViewHostForAutomation( |
| 611 | RenderViewHost* render_view_host, bool pending_view) { |
| 612 | if (render_view_host) { |
| 613 | AutomationResourceMessageFilter::RegisterRenderView( |
| 614 | render_view_host->process()->id(), |
| 615 | render_view_host->routing_id(), |
| 616 | tab_handle(), |
| 617 | automation_resource_message_filter_, |
| 618 | pending_view); |
| 619 | } |
| 620 | } |
| 621 | |
[email protected] | fd571bb | 2010-03-19 01:23:54 | [diff] [blame] | 622 | void ExternalTabContainer::RegisterRenderViewHost( |
| 623 | RenderViewHost* render_view_host) { |
| 624 | // RenderViewHost instances that are to be associated with this |
| 625 | // ExternalTabContainer should share the same resource request automation |
| 626 | // settings. |
| 627 | RegisterRenderViewHostForAutomation( |
| 628 | render_view_host, |
| 629 | false); // Network requests should not be handled later. |
| 630 | } |
| 631 | |
| 632 | void ExternalTabContainer::UnregisterRenderViewHost( |
| 633 | RenderViewHost* render_view_host) { |
| 634 | // Undo the resource automation registration performed in |
| 635 | // ExternalTabContainer::RegisterRenderViewHost. |
| 636 | if (render_view_host) { |
| 637 | AutomationResourceMessageFilter::UnRegisterRenderView( |
| 638 | render_view_host->process()->id(), |
| 639 | render_view_host->routing_id()); |
| 640 | } |
| 641 | } |
| 642 | |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 643 | content::JavaScriptDialogCreator* |
| 644 | ExternalTabContainer::GetJavaScriptDialogCreator() { |
| 645 | return GetJavaScriptDialogCreatorInstance(); |
| 646 | } |
| 647 | |
[email protected] | e943d666 | 2009-06-12 03:50:39 | [diff] [blame] | 648 | bool ExternalTabContainer::HandleContextMenu(const ContextMenuParams& params) { |
| 649 | if (!automation_) { |
| 650 | NOTREACHED(); |
| 651 | return false; |
| 652 | } |
[email protected] | e943d666 | 2009-06-12 03:50:39 | [diff] [blame] | 653 | external_context_menu_.reset( |
[email protected] | 14831ef | 2010-05-11 23:51:20 | [diff] [blame] | 654 | new RenderViewContextMenuViews(tab_contents(), params)); |
| 655 | external_context_menu_->SetExternal(); |
[email protected] | e943d666 | 2009-06-12 03:50:39 | [diff] [blame] | 656 | external_context_menu_->Init(); |
[email protected] | a5e04ea | 2010-06-08 13:37:08 | [diff] [blame] | 657 | external_context_menu_->UpdateMenuItemStates(); |
[email protected] | e943d666 | 2009-06-12 03:50:39 | [diff] [blame] | 658 | |
[email protected] | b516e2d | 2011-07-12 16:54:12 | [diff] [blame] | 659 | scoped_ptr<ContextMenuModel> context_menu_model( |
| 660 | ConvertMenuModel(&external_context_menu_->menu_model())); |
| 661 | |
[email protected] | e943d666 | 2009-06-12 03:50:39 | [diff] [blame] | 662 | POINT screen_pt = { params.x, params.y }; |
| 663 | MapWindowPoints(GetNativeView(), HWND_DESKTOP, &screen_pt, 1); |
| 664 | |
[email protected] | 3b3ec721 | 2011-10-21 17:35:08 | [diff] [blame] | 665 | MiniContextMenuParams ipc_params; |
| 666 | ipc_params.screen_x = screen_pt.x; |
| 667 | ipc_params.screen_y = screen_pt.y; |
| 668 | ipc_params.link_url = params.link_url; |
| 669 | ipc_params.unfiltered_link_url = params.unfiltered_link_url; |
| 670 | ipc_params.src_url = params.src_url; |
| 671 | ipc_params.page_url = params.page_url; |
| 672 | ipc_params.keyword_url = params.keyword_url; |
| 673 | ipc_params.frame_url = params.frame_url; |
[email protected] | 35f13ab | 2009-12-16 23:59:17 | [diff] [blame] | 674 | |
[email protected] | 7cf1b6ce | 2010-03-20 06:37:01 | [diff] [blame] | 675 | bool rtl = base::i18n::IsRTL(); |
[email protected] | e943d666 | 2009-06-12 03:50:39 | [diff] [blame] | 676 | automation_->Send( |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 677 | new AutomationMsg_ForwardContextMenuToExternalHost(tab_handle_, |
[email protected] | b516e2d | 2011-07-12 16:54:12 | [diff] [blame] | 678 | *context_menu_model, |
[email protected] | 35f13ab | 2009-12-16 23:59:17 | [diff] [blame] | 679 | rtl ? TPM_RIGHTALIGN : TPM_LEFTALIGN, ipc_params)); |
[email protected] | e943d666 | 2009-06-12 03:50:39 | [diff] [blame] | 680 | |
| 681 | return true; |
| 682 | } |
| 683 | |
| 684 | bool ExternalTabContainer::ExecuteContextMenuCommand(int command) { |
| 685 | if (!external_context_menu_.get()) { |
| 686 | NOTREACHED(); |
| 687 | return false; |
| 688 | } |
| 689 | |
[email protected] | 35f13ab | 2009-12-16 23:59:17 | [diff] [blame] | 690 | switch (command) { |
| 691 | case IDS_CONTENT_CONTEXT_SAVEAUDIOAS: |
| 692 | case IDS_CONTENT_CONTEXT_SAVEVIDEOAS: |
| 693 | case IDS_CONTENT_CONTEXT_SAVEIMAGEAS: |
| 694 | case IDS_CONTENT_CONTEXT_SAVELINKAS: { |
| 695 | NOTREACHED(); // Should be handled in host. |
| 696 | break; |
| 697 | } |
| 698 | } |
| 699 | |
[email protected] | e943d666 | 2009-06-12 03:50:39 | [diff] [blame] | 700 | external_context_menu_->ExecuteCommand(command); |
| 701 | return true; |
| 702 | } |
| 703 | |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 704 | bool ExternalTabContainer::PreHandleKeyboardEvent( |
| 705 | const NativeWebKeyboardEvent& event, bool* is_keyboard_shortcut) { |
| 706 | return false; |
| 707 | } |
| 708 | |
| 709 | void ExternalTabContainer::HandleKeyboardEvent( |
[email protected] | 334a105b | 2009-07-14 03:42:55 | [diff] [blame] | 710 | const NativeWebKeyboardEvent& event) { |
[email protected] | 867125a0 | 2009-12-10 06:01:48 | [diff] [blame] | 711 | ProcessUnhandledKeyStroke(event.os_event.hwnd, event.os_event.message, |
| 712 | event.os_event.wParam, event.os_event.lParam); |
[email protected] | 334a105b | 2009-07-14 03:42:55 | [diff] [blame] | 713 | } |
| 714 | |
[email protected] | d9d8f0c | 2010-09-17 21:47:16 | [diff] [blame] | 715 | void ExternalTabContainer::BeforeUnloadFired(TabContents* tab, |
| 716 | bool proceed, |
| 717 | bool* proceed_to_fire_unload) { |
[email protected] | d9d8f0c | 2010-09-17 21:47:16 | [diff] [blame] | 718 | *proceed_to_fire_unload = true; |
| 719 | |
| 720 | if (!automation_) { |
| 721 | delete unload_reply_message_; |
| 722 | unload_reply_message_ = NULL; |
| 723 | return; |
| 724 | } |
| 725 | |
[email protected] | b5e0a19 | 2011-03-22 19:15:32 | [diff] [blame] | 726 | if (!unload_reply_message_) { |
| 727 | NOTREACHED() << "**** NULL unload reply message pointer."; |
| 728 | return; |
| 729 | } |
| 730 | |
[email protected] | d9d8f0c | 2010-09-17 21:47:16 | [diff] [blame] | 731 | if (!proceed) { |
| 732 | AutomationMsg_RunUnloadHandlers::WriteReplyParams(unload_reply_message_, |
| 733 | false); |
| 734 | automation_->Send(unload_reply_message_); |
| 735 | unload_reply_message_ = NULL; |
| 736 | *proceed_to_fire_unload = false; |
| 737 | } |
| 738 | } |
| 739 | |
[email protected] | 2fc22d1 | 2010-12-02 23:08:16 | [diff] [blame] | 740 | void ExternalTabContainer::ShowRepostFormWarningDialog( |
| 741 | TabContents* tab_contents) { |
| 742 | browser::ShowRepostFormWarningDialog(GetNativeView(), tab_contents); |
| 743 | } |
| 744 | |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 745 | void ExternalTabContainer::RunFileChooser( |
| 746 | TabContents* tab, const ViewHostMsg_RunFileChooser_Params& params) { |
| 747 | Browser::RunFileChooserHelper(tab, params); |
| 748 | } |
| 749 | |
| 750 | void ExternalTabContainer::EnumerateDirectory(TabContents* tab, int request_id, |
| 751 | const FilePath& path) { |
| 752 | Browser::EnumerateDirectoryHelper(tab, request_id, path); |
| 753 | } |
| 754 | |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 755 | void ExternalTabContainer::JSOutOfMemory(TabContents* tab) { |
| 756 | Browser::JSOutOfMemoryHelper(tab); |
| 757 | } |
| 758 | |
| 759 | void ExternalTabContainer::RegisterProtocolHandler(TabContents* tab, |
| 760 | const std::string& protocol, |
| 761 | const GURL& url, |
| 762 | const string16& title) { |
| 763 | Browser::RegisterProtocolHandlerHelper(tab, protocol, url, title); |
| 764 | } |
| 765 | |
| 766 | void ExternalTabContainer::RegisterIntentHandler(TabContents* tab, |
| 767 | const string16& action, |
| 768 | const string16& type, |
| 769 | const string16& href, |
[email protected] | 63c23932 | 2011-10-31 23:56:30 | [diff] [blame] | 770 | const string16& title, |
| 771 | const string16& disposition) { |
| 772 | Browser::RegisterIntentHandlerHelper( |
| 773 | tab, action, type, href, title, disposition); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 774 | } |
| 775 | |
[email protected] | ce975194 | 2011-09-21 01:57:24 | [diff] [blame] | 776 | void ExternalTabContainer::WebIntentDispatch( |
| 777 | TabContents* tab, |
| 778 | int routing_id, |
| 779 | const webkit_glue::WebIntentData& intent, |
| 780 | int intent_id) { |
[email protected] | 828e61af | 2011-09-14 19:45:06 | [diff] [blame] | 781 | // TODO(binji) How do we want to display the WebIntentPicker bubble if there |
| 782 | // is no BrowserWindow? |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 783 | } |
| 784 | |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 785 | void ExternalTabContainer::FindReply(TabContents* tab, |
| 786 | int request_id, |
| 787 | int number_of_matches, |
| 788 | const gfx::Rect& selection_rect, |
| 789 | int active_match_ordinal, |
| 790 | bool final_update) { |
| 791 | Browser::FindReplyHelper(tab, request_id, number_of_matches, selection_rect, |
| 792 | active_match_ordinal, final_update); |
| 793 | } |
| 794 | |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 795 | void ExternalTabContainer::CrashedPlugin(TabContents* tab, |
| 796 | const FilePath& plugin_path) { |
| 797 | Browser::CrashedPluginHelper(tab, plugin_path); |
| 798 | } |
| 799 | |
[email protected] | 15b2c6a | 2011-05-16 23:54:40 | [diff] [blame] | 800 | bool ExternalTabContainer::OnMessageReceived(const IPC::Message& message) { |
| 801 | bool handled = true; |
| 802 | IPC_BEGIN_MESSAGE_MAP(ExternalTabContainer, message) |
[email protected] | 2ccf45c | 2011-08-19 23:35:50 | [diff] [blame] | 803 | IPC_MESSAGE_HANDLER(ChromeViewHostMsg_ForwardMessageToExternalHost, |
[email protected] | 15b2c6a | 2011-05-16 23:54:40 | [diff] [blame] | 804 | OnForwardMessageToExternalHost) |
| 805 | IPC_MESSAGE_UNHANDLED(handled = false) |
| 806 | IPC_END_MESSAGE_MAP() |
| 807 | return handled; |
| 808 | } |
| 809 | |
| 810 | void ExternalTabContainer::OnForwardMessageToExternalHost( |
| 811 | const std::string& message, |
| 812 | const std::string& origin, |
| 813 | const std::string& target) { |
| 814 | if (automation_) { |
| 815 | automation_->Send(new AutomationMsg_ForwardMessageToExternalHost( |
| 816 | tab_handle_, message, origin, target)); |
| 817 | } |
| 818 | } |
| 819 | |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 820 | //////////////////////////////////////////////////////////////////////////////// |
| 821 | // ExternalTabContainer, NotificationObserver implementation: |
| 822 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 823 | void ExternalTabContainer::Observe(int type, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 824 | const content::NotificationSource& source, |
| 825 | const content::NotificationDetails& details) { |
[email protected] | 33ee8da | 2009-04-16 17:45:37 | [diff] [blame] | 826 | if (!automation_) |
| 827 | return; |
| 828 | |
[email protected] | 2e39d2e | 2009-02-19 18:41:31 | [diff] [blame] | 829 | static const int kHttpClientErrorStart = 400; |
| 830 | static const int kHttpServerErrorEnd = 510; |
| 831 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 832 | switch (type) { |
| 833 | case content::NOTIFICATION_LOAD_STOP: { |
[email protected] | 33ee8da | 2009-04-16 17:45:37 | [diff] [blame] | 834 | const LoadNotificationDetails* load = |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 835 | content::Details<LoadNotificationDetails>(details).ptr(); |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 836 | if (load != NULL && |
| 837 | content::PageTransitionIsMainFrame(load->origin())) { |
[email protected] | 366ae24 | 2011-05-10 02:23:58 | [diff] [blame] | 838 | TRACE_EVENT_END_ETW("ExternalTabContainer::Navigate", 0, |
| 839 | load->url().spec()); |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 840 | automation_->Send(new AutomationMsg_TabLoaded(tab_handle_, |
[email protected] | eac83f0 | 2009-05-08 18:44:44 | [diff] [blame] | 841 | load->url())); |
[email protected] | 33ee8da | 2009-04-16 17:45:37 | [diff] [blame] | 842 | } |
| 843 | break; |
[email protected] | 2e39d2e | 2009-02-19 18:41:31 | [diff] [blame] | 844 | } |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 845 | case content::NOTIFICATION_NAV_ENTRY_COMMITTED: { |
[email protected] | 867ea80 | 2011-10-28 21:14:51 | [diff] [blame] | 846 | if (ignore_next_load_notification_) { |
| 847 | ignore_next_load_notification_ = false; |
| 848 | return; |
[email protected] | 0e8db94 | 2008-09-24 21:21:48 | [diff] [blame] | 849 | } |
[email protected] | 867ea80 | 2011-10-28 21:14:51 | [diff] [blame] | 850 | |
| 851 | const content::LoadCommittedDetails* commit = |
| 852 | content::Details<content::LoadCommittedDetails>(details).ptr(); |
| 853 | |
| 854 | if (commit->http_status_code >= kHttpClientErrorStart && |
| 855 | commit->http_status_code <= kHttpServerErrorEnd) { |
| 856 | automation_->Send(new AutomationMsg_NavigationFailed( |
| 857 | tab_handle_, commit->http_status_code, commit->entry->url())); |
| 858 | |
| 859 | ignore_next_load_notification_ = true; |
| 860 | } else { |
| 861 | NavigationInfo navigation_info; |
| 862 | // When the previous entry index is invalid, it will be -1, which |
| 863 | // will still make the computation come out right (navigating to the |
| 864 | // 0th entry will be +1). |
| 865 | if (InitNavigationInfo(&navigation_info, commit->type, |
| 866 | commit->previous_entry_index - |
| 867 | tab_contents_->controller().last_committed_entry_index())) |
| 868 | automation_->Send(new AutomationMsg_DidNavigate(tab_handle_, |
| 869 | navigation_info)); |
| 870 | } |
| 871 | break; |
| 872 | } |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 873 | case content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR: { |
[email protected] | 33ee8da | 2009-04-16 17:45:37 | [diff] [blame] | 874 | const ProvisionalLoadDetails* load_details = |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 875 | content::Details<ProvisionalLoadDetails>(details).ptr(); |
[email protected] | 33ee8da | 2009-04-16 17:45:37 | [diff] [blame] | 876 | automation_->Send(new AutomationMsg_NavigationFailed( |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 877 | tab_handle_, load_details->error_code(), load_details->url())); |
[email protected] | 2e39d2e | 2009-02-19 18:41:31 | [diff] [blame] | 878 | |
[email protected] | 33ee8da | 2009-04-16 17:45:37 | [diff] [blame] | 879 | ignore_next_load_notification_ = true; |
[email protected] | 2e39d2e | 2009-02-19 18:41:31 | [diff] [blame] | 880 | break; |
| 881 | } |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 882 | case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB: { |
[email protected] | 2e4633c | 2009-07-09 16:58:06 | [diff] [blame] | 883 | if (load_requests_via_automation_) { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 884 | RenderViewHost* rvh = content::Details<RenderViewHost>(details).ptr(); |
[email protected] | fd571bb | 2010-03-19 01:23:54 | [diff] [blame] | 885 | RegisterRenderViewHostForAutomation(rvh, false); |
[email protected] | 2e4633c | 2009-07-09 16:58:06 | [diff] [blame] | 886 | } |
| 887 | break; |
| 888 | } |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 889 | case content::NOTIFICATION_RENDER_VIEW_HOST_DELETED: { |
[email protected] | 2e4633c | 2009-07-09 16:58:06 | [diff] [blame] | 890 | if (load_requests_via_automation_) { |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 891 | RenderViewHost* rvh = content::Source<RenderViewHost>(source).ptr(); |
[email protected] | fd571bb | 2010-03-19 01:23:54 | [diff] [blame] | 892 | UnregisterRenderViewHost(rvh); |
[email protected] | 2e4633c | 2009-07-09 16:58:06 | [diff] [blame] | 893 | } |
| 894 | break; |
| 895 | } |
[email protected] | 867ea80 | 2011-10-28 21:14:51 | [diff] [blame] | 896 | case content::NOTIFICATION_RENDER_VIEW_HOST_CREATED: { |
| 897 | if (load_requests_via_automation_) { |
| 898 | RenderViewHost* rvh = content::Source<RenderViewHost>(source).ptr(); |
| 899 | RegisterRenderViewHostForAutomation(rvh, false); |
| 900 | } |
| 901 | break; |
| 902 | } |
[email protected] | 0e8db94 | 2008-09-24 21:21:48 | [diff] [blame] | 903 | default: |
| 904 | NOTREACHED(); |
| 905 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 906 | } |
| 907 | |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 908 | //////////////////////////////////////////////////////////////////////////////// |
[email protected] | 2fc6672 | 2011-05-19 14:43:12 | [diff] [blame] | 909 | // ExternalTabContainer, views::NativeWidgetWin overrides: |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 910 | |
[email protected] | 632fbb1 | 2009-09-06 15:27:14 | [diff] [blame] | 911 | LRESULT ExternalTabContainer::OnCreate(LPCREATESTRUCT create_struct) { |
[email protected] | 2fc6672 | 2011-05-19 14:43:12 | [diff] [blame] | 912 | LRESULT result = views::NativeWidgetWin::OnCreate(create_struct); |
[email protected] | 632fbb1 | 2009-09-06 15:27:14 | [diff] [blame] | 913 | if (result == 0) { |
| 914 | // Grab a reference here which will be released in OnFinalMessage |
| 915 | AddRef(); |
| 916 | } |
| 917 | return result; |
| 918 | } |
| 919 | |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 920 | void ExternalTabContainer::OnDestroy() { |
[email protected] | 7c9d829 | 2010-11-01 16:57:13 | [diff] [blame] | 921 | prop_.reset(); |
[email protected] | 632fbb1 | 2009-09-06 15:27:14 | [diff] [blame] | 922 | Uninitialize(); |
[email protected] | 2fc6672 | 2011-05-19 14:43:12 | [diff] [blame] | 923 | NativeWidgetWin::OnDestroy(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 924 | } |
| 925 | |
[email protected] | 632fbb1 | 2009-09-06 15:27:14 | [diff] [blame] | 926 | void ExternalTabContainer::OnFinalMessage(HWND window) { |
| 927 | // Release the reference which we grabbed in WM_CREATE. |
| 928 | Release(); |
[email protected] | 334a105b | 2009-07-14 03:42:55 | [diff] [blame] | 929 | } |
| 930 | |
[email protected] | d9d8f0c | 2010-09-17 21:47:16 | [diff] [blame] | 931 | void ExternalTabContainer::RunUnloadHandlers(IPC::Message* reply_message) { |
| 932 | if (!automation_) { |
| 933 | delete reply_message; |
| 934 | return; |
[email protected] | 1f71d588 | 2010-07-15 20:39:07 | [diff] [blame] | 935 | } |
[email protected] | d9d8f0c | 2010-09-17 21:47:16 | [diff] [blame] | 936 | |
| 937 | // If we have a pending unload message, then just respond back to this |
| 938 | // request and continue processing the previous unload message. |
| 939 | if (unload_reply_message_) { |
| 940 | AutomationMsg_RunUnloadHandlers::WriteReplyParams(reply_message, true); |
| 941 | automation_->Send(reply_message); |
| 942 | return; |
| 943 | } |
[email protected] | b5e0a19 | 2011-03-22 19:15:32 | [diff] [blame] | 944 | |
| 945 | unload_reply_message_ = reply_message; |
| 946 | bool wait_for_unload_handlers = |
| 947 | tab_contents_.get() && |
| 948 | Browser::RunUnloadEventsHelper(tab_contents_->tab_contents()); |
| 949 | if (!wait_for_unload_handlers) { |
[email protected] | d9d8f0c | 2010-09-17 21:47:16 | [diff] [blame] | 950 | AutomationMsg_RunUnloadHandlers::WriteReplyParams(reply_message, true); |
| 951 | automation_->Send(reply_message); |
[email protected] | b5e0a19 | 2011-03-22 19:15:32 | [diff] [blame] | 952 | unload_reply_message_ = NULL; |
[email protected] | 1f71d588 | 2010-07-15 20:39:07 | [diff] [blame] | 953 | } |
| 954 | } |
| 955 | |
[email protected] | 632fbb1 | 2009-09-06 15:27:14 | [diff] [blame] | 956 | //////////////////////////////////////////////////////////////////////////////// |
| 957 | // ExternalTabContainer, private: |
[email protected] | 334a105b | 2009-07-14 03:42:55 | [diff] [blame] | 958 | bool ExternalTabContainer::ProcessUnhandledKeyStroke(HWND window, |
| 959 | UINT message, |
| 960 | WPARAM wparam, |
| 961 | LPARAM lparam) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 962 | if (!automation_) { |
| 963 | return false; |
| 964 | } |
[email protected] | a8e2058 | 2010-12-31 17:18:50 | [diff] [blame] | 965 | if ((wparam == VK_TAB) && !base::win::IsCtrlPressed()) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 966 | // Tabs are handled separately (except if this is Ctrl-Tab or |
| 967 | // Ctrl-Shift-Tab) |
| 968 | return false; |
| 969 | } |
[email protected] | 060254c | 2009-05-02 16:45:27 | [diff] [blame] | 970 | |
[email protected] | 01dba67 | 2010-02-12 21:55:48 | [diff] [blame] | 971 | // Send this keystroke to the external host as it could be processed as an |
| 972 | // accelerator there. If the host does not handle this accelerator, it will |
| 973 | // reflect the accelerator back to us via the ProcessUnhandledAccelerator |
| 974 | // method. |
| 975 | MSG msg = {0}; |
| 976 | msg.hwnd = window; |
| 977 | msg.message = message; |
| 978 | msg.wParam = wparam; |
| 979 | msg.lParam = lparam; |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 980 | automation_->Send(new AutomationMsg_HandleAccelerator(tab_handle_, msg)); |
[email protected] | 01dba67 | 2010-02-12 21:55:48 | [diff] [blame] | 981 | return true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 982 | } |
[email protected] | 4150ef0 | 2009-08-19 23:14:26 | [diff] [blame] | 983 | |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 984 | bool ExternalTabContainer::InitNavigationInfo(NavigationInfo* nav_info, |
[email protected] | 610cbb8 | 2011-10-18 16:35:08 | [diff] [blame] | 985 | content::NavigationType nav_type, |
[email protected] | 4150ef0 | 2009-08-19 23:14:26 | [diff] [blame] | 986 | int relative_offset) { |
[email protected] | 4150ef0 | 2009-08-19 23:14:26 | [diff] [blame] | 987 | DCHECK(nav_info); |
[email protected] | 6c908bb | 2009-08-21 19:03:50 | [diff] [blame] | 988 | NavigationEntry* entry = tab_contents_->controller().GetActiveEntry(); |
| 989 | // If this is very early in the game then we may not have an entry. |
| 990 | if (!entry) |
| 991 | return false; |
[email protected] | 4150ef0 | 2009-08-19 23:14:26 | [diff] [blame] | 992 | |
| 993 | nav_info->navigation_type = nav_type; |
| 994 | nav_info->relative_offset = relative_offset; |
| 995 | nav_info->navigation_index = |
| 996 | tab_contents_->controller().GetCurrentEntryIndex(); |
[email protected] | 4150ef0 | 2009-08-19 23:14:26 | [diff] [blame] | 997 | nav_info->url = entry->url(); |
[email protected] | a1955adf | 2010-08-02 17:59:39 | [diff] [blame] | 998 | nav_info->referrer = entry->referrer(); |
[email protected] | 6b2f7a8 | 2011-04-25 19:30:51 | [diff] [blame] | 999 | nav_info->title = UTF16ToWideHack(entry->title()); |
[email protected] | 24f98bba | 2009-10-14 18:47:49 | [diff] [blame] | 1000 | if (nav_info->title.empty()) |
| 1001 | nav_info->title = UTF8ToWide(nav_info->url.spec()); |
| 1002 | |
[email protected] | f5cde2b | 2009-09-11 22:33:58 | [diff] [blame] | 1003 | nav_info->security_style = entry->ssl().security_style(); |
[email protected] | b4e75c1 | 2010-05-18 18:28:48 | [diff] [blame] | 1004 | nav_info->displayed_insecure_content = |
| 1005 | entry->ssl().displayed_insecure_content(); |
| 1006 | nav_info->ran_insecure_content = entry->ssl().ran_insecure_content(); |
[email protected] | 6c908bb | 2009-08-21 19:03:50 | [diff] [blame] | 1007 | return true; |
[email protected] | 4150ef0 | 2009-08-19 23:14:26 | [diff] [blame] | 1008 | } |
| 1009 | |
[email protected] | cd0dec6 | 2010-02-11 02:33:18 | [diff] [blame] | 1010 | scoped_refptr<ExternalTabContainer> ExternalTabContainer::RemovePendingTab( |
[email protected] | b1c5563861 | 2010-03-08 16:26:11 | [diff] [blame] | 1011 | uintptr_t cookie) { |
[email protected] | d0ed50d | 2010-06-22 01:01:32 | [diff] [blame] | 1012 | ExternalTabContainer::PendingTabs& pending_tabs = pending_tabs_.Get(); |
| 1013 | PendingTabs::iterator index = pending_tabs.find(cookie); |
| 1014 | if (index != pending_tabs.end()) { |
[email protected] | 632fbb1 | 2009-09-06 15:27:14 | [diff] [blame] | 1015 | scoped_refptr<ExternalTabContainer> container = (*index).second; |
[email protected] | d0ed50d | 2010-06-22 01:01:32 | [diff] [blame] | 1016 | pending_tabs.erase(index); |
[email protected] | cd0dec6 | 2010-02-11 02:33:18 | [diff] [blame] | 1017 | return container; |
[email protected] | 632fbb1 | 2009-09-06 15:27:14 | [diff] [blame] | 1018 | } |
| 1019 | |
| 1020 | NOTREACHED() << "Failed to find ExternalTabContainer for cookie: " |
| 1021 | << cookie; |
| 1022 | return NULL; |
| 1023 | } |
| 1024 | |
[email protected] | 9ac174e9 | 2011-04-16 00:58:56 | [diff] [blame] | 1025 | SkColor ExternalTabContainer::GetInfoBarSeparatorColor() const { |
| 1026 | return ResourceBundle::toolbar_separator_color; |
| 1027 | } |
| 1028 | |
[email protected] | 4f2d40d | 2011-05-05 01:33:30 | [diff] [blame] | 1029 | void ExternalTabContainer::InfoBarContainerStateChanged(bool is_animating) { |
[email protected] | f4f50ef | 2011-01-21 19:01:19 | [diff] [blame] | 1030 | if (external_tab_view_) |
[email protected] | ba67fd8 | 2010-07-09 18:30:31 | [diff] [blame] | 1031 | external_tab_view_->Layout(); |
[email protected] | ab861b4 | 2010-02-05 19:13:44 | [diff] [blame] | 1032 | } |
| 1033 | |
[email protected] | ee12087 | 2011-04-15 01:37:06 | [diff] [blame] | 1034 | bool ExternalTabContainer::DrawInfoBarArrows(int* x) const { |
| 1035 | return false; |
| 1036 | } |
| 1037 | |
[email protected] | 3f70c1e1 | 2010-01-12 20:38:49 | [diff] [blame] | 1038 | bool ExternalTabContainer::AcceleratorPressed( |
[email protected] | c5be11f | 2011-11-14 13:33:23 | [diff] [blame^] | 1039 | const ui::Accelerator& accelerator) { |
| 1040 | std::map<ui::Accelerator, int>::const_iterator iter = |
[email protected] | 3f70c1e1 | 2010-01-12 20:38:49 | [diff] [blame] | 1041 | accelerator_table_.find(accelerator); |
| 1042 | DCHECK(iter != accelerator_table_.end()); |
| 1043 | |
[email protected] | 7b8d4a2 | 2011-02-10 20:57:54 | [diff] [blame] | 1044 | if (!tab_contents_.get() || !tab_contents_->render_view_host()) { |
[email protected] | 3f70c1e1 | 2010-01-12 20:38:49 | [diff] [blame] | 1045 | NOTREACHED(); |
| 1046 | return false; |
| 1047 | } |
| 1048 | |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 1049 | RenderViewHost* host = tab_contents_->render_view_host(); |
[email protected] | 3f70c1e1 | 2010-01-12 20:38:49 | [diff] [blame] | 1050 | int command_id = iter->second; |
| 1051 | switch (command_id) { |
| 1052 | case IDC_ZOOM_PLUS: |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 1053 | host->Zoom(content::PAGE_ZOOM_IN); |
[email protected] | 3f70c1e1 | 2010-01-12 20:38:49 | [diff] [blame] | 1054 | break; |
| 1055 | case IDC_ZOOM_NORMAL: |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 1056 | host->Zoom(content::PAGE_ZOOM_RESET); |
[email protected] | 3f70c1e1 | 2010-01-12 20:38:49 | [diff] [blame] | 1057 | break; |
| 1058 | case IDC_ZOOM_MINUS: |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 1059 | host->Zoom(content::PAGE_ZOOM_OUT); |
[email protected] | 3f70c1e1 | 2010-01-12 20:38:49 | [diff] [blame] | 1060 | break; |
| 1061 | case IDC_DEV_TOOLS: |
[email protected] | aebdd07 | 2011-07-07 12:36:59 | [diff] [blame] | 1062 | DevToolsWindow::ToggleDevToolsWindow( |
[email protected] | 2a8a9812 | 2010-07-16 11:58:48 | [diff] [blame] | 1063 | tab_contents_->render_view_host(), DEVTOOLS_TOGGLE_ACTION_NONE); |
[email protected] | 3f70c1e1 | 2010-01-12 20:38:49 | [diff] [blame] | 1064 | break; |
| 1065 | case IDC_DEV_TOOLS_CONSOLE: |
[email protected] | aebdd07 | 2011-07-07 12:36:59 | [diff] [blame] | 1066 | DevToolsWindow::ToggleDevToolsWindow( |
[email protected] | 2a8a9812 | 2010-07-16 11:58:48 | [diff] [blame] | 1067 | tab_contents_->render_view_host(), |
| 1068 | DEVTOOLS_TOGGLE_ACTION_SHOW_CONSOLE); |
| 1069 | break; |
| 1070 | case IDC_DEV_TOOLS_INSPECT: |
[email protected] | aebdd07 | 2011-07-07 12:36:59 | [diff] [blame] | 1071 | DevToolsWindow::ToggleDevToolsWindow( |
[email protected] | 2a8a9812 | 2010-07-16 11:58:48 | [diff] [blame] | 1072 | tab_contents_->render_view_host(), |
| 1073 | DEVTOOLS_TOGGLE_ACTION_INSPECT); |
[email protected] | 3f70c1e1 | 2010-01-12 20:38:49 | [diff] [blame] | 1074 | break; |
| 1075 | default: |
| 1076 | NOTREACHED() << "Unsupported accelerator: " << command_id; |
| 1077 | return false; |
| 1078 | } |
| 1079 | return true; |
| 1080 | } |
| 1081 | |
[email protected] | f5cde2b | 2009-09-11 22:33:58 | [diff] [blame] | 1082 | void ExternalTabContainer::Navigate(const GURL& url, const GURL& referrer) { |
[email protected] | 7b8d4a2 | 2011-02-10 20:57:54 | [diff] [blame] | 1083 | if (!tab_contents_.get()) { |
[email protected] | f5cde2b | 2009-09-11 22:33:58 | [diff] [blame] | 1084 | NOTREACHED(); |
| 1085 | return; |
| 1086 | } |
| 1087 | |
[email protected] | 366ae24 | 2011-05-10 02:23:58 | [diff] [blame] | 1088 | TRACE_EVENT_BEGIN_ETW("ExternalTabContainer::Navigate", 0, url.spec()); |
[email protected] | a872ea1f | 2010-08-11 04:45:33 | [diff] [blame] | 1089 | |
[email protected] | f5cde2b | 2009-09-11 22:33:58 | [diff] [blame] | 1090 | tab_contents_->controller().LoadURL(url, referrer, |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1091 | content::PAGE_TRANSITION_START_PAGE, |
[email protected] | 79046fd | 2011-09-10 05:48:33 | [diff] [blame] | 1092 | std::string()); |
[email protected] | f5cde2b | 2009-09-11 22:33:58 | [diff] [blame] | 1093 | } |
[email protected] | f9cc4c45 | 2009-10-13 14:56:38 | [diff] [blame] | 1094 | |
| 1095 | bool ExternalTabContainer::OnGoToEntryOffset(int offset) { |
| 1096 | if (load_requests_via_automation_) { |
| 1097 | automation_->Send(new AutomationMsg_RequestGoToHistoryEntryOffset( |
[email protected] | f5494d4 | 2010-12-23 22:15:34 | [diff] [blame] | 1098 | tab_handle_, offset)); |
[email protected] | f9cc4c45 | 2009-10-13 14:56:38 | [diff] [blame] | 1099 | return false; |
| 1100 | } |
| 1101 | |
| 1102 | return true; |
| 1103 | } |
[email protected] | 1a98a93 | 2009-11-17 00:12:52 | [diff] [blame] | 1104 | |
[email protected] | 3f70c1e1 | 2010-01-12 20:38:49 | [diff] [blame] | 1105 | void ExternalTabContainer::LoadAccelerators() { |
| 1106 | HACCEL accelerator_table = AtlLoadAccelerators(IDR_CHROMEFRAME); |
| 1107 | DCHECK(accelerator_table); |
| 1108 | |
| 1109 | // We have to copy the table to access its contents. |
| 1110 | int count = CopyAcceleratorTable(accelerator_table, 0, 0); |
| 1111 | if (count == 0) { |
| 1112 | // Nothing to do in that case. |
| 1113 | return; |
| 1114 | } |
| 1115 | |
[email protected] | 1f1e7cb | 2011-10-07 22:55:47 | [diff] [blame] | 1116 | scoped_array<ACCEL> scoped_accelerators(new ACCEL[count]); |
[email protected] | 3f70c1e1 | 2010-01-12 20:38:49 | [diff] [blame] | 1117 | ACCEL* accelerators = scoped_accelerators.get(); |
| 1118 | DCHECK(accelerators != NULL); |
| 1119 | |
| 1120 | CopyAcceleratorTable(accelerator_table, accelerators, count); |
| 1121 | |
[email protected] | 9a56a0d | 2011-05-13 19:03:31 | [diff] [blame] | 1122 | focus_manager_ = GetWidget()->GetFocusManager(); |
[email protected] | 9368547 | 2010-04-23 00:57:50 | [diff] [blame] | 1123 | DCHECK(focus_manager_); |
[email protected] | 3f70c1e1 | 2010-01-12 20:38:49 | [diff] [blame] | 1124 | |
| 1125 | // Let's fill our own accelerator table. |
| 1126 | for (int i = 0; i < count; ++i) { |
| 1127 | bool alt_down = (accelerators[i].fVirt & FALT) == FALT; |
| 1128 | bool ctrl_down = (accelerators[i].fVirt & FCONTROL) == FCONTROL; |
| 1129 | bool shift_down = (accelerators[i].fVirt & FSHIFT) == FSHIFT; |
[email protected] | c5be11f | 2011-11-14 13:33:23 | [diff] [blame^] | 1130 | ui::Accelerator accelerator( |
[email protected] | b6d8126 | 2011-01-13 17:36:09 | [diff] [blame] | 1131 | static_cast<ui::KeyboardCode>(accelerators[i].key), |
[email protected] | 3f70c1e1 | 2010-01-12 20:38:49 | [diff] [blame] | 1132 | shift_down, ctrl_down, alt_down); |
| 1133 | accelerator_table_[accelerator] = accelerators[i].cmd; |
| 1134 | |
| 1135 | // Also register with the focus manager. |
[email protected] | 9368547 | 2010-04-23 00:57:50 | [diff] [blame] | 1136 | if (focus_manager_) |
| 1137 | focus_manager_->RegisterAccelerator(accelerator, this); |
[email protected] | 3f70c1e1 | 2010-01-12 20:38:49 | [diff] [blame] | 1138 | } |
| 1139 | } |
[email protected] | 18290eb | 2010-01-30 00:47:06 | [diff] [blame] | 1140 | |
| 1141 | void ExternalTabContainer::OnReinitialize() { |
[email protected] | 6c2e45b | 2010-05-07 00:55:25 | [diff] [blame] | 1142 | if (load_requests_via_automation_) { |
[email protected] | 6c2e45b | 2010-05-07 00:55:25 | [diff] [blame] | 1143 | RenderViewHost* rvh = tab_contents_->render_view_host(); |
| 1144 | if (rvh) { |
| 1145 | AutomationResourceMessageFilter::ResumePendingRenderView( |
| 1146 | rvh->process()->id(), rvh->routing_id(), |
| 1147 | tab_handle_, automation_resource_message_filter_); |
| 1148 | } |
| 1149 | } |
| 1150 | |
[email protected] | 7b8d4a2 | 2011-02-10 20:57:54 | [diff] [blame] | 1151 | NavigationStateChanged(tab_contents(), 0); |
[email protected] | 18290eb | 2010-01-30 00:47:06 | [diff] [blame] | 1152 | ServicePendingOpenURLRequests(); |
| 1153 | } |
| 1154 | |
| 1155 | void ExternalTabContainer::ServicePendingOpenURLRequests() { |
| 1156 | DCHECK(pending()); |
| 1157 | |
| 1158 | set_pending(false); |
| 1159 | |
| 1160 | for (size_t index = 0; index < pending_open_url_requests_.size(); |
[email protected] | 7b8d4a2 | 2011-02-10 20:57:54 | [diff] [blame] | 1161 | ++index) { |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 1162 | const OpenURLParams& url_request = pending_open_url_requests_[index]; |
| 1163 | OpenURLFromTab(tab_contents(), url_request); |
[email protected] | 18290eb | 2010-01-30 00:47:06 | [diff] [blame] | 1164 | } |
| 1165 | pending_open_url_requests_.clear(); |
| 1166 | } |
| 1167 | |
[email protected] | ab861b4 | 2010-02-05 19:13:44 | [diff] [blame] | 1168 | void ExternalTabContainer::SetupExternalTabView() { |
| 1169 | // Create a TabContentsContainer to handle focus cycling using Tab and |
| 1170 | // Shift-Tab. |
| 1171 | tab_contents_container_ = new TabContentsContainer; |
| 1172 | |
| 1173 | // The views created here will be destroyed when the ExternalTabContainer |
| 1174 | // widget is torn down. |
[email protected] | ba67fd8 | 2010-07-09 18:30:31 | [diff] [blame] | 1175 | external_tab_view_ = new views::View(); |
[email protected] | ab861b4 | 2010-02-05 19:13:44 | [diff] [blame] | 1176 | |
[email protected] | 6c6614f1 | 2011-03-31 18:51:42 | [diff] [blame] | 1177 | InfoBarContainerView* info_bar_container = new InfoBarContainerView(this); |
[email protected] | 95a33ed6 | 2011-09-30 15:07:08 | [diff] [blame] | 1178 | info_bar_container->ChangeTabContents(tab_contents_->infobar_tab_helper()); |
[email protected] | ab861b4 | 2010-02-05 19:13:44 | [diff] [blame] | 1179 | |
[email protected] | ba67fd8 | 2010-07-09 18:30:31 | [diff] [blame] | 1180 | views::GridLayout* layout = new views::GridLayout(external_tab_view_); |
| 1181 | // Give this column an identifier of 0. |
| 1182 | views::ColumnSet* columns = layout->AddColumnSet(0); |
[email protected] | ab861b4 | 2010-02-05 19:13:44 | [diff] [blame] | 1183 | columns->AddColumn(views::GridLayout::FILL, |
| 1184 | views::GridLayout::FILL, |
| 1185 | 1, |
| 1186 | views::GridLayout::USE_PREF, |
| 1187 | 0, |
| 1188 | 0); |
| 1189 | |
[email protected] | ba67fd8 | 2010-07-09 18:30:31 | [diff] [blame] | 1190 | external_tab_view_->SetLayoutManager(layout); |
[email protected] | ab861b4 | 2010-02-05 19:13:44 | [diff] [blame] | 1191 | |
| 1192 | layout->StartRow(0, 0); |
| 1193 | layout->AddView(info_bar_container); |
| 1194 | layout->StartRow(1, 0); |
| 1195 | layout->AddView(tab_contents_container_); |
[email protected] | 9a56a0d | 2011-05-13 19:03:31 | [diff] [blame] | 1196 | GetWidget()->SetContentsView(external_tab_view_); |
[email protected] | ab861b4 | 2010-02-05 19:13:44 | [diff] [blame] | 1197 | // Note that SetTabContents must be called after AddChildView is called |
[email protected] | 7b8d4a2 | 2011-02-10 20:57:54 | [diff] [blame] | 1198 | tab_contents_container_->ChangeTabContents(tab_contents()); |
[email protected] | ab861b4 | 2010-02-05 19:13:44 | [diff] [blame] | 1199 | } |
[email protected] | 9eeb35e | 2010-09-30 21:38:50 | [diff] [blame] | 1200 | |
| 1201 | TemporaryPopupExternalTabContainer::TemporaryPopupExternalTabContainer( |
| 1202 | AutomationProvider* automation, |
| 1203 | AutomationResourceMessageFilter* filter) |
| 1204 | : ExternalTabContainer(automation, filter) { |
| 1205 | } |
| 1206 | |
| 1207 | TemporaryPopupExternalTabContainer::~TemporaryPopupExternalTabContainer() { |
[email protected] | 8e96e50 | 2010-10-21 20:57:12 | [diff] [blame] | 1208 | DVLOG(1) << __FUNCTION__; |
[email protected] | 9eeb35e | 2010-09-30 21:38:50 | [diff] [blame] | 1209 | } |
| 1210 | |
[email protected] | 992e454 | 2011-07-20 23:09:25 | [diff] [blame] | 1211 | TabContents* TemporaryPopupExternalTabContainer::OpenURLFromTab( |
[email protected] | 9eeb35e | 2010-09-30 21:38:50 | [diff] [blame] | 1212 | TabContents* source, const GURL& url, const GURL& referrer, |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1213 | WindowOpenDisposition disposition, content::PageTransition transition) { |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 1214 | return OpenURLFromTab(source, |
[email protected] | e47ae947 | 2011-10-13 19:48:34 | [diff] [blame] | 1215 | OpenURLParams(url, referrer, disposition, transition, |
| 1216 | false)); |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 1217 | } |
| 1218 | |
| 1219 | TabContents* TemporaryPopupExternalTabContainer::OpenURLFromTab( |
| 1220 | TabContents* source, |
| 1221 | const OpenURLParams& params) { |
[email protected] | 9eeb35e | 2010-09-30 21:38:50 | [diff] [blame] | 1222 | if (!automation_) |
[email protected] | 992e454 | 2011-07-20 23:09:25 | [diff] [blame] | 1223 | return NULL; |
[email protected] | 9eeb35e | 2010-09-30 21:38:50 | [diff] [blame] | 1224 | |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 1225 | OpenURLParams forward_params = params; |
| 1226 | if (params.disposition == CURRENT_TAB) { |
[email protected] | 9eeb35e | 2010-09-30 21:38:50 | [diff] [blame] | 1227 | DCHECK(route_all_top_level_navigations_); |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 1228 | forward_params.disposition = NEW_FOREGROUND_TAB; |
[email protected] | 9eeb35e | 2010-09-30 21:38:50 | [diff] [blame] | 1229 | } |
[email protected] | 992e454 | 2011-07-20 23:09:25 | [diff] [blame] | 1230 | TabContents* new_contents = |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 1231 | ExternalTabContainer::OpenURLFromTab(source, forward_params); |
[email protected] | 9eeb35e | 2010-09-30 21:38:50 | [diff] [blame] | 1232 | // support only one navigation for a dummy tab before it is killed. |
| 1233 | ::DestroyWindow(GetNativeView()); |
[email protected] | 992e454 | 2011-07-20 23:09:25 | [diff] [blame] | 1234 | return new_contents; |
[email protected] | 9eeb35e | 2010-09-30 21:38:50 | [diff] [blame] | 1235 | } |