Commit 87402bb8 authored by Guillaume Jenkins's avatar Guillaume Jenkins Committed by Commit Bot

[Siri Shortcuts] Add checks for old shortcut actions

It appears that in some rare cases that aren't fully understood yet, old
versions of intents are passed to Chrome instead of the new intents.
This makes it so any new intent parameter isn't there or is of the wrong
type, which can lead to crashes.

This CL attempts to prevent these crashes by adding type checks and null
checks for properties missing in old intent versions.

Bug: 1133825
Change-Id: I55ec931ccdaf1afaf36ab31f73c405ac7c2b49b9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2441631Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Commit-Queue: Guillaume Jenkins <gujen@google.com>
Cr-Commit-Position: refs/heads/master@{#813264}
parent d97cc903
......@@ -170,10 +170,10 @@ std::vector<GURL> createGURLVectorFromIntentURLs(NSArray<NSURL*>* intentURLs) {
base::mac::ObjCCastStrict<SearchInChromeIntent>(
userActivity.interaction.intent);
NSString* searchPhrase = intent.searchPhrase;
if ([searchPhrase length]) {
startupParams.textQuery = searchPhrase;
if (intent &&
[intent respondsToSelector:NSSelectorFromString(@"searchPhrase")] &&
intent.searchPhrase && [intent.searchPhrase length]) {
startupParams.textQuery = intent.searchPhrase;
} else {
startupParams.postOpeningAction = FOCUS_OMNIBOX;
}
......@@ -188,11 +188,27 @@ std::vector<GURL> createGURLVectorFromIntentURLs(NSArray<NSURL*>* intentURLs) {
OpenInChromeIntent* intent = base::mac::ObjCCastStrict<OpenInChromeIntent>(
userActivity.interaction.intent);
if (!intent.url || intent.url.count == 0) {
if (!intent.url) {
return NO;
}
std::vector<GURL> URLs;
if ([intent.url isKindOfClass:[NSURL class]]) {
// Old intent version where |url| is of type NSURL rather than an array.
GURL webpageGURL(
net::GURLWithNSURL(base::mac::ObjCCastStrict<NSURL>(intent.url)));
if (!webpageGURL.is_valid())
return NO;
URLs.push_back(webpageGURL);
} else if ([intent.url isKindOfClass:[NSArray class]] &&
intent.url.count > 0) {
URLs = createGURLVectorFromIntentURLs(intent.url);
} else {
// Unknown or invalid intent object.
return NO;
}
std::vector<GURL> URLs = createGURLVectorFromIntentURLs(intent.url);
AppStartupParameters* startupParams =
[[AppStartupParameters alloc] initWithURLs:URLs];
......
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