Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Minimal Chrome Frame with Aura.

It builds and runs, but not a whole lot else. This change includes:

* ChromeFrameAutomationProvider is now OS_WIN only. In practice, this
  has been the case for some time. Now it's formalized by giving the
  implementation files the _win suffix.

* Automation messages and datatypes used exclusively by Chrome Frame now
  use HWND directly rather than a toolkit-specific gfx typedef of one
  since the requirement is that an actual HWND be sent over the
  channel. A change in toolkit (e.g., switching to Aura) must not change
  this. As a consequence of this change, some automation types and
  messages are now only defined for OS_WIN builds.

* ExternalTabContainerWin is no longer derived from a NativeWidget type
  (this was previously the case so that the ETCW could be notified of NW
  lifecycle events). Now, in contrast, ETCW registers itself as an
  observer of its Widget. Two additional lifecycle methods have been
  added to WidgetObserver: OnWidgetCreated and OnWidgetDestroyed.

* ExternalTabContianerWin initializes its Widget with an instance of
  DesktopNativeWidgetAura when use_aura.

* A special note about HWND IPC marshaling: this change adds a type
  mapping from HWND to a generic HANDLE in ipc_message_utils.h, which
  allows for the removal of a hack in content_message_generator.h to
  marshal HWNDs.

This change reverts all of:

* r178752 -- Remove CF from all.gyp targets if use_aura is defined.
* r164590 -- Remove setup -> Chrome Frame dependency. Make it possible
  to build an installer for Aura.

and portions of:

* r99993 -- Get chrome to link with USE_AURA
* r99787 -- Preliminary work to allow Chrome to build with USE_AURA.

BUG=171018
TEST=chrome_frame_tests provides good coverage in non-Aura builds.

Review URL: https://chromiumcodereview.appspot.com/12220101

git-svn-id: http://src.chromium.org/svn/trunk/src/chrome/browser@185328 4ff67af0-8c30-449e-8e8b-ad334ec8d88c
  • Loading branch information...
