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

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"
8 #include "base/values.h" 7 #include "base/values.h"
9 #include "chrome/browser/extensions/event_names.h" 8 #include "chrome/browser/extensions/event_names.h"
10 #include "chrome/browser/extensions/event_router.h" 9 #include "chrome/browser/extensions/event_router.h"
11 #include "chrome/browser/extensions/extension_system.h" 10 #include "chrome/browser/extensions/extension_system.h"
12 #include "chrome/browser/extensions/window_controller.h" 11 #include "chrome/browser/extensions/window_controller.h"
13 #include "chrome/browser/extensions/window_controller_list.h" 12 #include "chrome/browser/extensions/window_controller_list.h"
14 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/common/chrome_notification_types.h" 14 #include "chrome/common/chrome_notification_types.h"
16 #include "chrome/common/extensions/extension_constants.h" 15 #include "chrome/common/extensions/extension_constants.h"
17 #include "content/public/browser/notification_service.h" 16 #include "content/public/browser/notification_service.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 profile_->IsSameProfile(window_controller->profile())) { 120 profile_->IsSameProfile(window_controller->profile())) {
122 window_profile = window_controller->profile(); 121 window_profile = window_controller->profile();
123 window_id = window_controller->GetWindowId(); 122 window_id = window_controller->GetWindowId();
124 } 123 }
125 124
126 if (focused_window_id_ == window_id) 125 if (focused_window_id_ == window_id)
127 return; 126 return;
128 127
129 // window_profile is either the default profile for the active window, its 128 // window_profile is either the default profile for the active window, its
130 // incognito profile, or NULL iff the previous profile is losing focus. 129 // incognito profile, or NULL iff the previous profile is losing focus.
130 // Note that |previous_focused_profile| may already be destroyed!
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 scoped_ptr<base::ListValue> real_args(new ListValue()); 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 137
138 // When switching between windows in the default and incognitoi profiles, 138 // When switching between windows in the default and incognito profiles,
139 // dispatch WINDOW_ID_NONE to extensions whose profile lost focus that 139 // dispatch WINDOW_ID_NONE to extensions whose profile lost focus that
140 // can't see the new focused window across the incognito boundary. 140 // can't see the new focused window across the incognito boundary.
141 // See crbug.com/46610. 141 // See crbug.com/46610.
142 scoped_ptr<base::ListValue> none_args(new ListValue()); 142 scoped_ptr<base::ListValue> none_args(new ListValue());
143 if (focused_profile_ != NULL && previous_focused_profile != NULL && 143 if (focused_profile_ != NULL && previous_focused_profile != NULL &&
144 focused_profile_ != previous_focused_profile) { 144 focused_profile_ != previous_focused_profile) {
145 none_args->Append( 145 none_args->Append(
146 Value::CreateIntegerValue(extension_misc::kUnknownWindowId)); 146 Value::CreateIntegerValue(extension_misc::kUnknownWindowId));
147 } 147 }
148 148
149 if (!window_profile) 149 // Note that we may pass a NULL |window_profile| for the |restrict_to_profile|
150 window_profile = previous_focused_profile; 150 // argument.
151 if (!profile_->IsSameProfile(window_profile) || 151 ExtensionSystem::Get(profile_)->event_router()->
152 !ExtensionSystem::Get(window_profile)->event_router()) {
153 return;
154 }
155
156 ExtensionSystem::Get(window_profile)->event_router()->
157 DispatchEventsToRenderersAcrossIncognito( 152 DispatchEventsToRenderersAcrossIncognito(
158 event_names::kOnWindowFocusedChanged, 153 event_names::kOnWindowFocusedChanged,
159 real_args.Pass(), 154 real_args.Pass(),
160 window_profile, 155 window_profile,
161 none_args.Pass(), 156 none_args.Pass(),
162 GURL()); 157 GURL());
163 } 158 }
164 159
165 void WindowEventRouter::DispatchEvent(const char* event_name, 160 void WindowEventRouter::DispatchEvent(const char* event_name,
166 Profile* profile, 161 Profile* profile,
167 scoped_ptr<base::ListValue> args) { 162 scoped_ptr<base::ListValue> args) {
168 ExtensionSystem::Get(profile)->event_router()-> 163 ExtensionSystem::Get(profile)->event_router()->
169 DispatchEventToRenderers(event_name, args.Pass(), profile, GURL()); 164 DispatchEventToRenderers(event_name, args.Pass(), profile, GURL());
170 } 165 }
171 166
172 } // namespace extensions 167 } // 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