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

Side by Side Diff: chrome/browser/extensions/api/tabs/tabs_event_router.cc

Issue 225093019: Zoom Extension API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Using callbacks instead of zoom IDs. Created 6 years, 8 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/api/tabs/tabs_event_router.h" 5 #include "chrome/browser/extensions/api/tabs/tabs_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/chrome_notification_types.h" 9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/extensions/api/tabs/tabs_constants.h" 10 #include "chrome/browser/extensions/api/tabs/tabs_constants.h"
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 142
143 // Observing NOTIFICATION_WEB_CONTENTS_DESTROYED is necessary because it's 143 // Observing NOTIFICATION_WEB_CONTENTS_DESTROYED is necessary because it's
144 // possible for tabs to be created, detached and then destroyed without 144 // possible for tabs to be created, detached and then destroyed without
145 // ever having been re-attached and closed. This happens in the case of 145 // ever having been re-attached and closed. This happens in the case of
146 // a devtools WebContents that is opened in window, docked, then closed. 146 // a devtools WebContents that is opened in window, docked, then closed.
147 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 147 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
148 content::Source<WebContents>(contents)); 148 content::Source<WebContents>(contents));
149 149
150 registrar_.Add(this, chrome::NOTIFICATION_FAVICON_UPDATED, 150 registrar_.Add(this, chrome::NOTIFICATION_FAVICON_UPDATED,
151 content::Source<WebContents>(contents)); 151 content::Source<WebContents>(contents));
152
153 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_ZOOM_CHANGE,
not at google - send to devlin 2014/04/09 03:52:11 it's a shame this uses notifications rather than a
paulmeyer 2014/04/11 03:01:02 Jam just expressed something similar about the not
154 content::Source<WebContents>(contents));
152 } 155 }
153 156
154 void TabsEventRouter::UnregisterForTabNotifications(WebContents* contents) { 157 void TabsEventRouter::UnregisterForTabNotifications(WebContents* contents) {
155 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 158 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
156 content::Source<NavigationController>(&contents->GetController())); 159 content::Source<NavigationController>(&contents->GetController()));
157 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 160 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
158 content::Source<WebContents>(contents)); 161 content::Source<WebContents>(contents));
159 registrar_.Remove(this, chrome::NOTIFICATION_FAVICON_UPDATED, 162 registrar_.Remove(this, chrome::NOTIFICATION_FAVICON_UPDATED,
160 content::Source<WebContents>(contents)); 163 content::Source<WebContents>(contents));
164 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_ZOOM_CHANGE,
165 content::Source<WebContents>(contents));
not at google - send to devlin 2014/04/09 03:52:11 this code should be using registar_.RemoveAll()
paulmeyer 2014/04/11 03:01:02 I agree, although I'm not using this notification
not at google - send to devlin 2014/04/11 15:04:25 Probably not. Somebody can clean those up separate
161 } 166 }
162 167
163 void TabsEventRouter::OnBrowserRemoved(Browser* browser) { 168 void TabsEventRouter::OnBrowserRemoved(Browser* browser) {
164 if (!profile_->IsSameProfile(browser->profile())) 169 if (!profile_->IsSameProfile(browser->profile()))
165 return; 170 return;
166 171
167 // Stop listening to TabStripModel events for this browser. 172 // Stop listening to TabStripModel events for this browser.
168 browser->tab_strip_model()->RemoveObserver(this); 173 browser->tab_strip_model()->RemoveObserver(this);
169 } 174 }
170 175
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 new Event(tabs::OnUpdated::kEventName, args_base.Pass())); 471 new Event(tabs::OnUpdated::kEventName, args_base.Pass()));
467 event->restrict_to_browser_context = profile; 472 event->restrict_to_browser_context = profile;
468 event->user_gesture = EventRouter::USER_GESTURE_NOT_ENABLED; 473 event->user_gesture = EventRouter::USER_GESTURE_NOT_ENABLED;
469 event->will_dispatch_callback = 474 event->will_dispatch_callback =
470 base::Bind(&WillDispatchTabUpdatedEvent, 475 base::Bind(&WillDispatchTabUpdatedEvent,
471 contents, 476 contents,
472 changed_properties.get()); 477 changed_properties.get());
473 ExtensionSystem::Get(profile)->event_router()->BroadcastEvent(event.Pass()); 478 ExtensionSystem::Get(profile)->event_router()->BroadcastEvent(event.Pass());
474 } 479 }
475 480
481 void TabsEventRouter::DispatchTabZoomChangeEvent(
482 WebContents* contents,
483 double old_zoom_factor,
484 double new_zoom_factor,
485 base::DictionaryValue* zoom_settings) {
486 DCHECK(contents);
487 scoped_ptr<base::ListValue> args(new base::ListValue);
488 int tab_id = ExtensionTabUtil::GetTabId(contents);
489 if (tab_id < 0)
490 return;
491
492 args->AppendInteger(tab_id);
493 args->AppendDouble(old_zoom_factor);
494 args->AppendDouble(new_zoom_factor);
495 args->Append(zoom_settings);
not at google - send to devlin 2014/04/09 03:52:11 a model will be getting generated for OnZoomChange
paulmeyer 2014/04/11 03:01:02 Done.
496
497 Profile* profile = Profile::FromBrowserContext(
498 contents->GetBrowserContext());
499 DispatchEvent(profile, tabs::OnZoomChange::kEventName, args.Pass(),
500 EventRouter::USER_GESTURE_UNKNOWN);
501 }
502
476 TabsEventRouter::TabEntry* TabsEventRouter::GetTabEntry( 503 TabsEventRouter::TabEntry* TabsEventRouter::GetTabEntry(
477 const WebContents* contents) { 504 const WebContents* contents) {
478 int tab_id = ExtensionTabUtil::GetTabId(contents); 505 int tab_id = ExtensionTabUtil::GetTabId(contents);
479 std::map<int, TabEntry>::iterator i = tab_entries_.find(tab_id); 506 std::map<int, TabEntry>::iterator i = tab_entries_.find(tab_id);
480 if (tab_entries_.end() == i) 507 if (tab_entries_.end() == i)
481 return NULL; 508 return NULL;
482 return &i->second; 509 return &i->second;
483 } 510 }
484 511
485 void TabsEventRouter::Observe(int type, 512 void TabsEventRouter::Observe(int type,
486 const content::NotificationSource& source, 513 const content::NotificationSource& source,
487 const content::NotificationDetails& details) { 514 const content::NotificationDetails& details) {
488 if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) { 515 if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) {
not at google - send to devlin 2014/04/09 03:52:11 bleh this should be a switch. whatevs.
paulmeyer 2014/04/11 03:01:02 My code is gone from here now too. Is it worth cha
not at google - send to devlin 2014/04/11 15:04:25 nah
489 NavigationController* source_controller = 516 NavigationController* source_controller =
490 content::Source<NavigationController>(source).ptr(); 517 content::Source<NavigationController>(source).ptr();
491 TabUpdated(source_controller->GetWebContents(), true); 518 TabUpdated(source_controller->GetWebContents(), true);
492 } else if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) { 519 } else if (type == content::NOTIFICATION_WEB_CONTENTS_DESTROYED) {
493 // Tab was destroyed after being detached (without being re-attached). 520 // Tab was destroyed after being detached (without being re-attached).
494 WebContents* contents = content::Source<WebContents>(source).ptr(); 521 WebContents* contents = content::Source<WebContents>(source).ptr();
495 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 522 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
496 content::Source<NavigationController>(&contents->GetController())); 523 content::Source<NavigationController>(&contents->GetController()));
497 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 524 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
498 content::Source<WebContents>(contents)); 525 content::Source<WebContents>(contents));
499 registrar_.Remove(this, chrome::NOTIFICATION_FAVICON_UPDATED, 526 registrar_.Remove(this, chrome::NOTIFICATION_FAVICON_UPDATED,
500 content::Source<WebContents>(contents)); 527 content::Source<WebContents>(contents));
not at google - send to devlin 2014/04/09 03:52:11 you presumably need to unregister for tab zoom not
paulmeyer 2014/04/11 03:01:02 Not using notifications anymore. On 2014/04/09 03
501 } else if (type == chrome::NOTIFICATION_FAVICON_UPDATED) { 528 } else if (type == chrome::NOTIFICATION_FAVICON_UPDATED) {
502 bool icon_url_changed = *content::Details<bool>(details).ptr(); 529 bool icon_url_changed = *content::Details<bool>(details).ptr();
503 if (icon_url_changed) 530 if (icon_url_changed)
504 FaviconUrlUpdated(content::Source<WebContents>(source).ptr()); 531 FaviconUrlUpdated(content::Source<WebContents>(source).ptr());
532 } else if (type == content::NOTIFICATION_WEB_CONTENTS_ZOOM_CHANGE) {
533 content::ZoomChangeDetails zoom_change_details =
534 *content::Details<content::ZoomChangeDetails>(details).ptr();
535 double old_zoom_factor =
536 content::ZoomLevelToZoomFactor(zoom_change_details.old_zoom_level);
537 double new_zoom_factor =
538 content::ZoomLevelToZoomFactor(zoom_change_details.new_zoom_level);
539 base::DictionaryValue* zoom_settings = new base::DictionaryValue();
540 ZoomModeToZoomSettings(zoom_change_details.zoom_mode, zoom_settings);
541 DispatchTabZoomChangeEvent(content::Source<WebContents>(source).ptr(),
542 old_zoom_factor, new_zoom_factor, zoom_settings);
505 } else { 543 } else {
506 NOTREACHED(); 544 NOTREACHED();
507 } 545 }
508 } 546 }
509 547
510 void TabsEventRouter::TabChangedAt(WebContents* contents, 548 void TabsEventRouter::TabChangedAt(WebContents* contents,
511 int index, 549 int index,
512 TabChangeType change_type) { 550 TabChangeType change_type) {
513 TabUpdated(contents, false); 551 TabUpdated(contents, false);
514 } 552 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 if (ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index)) { 586 if (ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index)) {
549 scoped_ptr<base::DictionaryValue> changed_properties( 587 scoped_ptr<base::DictionaryValue> changed_properties(
550 new base::DictionaryValue()); 588 new base::DictionaryValue());
551 changed_properties->SetBoolean(tabs_constants::kPinnedKey, 589 changed_properties->SetBoolean(tabs_constants::kPinnedKey,
552 tab_strip->IsTabPinned(tab_index)); 590 tab_strip->IsTabPinned(tab_index));
553 DispatchTabUpdatedEvent(contents, changed_properties.Pass()); 591 DispatchTabUpdatedEvent(contents, changed_properties.Pass());
554 } 592 }
555 } 593 }
556 594
557 } // namespace extensions 595 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698