| Index: chrome/browser/ui/views/ash/window_manager_extension.cc
|
| diff --git a/chrome/browser/ui/views/ash/window_manager_extension.cc b/chrome/browser/ui/views/ash/window_manager_extension.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..12c03c0c65f96e06f6280591182ce7a6cdd2cff7
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/views/ash/window_manager_extension.cc
|
| @@ -0,0 +1,82 @@
|
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/ui/views/ash/window_manager_extension.h"
|
| +
|
| +#include "base/json/json_writer.h"
|
| +#include "base/memory/ref_counted.h"
|
| +#include "chrome/browser/extensions/api/wm/wm_utils.h"
|
| +#include "chrome/browser/extensions/event_names.h"
|
| +#include "chrome/browser/extensions/event_router.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| +#include "chrome/browser/profiles/profile_manager.h"
|
| +#include "chrome/common/extensions/api/experimental_wm.h"
|
| +#include "ui/aura/window.h"
|
| +
|
| +namespace {
|
| +
|
| +bool ShouldProcessWindow(const aura::Window* window) {
|
| + return (window->type() == aura::client::WINDOW_TYPE_NORMAL ||
|
| + window->type() == aura::client::WINDOW_TYPE_PANEL);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +using namespace extensions;
|
| +
|
| +WindowManagerExtension::WindowManagerExtension() {
|
| +}
|
| +
|
| +WindowManagerExtension::~WindowManagerExtension() {
|
| +}
|
| +
|
| +void WindowManagerExtension::DispatchEventForWindow(const aura::Window* window,
|
| + const char event_name[]) {
|
| + extensions::api::experimental_wm::AshWindow extension_window;
|
| + extensions::api::wm::utils::AuraWindowToExtensionWindow(window,
|
| + &extension_window);
|
| + scoped_ptr<ListValue> args(new ListValue());
|
| + args->Append(extension_window.ToValue().release());
|
| +
|
| + Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
|
| + profile->GetExtensionEventRouter()->DispatchEventToRenderers(
|
| + event_name,
|
| + args.Pass(),
|
| + NULL,
|
| + GURL());
|
| +}
|
| +
|
| +void WindowManagerExtension::OnWindowCreated(const aura::Window* window) {
|
| + if (!ShouldProcessWindow(window))
|
| + return;
|
| + extensions::api::wm::WindowIdTracker::GetInstance()->TrackWindow(window);
|
| + DispatchEventForWindow(window, event_names::kAshWmOnWindowCreated);
|
| +}
|
| +
|
| +void WindowManagerExtension::OnWindowClosed(const aura::Window* window) {
|
| + if (!ShouldProcessWindow(window))
|
| + return;
|
| + DispatchEventForWindow(window, event_names::kAshWmOnWindowClosed);
|
| + extensions::api::wm::WindowIdTracker::GetInstance()->UntrackWindow(window);
|
| +}
|
| +
|
| +void WindowManagerExtension::OnWindowHidden(const aura::Window* window) {
|
| + if (!ShouldProcessWindow(window))
|
| + return;
|
| + DispatchEventForWindow(window, event_names::kAshWmOnWindowHidden);
|
| +}
|
| +
|
| +void WindowManagerExtension::OnWindowShown(const aura::Window* window) {
|
| + if (!ShouldProcessWindow(window))
|
| + return;
|
| + DispatchEventForWindow(window, event_names::kAshWmOnWindowShown);
|
| +}
|
| +
|
| +void WindowManagerExtension::OnActiveWindowChanged(const aura::Window* window) {
|
| + if (window && !ShouldProcessWindow(window))
|
| + return;
|
| + extensions::api::wm::WindowIdTracker::GetInstance()->ActivateWindow(window);
|
| + DispatchEventForWindow(window,
|
| + event_names::kAshWmOnActiveWindowChanged);
|
| +}
|
|
|