Commit 315c1fb2 authored by Jay Harris's avatar Jay Harris Committed by Commit Bot

Null check BadgeManager before attempting to add it to a ReceiverSet.

In incognito and guest profiles, the BadgeManagerFactory does not create
a BadgeManager. As there are no apps in incognito/guest profiles this
would not normally be a problem. However, in BadgeManager::BindRequest,
we were attempting to add the null BadgeManager to a mojo reciever set,
causing a crash.

Note: This does not affect the API exposed to the, so this cannot be
used to detect incognito mode.

Bug: 1004122
Change-Id: I5024665257a67aaaf28aa7f3bb8cd9cfcdef2d25
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1824041Reviewed-by: default avatarAlan Cutter <alancutter@chromium.org>
Commit-Queue: Jay Harris <harrisjay@chromium.org>
Cr-Commit-Position: refs/heads/master@{#700073}
parent 61ab9830
...@@ -52,10 +52,13 @@ void BadgeManager::BindReceiver( ...@@ -52,10 +52,13 @@ void BadgeManager::BindReceiver(
mojo::PendingReceiver<blink::mojom::BadgeService> receiver) { mojo::PendingReceiver<blink::mojom::BadgeService> receiver) {
Profile* profile = Profile::FromBrowserContext( Profile* profile = Profile::FromBrowserContext(
content::WebContents::FromRenderFrameHost(frame)->GetBrowserContext()); content::WebContents::FromRenderFrameHost(frame)->GetBrowserContext());
badging::BadgeManager* badge_manager = badging::BadgeManager* badge_manager =
badging::BadgeManagerFactory::GetInstance()->GetForProfile(profile); badging::BadgeManagerFactory::GetInstance()->GetForProfile(profile);
BindingContext context(frame->GetProcess()->GetID(), frame->GetRoutingID()); if (!badge_manager)
return;
BindingContext context(frame->GetProcess()->GetID(), frame->GetRoutingID());
badge_manager->receivers_.Add(badge_manager, std::move(receiver), badge_manager->receivers_.Add(badge_manager, std::move(receiver),
std::move(context)); std::move(context));
} }
......
...@@ -22,6 +22,8 @@ class BadgeManager; ...@@ -22,6 +22,8 @@ class BadgeManager;
// Singleton that provides access to Profile specific BadgeManagers. // Singleton that provides access to Profile specific BadgeManagers.
class BadgeManagerFactory : public BrowserContextKeyedServiceFactory { class BadgeManagerFactory : public BrowserContextKeyedServiceFactory {
public: public:
// Gets the BadgeManager for the current profile. |nullptr| for guest and
// incognito profiles.
static BadgeManager* GetForProfile(Profile* profile); static BadgeManager* GetForProfile(Profile* profile);
// Returns the BadgeManagerFactory singleton. // Returns the BadgeManagerFactory singleton.
......
...@@ -215,6 +215,21 @@ IN_PROC_BROWSER_TEST_P(WebAppBadgingBrowserTest, ...@@ -215,6 +215,21 @@ IN_PROC_BROWSER_TEST_P(WebAppBadgingBrowserTest,
ASSERT_EQ(base::nullopt, last_badge_content_); ASSERT_EQ(base::nullopt, last_badge_content_);
} }
// Tests that badging incognito windows does not cause a crash.
IN_PROC_BROWSER_TEST_P(WebAppBadgingBrowserTest,
BadgingIncognitoWindowsDoesNotCrash) {
Browser* incognito_browser =
OpenURLOffTheRecord(profile(), main_frame_->GetLastCommittedURL());
RenderFrameHost* incognito_frame = incognito_browser->tab_strip_model()
->GetActiveWebContents()
->GetMainFrame();
ASSERT_TRUE(
content::ExecuteScript(incognito_frame, "ExperimentalBadge.set()"));
ASSERT_TRUE(
content::ExecuteScript(incognito_frame, "ExperimentalBadge.clear()"));
}
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
/* no prefix */, /* no prefix */,
WebAppBadgingBrowserTest, WebAppBadgingBrowserTest,
......
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