| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/external_tab_container.h" | 5 #include "chrome/browser/external_tab_container.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "app/win_util.h" | 10 #include "app/win_util.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/win_util.h" | 12 #include "base/win_util.h" |
| 13 #include "chrome/browser/automation/automation_provider.h" | 13 #include "chrome/browser/automation/automation_provider.h" |
| 14 #include "chrome/browser/browser_window.h" | 14 #include "chrome/browser/browser_window.h" |
| 15 #include "chrome/browser/load_notification_details.h" | 15 #include "chrome/browser/load_notification_details.h" |
| 16 #include "chrome/browser/profile.h" | 16 #include "chrome/browser/profile.h" |
| 17 #include "chrome/browser/tab_contents/provisional_load_details.h" | 17 #include "chrome/browser/tab_contents/provisional_load_details.h" |
| 18 #include "chrome/browser/views/tab_contents/render_view_context_menu_external_wi
n.h" | 18 #include "chrome/browser/views/tab_contents/render_view_context_menu_external_wi
n.h" |
| 19 #include "chrome/browser/tab_contents/tab_contents.h" | 19 #include "chrome/browser/tab_contents/tab_contents.h" |
| 20 #include "chrome/browser/views/tab_contents/tab_contents_container.h" | 20 #include "chrome/browser/views/tab_contents/tab_contents_container.h" |
| 21 #include "chrome/common/bindings_policy.h" | 21 #include "chrome/common/bindings_policy.h" |
| 22 #include "chrome/common/chrome_constants.h" | 22 #include "chrome/common/chrome_constants.h" |
| 23 #include "chrome/common/notification_service.h" | 23 #include "chrome/common/notification_service.h" |
| 24 #include "chrome/test/automation/automation_messages.h" | 24 #include "chrome/test/automation/automation_messages.h" |
| 25 | 25 |
| 26 #include "grit/generated_resources.h" | 26 #include "grit/generated_resources.h" |
| 27 | 27 |
| 28 static const wchar_t kWindowObjectKey[] = L"ChromeWindowObject"; | 28 static const wchar_t kWindowObjectKey[] = L"ChromeWindowObject"; |
| 29 | 29 |
| 30 ExternalTabContainer::PendingTabs ExternalTabContainer::pending_tabs_; |
| 31 |
| 30 ExternalTabContainer::ExternalTabContainer( | 32 ExternalTabContainer::ExternalTabContainer( |
| 31 AutomationProvider* automation, AutomationResourceMessageFilter* filter) | 33 AutomationProvider* automation, AutomationResourceMessageFilter* filter) |
| 32 : automation_(automation), | 34 : automation_(automation), |
| 33 tab_contents_(NULL), | 35 tab_contents_(NULL), |
| 34 tab_contents_container_(NULL), | 36 tab_contents_container_(NULL), |
| 35 tab_handle_(0), | 37 tab_handle_(0), |
| 36 ignore_next_load_notification_(false), | 38 ignore_next_load_notification_(false), |
| 37 automation_resource_message_filter_(filter), | 39 automation_resource_message_filter_(filter), |
| 38 load_requests_via_automation_(false), | 40 load_requests_via_automation_(false), |
| 39 handle_top_level_requests_(false) { | 41 handle_top_level_requests_(false) { |
| 40 } | 42 } |
| 41 | 43 |
| 42 ExternalTabContainer::~ExternalTabContainer() { | 44 ExternalTabContainer::~ExternalTabContainer() { |
| 43 Uninitialize(GetNativeView()); | 45 Uninitialize(); |
| 44 } | 46 } |
| 45 | 47 |
| 46 bool ExternalTabContainer::Init(Profile* profile, | 48 bool ExternalTabContainer::Init(Profile* profile, |
| 47 HWND parent, | 49 HWND parent, |
| 48 const gfx::Rect& bounds, | 50 const gfx::Rect& bounds, |
| 49 DWORD style, | 51 DWORD style, |
| 50 bool load_requests_via_automation, | 52 bool load_requests_via_automation, |
| 51 bool handle_top_level_requests, | 53 bool handle_top_level_requests, |
| 52 TabContents* existing_contents) { | 54 TabContents* existing_contents) { |
| 53 if (IsWindow()) { | 55 if (IsWindow()) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 74 // Customize our profile. | 76 // Customize our profile. |
| 75 // TODO(joshia): If we are loading requests via automation | 77 // TODO(joshia): If we are loading requests via automation |
| 76 // and handling cookies in automation then it's probably better to | 78 // and handling cookies in automation then it's probably better to |
| 77 // use OTR profile so that cookies are not persisted in chrome. | 79 // use OTR profile so that cookies are not persisted in chrome. |
| 78 automation_profile_.reset(new AutomationProfileImpl); | 80 automation_profile_.reset(new AutomationProfileImpl); |
| 79 automation_profile_->Initialize(profile, | 81 automation_profile_->Initialize(profile, |
| 80 automation_resource_message_filter_); | 82 automation_resource_message_filter_); |
| 81 profile = automation_profile_.get(); | 83 profile = automation_profile_.get(); |
| 82 } | 84 } |
| 83 | 85 |
| 84 if (existing_contents) | 86 if (existing_contents) { |
| 85 tab_contents_ = existing_contents; | 87 tab_contents_ = existing_contents; |
| 86 else | 88 tab_contents_->controller().set_profile(profile); |
| 89 } else { |
| 87 tab_contents_ = new TabContents(profile, NULL, MSG_ROUTING_NONE, NULL); | 90 tab_contents_ = new TabContents(profile, NULL, MSG_ROUTING_NONE, NULL); |
| 91 } |
| 88 | 92 |
| 89 tab_contents_->set_delegate(this); | 93 tab_contents_->set_delegate(this); |
| 94 |
| 90 tab_contents_->GetMutableRendererPrefs()->browser_handles_top_level_requests = | 95 tab_contents_->GetMutableRendererPrefs()->browser_handles_top_level_requests = |
| 91 handle_top_level_requests; | 96 handle_top_level_requests; |
| 92 | 97 |
| 93 if (!existing_contents) { | 98 if (!existing_contents) { |
| 94 tab_contents_->render_view_host()->AllowBindings( | 99 tab_contents_->render_view_host()->AllowBindings( |
| 95 BindingsPolicy::EXTERNAL_HOST); | 100 BindingsPolicy::EXTERNAL_HOST); |
| 96 } | 101 } |
| 97 | 102 |
| 98 // Create a TabContentsContainer to handle focus cycling using Tab and | 103 // Create a TabContentsContainer to handle focus cycling using Tab and |
| 99 // Shift-Tab. | 104 // Shift-Tab. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 if (parent) | 137 if (parent) |
| 133 SetParent(GetNativeView(), parent); | 138 SetParent(GetNativeView(), parent); |
| 134 | 139 |
| 135 ::ShowWindow(tab_contents_->GetNativeView(), SW_SHOWNA); | 140 ::ShowWindow(tab_contents_->GetNativeView(), SW_SHOWNA); |
| 136 | 141 |
| 137 disabled_context_menu_ids_.push_back( | 142 disabled_context_menu_ids_.push_back( |
| 138 IDS_CONTENT_CONTEXT_OPENLINKOFFTHERECORD); | 143 IDS_CONTENT_CONTEXT_OPENLINKOFFTHERECORD); |
| 139 return true; | 144 return true; |
| 140 } | 145 } |
| 141 | 146 |
| 147 void ExternalTabContainer::Uninitialize() { |
| 148 registrar_.RemoveAll(); |
| 149 if (tab_contents_) { |
| 150 NotificationService::current()->Notify( |
| 151 NotificationType::EXTERNAL_TAB_CLOSED, |
| 152 Source<NavigationController>(&tab_contents_->controller()), |
| 153 Details<ExternalTabContainer>(this)); |
| 154 |
| 155 delete tab_contents_; |
| 156 tab_contents_ = NULL; |
| 157 } |
| 158 } |
| 159 |
| 160 bool ExternalTabContainer::Reinitialize( |
| 161 AutomationProvider* automation_provider, |
| 162 AutomationResourceMessageFilter* filter) { |
| 163 if (!automation_provider || !filter) { |
| 164 NOTREACHED(); |
| 165 return false; |
| 166 } |
| 167 |
| 168 automation_ = automation_provider; |
| 169 automation_resource_message_filter_ = filter; |
| 170 |
| 171 if (load_requests_via_automation_) { |
| 172 RenderViewHost* rvh = tab_contents_->render_view_host(); |
| 173 if (rvh) { |
| 174 AutomationResourceMessageFilter::RegisterRenderView( |
| 175 rvh->process()->id(), rvh->routing_id(), |
| 176 tab_handle_, automation_resource_message_filter_); |
| 177 } |
| 178 |
| 179 DCHECK(automation_profile_.get() != NULL); |
| 180 Profile* profile = tab_contents_->profile()->GetOriginalProfile(); |
| 181 DCHECK(profile != NULL); |
| 182 automation_profile_->Initialize(profile, filter); |
| 183 } |
| 184 |
| 185 return true; |
| 186 } |
| 187 |
| 142 void ExternalTabContainer::ProcessUnhandledAccelerator(const MSG& msg) { | 188 void ExternalTabContainer::ProcessUnhandledAccelerator(const MSG& msg) { |
| 143 DefWindowProc(msg.hwnd, msg.message, msg.wParam, msg.lParam); | 189 DefWindowProc(msg.hwnd, msg.message, msg.wParam, msg.lParam); |
| 144 } | 190 } |
| 145 | 191 |
| 146 void ExternalTabContainer::FocusThroughTabTraversal(bool reverse) { | 192 void ExternalTabContainer::FocusThroughTabTraversal(bool reverse) { |
| 147 DCHECK(tab_contents_); | 193 DCHECK(tab_contents_); |
| 148 if (tab_contents_) { | 194 if (tab_contents_) { |
| 149 static_cast<TabContents*>(tab_contents_)->Focus(); | 195 static_cast<TabContents*>(tab_contents_)->Focus(); |
| 150 static_cast<TabContents*>(tab_contents_)->FocusThroughTabTraversal(reverse); | 196 static_cast<TabContents*>(tab_contents_)->FocusThroughTabTraversal(reverse); |
| 151 } | 197 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 Browser::BuildPopupWindowHelper(source, new_contents, initial_pos, | 268 Browser::BuildPopupWindowHelper(source, new_contents, initial_pos, |
| 223 Browser::TYPE_POPUP, | 269 Browser::TYPE_POPUP, |
| 224 tab_contents_->profile(), true); | 270 tab_contents_->profile(), true); |
| 225 break; | 271 break; |
| 226 } | 272 } |
| 227 | 273 |
| 228 case NEW_FOREGROUND_TAB: | 274 case NEW_FOREGROUND_TAB: |
| 229 case NEW_BACKGROUND_TAB: { | 275 case NEW_BACKGROUND_TAB: { |
| 230 DCHECK(automation_ != NULL); | 276 DCHECK(automation_ != NULL); |
| 231 | 277 |
| 232 ExternalTabContainer* new_container = | 278 scoped_refptr<ExternalTabContainer> new_container = |
| 233 new ExternalTabContainer(automation_, | 279 new ExternalTabContainer(NULL, NULL); |
| 234 automation_resource_message_filter_); | |
| 235 bool result = new_container->Init(automation_profile_.get(), | |
| 236 NULL, | |
| 237 initial_pos, | |
| 238 WS_CHILD, | |
| 239 load_requests_via_automation_, | |
| 240 handle_top_level_requests_, | |
| 241 new_contents); | |
| 242 DCHECK(result); | |
| 243 result = automation_->AddExternalTab(new_container); | |
| 244 DCHECK(result); | |
| 245 | 280 |
| 246 automation_->Send(new AutomationMsg_AttachExternalTab( | 281 // Make sure that ExternalTabContainer instance is initialized with |
| 247 0, tab_handle_, new_container->tab_handle(), | 282 // an unwrapped Profile. |
| 248 new_container->GetNativeView(), new_contents->GetNativeView(), | 283 bool result = new_container->Init( |
| 249 disposition)); | 284 new_contents->profile()->GetOriginalProfile(), |
| 285 NULL, |
| 286 initial_pos, |
| 287 WS_CHILD, |
| 288 load_requests_via_automation_, |
| 289 handle_top_level_requests_, |
| 290 new_contents); |
| 291 |
| 292 if (result) { |
| 293 pending_tabs_[reinterpret_cast<intptr_t>(new_container.get())] = |
| 294 new_container; |
| 295 |
| 296 automation_->Send(new AutomationMsg_AttachExternalTab( |
| 297 0, |
| 298 tab_handle_, |
| 299 reinterpret_cast<intptr_t>(new_container.get()), |
| 300 disposition)); |
| 301 } else { |
| 302 NOTREACHED(); |
| 303 } |
| 250 break; | 304 break; |
| 251 } | 305 } |
| 252 | 306 |
| 253 default: | 307 default: |
| 254 NOTREACHED(); | 308 NOTREACHED(); |
| 255 break; | 309 break; |
| 256 } | 310 } |
| 257 } | 311 } |
| 258 | 312 |
| 259 void ExternalTabContainer::ActivateContents(TabContents* contents) { | 313 void ExternalTabContainer::ActivateContents(TabContents* contents) { |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 break; | 500 break; |
| 447 } | 501 } |
| 448 default: | 502 default: |
| 449 NOTREACHED(); | 503 NOTREACHED(); |
| 450 } | 504 } |
| 451 } | 505 } |
| 452 | 506 |
| 453 //////////////////////////////////////////////////////////////////////////////// | 507 //////////////////////////////////////////////////////////////////////////////// |
| 454 // ExternalTabContainer, views::WidgetWin overrides: | 508 // ExternalTabContainer, views::WidgetWin overrides: |
| 455 | 509 |
| 510 LRESULT ExternalTabContainer::OnCreate(LPCREATESTRUCT create_struct) { |
| 511 LRESULT result = views::WidgetWin::OnCreate(create_struct); |
| 512 if (result == 0) { |
| 513 // Grab a reference here which will be released in OnFinalMessage |
| 514 AddRef(); |
| 515 } |
| 516 return result; |
| 517 } |
| 518 |
| 456 void ExternalTabContainer::OnDestroy() { | 519 void ExternalTabContainer::OnDestroy() { |
| 457 Uninitialize(GetNativeView()); | 520 Uninitialize(); |
| 458 WidgetWin::OnDestroy(); | 521 WidgetWin::OnDestroy(); |
| 459 if (browser_.get()) { | 522 if (browser_.get()) { |
| 460 ::DestroyWindow(browser_->window()->GetNativeHandle()); | 523 ::DestroyWindow(browser_->window()->GetNativeHandle()); |
| 461 } | 524 } |
| 462 } | 525 } |
| 463 | 526 |
| 527 void ExternalTabContainer::OnFinalMessage(HWND window) { |
| 528 // Release the reference which we grabbed in WM_CREATE. |
| 529 Release(); |
| 530 } |
| 531 |
| 464 //////////////////////////////////////////////////////////////////////////////// | 532 //////////////////////////////////////////////////////////////////////////////// |
| 465 // ExternalTabContainer, private: | 533 // ExternalTabContainer, private: |
| 466 | |
| 467 void ExternalTabContainer::Uninitialize(HWND window) { | |
| 468 registrar_.RemoveAll(); | |
| 469 if (tab_contents_) { | |
| 470 NotificationService::current()->Notify( | |
| 471 NotificationType::EXTERNAL_TAB_CLOSED, | |
| 472 Source<NavigationController>(&tab_contents_->controller()), | |
| 473 Details<ExternalTabContainer>(this)); | |
| 474 | |
| 475 delete tab_contents_; | |
| 476 tab_contents_ = NULL; | |
| 477 } | |
| 478 } | |
| 479 | |
| 480 bool ExternalTabContainer::ProcessUnhandledKeyStroke(HWND window, | 534 bool ExternalTabContainer::ProcessUnhandledKeyStroke(HWND window, |
| 481 UINT message, | 535 UINT message, |
| 482 WPARAM wparam, | 536 WPARAM wparam, |
| 483 LPARAM lparam) { | 537 LPARAM lparam) { |
| 484 if (!automation_) { | 538 if (!automation_) { |
| 485 return false; | 539 return false; |
| 486 } | 540 } |
| 487 if ((wparam == VK_TAB) && !win_util::IsCtrlPressed()) { | 541 if ((wparam == VK_TAB) && !win_util::IsCtrlPressed()) { |
| 488 // Tabs are handled separately (except if this is Ctrl-Tab or | 542 // Tabs are handled separately (except if this is Ctrl-Tab or |
| 489 // Ctrl-Shift-Tab) | 543 // Ctrl-Shift-Tab) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 | 581 |
| 528 nav_info->navigation_type = nav_type; | 582 nav_info->navigation_type = nav_type; |
| 529 nav_info->relative_offset = relative_offset; | 583 nav_info->relative_offset = relative_offset; |
| 530 nav_info->navigation_index = | 584 nav_info->navigation_index = |
| 531 tab_contents_->controller().GetCurrentEntryIndex(); | 585 tab_contents_->controller().GetCurrentEntryIndex(); |
| 532 nav_info->title = UTF16ToWideHack(entry->title()); | 586 nav_info->title = UTF16ToWideHack(entry->title()); |
| 533 nav_info->url = entry->url(); | 587 nav_info->url = entry->url(); |
| 534 return true; | 588 return true; |
| 535 } | 589 } |
| 536 | 590 |
| 591 ExternalTabContainer* ExternalTabContainer::RemovePendingTab(intptr_t cookie) { |
| 592 PendingTabs::iterator index = pending_tabs_.find(cookie); |
| 593 if (index != pending_tabs_.end()) { |
| 594 scoped_refptr<ExternalTabContainer> container = (*index).second; |
| 595 pending_tabs_.erase(index); |
| 596 return container.release(); |
| 597 } |
| 598 |
| 599 NOTREACHED() << "Failed to find ExternalTabContainer for cookie: " |
| 600 << cookie; |
| 601 return NULL; |
| 602 } |
| 603 |
| OLD | NEW |