diff options
| author | Patrick Scott <phanna@android.com> | 2009-11-18 13:55:30 -0500 |
|---|---|---|
| committer | Patrick Scott <phanna@android.com> | 2009-11-19 09:19:18 -0500 |
| commit | 27e40b2407e7e39b8fde83728baee90aae279760 (patch) | |
| tree | f06d6bbc372c2f3541721893f0c6e1e2bef7a085 | |
| parent | 19e61e8bbfd288bd9bf211069dd66e51ffadce15 (diff) | |
| download | external_webkit-27e40b2407e7e39b8fde83728baee90aae279760.zip external_webkit-27e40b2407e7e39b8fde83728baee90aae279760.tar.gz external_webkit-27e40b2407e7e39b8fde83728baee90aae279760.tar.bz2 | |
Change window focus only if the user initiated the event.
This does not work in the javascript case because the user gesture is stored in
the caller's script environment and that knowledge is not obtainable in the
receiving frame. However, this change allows targeted links to change the focus
to the correct window but prevents sites like slate.com from changing back to
the opening window.
This change will be followed by a simple revert of the previous change in the
Browser app.
Bug: 2161671
| -rw-r--r-- | WebCore/loader/EmptyClients.h | 4 | ||||
| -rw-r--r-- | WebCore/loader/FrameLoader.cpp | 8 | ||||
| -rw-r--r-- | WebCore/page/Chrome.cpp | 7 | ||||
| -rw-r--r-- | WebCore/page/Chrome.h | 4 | ||||
| -rw-r--r-- | WebCore/page/ChromeClient.h | 4 | ||||
| -rw-r--r-- | WebCore/page/Frame.cpp | 6 | ||||
| -rw-r--r-- | WebKit/android/WebCoreSupport/ChromeClientAndroid.cpp | 11 | ||||
| -rw-r--r-- | WebKit/android/WebCoreSupport/ChromeClientAndroid.h | 4 |
8 files changed, 47 insertions, 1 deletions
diff --git a/WebCore/loader/EmptyClients.h b/WebCore/loader/EmptyClients.h index 44fad72..b4952b1 100644 --- a/WebCore/loader/EmptyClients.h +++ b/WebCore/loader/EmptyClients.h @@ -70,7 +70,11 @@ public: virtual float scaleFactor() { return 1.f; } +#ifdef ANDROID_USER_GESTURE + virtual void focus(bool userGesture) { } +#else virtual void focus() { } +#endif virtual void unfocus() { } virtual bool canTakeFocus(FocusDirection) { return false; } diff --git a/WebCore/loader/FrameLoader.cpp b/WebCore/loader/FrameLoader.cpp index 80fcff8..f9dc2bf 100644 --- a/WebCore/loader/FrameLoader.cpp +++ b/WebCore/loader/FrameLoader.cpp @@ -262,7 +262,11 @@ Frame* FrameLoader::createWindow(FrameLoader* frameLoaderForFrameLookup, const F if (!request.resourceRequest().url().isEmpty()) frame->loader()->loadFrameRequest(request, false, false, 0, 0, SendReferrer); if (Page* page = frame->page()) +#ifdef ANDROID_USER_GESTURE + page->chrome()->focus(isProcessingUserGesture()); +#else page->chrome()->focus(); +#endif created = false; return frame; } @@ -1882,7 +1886,11 @@ void FrameLoader::loadFrameRequest(const FrameLoadRequest& request, bool lockHis Frame* targetFrame = sourceFrame->loader()->findFrameForNavigation(request.frameName()); if (targetFrame && targetFrame != sourceFrame) { if (Page* page = targetFrame->page()) +#ifdef ANDROID_USER_GESTURE + page->chrome()->focus(request.resourceRequest().getUserGesture()); +#else page->chrome()->focus(); +#endif } } diff --git a/WebCore/page/Chrome.cpp b/WebCore/page/Chrome.cpp index 96f0fb7..7e14b3e 100644 --- a/WebCore/page/Chrome.cpp +++ b/WebCore/page/Chrome.cpp @@ -127,10 +127,17 @@ float Chrome::scaleFactor() return m_client->scaleFactor(); } +#ifdef ANDROID_USER_GESTURE +void Chrome::focus(bool userGesture) const +{ + m_client->focus(userGesture); +} +#else void Chrome::focus() const { m_client->focus(); } +#endif void Chrome::unfocus() const { diff --git a/WebCore/page/Chrome.h b/WebCore/page/Chrome.h index 033311d..c562f33 100644 --- a/WebCore/page/Chrome.h +++ b/WebCore/page/Chrome.h @@ -76,7 +76,11 @@ namespace WebCore { float scaleFactor(); +#ifdef ANDROID_USER_GESTURE + void focus(bool userGesture) const; +#else void focus() const; +#endif void unfocus() const; bool canTakeFocus(FocusDirection) const; diff --git a/WebCore/page/ChromeClient.h b/WebCore/page/ChromeClient.h index 5231603..194f855 100644 --- a/WebCore/page/ChromeClient.h +++ b/WebCore/page/ChromeClient.h @@ -77,7 +77,11 @@ namespace WebCore { virtual float scaleFactor() = 0; +#ifdef ANDROID_USER_GESTURE + virtual void focus(bool userGesture) = 0; +#else virtual void focus() = 0; +#endif virtual void unfocus() = 0; virtual bool canTakeFocus(FocusDirection) = 0; diff --git a/WebCore/page/Frame.cpp b/WebCore/page/Frame.cpp index afda0b9..dac6553 100644 --- a/WebCore/page/Frame.cpp +++ b/WebCore/page/Frame.cpp @@ -1665,7 +1665,13 @@ void Frame::focusWindow() // If we're a top level window, bring the window to the front. if (!tree()->parent()) +#ifdef ANDROID_USER_GESTURE + // FrameLoader::isProcessingUserGesture() will be false when a + // different frame tries to focus this frame through javascript. + page()->chrome()->focus(m_loader.isProcessingUserGesture()); +#else page()->chrome()->focus(); +#endif eventHandler()->focusDocumentView(); } diff --git a/WebKit/android/WebCoreSupport/ChromeClientAndroid.cpp b/WebKit/android/WebCoreSupport/ChromeClientAndroid.cpp index cfac25e..f441aa1 100644 --- a/WebKit/android/WebCoreSupport/ChromeClientAndroid.cpp +++ b/WebKit/android/WebCoreSupport/ChromeClientAndroid.cpp @@ -105,10 +105,19 @@ float ChromeClientAndroid::scaleFactor() return 1.0f; } +#ifdef ANDROID_USER_GESTURE +void ChromeClientAndroid::focus(bool userGesture) { +#else void ChromeClientAndroid::focus() { + // The old behavior was to always allow javascript to focus a window. If we + // turn off ANDROID_USER_GESTURE, go back to the old behavior by forcing + // userGesture to be true. + bool userGesture = true; +#endif ASSERT(m_webFrame); // Ask the application to focus this WebView. - m_webFrame->requestFocus(); + if (userGesture) + m_webFrame->requestFocus(); } void ChromeClientAndroid::unfocus() { notImplemented(); } diff --git a/WebKit/android/WebCoreSupport/ChromeClientAndroid.h b/WebKit/android/WebCoreSupport/ChromeClientAndroid.h index 7bd7088..5ed785a 100644 --- a/WebKit/android/WebCoreSupport/ChromeClientAndroid.h +++ b/WebKit/android/WebCoreSupport/ChromeClientAndroid.h @@ -53,7 +53,11 @@ namespace android { virtual float scaleFactor(); +#ifdef ANDROID_USER_GESTURE + virtual void focus(bool userGesture); +#else virtual void focus(); +#endif virtual void unfocus(); virtual bool canTakeFocus(FocusDirection); |
