| 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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 // that all extensions hear about the event regardless of whether the browser | 208 // that all extensions hear about the event regardless of whether the browser |
| 209 // that lost focus was OTR or if the extension is OTR-enabled. | 209 // that lost focus was OTR or if the extension is OTR-enabled. |
| 210 // See crbug.com/46610. | 210 // See crbug.com/46610. |
| 211 DispatchSimpleBrowserEvent(browser ? browser->profile() : profile_, | 211 DispatchSimpleBrowserEvent(browser ? browser->profile() : profile_, |
| 212 focused_window_id_, | 212 focused_window_id_, |
| 213 events::kOnWindowFocusedChanged); | 213 events::kOnWindowFocusedChanged); |
| 214 } | 214 } |
| 215 | 215 |
| 216 void ExtensionBrowserEventRouter::TabCreatedAt(TabContents* contents, | 216 void ExtensionBrowserEventRouter::TabCreatedAt(TabContents* contents, |
| 217 int index, | 217 int index, |
| 218 bool foreground) { | 218 bool active) { |
| 219 DispatchEventWithTab(contents->profile(), "", events::kOnTabCreated, | 219 DispatchEventWithTab(contents->profile(), "", events::kOnTabCreated, |
| 220 contents); | 220 contents, active); |
| 221 | 221 |
| 222 RegisterForTabNotifications(contents); | 222 RegisterForTabNotifications(contents); |
| 223 } | 223 } |
| 224 | 224 |
| 225 void ExtensionBrowserEventRouter::TabInsertedAt(TabContentsWrapper* contents, | 225 void ExtensionBrowserEventRouter::TabInsertedAt(TabContentsWrapper* contents, |
| 226 int index, | 226 int index, |
| 227 bool foreground) { | 227 bool active) { |
| 228 // If tab is new, send created event. | 228 // If tab is new, send created event. |
| 229 int tab_id = ExtensionTabUtil::GetTabId(contents->tab_contents()); | 229 int tab_id = ExtensionTabUtil::GetTabId(contents->tab_contents()); |
| 230 if (!GetTabEntry(contents->tab_contents())) { | 230 if (!GetTabEntry(contents->tab_contents())) { |
| 231 tab_entries_[tab_id] = TabEntry(); | 231 tab_entries_[tab_id] = TabEntry(); |
| 232 | 232 |
| 233 TabCreatedAt(contents->tab_contents(), index, foreground); | 233 TabCreatedAt(contents->tab_contents(), index, active); |
| 234 return; | 234 return; |
| 235 } | 235 } |
| 236 | 236 |
| 237 ListValue args; | 237 ListValue args; |
| 238 args.Append(Value::CreateIntegerValue(tab_id)); | 238 args.Append(Value::CreateIntegerValue(tab_id)); |
| 239 | 239 |
| 240 DictionaryValue* object_args = new DictionaryValue(); | 240 DictionaryValue* object_args = new DictionaryValue(); |
| 241 object_args->Set(tab_keys::kNewWindowIdKey, Value::CreateIntegerValue( | 241 object_args->Set(tab_keys::kNewWindowIdKey, Value::CreateIntegerValue( |
| 242 ExtensionTabUtil::GetWindowIdOfTab(contents->tab_contents()))); | 242 ExtensionTabUtil::GetWindowIdOfTab(contents->tab_contents()))); |
| 243 object_args->Set(tab_keys::kNewPositionKey, Value::CreateIntegerValue( | 243 object_args->Set(tab_keys::kNewPositionKey, Value::CreateIntegerValue( |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 return; | 379 return; |
| 380 | 380 |
| 381 profile->GetExtensionEventRouter()->DispatchEventToExtension( | 381 profile->GetExtensionEventRouter()->DispatchEventToExtension( |
| 382 extension_id, event_name, json_args, profile, GURL()); | 382 extension_id, event_name, json_args, profile, GURL()); |
| 383 } | 383 } |
| 384 | 384 |
| 385 void ExtensionBrowserEventRouter::DispatchEventWithTab( | 385 void ExtensionBrowserEventRouter::DispatchEventWithTab( |
| 386 Profile* profile, | 386 Profile* profile, |
| 387 const std::string& extension_id, | 387 const std::string& extension_id, |
| 388 const char* event_name, | 388 const char* event_name, |
| 389 const TabContents* tab_contents) { | 389 const TabContents* tab_contents, |
| 390 bool active) { |
| 390 if (!profile_->IsSameProfile(profile)) | 391 if (!profile_->IsSameProfile(profile)) |
| 391 return; | 392 return; |
| 392 | 393 |
| 393 ListValue args; | 394 ListValue args; |
| 394 args.Append(ExtensionTabUtil::CreateTabValue(tab_contents)); | 395 args.Append(ExtensionTabUtil::CreateTabValueActive( |
| 396 tab_contents, active)); |
| 395 std::string json_args; | 397 std::string json_args; |
| 396 base::JSONWriter::Write(&args, false, &json_args); | 398 base::JSONWriter::Write(&args, false, &json_args); |
| 397 if (!extension_id.empty()) { | 399 if (!extension_id.empty()) { |
| 398 DispatchEventToExtension(profile, extension_id, event_name, json_args); | 400 DispatchEventToExtension(profile, extension_id, event_name, json_args); |
| 399 } else { | 401 } else { |
| 400 DispatchEvent(profile, event_name, json_args); | 402 DispatchEvent(profile, event_name, json_args); |
| 401 } | 403 } |
| 402 } | 404 } |
| 403 | 405 |
| 404 void ExtensionBrowserEventRouter::DispatchSimpleBrowserEvent( | 406 void ExtensionBrowserEventRouter::DispatchSimpleBrowserEvent( |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 const std::string& url, | 538 const std::string& url, |
| 537 int button) { | 539 int button) { |
| 538 DispatchOldPageActionEvent(profile, extension_id, page_action_id, tab_id, url, | 540 DispatchOldPageActionEvent(profile, extension_id, page_action_id, tab_id, url, |
| 539 button); | 541 button); |
| 540 TabContentsWrapper* tab_contents = NULL; | 542 TabContentsWrapper* tab_contents = NULL; |
| 541 if (!ExtensionTabUtil::GetTabById(tab_id, profile, profile->IsOffTheRecord(), | 543 if (!ExtensionTabUtil::GetTabById(tab_id, profile, profile->IsOffTheRecord(), |
| 542 NULL, NULL, &tab_contents, NULL)) { | 544 NULL, NULL, &tab_contents, NULL)) { |
| 543 return; | 545 return; |
| 544 } | 546 } |
| 545 DispatchEventWithTab(profile, extension_id, "pageAction.onClicked", | 547 DispatchEventWithTab(profile, extension_id, "pageAction.onClicked", |
| 546 tab_contents->tab_contents()); | 548 tab_contents->tab_contents(), true); |
| 547 } | 549 } |
| 548 | 550 |
| 549 void ExtensionBrowserEventRouter::BrowserActionExecuted( | 551 void ExtensionBrowserEventRouter::BrowserActionExecuted( |
| 550 Profile* profile, const std::string& extension_id, Browser* browser) { | 552 Profile* profile, const std::string& extension_id, Browser* browser) { |
| 551 TabContentsWrapper* tab_contents = NULL; | 553 TabContentsWrapper* tab_contents = NULL; |
| 552 int tab_id = 0; | 554 int tab_id = 0; |
| 553 if (!ExtensionTabUtil::GetDefaultTab(browser, &tab_contents, &tab_id)) | 555 if (!ExtensionTabUtil::GetDefaultTab(browser, &tab_contents, &tab_id)) |
| 554 return; | 556 return; |
| 555 DispatchEventWithTab(profile, extension_id, "browserAction.onClicked", | 557 DispatchEventWithTab(profile, extension_id, "browserAction.onClicked", |
| 556 tab_contents->tab_contents()); | 558 tab_contents->tab_contents(), true); |
| 557 } | 559 } |
| OLD | NEW |