license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
| 5 | #include "chrome/browser/external_tab_container.h" |
| 6 | |
[email protected] | 4a0765a | 2009-05-08 23:12:25 | [diff] [blame] | 7 | #include "app/win_util.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 8 | #include "base/logging.h" |
[email protected] | 1eb89e8 | 2008-08-15 12:27:03 | [diff] [blame] | 9 | #include "base/win_util.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 10 | #include "chrome/browser/automation/automation_provider.h" |
[email protected] | 9f5b80a | 2009-04-08 01:26:07 | [diff] [blame] | 11 | #include "chrome/browser/browser.h" |
[email protected] | 6dfed10 | 2009-04-28 03:09:53 | [diff] [blame] | 12 | #include "chrome/browser/extensions/extension_function_dispatcher.h" |
[email protected] | 33ee8da | 2009-04-16 17:45:37 | [diff] [blame] | 13 | #include "chrome/browser/load_notification_details.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 14 | #include "chrome/browser/profile.h" |
[email protected] | 2e39d2e | 2009-02-19 18:41:31 | [diff] [blame] | 15 | #include "chrome/browser/tab_contents/provisional_load_details.h" |
[email protected] | f3ec774 | 2009-01-15 00:59:16 | [diff] [blame] | 16 | #include "chrome/browser/tab_contents/tab_contents.h" |
[email protected] | 610d36a | 2009-05-22 23:00:38 | [diff] [blame] | 17 | #include "chrome/browser/views/tab_contents/tab_contents_container.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 18 | #include "chrome/common/chrome_constants.h" |
[email protected] | 1c58a5c | 2009-05-21 18:47:14 | [diff] [blame] | 19 | #include "chrome/common/notification_service.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 20 | #include "chrome/test/automation/automation_messages.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 21 | |
| 22 | static const wchar_t kWindowObjectKey[] = L"ChromeWindowObject"; |
| 23 | |
| 24 | // TODO(sanjeevr): The external_accel_table_ and external_accel_entry_count_ |
| 25 | // member variables are now obsolete and we don't use them. |
| 26 | // We need to remove them. |
| 27 | ExternalTabContainer::ExternalTabContainer( |
| 28 | AutomationProvider* automation) |
| 29 | : automation_(automation), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 30 | tab_contents_(NULL), |
| 31 | external_accel_table_(NULL), |
| 32 | external_accel_entry_count_(0), |
[email protected] | 2e39d2e | 2009-02-19 18:41:31 | [diff] [blame] | 33 | tab_contents_container_(NULL), |
[email protected] | eac83f0 | 2009-05-08 18:44:44 | [diff] [blame] | 34 | tab_handle_(0), |
[email protected] | 2e39d2e | 2009-02-19 18:41:31 | [diff] [blame] | 35 | ignore_next_load_notification_(false) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | ExternalTabContainer::~ExternalTabContainer() { |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 39 | Uninitialize(GetNativeView()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 40 | } |
| 41 | |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 42 | bool ExternalTabContainer::Init(Profile* profile, |
| 43 | HWND parent, |
| 44 | const gfx::Rect& bounds, |
| 45 | DWORD style) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 46 | if (IsWindow()) { |
| 47 | NOTREACHED(); |
| 48 | return false; |
| 49 | } |
[email protected] | 0498f7f8 | 2009-02-24 03:04:12 | [diff] [blame] | 50 | |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 51 | set_window_style(WS_POPUP); |
[email protected] | 08ed00a | 2009-05-28 20:48:14 | [diff] [blame^] | 52 | views::WidgetWin::Init(NULL, bounds, true); |
| 53 | if (!IsWindow()) { |
| 54 | NOTREACHED(); |
| 55 | return false; |
| 56 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 57 | |
| 58 | // We don't ever remove the prop because the lifetime of this object |
| 59 | // is the same as the lifetime of the window |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 60 | SetProp(GetNativeView(), kWindowObjectKey, this); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 61 | |
[email protected] | c2dacc9 | 2008-10-16 23:51:38 | [diff] [blame] | 62 | views::FocusManager* focus_manager = |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 63 | views::FocusManager::GetFocusManager(GetNativeView()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 64 | focus_manager->AddKeystrokeListener(this); |
[email protected] | 0498f7f8 | 2009-02-24 03:04:12 | [diff] [blame] | 65 | |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 66 | tab_contents_ = new TabContents(profile, NULL, MSG_ROUTING_NONE, NULL); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 67 | tab_contents_->set_delegate(this); |
[email protected] | 3ff3493 | 2009-04-07 16:48:07 | [diff] [blame] | 68 | tab_contents_->render_view_host()->AllowExternalHostBindings(); |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 69 | |
[email protected] | 610d36a | 2009-05-22 23:00:38 | [diff] [blame] | 70 | // Create a TabContentsContainer to handle focus cycling using Tab and |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 71 | // Shift-Tab. |
[email protected] | 610d36a | 2009-05-22 23:00:38 | [diff] [blame] | 72 | tab_contents_container_ = new TabContentsContainer; |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 73 | SetContentsView(tab_contents_container_); |
| 74 | |
[email protected] | b9d22749 | 2009-02-10 15:20:27 | [diff] [blame] | 75 | // Note that SetTabContents must be called after AddChildView is called |
[email protected] | 610d36a | 2009-05-22 23:00:38 | [diff] [blame] | 76 | tab_contents_container_->ChangeTabContents(tab_contents_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 77 | |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 78 | NavigationController* controller = &tab_contents_->controller(); |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 79 | registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, |
[email protected] | 0e8db94 | 2008-09-24 21:21:48 | [diff] [blame] | 80 | Source<NavigationController>(controller)); |
[email protected] | 2e39d2e | 2009-02-19 18:41:31 | [diff] [blame] | 81 | registrar_.Add(this, NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR, |
| 82 | Source<NavigationController>(controller)); |
[email protected] | 33ee8da | 2009-04-16 17:45:37 | [diff] [blame] | 83 | registrar_.Add(this, NotificationType::LOAD_STOP, |
| 84 | Source<NavigationController>(controller)); |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 85 | NotificationService::current()->Notify( |
| 86 | NotificationType::EXTERNAL_TAB_CREATED, |
| 87 | Source<NavigationController>(controller), |
| 88 | NotificationService::NoDetails()); |
[email protected] | 31fb11052 | 2009-01-28 21:50:39 | [diff] [blame] | 89 | |
[email protected] | 0498f7f8 | 2009-02-24 03:04:12 | [diff] [blame] | 90 | // We need WS_POPUP to be on the window during initialization, but |
| 91 | // once initialized we apply the requested style which may or may not |
| 92 | // include the popup bit. |
| 93 | // Note that it's important to do this before we call SetParent since |
| 94 | // during the SetParent call we will otherwise get a WA_ACTIVATE call |
| 95 | // that causes us to steal the current focus. |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 96 | SetWindowLong(GWL_STYLE, (GetWindowLong(GWL_STYLE) & ~WS_POPUP) | style); |
[email protected] | 0498f7f8 | 2009-02-24 03:04:12 | [diff] [blame] | 97 | |
[email protected] | 31fb11052 | 2009-01-28 21:50:39 | [diff] [blame] | 98 | // Now apply the parenting and style |
| 99 | if (parent) |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 100 | SetParent(GetNativeView(), parent); |
[email protected] | 7e50312 | 2009-02-04 21:52:48 | [diff] [blame] | 101 | |
[email protected] | 0498f7f8 | 2009-02-24 03:04:12 | [diff] [blame] | 102 | ::ShowWindow(tab_contents_->GetNativeView(), SW_SHOWNA); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 103 | return true; |
| 104 | } |
| 105 | |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 106 | void ExternalTabContainer::SetAccelerators(HACCEL accel_table, |
| 107 | int accel_table_entry_count) { |
| 108 | external_accel_table_ = accel_table; |
| 109 | external_accel_entry_count_ = accel_table_entry_count; |
| 110 | } |
[email protected] | 91d8fbcc | 2009-03-05 02:09:41 | [diff] [blame] | 111 | |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 112 | void ExternalTabContainer::ProcessUnhandledAccelerator(const MSG& msg) { |
| 113 | // We just received an accelerator key that we had sent to external host |
| 114 | // back. Since the external host was not interested in handling this, we |
| 115 | // need to dispatch this message as if we had just peeked this out. (we |
| 116 | // also need to call TranslateMessage to generate a WM_CHAR if needed). |
| 117 | TranslateMessage(&msg); |
| 118 | DispatchMessage(&msg); |
| 119 | } |
| 120 | |
| 121 | void ExternalTabContainer::SetInitialFocus(bool reverse) { |
| 122 | DCHECK(tab_contents_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 123 | if (tab_contents_) { |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 124 | static_cast<TabContents*>(tab_contents_)->Focus(); |
| 125 | static_cast<TabContents*>(tab_contents_)->SetInitialFocus(reverse); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 126 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 127 | } |
| 128 | |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 129 | // static |
| 130 | bool ExternalTabContainer::IsExternalTabContainer(HWND window) { |
[email protected] | 5cdc8bd | 2009-05-27 23:01:21 | [diff] [blame] | 131 | if (GetProp(window, kWindowObjectKey) != NULL) |
| 132 | return true; |
| 133 | |
| 134 | return false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 135 | } |
| 136 | |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 137 | // static |
| 138 | ExternalTabContainer* ExternalTabContainer::GetContainerForTab( |
| 139 | HWND tab_window) { |
| 140 | HWND parent_window = ::GetParent(tab_window); |
| 141 | if (!::IsWindow(parent_window)) { |
| 142 | return NULL; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 143 | } |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 144 | if (!IsExternalTabContainer(parent_window)) { |
| 145 | return NULL; |
| 146 | } |
| 147 | ExternalTabContainer* container = reinterpret_cast<ExternalTabContainer*>( |
| 148 | GetProp(parent_window, kWindowObjectKey)); |
| 149 | return container; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 150 | } |
| 151 | |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 152 | //////////////////////////////////////////////////////////////////////////////// |
| 153 | // ExternalTabContainer, TabContentsDelegate implementation: |
[email protected] | 72baf676 | 2009-05-06 18:45:33 | [diff] [blame] | 154 | |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 155 | void ExternalTabContainer::OpenURLFromTab(TabContents* source, |
| 156 | const GURL& url, |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 157 | const GURL& referrer, |
[email protected] | e38f4015 | 2008-09-12 23:08:30 | [diff] [blame] | 158 | WindowOpenDisposition disposition, |
| 159 | PageTransition::Type transition) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 160 | switch (disposition) { |
| 161 | case CURRENT_TAB: |
[email protected] | fba16f5 | 2009-04-02 22:30:35 | [diff] [blame] | 162 | case SINGLETON_TAB: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 163 | case NEW_FOREGROUND_TAB: |
| 164 | case NEW_BACKGROUND_TAB: |
| 165 | case NEW_WINDOW: |
| 166 | if (automation_) { |
[email protected] | eac83f0 | 2009-05-08 18:44:44 | [diff] [blame] | 167 | automation_->Send(new AutomationMsg_OpenURL(0, tab_handle_, |
| 168 | url, disposition)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 169 | } |
| 170 | break; |
| 171 | default: |
| 172 | break; |
[email protected] | 6dfed10 | 2009-04-28 03:09:53 | [diff] [blame] | 173 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | void ExternalTabContainer::NavigationStateChanged(const TabContents* source, |
[email protected] | b9d22749 | 2009-02-10 15:20:27 | [diff] [blame] | 177 | unsigned changed_flags) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 178 | if (automation_) { |
[email protected] | eac83f0 | 2009-05-08 18:44:44 | [diff] [blame] | 179 | automation_->Send(new AutomationMsg_NavigationStateChanged(0, tab_handle_, |
| 180 | changed_flags)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 181 | } |
| 182 | } |
| 183 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 184 | void ExternalTabContainer::AddNewContents(TabContents* source, |
| 185 | TabContents* new_contents, |
| 186 | WindowOpenDisposition disposition, |
| 187 | const gfx::Rect& initial_pos, |
| 188 | bool user_gesture) { |
[email protected] | 9f5b80a | 2009-04-08 01:26:07 | [diff] [blame] | 189 | if (disposition == NEW_POPUP || disposition == NEW_WINDOW) { |
| 190 | Browser::BuildPopupWindowHelper(source, new_contents, initial_pos, |
| 191 | Browser::TYPE_POPUP, |
| 192 | tab_contents_->profile(), true); |
| 193 | } else { |
| 194 | NOTREACHED(); |
| 195 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 196 | } |
| 197 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 198 | void ExternalTabContainer::ActivateContents(TabContents* contents) { |
| 199 | } |
| 200 | |
| 201 | void ExternalTabContainer::LoadingStateChanged(TabContents* source) { |
| 202 | } |
| 203 | |
| 204 | void ExternalTabContainer::CloseContents(TabContents* source) { |
| 205 | } |
| 206 | |
[email protected] | b9d22749 | 2009-02-10 15:20:27 | [diff] [blame] | 207 | void ExternalTabContainer::MoveContents(TabContents* source, |
| 208 | const gfx::Rect& pos) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | bool ExternalTabContainer::IsPopup(TabContents* source) { |
| 212 | return false; |
| 213 | } |
| 214 | |
[email protected] | b9d22749 | 2009-02-10 15:20:27 | [diff] [blame] | 215 | void ExternalTabContainer::URLStarredChanged(TabContents* source, |
| 216 | bool starred) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | void ExternalTabContainer::UpdateTargetURL(TabContents* source, |
| 220 | const GURL& url) { |
| 221 | if (automation_) { |
| 222 | std::wstring url_string = CA2W(url.spec().c_str()); |
| 223 | automation_->Send( |
[email protected] | eac83f0 | 2009-05-08 18:44:44 | [diff] [blame] | 224 | new AutomationMsg_UpdateTargetUrl(0, tab_handle_, url_string)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 225 | } |
| 226 | } |
| 227 | |
| 228 | void ExternalTabContainer::ContentsZoomChange(bool zoom_in) { |
| 229 | } |
| 230 | |
| 231 | void ExternalTabContainer::ToolbarSizeChanged(TabContents* source, |
[email protected] | b9d22749 | 2009-02-10 15:20:27 | [diff] [blame] | 232 | bool finished) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 233 | } |
| 234 | |
[email protected] | 18cb257 | 2008-08-21 20:34:45 | [diff] [blame] | 235 | void ExternalTabContainer::ForwardMessageToExternalHost( |
[email protected] | 2879092 | 2009-03-09 19:48:37 | [diff] [blame] | 236 | const std::string& message, const std::string& origin, |
| 237 | const std::string& target) { |
[email protected] | 5e40e26 | 2008-08-15 20:33:28 | [diff] [blame] | 238 | if(automation_) { |
| 239 | automation_->Send( |
[email protected] | eac83f0 | 2009-05-08 18:44:44 | [diff] [blame] | 240 | new AutomationMsg_ForwardMessageToExternalHost(0, tab_handle_, |
| 241 | message, origin, target)); |
[email protected] | 5e40e26 | 2008-08-15 20:33:28 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 245 | ExtensionFunctionDispatcher* ExternalTabContainer:: |
| 246 | CreateExtensionFunctionDispatcher(RenderViewHost* render_view_host, |
| 247 | const std::string& extension_id) { |
| 248 | return new ExtensionFunctionDispatcher(render_view_host, NULL, extension_id); |
| 249 | } |
| 250 | |
[email protected] | 1e0a02d6 | 2009-04-23 22:55:56 | [diff] [blame] | 251 | bool ExternalTabContainer::TakeFocus(bool reverse) { |
| 252 | if (automation_) { |
| 253 | views::FocusManager* focus_manager = |
| 254 | views::FocusManager::GetFocusManager(GetNativeView()); |
| 255 | DCHECK(focus_manager); |
| 256 | if (focus_manager) { |
| 257 | focus_manager->ClearFocus(); |
[email protected] | eac83f0 | 2009-05-08 18:44:44 | [diff] [blame] | 258 | automation_->Send(new AutomationMsg_TabbedOut(0, tab_handle_, |
[email protected] | 1e0a02d6 | 2009-04-23 22:55:56 | [diff] [blame] | 259 | win_util::IsShiftPressed())); |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | return true; |
| 264 | } |
| 265 | |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 266 | //////////////////////////////////////////////////////////////////////////////// |
| 267 | // ExternalTabContainer, NotificationObserver implementation: |
| 268 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 269 | void ExternalTabContainer::Observe(NotificationType type, |
| 270 | const NotificationSource& source, |
| 271 | const NotificationDetails& details) { |
[email protected] | 33ee8da | 2009-04-16 17:45:37 | [diff] [blame] | 272 | if (!automation_) |
| 273 | return; |
| 274 | |
[email protected] | 2e39d2e | 2009-02-19 18:41:31 | [diff] [blame] | 275 | static const int kHttpClientErrorStart = 400; |
| 276 | static const int kHttpServerErrorEnd = 510; |
| 277 | |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 278 | switch (type.value) { |
[email protected] | 33ee8da | 2009-04-16 17:45:37 | [diff] [blame] | 279 | case NotificationType::LOAD_STOP: { |
| 280 | const LoadNotificationDetails* load = |
| 281 | Details<LoadNotificationDetails>(details).ptr(); |
[email protected] | d86153f | 2009-05-18 21:10:52 | [diff] [blame] | 282 | if (load != NULL && PageTransition::IsMainFrame(load->origin())) { |
[email protected] | eac83f0 | 2009-05-08 18:44:44 | [diff] [blame] | 283 | automation_->Send(new AutomationMsg_TabLoaded(0, tab_handle_, |
| 284 | load->url())); |
[email protected] | 33ee8da | 2009-04-16 17:45:37 | [diff] [blame] | 285 | } |
| 286 | break; |
[email protected] | 2e39d2e | 2009-02-19 18:41:31 | [diff] [blame] | 287 | } |
[email protected] | 33ee8da | 2009-04-16 17:45:37 | [diff] [blame] | 288 | case NotificationType::NAV_ENTRY_COMMITTED: { |
| 289 | if (ignore_next_load_notification_) { |
| 290 | ignore_next_load_notification_ = false; |
| 291 | return; |
| 292 | } |
[email protected] | 2e39d2e | 2009-02-19 18:41:31 | [diff] [blame] | 293 | |
[email protected] | 0e8db94 | 2008-09-24 21:21:48 | [diff] [blame] | 294 | const NavigationController::LoadCommittedDetails* commit = |
| 295 | Details<NavigationController::LoadCommittedDetails>(details).ptr(); |
| 296 | |
[email protected] | f0a51fb5 | 2009-03-05 12:46:38 | [diff] [blame] | 297 | if (commit->http_status_code >= kHttpClientErrorStart && |
[email protected] | 2e39d2e | 2009-02-19 18:41:31 | [diff] [blame] | 298 | commit->http_status_code <= kHttpServerErrorEnd) { |
| 299 | automation_->Send(new AutomationMsg_NavigationFailed( |
[email protected] | eac83f0 | 2009-05-08 18:44:44 | [diff] [blame] | 300 | 0, tab_handle_, commit->http_status_code, commit->entry->url())); |
[email protected] | 2e39d2e | 2009-02-19 18:41:31 | [diff] [blame] | 301 | |
| 302 | ignore_next_load_notification_ = true; |
| 303 | } else { |
| 304 | // When the previous entry index is invalid, it will be -1, which |
| 305 | // will still make the computation come out right (navigating to the |
| 306 | // 0th entry will be +1). |
| 307 | automation_->Send(new AutomationMsg_DidNavigate( |
[email protected] | eac83f0 | 2009-05-08 18:44:44 | [diff] [blame] | 308 | 0, tab_handle_, commit->type, |
[email protected] | 2e39d2e | 2009-02-19 18:41:31 | [diff] [blame] | 309 | commit->previous_entry_index - |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 310 | tab_contents_->controller().last_committed_entry_index(), |
[email protected] | dc7588ee | 2009-03-06 21:30:08 | [diff] [blame] | 311 | commit->entry->url())); |
[email protected] | 2e39d2e | 2009-02-19 18:41:31 | [diff] [blame] | 312 | } |
[email protected] | 33ee8da | 2009-04-16 17:45:37 | [diff] [blame] | 313 | break; |
[email protected] | 0e8db94 | 2008-09-24 21:21:48 | [diff] [blame] | 314 | } |
[email protected] | 2e39d2e | 2009-02-19 18:41:31 | [diff] [blame] | 315 | case NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR: { |
[email protected] | 33ee8da | 2009-04-16 17:45:37 | [diff] [blame] | 316 | const ProvisionalLoadDetails* load_details = |
| 317 | Details<ProvisionalLoadDetails>(details).ptr(); |
| 318 | automation_->Send(new AutomationMsg_NavigationFailed( |
[email protected] | eac83f0 | 2009-05-08 18:44:44 | [diff] [blame] | 319 | 0, tab_handle_, load_details->error_code(), load_details->url())); |
[email protected] | 2e39d2e | 2009-02-19 18:41:31 | [diff] [blame] | 320 | |
[email protected] | 33ee8da | 2009-04-16 17:45:37 | [diff] [blame] | 321 | ignore_next_load_notification_ = true; |
[email protected] | 2e39d2e | 2009-02-19 18:41:31 | [diff] [blame] | 322 | break; |
| 323 | } |
[email protected] | 0e8db94 | 2008-09-24 21:21:48 | [diff] [blame] | 324 | default: |
| 325 | NOTREACHED(); |
| 326 | } |
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 | //////////////////////////////////////////////////////////////////////////////// |
| 330 | // ExternalTabContainer, views::WidgetWin overrides: |
| 331 | |
| 332 | void ExternalTabContainer::OnDestroy() { |
| 333 | Uninitialize(GetNativeView()); |
| 334 | WidgetWin::OnDestroy(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 335 | } |
| 336 | |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 337 | //////////////////////////////////////////////////////////////////////////////// |
| 338 | // ExternalTabContainer, views::KeystrokeListener implementation: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 339 | |
[email protected] | 060254c | 2009-05-02 16:45:27 | [diff] [blame] | 340 | bool ExternalTabContainer::ProcessKeyStroke(HWND window, UINT message, |
| 341 | WPARAM wparam, LPARAM lparam) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 342 | if (!automation_) { |
| 343 | return false; |
| 344 | } |
| 345 | if ((wparam == VK_TAB) && !win_util::IsCtrlPressed()) { |
| 346 | // Tabs are handled separately (except if this is Ctrl-Tab or |
| 347 | // Ctrl-Shift-Tab) |
| 348 | return false; |
| 349 | } |
[email protected] | 060254c | 2009-05-02 16:45:27 | [diff] [blame] | 350 | |
| 351 | unsigned int flags = HIWORD(lparam); |
| 352 | bool alt = (flags & KF_ALTDOWN) != 0; |
| 353 | if (!alt && (message == WM_SYSKEYUP || message == WM_KEYUP)) { |
| 354 | // In case the Alt key is being released. |
| 355 | alt = (wparam == VK_MENU); |
| 356 | } |
| 357 | |
| 358 | if ((flags & KF_EXTENDED) || alt || (wparam >= VK_F1 && wparam <= VK_F24) || |
| 359 | wparam == VK_ESCAPE || wparam == VK_RETURN || |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 360 | win_util::IsShiftPressed() || win_util::IsCtrlPressed()) { |
| 361 | // If this is an extended key or if one or more of Alt, Shift and Control |
| 362 | // are pressed, this might be an accelerator that the external host wants |
| 363 | // to handle. If the host does not handle this accelerator, it will reflect |
| 364 | // the accelerator back to us via the ProcessUnhandledAccelerator method. |
| 365 | MSG msg = {0}; |
| 366 | msg.hwnd = window; |
| 367 | msg.message = message; |
| 368 | msg.wParam = wparam; |
| 369 | msg.lParam = lparam; |
[email protected] | eac83f0 | 2009-05-08 18:44:44 | [diff] [blame] | 370 | automation_->Send(new AutomationMsg_HandleAccelerator(0, tab_handle_, msg)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 371 | return true; |
| 372 | } |
[email protected] | 060254c | 2009-05-02 16:45:27 | [diff] [blame] | 373 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 374 | return false; |
| 375 | } |
| 376 | |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 377 | //////////////////////////////////////////////////////////////////////////////// |
| 378 | // ExternalTabContainer, private: |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 379 | |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 380 | void ExternalTabContainer::Uninitialize(HWND window) { |
| 381 | if (::IsWindow(window)) { |
| 382 | views::FocusManager* focus_manager = |
| 383 | views::FocusManager::GetFocusManager(window); |
| 384 | if (focus_manager) |
| 385 | focus_manager->RemoveKeystrokeListener(this); |
| 386 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 387 | |
[email protected] | b9d22749 | 2009-02-10 15:20:27 | [diff] [blame] | 388 | if (tab_contents_) { |
[email protected] | 9095e98 | 2009-05-27 17:28:24 | [diff] [blame] | 389 | NotificationService::current()->Notify( |
| 390 | NotificationType::EXTERNAL_TAB_CLOSED, |
| 391 | Source<NavigationController>(&tab_contents_->controller()), |
| 392 | Details<ExternalTabContainer>(this)); |
| 393 | |
| 394 | delete tab_contents_; |
| 395 | tab_contents_ = NULL; |
[email protected] | b9d22749 | 2009-02-10 15:20:27 | [diff] [blame] | 396 | } |
| 397 | } |
| 398 | |