Commit f946f83f authored by David Black's avatar David Black Committed by Commit Bot

Roughs in support for feedback deep link.

Deep link launches Chrome OS feedback.

Known issues:
- Feedback UI launches behind Assistant UI.
- Feedback does not attach Assistant server logs.

See bug for demo.

Bug: b:111222894
Change-Id: I6424cfdf633c1dfdfec1e91663259c2c04d810b5
Reviewed-on: https://chromium-review.googlesource.com/1134470
Commit-Queue: David Black <dmblack@google.com>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#574959}
parent 99794227
...@@ -28,11 +28,13 @@ AssistantController::AssistantController() ...@@ -28,11 +28,13 @@ AssistantController::AssistantController()
std::make_unique<AssistantScreenContextController>(this)), std::make_unique<AssistantScreenContextController>(this)),
assistant_ui_controller_(std::make_unique<AssistantUiController>(this)), assistant_ui_controller_(std::make_unique<AssistantUiController>(this)),
weak_factory_(this) { weak_factory_(this) {
AddObserver(this);
NotifyConstructed(); NotifyConstructed();
} }
AssistantController::~AssistantController() { AssistantController::~AssistantController() {
NotifyDestroying(); NotifyDestroying();
RemoveObserver(this);
} }
void AssistantController::BindRequest( void AssistantController::BindRequest(
...@@ -143,6 +145,15 @@ void AssistantController::DownloadImage( ...@@ -143,6 +145,15 @@ void AssistantController::DownloadImage(
assistant_image_downloader_->Download(account_id, url, std::move(callback)); assistant_image_downloader_->Download(account_id, url, std::move(callback));
} }
void AssistantController::OnDeepLinkReceived(const GURL& deep_link) {
// TODO(dmblack): Possibly use a new FeedbackSource (this method defaults to
// kFeedbackSourceAsh). This may be useful for differentiating feedback UI and
// behavior for Assistant.
using assistant::util::DeepLinkType;
if (assistant::util::IsDeepLinkType(deep_link, DeepLinkType::kFeedback))
Shell::Get()->new_window_controller()->OpenFeedbackPage();
}
void AssistantController::OnOpenUrlFromTab(const GURL& url) { void AssistantController::OnOpenUrlFromTab(const GURL& url) {
OpenUrl(url); OpenUrl(url);
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <vector> #include <vector>
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "ash/assistant/assistant_controller_observer.h"
#include "ash/public/interfaces/assistant_controller.mojom.h" #include "ash/public/interfaces/assistant_controller.mojom.h"
#include "ash/public/interfaces/assistant_image_downloader.mojom.h" #include "ash/public/interfaces/assistant_image_downloader.mojom.h"
#include "ash/public/interfaces/assistant_setup.mojom.h" #include "ash/public/interfaces/assistant_setup.mojom.h"
...@@ -27,7 +28,6 @@ class UnguessableToken; ...@@ -27,7 +28,6 @@ class UnguessableToken;
namespace ash { namespace ash {
class AssistantControllerObserver;
class AssistantInteractionController; class AssistantInteractionController;
class AssistantNotificationController; class AssistantNotificationController;
class AssistantScreenContextController; class AssistantScreenContextController;
...@@ -35,6 +35,7 @@ class AssistantUiController; ...@@ -35,6 +35,7 @@ class AssistantUiController;
class ASH_EXPORT AssistantController class ASH_EXPORT AssistantController
: public mojom::AssistantController, : public mojom::AssistantController,
public AssistantControllerObserver,
public mojom::ManagedWebContentsOpenUrlDelegate { public mojom::ManagedWebContentsOpenUrlDelegate {
public: public:
AssistantController(); AssistantController();
...@@ -84,6 +85,9 @@ class ASH_EXPORT AssistantController ...@@ -84,6 +85,9 @@ class ASH_EXPORT AssistantController
void RequestScreenshot(const gfx::Rect& rect, void RequestScreenshot(const gfx::Rect& rect,
RequestScreenshotCallback callback) override; RequestScreenshotCallback callback) override;
// AssistantControllerObserver:
void OnDeepLinkReceived(const GURL& deep_link) override;
// mojom::ManagedWebContentsOpenUrlDelegate: // mojom::ManagedWebContentsOpenUrlDelegate:
void OnOpenUrlFromTab(const GURL& url) override; void OnOpenUrlFromTab(const GURL& url) override;
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "ash/assistant/assistant_interaction_controller.h" #include "ash/assistant/assistant_interaction_controller.h"
#include "ash/assistant/assistant_controller.h" #include "ash/assistant/assistant_controller.h"
#include "ash/assistant/assistant_notification_controller.h"
#include "ash/assistant/assistant_ui_controller.h" #include "ash/assistant/assistant_ui_controller.h"
#include "ash/assistant/model/assistant_interaction_model_observer.h" #include "ash/assistant/model/assistant_interaction_model_observer.h"
#include "ash/assistant/model/assistant_query.h" #include "ash/assistant/model/assistant_query.h"
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "ash/assistant/util/deep_link_util.h" #include "ash/assistant/util/deep_link_util.h"
#include <set>
#include "base/strings/string_split.h" #include "base/strings/string_split.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -14,7 +16,9 @@ namespace util { ...@@ -14,7 +16,9 @@ namespace util {
namespace { namespace {
// Supported deep link prefixes.
constexpr char kAssistantExplorePrefix[] = "googleassistant://explore"; constexpr char kAssistantExplorePrefix[] = "googleassistant://explore";
constexpr char kAssistantFeedbackPrefix[] = "googleassistant://send-feedback";
constexpr char kAssistantOnboardingPrefix[] = "googleassistant://onboarding"; constexpr char kAssistantOnboardingPrefix[] = "googleassistant://onboarding";
constexpr char kAssistantRemindersPrefix[] = "googleassistant://reminders"; constexpr char kAssistantRemindersPrefix[] = "googleassistant://reminders";
constexpr char kAssistantSettingsPrefix[] = "googleassistant://settings"; constexpr char kAssistantSettingsPrefix[] = "googleassistant://settings";
...@@ -43,58 +47,71 @@ constexpr char kAssistantSettingsWebUrl[] = R"(data:text/html, ...@@ -43,58 +47,71 @@ constexpr char kAssistantSettingsWebUrl[] = R"(data:text/html,
</html> </html>
)"; )";
} // namespace // Map of supported deep link types to their prefixes.
const std::map<DeepLinkType, std::string> kSupportedDeepLinks = {
{DeepLinkType::kExplore, kAssistantExplorePrefix},
{DeepLinkType::kFeedback, kAssistantFeedbackPrefix},
{DeepLinkType::kOnboarding, kAssistantOnboardingPrefix},
{DeepLinkType::kReminders, kAssistantRemindersPrefix},
{DeepLinkType::kSettings, kAssistantSettingsPrefix}};
bool IsDeepLinkUrl(const GURL& url) { // Set of deep link types which open web contents in the Assistant UI.
return IsAssistantExploreDeepLink(url) || const std::set<DeepLinkType> kWebDeepLinks = {
IsAssistantOnboardingDeepLink(url) || DeepLinkType::kExplore, DeepLinkType::kReminders, DeepLinkType::kSettings};
IsAssistantRemindersDeepLink(url) || IsAssistantSettingsDeepLink(url);
}
bool IsAssistantExploreDeepLink(const GURL& url) { } // namespace
return base::StartsWith(url.spec(), kAssistantExplorePrefix,
base::CompareCase::SENSITIVE);
}
bool IsAssistantOnboardingDeepLink(const GURL& url) { GURL CreateAssistantSettingsDeepLink() {
return base::StartsWith(url.spec(), kAssistantOnboardingPrefix, return GURL(kAssistantSettingsPrefix);
base::CompareCase::SENSITIVE);
} }
bool IsAssistantRemindersDeepLink(const GURL& url) { DeepLinkType GetDeepLinkType(const GURL& url) {
return base::StartsWith(url.spec(), kAssistantRemindersPrefix, for (const auto& supported_deep_link : kSupportedDeepLinks) {
base::CompareCase::SENSITIVE); if (base::StartsWith(url.spec(), supported_deep_link.second,
base::CompareCase::SENSITIVE)) {
return supported_deep_link.first;
}
}
return DeepLinkType::kUnsupported;
} }
GURL CreateAssistantSettingsDeepLink() { bool IsDeepLinkType(const GURL& url, DeepLinkType type) {
return GURL(kAssistantSettingsPrefix); return GetDeepLinkType(url) == type;
} }
bool IsAssistantSettingsDeepLink(const GURL& url) { bool IsDeepLinkUrl(const GURL& url) {
return base::StartsWith(url.spec(), kAssistantSettingsPrefix, return GetDeepLinkType(url) != DeepLinkType::kUnsupported;
base::CompareCase::SENSITIVE);
} }
base::Optional<GURL> GetWebUrl(const GURL& deep_link) { base::Optional<GURL> GetWebUrl(const GURL& deep_link) {
if (!IsWebDeepLink(deep_link)) DeepLinkType type = GetDeepLinkType(deep_link);
return base::nullopt;
if (IsAssistantExploreDeepLink(deep_link))
return GURL(kAssistantExploreWebUrl);
if (IsAssistantRemindersDeepLink(deep_link)) if (!IsWebDeepLinkType(type))
return GURL(kAssistantRemindersWebUrl); return base::nullopt;
if (IsAssistantSettingsDeepLink(deep_link)) switch (type) {
return GURL(kAssistantSettingsWebUrl); case DeepLinkType::kExplore:
return GURL(kAssistantExploreWebUrl);
case DeepLinkType::kReminders:
return GURL(kAssistantRemindersWebUrl);
case DeepLinkType::kSettings:
return GURL(kAssistantSettingsWebUrl);
case DeepLinkType::kUnsupported:
case DeepLinkType::kFeedback:
case DeepLinkType::kOnboarding:
NOTREACHED();
return base::nullopt;
}
NOTIMPLEMENTED();
return base::nullopt; return base::nullopt;
} }
bool IsWebDeepLink(const GURL& url) { bool IsWebDeepLink(const GURL& deep_link) {
return IsAssistantExploreDeepLink(url) || IsAssistantRemindersDeepLink(url) || return IsWebDeepLinkType(GetDeepLinkType(deep_link));
IsAssistantSettingsDeepLink(url); }
bool IsWebDeepLinkType(DeepLinkType type) {
return kWebDeepLinks.count(type) != 0;
} }
bool ParseDeepLinkParams(const GURL& deep_link, bool ParseDeepLinkParams(const GURL& deep_link,
......
...@@ -17,35 +17,39 @@ namespace ash { ...@@ -17,35 +17,39 @@ namespace ash {
namespace assistant { namespace assistant {
namespace util { namespace util {
// Returns true if the specified |url| is a deep link, false otherwise. // Enumeration of deep link types.
ASH_EXPORT bool IsDeepLinkUrl(const GURL& url); enum class DeepLinkType {
kUnsupported,
// Returns true if the specified |url| is an Assistant explore deep link, kExplore,
// false otherwise. kFeedback,
ASH_EXPORT bool IsAssistantExploreDeepLink(const GURL& url); kOnboarding,
kReminders,
// Returns true if the specified |url| is an Assistant onboarding deep link, kSettings,
// false otherwise. };
ASH_EXPORT bool IsAssistantOnboardingDeepLink(const GURL& url);
// Returns true if the specified |url| is an Assistant reminders deep link,
// false otherwise.
ASH_EXPORT bool IsAssistantRemindersDeepLink(const GURL& url);
// Returns a deep link to top level Assistant Settings. // Returns a deep link to top level Assistant Settings.
ASH_EXPORT GURL CreateAssistantSettingsDeepLink(); ASH_EXPORT GURL CreateAssistantSettingsDeepLink();
// Returns true if the specified |url| is an Assistant Settings deep link, false // Returns the deep link type of the specified |url|. If the specified url is
// otherwise. // not a supported deep link, DeepLinkType::kUnsupported is returned.
ASH_EXPORT bool IsAssistantSettingsDeepLink(const GURL& url); ASH_EXPORT DeepLinkType GetDeepLinkType(const GURL& url);
// Returns true if the specified |url| is a deep link of the given |type|.
ASH_EXPORT bool IsDeepLinkType(const GURL& url, DeepLinkType type);
// Returns true if the specified |url| is a deep link, false otherwise.
ASH_EXPORT bool IsDeepLinkUrl(const GURL& url);
// Returns the web URL for the specified |deep_link|. A return value will only // Returns the web URL for the specified |deep_link|. A return value will only
// be present if |deep_link| is a web deep link as identified by the // be present if |deep_link| is a web deep link as identified by the
// IsWebDeepLink(GURL) API. // IsWebDeepLink(GURL) API.
ASH_EXPORT base::Optional<GURL> GetWebUrl(const GURL& deep_link); ASH_EXPORT base::Optional<GURL> GetWebUrl(const GURL& deep_link);
// Returns true if the specified |url| is a web deep link, false otherwise. // Returns true if the specified |deep_link| is a web deep link.
ASH_EXPORT bool IsWebDeepLink(const GURL& url); ASH_EXPORT bool IsWebDeepLink(const GURL& deep_link);
// Returns true if the specified deep link |type| is a web deep link.
ASH_EXPORT bool IsWebDeepLinkType(DeepLinkType type);
// Parses the specified |deep_link| for the values corresponding to the keys in // Parses the specified |deep_link| for the values corresponding to the keys in
// |params|. If a value for a key in |params| is found, it is inserted into the // |params|. If a value for a key in |params| is found, it is inserted into the
......
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