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

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: ETU now SetString()'s for empty values 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(
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 scoped_ptr<ListValue> args(event_args->DeepCopy());
408 args->Append(ExtensionTabUtil::CreateTabValueActive(
409 web_contents,
410 active,
411 profile->GetExtensionService()->extensions()->GetByID(
412 (*it)->extension_id)));
413 DispatchEventToExtension(profile, (*it)->extension_id, event_name,
414 args.Pass(), user_gesture);
415 }
399 } 416 }
400 } 417 }
401 418
402 void BrowserEventRouter::DispatchSimpleBrowserEvent( 419 void BrowserEventRouter::DispatchSimpleBrowserEvent(
403 Profile* profile, const int window_id, const char* event_name) { 420 Profile* profile, const int window_id, const char* event_name) {
404 if (!profile_->IsSameProfile(profile)) 421 if (!profile_->IsSameProfile(profile))
405 return; 422 return;
406 423
407 scoped_ptr<ListValue> args(new ListValue()); 424 scoped_ptr<ListValue> args(new ListValue());
408 args->Append(Value::CreateIntegerValue(window_id)); 425 args->Append(Value::CreateIntegerValue(window_id));
(...skipping 11 matching lines...) Expand all
420 // changed. Send a notification to the extension. 437 // changed. Send a notification to the extension.
421 scoped_ptr<ListValue> args(new ListValue()); 438 scoped_ptr<ListValue> args(new ListValue());
422 439
423 // First arg: The id of the tab that changed. 440 // First arg: The id of the tab that changed.
424 args->Append(Value::CreateIntegerValue(ExtensionTabUtil::GetTabId(contents))); 441 args->Append(Value::CreateIntegerValue(ExtensionTabUtil::GetTabId(contents)));
425 442
426 // Second arg: An object containing the changes to the tab state. 443 // Second arg: An object containing the changes to the tab state.
427 args->Append(changed_properties); 444 args->Append(changed_properties);
428 445
429 // Third arg: An object containing the state of the tab. 446 // Third arg: An object containing the state of the tab.
430 args->Append(ExtensionTabUtil::CreateTabValue(contents)); 447 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
431 448
432 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); 449 DispatchEventWithTab(profile, "", events::kOnTabUpdated, contents, true,
433 DispatchEvent(profile, events::kOnTabUpdated, args.Pass(), 450 EventRouter::USER_GESTURE_UNKNOWN, args.Pass());
434 EventRouter::USER_GESTURE_UNKNOWN);
435 } 451 }
436 452
437 BrowserEventRouter::TabEntry* BrowserEventRouter::GetTabEntry( 453 BrowserEventRouter::TabEntry* BrowserEventRouter::GetTabEntry(
438 const WebContents* contents) { 454 const WebContents* contents) {
439 int tab_id = ExtensionTabUtil::GetTabId(contents); 455 int tab_id = ExtensionTabUtil::GetTabId(contents);
440 std::map<int, TabEntry>::iterator i = tab_entries_.find(tab_id); 456 std::map<int, TabEntry>::iterator i = tab_entries_.find(tab_id);
441 if (tab_entries_.end() == i) 457 if (tab_entries_.end() == i)
442 return NULL; 458 return NULL;
443 return &i->second; 459 return &i->second;
444 } 460 }
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 DispatchEventWithTab(profile, 600 DispatchEventWithTab(profile,
585 extension_action.extension_id(), 601 extension_action.extension_id(),
586 event_name, 602 event_name,
587 tab_contents->web_contents(), 603 tab_contents->web_contents(),
588 true, 604 true,
589 EventRouter::USER_GESTURE_ENABLED); 605 EventRouter::USER_GESTURE_ENABLED);
590 } 606 }
591 } 607 }
592 608
593 } // namespace extensions 609 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/browser_event_router.h ('k') | chrome/browser/extensions/browser_extension_window_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698