Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: chrome/browser/extensions/window_event_router.cc

Issue 10694085: Refactor extension event distribution to use Values instead of JSON strings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing memory leak in a test. Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/window_event_router.h" 5 #include "chrome/browser/extensions/window_event_router.h"
6 6
7 #include "base/json/json_writer.h" 7 #include "base/json/json_writer.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/extensions/event_names.h" 9 #include "chrome/browser/extensions/event_names.h"
10 #include "chrome/browser/extensions/event_router.h" 10 #include "chrome/browser/extensions/event_router.h"
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 #endif 60 #endif
61 61
62 initialized_ = true; 62 initialized_ = true;
63 } 63 }
64 64
65 void WindowEventRouter::OnWindowControllerAdded( 65 void WindowEventRouter::OnWindowControllerAdded(
66 WindowController* window_controller) { 66 WindowController* window_controller) {
67 if (!profile_->IsSameProfile(window_controller->profile())) 67 if (!profile_->IsSameProfile(window_controller->profile()))
68 return; 68 return;
69 69
70 base::ListValue args; 70 scoped_ptr<base::ListValue> args(new ListValue());
71 DictionaryValue* window_dictionary = window_controller->CreateWindowValue(); 71 DictionaryValue* window_dictionary = window_controller->CreateWindowValue();
72 args.Append(window_dictionary); 72 args->Append(window_dictionary);
73 DispatchEvent(event_names::kOnWindowCreated, window_controller->profile(), 73 DispatchEvent(event_names::kOnWindowCreated, window_controller->profile(),
74 &args); 74 args.Pass());
75 } 75 }
76 76
77 void WindowEventRouter::OnWindowControllerRemoved( 77 void WindowEventRouter::OnWindowControllerRemoved(
78 WindowController* window_controller) { 78 WindowController* window_controller) {
79 if (!profile_->IsSameProfile(window_controller->profile())) 79 if (!profile_->IsSameProfile(window_controller->profile()))
80 return; 80 return;
81 81
82 int window_id = window_controller->GetWindowId(); 82 int window_id = window_controller->GetWindowId();
83 base::ListValue args; 83 scoped_ptr<base::ListValue> args(new ListValue());
84 args.Append(Value::CreateIntegerValue(window_id)); 84 args->Append(Value::CreateIntegerValue(window_id));
85 DispatchEvent(event_names::kOnWindowRemoved, window_controller->profile(), 85 DispatchEvent(event_names::kOnWindowRemoved, window_controller->profile(),
86 &args); 86 args.Pass());
87 } 87 }
88 88
89 #if defined(TOOLKIT_VIEWS) 89 #if defined(TOOLKIT_VIEWS)
90 void WindowEventRouter::OnNativeFocusChange( 90 void WindowEventRouter::OnNativeFocusChange(
91 gfx::NativeView focused_before, 91 gfx::NativeView focused_before,
92 gfx::NativeView focused_now) { 92 gfx::NativeView focused_now) {
93 if (!focused_now) 93 if (!focused_now)
94 OnActiveWindowChanged(NULL); 94 OnActiveWindowChanged(NULL);
95 } 95 }
96 #elif defined(TOOLKIT_GTK) 96 #elif defined(TOOLKIT_GTK)
(...skipping 28 matching lines...) Expand all
125 125
126 if (focused_window_id_ == window_id) 126 if (focused_window_id_ == window_id)
127 return; 127 return;
128 128
129 // window_profile is either the default profile for the active window, its 129 // window_profile is either the default profile for the active window, its
130 // incognito profile, or NULL iff the previous profile is losing focus. 130 // incognito profile, or NULL iff the previous profile is losing focus.
131 Profile* previous_focused_profile = focused_profile_; 131 Profile* previous_focused_profile = focused_profile_;
132 focused_profile_ = window_profile; 132 focused_profile_ = window_profile;
133 focused_window_id_ = window_id; 133 focused_window_id_ = window_id;
134 134
135 base::ListValue real_args; 135 scoped_ptr<base::ListValue> real_args(new ListValue());
136 real_args.Append(Value::CreateIntegerValue(window_id)); 136 real_args->Append(Value::CreateIntegerValue(window_id));
137 std::string real_json_args;
138 base::JSONWriter::Write(&real_args, &real_json_args);
139 137
140 // When switching between windows in the default and incognitoi profiles, 138 // When switching between windows in the default and incognitoi profiles,
141 // dispatch WINDOW_ID_NONE to extensions whose profile lost focus that 139 // dispatch WINDOW_ID_NONE to extensions whose profile lost focus that
142 // can't see the new focused window across the incognito boundary. 140 // can't see the new focused window across the incognito boundary.
143 // See crbug.com/46610. 141 // See crbug.com/46610.
144 std::string none_json_args; 142 scoped_ptr<base::ListValue> none_args(new ListValue());
145 if (focused_profile_ != NULL && previous_focused_profile != NULL && 143 if (focused_profile_ != NULL && previous_focused_profile != NULL &&
146 focused_profile_ != previous_focused_profile) { 144 focused_profile_ != previous_focused_profile) {
147 ListValue none_args; 145 none_args->Append(
148 none_args.Append(
149 Value::CreateIntegerValue(extension_misc::kUnknownWindowId)); 146 Value::CreateIntegerValue(extension_misc::kUnknownWindowId));
150 base::JSONWriter::Write(&none_args, &none_json_args);
151 } 147 }
152 148
153 if (!window_profile) 149 if (!window_profile)
154 window_profile = previous_focused_profile; 150 window_profile = previous_focused_profile;
155 if (!profile_->IsSameProfile(window_profile) || 151 if (!profile_->IsSameProfile(window_profile) ||
156 !ExtensionSystem::Get(window_profile)->event_router()) { 152 !ExtensionSystem::Get(window_profile)->event_router()) {
157 return; 153 return;
158 } 154 }
159 155
160 ExtensionSystem::Get(window_profile)->event_router()-> 156 ExtensionSystem::Get(window_profile)->event_router()->
161 DispatchEventsToRenderersAcrossIncognito( 157 DispatchEventsToRenderersAcrossIncognito(
162 event_names::kOnWindowFocusedChanged, 158 event_names::kOnWindowFocusedChanged,
163 real_json_args, 159 real_args.Pass(),
164 window_profile, 160 window_profile,
165 none_json_args, 161 none_args.Pass(),
166 GURL()); 162 GURL());
167 } 163 }
168 164
169 void WindowEventRouter::DispatchEvent(const char* event_name, 165 void WindowEventRouter::DispatchEvent(const char* event_name,
170 Profile* profile, 166 Profile* profile,
171 base::ListValue* args) { 167 scoped_ptr<base::ListValue> args) {
172 std::string json_args;
173 base::JSONWriter::Write(args, &json_args);
174 ExtensionSystem::Get(profile)->event_router()-> 168 ExtensionSystem::Get(profile)->event_router()->
175 DispatchEventToRenderers(event_name, json_args, profile, GURL()); 169 DispatchEventToRenderers(event_name, args.Pass(), profile, GURL());
176 } 170 }
177 171
178 } // namespace extensions 172 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/window_event_router.h ('k') | chrome/browser/history/history_extension_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698