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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 SetProp(*this, kWindowObjectKey, this); | 57 SetProp(*this, kWindowObjectKey, this); |
58 | 58 |
59 views::SetRootViewForHWND(m_hWnd, &root_view_); | 59 views::SetRootViewForHWND(m_hWnd, &root_view_); |
60 // CreateFocusManager will subclass this window and delete the FocusManager | 60 // CreateFocusManager will subclass this window and delete the FocusManager |
61 // instance when this window goes away. | 61 // instance when this window goes away. |
62 views::FocusManager* focus_manager = | 62 views::FocusManager* focus_manager = |
63 views::FocusManager::CreateFocusManager(m_hWnd, GetRootView()); | 63 views::FocusManager::CreateFocusManager(m_hWnd, GetRootView()); |
64 | 64 |
65 DCHECK(focus_manager); | 65 DCHECK(focus_manager); |
66 focus_manager->AddKeystrokeListener(this); | 66 focus_manager->AddKeystrokeListener(this); |
67 tab_contents_ = TabContents::CreateWithType(TAB_CONTENTS_WEB, profile, | |
68 NULL, NULL); | |
69 if (!tab_contents_) { | |
70 NOTREACHED(); | |
71 DestroyWindow(); | |
72 return false; | |
73 } | |
74 | 67 |
| 68 tab_contents_ = new WebContents(profile, NULL, MSG_ROUTING_NONE, NULL); |
75 tab_contents_->SetupController(profile); | 69 tab_contents_->SetupController(profile); |
76 tab_contents_->set_delegate(this); | 70 tab_contents_->set_delegate(this); |
77 | 71 tab_contents_->render_view_host()->AllowExternalHostBindings(); |
78 WebContents* web_conents = tab_contents_->AsWebContents(); | |
79 if (web_conents) | |
80 web_conents->render_view_host()->AllowExternalHostBindings(); | |
81 | 72 |
82 // Create a TabContentsContainerView to handle focus cycling using Tab and | 73 // Create a TabContentsContainerView to handle focus cycling using Tab and |
83 // Shift-Tab. | 74 // Shift-Tab. |
84 tab_contents_container_ = new TabContentsContainerView(); | 75 tab_contents_container_ = new TabContentsContainerView(); |
85 root_view_.AddChildView(tab_contents_container_); | 76 root_view_.AddChildView(tab_contents_container_); |
86 // Note that SetTabContents must be called after AddChildView is called | 77 // Note that SetTabContents must be called after AddChildView is called |
87 tab_contents_container_->SetTabContents(tab_contents_); | 78 tab_contents_container_->SetTabContents(tab_contents_); |
88 // Add a dummy view to catch when the user tabs out of the tab | 79 // Add a dummy view to catch when the user tabs out of the tab |
89 // Create a dummy FocusTraversable object to represent the frame of the | 80 // Create a dummy FocusTraversable object to represent the frame of the |
90 // external host. This will allow Tab and Shift-Tab to cycle into the | 81 // external host. This will allow Tab and Shift-Tab to cycle into the |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 // back. Since the external host was not interested in handling this, we | 386 // back. Since the external host was not interested in handling this, we |
396 // need to dispatch this message as if we had just peeked this out. (we | 387 // need to dispatch this message as if we had just peeked this out. (we |
397 // also need to call TranslateMessage to generate a WM_CHAR if needed). | 388 // also need to call TranslateMessage to generate a WM_CHAR if needed). |
398 TranslateMessage(&msg); | 389 TranslateMessage(&msg); |
399 DispatchMessage(&msg); | 390 DispatchMessage(&msg); |
400 } | 391 } |
401 | 392 |
402 void ExternalTabContainer::SetInitialFocus(bool reverse) { | 393 void ExternalTabContainer::SetInitialFocus(bool reverse) { |
403 DCHECK(tab_contents_); | 394 DCHECK(tab_contents_); |
404 if (tab_contents_) { | 395 if (tab_contents_) { |
405 tab_contents_->SetInitialFocus(reverse); | 396 static_cast<TabContents*>(tab_contents_)->SetInitialFocus(reverse); |
406 } | 397 } |
407 } | 398 } |
408 | 399 |
409 // static | 400 // static |
410 bool ExternalTabContainer::IsExternalTabContainer(HWND window) { | 401 bool ExternalTabContainer::IsExternalTabContainer(HWND window) { |
411 std::wstring class_name = win_util::GetClassName(window); | 402 std::wstring class_name = win_util::GetClassName(window); |
412 return _wcsicmp(class_name.c_str(), chrome::kExternalTabWindowClass) == 0; | 403 return _wcsicmp(class_name.c_str(), chrome::kExternalTabWindowClass) == 0; |
413 } | 404 } |
414 | 405 |
415 // static | 406 // static |
416 ExternalTabContainer* ExternalTabContainer::GetContainerForTab( | 407 ExternalTabContainer* ExternalTabContainer::GetContainerForTab( |
417 HWND tab_window) { | 408 HWND tab_window) { |
418 HWND parent_window = ::GetParent(tab_window); | 409 HWND parent_window = ::GetParent(tab_window); |
419 if (!::IsWindow(parent_window)) { | 410 if (!::IsWindow(parent_window)) { |
420 return NULL; | 411 return NULL; |
421 } | 412 } |
422 if (!IsExternalTabContainer(parent_window)) { | 413 if (!IsExternalTabContainer(parent_window)) { |
423 return NULL; | 414 return NULL; |
424 } | 415 } |
425 ExternalTabContainer* container = reinterpret_cast<ExternalTabContainer*>( | 416 ExternalTabContainer* container = reinterpret_cast<ExternalTabContainer*>( |
426 GetProp(parent_window, kWindowObjectKey)); | 417 GetProp(parent_window, kWindowObjectKey)); |
427 return container; | 418 return container; |
428 } | 419 } |
OLD | NEW |