Commit 39feff8d authored by Javier Ernesto Flores Robles's avatar Javier Ernesto Flores Robles Committed by Commit Bot

[iOS][WidgetKit] Wire actions

- Wires the widget commands to the respective actions
- Logs start action for widget
- Adds TODOs in the places where specific action metrics will go

Bug: 1138719
Change-Id: I2a10d029b0f0b8b1b100cc37b7a93274c939a33c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2511850
Commit-Queue: Javier Flores <javierrobles@chromium.org>
Reviewed-by: default avatarChris Lu <thegreenfrog@chromium.org>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#823171}
parent 1c4431bb
......@@ -8,6 +8,7 @@
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
#include "base/strings/stringprintf.h"
#include "base/strings/sys_string_conversions.h"
#include "ios/chrome/browser/chrome_url_constants.h"
#import "ios/chrome/browser/ui/whats_new/default_browser_utils.h"
......@@ -34,6 +35,31 @@ const char kApplicationGroupCommandDelay[] =
// here due to a Smart App Banner presentation on a Google.com page.
NSString* const kSmartAppBannerKey = @"safarisab";
// TODO(crbug.com/1138702): When swift is supported move WidgetKit constants to
// a file where they can be shared with the extension. Currently these are also
// declared as URLs in ios/c/widget_kit_extension/widget_constants.swift.
//
// Scheme used by the widget extension actions. It's important that this scheme
// is never defined as Custom URL Scheme for Chrome so only the widgets can use
// the actions on it.
NSString* const kWidgetKitSchemeChrome = @"chromewidgetkit";
// Host used to identify Search (small) widget.
NSString* const kWidgetKitHostSearchWidget = @"search-widget";
// Host used to identify Quick Actions (medium) widget.
NSString* const kWidgetKitHostQuickActionsWidget = @"quick-actions-widget";
// Host used to identify Dino Game (small) widget.
NSString* const kWidgetKitHostDinoGameWidget = @"dino-game-widget";
// Path for search action.
NSString* const kWidgetKitActionSearch = @"/search";
// Path for incognito action.
NSString* const kWidgetKitActionIncognito = @"/incognito";
// Path for Voice Search action.
NSString* const kWidgetKitActionVoiceSearch = @"/voicesearch";
// Path for QR Reader action.
NSString* const kWidgetKitActionQRReader = @"/qrreader";
// Path for Game action.
NSString* const kWidgetKitActionGame = @"/game";
const CGFloat kAppGroupTriggersVoiceSearchTimeout = 15.0;
// Values of the UMA Startup.MobileSessionStartAction histogram.
......@@ -61,7 +87,8 @@ enum MobileSessionStartAction {
// browser on iOS 14+ as http openURL calls will be directed to Chrome by the
// system from all other apps.
START_ACTION_OPEN_HTTPS_FROM_OS = 8,
MOBILE_SESSION_START_ACTION_COUNT,
START_ACTION_WIDGET_KIT_COMMAND = 9,
MOBILE_SESSION_START_ACTION_COUNT
};
// Values of the UMA iOS.SearchExtension.Action histogram.
......@@ -104,8 +131,47 @@ enum SearchExtensionAction {
if (!gurl.is_valid() || gurl.scheme().length() == 0)
return nil;
// TODO(crbug.com/228098): Temporary fix.
if (IsXCallbackURL(gurl)) {
if ([completeURL.scheme isEqual:kWidgetKitSchemeChrome]) {
UMA_HISTOGRAM_ENUMERATION(kUMAMobileSessionStartActionHistogram,
START_ACTION_WIDGET_KIT_COMMAND,
MOBILE_SESSION_START_ACTION_COUNT);
const char* command = "";
NSString* sourceWidget = completeURL.host;
if ([completeURL.path isEqual:kWidgetKitActionSearch]) {
command = app_group::kChromeAppGroupFocusOmniboxCommand;
} else if ([completeURL.path isEqual:kWidgetKitActionIncognito]) {
command = app_group::kChromeAppGroupIncognitoSearchCommand;
} else if ([completeURL.path isEqual:kWidgetKitActionVoiceSearch]) {
command = app_group::kChromeAppGroupVoiceSearchCommand;
} else if ([completeURL.path isEqual:kWidgetKitActionQRReader]) {
command = app_group::kChromeAppGroupQRScannerCommand;
} else if ([completeURL.path isEqual:kWidgetKitActionGame]) {
// TODO(crbug.com/1138720): log histogram.
LogLikelyInterestedDefaultBrowserUserActivity();
GURL URL(
base::StringPrintf("%s://%s", kChromeUIScheme, kChromeUIDinoHost));
return
[[ChromeAppStartupParameters alloc] initWithExternalURL:URL
declaredSourceApp:appId
secureSourceApp:sourceWidget
completeURL:completeURL];
}
NSString* commandString = base::SysUTF8ToNSString(command);
return [self newAppStartupParametersForCommand:commandString
withExternalText:nil
withExternalData:nil
withIndex:0
withURL:nil
fromSourceApplication:appId
fromSecureSourceApplication:sourceWidget];
} else if (IsXCallbackURL(gurl)) {
// TODO(crbug.com/228098): Temporary fix.
NSString* action = [completeURL path];
// Currently only "open" and "extension-command" are supported.
// Other actions are being considered (see b/6914153).
......@@ -420,6 +486,12 @@ enum SearchExtensionAction {
UMA_HISTOGRAM_COUNTS_100("IOS.ContentExtension.Index",
[index integerValue]);
}
if ([secureSourceApp isEqualToString:kWidgetKitHostSearchWidget]) {
// TODO(crbug.com/1138720): log histogram.
}
if ([secureSourceApp isEqualToString:kWidgetKitHostQuickActionsWidget]) {
// TODO(crbug.com/1138720): log histograms.
}
return params;
}
......
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