Commit 888f8247 authored by Richard Knoll's avatar Richard Knoll Committed by Commit Bot

Close SharingDialogs on main frame cross origin navigation

This closes SharingDialogViews when the main frame navigates to a
different origin. Right now this only affects the SharingDialog and
(for CrOS) the IntentPickerBubbleView but will be enabled for all
subclasses of LocationBarBubbleDelegateView in a subsequent change.

Bug: 1027408
Change-Id: I07ca9ce55042265d85e56a84c5e43efa3cb026d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1948839
Commit-Queue: Richard Knoll <knollr@chromium.org>
Reviewed-by: default avatarElly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: default avatarEmily Stark <estark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721565}
parent 0191c254
......@@ -296,6 +296,8 @@ IntentPickerBubbleView::IntentPickerBubbleView(
ui::DIALOG_BUTTON_CANCEL,
l10n_util::GetStringUTF16(IDS_INTENT_PICKER_BUBBLE_VIEW_STAY_IN_CHROME));
set_close_on_main_frame_origin_navigation(true);
chrome::RecordDialogCreation(chrome::DialogIdentifier::INTENT_PICKER);
}
......
......@@ -9,10 +9,12 @@
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/layout_constants.h"
#include "chrome/grit/generated_resources.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_view_host.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/views/accessibility/view_accessibility.h"
#include "url/origin.h"
LocationBarBubbleDelegateView::WebContentMouseHandler::WebContentMouseHandler(
LocationBarBubbleDelegateView* bubble,
......@@ -91,6 +93,21 @@ void LocationBarBubbleDelegateView::WebContentsDestroyed() {
CloseBubble();
}
void LocationBarBubbleDelegateView::DidFinishNavigation(
content::NavigationHandle* navigation_handle) {
if (!close_on_main_frame_origin_navigation_ ||
!navigation_handle->IsInMainFrame() ||
!navigation_handle->HasCommitted()) {
return;
}
// Close dialog when navigating to a different domain.
if (!url::IsSameOriginWith(navigation_handle->GetPreviousURL(),
navigation_handle->GetURL())) {
CloseBubble();
}
}
gfx::Rect LocationBarBubbleDelegateView::GetAnchorBoundsInScreen() const {
gfx::Rect bounds = GetBoundsInScreen();
bounds.Inset(gfx::Insets(
......
......@@ -61,6 +61,8 @@ class LocationBarBubbleDelegateView : public views::BubbleDialogDelegateView,
// content::WebContentsObserver:
void OnVisibilityChanged(content::Visibility visibility) override;
void WebContentsDestroyed() override;
void DidFinishNavigation(
content::NavigationHandle* navigation_handle) override;
// views::BubbleDialogDelegateView:
gfx::Rect GetAnchorBoundsInScreen() const override;
......@@ -95,10 +97,18 @@ class LocationBarBubbleDelegateView : public views::BubbleDialogDelegateView,
// Closes the bubble.
virtual void CloseBubble();
void set_close_on_main_frame_origin_navigation(bool close) {
close_on_main_frame_origin_navigation_ = close;
}
private:
ScopedObserver<FullscreenController, FullscreenObserver> fullscreen_observer_{
this};
// A flag controlling bubble closure when the main frame navigates to a
// different origin.
bool close_on_main_frame_origin_navigation_ = false;
DISALLOW_COPY_AND_ASSIGN(LocationBarBubbleDelegateView);
};
......
......@@ -539,6 +539,31 @@ IN_PROC_BROWSER_TEST_F(ClickToCallBrowserTest, OpenNewTabAndShowBubble) {
#endif // defined(OS_CHROMEOS)
}
IN_PROC_BROWSER_TEST_F(ClickToCallBrowserTest, NavigateDifferentOrigin) {
Init(sync_pb::SharingSpecificFields::CLICK_TO_CALL,
sync_pb::SharingSpecificFields::UNKNOWN);
base::RunLoop run_loop;
PageActionIconView* click_to_call_icon =
GetPageActionIconView(PageActionIconType::kClickToCall);
ClickToCallUiController::GetOrCreateFromWebContents(web_contents())
->set_on_dialog_shown_closure_for_testing(run_loop.QuitClosure());
// Click on the tel link to trigger the bubble view.
web_contents()->GetMainFrame()->ExecuteJavaScriptForTests(
base::ASCIIToUTF16("document.querySelector('a').click();"),
base::NullCallback());
// Wait until the bubble is visible.
run_loop.Run();
EXPECT_NE(nullptr, click_to_call_icon->GetBubble());
// Navigate to a different origin.
sessions_helper::NavigateTab(/*browser_index=*/0, GURL("https://google.com"));
// Ensure that the bubble is now closed.
EXPECT_EQ(nullptr, click_to_call_icon->GetBubble());
}
class ClickToCallPolicyTest
: public policy::PolicyTest,
public testing::WithParamInterface<ClickToCallPolicy> {
......
......@@ -182,6 +182,7 @@ SharingDialogView::SharingDialogView(views::View* anchor_view,
DialogDelegate::set_buttons(ui::DIALOG_BUTTON_NONE);
DialogDelegate::SetFootnoteView(
CreateHelpOrOriginView(data_, web_contents, this));
set_close_on_main_frame_origin_navigation(true);
}
SharingDialogView::~SharingDialogView() = default;
......
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