commit 81ff05225fff92cea7915787a46d5e933ff70adc 1 parent f3c85e4
grt@chromium.org authored
View
2  automation/automation_provider.cc
@@ -428,7 +428,7 @@ bool AutomationProvider::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(AutomationMsg_BeginTracing, BeginTracing)
IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_EndTracing, EndTracing)
IPC_MESSAGE_HANDLER(AutomationMsg_GetTracingOutput, GetTracingOutput)
-#if defined(OS_WIN) && !defined(USE_AURA)
+#if defined(OS_WIN)
// These are for use with external tabs.
IPC_MESSAGE_HANDLER(AutomationMsg_CreateExternalTab, CreateExternalTab)
IPC_MESSAGE_HANDLER(AutomationMsg_ProcessUnhandledAccelerator,
View
16 automation/automation_provider.h
@@ -146,7 +146,7 @@ class AutomationProvider
return reply_message;
}
-#if defined(OS_WIN) && !defined(USE_AURA)
+#if defined(OS_WIN)
// Adds the external tab passed in to the tab tracker.
bool AddExternalTab(ExternalTabContainer* external_tab);
#endif
@@ -285,7 +285,7 @@ class AutomationProvider
// Method called by the popup menu tracker when a popup menu is opened.
void NotifyPopupMenuOpened();
-#if defined(OS_WIN) && !defined(USE_AURA)
+#if defined(OS_WIN)
// The functions in this block are for use with external tabs, so they are
// Windows only.
@@ -304,16 +304,16 @@ class AutomationProvider
void OnForwardContextMenuCommandToChrome(int tab_handle, int command);
void CreateExternalTab(const ExternalTabSettings& settings,
- gfx::NativeWindow* tab_container_window,
- gfx::NativeWindow* tab_window,
+ HWND* tab_container_window,
+ HWND* tab_window,
int* tab_handle,
int* session_id);
void ConnectExternalTab(uint64 cookie,
bool allow,
- gfx::NativeWindow parent_window,
- gfx::NativeWindow* tab_container_window,
- gfx::NativeWindow* tab_window,
+ HWND parent_window,
+ HWND* tab_container_window,
+ HWND* tab_window,
int* tab_handle,
int* session_id);
@@ -335,7 +335,7 @@ class AutomationProvider
void OnSetZoomLevel(int handle, int zoom_level);
ExternalTabContainer* GetExternalTabForHandle(int handle);
-#endif // defined(OS_WIN) && !defined(USE_AURA)
+#endif // defined(OS_WIN)
scoped_ptr<IPC::ChannelProxy> channel_;
scoped_ptr<NewTabUILoadObserver> new_tab_ui_load_observer_;
View
37 automation/automation_provider_win.cc
@@ -24,7 +24,6 @@
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
-#include "content/public/browser/web_contents_view.h"
#include "content/public/common/page_zoom.h"
#include "ui/base/keycodes/keyboard_codes.h"
#include "ui/views/focus/accelerator_handler.h"
@@ -36,8 +35,10 @@ using content::WebContents;
void AutomationProvider::CreateExternalTab(
const ExternalTabSettings& settings,
- gfx::NativeWindow* tab_container_window, gfx::NativeWindow* tab_window,
- int* tab_handle, int* session_id) {
+ HWND* tab_container_window,
+ HWND* tab_window,
+ int* tab_handle,
+ int* session_id) {
TRACE_EVENT_BEGIN_ETW("AutomationProvider::CreateExternalTab", 0, "");
*tab_handle = 0;
@@ -63,8 +64,8 @@ void AutomationProvider::CreateExternalTab(
SessionTabHelper* session_tab_helper =
SessionTabHelper::FromWebContents(web_contents);
*tab_handle = external_tab_container->GetTabHandle();
- *tab_container_window = external_tab_container->GetExternalTabNativeView();
- *tab_window = web_contents->GetView()->GetNativeView();
+ *tab_container_window = external_tab_container->GetExternalTabHWND();
+ *tab_window = external_tab_container->GetContentHWND();
*session_id = session_tab_helper->session_id().id();
} else {
external_tab_container->Uninitialize();
@@ -118,15 +119,14 @@ void AutomationProvider::PrintAsync(int tab_handle) {
ExternalTabContainer* AutomationProvider::GetExternalTabForHandle(int handle) {
if (tab_tracker_->ContainsHandle(handle)) {
NavigationController* tab = tab_tracker_->GetResource(handle);
- return ExternalTabContainer::GetContainerForTab(
- tab->GetWebContents()->GetView()->GetNativeView());
+ return ExternalTabContainer::GetContainerForTab(tab->GetWebContents());
}
return NULL;
}
-void AutomationProvider::OnTabReposition(
- int tab_handle, const Reposition_Params& params) {
+void AutomationProvider::OnTabReposition(int tab_handle,
+ const Reposition_Params& params) {
if (!tab_tracker_->ContainsHandle(tab_handle))
return;
@@ -161,14 +161,13 @@ void AutomationProvider::OnForwardContextMenuCommandToChrome(int tab_handle,
external_tab->ExecuteContextMenuCommand(command);
}
-void AutomationProvider::ConnectExternalTab(
- uint64 cookie,
- bool allow,
- gfx::NativeWindow parent_window,
- gfx::NativeWindow* tab_container_window,
- gfx::NativeWindow* tab_window,
- int* tab_handle,
- int* session_id) {
+void AutomationProvider::ConnectExternalTab(uint64 cookie,
+ bool allow,
+ HWND parent_window,
+ HWND* tab_container_window,
+ HWND* tab_window,
+ int* tab_handle,
+ int* session_id) {
TRACE_EVENT_BEGIN_ETW("AutomationProvider::ConnectExternalTab", 0, "");
*tab_handle = 0;
@@ -191,8 +190,8 @@ void AutomationProvider::ConnectExternalTab(
SessionTabHelper* session_tab_helper =
SessionTabHelper::FromWebContents(web_contents);
*tab_handle = external_tab_container->GetTabHandle();
- *tab_container_window = external_tab_container->GetExternalTabNativeView();
- *tab_window = web_contents->GetView()->GetNativeView();
+ *tab_container_window = external_tab_container->GetExternalTabHWND();
+ *tab_window = external_tab_container->GetContentHWND();
*session_id = session_tab_helper->session_id().id();
} else {
external_tab_container->Uninitialize();
View
9 ...ation/chrome_frame_automation_provider.cc → ...n/chrome_frame_automation_provider_win.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/automation/chrome_frame_automation_provider.h"
+#include "chrome/browser/automation/chrome_frame_automation_provider_win.h"
#include <algorithm>
@@ -83,14 +83,10 @@ bool ChromeFrameAutomationProvider::IsValidMessage(uint32 type) {
switch (type) {
case AutomationMsg_CreateExternalTab::ID:
case AutomationMsg_ConnectExternalTab::ID:
-#if defined(OS_WIN)
case AutomationMsg_BrowserMove::ID:
case AutomationMsg_ProcessUnhandledAccelerator::ID:
case AutomationMsg_ForwardContextMenuCommandToChrome::ID:
-#endif // defined(OS_WIN)
-#if defined(OS_WIN)
case AutomationMsg_TabReposition::ID:
-#endif
case AutomationMsg_NavigateInExternalTab::ID:
case AutomationMsg_NavigateExternalTabAtIndex::ID:
case AutomationMsg_Find::ID:
@@ -128,8 +124,7 @@ bool ChromeFrameAutomationProvider::IsValidMessage(uint32 type) {
// static
void ChromeFrameAutomationProvider::ReleaseBrowserProcess() {
if (g_browser_process) {
- VLOG(1) << "ChromeFrameAutomationProvider: "
- "Releasing browser process.";
+ VLOG(1) << "ChromeFrameAutomationProvider: Releasing browser process.";
g_browser_process->ReleaseModule();
}
}
View
6 ...mation/chrome_frame_automation_provider.h → ...on/chrome_frame_automation_provider_win.h
@@ -8,8 +8,8 @@
// The entire lifetime of this object should be contained within that of
// the BrowserProcess
-#ifndef CHROME_BROWSER_AUTOMATION_CHROME_FRAME_AUTOMATION_PROVIDER_H_
-#define CHROME_BROWSER_AUTOMATION_CHROME_FRAME_AUTOMATION_PROVIDER_H_
+#ifndef CHROME_BROWSER_AUTOMATION_CHROME_FRAME_AUTOMATION_PROVIDER_WIN_H_
+#define CHROME_BROWSER_AUTOMATION_CHROME_FRAME_AUTOMATION_PROVIDER_WIN_H_
#include "base/basictypes.h"
#include "chrome/browser/automation/automation_provider.h"
@@ -41,5 +41,5 @@ class ChromeFrameAutomationProvider : public AutomationProvider {
DISALLOW_COPY_AND_ASSIGN(ChromeFrameAutomationProvider);
};
-#endif // CHROME_BROWSER_AUTOMATION_CHROME_FRAME_AUTOMATION_PROVIDER_H_
+#endif // CHROME_BROWSER_AUTOMATION_CHROME_FRAME_AUTOMATION_PROVIDER_WIN_H_
View
3  automation/automation_provider_unittest.cc → ...frame_automation_provider_win_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/automation/chrome_frame_automation_provider.h"
+#include "chrome/browser/automation/chrome_frame_automation_provider_win.h"
#include "chrome/test/base/testing_browser_process.h"
#include "content/public/test/test_browser_thread.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -37,4 +37,3 @@ TEST_F(AutomationProviderTest, TestInvalidChromeFrameMessage) {
-1))).Times(1);
mock->OnMessageReceived(bad_msg);
}
-
View
14 external_tab/external_tab_container.h
@@ -34,14 +34,17 @@ class ExternalTabContainer : public base::RefCounted<ExternalTabContainer> {
AutomationResourceMessageFilter* filter);
// A helper method that retrieves the ExternalTabContainer object that
- // hosts the given tab window.
- static ExternalTabContainer* GetContainerForTab(HWND tab_window);
+ // hosts the given WebContents.
+ static ExternalTabContainer* GetContainerForTab(
+ content::WebContents* web_contents);
// Returns the ExternalTabContainer instance associated with the cookie
// passed in. It also erases the corresponding reference from the map.
// Returns NULL if we fail to find the cookie in the map.
static scoped_refptr<ExternalTabContainer> RemovePendingTab(uintptr_t cookie);
+ // Initializes the instance. This must be invoked before any other member
+ // functions.
virtual bool Init(Profile* profile,
HWND parent,
const gfx::Rect& bounds,
@@ -66,7 +69,7 @@ class ExternalTabContainer : public base::RefCounted<ExternalTabContainer> {
// instance is created by Chrome and attached to an automation client.
virtual bool Reinitialize(AutomationProvider* automation_provider,
AutomationResourceMessageFilter* filter,
- gfx::NativeWindow parent_window) = 0;
+ HWND parent_window) = 0;
// This is invoked when the external host reflects back to us a keyboard
// message it did not process.
@@ -79,9 +82,8 @@ class ExternalTabContainer : public base::RefCounted<ExternalTabContainer> {
virtual void RunUnloadHandlers(IPC::Message* reply_message) = 0;
virtual content::WebContents* GetWebContents() const = 0;
-
- // This is a wrapper for GetNativeView from ExternalTabContainerWin.
- virtual gfx::NativeView GetExternalTabNativeView() const = 0;
+ virtual HWND GetExternalTabHWND() const = 0;
+ virtual HWND GetContentHWND() const = 0;
virtual void SetTabHandle(int handle) = 0;
virtual int GetTabHandle() const = 0;
View
4 ui/startup/startup_browser_creator.cc
@@ -27,7 +27,6 @@
#include "chrome/browser/auto_launch_trial.h"
#include "chrome/browser/automation/automation_provider.h"
#include "chrome/browser/automation/automation_provider_list.h"
-#include "chrome/browser/automation/chrome_frame_automation_provider.h"
#include "chrome/browser/automation/testing_automation_provider.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/custom_handlers/protocol_handler_registry.h"
@@ -78,6 +77,7 @@
#endif
#if defined(OS_WIN)
+#include "chrome/browser/automation/chrome_frame_automation_provider_win.h"
#include "chrome/browser/ui/startup/startup_browser_creator_win.h"
#endif
@@ -497,7 +497,7 @@ bool StartupBrowserCreator::ProcessCmdLineImpl(
silent_launch = true;
if (command_line.HasSwitch(switches::kChromeFrame)) {
-#if !defined(USE_AURA)
+#if defined(OS_WIN)
if (!CreateAutomationProvider<ChromeFrameAutomationProvider>(
automation_channel_id, last_used_profile, expected_tabs))
return false;
View
177 ui/views/external_tab_container_win.cc
@@ -4,6 +4,10 @@
#include "chrome/browser/ui/views/external_tab_container_win.h"
+#include <atlbase.h>
+#include <atlapp.h>
+#include <atlconv.h>
+#include <atlmisc.h>
#include <string>
#include "base/bind.h"
@@ -36,6 +40,7 @@
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/media_stream_infobar_delegate.h"
#include "chrome/browser/ui/tab_modal_confirm_dialog.h"
+#include "chrome/browser/ui/views/hwnd_util.h"
#include "chrome/browser/ui/views/infobars/infobar_container_view.h"
#include "chrome/browser/ui/views/tab_contents/render_view_context_menu_win.h"
#include "chrome/common/automation_messages.h"
@@ -70,7 +75,12 @@
#include "ui/base/view_prop.h"
#include "ui/views/controls/webview/webview.h"
#include "ui/views/layout/grid_layout.h"
-#include "ui/views/win/hwnd_message_handler.h"
+#include "ui/views/widget/widget.h"
+
+#if defined(USE_AURA)
+#include "ui/aura/root_window.h"
+#include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
+#endif
using content::BrowserThread;
using content::LoadNotificationDetails;
@@ -81,15 +91,44 @@ using content::OpenURLParams;
using content::RenderViewHost;
using content::SSLStatus;
using content::WebContents;
-using ui::ViewProp;
using WebKit::WebCString;
using WebKit::WebReferrerPolicy;
using WebKit::WebSecurityPolicy;
using WebKit::WebString;
+namespace {
+
static const char kWindowObjectKey[] = "ChromeWindowObject";
-namespace {
+// The following helper functions exist to localize UI toolkit-specific code.
+
+void ShowNativeView(gfx::NativeView view) {
+#if !defined(USE_AURA)
+ ::ShowWindow(view, SW_SHOWNA);
+#endif
+}
+
+scoped_ptr<content::NativeWebKeyboardEvent> CreateKeyboardEvent(
+ const MSG& msg) {
+#if defined(USE_AURA)
+ // TODO(grt): confirm that this is a translated character event.
+ ui::KeyEvent key_event(msg, true);
+ return scoped_ptr<content::NativeWebKeyboardEvent>(
+ new content::NativeWebKeyboardEvent(&key_event));
+#else
+ return scoped_ptr<content::NativeWebKeyboardEvent>(
+ new content::NativeWebKeyboardEvent(msg));
+#endif
+}
+
+const MSG& MessageFromKeyboardEvent(
+ const content::NativeWebKeyboardEvent& event) {
+#if defined(USE_AURA)
+ return event.os_event->native_event();
+#else
+ return event.os_event;
+#endif
+}
// Convert ui::MenuModel into a serializable form for Chrome Frame
ContextMenuModel* ConvertMenuModel(const ui::MenuModel* ui_model) {
@@ -123,7 +162,7 @@ base::LazyInstance<ExternalTabContainerWin::PendingTabs>
ExternalTabContainerWin::ExternalTabContainerWin(
AutomationProvider* automation,
AutomationResourceMessageFilter* filter)
- : views::NativeWidgetWin(new views::Widget),
+ : widget_(NULL),
automation_(automation),
tab_contents_container_(NULL),
tab_handle_(0),
@@ -131,12 +170,12 @@ ExternalTabContainerWin::ExternalTabContainerWin(
automation_resource_message_filter_(filter),
load_requests_via_automation_(false),
handle_top_level_requests_(false),
+ route_all_top_level_navigations_(false),
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
pending_(false),
focus_manager_(NULL),
external_tab_view_(NULL),
unload_reply_message_(NULL),
- route_all_top_level_navigations_(false),
is_popup_window_(false) {
}
@@ -167,29 +206,28 @@ bool ExternalTabContainerWin::Init(Profile* profile,
const GURL& referrer,
bool infobars_enabled,
bool route_all_top_level_navigations) {
- if (IsWindow(GetNativeView())) {
+ if (widget_) {
NOTREACHED();
return false;
}
+ widget_ = new views::Widget();
+ widget_->AddObserver(this);
load_requests_via_automation_ = load_requests_via_automation;
handle_top_level_requests_ = handle_top_level_requests;
route_all_top_level_navigations_ = route_all_top_level_navigations;
- GetMessageHandler()->set_window_style(WS_POPUP | WS_CLIPCHILDREN);
-
views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
params.bounds = bounds;
- params.native_widget = this;
- GetWidget()->Init(params);
- if (!IsWindow(GetNativeView())) {
- NOTREACHED();
- return false;
- }
+#if defined(USE_AURA)
+ params.native_widget = new views::DesktopNativeWidgetAura(widget_);
+#endif
+ widget_->Init(params);
+ HWND window = chrome::HWNDForWidget(widget_);
// TODO(jcampan): limit focus traversal to contents.
- prop_.reset(new ViewProp(GetNativeView(), kWindowObjectKey, this));
+ prop_.reset(new ui::ViewProp(window, kWindowObjectKey, this));
if (existing_contents) {
existing_contents->GetController().SetBrowserContext(profile);
@@ -243,15 +281,14 @@ bool ExternalTabContainerWin::Init(Profile* profile,
// Note that it's important to do this before we call SetParent since
// during the SetParent call we will otherwise get a WA_ACTIVATE call
// that causes us to steal the current focus.
- SetWindowLong(
- GetNativeView(), GWL_STYLE,
- (GetWindowLong(GetNativeView(), GWL_STYLE) & ~WS_POPUP) | style);
+ SetWindowLong(window, GWL_STYLE,
+ (GetWindowLong(window, GWL_STYLE) & ~WS_POPUP) | style);
// Now apply the parenting and style
if (parent)
- SetParent(GetNativeView(), parent);
+ SetParent(window, parent);
- ::ShowWindow(existing_contents->GetView()->GetNativeView(), SW_SHOWNA);
+ ShowNativeView(existing_contents->GetView()->GetNativeView());
LoadAccelerators();
SetupExternalTabView();
@@ -263,6 +300,7 @@ bool ExternalTabContainerWin::Init(Profile* profile,
void ExternalTabContainerWin::Uninitialize() {
registrar_.RemoveAll();
if (web_contents_.get()) {
+ tab_contents_container_->SetWebContents(NULL);
UnregisterRenderViewHost(web_contents_->GetRenderViewHost());
// Explicitly tell the RPH to shutdown, as doing so is the only thing that
@@ -284,8 +322,9 @@ void ExternalTabContainerWin::Uninitialize() {
// more fitting.
web_contents_->GetRenderProcessHost()->FastShutdownForPageCount(1);
- if (GetWidget()->GetRootView())
- GetWidget()->GetRootView()->RemoveAllChildViews(true);
+ if (widget_->GetRootView())
+ widget_->GetRootView()->RemoveAllChildViews(true);
+ widget_ = NULL;
content::NotificationService::current()->Notify(
chrome::NOTIFICATION_EXTERNAL_TAB_CLOSED,
@@ -308,7 +347,7 @@ void ExternalTabContainerWin::Uninitialize() {
bool ExternalTabContainerWin::Reinitialize(
AutomationProvider* automation_provider,
AutomationResourceMessageFilter* filter,
- gfx::NativeWindow parent_window) {
+ HWND parent_window) {
if (!automation_provider || !filter) {
NOTREACHED();
return false;
@@ -323,7 +362,7 @@ bool ExternalTabContainerWin::Reinitialize(
weak_factory_.GetWeakPtr()));
if (parent_window)
- SetParent(GetNativeView(), parent_window);
+ SetParent(chrome::HWNDForWidget(widget_), parent_window);
return true;
}
@@ -331,8 +370,12 @@ WebContents* ExternalTabContainerWin::GetWebContents() const {
return web_contents_.get();
}
-gfx::NativeView ExternalTabContainerWin::GetExternalTabNativeView() const {
- return GetNativeView();
+HWND ExternalTabContainerWin::GetExternalTabHWND() const {
+ return chrome::HWNDForWidget(widget_);
+}
+
+HWND ExternalTabContainerWin::GetContentHWND() const {
+ return chrome::HWNDForNativeWindow(web_contents_->GetView()->GetNativeView());
}
void ExternalTabContainerWin::SetTabHandle(int handle) {
@@ -389,8 +432,8 @@ void ExternalTabContainerWin::RunUnloadHandlers(IPC::Message* reply_message) {
}
void ExternalTabContainerWin::ProcessUnhandledAccelerator(const MSG& msg) {
- NativeWebKeyboardEvent keyboard_event(msg);
- unhandled_keyboard_event_handler_.HandleKeyboardEvent(keyboard_event,
+ scoped_ptr<NativeWebKeyboardEvent> keyboard_event(CreateKeyboardEvent(msg));
+ unhandled_keyboard_event_handler_.HandleKeyboardEvent(*keyboard_event,
focus_manager_);
}
@@ -409,22 +452,6 @@ void ExternalTabContainerWin::FocusThroughTabTraversal(
web_contents_->FocusThroughTabTraversal(reverse);
}
-// static
-bool ExternalTabContainerWin::IsExternalTabContainer(HWND window) {
- return ViewProp::GetValue(window, kWindowObjectKey) != NULL;
-}
-
-// static
-ExternalTabContainer*
- ExternalTabContainerWin::GetExternalContainerFromNativeWindow(
- gfx::NativeView native_window) {
- ExternalTabContainer* tab_container = NULL;
- if (native_window) {
- tab_container = reinterpret_cast<ExternalTabContainer*>(
- ViewProp::GetValue(native_window, kWindowObjectKey));
- }
- return tab_container;
-}
////////////////////////////////////////////////////////////////////////////////
// ExternalTabContainer, content::WebContentsDelegate implementation:
@@ -719,7 +746,7 @@ bool ExternalTabContainerWin::HandleContextMenu(
ConvertMenuModel(&external_context_menu_->menu_model()));
POINT screen_pt = { params.x, params.y };
- MapWindowPoints(GetNativeView(), HWND_DESKTOP, &screen_pt, 1);
+ MapWindowPoints(chrome::HWNDForWidget(widget_), HWND_DESKTOP, &screen_pt, 1);
MiniContextMenuParams ipc_params;
ipc_params.screen_x = screen_pt.x;
@@ -750,8 +777,9 @@ bool ExternalTabContainerWin::PreHandleKeyboardEvent(
void ExternalTabContainerWin::HandleKeyboardEvent(
content::WebContents* source,
const NativeWebKeyboardEvent& event) {
- ProcessUnhandledKeyStroke(event.os_event.hwnd, event.os_event.message,
- event.os_event.wParam, event.os_event.lParam);
+ const MSG& message = MessageFromKeyboardEvent(event);
+ ProcessUnhandledKeyStroke(message.hwnd, message.message,
+ message.wParam, message.lParam);
}
void ExternalTabContainerWin::BeforeUnloadFired(WebContents* tab,
@@ -950,30 +978,23 @@ void ExternalTabContainerWin::Observe(
}
////////////////////////////////////////////////////////////////////////////////
-// ExternalTabContainer, views::NativeWidgetWin overrides:
-
-bool ExternalTabContainerWin::PreHandleMSG(UINT message,
- WPARAM w_param,
- LPARAM l_param,
- LRESULT* result) {
- if (message == WM_DESTROY) {
- prop_.reset();
- Uninitialize();
- }
- return false;
+// WidgetObserver overrides:
+
+void ExternalTabContainerWin::OnWidgetCreated(views::Widget* widget) {
+ DCHECK_EQ(widget_, widget);
+ // Grab a reference here which will be released in OnWidgetDestroyed.
+ AddRef();
}
-void ExternalTabContainerWin::PostHandleMSG(UINT message,
- WPARAM w_param,
- LPARAM l_param) {
- // Grab a reference here which will be released in OnFinalMessage
- if (message == WM_CREATE)
- AddRef();
+void ExternalTabContainerWin::OnWidgetDestroying(views::Widget* widget) {
+ DCHECK_EQ(widget_, widget);
+ Uninitialize();
+ prop_.reset();
}
-void ExternalTabContainerWin::OnFinalMessage(HWND window) {
- GetWidget()->OnNativeWidgetDestroyed();
- // Release the reference which we grabbed in WM_CREATE.
+void ExternalTabContainerWin::OnWidgetDestroyed(views::Widget* widget) {
+ DCHECK_EQ(widget_, static_cast<views::Widget*>(NULL));
+ // Release the reference which we grabbed in OnWidgetCreated.
Release();
}
@@ -1144,7 +1165,7 @@ void ExternalTabContainerWin::LoadAccelerators() {
CopyAcceleratorTable(accelerator_table, accelerators, count);
- focus_manager_ = GetWidget()->GetFocusManager();
+ focus_manager_ = widget_->GetFocusManager();
DCHECK(focus_manager_);
// Let's fill our own accelerator table.
@@ -1222,7 +1243,7 @@ void ExternalTabContainerWin::SetupExternalTabView() {
layout->AddView(info_bar_container);
layout->StartRow(1, 0);
layout->AddView(tab_contents_container_);
- GetWidget()->SetContentsView(external_tab_view_);
+ widget_->SetContentsView(external_tab_view_);
// Note that SetWebContents must be called after AddChildView is called
tab_contents_container_->SetWebContents(web_contents());
}
@@ -1236,17 +1257,13 @@ ExternalTabContainer* ExternalTabContainer::Create(
// static
ExternalTabContainer* ExternalTabContainer::GetContainerForTab(
- HWND tab_window) {
- HWND parent_window = ::GetParent(tab_window);
- if (!::IsWindow(parent_window)) {
+ content::WebContents* web_contents) {
+ HWND parent_window = chrome::HWNDForNativeWindow(
+ web_contents->GetView()->GetTopLevelNativeWindow());
+ if (!::IsWindow(parent_window))
return NULL;
- }
- if (!ExternalTabContainerWin::IsExternalTabContainer(parent_window)) {
- return NULL;
- }
- ExternalTabContainer* container = reinterpret_cast<ExternalTabContainer*>(
- ViewProp::GetValue(parent_window, kWindowObjectKey));
- return container;
+ return reinterpret_cast<ExternalTabContainerWin*>(
+ ui::ViewProp::GetValue(parent_window, kWindowObjectKey));
}
// static
@@ -1283,6 +1300,6 @@ WebContents* TemporaryPopupExternalTabContainerWin::OpenURLFromTab(
WebContents* new_contents =
ExternalTabContainerWin::OpenURLFromTab(source, forward_params);
// support only one navigation for a dummy tab before it is killed.
- ::DestroyWindow(GetNativeView());
+ widget_->CloseNow();
return new_contents;
}
View
45 ui/views/external_tab_container_win.h
@@ -25,7 +25,7 @@
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h"
#include "ui/base/accelerators/accelerator.h"
-#include "ui/views/widget/native_widget_win.h"
+#include "ui/views/widget/widget_observer.h"
class AutomationProvider;
class Browser;
@@ -39,7 +39,9 @@ class ViewProp;
}
namespace views {
+class View;
class WebView;
+class Widget;
}
// This class serves as the container window for an external tab.
@@ -50,7 +52,7 @@ class ExternalTabContainerWin : public ExternalTabContainer,
public content::WebContentsDelegate,
public content::WebContentsObserver,
public content::NotificationObserver,
- public views::NativeWidgetWin,
+ public views::WidgetObserver,
public ui::AcceleratorTarget,
public InfoBarContainer::Delegate,
public BlockedContentTabHelperDelegate {
@@ -79,9 +81,10 @@ class ExternalTabContainerWin : public ExternalTabContainer,
virtual void Uninitialize() OVERRIDE;
virtual bool Reinitialize(AutomationProvider* automation_provider,
AutomationResourceMessageFilter* filter,
- gfx::NativeWindow parent_window) OVERRIDE;
+ HWND parent_window) OVERRIDE;
virtual content::WebContents* GetWebContents() const OVERRIDE;
- virtual gfx::NativeView GetExternalTabNativeView() const OVERRIDE;
+ virtual HWND GetExternalTabHWND() const OVERRIDE;
+ virtual HWND GetContentHWND() const OVERRIDE;
virtual void SetTabHandle(int handle) OVERRIDE;
virtual int GetTabHandle() const OVERRIDE;
virtual bool ExecuteContextMenuCommand(int command) OVERRIDE;
@@ -90,16 +93,6 @@ class ExternalTabContainerWin : public ExternalTabContainer,
virtual void FocusThroughTabTraversal(bool reverse,
bool restore_focus_to_view) OVERRIDE;
- // A helper method that tests whether the given window is an
- // ExternalTabContainerWin window.
- static bool IsExternalTabContainer(HWND window);
-
- // A helper function that returns a pointer to the ExternalTabContainerWin
- // instance associated with a native view. Returns NULL if the window
- // is not an ExternalTabContainerWin.
- static ExternalTabContainer* GetExternalContainerFromNativeWindow(
- gfx::NativeView native_window);
-
// Overridden from content::WebContentsDelegate:
virtual content::WebContents* OpenURLFromTab(
content::WebContents* source,
@@ -219,15 +212,10 @@ class ExternalTabContainerWin : public ExternalTabContainer,
protected:
virtual ~ExternalTabContainerWin();
- // Overridden from views::NativeWidgetWin:
- virtual bool PreHandleMSG(UINT message,
- WPARAM w_param,
- LPARAM l_param,
- LRESULT* result) OVERRIDE;
- virtual void PostHandleMSG(UINT message,
- WPARAM w_param,
- LPARAM l_param) OVERRIDE;
- virtual void OnFinalMessage(HWND window);
+ // WidgetObserver overrides.
+ virtual void OnWidgetCreated(views::Widget* widget) OVERRIDE;
+ virtual void OnWidgetDestroying(views::Widget* widget) OVERRIDE;
+ virtual void OnWidgetDestroyed(views::Widget* widget) OVERRIDE;
bool InitNavigationInfo(NavigationInfo* nav_info,
content::NavigationType nav_type,
@@ -257,6 +245,7 @@ class ExternalTabContainerWin : public ExternalTabContainer,
// ExternalTabContainerWin.
void SetupExternalTabView();
+ views::Widget* widget_;
scoped_ptr<content::WebContents> web_contents_;
scoped_refptr<AutomationProvider> automation_;
@@ -284,6 +273,11 @@ class ExternalTabContainerWin : public ExternalTabContainer,
// whether top level URL requests are to be handled by the automation client.
bool handle_top_level_requests_;
+ // Set to true if the host needs to get notified of all top level navigations
+ // in this page. This typically applies to hosts which would render the new
+ // page without chrome frame.
+ bool route_all_top_level_navigations_;
+
// Contains ExternalTabContainers that have not been connected to as yet.
static base::LazyInstance<PendingTabs> pending_tabs_;
@@ -322,11 +316,6 @@ class ExternalTabContainerWin : public ExternalTabContainer,
IPC::Message* unload_reply_message_;
- // set to true if the host needs to get notified of all top level navigations
- // in this page. This typically applies to hosts which would render the new
- // page without chrome frame.
- bool route_all_top_level_navigations_;
-
scoped_ptr<ui::ViewProp> prop_;
// if this tab is a popup
Please sign in to comment.
Something went wrong with that request. Please try again.