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

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

Issue 301733006: Zoom Extension API (chrome) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix javascript test function signature. Created 6 years, 5 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 141
142 // Observing NOTIFICATION_WEB_CONTENTS_DESTROYED is necessary because it's 142 // Observing NOTIFICATION_WEB_CONTENTS_DESTROYED is necessary because it's
143 // possible for tabs to be created, detached and then destroyed without 143 // possible for tabs to be created, detached and then destroyed without
144 // ever having been re-attached and closed. This happens in the case of 144 // ever having been re-attached and closed. This happens in the case of
145 // a devtools WebContents that is opened in window, docked, then closed. 145 // a devtools WebContents that is opened in window, docked, then closed.
146 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 146 registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
147 content::Source<WebContents>(contents)); 147 content::Source<WebContents>(contents));
148 148
149 registrar_.Add(this, chrome::NOTIFICATION_FAVICON_UPDATED, 149 registrar_.Add(this, chrome::NOTIFICATION_FAVICON_UPDATED,
150 content::Source<WebContents>(contents)); 150 content::Source<WebContents>(contents));
151
152 ZoomController::FromWebContents(contents)->AddObserver(this);
151 } 153 }
152 154
153 void TabsEventRouter::UnregisterForTabNotifications(WebContents* contents) { 155 void TabsEventRouter::UnregisterForTabNotifications(WebContents* contents) {
154 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 156 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
155 content::Source<NavigationController>(&contents->GetController())); 157 content::Source<NavigationController>(&contents->GetController()));
156 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, 158 registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
157 content::Source<WebContents>(contents)); 159 content::Source<WebContents>(contents));
158 registrar_.Remove(this, chrome::NOTIFICATION_FAVICON_UPDATED, 160 registrar_.Remove(this, chrome::NOTIFICATION_FAVICON_UPDATED,
159 content::Source<WebContents>(contents)); 161 content::Source<WebContents>(contents));
162
163 ZoomController::FromWebContents(contents)->RemoveObserver(this);
160 } 164 }
161 165
162 void TabsEventRouter::OnBrowserRemoved(Browser* browser) { 166 void TabsEventRouter::OnBrowserRemoved(Browser* browser) {
163 if (!profile_->IsSameProfile(browser->profile())) 167 if (!profile_->IsSameProfile(browser->profile()))
164 return; 168 return;
165 169
166 // Stop listening to TabStripModel events for this browser. 170 // Stop listening to TabStripModel events for this browser.
167 browser->tab_strip_model()->RemoveObserver(this); 171 browser->tab_strip_model()->RemoveObserver(this);
168 } 172 }
169 173
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 549
546 if (ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index)) { 550 if (ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index)) {
547 scoped_ptr<base::DictionaryValue> changed_properties( 551 scoped_ptr<base::DictionaryValue> changed_properties(
548 new base::DictionaryValue()); 552 new base::DictionaryValue());
549 changed_properties->SetBoolean(tabs_constants::kPinnedKey, 553 changed_properties->SetBoolean(tabs_constants::kPinnedKey,
550 tab_strip->IsTabPinned(tab_index)); 554 tab_strip->IsTabPinned(tab_index));
551 DispatchTabUpdatedEvent(contents, changed_properties.Pass()); 555 DispatchTabUpdatedEvent(contents, changed_properties.Pass());
552 } 556 }
553 } 557 }
554 558
559 void TabsEventRouter::OnZoomChanged(
560 const ZoomController::ZoomChangedEventData& data) {
561 DCHECK(data.web_contents);
562 int tab_id = ExtensionTabUtil::GetTabId(data.web_contents);
563 if (tab_id < 0)
564 return;
565
566 // Prepare the zoom change information.
567 api::tabs::OnZoomChange::ZoomChangeInfo zoom_change_info;
568 zoom_change_info.tab_id = tab_id;
569 zoom_change_info.old_zoom_factor =
570 content::ZoomLevelToZoomFactor(data.old_zoom_level);
571 zoom_change_info.new_zoom_factor =
572 content::ZoomLevelToZoomFactor(data.new_zoom_level);
573 ZoomModeToZoomSettings(data.zoom_mode,
574 &zoom_change_info.zoom_settings);
575
576 // Dispatch the |onZoomChange| event.
577 Profile* profile = Profile::FromBrowserContext(
578 data.web_contents->GetBrowserContext());
579 DispatchEvent(profile,
580 tabs::OnZoomChange::kEventName,
581 api::tabs::OnZoomChange::Create(zoom_change_info),
582 EventRouter::USER_GESTURE_UNKNOWN);
583 }
584
555 } // namespace extensions 585 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698