Commit 48d9345a authored by Guillaume Jenkins's avatar Guillaume Jenkins Committed by Commit Bot

[Siri Shortcuts] Donate Search in Chrome intent on query

Donates the Search In Chrome intent to SiriKit every time a search is
performed in the Omnibox. The donation is performed on the IO thread to
avoid blocking the UI thread. This also updates the intents definition
file to make the Search in Chrome intent available for Siri
suggestions, which was previously disabled and prevented intent
donation.

Bug: 1146116
Change-Id: I6f7beb004a7f38d3a6297c8e7c171675fef2277c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2521202
Commit-Queue: Guillaume Jenkins <gujen@google.com>
Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826305}
parent b5f7e825
......@@ -177,7 +177,10 @@ std::vector<GURL> createGURLVectorFromIntentURLs(NSArray<NSURL*>* intentURLs) {
id searchPhrase = [intent valueForKey:@"searchPhrase"];
if ([searchPhrase isKindOfClass:[NSString class]] &&
[searchPhrase length]) {
[searchPhrase
stringByTrimmingCharactersInSet:[NSCharacterSet
whitespaceCharacterSet]]
.length > 0) {
startupParams.textQuery = searchPhrase;
} else {
startupParams.postOpeningAction = FOCUS_OMNIBOX;
......
......@@ -9,11 +9,11 @@
<key>INIntentDefinitionNamespace</key>
<string>Oi5136</string>
<key>INIntentDefinitionSystemVersion</key>
<string>19F101</string>
<string>19H2</string>
<key>INIntentDefinitionToolsBuildVersion</key>
<string>11E608c</string>
<string>11E708</string>
<key>INIntentDefinitionToolsVersion</key>
<string>11.5</string>
<string>11.6</string>
<key>INIntents</key>
<array>
<dict>
......@@ -110,15 +110,13 @@
</dict>
<dict>
<key>INIntentCategory</key>
<string>information</string>
<string>search</string>
<key>INIntentConfigurable</key>
<true/>
<key>INIntentDescriptionID</key>
<string>k0Ho6W</string>
<key>INIntentEligibleForWidgets</key>
<true/>
<key>INIntentIneligibleForSuggestions</key>
<true/>
<key>INIntentInput</key>
<string>searchPhrase</string>
<key>INIntentLastParameterTag</key>
......@@ -139,6 +137,20 @@
</dict>
<key>INIntentName</key>
<string>SearchInChrome</string>
<key>INIntentParameterCombinations</key>
<dict>
<key>searchPhrase</key>
<dict>
<key>INIntentParameterCombinationIsPrimary</key>
<true/>
<key>INIntentParameterCombinationSupportsBackgroundExecution</key>
<false/>
<key>INIntentParameterCombinationTitle</key>
<string>Search in Chrome</string>
<key>INIntentParameterCombinationTitleID</key>
<string>1Ukwhx</string>
</dict>
</dict>
<key>INIntentParameters</key>
<array>
<dict>
......@@ -201,7 +213,7 @@
<key>INIntentType</key>
<string>Custom</string>
<key>INIntentVerb</key>
<string>Open</string>
<string>Search</string>
</dict>
<dict>
<key>INIntentCategory</key>
......
......@@ -66,6 +66,12 @@
<key>output</key>
<string>Z6KvRw</string>
</dict>
<dict>
<key>input</key>
<string>IDS_IOS_INTENTS_SEARCH_IN_CHROME_SUGGEST_TITLE</string>
<key>output</key>
<string>1Ukwhx</string>
</dict>
<dict>
<key>input</key>
<string>IDS_IOS_INTENTS_SEARCH_IN_CHROME_PARAMETER_COMBINATION_TITLE</string>
......
......@@ -993,6 +993,9 @@ Because your account is managed by <ph name="HOSTED_DOMAIN">$1<ex>google.com</ex
<message name="IDS_IOS_INTENTS_SEARCH_IN_CHROME_TITLE" desc="Siri Shortcut for search in chrome title [iOS only].">
Search in Chrome
</message>
<message name="IDS_IOS_INTENTS_SEARCH_IN_CHROME_SUGGEST_TITLE" desc="Siri Shortcut for search in chrome title [iOS only].">
Search in Chrome
</message>
<message name="IDS_IOS_INTENTS_SEARCH_IN_CHROME_PARAMETER_COMBINATION_TITLE" desc="Apple Shortcuts App's format for displaying the user search phrase input, shown by the Siri Shortcut app when the
user is adding or editing a Search in Chrome shortcut[iOS only].">
Search ${searchPhrase} in Chrome
......
6a7f21f02a8533dfd98661a4000e0d235581257b
\ No newline at end of file
......@@ -138,6 +138,7 @@ source_set("omnibox_internal") {
"//components/search_engines",
"//components/security_state/core",
"//components/strings",
"//ios/chrome/app/intents",
"//ios/chrome/app/strings",
"//ios/chrome/browser",
"//ios/chrome/browser/autocomplete",
......
......@@ -48,6 +48,7 @@ class ChromeOmniboxClientIOS : public OmniboxClient {
void OnResultChanged(const AutocompleteResult& result,
bool default_match_changed,
const BitmapFetchedCallback& on_bitmap_fetched) override;
void OnURLOpenedFromOmnibox(OmniboxLog* log) override;
void DiscardNonCommittedNavigations() override;
const base::string16& GetTitle() const override;
gfx::Image GetFavicon() const override;
......
......@@ -6,11 +6,14 @@
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/post_task.h"
#include "components/favicon/ios/web_favicon_driver.h"
#include "components/omnibox/browser/autocomplete_match.h"
#include "components/omnibox/browser/autocomplete_result.h"
#include "components/omnibox/browser/omnibox_edit_controller.h"
#include "components/omnibox/browser/omnibox_log.h"
#include "components/search_engines/template_url_service.h"
#include "ios/chrome/app/intents/SearchInChromeIntent.h"
#include "ios/chrome/browser/autocomplete/autocomplete_classifier_factory.h"
#include "ios/chrome/browser/autocomplete/autocomplete_provider_client_impl.h"
#include "ios/chrome/browser/bookmarks/bookmark_model_factory.h"
......@@ -22,9 +25,11 @@
#include "ios/chrome/browser/search_engines/template_url_service_factory.h"
#include "ios/chrome/browser/sessions/ios_chrome_session_tab_helper.h"
#include "ios/chrome/browser/ui/omnibox/web_omnibox_edit_controller.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
#import "ios/web/public/navigation/navigation_manager.h"
#import "ios/web/public/web_state.h"
#include "ui/base/l10n/l10n_util.h"
#include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
......@@ -164,6 +169,34 @@ void ChromeOmniboxClientIOS::OnResultChanged(
}
}
void ChromeOmniboxClientIOS::OnURLOpenedFromOmnibox(OmniboxLog* log) {
// If a search was done, donate the Search In Chrome intent to the OS for
// future Siri suggestions.
if (!browser_state_->IsOffTheRecord() &&
(log->input_type == metrics::OmniboxInputType::QUERY ||
log->input_type == metrics::OmniboxInputType::UNKNOWN)) {
base::ThreadPool::PostTask(
FROM_HERE, {base::MayBlock(), base::TaskPriority::BEST_EFFORT},
base::BindOnce(^{
SearchInChromeIntent* searchInChromeIntent =
[[SearchInChromeIntent alloc] init];
// SiriKit requires the intent parameter to be set to a non-empty
// string in order to accept the intent donation. Set it to a single
// space, to be later trimmed by the intent handler, which will result
// in the shortcut being treated as if no search phrase was supplied.
searchInChromeIntent.searchPhrase = @" ";
searchInChromeIntent.suggestedInvocationPhrase =
l10n_util::GetNSString(
IDS_IOS_INTENTS_SEARCH_IN_CHROME_INVOCATION_PHRASE);
INInteraction* interaction =
[[INInteraction alloc] initWithIntent:searchInChromeIntent
response:nil];
[interaction donateInteractionWithCompletion:nil];
}));
}
}
void ChromeOmniboxClientIOS::DiscardNonCommittedNavigations() {
controller_->GetWebState()
->GetNavigationManager()
......
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