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

Side by Side Diff: chrome/browser/extensions/browser_event_router.cc

Issue 10829186: Tabs API is usable without tabs permission. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: . Created 8 years, 3 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
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/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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 event_name, event_args.Pass(), profile, cross_incognito_args.Pass(), 377 event_name, event_args.Pass(), profile, cross_incognito_args.Pass(),
378 GURL()); 378 GURL());
379 } 379 }
380 380
381 void BrowserEventRouter::DispatchEventWithTab( 381 void BrowserEventRouter::DispatchEventWithTab(
382 Profile* profile, 382 Profile* profile,
383 const std::string& extension_id, 383 const std::string& extension_id,
384 const char* event_name, 384 const char* event_name,
385 const WebContents* web_contents, 385 const WebContents* web_contents,
386 bool active, 386 bool active,
387 EventRouter::UserGestureState user_gesture) { 387 EventRouter::UserGestureState user_gesture,
388 scoped_ptr<ListValue> event_args) {
388 if (!profile_->IsSameProfile(profile)) 389 if (!profile_->IsSameProfile(profile))
389 return; 390 return;
390 391
391 scoped_ptr<ListValue> args(new ListValue());
392 args->Append(ExtensionTabUtil::CreateTabValueActive(
393 web_contents, active));
394 if (!extension_id.empty()) { 392 if (!extension_id.empty()) {
395 DispatchEventToExtension(profile, extension_id, event_name, args.Pass(), 393 event_args->Append(ExtensionTabUtil::CreateTabValueActive(
396 user_gesture); 394 web_contents,
395 active,
396 profile->GetExtensionService()->extensions()->GetByID(extension_id)));
397 DispatchEventToExtension(profile, extension_id, event_name,
398 event_args.Pass(), user_gesture);
397 } else { 399 } else {
398 DispatchEvent(profile, event_name, args.Pass(), user_gesture); 400 const EventListenerMap::ListenerList& listeners(
Aaron Boodman 2012/08/31 20:28:51 Nit: typical style would be to use equals here. I
401 ExtensionSystem::Get(profile)->event_router()->
402 listeners().GetEventListenersByName(event_name));
403
404 for (EventListenerMap::ListenerList::const_iterator it = listeners.begin();
405 it != listeners.end();
406 ++it) {
407 event_args->Append(ExtensionTabUtil::CreateTabValueActive(
408 web_contents,
409 active,
410 profile->GetExtensionService()->extensions()->GetByID(
411 (*it)->extension_id)));
412 DispatchEventToExtension(profile, (*it)->extension_id, event_name,
413 event_args.Pass(), user_gesture);
414 }
399 } 415 }
400 } 416 }
401 417
402 void BrowserEventRouter::DispatchSimpleBrowserEvent( 418 void BrowserEventRouter::DispatchSimpleBrowserEvent(
403 Profile* profile, const int window_id, const char* event_name) { 419 Profile* profile, const int window_id, const char* event_name) {
404 if (!profile_->IsSameProfile(profile)) 420 if (!profile_->IsSameProfile(profile))
405 return; 421 return;
406 422
407 scoped_ptr<ListValue> args(new ListValue()); 423 scoped_ptr<ListValue> args(new ListValue());
408 args->Append(Value::CreateIntegerValue(window_id)); 424 args->Append(Value::CreateIntegerValue(window_id));
(...skipping 11 matching lines...) Expand all
420 // changed. Send a notification to the extension. 436 // changed. Send a notification to the extension.
421 scoped_ptr<ListValue> args(new ListValue()); 437 scoped_ptr<ListValue> args(new ListValue());
422 438
423 // First arg: The id of the tab that changed. 439 // First arg: The id of the tab that changed.
424 args->Append(Value::CreateIntegerValue(ExtensionTabUtil::GetTabId(contents))); 440 args->Append(Value::CreateIntegerValue(ExtensionTabUtil::GetTabId(contents)));
425 441
426 // Second arg: An object containing the changes to the tab state. 442 // Second arg: An object containing the changes to the tab state.
427 args->Append(changed_properties); 443 args->Append(changed_properties);
428 444
429 // Third arg: An object containing the state of the tab. 445 // Third arg: An object containing the state of the tab.
430 args->Append(ExtensionTabUtil::CreateTabValue(contents)); 446 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
431 447
432 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); 448 DispatchEventWithTab(profile, "", events::kOnTabUpdated, contents, true,
433 DispatchEvent(profile, events::kOnTabUpdated, args.Pass(), 449 EventRouter::USER_GESTURE_UNKNOWN, args.Pass());
434 EventRouter::USER_GESTURE_UNKNOWN);
435 } 450 }
436 451
437 BrowserEventRouter::TabEntry* BrowserEventRouter::GetTabEntry( 452 BrowserEventRouter::TabEntry* BrowserEventRouter::GetTabEntry(
438 const WebContents* contents) { 453 const WebContents* contents) {
439 int tab_id = ExtensionTabUtil::GetTabId(contents); 454 int tab_id = ExtensionTabUtil::GetTabId(contents);
440 std::map<int, TabEntry>::iterator i = tab_entries_.find(tab_id); 455 std::map<int, TabEntry>::iterator i = tab_entries_.find(tab_id);
441 if (tab_entries_.end() == i) 456 if (tab_entries_.end() == i)
442 return NULL; 457 return NULL;
443 return &i->second; 458 return &i->second;
444 } 459 }
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 DispatchEventWithTab(profile, 599 DispatchEventWithTab(profile,
585 extension_action.extension_id(), 600 extension_action.extension_id(),
586 event_name, 601 event_name,
587 tab_contents->web_contents(), 602 tab_contents->web_contents(),
588 true, 603 true,
589 EventRouter::USER_GESTURE_ENABLED); 604 EventRouter::USER_GESTURE_ENABLED);
590 } 605 }
591 } 606 }
592 607
593 } // namespace extensions 608 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698