| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/win_util.h" | 8 #include "base/win_util.h" |
| 9 #include "chrome/browser/automation/automation_provider.h" | 9 #include "chrome/browser/automation/automation_provider.h" |
| 10 #include "chrome/browser/profile.h" | 10 #include "chrome/browser/profile.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 : automation_(automation), | 28 : automation_(automation), |
| 29 root_view_(this), | 29 root_view_(this), |
| 30 tab_contents_(NULL), | 30 tab_contents_(NULL), |
| 31 external_accel_table_(NULL), | 31 external_accel_table_(NULL), |
| 32 external_accel_entry_count_(0), | 32 external_accel_entry_count_(0), |
| 33 tab_contents_container_(NULL), | 33 tab_contents_container_(NULL), |
| 34 ignore_next_load_notification_(false) { | 34 ignore_next_load_notification_(false) { |
| 35 } | 35 } |
| 36 | 36 |
| 37 ExternalTabContainer::~ExternalTabContainer() { | 37 ExternalTabContainer::~ExternalTabContainer() { |
| 38 Uninitialize(m_hWnd); |
| 38 } | 39 } |
| 39 | 40 |
| 40 bool ExternalTabContainer::Init(Profile* profile, HWND parent, | 41 bool ExternalTabContainer::Init(Profile* profile, HWND parent, |
| 41 const gfx::Rect& dimensions, | 42 const gfx::Rect& dimensions, |
| 42 unsigned int style) { | 43 unsigned int style) { |
| 43 if (IsWindow()) { | 44 if (IsWindow()) { |
| 44 NOTREACHED(); | 45 NOTREACHED(); |
| 45 return false; | 46 return false; |
| 46 } | 47 } |
| 47 | 48 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 // Note that it's important to do this before we call SetParent since | 114 // Note that it's important to do this before we call SetParent since |
| 114 // during the SetParent call we will otherwise get a WA_ACTIVATE call | 115 // during the SetParent call we will otherwise get a WA_ACTIVATE call |
| 115 // that causes us to steal the current focus. | 116 // that causes us to steal the current focus. |
| 116 ModifyStyle(WS_POPUP, style, 0); | 117 ModifyStyle(WS_POPUP, style, 0); |
| 117 | 118 |
| 118 // Now apply the parenting and style | 119 // Now apply the parenting and style |
| 119 if (parent) | 120 if (parent) |
| 120 SetParent(parent); | 121 SetParent(parent); |
| 121 | 122 |
| 122 ::ShowWindow(tab_contents_->GetNativeView(), SW_SHOWNA); | 123 ::ShowWindow(tab_contents_->GetNativeView(), SW_SHOWNA); |
| 123 | |
| 124 return true; | 124 return true; |
| 125 } | 125 } |
| 126 | 126 |
| 127 void ExternalTabContainer::OnDestroy() { | 127 bool ExternalTabContainer::Uninitialize(HWND window) { |
| 128 views::FocusManager* focus_manager = | 128 if (::IsWindow(window)) { |
| 129 views::FocusManager::GetFocusManager(GetHWND()); | 129 views::FocusManager* focus_manager = |
| 130 if (focus_manager) { | 130 views::FocusManager::GetFocusManager(window); |
| 131 focus_manager->RemoveKeystrokeListener(this); | 131 if (focus_manager) { |
| 132 focus_manager->RemoveKeystrokeListener(this); |
| 133 } |
| 132 } | 134 } |
| 135 |
| 133 root_view_.RemoveAllChildViews(true); | 136 root_view_.RemoveAllChildViews(true); |
| 134 if (tab_contents_) { | 137 if (tab_contents_) { |
| 135 NavigationController* controller = tab_contents_->controller(); | 138 NavigationController* controller = tab_contents_->controller(); |
| 136 DCHECK(controller); | 139 DCHECK(controller); |
| 137 | 140 |
| 138 NotificationService::current()->Notify( | 141 NotificationService::current()->Notify( |
| 139 NotificationType::EXTERNAL_TAB_CLOSED, | 142 NotificationType::EXTERNAL_TAB_CLOSED, |
| 140 Source<NavigationController>(controller), | 143 Source<NavigationController>(controller), |
| 141 Details<ExternalTabContainer>(this)); | 144 Details<ExternalTabContainer>(this)); |
| 145 |
| 142 tab_contents_->set_delegate(NULL); | 146 tab_contents_->set_delegate(NULL); |
| 143 tab_contents_->CloseContents(); | 147 tab_contents_->CloseContents(); |
| 144 // WARNING: tab_contents_ has likely been deleted. | 148 // WARNING: tab_contents_ has likely been deleted. |
| 145 tab_contents_ = NULL; | 149 tab_contents_ = NULL; |
| 146 } | 150 } |
| 151 |
| 152 return true; |
| 147 } | 153 } |
| 148 | 154 |
| 149 void ExternalTabContainer::OnFinalMessage(HWND window) { | 155 void ExternalTabContainer::OnFinalMessage(HWND window) { |
| 156 Uninitialize(window); |
| 150 delete this; | 157 delete this; |
| 151 } | 158 } |
| 152 | 159 |
| 153 LRESULT ExternalTabContainer::OnSize(UINT, WPARAM, LPARAM, BOOL& handled) { | 160 LRESULT ExternalTabContainer::OnSize(UINT, WPARAM, LPARAM, BOOL& handled) { |
| 154 if (tab_contents_) { | 161 if (tab_contents_) { |
| 155 RECT client_rect = {0}; | 162 RECT client_rect = {0}; |
| 156 GetClientRect(&client_rect); | 163 GetClientRect(&client_rect); |
| 157 ::SetWindowPos(tab_contents_->GetNativeView(), NULL, client_rect.left, | 164 ::SetWindowPos(tab_contents_->GetNativeView(), NULL, client_rect.left, |
| 158 client_rect.top, client_rect.right - client_rect.left, | 165 client_rect.top, client_rect.right - client_rect.left, |
| 159 client_rect.bottom - client_rect.top, SWP_NOZORDER); | 166 client_rect.bottom - client_rect.top, SWP_NOZORDER); |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 if (!::IsWindow(parent_window)) { | 413 if (!::IsWindow(parent_window)) { |
| 407 return NULL; | 414 return NULL; |
| 408 } | 415 } |
| 409 if (!IsExternalTabContainer(parent_window)) { | 416 if (!IsExternalTabContainer(parent_window)) { |
| 410 return NULL; | 417 return NULL; |
| 411 } | 418 } |
| 412 ExternalTabContainer* container = reinterpret_cast<ExternalTabContainer*>( | 419 ExternalTabContainer* container = reinterpret_cast<ExternalTabContainer*>( |
| 413 GetProp(parent_window, kWindowObjectKey)); | 420 GetProp(parent_window, kWindowObjectKey)); |
| 414 return container; | 421 return container; |
| 415 } | 422 } |
| OLD | NEW |