Skip to content

Commit

Permalink
Remove code in ChromeAppView that used winrt_utils::FindCoreWindow. R…
Browse files Browse the repository at this point in the history
…emove FindCoreWindow.

BUG=15171
TEST=NONE


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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@193719 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
robertshield@chromium.org committed Apr 11, 2013
1 parent 81b4dfd commit e6fb17a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 50 deletions.
45 changes: 23 additions & 22 deletions win8/metro_driver/chrome_app_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@

#include "win8/metro_driver/stdafx.h"
#include "win8/metro_driver/chrome_app_view.h"
#include "win8/metro_driver/direct3d_helper.h"

#include <algorithm>
#include <corewindow.h>
#include <windows.applicationModel.datatransfer.h>
#include <windows.foundation.h>

#include <algorithm>

#include "base/bind.h"
#include "base/message_loop.h"
#include "base/win/metro.h"

#include "ui/gfx/native_widget_types.h"
#include "ui/metro_viewer/metro_viewer_messages.h"

// This include allows to send WM_SYSCOMMANDs to chrome.
#include "chrome/app/chrome_command_ids.h"
#include "ui/base/ui_base_switches.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/metro_viewer/metro_viewer_messages.h"
#include "win8/metro_driver/metro_driver.h"
#include "win8/metro_driver/winrt_utils.h"
#include "ui/base/ui_base_switches.h"

