Skip to content

Commit

Permalink
views: register ShellCrApplication in views content clients
Browse files Browse the repository at this point in the history
Not doing this causes a DCHECK failure at startup (issue 917698) but also causes
the Chrome message loop not to interoperate properly with the native message
loop.

Bug: 917698
Change-Id: Ife2e789a2eb8679bc32bc5b8349fef1dbebb0c80
Reviewed-on: https://chromium-review.googlesource.com/c/1432652
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Auto-Submit: Elly Fong-Jones <ellyjones@chromium.org>
Reviewed-by: Trent Apted <tapted@chromium.org>
Cr-Commit-Position: refs/heads/master@{#625709}
  • Loading branch information
Elly Fong-Jones authored and Commit Bot committed Jan 24, 2019
1 parent cf92464 commit 3ebef67
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ui/views_content_client/views_content_client_main_parts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <utility>

#include "base/run_loop.h"
#include "build/build_config.h"
#include "content/public/browser/context_factory.h"
#include "content/shell/browser/shell_browser_context.h"
#include "ui/base/ime/input_method_initializer.h"
Expand All @@ -25,6 +26,10 @@ ViewsContentClientMainParts::ViewsContentClientMainParts(
ViewsContentClientMainParts::~ViewsContentClientMainParts() {
}

#if !defined(OS_MACOSX)
void ViewsContentClientMainParts::PreCreateMainMessageLoop() {}
#endif

void ViewsContentClientMainParts::PreMainMessageLoopRun() {
ui::MaterialDesignController::Initialize();
ui::InitializeInputMethodForTesting();
Expand Down
3 changes: 3 additions & 0 deletions ui/views_content_client/views_content_client_main_parts.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class ViewsContentClientMainParts : public content::BrowserMainParts {
const content::MainFunctionParams& content_params,
ViewsContentClient* views_content_client);

// Invoked before the BrowserMainLoop constructor.
static void PreCreateMainMessageLoop();

~ViewsContentClientMainParts() override;

// content::BrowserMainParts:
Expand Down
12 changes: 12 additions & 0 deletions ui/views_content_client/views_content_client_main_parts_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "base/path_service.h"
#include "content/public/browser/plugin_service.h"
#include "content/public/common/content_paths.h"
#include "content/shell/browser/shell_application_mac.h"
#include "content/shell/browser/shell_browser_context.h"
#include "ui/views_content_client/views_content_client.h"
#include "ui/views_content_client/views_content_client_main_parts.h"
Expand Down Expand Up @@ -84,6 +85,15 @@ - (void)setTask:(const base::Closure&)task;
new ViewsContentClientMainPartsMac(content_params, views_content_client);
}

// static
void ViewsContentClientMainParts::PreCreateMainMessageLoop() {
// Simply instantiating an instance of ShellCrApplication serves to register
// it as the application class. Do make sure that no other code has done this
// first, though.
CHECK_EQ(NSApp, nil);
[ShellCrApplication sharedApplication];
}

} // namespace ui

@implementation ViewsContentClientAppController
Expand Down Expand Up @@ -114,6 +124,8 @@ - (void)applicationDidFinishLaunching:(NSNotification*)aNotification {
keyEquivalent:@"q"];
[appMenuItem setSubmenu:appMenu];

CHECK([NSApp isKindOfClass:[ShellCrApplication class]]);

task_.Run();
}

Expand Down
6 changes: 6 additions & 0 deletions ui/views_content_client/views_content_main_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_paths.h"
#include "ui/views_content_client/views_content_browser_client.h"
#include "ui/views_content_client/views_content_client_main_parts.h"

#if defined(OS_WIN)
#include "base/logging_win.h"
Expand Down Expand Up @@ -79,6 +80,11 @@ void ViewsContentMainDelegate::PreSandboxStartup() {
}
}

void ViewsContentMainDelegate::PreCreateMainMessageLoop() {
content::ContentMainDelegate::PreCreateMainMessageLoop();
ViewsContentClientMainParts::PreCreateMainMessageLoop();
}

content::ContentBrowserClient*
ViewsContentMainDelegate::CreateContentBrowserClient() {
browser_client_.reset(new ViewsContentBrowserClient(views_content_client_));
Expand Down
1 change: 1 addition & 0 deletions ui/views_content_client/views_content_main_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class ViewsContentMainDelegate : public content::ContentMainDelegate {
// content::ContentMainDelegate implementation
bool BasicStartupComplete(int* exit_code) override;
void PreSandboxStartup() override;
void PreCreateMainMessageLoop() override;
content::ContentBrowserClient* CreateContentBrowserClient() override;

private:
Expand Down

0 comments on commit 3ebef67

Please sign in to comment.