Commit 521a0ab3 authored by jamescook's avatar jamescook Committed by Commit bot

app_shell: Fix focus on opening new app windows

app_shell is pure-aura, so cannot rely on the usual views::WebView and
views::Widget initial-focus behavior. It must manually set focus on the
WebContents during creation.

BUG=438751
TEST=added to app_shell_browsertests ShellApiTest

Review URL: https://codereview.chromium.org/754313003

Cr-Commit-Position: refs/heads/master@{#307040}
parent c8275048
......@@ -4,6 +4,7 @@
#include "extensions/shell/browser/shell_app_delegate.h"
#include "content/public/browser/web_contents.h"
#include "extensions/common/constants.h"
#include "extensions/shell/browser/media_capture_util.h"
......@@ -16,6 +17,7 @@ ShellAppDelegate::~ShellAppDelegate() {
}
void ShellAppDelegate::InitWebContents(content::WebContents* web_contents) {
Observe(web_contents);
}
void ShellAppDelegate::ResizeWebContents(content::WebContents* web_contents,
......@@ -92,4 +94,11 @@ void ShellAppDelegate::SetTerminatingCallback(const base::Closure& callback) {
NOTIMPLEMENTED();
}
void ShellAppDelegate::RenderViewCreated(
content::RenderViewHost* render_view_host) {
// The views implementation of AppWindow takes focus via SetInitialFocus()
// and views::WebView but app_shell is aura-only and must do it manually.
web_contents()->Focus();
}
} // namespace extensions
......@@ -6,11 +6,14 @@
#define EXTENSIONS_SHELL_BROWSER_SHELL_APP_DELEGATE_H_
#include "extensions/browser/app_window/app_delegate.h"
#include "content/public/browser/web_contents_observer.h"
namespace extensions {
// app_shell's AppDelegate implementation.
class ShellAppDelegate : public AppDelegate {
// AppDelegate implementation for app_shell. Sets focus after the WebContents is
// created. Ignores most operations that would create a new dialog or window.
class ShellAppDelegate : public AppDelegate,
public content::WebContentsObserver {
public:
ShellAppDelegate();
~ShellAppDelegate() override;
......@@ -48,6 +51,9 @@ class ShellAppDelegate : public AppDelegate {
bool IsWebContentsVisible(content::WebContents* web_contents) override;
void SetTerminatingCallback(const base::Closure& callback) override;
// content::WebContentsObserver:
void RenderViewCreated(content::RenderViewHost* render_view_host) override;
private:
DISALLOW_COPY_AND_ASSIGN(ShellAppDelegate);
};
......
......@@ -4,15 +4,27 @@
#include "base/logging.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/app_window/app_window.h"
#include "extensions/browser/app_window/app_window_registry.h"
#include "extensions/browser/notification_types.h"
#include "extensions/shell/test/shell_apitest.h"
#include "ui/aura/window.h"
namespace extensions {
// Test that we can open an app window and wait for it to load.
IN_PROC_BROWSER_TEST_F(ShellApiTest, Basic) {
ASSERT_TRUE(RunAppTest("platform_app")) << message_;
// A window was created.
AppWindow* app_window =
AppWindowRegistry::Get(browser_context())->app_windows().front();
ASSERT_TRUE(app_window);
// The web contents have focus.
EXPECT_TRUE(app_window->web_contents()->GetContentNativeView()->HasFocus());
}
} // namespace extensions
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