From 4b505593cad3b9a3bae0d81a8237cacb0fce2b00 Mon Sep 17 00:00:00 2001 From: Yi Su Date: Wed, 30 Jan 2019 05:50:59 +0000 Subject: [PATCH] Cast find_in_page.js return value from id to NSString. Currently JsFindinpageManager passes the result of find_in_page.js to base::SysNSStringToUTF8 with "id" type. This CL casts it to NSString to prevent it from crashing the APP when the result is not NSString. Bug: 924441 Change-Id: Ib02e80c09ef8c3af9f877f0c70cf1361fc019dd5 Reviewed-on: https://chromium-review.googlesource.com/c/1433754 Commit-Queue: Yi Su Reviewed-by: Mike Dougherty Cr-Original-Commit-Position: refs/heads/master@{#626028}(cherry picked from commit 831dfd60ade0c8e28df4a0f092ca44f11eb12264) Reviewed-on: https://chromium-review.googlesource.com/c/1445038 Reviewed-by: Yi Su Cr-Commit-Position: refs/branch-heads/3683@{#61} Cr-Branched-From: e51029943e0a38dd794b73caaf6373d5496ae783-refs/heads/master@{#625896} --- ios/chrome/browser/find_in_page/js_findinpage_manager.mm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ios/chrome/browser/find_in_page/js_findinpage_manager.mm b/ios/chrome/browser/find_in_page/js_findinpage_manager.mm index 937922144792b..37047b5526c08 100644 --- a/ios/chrome/browser/find_in_page/js_findinpage_manager.mm +++ b/ios/chrome/browser/find_in_page/js_findinpage_manager.mm @@ -169,11 +169,12 @@ - (void)disableWithCompletionHandler:(ProceduralBlock)completionHandler { #pragma mark FindInPageEntry - (BOOL)processFindInPageResult:(id)result scrollPosition:(CGPoint*)point { - if (!result) + NSString* result_str = base::mac::ObjCCastStrict(result); + if (!result_str) return NO; // Parse JSONs. - std::string json = base::SysNSStringToUTF8(result); + std::string json = base::SysNSStringToUTF8(result_str); std::unique_ptr root(base::JSONReader::Read(json, false)); if (!root.get()) return YES;