1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/ash/user_action_handler.h"
7 #include "ash/wm/window_util.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/browser_finder.h"
10 #include "chrome/browser/ui/browser_window.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "content/public/browser/web_contents.h"
14 // Returns the currently-active WebContents belonging to the active browser, or
15 // NULL if there's no currently-active browser.
16 content::WebContents
* GetActiveWebContents() {
17 Browser
* browser
= chrome::FindLastActiveWithHostDesktopType(
18 chrome::HOST_DESKTOP_TYPE_ASH
);
21 if (!ash::wm::IsActiveWindow(browser
->window()->GetNativeWindow()))
24 return browser
->tab_strip_model()->GetActiveWebContents();
27 UserActionHandler::UserActionHandler() {}
29 UserActionHandler::~UserActionHandler() {}
31 bool UserActionHandler::OnUserAction(
32 aura::client::UserActionClient::Command command
) {
34 case aura::client::UserActionClient::BACK
: {
35 content::WebContents
* contents
= GetActiveWebContents();
36 if (contents
&& contents
->GetController().CanGoBack()) {
37 contents
->GetController().GoBack();
42 case aura::client::UserActionClient::FORWARD
: {
43 content::WebContents
* contents
= GetActiveWebContents();
44 if (contents
&& contents
->GetController().CanGoForward()) {
45 contents
->GetController().GoForward();