typedef winfoundtn::ITypedEventHandler<
winapp::Core::CoreApplicationView*,
Expand Down Expand Up @@ -150,12 +149,13 @@ void SendMnemonic(WORD mnemonic_char, Modifier modifiers, bool extended,
// ICoreApplicationExit::Exit function in a background delayed task which
// ensures that chrome exits.
void MetroExit(bool send_alt_f4_mnemonic) {
if (send_alt_f4_mnemonic && globals.core_window == ::GetForegroundWindow()) {
if (send_alt_f4_mnemonic && globals.view &&
globals.view->core_window_hwnd() == ::GetForegroundWindow()) {
DVLOG(1) << "We are in the foreground. Exiting via Alt F4";
SendMnemonic(VK_F4, ALT, false, false);
DWORD core_window_process_id = 0;
DWORD core_window_thread_id = GetWindowThreadProcessId(
globals.core_window, &core_window_process_id);
globals.view->core_window_hwnd(), &core_window_process_id);
if (core_window_thread_id != ::GetCurrentThreadId()) {
globals.appview_msg_loop->PostDelayedTask(
FROM_HERE,
Expand All @@ -164,13 +164,12 @@ void MetroExit(bool send_alt_f4_mnemonic) {
}
} else {
globals.app_exit->Exit();
globals.core_window = NULL;
}
}

void AdjustToFitWindow(HWND hwnd, int flags) {
RECT rect = {0};
::GetWindowRect(globals.core_window, &rect);
::GetWindowRect(globals.view->core_window_hwnd() , &rect);
int cx = rect.right - rect.left;
int cy = rect.bottom - rect.top;

Expand Down Expand Up @@ -436,7 +435,7 @@ void MetroUnsnap() {
extern "C" __declspec(dllexport)
HWND GetRootWindow() {
DVLOG(1) << __FUNCTION__;
return globals.core_window;
return globals.view->core_window_hwnd();
}

extern "C" __declspec(dllexport)
Expand Down Expand Up @@ -639,7 +638,7 @@ DWORD WINAPI HostMainThreadProc(void*) {

globals.g_core_proc =
reinterpret_cast<WNDPROC>(::SetWindowLongPtr(
globals.core_window, GWLP_WNDPROC,
globals.view->core_window_hwnd(), GWLP_WNDPROC,
reinterpret_cast<LONG_PTR>(ChromeAppView::CoreWindowProc)));
DWORD exit_code = globals.host_main(globals.host_context);

Expand All @@ -650,7 +649,8 @@ DWORD WINAPI HostMainThreadProc(void*) {

ChromeAppView::ChromeAppView()
: osk_visible_notification_received_(false),
osk_offset_adjustment_(0) {
osk_offset_adjustment_(0),
core_window_hwnd_(NULL) {
globals.previous_state =
winapp::Activation::ApplicationExecutionState_NotRunning;
}
Expand All @@ -663,7 +663,6 @@ IFACEMETHODIMP
ChromeAppView::Initialize(winapp::Core::ICoreApplicationView* view) {
view_ = view;
DVLOG(1) << __FUNCTION__;
globals.main_thread_id = ::GetCurrentThreadId();

HRESULT hr = view_->add_Activated(mswr::Callback<ActivatedHandler>(
this, &ChromeAppView::OnActivate).Get(),
Expand All @@ -677,7 +676,14 @@ ChromeAppView::SetWindow(winui::Core::ICoreWindow* window) {
window_ = window;
DVLOG(1) << __FUNCTION__;

HRESULT hr = url_launch_handler_.Initialize();
// Retrieve the native window handle via the interop layer.
mswr::ComPtr<ICoreWindowInterop> interop;
HRESULT hr = window->QueryInterface(interop.GetAddressOf());
CheckHR(hr);
hr = interop->get_WindowHandle(&core_window_hwnd_);
CheckHR(hr);

hr = url_launch_handler_.Initialize();
CheckHR(hr, "Failed to initialize url launch handler.");
// Register for size notifications.
hr = window_->add_SizeChanged(mswr::Callback<SizeChangedHandler>(
Expand Down Expand Up @@ -920,11 +926,6 @@ HRESULT ChromeAppView::OnActivate(winapp::Core::ICoreApplicationView*,
return S_OK;
}

globals.core_window =
winrt_utils::FindCoreWindow(globals.main_thread_id, 10);

DVLOG(1) << "CoreWindow found: " << std::hex << globals.core_window;

if (!globals.host_thread) {
DWORD chrome_ui_thread_id = 0;
globals.host_thread =
Expand All @@ -937,7 +938,7 @@ HRESULT ChromeAppView::OnActivate(winapp::Core::ICoreApplicationView*,
}
}

if (RegisterHotKey(globals.core_window, kFlipWindowsHotKeyId,
if (RegisterHotKey(core_window_hwnd_, kFlipWindowsHotKeyId,
MOD_CONTROL, VK_F12)) {
DVLOG(1) << "Registered flip window hotkey.";
} else {
Expand Down
7 changes: 5 additions & 2 deletions win8/metro_driver/chrome_app_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class ChromeAppView
// Returns the current view state of the chrome window.
winui::ViewManagement::ApplicationViewState GetViewState();

HWND core_window_hwnd() { return core_window_hwnd_; }

private:
HRESULT OnActivate(winapp::Core::ICoreApplicationView* view,
winapp::Activation::IActivatedEventArgs* args);
Expand Down Expand Up @@ -115,6 +117,9 @@ class ChromeAppView
EventRegistrationToken input_pane_hiding_token_;
EventRegistrationToken app_exit_token_;

// The actual window behind the view surface.
HWND core_window_hwnd_;

ChromeUrlLaunchHandler url_launch_handler_;
metro_driver::DevicesHandler devices_handler_;
SettingsHandler settings_handler_;
Expand Down Expand Up @@ -143,13 +148,11 @@ class ChromeAppView
struct Globals {
LPTHREAD_START_ROUTINE host_main;
void* host_context;
HWND core_window;
// The pair below contains the HWND and a bool which indicates whether the
// window was displaced to ensure that the focused region is visible when
// the OSK is displayed.
std::list<std::pair<HWND, bool> > host_windows;
HANDLE host_thread;
DWORD main_thread_id;
ChromeAppView* view;
WNDPROC g_core_proc;
string16 navigation_url;
Expand Down
22 changes: 0 additions & 22 deletions win8/metro_driver/winrt_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,6 @@ HRESULT Create ## Name ## Property(Type value, \
*result = 0; \
hr = S_OK


BOOL CALLBACK CoreWindowFinder(HWND hwnd, LPARAM param) {
HWND* window = reinterpret_cast<HWND*>(param);
char classname[128];
if (::GetClassNameA(hwnd, classname, ARRAYSIZE(classname))) {
if (lstrcmpiA("Windows.UI.Core.CoreWindow", classname) == 0) {
*window = hwnd;
return FALSE;
}
}
return TRUE;
}

} // namespace

namespace winrt_utils {
Expand Down Expand Up @@ -236,13 +223,4 @@ string16 ReadArgumentsFromPinnedTaskbarShortcut() {
return L"";
}

HWND FindCoreWindow(DWORD thread_id, int wait_ms) {
HWND window = NULL;
do {
::Sleep(wait_ms);
::EnumThreadWindows(thread_id, &CoreWindowFinder, LPARAM(&window));
} while (window == NULL);
return window;
}

} // namespace winrt_utils
4 changes: 0 additions & 4 deletions win8/metro_driver/winrt_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ HRESULT CompareProperties(
// empty string on failure.
string16 ReadArgumentsFromPinnedTaskbarShortcut();

// Looks for a Window with the right class name that belongs to |thread_id|
// thread. It loops forever looking for it, waiting |wait_ms| between loops.
HWND FindCoreWindow(DWORD thread_id, int wait_ms);

} // namespace winrt_utils

#endif // WIN8_METRO_DRIVER_WINRT_UTILS_H_

0 comments on commit e6fb17a

Please sign in to comment.