diff options
-rw-r--r-- | chrome_frame/chrome_active_document.cc | 5 | ||||
-rw-r--r-- | chrome_frame/chrome_active_document.h | 3 | ||||
-rw-r--r-- | chrome_frame/chrome_frame_plugin.h | 17 | ||||
-rw-r--r-- | chrome_frame/test/chrome_frame_unittests.cc | 31 |
4 files changed, 48 insertions, 8 deletions
diff --git a/chrome_frame/chrome_active_document.cc b/chrome_frame/chrome_active_document.cc index 56b13be..2406f6e 100644 --- a/chrome_frame/chrome_active_document.cc +++ b/chrome_frame/chrome_active_document.cc @@ -178,6 +178,11 @@ bool ChromeActiveDocument::is_frame_busting_enabled() { return false; } +void ChromeActiveDocument::OnAutomationServerReady() { + Base::OnAutomationServerReady(); + Base::GiveFocusToChrome(); +} + STDMETHODIMP ChromeActiveDocument::Load(BOOL fully_avalable, IMoniker* moniker_name, LPBC bind_context, diff --git a/chrome_frame/chrome_active_document.h b/chrome_frame/chrome_active_document.h index 103eb49..dbd430f 100644 --- a/chrome_frame/chrome_active_document.h +++ b/chrome_frame/chrome_active_document.h @@ -242,6 +242,9 @@ END_EXEC_COMMAND_MAP() // responses served with the X-Frame-Options header? bool is_frame_busting_enabled(); + // ChromeFramePlugin overrides. + virtual void OnAutomationServerReady(); + protected: // ChromeFrameActivexBase overrides virtual void OnOpenURL(int tab_handle, const GURL& url_to_open, diff --git a/chrome_frame/chrome_frame_plugin.h b/chrome_frame/chrome_frame_plugin.h index 01ee2e5..36f2fc2 100644 --- a/chrome_frame/chrome_frame_plugin.h +++ b/chrome_frame/chrome_frame_plugin.h @@ -122,14 +122,8 @@ END_MSG_MAP() LRESULT OnSetFocus(UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) { // NO_LINT if (!ignore_setfocus_ && automation_client_ != NULL) { - TabProxy* tab = automation_client_->tab(); - HWND chrome_window = automation_client_->tab_window(); - if (tab && ::IsWindow(chrome_window)) { - DLOG(INFO) << "Setting initial focus"; - tab->SetInitialFocus(win_util::IsShiftPressed()); - } + GiveFocusToChrome(); } - return 0; } @@ -190,6 +184,15 @@ END_MSG_MAP() return new ChromeFrameAutomationClient; } + void GiveFocusToChrome() { + TabProxy* tab = automation_client_->tab(); + HWND chrome_window = automation_client_->tab_window(); + if (tab && ::IsWindow(chrome_window)) { + DLOG(INFO) << "Setting initial focus"; + tab->SetInitialFocus(win_util::IsShiftPressed()); + } + } + protected: // Our gateway to chrome land scoped_refptr<ChromeFrameAutomationClient> automation_client_; diff --git a/chrome_frame/test/chrome_frame_unittests.cc b/chrome_frame/test/chrome_frame_unittests.cc index 875695e..c9d081a 100644 --- a/chrome_frame/test/chrome_frame_unittests.cc +++ b/chrome_frame/test/chrome_frame_unittests.cc @@ -101,7 +101,10 @@ void ChromeFrameTestWithWebServer::TearDown() { bool ChromeFrameTestWithWebServer::LaunchBrowser(BrowserKind browser, const wchar_t* page) { - std::wstring url = UTF8ToWide(server_.Resolve(page).spec()); + std::wstring url = page; + if (url.find(L"files/") != std::wstring::npos) + url = UTF8ToWide(server_.Resolve(page).spec()); + browser_ = browser; if (browser == IE) { browser_handle_.Set(chrome_frame_test::LaunchIE(url)); @@ -1741,3 +1744,29 @@ TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_BackForward) { chrome_frame_test::CloseAllIEWindows(); } +const wchar_t kChromeFrameAboutBlankUrl[] = L"cf:about:blank"; + +TEST_F(ChromeFrameTestWithWebServer, FullTabModeIE_ChromeFrameFocusTest) { + TimedMsgLoop loop; + + ASSERT_TRUE(LaunchBrowser(IE, kChromeFrameAboutBlankUrl)); + + // Allow some time for chrome to be launched. + loop.RunFor(kChromeFrameLaunchDelay); + + HWND renderer_window = chrome_frame_test::GetChromeRendererWindow(); + EXPECT_TRUE(IsWindow(renderer_window)); + + DWORD renderer_thread_id = 0; + DWORD renderer_process_id = 0; + renderer_thread_id = GetWindowThreadProcessId(renderer_window, + &renderer_process_id); + + AttachThreadInput(GetCurrentThreadId(), renderer_thread_id, TRUE); + HWND focus_window = GetFocus(); + EXPECT_TRUE(focus_window == renderer_window); + AttachThreadInput(GetCurrentThreadId(), renderer_thread_id, FALSE); + + chrome_frame_test::CloseAllIEWindows(); +} + |