Commit 64ab8afe authored by David Jacobo's avatar David Jacobo Committed by Commit Bot

Show picker's icon even if Chrome is preferred

When there is a preferred app (because the user set it previously) we
need to honor that decision and use that preference for the next similar
urls. This means that the intent picker won't be auto-displayed, however
the icon needs to be shown, so the user can still decide to continue in
other app instead of their previously recorded preferred app.

Also removing ShowIntentPickerCallback since the throttle no longer
communicates directly with the UI.

Bug: 678141
Test: Try.
Change-Id: Id550d4763a05d7db1734ce4b11dd1077e38bee9d
Reviewed-on: https://chromium-review.googlesource.com/722071
Commit-Queue: David Jacobo <djacobo@chromium.org>
Reviewed-by: default avatarYusuke Sato <yusukes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#509243}
parent 2ed77c0c
...@@ -3300,9 +3300,8 @@ ChromeContentBrowserClient::CreateThrottlesForNavigation( ...@@ -3300,9 +3300,8 @@ ChromeContentBrowserClient::CreateThrottlesForNavigation(
prerender::PrerenderContents::FromWebContents( prerender::PrerenderContents::FromWebContents(
handle->GetWebContents()); handle->GetWebContents());
if (!prerender_contents) { if (!prerender_contents) {
auto intent_picker_cb = base::Bind(ShowIntentPickerBubble()); auto url_to_arc_throttle =
auto url_to_arc_throttle = base::MakeUnique<arc::ArcNavigationThrottle>( base::MakeUnique<arc::ArcNavigationThrottle>(handle);
handle, intent_picker_cb);
throttles.push_back(std::move(url_to_arc_throttle)); throttles.push_back(std::move(url_to_arc_throttle));
} }
} }
......
...@@ -99,10 +99,8 @@ size_t FindPreferredApp( ...@@ -99,10 +99,8 @@ size_t FindPreferredApp(
} // namespace } // namespace
ArcNavigationThrottle::ArcNavigationThrottle( ArcNavigationThrottle::ArcNavigationThrottle(
content::NavigationHandle* navigation_handle, content::NavigationHandle* navigation_handle)
const ShowIntentPickerCallback& show_intent_picker_cb)
: content::NavigationThrottle(navigation_handle), : content::NavigationThrottle(navigation_handle),
show_intent_picker_callback_(show_intent_picker_cb),
ui_displayed_(false), ui_displayed_(false),
weak_ptr_factory_(this) {} weak_ptr_factory_(this) {}
...@@ -253,20 +251,24 @@ void ArcNavigationThrottle::OnAppCandidatesReceived( ...@@ -253,20 +251,24 @@ void ArcNavigationThrottle::OnAppCandidatesReceived(
if (!instance) { if (!instance) {
close_reason = CloseReason::ERROR; close_reason = CloseReason::ERROR;
} else if (!ArcIntentHelperBridge::IsIntentHelperPackage(package_name)) { } else {
Browser* browser = chrome::FindBrowserWithWebContents( if (!ArcIntentHelperBridge::IsIntentHelperPackage(package_name))
navigation_handle()->GetWebContents()); instance->HandleUrl(url.spec(), package_name);
// Make intent picker's icon visible if there are installed apps that can
// handle the current URL, this enables the user to still access ARC's
// apps even if they marked an app or Chrome as preferred before.
Browser* browser =
chrome::FindBrowserWithWebContents(handle->GetWebContents());
if (browser) if (browser)
chrome::SetIntentPickerViewVisibility(browser, true); chrome::SetIntentPickerViewVisibility(browser, true);
instance->HandleUrl(url.spec(), package_name);
} }
Platform platform = GetDestinationPlatform(package_name, close_reason); Platform platform = GetDestinationPlatform(package_name, close_reason);
RecordUma(close_reason, platform); RecordUma(close_reason, platform);
} else { } else {
auto* intent_helper_bridge = ArcIntentHelperBridge::GetForBrowserContext( auto* intent_helper_bridge = ArcIntentHelperBridge::GetForBrowserContext(
navigation_handle()->GetWebContents()->GetBrowserContext()); handle->GetWebContents()->GetBrowserContext());
if (!intent_helper_bridge) { if (!intent_helper_bridge) {
LOG(ERROR) << "Cannot get an instance of ArcIntentHelperBridge"; LOG(ERROR) << "Cannot get an instance of ArcIntentHelperBridge";
return; return;
...@@ -276,10 +278,10 @@ void ArcNavigationThrottle::OnAppCandidatesReceived( ...@@ -276,10 +278,10 @@ void ArcNavigationThrottle::OnAppCandidatesReceived(
activities.emplace_back(handler->package_name, handler->activity_name); activities.emplace_back(handler->package_name, handler->activity_name);
intent_helper_bridge->GetActivityIcons( intent_helper_bridge->GetActivityIcons(
activities, base::Bind(&ArcNavigationThrottle::AsyncOnAppIconsReceived, activities,
chrome::FindBrowserWithWebContents( base::Bind(&ArcNavigationThrottle::AsyncOnAppIconsReceived,
navigation_handle()->GetWebContents()), chrome::FindBrowserWithWebContents(handle->GetWebContents()),
base::Passed(&handlers), url)); base::Passed(&handlers), url));
} }
} }
......
...@@ -22,14 +22,8 @@ class Browser; ...@@ -22,14 +22,8 @@ class Browser;
namespace content { namespace content {
class NavigationHandle; class NavigationHandle;
class WebContents;
} // namespace content } // namespace content
namespace views {
class View;
class Widget;
} // namespace views
namespace arc { namespace arc {
// A class that allow us to retrieve ARC app's information and handle URL // A class that allow us to retrieve ARC app's information and handle URL
...@@ -84,17 +78,11 @@ class ArcNavigationThrottle : public content::NavigationThrottle { ...@@ -84,17 +78,11 @@ class ArcNavigationThrottle : public content::NavigationThrottle {
std::string activity_name; std::string activity_name;
}; };
using ShowIntentPickerCallback = base::Callback<views::Widget*(
views::View* anchor_view,
content::WebContents* web_contents,
const std::vector<AppInfo>& app_info,
const base::Callback<void(const std::string&, CloseReason)>& cb)>;
using QueryAndDisplayArcAppsCallback = base::Callback<void( using QueryAndDisplayArcAppsCallback = base::Callback<void(
const Browser* browser, const Browser* browser,
const std::vector<AppInfo>& app_info, const std::vector<AppInfo>& app_info,
const base::Callback<void(const std::string&, CloseReason)>& cb)>; const base::Callback<void(const std::string&, CloseReason)>& cb)>;
ArcNavigationThrottle(content::NavigationHandle* navigation_handle, explicit ArcNavigationThrottle(content::NavigationHandle* navigation_handle);
const ShowIntentPickerCallback& show_intent_picker_cb);
~ArcNavigationThrottle() override; ~ArcNavigationThrottle() override;
static bool ShouldOverrideUrlLoadingForTesting(const GURL& previous_url, static bool ShouldOverrideUrlLoadingForTesting(const GURL& previous_url,
...@@ -167,11 +155,6 @@ class ArcNavigationThrottle : public content::NavigationThrottle { ...@@ -167,11 +155,6 @@ class ArcNavigationThrottle : public content::NavigationThrottle {
const std::string& package_name, const std::string& package_name,
arc::ArcNavigationThrottle::CloseReason close_reason); arc::ArcNavigationThrottle::CloseReason close_reason);
// A callback object that allow us to display an IntentPicker when Run() is
// executed, it also allow us to report the user's selection back to
// OnIntentPickerClosed().
ShowIntentPickerCallback show_intent_picker_callback_;
// Keeps a referrence to the starting GURL. // Keeps a referrence to the starting GURL.
GURL starting_gurl_; GURL starting_gurl_;
......
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