Commit 249cd0d7 authored by Richard Knoll's avatar Richard Knoll Committed by Commit Bot

Use active WebContents for SharingDialogs

Instead of using the WebContents from the tab that initiated showing a
SharingDialog, always use the one from the currently shown tab. This
makes sure that we show the origin if the initiating one does not match
the one in the active tab.

Bug: 1029414
Change-Id: Idf79aeff17db3c5cf3137af19727bdaf79989bf6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1948838
Commit-Queue: Richard Knoll <knollr@chromium.org>
Reviewed-by: default avatarMichael van Ouwerkerk <mvanouwerkerk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#721409}
parent e210af07
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "chrome/browser/sharing/sharing_dialog.h" #include "chrome/browser/sharing/sharing_dialog.h"
#include "chrome/browser/shell_integration.h" #include "chrome/browser/shell_integration.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "components/sync_device_info/device_info.h" #include "components/sync_device_info/device_info.h"
#include "components/vector_icons/vector_icons.h" #include "components/vector_icons/vector_icons.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
...@@ -27,6 +28,10 @@ using SharingMessage = chrome_browser_sharing::SharingMessage; ...@@ -27,6 +28,10 @@ using SharingMessage = chrome_browser_sharing::SharingMessage;
// static // static
ClickToCallUiController* ClickToCallUiController::GetOrCreateFromWebContents( ClickToCallUiController* ClickToCallUiController::GetOrCreateFromWebContents(
content::WebContents* web_contents) { content::WebContents* web_contents) {
// Use active WebContents if available.
Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
if (browser)
web_contents = browser->tab_strip_model()->GetActiveWebContents();
ClickToCallUiController::CreateForWebContents(web_contents); ClickToCallUiController::CreateForWebContents(web_contents);
return ClickToCallUiController::FromWebContents(web_contents); return ClickToCallUiController::FromWebContents(web_contents);
} }
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include "chrome/app/vector_icons/vector_icons.h" #include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/sharing/sharing_constants.h" #include "chrome/browser/sharing/sharing_constants.h"
#include "chrome/browser/sharing/sharing_dialog.h" #include "chrome/browser/sharing/sharing_dialog.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "components/sync_device_info/device_info.h" #include "components/sync_device_info/device_info.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
...@@ -21,6 +23,10 @@ ...@@ -21,6 +23,10 @@
SharedClipboardUiController* SharedClipboardUiController*
SharedClipboardUiController::GetOrCreateFromWebContents( SharedClipboardUiController::GetOrCreateFromWebContents(
content::WebContents* web_contents) { content::WebContents* web_contents) {
// Use active WebContents if available.
Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
if (browser)
web_contents = browser->tab_strip_model()->GetActiveWebContents();
SharedClipboardUiController::CreateForWebContents(web_contents); SharedClipboardUiController::CreateForWebContents(web_contents);
return SharedClipboardUiController::FromWebContents(web_contents); return SharedClipboardUiController::FromWebContents(web_contents);
} }
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "chrome/browser/ui/views/sharing/sharing_browsertest.h" #include "chrome/browser/ui/views/sharing/sharing_browsertest.h"
#include "chrome/browser/ui/views/sharing/sharing_dialog_view.h" #include "chrome/browser/ui/views/sharing/sharing_dialog_view.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/policy/policy_constants.h" #include "components/policy/policy_constants.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/sync/driver/profile_sync_service.h" #include "components/sync/driver/profile_sync_service.h"
...@@ -37,6 +38,7 @@ ...@@ -37,6 +38,7 @@
#include "services/metrics/public/cpp/ukm_builders.h" #include "services/metrics/public/cpp/ukm_builders.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "ui/events/base_event_utils.h" #include "ui/events/base_event_utils.h"
#include "ui/views/layout/grid_layout.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace { namespace {
...@@ -499,6 +501,44 @@ IN_PROC_BROWSER_TEST_F(ClickToCallBrowserTest, LeftClick_ChooseDevice) { ...@@ -499,6 +501,44 @@ IN_PROC_BROWSER_TEST_F(ClickToCallBrowserTest, LeftClick_ChooseDevice) {
} }
#endif #endif
IN_PROC_BROWSER_TEST_F(ClickToCallBrowserTest, OpenNewTabAndShowBubble) {
Init(sync_pb::SharingSpecificFields::CLICK_TO_CALL,
sync_pb::SharingSpecificFields::UNKNOWN);
// Open tab to different origin.
sessions_helper::OpenTab(
/*browser_index=*/0,
embedded_test_server()->GetURL("mock2.http", GetTestPageURL()));
// Expect dialog to be shown in context of active WebContents.
base::RunLoop run_loop;
ClickToCallUiController::GetOrCreateFromWebContents(
GetBrowser(0)->tab_strip_model()->GetWebContentsAt(1))
->set_on_dialog_shown_closure_for_testing(run_loop.QuitClosure());
// Navigate initial tab to a tel link.
NavigateParams params(GetBrowser(0), GURL(kTelUrl), ui::PAGE_TRANSITION_LINK);
params.source_contents = web_contents();
params.initiator_origin = url::Origin::Create(GURL("mock.http"));
params.disposition = WindowOpenDisposition::CURRENT_TAB;
ui_test_utils::NavigateToURL(&params);
// Wait until the bubble is visible.
run_loop.Run();
views::BubbleDialogDelegateView* bubble =
GetPageActionIconView(PageActionIconType::kClickToCall)->GetBubble();
ASSERT_NE(nullptr, bubble);
#if defined(OS_CHROMEOS)
// Ensure that the dialog shows the origin in column id 1.
EXPECT_NE(nullptr, static_cast<views::GridLayout*>(bubble->GetLayoutManager())
->GetColumnSet(1));
#else
// Ensure that the dialog shows the origin in the footnote.
EXPECT_NE(nullptr, bubble->GetFootnoteViewForTesting());
#endif // defined(OS_CHROMEOS)
}
class ClickToCallPolicyTest class ClickToCallPolicyTest
: public policy::PolicyTest, : public policy::PolicyTest,
public testing::WithParamInterface<ClickToCallPolicy> { public testing::WithParamInterface<ClickToCallPolicy> {
......
...@@ -39,6 +39,7 @@ SharingBrowserTest::~SharingBrowserTest() = default; ...@@ -39,6 +39,7 @@ SharingBrowserTest::~SharingBrowserTest() = default;
void SharingBrowserTest::SetUpOnMainThread() { void SharingBrowserTest::SetUpOnMainThread() {
SyncTest::SetUpOnMainThread(); SyncTest::SetUpOnMainThread();
host_resolver()->AddRule("mock.http", "127.0.0.1"); host_resolver()->AddRule("mock.http", "127.0.0.1");
host_resolver()->AddRule("mock2.http", "127.0.0.1");
} }
void SharingBrowserTest::Init( void SharingBrowserTest::Init(
......
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