Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/browser_event_router.h" | 5 #include "chrome/browser/extensions/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/api/extension_action/extension_page_actions_ api_constants.h" | 9 #include "chrome/browser/extensions/api/extension_action/extension_page_actions_ api_constants.h" |
| 10 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" | 10 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 to_index)); | 332 to_index)); |
| 333 args->Append(object_args); | 333 args->Append(object_args); |
| 334 | 334 |
| 335 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 335 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
| 336 DispatchEvent(profile, events::kOnTabMoved, args.Pass(), | 336 DispatchEvent(profile, events::kOnTabMoved, args.Pass(), |
| 337 EventRouter::USER_GESTURE_UNKNOWN); | 337 EventRouter::USER_GESTURE_UNKNOWN); |
| 338 } | 338 } |
| 339 | 339 |
| 340 void BrowserEventRouter::TabUpdated(WebContents* contents, bool did_navigate) { | 340 void BrowserEventRouter::TabUpdated(WebContents* contents, bool did_navigate) { |
| 341 TabEntry* entry = GetTabEntry(contents); | 341 TabEntry* entry = GetTabEntry(contents); |
| 342 DictionaryValue* changed_properties = NULL; | 342 scoped_ptr<DictionaryValue> changed_properties; |
| 343 | 343 |
| 344 DCHECK(entry); | 344 DCHECK(entry); |
| 345 | 345 |
| 346 if (did_navigate) | 346 if (did_navigate) |
| 347 changed_properties = entry->DidNavigate(contents); | 347 changed_properties.reset(entry->DidNavigate(contents)); |
| 348 else | 348 else |
| 349 changed_properties = entry->UpdateLoadState(contents); | 349 changed_properties.reset(entry->UpdateLoadState(contents)); |
| 350 | 350 |
| 351 if (changed_properties) | 351 if (changed_properties.get()) |
|
not at google - send to devlin
2013/01/09 02:04:29
scoped_ptr works in conditionals without the .get(
mvrable
2013/01/09 19:25:35
Done.
| |
| 352 DispatchTabUpdatedEvent(contents, changed_properties); | 352 DispatchTabUpdatedEvent(contents, changed_properties.Pass()); |
| 353 } | 353 } |
| 354 | 354 |
| 355 void BrowserEventRouter::DispatchEvent( | 355 void BrowserEventRouter::DispatchEvent( |
| 356 Profile* profile, | 356 Profile* profile, |
| 357 const char* event_name, | 357 const char* event_name, |
| 358 scoped_ptr<ListValue> args, | 358 scoped_ptr<ListValue> args, |
| 359 EventRouter::UserGestureState user_gesture) { | 359 EventRouter::UserGestureState user_gesture) { |
| 360 if (!profile_->IsSameProfile(profile) || | 360 if (!profile_->IsSameProfile(profile) || |
| 361 !extensions::ExtensionSystem::Get(profile)->event_router()) | 361 !extensions::ExtensionSystem::Get(profile)->event_router()) |
| 362 return; | 362 return; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 390 return; | 390 return; |
| 391 | 391 |
| 392 scoped_ptr<ListValue> args(new ListValue()); | 392 scoped_ptr<ListValue> args(new ListValue()); |
| 393 args->Append(Value::CreateIntegerValue(window_id)); | 393 args->Append(Value::CreateIntegerValue(window_id)); |
| 394 | 394 |
| 395 DispatchEvent(profile, event_name, args.Pass(), | 395 DispatchEvent(profile, event_name, args.Pass(), |
| 396 EventRouter::USER_GESTURE_UNKNOWN); | 396 EventRouter::USER_GESTURE_UNKNOWN); |
| 397 } | 397 } |
| 398 | 398 |
| 399 static void WillDispatchTabUpdatedEvent(WebContents* contents, | 399 static void WillDispatchTabUpdatedEvent(WebContents* contents, |
| 400 DictionaryValue* changed_properties, | |
|
not at google - send to devlin
2013/01/09 02:04:29
const&?
mvrable
2013/01/09 19:25:35
Changed to a const*. I'm getting compiler errors
| |
| 400 Profile* profile, | 401 Profile* profile, |
| 401 const Extension* extension, | 402 const Extension* extension, |
| 402 ListValue* event_args) { | 403 ListValue* event_args) { |
| 404 // Overwrite the second argument with the appropriate properties dictionary, | |
| 405 // depending on extension permissions. | |
| 406 DictionaryValue* properties_value = changed_properties->DeepCopy(); | |
| 407 ExtensionTabUtil::ScrubTabValueForExtension(contents, extension, | |
| 408 properties_value); | |
| 409 event_args->Set(1, properties_value); | |
| 410 | |
| 411 // Overwrite the third arg with our tab value as seen by this extension. | |
| 403 DictionaryValue* tab_value = ExtensionTabUtil::CreateTabValue( | 412 DictionaryValue* tab_value = ExtensionTabUtil::CreateTabValue( |
| 404 contents, extension); | 413 contents, extension); |
| 405 // Overwrite the third arg with our tab value as seen by this extension. | |
| 406 event_args->Set(2, tab_value); | 414 event_args->Set(2, tab_value); |
| 407 } | 415 } |
| 408 | 416 |
| 409 void BrowserEventRouter::DispatchTabUpdatedEvent( | 417 void BrowserEventRouter::DispatchTabUpdatedEvent( |
| 410 WebContents* contents, DictionaryValue* changed_properties) { | 418 WebContents* contents, scoped_ptr<DictionaryValue> changed_properties) { |
| 411 DCHECK(changed_properties); | 419 DCHECK(changed_properties.get()); |
|
not at google - send to devlin
2013/01/09 02:04:29
can omit the .get()
mvrable
2013/01/09 19:25:35
Done.
| |
| 412 DCHECK(contents); | 420 DCHECK(contents); |
| 413 | 421 |
| 414 // The state of the tab (as seen from the extension point of view) has | 422 // The state of the tab (as seen from the extension point of view) has |
| 415 // changed. Send a notification to the extension. | 423 // changed. Send a notification to the extension. |
| 416 scoped_ptr<ListValue> args_base(new ListValue()); | 424 scoped_ptr<ListValue> args_base(new ListValue()); |
| 417 | 425 |
| 418 // First arg: The id of the tab that changed. | 426 // First arg: The id of the tab that changed. |
| 419 args_base->AppendInteger(ExtensionTabUtil::GetTabId(contents)); | 427 args_base->AppendInteger(ExtensionTabUtil::GetTabId(contents)); |
| 420 | 428 |
| 421 // Second arg: An object containing the changes to the tab state. | 429 // Second arg: An object containing the changes to the tab state. Filled in |
| 422 args_base->Append(changed_properties); | 430 // by WillDispatchTabUpdatedEvent as a copy of changed_properties, if the |
| 431 // extension has the tabs permission. | |
| 423 | 432 |
| 424 // Third arg: An object containing the state of the tab. Filled in by | 433 // Third arg: An object containing the state of the tab. Filled in by |
| 425 // WillDispatchTabUpdatedEvent. | 434 // WillDispatchTabUpdatedEvent. |
| 426 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); | 435 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); |
| 427 | 436 |
| 428 scoped_ptr<Event> event(new Event(events::kOnTabUpdated, args_base.Pass())); | 437 scoped_ptr<Event> event(new Event(events::kOnTabUpdated, args_base.Pass())); |
| 429 event->restrict_to_profile = profile; | 438 event->restrict_to_profile = profile; |
| 430 event->user_gesture = EventRouter::USER_GESTURE_NOT_ENABLED; | 439 event->user_gesture = EventRouter::USER_GESTURE_NOT_ENABLED; |
| 431 event->will_dispatch_callback = | 440 event->will_dispatch_callback = |
| 432 base::Bind(&WillDispatchTabUpdatedEvent, contents); | 441 base::Bind(&WillDispatchTabUpdatedEvent, |
| 442 contents, changed_properties.get()); | |
| 433 ExtensionSystem::Get(profile)->event_router()->BroadcastEvent(event.Pass()); | 443 ExtensionSystem::Get(profile)->event_router()->BroadcastEvent(event.Pass()); |
| 434 } | 444 } |
| 435 | 445 |
| 436 BrowserEventRouter::TabEntry* BrowserEventRouter::GetTabEntry( | 446 BrowserEventRouter::TabEntry* BrowserEventRouter::GetTabEntry( |
| 437 const WebContents* contents) { | 447 const WebContents* contents) { |
| 438 int tab_id = ExtensionTabUtil::GetTabId(contents); | 448 int tab_id = ExtensionTabUtil::GetTabId(contents); |
| 439 std::map<int, TabEntry>::iterator i = tab_entries_.find(tab_id); | 449 std::map<int, TabEntry>::iterator i = tab_entries_.find(tab_id); |
| 440 if (tab_entries_.end() == i) | 450 if (tab_entries_.end() == i) |
| 441 return NULL; | 451 return NULL; |
| 442 return &i->second; | 452 return &i->second; |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 474 TabClosingAt(tab_strip_model, old_contents, index); | 484 TabClosingAt(tab_strip_model, old_contents, index); |
| 475 TabInsertedAt(new_contents, index, tab_strip_model->active_index() == index); | 485 TabInsertedAt(new_contents, index, tab_strip_model->active_index() == index); |
| 476 } | 486 } |
| 477 | 487 |
| 478 void BrowserEventRouter::TabPinnedStateChanged(WebContents* contents, | 488 void BrowserEventRouter::TabPinnedStateChanged(WebContents* contents, |
| 479 int index) { | 489 int index) { |
| 480 TabStripModel* tab_strip = NULL; | 490 TabStripModel* tab_strip = NULL; |
| 481 int tab_index; | 491 int tab_index; |
| 482 | 492 |
| 483 if (ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index)) { | 493 if (ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index)) { |
| 484 DictionaryValue* changed_properties = new DictionaryValue(); | 494 scoped_ptr<DictionaryValue> changed_properties(new DictionaryValue()); |
| 485 changed_properties->SetBoolean(tab_keys::kPinnedKey, | 495 changed_properties->SetBoolean(tab_keys::kPinnedKey, |
| 486 tab_strip->IsTabPinned(tab_index)); | 496 tab_strip->IsTabPinned(tab_index)); |
| 487 DispatchTabUpdatedEvent(contents, changed_properties); | 497 DispatchTabUpdatedEvent(contents, changed_properties.Pass()); |
| 488 } | 498 } |
| 489 } | 499 } |
| 490 | 500 |
| 491 void BrowserEventRouter::TabStripEmpty() {} | 501 void BrowserEventRouter::TabStripEmpty() {} |
| 492 | 502 |
| 493 void BrowserEventRouter::DispatchOldPageActionEvent( | 503 void BrowserEventRouter::DispatchOldPageActionEvent( |
| 494 Profile* profile, | 504 Profile* profile, |
| 495 const std::string& extension_id, | 505 const std::string& extension_id, |
| 496 const std::string& page_action_id, | 506 const std::string& page_action_id, |
| 497 int tab_id, | 507 int tab_id, |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 564 event_name = "scriptBadge.onClicked"; | 574 event_name = "scriptBadge.onClicked"; |
| 565 break; | 575 break; |
| 566 case Extension::ActionInfo::TYPE_SYSTEM_INDICATOR: | 576 case Extension::ActionInfo::TYPE_SYSTEM_INDICATOR: |
| 567 // The System Indicator handles its own clicks. | 577 // The System Indicator handles its own clicks. |
| 568 break; | 578 break; |
| 569 } | 579 } |
| 570 | 580 |
| 571 if (event_name) { | 581 if (event_name) { |
| 572 scoped_ptr<ListValue> args(new ListValue()); | 582 scoped_ptr<ListValue> args(new ListValue()); |
| 573 DictionaryValue* tab_value = ExtensionTabUtil::CreateTabValue( | 583 DictionaryValue* tab_value = ExtensionTabUtil::CreateTabValue( |
| 574 web_contents, | 584 web_contents); |
| 575 ExtensionTabUtil::INCLUDE_PRIVACY_SENSITIVE_FIELDS); | |
| 576 args->Append(tab_value); | 585 args->Append(tab_value); |
| 577 | 586 |
| 578 DispatchEventToExtension(profile, | 587 DispatchEventToExtension(profile, |
| 579 extension_action.extension_id(), | 588 extension_action.extension_id(), |
| 580 event_name, | 589 event_name, |
| 581 args.Pass(), | 590 args.Pass(), |
| 582 EventRouter::USER_GESTURE_ENABLED); | 591 EventRouter::USER_GESTURE_ENABLED); |
| 583 } | 592 } |
| 584 } | 593 } |
| 585 | 594 |
| 586 } // namespace extensions | 595 } // namespace extensions |
| OLD | NEW |