-
Notifications
You must be signed in to change notification settings - Fork 896
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a220e96
commit 820ff66
Showing
20 changed files
with
303 additions
and
273 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright (c) 2025 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
#include "brave/browser/tab_informer/tab_informer.h" | ||
|
||
#include <utility> | ||
|
||
#include "base/strings/utf_string_conversions.h" | ||
#include "brave/browser/tab_informer/tab_informer_service_factory.h" | ||
#include "brave/components/tab_informer/browser/tab_informer_service.h" | ||
#include "brave/components/tab_informer/common/tab_informer.mojom.h" | ||
#include "chrome/browser/ui/tabs/tab_model.h" | ||
#include "content/public/browser/navigation_entry.h" | ||
#include "content/public/browser/navigation_handle.h" | ||
#include "content/public/browser/web_contents_observer.h" | ||
|
||
namespace tab_informer { | ||
|
||
namespace { | ||
|
||
mojom::TabPtr FromWebContents(content::WebContents* web_contents) { | ||
auto tab = mojom::Tab::New(); | ||
tab->content_id = | ||
web_contents->GetController().GetVisibleEntry()->GetUniqueID(); | ||
tab->title = base::UTF16ToUTF8(web_contents->GetTitle()); | ||
tab->url = web_contents->GetLastCommittedURL(); | ||
return tab; | ||
} | ||
|
||
} // namespace | ||
|
||
TabInformer::TabInformer(content::WebContents* web_contents) | ||
: content::WebContentsObserver(web_contents), | ||
tab_id_(tabs::TabModel::GetFromContents(web_contents)->GetTabHandle()) {} | ||
|
||
TabInformer::~TabInformer() { | ||
auto* service = TabInformerServiceFactory::GetForBrowserContext( | ||
web_contents()->GetBrowserContext()); | ||
if (!service) { | ||
return; | ||
} | ||
|
||
service->UpdateTab(tab_id_, nullptr); | ||
} | ||
|
||
void TabInformer::TitleWasSet(content::NavigationEntry* entry) { | ||
UpdateTab(); | ||
} | ||
|
||
void TabInformer::PrimaryPageChanged(content::Page& page) { | ||
UpdateTab(); | ||
} | ||
|
||
void TabInformer::UpdateTab() { | ||
auto* service = TabInformerServiceFactory::GetForBrowserContext( | ||
web_contents()->GetBrowserContext()); | ||
if (!service) { | ||
return; | ||
} | ||
|
||
auto tab = FromWebContents(web_contents()); | ||
tab->id = tab_id_; | ||
service->UpdateTab(tab_id_, std::move(tab)); | ||
} | ||
|
||
} // namespace tab_informer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright (c) 2025 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
// You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
#ifndef BRAVE_BROWSER_TAB_INFORMER_TAB_INFORMER_H_ | ||
#define BRAVE_BROWSER_TAB_INFORMER_TAB_INFORMER_H_ | ||
|
||
#include "content/public/browser/web_contents_observer.h" | ||
|
||
namespace content { | ||
class NavigationEntry; | ||
} | ||
|
||
namespace tab_informer { | ||
|
||
class TabInformer : public content::WebContentsObserver { | ||
public: | ||
explicit TabInformer(content::WebContents* contents); | ||
~TabInformer() override; | ||
|
||
TabInformer(const TabInformer&) = delete; | ||
TabInformer& operator=(const TabInformer&) = delete; | ||
|
||
void PrimaryPageChanged(content::Page& page) override; | ||
void TitleWasSet(content::NavigationEntry* entry) override; | ||
|
||
private: | ||
int32_t tab_id_ = 0; | ||
|
||
void UpdateTab(); | ||
}; | ||
|
||
} // namespace tab_informer | ||
|
||
#endif // BRAVE_BROWSER_TAB_INFORMER_TAB_INFORMER_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.