Commit 855ea26d authored by Maggie Cai's avatar Maggie Cai Committed by Commit Bot

Make intent picker icon persist across tab switches

Currently, when we switching between tabs, the intent picker icon will
disappear. This CL uses the tab helper to persist the intent picker icon
state and ensure it is up to date when switching between tabs.

BUG=801712,915949

Bug: b/120113310
Change-Id: I243773a805955b645e833719a4887905f72b311b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1605321
Commit-Queue: Maggie Cai <mxcai@chromium.org>
Reviewed-by: default avatarDavid Jacobo <djacobo@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Reviewed-by: default avatarAlan Cutter <alancutter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#660325}
parent 53f1748a
...@@ -2808,8 +2808,6 @@ jumbo_split_static_library("browser") { ...@@ -2808,8 +2808,6 @@ jumbo_split_static_library("browser") {
"apps/intent_helper/intent_picker_auto_display_service.h", "apps/intent_helper/intent_picker_auto_display_service.h",
"apps/intent_helper/intent_picker_auto_display_service_factory.cc", "apps/intent_helper/intent_picker_auto_display_service_factory.cc",
"apps/intent_helper/intent_picker_auto_display_service_factory.h", "apps/intent_helper/intent_picker_auto_display_service_factory.h",
"apps/intent_helper/intent_picker_controller.cc",
"apps/intent_helper/intent_picker_controller.h",
"apps/intent_helper/page_transition_util.cc", "apps/intent_helper/page_transition_util.cc",
"apps/intent_helper/page_transition_util.h", "apps/intent_helper/page_transition_util.h",
"background/background_contents.cc", "background/background_contents.cc",
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/extensions/application_launch.h" #include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/browser/ui/intent_picker_tab_helper.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
...@@ -235,10 +236,8 @@ content::NavigationThrottle::ThrottleCheckResult ...@@ -235,10 +236,8 @@ content::NavigationThrottle::ThrottleCheckResult
AppsNavigationThrottle::WillStartRequest() { AppsNavigationThrottle::WillStartRequest() {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
starting_url_ = GetStartingGURL(navigation_handle()); starting_url_ = GetStartingGURL(navigation_handle());
Browser* browser = IntentPickerTabHelper::SetShouldShowIcon(
chrome::FindBrowserWithWebContents(navigation_handle()->GetWebContents()); navigation_handle()->GetWebContents(), false);
if (browser)
browser->window()->SetIntentPickerViewVisibility(/*visible=*/false);
return HandleRequest(); return HandleRequest();
} }
...@@ -360,7 +359,7 @@ void AppsNavigationThrottle::ShowIntentPickerForApps( ...@@ -360,7 +359,7 @@ void AppsNavigationThrottle::ShowIntentPickerForApps(
switch (picker_show_state) { switch (picker_show_state) {
case PickerShowState::kOmnibox: case PickerShowState::kOmnibox:
ui_displayed_ = false; ui_displayed_ = false;
browser->window()->SetIntentPickerViewVisibility(true); IntentPickerTabHelper::SetShouldShowIcon(web_contents, true);
break; break;
case PickerShowState::kPopOut: case PickerShowState::kPopOut:
ShowIntentPickerBubbleForApps(web_contents, std::move(apps), ShowIntentPickerBubbleForApps(web_contents, std::move(apps),
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/apps/intent_helper/intent_picker_controller.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
namespace apps {
IntentPickerController::IntentPickerController(Browser* browser)
: browser_(browser) {
browser_->tab_strip_model()->AddObserver(this);
}
IntentPickerController::~IntentPickerController() {
browser_->tab_strip_model()->RemoveObserver(this);
}
void IntentPickerController::OnTabStripModelChanged(
TabStripModel* tab_strip_model,
const TabStripModelChange& change,
const TabStripSelectionChange& selection) {
if (tab_strip_model->empty())
return;
if (selection.selection_changed())
ResetVisibility();
}
void IntentPickerController::ResetVisibility() {
browser_->window()->SetIntentPickerViewVisibility(/*visible=*/false);
}
} // namespace apps
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_APPS_INTENT_HELPER_INTENT_PICKER_CONTROLLER_H_
#define CHROME_BROWSER_APPS_INTENT_HELPER_INTENT_PICKER_CONTROLLER_H_
#include "base/macros.h"
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
class Browser;
namespace apps {
// Controls the visibility of IntentPickerView by watching whenever the current
// tab is switched. An object of this class is owned by IntentPickerView.
class IntentPickerController : public TabStripModelObserver {
public:
explicit IntentPickerController(Browser* browser);
~IntentPickerController() override;
private:
// TabStripModelObserver:
void OnTabStripModelChanged(
TabStripModel* tab_strip_model,
const TabStripModelChange& change,
const TabStripSelectionChange& selection) override;
void ResetVisibility();
Browser* const browser_;
DISALLOW_COPY_AND_ASSIGN(IntentPickerController);
};
} // namespace apps
#endif // CHROME_BROWSER_APPS_INTENT_HELPER_INTENT_PICKER_CONTROLLER_H_
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/intent_picker_tab_helper.h"
#include "components/arc/arc_service_manager.h" #include "components/arc/arc_service_manager.h"
#include "components/arc/session/arc_bridge_service.h" #include "components/arc/session/arc_bridge_service.h"
#include "content/public/browser/browser_context.h" #include "content/public/browser/browser_context.h"
...@@ -368,11 +369,8 @@ void OnIntentPickerClosed(int render_process_host_id, ...@@ -368,11 +369,8 @@ void OnIntentPickerClosed(int render_process_host_id,
WebContents* web_contents = WebContents* web_contents =
tab_util::GetWebContentsByID(render_process_host_id, routing_id); tab_util::GetWebContentsByID(render_process_host_id, routing_id);
Browser* browser = if (web_contents)
web_contents ? chrome::FindBrowserWithWebContents(web_contents) : nullptr; IntentPickerTabHelper::SetShouldShowIcon(web_contents, false);
if (browser)
browser->window()->SetIntentPickerViewVisibility(/*visible=*/false);
// If the user selected an app to continue the navigation, confirm that the // If the user selected an app to continue the navigation, confirm that the
// |package_name| matches a valid option and return the index. // |package_name| matches a valid option and return the index.
...@@ -470,11 +468,11 @@ void OnAppIconsReceived( ...@@ -470,11 +468,11 @@ void OnAppIconsReceived(
Browser* browser = Browser* browser =
web_contents ? chrome::FindBrowserWithWebContents(web_contents) : nullptr; web_contents ? chrome::FindBrowserWithWebContents(web_contents) : nullptr;
if (!browser) if (!web_contents || !browser)
return; return;
browser->window()->SetIntentPickerViewVisibility(/*visible=*/true);
const bool stay_in_chrome = IsChromeAnAppCandidate(handlers); const bool stay_in_chrome = IsChromeAnAppCandidate(handlers);
IntentPickerTabHelper::SetShouldShowIcon(web_contents, true);
browser->window()->ShowIntentPickerBubble( browser->window()->ShowIntentPickerBubble(
std::move(app_info), stay_in_chrome, /*show_remember_selection=*/true, std::move(app_info), stay_in_chrome, /*show_remember_selection=*/true,
base::BindOnce(OnIntentPickerClosed, render_process_host_id, routing_id, base::BindOnce(OnIntentPickerClosed, render_process_host_id, routing_id,
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/intent_picker_tab_helper.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "components/arc/arc_service_manager.h" #include "components/arc/arc_service_manager.h"
#include "components/arc/intent_helper/arc_intent_helper_bridge.h" #include "components/arc/intent_helper/arc_intent_helper_bridge.h"
...@@ -311,9 +312,7 @@ apps::PreferredPlatform ArcIntentPickerAppFetcher::DidLaunchPreferredArcApp( ...@@ -311,9 +312,7 @@ apps::PreferredPlatform ArcIntentPickerAppFetcher::DidLaunchPreferredArcApp(
if (!instance) { if (!instance) {
close_reason = apps::IntentPickerCloseReason::PICKER_ERROR; close_reason = apps::IntentPickerCloseReason::PICKER_ERROR;
} else if (ArcIntentHelperBridge::IsIntentHelperPackage(package_name)) { } else if (ArcIntentHelperBridge::IsIntentHelperPackage(package_name)) {
Browser* browser = chrome::FindBrowserWithWebContents(web_contents()); IntentPickerTabHelper::SetShouldShowIcon(web_contents(), true);
if (browser)
browser->window()->SetIntentPickerViewVisibility(/*visible=*/true);
preferred_platform = apps::PreferredPlatform::NATIVE_CHROME; preferred_platform = apps::PreferredPlatform::NATIVE_CHROME;
} else { } else {
instance->HandleUrl(url.spec(), package_name); instance->HandleUrl(url.spec(), package_name);
......
...@@ -900,6 +900,8 @@ jumbo_split_static_library("ui") { ...@@ -900,6 +900,8 @@ jumbo_split_static_library("ui") {
"hats/hats_service_factory.h", "hats/hats_service_factory.h",
"hung_renderer/hung_renderer_core.cc", "hung_renderer/hung_renderer_core.cc",
"hung_renderer/hung_renderer_core.h", "hung_renderer/hung_renderer_core.h",
"intent_picker_tab_helper.cc",
"intent_picker_tab_helper.h",
"javascript_dialogs/javascript_dialog_views.cc", "javascript_dialogs/javascript_dialog_views.cc",
"javascript_dialogs/javascript_dialog_views.h", "javascript_dialogs/javascript_dialog_views.h",
"layout_constants.cc", "layout_constants.cc",
......
...@@ -52,6 +52,7 @@ void UpdatePageActionIcon(PageActionIconType icon_type, ...@@ -52,6 +52,7 @@ void UpdatePageActionIcon(PageActionIconType icon_type,
->UpdatePageActionIcon(icon_type); ->UpdatePageActionIcon(icon_type);
break; break;
case PageActionIconType::kFind: case PageActionIconType::kFind:
case PageActionIconType::kIntentPicker:
case PageActionIconType::kPwaInstall: case PageActionIconType::kPwaInstall:
case PageActionIconType::kSendTabToSelf: case PageActionIconType::kSendTabToSelf:
case PageActionIconType::kTranslate: case PageActionIconType::kTranslate:
......
...@@ -334,7 +334,6 @@ class BrowserWindow : public ui::BaseWindow { ...@@ -334,7 +334,6 @@ class BrowserWindow : public ui::BaseWindow {
bool show_stay_in_chrome, bool show_stay_in_chrome,
bool show_remember_selection, bool show_remember_selection,
IntentPickerResponse callback) = 0; IntentPickerResponse callback) = 0;
virtual void SetIntentPickerViewVisibility(bool visible) = 0;
#endif // !defined(OS_ANDROID) #endif // !defined(OS_ANDROID)
// Shows the Bookmark bubble. |url| is the URL being bookmarked, // Shows the Bookmark bubble. |url| is the URL being bookmarked,
......
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/intent_picker_tab_helper.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/page_action/page_action_icon_container.h"
IntentPickerTabHelper::~IntentPickerTabHelper() = default;
// static
void IntentPickerTabHelper::SetShouldShowIcon(
content::WebContents* web_contents,
bool should_show_icon) {
IntentPickerTabHelper* tab_helper = FromWebContents(web_contents);
if (!tab_helper)
return;
tab_helper->should_show_icon_ = should_show_icon;
Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
if (!browser)
return;
browser->window()->GetOmniboxPageActionIconContainer()->UpdatePageActionIcon(
PageActionIconType::kIntentPicker);
}
IntentPickerTabHelper::IntentPickerTabHelper(content::WebContents* web_contents)
: content::WebContentsObserver(web_contents) {}
WEB_CONTENTS_USER_DATA_KEY_IMPL(IntentPickerTabHelper)
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_INTENT_PICKER_TAB_HELPER_H_
#define CHROME_BROWSER_UI_INTENT_PICKER_TAB_HELPER_H_
#include "base/macros.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_contents_user_data.h"
// Controls the visibility of IntentPickerView by updating the visibility based
// on stored state.
class IntentPickerTabHelper
: public content::WebContentsObserver,
public content::WebContentsUserData<IntentPickerTabHelper> {
public:
~IntentPickerTabHelper() override;
static void SetShouldShowIcon(content::WebContents* web_contents,
bool should_show_icon);
bool should_show_icon() const { return should_show_icon_; }
WEB_CONTENTS_USER_DATA_KEY_DECL();
private:
explicit IntentPickerTabHelper(content::WebContents* web_contents);
friend class content::WebContentsUserData<IntentPickerTabHelper>;
bool should_show_icon_ = false;
DISALLOW_COPY_AND_ASSIGN(IntentPickerTabHelper);
};
#endif // CHROME_BROWSER_UI_INTENT_PICKER_TAB_HELPER_H_
...@@ -11,6 +11,7 @@ enum class PageActionIconType { ...@@ -11,6 +11,7 @@ enum class PageActionIconType {
kFind, kFind,
kLocalCardMigration, kLocalCardMigration,
kManagePasswords, kManagePasswords,
kIntentPicker,
kPwaInstall, kPwaInstall,
kSaveCard, kSaveCard,
kSendTabToSelf, kSendTabToSelf,
......
...@@ -109,6 +109,7 @@ ...@@ -109,6 +109,7 @@
#include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h" #include "chrome/browser/safe_browsing/safe_browsing_tab_observer.h"
#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h" #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
#include "chrome/browser/ui/hung_plugin_tab_helper.h" #include "chrome/browser/ui/hung_plugin_tab_helper.h"
#include "chrome/browser/ui/intent_picker_tab_helper.h"
#include "chrome/browser/ui/sad_tab_helper.h" #include "chrome/browser/ui/sad_tab_helper.h"
#include "chrome/browser/ui/search/search_tab_helper.h" #include "chrome/browser/ui/search/search_tab_helper.h"
#include "chrome/browser/ui/sync/browser_synced_tab_delegate.h" #include "chrome/browser/ui/sync/browser_synced_tab_delegate.h"
...@@ -289,6 +290,7 @@ void TabHelpers::AttachTabHelpers(WebContents* web_contents) { ...@@ -289,6 +290,7 @@ void TabHelpers::AttachTabHelpers(WebContents* web_contents) {
extensions::WebNavigationTabObserver::CreateForWebContents(web_contents); extensions::WebNavigationTabObserver::CreateForWebContents(web_contents);
FramebustBlockTabHelper::CreateForWebContents(web_contents); FramebustBlockTabHelper::CreateForWebContents(web_contents);
HungPluginTabHelper::CreateForWebContents(web_contents); HungPluginTabHelper::CreateForWebContents(web_contents);
IntentPickerTabHelper::CreateForWebContents(web_contents);
JavaScriptDialogTabHelper::CreateForWebContents(web_contents); JavaScriptDialogTabHelper::CreateForWebContents(web_contents);
ManagePasswordsUIController::CreateForWebContents(web_contents); ManagePasswordsUIController::CreateForWebContents(web_contents);
pdf::PDFWebContentsHelper::CreateForWebContentsWithClient( pdf::PDFWebContentsHelper::CreateForWebContentsWithClient(
......
...@@ -1312,18 +1312,6 @@ void BrowserView::ShowIntentPickerBubble( ...@@ -1312,18 +1312,6 @@ void BrowserView::ShowIntentPickerBubble(
std::move(callback)); std::move(callback));
} }
void BrowserView::SetIntentPickerViewVisibility(bool visible) {
LocationBarView* location_bar = GetLocationBarView();
if (!location_bar->intent_picker_view())
return;
if (location_bar->intent_picker_view()->GetVisible() != visible) {
location_bar->intent_picker_view()->SetVisible(visible);
location_bar->Layout();
}
}
void BrowserView::ShowBookmarkBubble(const GURL& url, bool already_bookmarked) { void BrowserView::ShowBookmarkBubble(const GURL& url, bool already_bookmarked) {
toolbar_->ShowBookmarkBubble(url, already_bookmarked, toolbar_->ShowBookmarkBubble(url, already_bookmarked,
bookmark_bar_view_.get()); bookmark_bar_view_.get());
......
...@@ -367,7 +367,6 @@ class BrowserView : public BrowserWindow, ...@@ -367,7 +367,6 @@ class BrowserView : public BrowserWindow,
bool show_stay_in_chrome, bool show_stay_in_chrome,
bool show_remember_selection, bool show_remember_selection,
IntentPickerResponse callback) override; IntentPickerResponse callback) override;
void SetIntentPickerViewVisibility(bool visible) override;
void ShowBookmarkBubble(const GURL& url, bool already_bookmarked) override; void ShowBookmarkBubble(const GURL& url, bool already_bookmarked) override;
autofill::SaveCardBubbleView* ShowSaveCreditCardBubble( autofill::SaveCardBubbleView* ShowSaveCreditCardBubble(
content::WebContents* contents, content::WebContents* contents,
......
...@@ -6,10 +6,13 @@ ...@@ -6,10 +6,13 @@
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "chrome/browser/extensions/bookmark_app_navigation_browsertest.h" #include "chrome/browser/extensions/bookmark_app_navigation_browsertest.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/views/frame/browser_view.h" #include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/toolbar_button_provider.h"
#include "chrome/browser/ui/views/intent_picker_bubble_view.h" #include "chrome/browser/ui/views/intent_picker_bubble_view.h"
#include "chrome/browser/ui/views/location_bar/intent_picker_view.h" #include "chrome/browser/ui/views/location_bar/intent_picker_view.h"
#include "chrome/browser/ui/views/location_bar/location_bar_view.h" #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "chrome/browser/ui/views/page_action/omnibox_page_action_icon_container_view.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -26,6 +29,16 @@ class IntentPickerBubbleViewBrowserTest ...@@ -26,6 +29,16 @@ class IntentPickerBubbleViewBrowserTest
extensions::test::BookmarkAppNavigationBrowserTest::SetUp(); extensions::test::BookmarkAppNavigationBrowserTest::SetUp();
} }
void OpenNewTab(const GURL& url) {
chrome::NewTab(browser());
content::WebContents* web_contents =
browser()->tab_strip_model()->GetActiveWebContents();
NavigateToLaunchingPage(browser());
TestTabActionDoesNotOpenAppWindow(
url, base::BindOnce(&ClickLinkAndWait, web_contents, url,
LinkTarget::SELF, GetParam()));
}
private: private:
base::test::ScopedFeatureList scoped_feature_list_; base::test::ScopedFeatureList scoped_feature_list_;
}; };
...@@ -46,10 +59,11 @@ IN_PROC_BROWSER_TEST_P(IntentPickerBubbleViewBrowserTest, ...@@ -46,10 +59,11 @@ IN_PROC_BROWSER_TEST_P(IntentPickerBubbleViewBrowserTest,
in_scope_url, base::BindOnce(&ClickLinkAndWait, web_contents, in_scope_url, base::BindOnce(&ClickLinkAndWait, web_contents,
in_scope_url, LinkTarget::SELF, GetParam())); in_scope_url, LinkTarget::SELF, GetParam()));
IntentPickerView* intent_picker_view = PageActionIconView* intent_picker_view =
BrowserView::GetBrowserViewForBrowser(browser()) BrowserView::GetBrowserViewForBrowser(browser())
->GetLocationBarView() ->toolbar_button_provider()
->intent_picker_view(); ->GetOmniboxPageActionIconContainerView()
->GetPageActionIconView(PageActionIconType::kIntentPicker);
EXPECT_TRUE(intent_picker_view->GetVisible()); EXPECT_TRUE(intent_picker_view->GetVisible());
IntentPickerBubbleView* intent_picker = IntentPickerBubbleView* intent_picker =
...@@ -159,6 +173,36 @@ IN_PROC_BROWSER_TEST_P( ...@@ -159,6 +173,36 @@ IN_PROC_BROWSER_TEST_P(
} }
} }
// Tests that the intent icon updates its visibiliy when switching between
// tabs.
IN_PROC_BROWSER_TEST_P(IntentPickerBubbleViewBrowserTest,
IconVisibilityAfterTabSwitching) {
InstallTestBookmarkApp();
const GURL in_scope_url =
https_server().GetURL(GetAppUrlHost(), GetInScopeUrlPath());
const GURL out_of_scope_url =
https_server().GetURL(GetAppUrlHost(), GetOutOfScopeUrlPath());
PageActionIconView* intent_picker_view =
BrowserView::GetBrowserViewForBrowser(browser())
->toolbar_button_provider()
->GetOmniboxPageActionIconContainerView()
->GetPageActionIconView(PageActionIconType::kIntentPicker);
// OpenNewTab opens a new tab and focus on the new tab.
OpenNewTab(in_scope_url);
EXPECT_TRUE(intent_picker_view->GetVisible());
OpenNewTab(out_of_scope_url);
EXPECT_FALSE(intent_picker_view->GetVisible());
chrome::SelectPreviousTab(browser());
EXPECT_TRUE(intent_picker_view->GetVisible());
chrome::SelectNextTab(browser());
EXPECT_FALSE(intent_picker_view->GetVisible());
}
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
/* no prefix */, /* no prefix */,
IntentPickerBubbleViewBrowserTest, IntentPickerBubbleViewBrowserTest,
......
...@@ -5,10 +5,10 @@ ...@@ -5,10 +5,10 @@
#include "chrome/browser/ui/views/location_bar/intent_picker_view.h" #include "chrome/browser/ui/views/location_bar/intent_picker_view.h"
#include "chrome/browser/apps/intent_helper/apps_navigation_throttle.h" #include "chrome/browser/apps/intent_helper/apps_navigation_throttle.h"
#include "chrome/browser/apps/intent_helper/intent_picker_controller.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/bookmarks/bookmark_utils.h" #include "chrome/browser/ui/bookmarks/bookmark_utils.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/intent_picker_tab_helper.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/views/intent_picker_bubble_view.h" #include "chrome/browser/ui/views/intent_picker_bubble_view.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
...@@ -26,53 +26,62 @@ class WebContents; ...@@ -26,53 +26,62 @@ class WebContents;
IntentPickerView::IntentPickerView(Browser* browser, IntentPickerView::IntentPickerView(Browser* browser,
PageActionIconView::Delegate* delegate) PageActionIconView::Delegate* delegate)
: PageActionIconView(nullptr, 0, delegate), browser_(browser) { : PageActionIconView(nullptr, 0, delegate), browser_(browser) {
if (browser_) {
intent_picker_controller_ =
std::make_unique<apps::IntentPickerController>(browser_);
}
} }
IntentPickerView::~IntentPickerView() = default; IntentPickerView::~IntentPickerView() = default;
void IntentPickerView::SetVisible(bool visible) { bool IntentPickerView::Update() {
// Besides changing visibility, make sure that we don't leave an opened bubble bool was_visible = GetVisible();
// when transitioning to !visible.
if (!visible) SetVisible(ShouldShowIcon());
if (!GetVisible())
IntentPickerBubbleView::CloseCurrentBubble(); IntentPickerBubbleView::CloseCurrentBubble();
PageActionIconView::SetVisible(visible); return was_visible != GetVisible();
} }
void IntentPickerView::OnExecuting( void IntentPickerView::OnExecuting(
PageActionIconView::ExecuteSource execute_source) { PageActionIconView::ExecuteSource execute_source) {
if (browser_ && !browser_->profile()->IsGuestSession() && DCHECK(ShouldShowIcon());
!IsIncognitoMode()) { content::WebContents* web_contents = GetWebContents();
SetVisible(true); const GURL& url = chrome::GetURLToBookmark(web_contents);
content::WebContents* web_contents =
browser_->tab_strip_model()->GetActiveWebContents();
const GURL& url = chrome::GetURLToBookmark(web_contents);
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
chromeos::ChromeOsAppsNavigationThrottle::ShowIntentPickerBubble( chromeos::ChromeOsAppsNavigationThrottle::ShowIntentPickerBubble(
web_contents, /*ui_auto_display_service=*/nullptr, url); web_contents, /*ui_auto_display_service=*/nullptr, url);
#else #else
apps::AppsNavigationThrottle::ShowIntentPickerBubble( apps::AppsNavigationThrottle::ShowIntentPickerBubble(
web_contents, /*ui_auto_display_service=*/nullptr, url); web_contents, /*ui_auto_display_service=*/nullptr, url);
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
} else {
SetVisible(false);
}
} }
views::BubbleDialogDelegateView* IntentPickerView::GetBubble() const { views::BubbleDialogDelegateView* IntentPickerView::GetBubble() const {
return IntentPickerBubbleView::intent_picker_bubble(); return IntentPickerBubbleView::intent_picker_bubble();
} }
bool IntentPickerView::IsIncognitoMode() { bool IntentPickerView::IsIncognitoMode() const {
DCHECK(browser_); DCHECK(browser_);
return browser_->profile()->IsOffTheRecord(); return browser_->profile()->IsOffTheRecord();
} }
bool IntentPickerView::ShouldShowIcon() const {
if (IsIncognitoMode())
return false;
content::WebContents* web_contents = GetWebContents();
if (!web_contents)
return false;
IntentPickerTabHelper* tab_helper =
IntentPickerTabHelper::FromWebContents(web_contents);
if (!tab_helper)
return false;
return tab_helper->should_show_icon();
}
const gfx::VectorIcon& IntentPickerView::GetVectorIcon() const { const gfx::VectorIcon& IntentPickerView::GetVectorIcon() const {
return omnibox::kOpenInNewIcon; return omnibox::kOpenInNewIcon;
} }
......
...@@ -5,15 +5,8 @@ ...@@ -5,15 +5,8 @@
#ifndef CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_INTENT_PICKER_VIEW_H_ #ifndef CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_INTENT_PICKER_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_INTENT_PICKER_VIEW_H_ #define CHROME_BROWSER_UI_VIEWS_LOCATION_BAR_INTENT_PICKER_VIEW_H_
#include <memory>
#include "base/macros.h"
#include "chrome/browser/ui/views/page_action/page_action_icon_view.h" #include "chrome/browser/ui/views/page_action/page_action_icon_view.h"
namespace apps {
class IntentPickerController;
} // namespace apps
class Browser; class Browser;
// The entry point for the intent picker. // The entry point for the intent picker.
...@@ -23,7 +16,7 @@ class IntentPickerView : public PageActionIconView { ...@@ -23,7 +16,7 @@ class IntentPickerView : public PageActionIconView {
~IntentPickerView() override; ~IntentPickerView() override;
// PageActionIconView: // PageActionIconView:
void SetVisible(bool visible) override; bool Update() override;
protected: protected:
// PageActionIconView: // PageActionIconView:
...@@ -33,9 +26,8 @@ class IntentPickerView : public PageActionIconView { ...@@ -33,9 +26,8 @@ class IntentPickerView : public PageActionIconView {
base::string16 GetTextForTooltipAndAccessibleName() const override; base::string16 GetTextForTooltipAndAccessibleName() const override;
private: private:
bool IsIncognitoMode(); bool IsIncognitoMode() const;
bool ShouldShowIcon() const;
std::unique_ptr<apps::IntentPickerController> intent_picker_controller_;
Browser* const browser_; Browser* const browser_;
......
...@@ -49,7 +49,6 @@ ...@@ -49,7 +49,6 @@
#include "chrome/browser/ui/views/chrome_typography.h" #include "chrome/browser/ui/views/chrome_typography.h"
#include "chrome/browser/ui/views/frame/browser_view.h" #include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h"
#include "chrome/browser/ui/views/location_bar/intent_picker_view.h"
#include "chrome/browser/ui/views/location_bar/keyword_hint_view.h" #include "chrome/browser/ui/views/location_bar/keyword_hint_view.h"
#include "chrome/browser/ui/views/location_bar/location_bar_layout.h" #include "chrome/browser/ui/views/location_bar/location_bar_layout.h"
#include "chrome/browser/ui/views/location_bar/location_icon_view.h" #include "chrome/browser/ui/views/location_bar/location_icon_view.h"
...@@ -227,6 +226,7 @@ void LocationBarView::Init() { ...@@ -227,6 +226,7 @@ void LocationBarView::Init() {
params.types_enabled.push_back(PageActionIconType::kManagePasswords); params.types_enabled.push_back(PageActionIconType::kManagePasswords);
} }
params.types_enabled.push_back(PageActionIconType::kFind); params.types_enabled.push_back(PageActionIconType::kFind);
params.types_enabled.push_back(PageActionIconType::kIntentPicker);
params.types_enabled.push_back(PageActionIconType::kTranslate); params.types_enabled.push_back(PageActionIconType::kTranslate);
params.types_enabled.push_back(PageActionIconType::kZoom); params.types_enabled.push_back(PageActionIconType::kZoom);
if (base::FeatureList::IsEnabled(features::kDesktopPWAsOmniboxInstall)) if (base::FeatureList::IsEnabled(features::kDesktopPWAsOmniboxInstall))
...@@ -259,9 +259,6 @@ void LocationBarView::Init() { ...@@ -259,9 +259,6 @@ void LocationBarView::Init() {
page_action_icons_.push_back(local_card_migration_icon_view_); page_action_icons_.push_back(local_card_migration_icon_view_);
} }
page_action_icons_.push_back(intent_picker_view_ =
new IntentPickerView(browser_, this));
page_action_icons_.push_back( page_action_icons_.push_back(
star_view_ = new StarView(command_updater(), browser_, this)); star_view_ = new StarView(command_updater(), browser_, this));
} }
...@@ -557,8 +554,6 @@ void LocationBarView::Layout() { ...@@ -557,8 +554,6 @@ void LocationBarView::Layout() {
if (star_view_) if (star_view_)
add_trailing_decoration(star_view_); add_trailing_decoration(star_view_);
add_trailing_decoration(omnibox_page_action_icon_container_view_); add_trailing_decoration(omnibox_page_action_icon_container_view_);
if (intent_picker_view_)
add_trailing_decoration(intent_picker_view_);
if (save_credit_card_icon_view_) if (save_credit_card_icon_view_)
add_trailing_decoration(save_credit_card_icon_view_); add_trailing_decoration(save_credit_card_icon_view_);
if (local_card_migration_icon_view_) if (local_card_migration_icon_view_)
...@@ -794,8 +789,6 @@ int LocationBarView::GetMinimumTrailingWidth() const { ...@@ -794,8 +789,6 @@ int LocationBarView::GetMinimumTrailingWidth() const {
IncrementalMinimumWidth(save_credit_card_icon_view_) + IncrementalMinimumWidth(save_credit_card_icon_view_) +
IncrementalMinimumWidth(local_card_migration_icon_view_); IncrementalMinimumWidth(local_card_migration_icon_view_);
trailing_width += IncrementalMinimumWidth(intent_picker_view_);
for (auto* content_setting_view : content_setting_views_) for (auto* content_setting_view : content_setting_views_)
trailing_width += IncrementalMinimumWidth(content_setting_view); trailing_width += IncrementalMinimumWidth(content_setting_view);
......
...@@ -41,7 +41,6 @@ ...@@ -41,7 +41,6 @@
class CommandUpdater; class CommandUpdater;
class ContentSettingBubbleModelDelegate; class ContentSettingBubbleModelDelegate;
class GURL; class GURL;
class IntentPickerView;
class KeywordHintView; class KeywordHintView;
class LocationIconView; class LocationIconView;
enum class OmniboxPart; enum class OmniboxPart;
...@@ -148,10 +147,6 @@ class LocationBarView : public LocationBar, ...@@ -148,10 +147,6 @@ class LocationBarView : public LocationBar,
// Toggles the star on or off. // Toggles the star on or off.
void SetStarToggled(bool on); void SetStarToggled(bool on);
// The intent picker, should not always be visible. It will be null when
// |browser_| is null.
IntentPickerView* intent_picker_view() { return intent_picker_view_; }
// The star. It may not be visible. It will be null when |browser_| is null. // The star. It may not be visible. It will be null when |browser_| is null.
StarView* star_view() { return star_view_; } StarView* star_view() { return star_view_; }
...@@ -430,10 +425,6 @@ class LocationBarView : public LocationBar, ...@@ -430,10 +425,6 @@ class LocationBarView : public LocationBar,
send_tab_to_self::SendTabToSelfIconView* send_tab_to_self_icon_view_ = send_tab_to_self::SendTabToSelfIconView* send_tab_to_self_icon_view_ =
nullptr; nullptr;
// The intent picker for accessing apps. It will be null when
// |browser_| is null.
IntentPickerView* intent_picker_view_ = nullptr;
// The star for bookmarking. It will be null when |browser_| is null. // The star for bookmarking. It will be null when |browser_| is null.
StarView* star_view_ = nullptr; StarView* star_view_ = nullptr;
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/views/location_bar/find_bar_icon.h" #include "chrome/browser/ui/views/location_bar/find_bar_icon.h"
#include "chrome/browser/ui/views/location_bar/intent_picker_view.h"
#include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h"
#include "chrome/browser/ui/views/page_action/pwa_install_view.h" #include "chrome/browser/ui/views/page_action/pwa_install_view.h"
#include "chrome/browser/ui/views/page_action/zoom_view.h" #include "chrome/browser/ui/views/page_action/zoom_view.h"
...@@ -44,6 +45,11 @@ OmniboxPageActionIconContainerView::OmniboxPageActionIconContainerView( ...@@ -44,6 +45,11 @@ OmniboxPageActionIconContainerView::OmniboxPageActionIconContainerView(
params.command_updater, params.page_action_icon_delegate); params.command_updater, params.page_action_icon_delegate);
page_action_icons_.push_back(manage_passwords_icon_); page_action_icons_.push_back(manage_passwords_icon_);
break; break;
case PageActionIconType::kIntentPicker:
intent_picker_view_ = new IntentPickerView(
params.browser, params.page_action_icon_delegate);
page_action_icons_.push_back(intent_picker_view_);
break;
case PageActionIconType::kPwaInstall: case PageActionIconType::kPwaInstall:
DCHECK(params.command_updater); DCHECK(params.command_updater);
pwa_install_view_ = new PwaInstallView( pwa_install_view_ = new PwaInstallView(
...@@ -98,6 +104,8 @@ PageActionIconView* OmniboxPageActionIconContainerView::GetPageActionIconView( ...@@ -98,6 +104,8 @@ PageActionIconView* OmniboxPageActionIconContainerView::GetPageActionIconView(
return find_bar_icon_; return find_bar_icon_;
case PageActionIconType::kManagePasswords: case PageActionIconType::kManagePasswords:
return manage_passwords_icon_; return manage_passwords_icon_;
case PageActionIconType::kIntentPicker:
return intent_picker_view_;
case PageActionIconType::kPwaInstall: case PageActionIconType::kPwaInstall:
return pwa_install_view_; return pwa_install_view_;
case PageActionIconType::kTranslate: case PageActionIconType::kTranslate:
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
class Browser; class Browser;
class CommandUpdater; class CommandUpdater;
class FindBarIcon; class FindBarIcon;
class IntentPickerView;
class ManagePasswordsIconViews; class ManagePasswordsIconViews;
class PwaInstallView; class PwaInstallView;
class TranslateIconView; class TranslateIconView;
...@@ -81,6 +82,7 @@ class OmniboxPageActionIconContainerView ...@@ -81,6 +82,7 @@ class OmniboxPageActionIconContainerView
ZoomView* zoom_view_ = nullptr; ZoomView* zoom_view_ = nullptr;
FindBarIcon* find_bar_icon_ = nullptr; FindBarIcon* find_bar_icon_ = nullptr;
ManagePasswordsIconViews* manage_passwords_icon_ = nullptr; ManagePasswordsIconViews* manage_passwords_icon_ = nullptr;
IntentPickerView* intent_picker_view_ = nullptr;
PwaInstallView* pwa_install_view_ = nullptr; PwaInstallView* pwa_install_view_ = nullptr;
send_tab_to_self::SendTabToSelfIconView* send_tab_to_self_icon_view_ = send_tab_to_self::SendTabToSelfIconView* send_tab_to_self_icon_view_ =
nullptr; nullptr;
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "chrome/browser/ui/extensions/hosted_app_browser_controller.h" #include "chrome/browser/ui/extensions/hosted_app_browser_controller.h"
#include "chrome/browser/ui/global_error/global_error_service.h" #include "chrome/browser/ui/global_error/global_error_service.h"
#include "chrome/browser/ui/global_error/global_error_service_factory.h" #include "chrome/browser/ui/global_error/global_error_service_factory.h"
#include "chrome/browser/ui/intent_picker_tab_helper.h"
#include "chrome/browser/ui/layout_constants.h" #include "chrome/browser/ui/layout_constants.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/ui_features.h" #include "chrome/browser/ui/ui_features.h"
...@@ -38,9 +39,9 @@ ...@@ -38,9 +39,9 @@
#include "chrome/browser/ui/views/extensions/extensions_toolbar_button.h" #include "chrome/browser/ui/views/extensions/extensions_toolbar_button.h"
#include "chrome/browser/ui/views/extensions/extensions_toolbar_container.h" #include "chrome/browser/ui/views/extensions/extensions_toolbar_container.h"
#include "chrome/browser/ui/views/frame/browser_view.h" #include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/location_bar/intent_picker_view.h"
#include "chrome/browser/ui/views/location_bar/star_view.h" #include "chrome/browser/ui/views/location_bar/star_view.h"
#include "chrome/browser/ui/views/media_router/cast_toolbar_button.h" #include "chrome/browser/ui/views/media_router/cast_toolbar_button.h"
#include "chrome/browser/ui/views/page_action/omnibox_page_action_icon_container_view.h"
#include "chrome/browser/ui/views/tabs/tab_strip.h" #include "chrome/browser/ui/views/tabs/tab_strip.h"
#include "chrome/browser/ui/views/toolbar/app_menu.h" #include "chrome/browser/ui/views/toolbar/app_menu.h"
#include "chrome/browser/ui/views/toolbar/browser_actions_container.h" #include "chrome/browser/ui/views/toolbar/browser_actions_container.h"
...@@ -391,13 +392,13 @@ void ToolbarView::ShowIntentPickerBubble( ...@@ -391,13 +392,13 @@ void ToolbarView::ShowIntentPickerBubble(
bool show_stay_in_chrome, bool show_stay_in_chrome,
bool show_remember_selection, bool show_remember_selection,
IntentPickerResponse callback) { IntentPickerResponse callback) {
IntentPickerView* intent_picker_view = location_bar()->intent_picker_view(); PageActionIconView* intent_picker_view =
location_bar()
->omnibox_page_action_icon_container_view()
->GetPageActionIconView(PageActionIconType::kIntentPicker);
if (intent_picker_view) { if (intent_picker_view) {
if (!intent_picker_view->GetVisible()) { if (!intent_picker_view->GetVisible())
intent_picker_view->SetVisible(true); IntentPickerTabHelper::SetShouldShowIcon(GetWebContents(), true);
location_bar()->Layout();
}
IntentPickerBubbleView::ShowBubble( IntentPickerBubbleView::ShowBubble(
intent_picker_view, GetWebContents(), std::move(app_info), intent_picker_view, GetWebContents(), std::move(app_info),
show_stay_in_chrome, show_remember_selection, std::move(callback)); show_stay_in_chrome, show_remember_selection, std::move(callback));
......
...@@ -125,7 +125,6 @@ class TestBrowserWindow : public BrowserWindow { ...@@ -125,7 +125,6 @@ class TestBrowserWindow : public BrowserWindow {
bool show_stay_in_chrome, bool show_stay_in_chrome,
bool show_remember_selection, bool show_remember_selection,
IntentPickerResponse callback) override {} IntentPickerResponse callback) override {}
void SetIntentPickerViewVisibility(bool visible) override {}
#endif // !define(OS_ANDROID) #endif // !define(OS_ANDROID)
autofill::SaveCardBubbleView* ShowSaveCreditCardBubble( autofill::SaveCardBubbleView* ShowSaveCreditCardBubble(
content::WebContents* contents, content::WebContents* contents,
......
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