OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/extension_browser_event_router.h" | 5 #include "chrome/browser/extensions/extension_browser_event_router.h" |
6 | 6 |
7 #include "base/json_writer.h" | 7 #include "base/json_writer.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/browser.h" | 9 #include "chrome/browser/browser.h" |
10 #include "chrome/browser/profile.h" | 10 #include "chrome/browser/profile.h" |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 std::string json_args; | 261 std::string json_args; |
262 JSONWriter::Write(&args, false, &json_args); | 262 JSONWriter::Write(&args, false, &json_args); |
263 | 263 |
264 DispatchEvent(contents->profile(), events::kOnTabMoved, json_args); | 264 DispatchEvent(contents->profile(), events::kOnTabMoved, json_args); |
265 } | 265 } |
266 | 266 |
267 void ExtensionBrowserEventRouter::TabUpdated(TabContents* contents, | 267 void ExtensionBrowserEventRouter::TabUpdated(TabContents* contents, |
268 bool did_navigate) { | 268 bool did_navigate) { |
269 int tab_id = ExtensionTabUtil::GetTabId(contents); | 269 int tab_id = ExtensionTabUtil::GetTabId(contents); |
270 std::map<int, TabEntry>::iterator i = tab_entries_.find(tab_id); | 270 std::map<int, TabEntry>::iterator i = tab_entries_.find(tab_id); |
271 CHECK(tab_entries_.end() != i); | 271 if(tab_entries_.end() == i) { |
| 272 // TODO(rafaelw): Unregister EBER on TAB_CONTENTS_DESTROYED in order |
| 273 // not to receive NAV_ENTRY_COMMITTED from objects that are allocated |
| 274 // at the same address as previously deleted TabContents. |
| 275 // |
| 276 // The problem here is that NAV_ENTRY_COMMITTED is issued by the navigation |
| 277 // controller independently from tabstrip model. One should not rely upon |
| 278 // TabStripModelObserver events when registering / unregistering |
| 279 // tab contents events' handlers. |
| 280 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED, |
| 281 Source<NavigationController>(&contents->controller())); |
| 282 return; |
| 283 } |
272 TabEntry& entry = i->second; | 284 TabEntry& entry = i->second; |
273 | 285 |
274 DictionaryValue* changed_properties = NULL; | 286 DictionaryValue* changed_properties = NULL; |
275 if (did_navigate) | 287 if (did_navigate) |
276 changed_properties = entry.DidNavigate(contents); | 288 changed_properties = entry.DidNavigate(contents); |
277 else | 289 else |
278 changed_properties = entry.UpdateLoadState(contents); | 290 changed_properties = entry.UpdateLoadState(contents); |
279 | 291 |
280 if (changed_properties) { | 292 if (changed_properties) { |
281 // The state of the tab (as seen from the extension point of view) has | 293 // The state of the tab (as seen from the extension point of view) has |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 data->Set(tab_keys::kTabUrlKey, Value::CreateStringValue(url)); | 336 data->Set(tab_keys::kTabUrlKey, Value::CreateStringValue(url)); |
325 object_args->Set(tab_keys::kDataKey, data); | 337 object_args->Set(tab_keys::kDataKey, data); |
326 | 338 |
327 args.Append(object_args); | 339 args.Append(object_args); |
328 | 340 |
329 std::string json_args; | 341 std::string json_args; |
330 JSONWriter::Write(&args, false, &json_args); | 342 JSONWriter::Write(&args, false, &json_args); |
331 | 343 |
332 DispatchEvent(profile, events::kOnPageActionExecuted, json_args); | 344 DispatchEvent(profile, events::kOnPageActionExecuted, json_args); |
333 } | 345 } |
OLD | NEW |