OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/api/tabs/windows_event_router.h" | 5 #include "chrome/browser/extensions/api/tabs/windows_event_router.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/browser/extensions/event_names.h" | 8 #include "chrome/browser/extensions/event_names.h" |
9 #include "chrome/browser/extensions/event_router.h" | 9 #include "chrome/browser/extensions/event_router.h" |
10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 #elif defined(TOOLKIT_GTK) | 50 #elif defined(TOOLKIT_GTK) |
51 ui::ActiveWindowWatcherX::RemoveObserver(this); | 51 ui::ActiveWindowWatcherX::RemoveObserver(this); |
52 #endif | 52 #endif |
53 } | 53 } |
54 | 54 |
55 void WindowsEventRouter::OnWindowControllerAdded( | 55 void WindowsEventRouter::OnWindowControllerAdded( |
56 WindowController* window_controller) { | 56 WindowController* window_controller) { |
57 if (!profile_->IsSameProfile(window_controller->profile())) | 57 if (!profile_->IsSameProfile(window_controller->profile())) |
58 return; | 58 return; |
59 | 59 |
60 scoped_ptr<base::ListValue> args(new ListValue()); | 60 scoped_ptr<base::ListValue> args(new base::ListValue()); |
61 DictionaryValue* window_dictionary = window_controller->CreateWindowValue(); | 61 base::DictionaryValue* window_dictionary = |
| 62 window_controller->CreateWindowValue(); |
62 args->Append(window_dictionary); | 63 args->Append(window_dictionary); |
63 DispatchEvent(event_names::kOnWindowCreated, window_controller->profile(), | 64 DispatchEvent(event_names::kOnWindowCreated, window_controller->profile(), |
64 args.Pass()); | 65 args.Pass()); |
65 } | 66 } |
66 | 67 |
67 void WindowsEventRouter::OnWindowControllerRemoved( | 68 void WindowsEventRouter::OnWindowControllerRemoved( |
68 WindowController* window_controller) { | 69 WindowController* window_controller) { |
69 if (!profile_->IsSameProfile(window_controller->profile())) | 70 if (!profile_->IsSameProfile(window_controller->profile())) |
70 return; | 71 return; |
71 | 72 |
72 int window_id = window_controller->GetWindowId(); | 73 int window_id = window_controller->GetWindowId(); |
73 scoped_ptr<base::ListValue> args(new ListValue()); | 74 scoped_ptr<base::ListValue> args(new base::ListValue()); |
74 args->Append(Value::CreateIntegerValue(window_id)); | 75 args->Append(Value::CreateIntegerValue(window_id)); |
75 DispatchEvent(event_names::kOnWindowRemoved, window_controller->profile(), | 76 DispatchEvent(event_names::kOnWindowRemoved, window_controller->profile(), |
76 args.Pass()); | 77 args.Pass()); |
77 } | 78 } |
78 | 79 |
79 #if defined(TOOLKIT_VIEWS) | 80 #if defined(TOOLKIT_VIEWS) |
80 void WindowsEventRouter::OnNativeFocusChange( | 81 void WindowsEventRouter::OnNativeFocusChange( |
81 gfx::NativeView focused_before, | 82 gfx::NativeView focused_before, |
82 gfx::NativeView focused_now) { | 83 gfx::NativeView focused_now) { |
83 if (!focused_now) | 84 if (!focused_now) |
(...skipping 16 matching lines...) Expand all Loading... |
100 OnActiveWindowChanged(NULL); | 101 OnActiveWindowChanged(NULL); |
101 return; | 102 return; |
102 } | 103 } |
103 #endif | 104 #endif |
104 } | 105 } |
105 | 106 |
106 static void WillDispatchWindowFocusedEvent(Profile* new_active_profile, | 107 static void WillDispatchWindowFocusedEvent(Profile* new_active_profile, |
107 int window_id, | 108 int window_id, |
108 Profile* profile, | 109 Profile* profile, |
109 const Extension* extension, | 110 const Extension* extension, |
110 ListValue* event_args) { | 111 base::ListValue* event_args) { |
111 // When switching between windows in the default and incognito profiles, | 112 // When switching between windows in the default and incognito profiles, |
112 // dispatch WINDOW_ID_NONE to extensions whose profile lost focus that | 113 // dispatch WINDOW_ID_NONE to extensions whose profile lost focus that |
113 // can't see the new focused window across the incognito boundary. | 114 // can't see the new focused window across the incognito boundary. |
114 // See crbug.com/46610. | 115 // See crbug.com/46610. |
115 if (new_active_profile && new_active_profile != profile && | 116 if (new_active_profile && new_active_profile != profile && |
116 !extensions::ExtensionSystem::Get(profile)->extension_service()-> | 117 !extensions::ExtensionSystem::Get(profile)->extension_service()-> |
117 CanCrossIncognito(extension)) { | 118 CanCrossIncognito(extension)) { |
118 event_args->Clear(); | 119 event_args->Clear(); |
119 event_args->Append(Value::CreateIntegerValue( | 120 event_args->Append(Value::CreateIntegerValue( |
120 extension_misc::kUnknownWindowId)); | 121 extension_misc::kUnknownWindowId)); |
(...skipping 15 matching lines...) Expand all Loading... |
136 | 137 |
137 if (focused_window_id_ == window_id) | 138 if (focused_window_id_ == window_id) |
138 return; | 139 return; |
139 | 140 |
140 // window_profile is either the default profile for the active window, its | 141 // window_profile is either the default profile for the active window, its |
141 // incognito profile, or NULL iff the previous profile is losing focus. | 142 // incognito profile, or NULL iff the previous profile is losing focus. |
142 focused_profile_ = window_profile; | 143 focused_profile_ = window_profile; |
143 focused_window_id_ = window_id; | 144 focused_window_id_ = window_id; |
144 | 145 |
145 scoped_ptr<Event> event(new Event(event_names::kOnWindowFocusedChanged, | 146 scoped_ptr<Event> event(new Event(event_names::kOnWindowFocusedChanged, |
146 make_scoped_ptr(new ListValue()))); | 147 make_scoped_ptr(new base::ListValue()))); |
147 event->will_dispatch_callback = | 148 event->will_dispatch_callback = |
148 base::Bind(&WillDispatchWindowFocusedEvent, window_profile, window_id); | 149 base::Bind(&WillDispatchWindowFocusedEvent, window_profile, window_id); |
149 ExtensionSystem::Get(profile_)->event_router()->BroadcastEvent(event.Pass()); | 150 ExtensionSystem::Get(profile_)->event_router()->BroadcastEvent(event.Pass()); |
150 } | 151 } |
151 | 152 |
152 void WindowsEventRouter::DispatchEvent(const char* event_name, | 153 void WindowsEventRouter::DispatchEvent(const char* event_name, |
153 Profile* profile, | 154 Profile* profile, |
154 scoped_ptr<base::ListValue> args) { | 155 scoped_ptr<base::ListValue> args) { |
155 scoped_ptr<Event> event(new Event(event_name, args.Pass())); | 156 scoped_ptr<Event> event(new Event(event_name, args.Pass())); |
156 event->restrict_to_profile = profile; | 157 event->restrict_to_profile = profile; |
157 ExtensionSystem::Get(profile)->event_router()->BroadcastEvent(event.Pass()); | 158 ExtensionSystem::Get(profile)->event_router()->BroadcastEvent(event.Pass()); |
158 } | 159 } |
159 | 160 |
160 } // namespace extensions | 161 } // namespace extensions |
OLD | NEW |