Commit bcf87ab6 authored by Marina Ciocea's avatar Marina Ciocea Committed by Commit Bot

Update tab sharing infobars label on shared tab navigation.

When the shared tab navigates to a new URL, update the label on the tab
sharing infobars to reflect the new name of the shared tab.

Bug: 999170
Change-Id: I025a8bb2a958bf73cd921a5337c7dc64ee6428ff
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1816537Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Commit-Queue: Marina Ciocea <marinaciocea@chromium.org>
Cr-Commit-Position: refs/heads/master@{#698433}
parent 9414ec3a
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "chrome/browser/ui/views/frame/browser_view.h" #include "chrome/browser/ui/views/frame/browser_view.h"
#include "components/infobars/core/infobar.h" #include "components/infobars/core/infobar.h"
#include "components/url_formatter/elide_url.h" #include "components/url_formatter/elide_url.h"
#include "content/public/browser/navigation_handle.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/common/origin_util.h" #include "content/public/common/origin_util.h"
...@@ -115,6 +116,7 @@ TabSharingUIViews::TabSharingUIViews(const content::DesktopMediaID& media_id, ...@@ -115,6 +116,7 @@ TabSharingUIViews::TabSharingUIViews(const content::DesktopMediaID& media_id,
content::RenderFrameHost::FromID( content::RenderFrameHost::FromID(
media_id.web_contents_id.render_process_id, media_id.web_contents_id.render_process_id,
media_id.web_contents_id.main_render_frame_id)); media_id.web_contents_id.main_render_frame_id));
Observe(shared_tab_);
shared_tab_name_ = GetTabName(shared_tab_); shared_tab_name_ = GetTabName(shared_tab_);
profile_ = ProfileManager::GetLastUsedProfileAllowedByPolicy(); profile_ = ProfileManager::GetLastUsedProfileAllowedByPolicy();
InitContentsBorderWidget(shared_tab_); InitContentsBorderWidget(shared_tab_);
...@@ -238,6 +240,25 @@ void TabSharingUIViews::OnInfoBarRemoved(infobars::InfoBar* info_bar, ...@@ -238,6 +240,25 @@ void TabSharingUIViews::OnInfoBarRemoved(infobars::InfoBar* info_bar,
StopSharing(); StopSharing();
} }
void TabSharingUIViews::DidFinishNavigation(content::NavigationHandle* handle) {
// Only interested in committed navigations on the shared tab that result in
// changing the shared tab's name.
if (!handle->IsInMainFrame() || !handle->HasCommitted() ||
handle->IsSameDocument() || handle->GetWebContents() != shared_tab_ ||
GetTabName(shared_tab_) == shared_tab_name_) {
return;
}
shared_tab_name_ = GetTabName(shared_tab_);
for (const auto& infobars_entry : infobars_) {
if (infobars_entry.first == shared_tab_)
continue;
// Recreate infobars to reflect the new shared tab name.
infobars_entry.second->owner()->RemoveObserver(this);
infobars_entry.second->RemoveSelf();
CreateInfobarForWebContents(infobars_entry.first);
}
}
void TabSharingUIViews::CreateInfobarsForAllTabs() { void TabSharingUIViews::CreateInfobarsForAllTabs() {
BrowserList* browser_list = BrowserList::GetInstance(); BrowserList* browser_list = BrowserList::GetInstance();
for (auto* browser : *browser_list) { for (auto* browser : *browser_list) {
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "chrome/browser/ui/tabs/tab_strip_model_observer.h" #include "chrome/browser/ui/tabs/tab_strip_model_observer.h"
#include "components/infobars/core/infobar_manager.h" #include "components/infobars/core/infobar_manager.h"
#include "content/public/browser/desktop_media_id.h" #include "content/public/browser/desktop_media_id.h"
#include "content/public/browser/web_contents_observer.h"
namespace content { namespace content {
class WebContents; class WebContents;
...@@ -31,7 +32,8 @@ class Profile; ...@@ -31,7 +32,8 @@ class Profile;
class TabSharingUIViews : public TabSharingUI, class TabSharingUIViews : public TabSharingUI,
public BrowserListObserver, public BrowserListObserver,
public TabStripModelObserver, public TabStripModelObserver,
public infobars::InfoBarManager::Observer { public infobars::InfoBarManager::Observer,
public content::WebContentsObserver {
public: public:
TabSharingUIViews(const content::DesktopMediaID& media_id, TabSharingUIViews(const content::DesktopMediaID& media_id,
base::string16 app_name); base::string16 app_name);
...@@ -69,6 +71,10 @@ class TabSharingUIViews : public TabSharingUI, ...@@ -69,6 +71,10 @@ class TabSharingUIViews : public TabSharingUI,
// InfoBarManager::Observer: // InfoBarManager::Observer:
void OnInfoBarRemoved(infobars::InfoBar* infobar, bool animate) override; void OnInfoBarRemoved(infobars::InfoBar* infobar, bool animate) override;
// WebContentsObserver:
void DidFinishNavigation(
content::NavigationHandle* navigation_handle) override;
private: private:
void CreateInfobarsForAllTabs(); void CreateInfobarsForAllTabs();
void CreateInfobarForWebContents(content::WebContents* contents); void CreateInfobarForWebContents(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