Skip to content

Commit ec7eb66

Browse files
committed
cobalt: Only observe WebContents on main app
Issue: 441738743
1 parent 8e157f9 commit ec7eb66

File tree

5 files changed

+28
-3
lines changed

5 files changed

+28
-3
lines changed

cobalt/browser/cobalt_content_browser_client.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include "cobalt/shell/browser/shell.h"
3838
#include "cobalt/shell/browser/shell_paths.h"
3939
#include "cobalt/shell/common/shell_switches.h"
40+
#include "cobalt/shell/common/url_constants.h"
4041
#include "components/metrics/metrics_state_manager.h"
4142
#include "components/metrics_services_manager/metrics_services_manager.h"
4243
#include "components/prefs/pref_registry_simple.h"
@@ -298,6 +299,12 @@ void CobaltContentBrowserClient::ConfigureNetworkContextParams(
298299
void CobaltContentBrowserClient::OnWebContentsCreated(
299300
content::WebContents* web_contents) {
300301
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
302+
if (web_contents->GetPrimaryMainFrame() &&
303+
web_contents->GetPrimaryMainFrame()->GetFrameName() ==
304+
content::kCobaltSplashMainFrameName) {
305+
// Don't observe and delegate WebContents if it's splash screen.
306+
return;
307+
}
301308
web_contents_observer_.reset(new CobaltWebContentsObserver(web_contents));
302309
web_contents_delegate_.reset(new CobaltWebContentsDelegate());
303310
content::Shell::SetShellCreatedCallback(base::BindOnce(

cobalt/shell/browser/shell.cc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,22 @@ gfx::Size Shell::AdjustWindowSize(const gfx::Size& initial_size) {
239239
Shell* Shell::CreateNewWindow(BrowserContext* browser_context,
240240
const GURL& url,
241241
const scoped_refptr<SiteInstance>& site_instance,
242-
const gfx::Size& initial_size) {
242+
const gfx::Size& initial_size,
243+
const std::string& main_frame_name) {
243244
WebContents::CreateParams create_params(browser_context, site_instance);
245+
#if BUILDFLAG(IS_ANDROID)
246+
// Workaround to determine if WebContents is for main app or splash screen.
247+
// As a result, CobaltContentBrowserClient::OnWebContentsCreated() only
248+
// observes WebContents on main app.
249+
if (!main_frame_name.empty()) {
250+
// Set |main_frame_name| for splash screen, where
251+
// ShellBrowserMainParts::InitializeMessageLoopContext() creates
252+
// WebContents, and it loads splash screen. On the other hand,
253+
// JNI_ShellManager_LaunchShell() should not set |main_frame_name|.
254+
create_params.main_frame_name = main_frame_name;
255+
}
256+
#endif // BUILDFLAG(IS_ANDROID)
257+
244258
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
245259
switches::kForcePresentationReceiverForTesting)) {
246260
create_params.starting_sandbox_flags = kPresentationReceiverSandboxFlags;

cobalt/shell/browser/shell.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ class Shell : public WebContentsDelegate, public WebContentsObserver {
9191
BrowserContext* browser_context,
9292
const GURL& url,
9393
const scoped_refptr<SiteInstance>& site_instance,
94-
const gfx::Size& initial_size);
94+
const gfx::Size& initial_size,
95+
const std::string& main_frame_name = "");
9596

9697
// Returns the Shell object corresponding to the given WebContents.
9798
static Shell* FromWebContents(WebContents* web_contents);

cobalt/shell/browser/shell_browser_main_parts.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "cobalt/shell/browser/shell_devtools_manager_delegate.h"
3636
#include "cobalt/shell/browser/shell_platform_delegate.h"
3737
#include "cobalt/shell/common/shell_switches.h"
38+
#include "cobalt/shell/common/url_constants.h"
3839
#include "components/performance_manager/embedder/graph_features.h"
3940
#include "components/performance_manager/embedder/performance_manager_lifetime.h"
4041
#include "content/public/browser/browser_thread.h"
@@ -142,7 +143,7 @@ void ShellBrowserMainParts::InitializeBrowserContexts() {
142143

143144
void ShellBrowserMainParts::InitializeMessageLoopContext() {
144145
Shell::CreateNewWindow(browser_context_.get(), GetStartupURL(), nullptr,
145-
gfx::Size());
146+
gfx::Size(), kCobaltSplashMainFrameName);
146147
}
147148

148149
void ShellBrowserMainParts::ToolkitInitialized() {

cobalt/shell/common/url_constants.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ namespace content {
1919

2020
inline constexpr char kH5vccEmbeddedScheme[] = "h5vcc-embedded";
2121

22+
inline constexpr char kCobaltSplashMainFrameName[] = "Splash";
23+
2224
} // namespace content
2325

2426
#endif // COBALT_SHELL_COMMON_URL_CONSTANTS_H_

0 commit comments

Comments
 (0)