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

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

Issue 10535077: TabContentsWrapper -> TabContents, part 12. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 6 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 | Annotate | Revision Log
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/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/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"
11 #include "chrome/browser/extensions/extension_event_names.h" 11 #include "chrome/browser/extensions/extension_event_names.h"
12 #include "chrome/browser/extensions/extension_event_router.h" 12 #include "chrome/browser/extensions/extension_event_router.h"
13 #include "chrome/browser/extensions/extension_service.h" 13 #include "chrome/browser/extensions/extension_service.h"
14 #include "chrome/browser/extensions/extension_tab_util.h" 14 #include "chrome/browser/extensions/extension_tab_util.h"
15 #include "chrome/browser/extensions/extension_window_controller.h" 15 #include "chrome/browser/extensions/extension_window_controller.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/ui/browser.h" 17 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 18 #include "chrome/browser/ui/tab_contents/tab_contents.h"
19 #include "chrome/browser/ui/tabs/tab_strip_model.h" 19 #include "chrome/browser/ui/tabs/tab_strip_model.h"
20 #include "chrome/common/chrome_notification_types.h" 20 #include "chrome/common/chrome_notification_types.h"
21 #include "chrome/common/extensions/extension.h" 21 #include "chrome/common/extensions/extension.h"
22 #include "chrome/common/extensions/extension_constants.h" 22 #include "chrome/common/extensions/extension_constants.h"
23 #include "content/public/browser/navigation_controller.h" 23 #include "content/public/browser/navigation_controller.h"
24 #include "content/public/browser/notification_service.h" 24 #include "content/public/browser/notification_service.h"
25 #include "content/public/browser/web_contents.h" 25 #include "content/public/browser/web_contents.h"
26 26
27 #if defined(TOOLKIT_GTK) 27 #if defined(TOOLKIT_GTK)
28 #include "ui/base/x/active_window_watcher_x.h" 28 #include "ui/base/x/active_window_watcher_x.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 // Init() can happen after the browser is running, so catch up with any 90 // Init() can happen after the browser is running, so catch up with any
91 // windows that already exist. 91 // windows that already exist.
92 for (BrowserList::const_iterator iter = BrowserList::begin(); 92 for (BrowserList::const_iterator iter = BrowserList::begin();
93 iter != BrowserList::end(); ++iter) { 93 iter != BrowserList::end(); ++iter) {
94 RegisterForBrowserNotifications(*iter); 94 RegisterForBrowserNotifications(*iter);
95 95
96 // Also catch up our internal bookkeeping of tab entries. 96 // Also catch up our internal bookkeeping of tab entries.
97 Browser* browser = *iter; 97 Browser* browser = *iter;
98 if (browser->tab_strip_model()) { 98 if (browser->tab_strip_model()) {
99 for (int i = 0; i < browser->tab_strip_model()->count(); ++i) { 99 for (int i = 0; i < browser->tab_strip_model()->count(); ++i) {
100 WebContents* contents = 100 WebContents* contents = browser->GetTabContentsAt(i)->web_contents();
101 browser->GetTabContentsWrapperAt(i)->web_contents();
102 int tab_id = ExtensionTabUtil::GetTabId(contents); 101 int tab_id = ExtensionTabUtil::GetTabId(contents);
103 tab_entries_[tab_id] = TabEntry(); 102 tab_entries_[tab_id] = TabEntry();
104 } 103 }
105 } 104 }
106 } 105 }
107 106
108 initialized_ = true; 107 initialized_ = true;
109 } 108 }
110 109
111 ExtensionBrowserEventRouter::ExtensionBrowserEventRouter(Profile* profile) 110 ExtensionBrowserEventRouter::ExtensionBrowserEventRouter(Profile* profile)
(...skipping 25 matching lines...) Expand all
137 browser->tab_strip_model()->AddObserver(this); 136 browser->tab_strip_model()->AddObserver(this);
138 137
139 // If this is a new window, it isn't ready at this point, so we register to be 138 // If this is a new window, it isn't ready at this point, so we register to be
140 // notified when it is. If this is an existing window, this is a no-op that we 139 // notified when it is. If this is an existing window, this is a no-op that we
141 // just do to reduce code complexity. 140 // just do to reduce code complexity.
142 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY, 141 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_WINDOW_READY,
143 content::Source<Browser>(browser)); 142 content::Source<Browser>(browser));
144 143
145 for (int i = 0; i < browser->tab_strip_model()->count(); ++i) { 144 for (int i = 0; i < browser->tab_strip_model()->count(); ++i) {
146 RegisterForTabNotifications( 145 RegisterForTabNotifications(
147 browser->GetTabContentsWrapperAt(i)->web_contents()); 146 browser->GetTabContentsAt(i)->web_contents());
148 } 147 }
149 } 148 }
150 149
151 void ExtensionBrowserEventRouter::RegisterForTabNotifications( 150 void ExtensionBrowserEventRouter::RegisterForTabNotifications(
152 WebContents* contents) { 151 WebContents* contents) {
153 registrar_.Add( 152 registrar_.Add(
154 this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 153 this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
155 content::Source<NavigationController>(&contents->GetController())); 154 content::Source<NavigationController>(&contents->GetController()));
156 155
157 // Observing NOTIFICATION_WEB_CONTENTS_DESTROYED is necessary because it's 156 // Observing NOTIFICATION_WEB_CONTENTS_DESTROYED is necessary because it's
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 258
260 void ExtensionBrowserEventRouter::TabCreatedAt(WebContents* contents, 259 void ExtensionBrowserEventRouter::TabCreatedAt(WebContents* contents,
261 int index, 260 int index,
262 bool active) { 261 bool active) {
263 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext()); 262 Profile* profile = Profile::FromBrowserContext(contents->GetBrowserContext());
264 DispatchEventWithTab(profile, "", events::kOnTabCreated, contents, active); 263 DispatchEventWithTab(profile, "", events::kOnTabCreated, contents, active);
265 264
266 RegisterForTabNotifications(contents); 265 RegisterForTabNotifications(contents);
267 } 266 }
268 267
269 void ExtensionBrowserEventRouter::TabInsertedAt(TabContentsWrapper* contents, 268 void ExtensionBrowserEventRouter::TabInsertedAt(TabContents* contents,
270 int index, 269 int index,
271 bool active) { 270 bool active) {
272 // If tab is new, send created event. 271 // If tab is new, send created event.
273 int tab_id = ExtensionTabUtil::GetTabId(contents->web_contents()); 272 int tab_id = ExtensionTabUtil::GetTabId(contents->web_contents());
274 if (!GetTabEntry(contents->web_contents())) { 273 if (!GetTabEntry(contents->web_contents())) {
275 tab_entries_[tab_id] = TabEntry(); 274 tab_entries_[tab_id] = TabEntry();
276 275
277 TabCreatedAt(contents->web_contents(), index, active); 276 TabCreatedAt(contents->web_contents(), index, active);
278 return; 277 return;
279 } 278 }
280 279
281 ListValue args; 280 ListValue args;
282 args.Append(Value::CreateIntegerValue(tab_id)); 281 args.Append(Value::CreateIntegerValue(tab_id));
283 282
284 DictionaryValue* object_args = new DictionaryValue(); 283 DictionaryValue* object_args = new DictionaryValue();
285 object_args->Set(tab_keys::kNewWindowIdKey, Value::CreateIntegerValue( 284 object_args->Set(tab_keys::kNewWindowIdKey, Value::CreateIntegerValue(
286 ExtensionTabUtil::GetWindowIdOfTab(contents->web_contents()))); 285 ExtensionTabUtil::GetWindowIdOfTab(contents->web_contents())));
287 object_args->Set(tab_keys::kNewPositionKey, Value::CreateIntegerValue( 286 object_args->Set(tab_keys::kNewPositionKey, Value::CreateIntegerValue(
288 index)); 287 index));
289 args.Append(object_args); 288 args.Append(object_args);
290 289
291 std::string json_args; 290 std::string json_args;
292 base::JSONWriter::Write(&args, &json_args); 291 base::JSONWriter::Write(&args, &json_args);
293 292
294 DispatchEvent(contents->profile(), events::kOnTabAttached, json_args); 293 DispatchEvent(contents->profile(), events::kOnTabAttached, json_args);
295 } 294 }
296 295
297 void ExtensionBrowserEventRouter::TabDetachedAt(TabContentsWrapper* contents, 296 void ExtensionBrowserEventRouter::TabDetachedAt(TabContents* contents,
298 int index) { 297 int index) {
299 if (!GetTabEntry(contents->web_contents())) { 298 if (!GetTabEntry(contents->web_contents())) {
300 // The tab was removed. Don't send detach event. 299 // The tab was removed. Don't send detach event.
301 return; 300 return;
302 } 301 }
303 302
304 ListValue args; 303 ListValue args;
305 args.Append(Value::CreateIntegerValue( 304 args.Append(Value::CreateIntegerValue(
306 ExtensionTabUtil::GetTabId(contents->web_contents()))); 305 ExtensionTabUtil::GetTabId(contents->web_contents())));
307 306
308 DictionaryValue* object_args = new DictionaryValue(); 307 DictionaryValue* object_args = new DictionaryValue();
309 object_args->Set(tab_keys::kOldWindowIdKey, Value::CreateIntegerValue( 308 object_args->Set(tab_keys::kOldWindowIdKey, Value::CreateIntegerValue(
310 ExtensionTabUtil::GetWindowIdOfTab(contents->web_contents()))); 309 ExtensionTabUtil::GetWindowIdOfTab(contents->web_contents())));
311 object_args->Set(tab_keys::kOldPositionKey, Value::CreateIntegerValue( 310 object_args->Set(tab_keys::kOldPositionKey, Value::CreateIntegerValue(
312 index)); 311 index));
313 args.Append(object_args); 312 args.Append(object_args);
314 313
315 std::string json_args; 314 std::string json_args;
316 base::JSONWriter::Write(&args, &json_args); 315 base::JSONWriter::Write(&args, &json_args);
317 316
318 DispatchEvent(contents->profile(), events::kOnTabDetached, json_args); 317 DispatchEvent(contents->profile(), events::kOnTabDetached, json_args);
319 } 318 }
320 319
321 void ExtensionBrowserEventRouter::TabClosingAt(TabStripModel* tab_strip_model, 320 void ExtensionBrowserEventRouter::TabClosingAt(TabStripModel* tab_strip_model,
322 TabContentsWrapper* contents, 321 TabContents* contents,
323 int index) { 322 int index) {
324 int tab_id = ExtensionTabUtil::GetTabId(contents->web_contents()); 323 int tab_id = ExtensionTabUtil::GetTabId(contents->web_contents());
325 324
326 ListValue args; 325 ListValue args;
327 args.Append(Value::CreateIntegerValue(tab_id)); 326 args.Append(Value::CreateIntegerValue(tab_id));
328 327
329 DictionaryValue* object_args = new DictionaryValue(); 328 DictionaryValue* object_args = new DictionaryValue();
330 object_args->SetBoolean(tab_keys::kWindowClosing, 329 object_args->SetBoolean(tab_keys::kWindowClosing,
331 tab_strip_model->closing_all()); 330 tab_strip_model->closing_all());
332 args.Append(object_args); 331 args.Append(object_args);
333 332
334 std::string json_args; 333 std::string json_args;
335 base::JSONWriter::Write(&args, &json_args); 334 base::JSONWriter::Write(&args, &json_args);
336 335
337 DispatchEvent(contents->profile(), events::kOnTabRemoved, json_args); 336 DispatchEvent(contents->profile(), events::kOnTabRemoved, json_args);
338 337
339 int removed_count = tab_entries_.erase(tab_id); 338 int removed_count = tab_entries_.erase(tab_id);
340 DCHECK_GT(removed_count, 0); 339 DCHECK_GT(removed_count, 0);
341 340
342 UnregisterForTabNotifications(contents->web_contents()); 341 UnregisterForTabNotifications(contents->web_contents());
343 } 342 }
344 343
345 void ExtensionBrowserEventRouter::ActiveTabChanged( 344 void ExtensionBrowserEventRouter::ActiveTabChanged(
346 TabContentsWrapper* old_contents, 345 TabContents* old_contents,
347 TabContentsWrapper* new_contents, 346 TabContents* new_contents,
348 int index, 347 int index,
349 bool user_gesture) { 348 bool user_gesture) {
350 ListValue args; 349 ListValue args;
351 int tab_id = ExtensionTabUtil::GetTabId(new_contents->web_contents()); 350 int tab_id = ExtensionTabUtil::GetTabId(new_contents->web_contents());
352 args.Append(Value::CreateIntegerValue(tab_id)); 351 args.Append(Value::CreateIntegerValue(tab_id));
353 352
354 DictionaryValue* object_args = new DictionaryValue(); 353 DictionaryValue* object_args = new DictionaryValue();
355 object_args->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue( 354 object_args->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue(
356 ExtensionTabUtil::GetWindowIdOfTab(new_contents->web_contents()))); 355 ExtensionTabUtil::GetWindowIdOfTab(new_contents->web_contents())));
357 args.Append(object_args); 356 args.Append(object_args);
(...skipping 17 matching lines...) Expand all
375 374
376 void ExtensionBrowserEventRouter::TabSelectionChanged( 375 void ExtensionBrowserEventRouter::TabSelectionChanged(
377 TabStripModel* tab_strip_model, 376 TabStripModel* tab_strip_model,
378 const TabStripSelectionModel& old_model) { 377 const TabStripSelectionModel& old_model) {
379 TabStripSelectionModel::SelectedIndices new_selection = 378 TabStripSelectionModel::SelectedIndices new_selection =
380 tab_strip_model->selection_model().selected_indices(); 379 tab_strip_model->selection_model().selected_indices();
381 ListValue* all = new ListValue(); 380 ListValue* all = new ListValue();
382 381
383 for (size_t i = 0; i < new_selection.size(); ++i) { 382 for (size_t i = 0; i < new_selection.size(); ++i) {
384 int index = new_selection[i]; 383 int index = new_selection[i];
385 TabContentsWrapper* contents = tab_strip_model->GetTabContentsAt(index); 384 TabContents* contents = tab_strip_model->GetTabContentsAt(index);
386 if (!contents) 385 if (!contents)
387 break; 386 break;
388 int tab_id = ExtensionTabUtil::GetTabId(contents->web_contents()); 387 int tab_id = ExtensionTabUtil::GetTabId(contents->web_contents());
389 all->Append(Value::CreateIntegerValue(tab_id)); 388 all->Append(Value::CreateIntegerValue(tab_id));
390 } 389 }
391 390
392 ListValue args; 391 ListValue args;
393 DictionaryValue* select_info = new DictionaryValue(); 392 DictionaryValue* select_info = new DictionaryValue();
394 393
395 select_info->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue( 394 select_info->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue(
396 ExtensionTabUtil::GetWindowIdOfTabStripModel(tab_strip_model))); 395 ExtensionTabUtil::GetWindowIdOfTabStripModel(tab_strip_model)));
397 396
398 select_info->Set(tab_keys::kTabIdsKey, all); 397 select_info->Set(tab_keys::kTabIdsKey, all);
399 args.Append(select_info); 398 args.Append(select_info);
400 399
401 std::string json_args; 400 std::string json_args;
402 base::JSONWriter::Write(&args, &json_args); 401 base::JSONWriter::Write(&args, &json_args);
403 402
404 // The onHighlighted event replaced onHighlightChanged. 403 // The onHighlighted event replaced onHighlightChanged.
405 Profile* profile = tab_strip_model->profile(); 404 Profile* profile = tab_strip_model->profile();
406 DispatchEvent(profile, events::kOnTabHighlightChanged, json_args); 405 DispatchEvent(profile, events::kOnTabHighlightChanged, json_args);
407 DispatchEvent(profile, events::kOnTabHighlighted, json_args); 406 DispatchEvent(profile, events::kOnTabHighlighted, json_args);
408 } 407 }
409 408
410 void ExtensionBrowserEventRouter::TabMoved(TabContentsWrapper* contents, 409 void ExtensionBrowserEventRouter::TabMoved(TabContents* contents,
411 int from_index, 410 int from_index,
412 int to_index) { 411 int to_index) {
413 ListValue args; 412 ListValue args;
414 args.Append(Value::CreateIntegerValue( 413 args.Append(Value::CreateIntegerValue(
415 ExtensionTabUtil::GetTabId(contents->web_contents()))); 414 ExtensionTabUtil::GetTabId(contents->web_contents())));
416 415
417 DictionaryValue* object_args = new DictionaryValue(); 416 DictionaryValue* object_args = new DictionaryValue();
418 object_args->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue( 417 object_args->Set(tab_keys::kWindowIdKey, Value::CreateIntegerValue(
419 ExtensionTabUtil::GetWindowIdOfTab(contents->web_contents()))); 418 ExtensionTabUtil::GetWindowIdOfTab(contents->web_contents())));
420 object_args->Set(tab_keys::kFromIndexKey, Value::CreateIntegerValue( 419 object_args->Set(tab_keys::kFromIndexKey, Value::CreateIntegerValue(
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 OnBrowserWindowReady(browser); 567 OnBrowserWindowReady(browser);
569 #if defined(OS_MACOSX) 568 #if defined(OS_MACOSX)
570 } else if (type == content::NOTIFICATION_NO_KEY_WINDOW) { 569 } else if (type == content::NOTIFICATION_NO_KEY_WINDOW) {
571 OnBrowserSetLastActive(NULL); 570 OnBrowserSetLastActive(NULL);
572 #endif 571 #endif
573 } else { 572 } else {
574 NOTREACHED(); 573 NOTREACHED();
575 } 574 }
576 } 575 }
577 576
578 void ExtensionBrowserEventRouter::TabChangedAt(TabContentsWrapper* contents, 577 void ExtensionBrowserEventRouter::TabChangedAt(TabContents* contents,
579 int index, 578 int index,
580 TabChangeType change_type) { 579 TabChangeType change_type) {
581 TabUpdated(contents->web_contents(), false); 580 TabUpdated(contents->web_contents(), false);
582 } 581 }
583 582
584 void ExtensionBrowserEventRouter::TabReplacedAt( 583 void ExtensionBrowserEventRouter::TabReplacedAt(
585 TabStripModel* tab_strip_model, 584 TabStripModel* tab_strip_model,
586 TabContentsWrapper* old_contents, 585 TabContents* old_contents,
587 TabContentsWrapper* new_contents, 586 TabContents* new_contents,
588 int index) { 587 int index) {
589 TabClosingAt(tab_strip_model, old_contents, index); 588 TabClosingAt(tab_strip_model, old_contents, index);
590 TabInsertedAt(new_contents, index, tab_strip_model->active_index() == index); 589 TabInsertedAt(new_contents, index, tab_strip_model->active_index() == index);
591 } 590 }
592 591
593 void ExtensionBrowserEventRouter::TabPinnedStateChanged( 592 void ExtensionBrowserEventRouter::TabPinnedStateChanged(
594 TabContentsWrapper* contents, 593 TabContents* contents,
595 int index) { 594 int index) {
596 TabStripModel* tab_strip = NULL; 595 TabStripModel* tab_strip = NULL;
597 int tab_index; 596 int tab_index;
598 597
599 if (ExtensionTabUtil::GetTabStripModel( 598 if (ExtensionTabUtil::GetTabStripModel(
600 contents->web_contents(), &tab_strip, &tab_index)) { 599 contents->web_contents(), &tab_strip, &tab_index)) {
601 DictionaryValue* changed_properties = new DictionaryValue(); 600 DictionaryValue* changed_properties = new DictionaryValue();
602 changed_properties->SetBoolean(tab_keys::kPinnedKey, 601 changed_properties->SetBoolean(tab_keys::kPinnedKey,
603 tab_strip->IsTabPinned(tab_index)); 602 tab_strip->IsTabPinned(tab_index));
604 DispatchTabUpdatedEvent(contents->web_contents(), changed_properties); 603 DispatchTabUpdatedEvent(contents->web_contents(), changed_properties);
(...skipping 20 matching lines...) Expand all
625 624
626 std::string json_args; 625 std::string json_args;
627 base::JSONWriter::Write(&args, &json_args); 626 base::JSONWriter::Write(&args, &json_args);
628 627
629 DispatchEventToExtension(profile, extension_id, "pageActions", json_args); 628 DispatchEventToExtension(profile, extension_id, "pageActions", json_args);
630 } 629 }
631 630
632 void ExtensionBrowserEventRouter::BrowserActionExecuted( 631 void ExtensionBrowserEventRouter::BrowserActionExecuted(
633 const std::string& extension_id, Browser* browser) { 632 const std::string& extension_id, Browser* browser) {
634 Profile* profile = browser->profile(); 633 Profile* profile = browser->profile();
635 TabContentsWrapper* tab_contents = NULL; 634 TabContents* tab_contents = NULL;
636 int tab_id = 0; 635 int tab_id = 0;
637 if (!ExtensionTabUtil::GetDefaultTab(browser, &tab_contents, &tab_id)) 636 if (!ExtensionTabUtil::GetDefaultTab(browser, &tab_contents, &tab_id))
638 return; 637 return;
639 ExtensionActionExecuted(profile, extension_id, tab_contents); 638 ExtensionActionExecuted(profile, extension_id, tab_contents);
640 } 639 }
641 640
642 void ExtensionBrowserEventRouter::PageActionExecuted( 641 void ExtensionBrowserEventRouter::PageActionExecuted(
643 Profile* profile, 642 Profile* profile,
644 const std::string& extension_id, 643 const std::string& extension_id,
645 const std::string& page_action_id, 644 const std::string& page_action_id,
646 int tab_id, 645 int tab_id,
647 const std::string& url, 646 const std::string& url,
648 int button) { 647 int button) {
649 DispatchOldPageActionEvent(profile, extension_id, page_action_id, tab_id, url, 648 DispatchOldPageActionEvent(profile, extension_id, page_action_id, tab_id, url,
650 button); 649 button);
651 TabContentsWrapper* tab_contents = NULL; 650 TabContents* tab_contents = NULL;
652 if (!ExtensionTabUtil::GetTabById(tab_id, profile, profile->IsOffTheRecord(), 651 if (!ExtensionTabUtil::GetTabById(tab_id, profile, profile->IsOffTheRecord(),
653 NULL, NULL, &tab_contents, NULL)) { 652 NULL, NULL, &tab_contents, NULL)) {
654 return; 653 return;
655 } 654 }
656 ExtensionActionExecuted(profile, extension_id, tab_contents); 655 ExtensionActionExecuted(profile, extension_id, tab_contents);
657 } 656 }
658 657
659 void ExtensionBrowserEventRouter::CommandExecuted( 658 void ExtensionBrowserEventRouter::CommandExecuted(
660 Profile* profile, 659 Profile* profile,
661 const std::string& extension_id, 660 const std::string& extension_id,
662 const std::string& command) { 661 const std::string& command) {
663 ListValue args; 662 ListValue args;
664 args.Append(Value::CreateStringValue(command)); 663 args.Append(Value::CreateStringValue(command));
665 std::string json_args; 664 std::string json_args;
666 base::JSONWriter::Write(&args, &json_args); 665 base::JSONWriter::Write(&args, &json_args);
667 666
668 DispatchEventToExtension(profile, 667 DispatchEventToExtension(profile,
669 extension_id, 668 extension_id,
670 "experimental.keybinding.onCommand", 669 "experimental.keybinding.onCommand",
671 json_args); 670 json_args);
672 } 671 }
673 672
674 void ExtensionBrowserEventRouter::ExtensionActionExecuted( 673 void ExtensionBrowserEventRouter::ExtensionActionExecuted(
675 Profile* profile, 674 Profile* profile,
676 const std::string& extension_id, 675 const std::string& extension_id,
677 TabContentsWrapper* tab_contents) { 676 TabContents* tab_contents) {
678 const extensions::Extension* extension = 677 const extensions::Extension* extension =
679 profile->GetExtensionService()->GetExtensionById(extension_id, false); 678 profile->GetExtensionService()->GetExtensionById(extension_id, false);
680 if (!extension) 679 if (!extension)
681 return; 680 return;
682 681
683 const char* event_name = NULL; 682 const char* event_name = NULL;
684 switch (extension->declared_action_type()) { 683 switch (extension->declared_action_type()) {
685 case ExtensionAction::TYPE_NONE: 684 case ExtensionAction::TYPE_NONE:
686 break; 685 break;
687 case ExtensionAction::TYPE_BROWSER: 686 case ExtensionAction::TYPE_BROWSER:
688 event_name = "browserAction.onClicked"; 687 event_name = "browserAction.onClicked";
689 break; 688 break;
690 case ExtensionAction::TYPE_PAGE: 689 case ExtensionAction::TYPE_PAGE:
691 event_name = "pageAction.onClicked"; 690 event_name = "pageAction.onClicked";
692 break; 691 break;
693 } 692 }
694 693
695 if (event_name) { 694 if (event_name) {
696 DispatchEventWithTab(profile, 695 DispatchEventWithTab(profile,
697 extension_id, 696 extension_id,
698 event_name, 697 event_name,
699 tab_contents->web_contents(), 698 tab_contents->web_contents(),
700 true); 699 true);
701 } 700 }
702 } 701 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_browser_event_router.h ('k') | chrome/browser/extensions/extension_browsertests_misc.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698