| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/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/extension_event_names.h" | 9 #include "chrome/browser/extensions/extension_event_names.h" |
| 10 #include "chrome/browser/extensions/extension_event_router.h" | 10 #include "chrome/browser/extensions/extension_event_router.h" |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 DispatchEventsAcrossIncognito((focused_profile_ ? focused_profile_ : | 238 DispatchEventsAcrossIncognito((focused_profile_ ? focused_profile_ : |
| 239 previous_focused_profile), | 239 previous_focused_profile), |
| 240 events::kOnWindowFocusedChanged, | 240 events::kOnWindowFocusedChanged, |
| 241 real_json_args, | 241 real_json_args, |
| 242 none_json_args); | 242 none_json_args); |
| 243 } | 243 } |
| 244 | 244 |
| 245 void ExtensionBrowserEventRouter::TabCreatedAt(TabContents* contents, | 245 void ExtensionBrowserEventRouter::TabCreatedAt(TabContents* contents, |
| 246 int index, | 246 int index, |
| 247 bool active) { | 247 bool active) { |
| 248 DispatchEventWithTab(contents->profile(), "", events::kOnTabCreated, | 248 Profile* profile = static_cast<Profile*>(contents->context()); |
| 249 DispatchEventWithTab(profile, "", events::kOnTabCreated, |
| 249 contents, active); | 250 contents, active); |
| 250 | 251 |
| 251 RegisterForTabNotifications(contents); | 252 RegisterForTabNotifications(contents); |
| 252 } | 253 } |
| 253 | 254 |
| 254 void ExtensionBrowserEventRouter::TabInsertedAt(TabContentsWrapper* contents, | 255 void ExtensionBrowserEventRouter::TabInsertedAt(TabContentsWrapper* contents, |
| 255 int index, | 256 int index, |
| 256 bool active) { | 257 bool active) { |
| 257 // If tab is new, send created event. | 258 // If tab is new, send created event. |
| 258 int tab_id = ExtensionTabUtil::GetTabId(contents->tab_contents()); | 259 int tab_id = ExtensionTabUtil::GetTabId(contents->tab_contents()); |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 | 470 |
| 470 // Second arg: An object containing the changes to the tab state. | 471 // Second arg: An object containing the changes to the tab state. |
| 471 args.Append(changed_properties); | 472 args.Append(changed_properties); |
| 472 | 473 |
| 473 // Third arg: An object containing the state of the tab. | 474 // Third arg: An object containing the state of the tab. |
| 474 args.Append(ExtensionTabUtil::CreateTabValue(contents)); | 475 args.Append(ExtensionTabUtil::CreateTabValue(contents)); |
| 475 | 476 |
| 476 std::string json_args; | 477 std::string json_args; |
| 477 base::JSONWriter::Write(&args, false, &json_args); | 478 base::JSONWriter::Write(&args, false, &json_args); |
| 478 | 479 |
| 479 DispatchEvent(contents->profile(), events::kOnTabUpdated, json_args); | 480 Profile* profile = static_cast<Profile*>(contents->context()); |
| 481 DispatchEvent(profile, events::kOnTabUpdated, json_args); |
| 480 } | 482 } |
| 481 | 483 |
| 482 ExtensionBrowserEventRouter::TabEntry* ExtensionBrowserEventRouter::GetTabEntry( | 484 ExtensionBrowserEventRouter::TabEntry* ExtensionBrowserEventRouter::GetTabEntry( |
| 483 const TabContents* contents) { | 485 const TabContents* contents) { |
| 484 int tab_id = ExtensionTabUtil::GetTabId(contents); | 486 int tab_id = ExtensionTabUtil::GetTabId(contents); |
| 485 std::map<int, TabEntry>::iterator i = tab_entries_.find(tab_id); | 487 std::map<int, TabEntry>::iterator i = tab_entries_.find(tab_id); |
| 486 if (tab_entries_.end() == i) | 488 if (tab_entries_.end() == i) |
| 487 return NULL; | 489 return NULL; |
| 488 return &i->second; | 490 return &i->second; |
| 489 } | 491 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 | 590 |
| 589 void ExtensionBrowserEventRouter::BrowserActionExecuted( | 591 void ExtensionBrowserEventRouter::BrowserActionExecuted( |
| 590 Profile* profile, const std::string& extension_id, Browser* browser) { | 592 Profile* profile, const std::string& extension_id, Browser* browser) { |
| 591 TabContentsWrapper* tab_contents = NULL; | 593 TabContentsWrapper* tab_contents = NULL; |
| 592 int tab_id = 0; | 594 int tab_id = 0; |
| 593 if (!ExtensionTabUtil::GetDefaultTab(browser, &tab_contents, &tab_id)) | 595 if (!ExtensionTabUtil::GetDefaultTab(browser, &tab_contents, &tab_id)) |
| 594 return; | 596 return; |
| 595 DispatchEventWithTab(profile, extension_id, "browserAction.onClicked", | 597 DispatchEventWithTab(profile, extension_id, "browserAction.onClicked", |
| 596 tab_contents->tab_contents(), true); | 598 tab_contents->tab_contents(), true); |
| 597 } | 599 } |
| OLD | NEW |