| OLD | NEW |
| (Empty) | |
| 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. |
| 4 |
| 5 #include "chrome/browser/ui/views/ash/window_manager_extension.h" |
| 6 |
| 7 #include "base/json/json_writer.h" |
| 8 #include "base/memory/ref_counted.h" |
| 9 #include "chrome/browser/extensions/api/wm/wm_utils.h" |
| 10 #include "chrome/browser/extensions/event_names.h" |
| 11 #include "chrome/browser/extensions/event_router.h" |
| 12 #include "chrome/browser/profiles/profile.h" |
| 13 #include "chrome/browser/profiles/profile_manager.h" |
| 14 #include "chrome/common/extensions/api/experimental_wm.h" |
| 15 #include "ui/aura/window.h" |
| 16 |
| 17 namespace { |
| 18 |
| 19 bool ShouldProcessWindow(const aura::Window* window) { |
| 20 return (window->type() == aura::client::WINDOW_TYPE_NORMAL || |
| 21 window->type() == aura::client::WINDOW_TYPE_PANEL); |
| 22 } |
| 23 |
| 24 } // namespace |
| 25 |
| 26 using namespace extensions; |
| 27 |
| 28 WindowManagerExtension::WindowManagerExtension() { |
| 29 } |
| 30 |
| 31 WindowManagerExtension::~WindowManagerExtension() { |
| 32 } |
| 33 |
| 34 void WindowManagerExtension::DispatchEventForWindow(const aura::Window* window, |
| 35 const char event_name[]) { |
| 36 extensions::api::experimental_wm::AshWindow extension_window; |
| 37 extensions::api::wm::utils::AuraWindowToExtensionWindow(window, |
| 38 &extension_window); |
| 39 scoped_ptr<ListValue> args(new ListValue()); |
| 40 args->Append(extension_window.ToValue().release()); |
| 41 |
| 42 Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord(); |
| 43 profile->GetExtensionEventRouter()->DispatchEventToRenderers( |
| 44 event_name, |
| 45 args.Pass(), |
| 46 NULL, |
| 47 GURL()); |
| 48 } |
| 49 |
| 50 void WindowManagerExtension::OnWindowCreated(const aura::Window* window) { |
| 51 if (!ShouldProcessWindow(window)) |
| 52 return; |
| 53 extensions::api::wm::WindowIdTracker::GetInstance()->TrackWindow(window); |
| 54 DispatchEventForWindow(window, event_names::kAshWmOnWindowCreated); |
| 55 } |
| 56 |
| 57 void WindowManagerExtension::OnWindowClosed(const aura::Window* window) { |
| 58 if (!ShouldProcessWindow(window)) |
| 59 return; |
| 60 DispatchEventForWindow(window, event_names::kAshWmOnWindowClosed); |
| 61 extensions::api::wm::WindowIdTracker::GetInstance()->UntrackWindow(window); |
| 62 } |
| 63 |
| 64 void WindowManagerExtension::OnWindowHidden(const aura::Window* window) { |
| 65 if (!ShouldProcessWindow(window)) |
| 66 return; |
| 67 DispatchEventForWindow(window, event_names::kAshWmOnWindowHidden); |
| 68 } |
| 69 |
| 70 void WindowManagerExtension::OnWindowShown(const aura::Window* window) { |
| 71 if (!ShouldProcessWindow(window)) |
| 72 return; |
| 73 DispatchEventForWindow(window, event_names::kAshWmOnWindowShown); |
| 74 } |
| 75 |
| 76 void WindowManagerExtension::OnActiveWindowChanged(const aura::Window* window) { |
| 77 if (window && !ShouldProcessWindow(window)) |
| 78 return; |
| 79 extensions::api::wm::WindowIdTracker::GetInstance()->ActivateWindow(window); |
| 80 DispatchEventForWindow(window, |
| 81 event_names::kAshWmOnActiveWindowChanged); |
| 82 } |
| OLD | NEW |