15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 52a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#ifndef CHROME_BROWSER_EXTENSIONS_API_TABS_WINDOWS_EVENT_ROUTER_H_ 62a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#define CHROME_BROWSER_EXTENSIONS_API_TABS_WINDOWS_EVENT_ROUTER_H_ 75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 84e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include <string> 94e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/basictypes.h" 115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/extensions/window_controller_list_observer.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_observer.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_registrar.h" 155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(TOOLKIT_VIEWS) 165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/views/focus/widget_focus_manager.h" 175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#elif defined(TOOLKIT_GTK) 185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/x/active_window_watcher_x_observer.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Profile; 225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base { 245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class ListValue; 255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace extensions { 285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// The WindowsEventRouter sends chrome.windows.* events to listeners 305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// inside extension process renderers. The router listens to *all* events, 315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// but will only route eventes within a profile to extension processes in the 325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// same profile. 332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class WindowsEventRouter : public WindowControllerListObserver, 345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(TOOLKIT_VIEWS) 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public views::WidgetFocusChangeListener, 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#elif defined(TOOLKIT_GTK) 375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public ui::ActiveWindowWatcherXObserver, 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public content::NotificationObserver { 405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) explicit WindowsEventRouter(Profile* profile); 422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~WindowsEventRouter(); 435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // WindowControllerListObserver methods: 455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnWindowControllerAdded( 465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowController* window_controller) OVERRIDE; 475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnWindowControllerRemoved( 485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) WindowController* window) OVERRIDE; 495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(TOOLKIT_VIEWS) 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void OnNativeFocusChange(gfx::NativeView focused_before, 525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gfx::NativeView focused_now) OVERRIDE; 535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#elif defined(TOOLKIT_GTK) 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void ActiveWindowChanged(GdkWindow* active_window) OVERRIDE; 555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif 565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // content::NotificationObserver. 585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void Observe(int type, 595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const content::NotificationSource& source, 605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const content::NotificationDetails& details) OVERRIDE; 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // |window_controller| is NULL to indicate a focused window has lost focus. 635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void OnActiveWindowChanged(WindowController* window_controller); 645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 664e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) void DispatchEvent(const std::string& event_name, 675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Profile* profile, 685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<base::ListValue> args); 695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) content::NotificationRegistrar registrar_; 715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The main profile that owns this event router. 735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Profile* profile_; 745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The profile the currently focused window belongs to; either the main or 765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // incognito profile or NULL (none of the above). We remember this in order 775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // to correctly handle focus changes between non-OTR and OTR windows. 785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Profile* focused_profile_; 795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // The currently focused window. We keep this so as to avoid sending multiple 815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // windows.onFocusChanged events with the same windowId. 825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) int focused_window_id_; 835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(WindowsEventRouter); 855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} // namespace extensions 885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif // CHROME_BROWSER_EXTENSIONS_API_TABS_WINDOWS_EVENT_ROUTER_H_ 90