Commit 580779d7 authored by djacobo's avatar djacobo Committed by Commit bot

Closing unused new tabs for ARC

Some links open a new tab while navigating, given that we redirect some
of the traffic to ARC, it can be necessary to close any unused tab.

Since we are closing the contained WebContents on a tab, we need to make
sure the callback within the UI doesn't get called twice, since intent
picker has an observer for the WebContents.

BUG=647806
TEST=manual test

Review-Url: https://codereview.chromium.org/2347273002
Cr-Commit-Position: refs/heads/master@{#419335}
parent 9d3621fa
...@@ -16,7 +16,9 @@ ...@@ -16,7 +16,9 @@
#include "components/arc/intent_helper/arc_intent_helper_bridge.h" #include "components/arc/intent_helper/arc_intent_helper_bridge.h"
#include "components/arc/intent_helper/local_activity_resolver.h" #include "components/arc/intent_helper/local_activity_resolver.h"
#include "content/public/browser/browser_thread.h" #include "content/public/browser/browser_thread.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/navigation_handle.h" #include "content/public/browser/navigation_handle.h"
#include "content/public/browser/web_contents.h"
#include "net/base/registry_controlled_domains/registry_controlled_domain.h" #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
#include "ui/base/page_transition_types.h" #include "ui/base/page_transition_types.h"
...@@ -231,6 +233,8 @@ void ArcNavigationThrottle::OnIntentPickerClosed( ...@@ -231,6 +233,8 @@ void ArcNavigationThrottle::OnIntentPickerClosed(
handlers[selected_app_index]->package_name); handlers[selected_app_index]->package_name);
handle->CancelDeferredNavigation( handle->CancelDeferredNavigation(
content::NavigationThrottle::CANCEL_AND_IGNORE); content::NavigationThrottle::CANCEL_AND_IGNORE);
if (handle->GetWebContents()->GetController().IsInitialNavigation())
handle->GetWebContents()->Close();
} }
break; break;
} }
......
...@@ -236,10 +236,10 @@ IntentPickerBubbleView::~IntentPickerBubbleView() { ...@@ -236,10 +236,10 @@ IntentPickerBubbleView::~IntentPickerBubbleView() {
// the callback so the caller can Resume the navigation. // the callback so the caller can Resume the navigation.
void IntentPickerBubbleView::OnWidgetDestroying(views::Widget* widget) { void IntentPickerBubbleView::OnWidgetDestroying(views::Widget* widget) {
if (!was_callback_run_) { if (!was_callback_run_) {
was_callback_run_ = true;
throttle_cb_.Run( throttle_cb_.Run(
kAppTagNoneSelected, kAppTagNoneSelected,
arc::ArcNavigationThrottle::CloseReason::DIALOG_DEACTIVATED); arc::ArcNavigationThrottle::CloseReason::DIALOG_DEACTIVATED);
was_callback_run_ = true;
} }
} }
...@@ -251,16 +251,16 @@ void IntentPickerBubbleView::ButtonPressed(views::Button* sender, ...@@ -251,16 +251,16 @@ void IntentPickerBubbleView::ButtonPressed(views::Button* sender,
const ui::Event& event) { const ui::Event& event) {
switch (sender->tag()) { switch (sender->tag()) {
case static_cast<int>(Option::ALWAYS): case static_cast<int>(Option::ALWAYS):
was_callback_run_ = true;
throttle_cb_.Run(selected_app_tag_, throttle_cb_.Run(selected_app_tag_,
arc::ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED); arc::ArcNavigationThrottle::CloseReason::ALWAYS_PRESSED);
was_callback_run_ = true;
GetWidget()->Close(); GetWidget()->Close();
break; break;
case static_cast<int>(Option::JUST_ONCE): case static_cast<int>(Option::JUST_ONCE):
was_callback_run_ = true;
throttle_cb_.Run( throttle_cb_.Run(
selected_app_tag_, selected_app_tag_,
arc::ArcNavigationThrottle::CloseReason::JUST_ONCE_PRESSED); arc::ArcNavigationThrottle::CloseReason::JUST_ONCE_PRESSED);
was_callback_run_ = true;
GetWidget()->Close(); GetWidget()->Close();
break; break;
default: default:
...@@ -297,9 +297,9 @@ gfx::Size IntentPickerBubbleView::GetPreferredSize() const { ...@@ -297,9 +297,9 @@ gfx::Size IntentPickerBubbleView::GetPreferredSize() const {
// should inform the caller about this error. // should inform the caller about this error.
void IntentPickerBubbleView::WebContentsDestroyed() { void IntentPickerBubbleView::WebContentsDestroyed() {
if (!was_callback_run_) { if (!was_callback_run_) {
was_callback_run_ = true;
throttle_cb_.Run(kAppTagNoneSelected, throttle_cb_.Run(kAppTagNoneSelected,
arc::ArcNavigationThrottle::CloseReason::ERROR); arc::ArcNavigationThrottle::CloseReason::ERROR);
was_callback_run_ = true;
} }
GetWidget()->Close(); GetWidget()->Close();
} }
......
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