Commit 9cdf6a51 authored by Mike Dougherty's avatar Mike Dougherty Committed by Commit Bot

Do not use GetFirstResponderSubview on iOS 10.

When a WKWebView is displaying a PDF, the first responder is not in the view hierarchy (but a class adhering to UIResponder).

Bug: 882470
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: I6f9e993e740541b7cf009b1d11e16183b409fdae
Reviewed-on: https://chromium-review.googlesource.com/c/1284438
Commit-Queue: Mike Dougherty <michaeldo@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600620}
parent 693d01a6
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "ios/chrome/browser/ui/ui_util.h" #include "ios/chrome/browser/ui/ui_util.h"
#import "ios/web/public/navigation_manager.h" #import "ios/web/public/navigation_manager.h"
#import "ios/web/public/test/fakes/test_web_state.h" #import "ios/web/public/test/fakes/test_web_state.h"
#include "ios/web/public/test/test_web_thread_bundle.h"
#import "ios/web/public/web_state/ui/crw_web_view_proxy.h" #import "ios/web/public/web_state/ui/crw_web_view_proxy.h"
#import "ios/web/public/web_state/web_state.h" #import "ios/web/public/web_state/web_state.h"
#import "testing/gtest_mac.h" #import "testing/gtest_mac.h"
...@@ -235,6 +236,9 @@ class FormSuggestionControllerTest : public PlatformTest { ...@@ -235,6 +236,9 @@ class FormSuggestionControllerTest : public PlatformTest {
// Accessory view controller. // Accessory view controller.
FormInputAccessoryMediator* accessory_mediator_; FormInputAccessoryMediator* accessory_mediator_;
// The associated test Web Threads.
web::TestWebThreadBundle thread_bundle_;
// The fake WebState to simulate navigation and JavaScript events. // The fake WebState to simulate navigation and JavaScript events.
web::TestWebState test_web_state_; web::TestWebState test_web_state_;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#include <cmath> #include <cmath>
#include "base/ios/ios_util.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "base/numerics/math_constants.h" #include "base/numerics/math_constants.h"
...@@ -600,19 +601,21 @@ UIView* GetFirstResponderSubview(UIView* view) { ...@@ -600,19 +601,21 @@ UIView* GetFirstResponderSubview(UIView* view) {
} }
UIResponder* GetFirstResponder() { UIResponder* GetFirstResponder() {
if (!base::FeatureList::IsEnabled(kFirstResponderKeyWindow)) { UIApplication* application = [UIApplication sharedApplication];
DCHECK_CURRENTLY_ON(web::WebThread::UI); if (base::ios::IsRunningOnIOS11OrLater() &&
DCHECK(!gFirstResponder); base::FeatureList::IsEnabled(kFirstResponderKeyWindow)) {
[[UIApplication sharedApplication] return GetFirstResponderSubview(application.keyWindow);
sendAction:@selector(cr_markSelfCurrentFirstResponder)
to:nil
from:nil
forEvent:nil];
UIResponder* firstResponder = gFirstResponder;
gFirstResponder = nil;
return firstResponder;
} }
return GetFirstResponderSubview([UIApplication sharedApplication].keyWindow);
DCHECK_CURRENTLY_ON(web::WebThread::UI);
DCHECK(!gFirstResponder);
[application sendAction:@selector(cr_markSelfCurrentFirstResponder)
to:nil
from:nil
forEvent:nil];
UIResponder* firstResponder = gFirstResponder;
gFirstResponder = nil;
return firstResponder;
} }
// Trigger a haptic vibration for the user selecting an action. This is a no-op // Trigger a haptic vibration for the user selecting an action. This is a no-op
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment