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

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

Issue 10837170: Fix crash in WindowEventRouter::OnActiveWindowChanged when closing an incognito window. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 profile_->IsSameProfile(window_controller->profile())) { 121 profile_->IsSameProfile(window_controller->profile())) {
122 window_profile = window_controller->profile(); 122 window_profile = window_controller->profile();
123 window_id = window_controller->GetWindowId(); 123 window_id = window_controller->GetWindowId();
124 } 124 }
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 // Note that |previous_focused_profile| may already be destroyed!
131 Profile* previous_focused_profile = focused_profile_; 132 Profile* previous_focused_profile = focused_profile_;
132 focused_profile_ = window_profile; 133 focused_profile_ = window_profile;
133 focused_window_id_ = window_id; 134 focused_window_id_ = window_id;
134 135
135 base::ListValue real_args; 136 base::ListValue real_args;
136 real_args.Append(Value::CreateIntegerValue(window_id)); 137 real_args.Append(Value::CreateIntegerValue(window_id));
137 std::string real_json_args; 138 std::string real_json_args;
138 base::JSONWriter::Write(&real_args, &real_json_args); 139 base::JSONWriter::Write(&real_args, &real_json_args);
139 140
140 // When switching between windows in the default and incognitoi profiles, 141 // When switching between windows in the default and incognito profiles,
141 // dispatch WINDOW_ID_NONE to extensions whose profile lost focus that 142 // dispatch WINDOW_ID_NONE to extensions whose profile lost focus that
142 // can't see the new focused window across the incognito boundary. 143 // can't see the new focused window across the incognito boundary.
143 // See crbug.com/46610. 144 // See crbug.com/46610.
144 std::string none_json_args; 145 std::string none_json_args;
145 if (focused_profile_ != NULL && previous_focused_profile != NULL && 146 if (focused_profile_ != NULL && previous_focused_profile != NULL &&
146 focused_profile_ != previous_focused_profile) { 147 focused_profile_ != previous_focused_profile) {
147 ListValue none_args; 148 ListValue none_args;
148 none_args.Append( 149 none_args.Append(
149 Value::CreateIntegerValue(extension_misc::kUnknownWindowId)); 150 Value::CreateIntegerValue(extension_misc::kUnknownWindowId));
150 base::JSONWriter::Write(&none_args, &none_json_args); 151 base::JSONWriter::Write(&none_args, &none_json_args);
151 } 152 }
152 153
153 if (!window_profile) 154 if ((window_profile && !profile_->IsSameProfile(window_profile)))
Yoyo Zhou 2012/08/08 19:36:58 excessive parentheses
dcheng 2012/08/08 20:05:56 Already removed in my latest snapshot.
154 window_profile = previous_focused_profile;
155 if (!profile_->IsSameProfile(window_profile) ||
156 !ExtensionSystem::Get(window_profile)->event_router()) {
157 return; 155 return;
158 }
159 156
160 ExtensionSystem::Get(window_profile)->event_router()-> 157 ExtensionSystem::Get(profile_)->event_router()->
Yoyo Zhou 2012/08/08 19:36:58 This seems to be the important fix.
161 DispatchEventsToRenderersAcrossIncognito( 158 DispatchEventsToRenderersAcrossIncognito(
162 event_names::kOnWindowFocusedChanged, 159 event_names::kOnWindowFocusedChanged,
163 real_json_args, 160 real_json_args,
164 window_profile, 161 window_profile,
Yoyo Zhou 2012/08/08 19:36:58 Are you sure this should be NULL in some cases?
dcheng 2012/08/08 20:05:56 Oops. While I think it's technically OK to pass NU
dcheng 2012/08/08 22:08:33 Passing NULL won't cause any crashes. However, I t
165 none_json_args, 162 none_json_args,
166 GURL()); 163 GURL());
167 } 164 }
168 165
169 void WindowEventRouter::DispatchEvent(const char* event_name, 166 void WindowEventRouter::DispatchEvent(const char* event_name,
170 Profile* profile, 167 Profile* profile,
171 base::ListValue* args) { 168 base::ListValue* args) {
172 std::string json_args; 169 std::string json_args;
173 base::JSONWriter::Write(args, &json_args); 170 base::JSONWriter::Write(args, &json_args);
174 ExtensionSystem::Get(profile)->event_router()-> 171 ExtensionSystem::Get(profile)->event_router()->
175 DispatchEventToRenderers(event_name, json_args, profile, GURL()); 172 DispatchEventToRenderers(event_name, json_args, profile, GURL());
176 } 173 }
177 174
178 } // namespace extensions 175 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698