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