diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-07 15:08:42 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-07 15:08:42 +0000 |
commit | 89c9aca0f74519e281f1a0ce425a8f6b195c658b (patch) | |
tree | 5bcdabc9ac9a1bfac3f7e78dca2ff04f5d39c49d | |
parent | 8fbdeb2c722073c80e2c99bd529d274dbe924645 (diff) | |
download | chromium_src-89c9aca0f74519e281f1a0ce425a8f6b195c658b.zip chromium_src-89c9aca0f74519e281f1a0ce425a8f6b195c658b.tar.gz chromium_src-89c9aca0f74519e281f1a0ce425a8f6b195c658b.tar.bz2 |
content: convert zoom notifications to callbacks
BUG=170921
Review URL: https://codereview.chromium.org/12039058
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@181307 0039d316-1c4b-4281-b951-d872f2087c98
21 files changed, 284 insertions, 213 deletions
diff --git a/chrome/browser/profiles/off_the_record_profile_impl.cc b/chrome/browser/profiles/off_the_record_profile_impl.cc index ce72d61..87f30a2 100644 --- a/chrome/browser/profiles/off_the_record_profile_impl.cc +++ b/chrome/browser/profiles/off_the_record_profile_impl.cc @@ -44,8 +44,6 @@ #include "chrome/common/render_messages.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/host_zoom_map.h" -#include "content/public/browser/notification_service.h" -#include "content/public/browser/notification_types.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/storage_partition.h" #include "content/public/browser/url_data_source.h" @@ -87,7 +85,9 @@ OffTheRecordProfileImpl::OffTheRecordProfileImpl(Profile* real_profile) : profile_(real_profile), prefs_(real_profile->GetOffTheRecordPrefs()), ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)), - start_time_(Time::Now()) { + start_time_(Time::Now()), + zoom_callback_(base::Bind(&OffTheRecordProfileImpl::OnZoomLevelChanged, + base::Unretained(this))) { } void OffTheRecordProfileImpl::Init() { @@ -129,6 +129,9 @@ void OffTheRecordProfileImpl::Init() { OffTheRecordProfileImpl::~OffTheRecordProfileImpl() { MaybeSendDestroyedNotification(); + HostZoomMap::GetForBrowserContext(profile_)->RemoveZoomLevelChangedCallback( + zoom_callback_); + #if defined(ENABLE_PLUGINS) ChromePluginServiceFilter::GetInstance()->UnregisterResourceContext( io_data_.GetResourceContextNoInit()); @@ -165,8 +168,7 @@ void OffTheRecordProfileImpl::InitHostZoomMap() { host_zoom_map->CopyFrom(parent_host_zoom_map); // Observe parent's HZM change for propagating change of parent's // change to this HZM. - registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, - content::Source<HostZoomMap>(parent_host_zoom_map)); + parent_host_zoom_map->AddZoomLevelChangedCallback(zoom_callback_); } #if defined(OS_ANDROID) @@ -428,23 +430,6 @@ GURL OffTheRecordProfileImpl::GetHomePage() { return profile_->GetHomePage(); } -void OffTheRecordProfileImpl::Observe( - int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - if (type == content::NOTIFICATION_ZOOM_LEVEL_CHANGED) { - const std::string& host = - *(content::Details<const std::string>(details).ptr()); - if (!host.empty()) { - HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this); - HostZoomMap* parent_host_zoom_map = - HostZoomMap::GetForBrowserContext(profile_); - double level = parent_host_zoom_map->GetZoomLevel(host); - host_zoom_map->SetZoomLevel(host, level); - } - } -} - #if defined(OS_CHROMEOS) // Special case of the OffTheRecordProfileImpl which is used while Guest // session in CrOS. @@ -476,3 +461,14 @@ Profile* Profile::CreateOffTheRecordProfile() { profile->Init(); return profile; } + +void OffTheRecordProfileImpl::OnZoomLevelChanged(const std::string& host) { + if (host.empty()) + return; + + HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this); + HostZoomMap* parent_host_zoom_map = + HostZoomMap::GetForBrowserContext(profile_); + double level = parent_host_zoom_map->GetZoomLevel(host); + host_zoom_map->SetZoomLevel(host, level); +} diff --git a/chrome/browser/profiles/off_the_record_profile_impl.h b/chrome/browser/profiles/off_the_record_profile_impl.h index 3066eae..8b659bd 100644 --- a/chrome/browser/profiles/off_the_record_profile_impl.h +++ b/chrome/browser/profiles/off_the_record_profile_impl.h @@ -11,8 +11,7 @@ #include "chrome/browser/profiles/off_the_record_profile_io_data.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser_list.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" +#include "content/public/browser/host_zoom_map.h" using base::Time; using base::TimeDelta; @@ -26,8 +25,7 @@ using base::TimeDelta; // Providing this header file is for unit testing. // //////////////////////////////////////////////////////////////////////////////// -class OffTheRecordProfileImpl : public Profile, - public content::NotificationObserver { +class OffTheRecordProfileImpl : public Profile { public: explicit OffTheRecordProfileImpl(Profile* real_profile); virtual ~OffTheRecordProfileImpl(); @@ -105,11 +103,6 @@ class OffTheRecordProfileImpl : public Profile, GetSpeechRecognitionPreferences() OVERRIDE; virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE; - // content::NotificationObserver implementation. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; - private: FRIEND_TEST_ALL_PREFIXES(OffTheRecordProfileImplTest, GetHostZoomMap); void InitHostZoomMap(); @@ -118,7 +111,7 @@ class OffTheRecordProfileImpl : public Profile, void UseSystemProxy(); #endif - content::NotificationRegistrar registrar_; + void OnZoomLevelChanged(const std::string& host); // The real underlying profile. Profile* profile_; @@ -138,6 +131,8 @@ class OffTheRecordProfileImpl : public Profile, scoped_ptr<PrefProxyConfigTracker> pref_proxy_config_tracker_; + content::HostZoomMap::ZoomLevelChangedCallback zoom_callback_; + DISALLOW_COPY_AND_ASSIGN(OffTheRecordProfileImpl); }; diff --git a/chrome/browser/profiles/off_the_record_profile_impl_unittest.cc b/chrome/browser/profiles/off_the_record_profile_impl_unittest.cc index b8572c5..4bd5c2b 100644 --- a/chrome/browser/profiles/off_the_record_profile_impl_unittest.cc +++ b/chrome/browser/profiles/off_the_record_profile_impl_unittest.cc @@ -16,24 +16,25 @@ #include "chrome/test/base/testing_pref_service.h" #include "chrome/test/base/testing_profile.h" #include "content/public/browser/host_zoom_map.h" -#include "content/public/browser/notification_details.h" -#include "content/public/browser/notification_source.h" -#include "content/public/browser/notification_types.h" using content::HostZoomMap; namespace { -class TestingProfileWithHostZoomMap : public TestingProfile, - public content::NotificationObserver { +class TestingProfileWithHostZoomMap : public TestingProfile { public: - TestingProfileWithHostZoomMap() { - HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this); - registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, - content::Source<HostZoomMap>(host_zoom_map)); + TestingProfileWithHostZoomMap() + : zoom_callback_( + base::Bind(&TestingProfileWithHostZoomMap::OnZoomLevelChanged, + base::Unretained(this))) { + HostZoomMap::GetForBrowserContext(this)->AddZoomLevelChangedCallback( + zoom_callback_); } - virtual ~TestingProfileWithHostZoomMap() {} + virtual ~TestingProfileWithHostZoomMap() { + HostZoomMap::GetForBrowserContext(this)->RemoveZoomLevelChangedCallback( + zoom_callback_); + } virtual Profile* GetOffTheRecordProfile() OVERRIDE { if (!off_the_record_profile_.get()) @@ -45,12 +46,8 @@ class TestingProfileWithHostZoomMap : public TestingProfile, return GetPrefs(); } - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE { - const std::string& host = - *(content::Details<const std::string>(details).ptr()); - DCHECK(type == content::NOTIFICATION_ZOOM_LEVEL_CHANGED); + private: + void OnZoomLevelChanged(const std::string& host) { if (host.empty()) return; @@ -66,11 +63,11 @@ class TestingProfileWithHostZoomMap : public TestingProfile, } } - private: - content::NotificationRegistrar registrar_; scoped_ptr<Profile> off_the_record_profile_; scoped_ptr<SSLConfigServiceManager> ssl_config_service_manager_; + content::HostZoomMap::ZoomLevelChangedCallback zoom_callback_; + DISALLOW_COPY_AND_ASSIGN(TestingProfileWithHostZoomMap); }; @@ -138,7 +135,7 @@ TEST_F(OffTheRecordProfileImplTest, GetHostZoomMap) { ASSERT_EQ(parent_zoom_map->GetZoomLevel(host), zoom_level_25); // TODO(yosin) We need to wait ProfileImpl::Observe done for - // NOTIFICATION_ZOOM_LEVEL_CHANGED. + // OnZoomLevelChanged. // Prepare child profile as off the record profile. scoped_ptr<OffTheRecordProfileImpl> child_profile( diff --git a/chrome/browser/profiles/profile_impl.cc b/chrome/browser/profiles/profile_impl.cc index ddb9b5a..06716b8 100644 --- a/chrome/browser/profiles/profile_impl.cc +++ b/chrome/browser/profiles/profile_impl.cc @@ -322,7 +322,9 @@ ProfileImpl::ProfileImpl( Delegate* delegate, CreateMode create_mode, base::SequencedTaskRunner* sequenced_task_runner) - : path_(path), + : zoom_callback_(base::Bind(&ProfileImpl::OnZoomLevelChanged, + base::Unretained(this))), + path_(path), ALLOW_THIS_IN_INITIALIZER_LIST(io_data_(this)), host_content_settings_map_(NULL), last_session_exit_type_(EXIT_NORMAL), @@ -567,8 +569,7 @@ void ProfileImpl::InitHostZoomMap() { } } - registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, - content::Source<HostZoomMap>(host_zoom_map)); + host_zoom_map->AddZoomLevelChangedCallback(zoom_callback_); } FilePath ProfileImpl::last_selected_directory() { @@ -582,6 +583,9 @@ void ProfileImpl::set_last_selected_directory(const FilePath& path) { ProfileImpl::~ProfileImpl() { MaybeSendDestroyedNotification(); + HostZoomMap::GetForBrowserContext(this)->RemoveZoomLevelChangedCallback( + zoom_callback_); + bool prefs_loaded = prefs_->GetInitializationStatus() != PrefService::INITIALIZATION_STATUS_WAITING; @@ -930,23 +934,6 @@ void ProfileImpl::Observe(int type, registrar_.Remove(this, chrome::NOTIFICATION_BOOKMARK_MODEL_LOADED, content::Source<Profile>(this)); break; - case content::NOTIFICATION_ZOOM_LEVEL_CHANGED: { - const std::string& host = - *(content::Details<const std::string>(details).ptr()); - if (!host.empty()) { - HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this); - double level = host_zoom_map->GetZoomLevel(host); - DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); - DictionaryValue* host_zoom_dictionary = update.Get(); - if (level == host_zoom_map->GetDefaultZoomLevel()) { - host_zoom_dictionary->RemoveWithoutPathExpansion(host, NULL); - } else { - host_zoom_dictionary->SetWithoutPathExpansion( - host, Value::CreateDoubleValue(level)); - } - } - break; - } default: NOTREACHED(); } @@ -957,6 +944,21 @@ void ProfileImpl::OnDefaultZoomLevelChanged() { pref_change_registrar_.prefs()->GetDouble(prefs::kDefaultZoomLevel)); } +void ProfileImpl::OnZoomLevelChanged(const std::string& host) { + if (host.empty()) + return; + HostZoomMap* host_zoom_map = HostZoomMap::GetForBrowserContext(this); + double level = host_zoom_map->GetZoomLevel(host); + DictionaryPrefUpdate update(prefs_.get(), prefs::kPerHostZoomLevels); + DictionaryValue* host_zoom_dictionary = update.Get(); + if (level == host_zoom_map->GetDefaultZoomLevel()) { + host_zoom_dictionary->RemoveWithoutPathExpansion(host, NULL); + } else { + host_zoom_dictionary->SetWithoutPathExpansion( + host, Value::CreateDoubleValue(level)); + } +} + #if defined(ENABLE_SESSION_SERVICE) void ProfileImpl::StopCreateSessionServiceTimer() { create_session_service_timer_.Stop(); diff --git a/chrome/browser/profiles/profile_impl.h b/chrome/browser/profiles/profile_impl.h index 87d2c1d..2c81c8c 100644 --- a/chrome/browser/profiles/profile_impl.h +++ b/chrome/browser/profiles/profile_impl.h @@ -19,6 +19,7 @@ #include "chrome/browser/profiles/profile_impl_io_data.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" +#include "content/public/browser/host_zoom_map.h" class NetPrefObserver; class PrefServiceSyncable; @@ -159,6 +160,7 @@ class ProfileImpl : public Profile, void InitHostZoomMap(); void OnDefaultZoomLevelChanged(); + void OnZoomLevelChanged(const std::string& host); void OnInitializationCompleted(PrefServiceBase* pref_service, bool succeeded); @@ -190,6 +192,7 @@ class ProfileImpl : public Profile, int* max_size); content::NotificationRegistrar registrar_; + content::HostZoomMap::ZoomLevelChangedCallback zoom_callback_; PrefChangeRegistrar pref_change_registrar_; FilePath path_; diff --git a/chrome/browser/ui/browser_browsertest.cc b/chrome/browser/ui/browser_browsertest.cc index 26275a5..5ec5439 100644 --- a/chrome/browser/ui/browser_browsertest.cc +++ b/chrome/browser/ui/browser_browsertest.cc @@ -49,11 +49,10 @@ #include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/ui_test_utils.h" #include "content/public/browser/favicon_status.h" +#include "content/public/browser/host_zoom_map.h" #include "content/public/browser/interstitial_page.h" #include "content/public/browser/interstitial_page_delegate.h" #include "content/public/browser/navigation_entry.h" -#include "content/public/browser/notification_service.h" -#include "content/public/browser/notification_source.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/render_widget_host_view.h" @@ -1322,6 +1321,15 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, EXPECT_FALSE(command_updater->IsCommandEnabled(IDC_IMPORT_SETTINGS)); } +namespace { + +void OnZoomLevelChanged(const base::Closure& callback, + const std::string& host) { + callback.Run(); +} + +} // namespace + #if defined(OS_WIN) // Flakes regularly on Windows XP // http://crbug.com/146040 @@ -1333,32 +1341,53 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, MAYBE_PageZoom) { WebContents* contents = browser()->tab_strip_model()->GetActiveWebContents(); bool enable_plus, enable_minus; - content::WindowedNotificationObserver zoom_in_observer( - content::NOTIFICATION_ZOOM_LEVEL_CHANGED, - content::NotificationService::AllSources()); - chrome::Zoom(browser(), content::PAGE_ZOOM_IN); - zoom_in_observer.Wait(); - EXPECT_EQ(contents->GetZoomPercent(&enable_plus, &enable_minus), 110); - EXPECT_TRUE(enable_plus); - EXPECT_TRUE(enable_minus); - - content::WindowedNotificationObserver zoom_reset_observer( - content::NOTIFICATION_ZOOM_LEVEL_CHANGED, - content::NotificationService::AllSources()); - chrome::Zoom(browser(), content::PAGE_ZOOM_RESET); - zoom_reset_observer.Wait(); - EXPECT_EQ(contents->GetZoomPercent(&enable_plus, &enable_minus), 100); - EXPECT_TRUE(enable_plus); - EXPECT_TRUE(enable_minus); + { + scoped_refptr<content::MessageLoopRunner> loop_runner( + new content::MessageLoopRunner); + content::HostZoomMap::ZoomLevelChangedCallback callback( + base::Bind(&OnZoomLevelChanged, loop_runner->QuitClosure())); + content::HostZoomMap::GetForBrowserContext( + browser()->profile())->AddZoomLevelChangedCallback(callback); + chrome::Zoom(browser(), content::PAGE_ZOOM_IN); + loop_runner->Run(); + content::HostZoomMap::GetForBrowserContext( + browser()->profile())->RemoveZoomLevelChangedCallback(callback); + EXPECT_EQ(contents->GetZoomPercent(&enable_plus, &enable_minus), 110); + EXPECT_TRUE(enable_plus); + EXPECT_TRUE(enable_minus); + } - content::WindowedNotificationObserver zoom_out_observer( - content::NOTIFICATION_ZOOM_LEVEL_CHANGED, - content::NotificationService::AllSources()); - chrome::Zoom(browser(), content::PAGE_ZOOM_OUT); - zoom_out_observer.Wait(); - EXPECT_EQ(contents->GetZoomPercent(&enable_plus, &enable_minus), 90); - EXPECT_TRUE(enable_plus); - EXPECT_TRUE(enable_minus); + { + scoped_refptr<content::MessageLoopRunner> loop_runner( + new content::MessageLoopRunner); + content::HostZoomMap::ZoomLevelChangedCallback callback( + base::Bind(&OnZoomLevelChanged, loop_runner->QuitClosure())); + content::HostZoomMap::GetForBrowserContext( + browser()->profile())->AddZoomLevelChangedCallback(callback); + chrome::Zoom(browser(), content::PAGE_ZOOM_RESET); + loop_runner->Run(); + content::HostZoomMap::GetForBrowserContext( + browser()->profile())->RemoveZoomLevelChangedCallback(callback); + EXPECT_EQ(contents->GetZoomPercent(&enable_plus, &enable_minus), 100); + EXPECT_TRUE(enable_plus); + EXPECT_TRUE(enable_minus); + } + + { + scoped_refptr<content::MessageLoopRunner> loop_runner( + new content::MessageLoopRunner); + content::HostZoomMap::ZoomLevelChangedCallback callback( + base::Bind(&OnZoomLevelChanged, loop_runner->QuitClosure())); + content::HostZoomMap::GetForBrowserContext( + browser()->profile())->AddZoomLevelChangedCallback(callback); + chrome::Zoom(browser(), content::PAGE_ZOOM_OUT); + loop_runner->Run(); + content::HostZoomMap::GetForBrowserContext( + browser()->profile())->RemoveZoomLevelChangedCallback(callback); + EXPECT_EQ(contents->GetZoomPercent(&enable_plus, &enable_minus), 90); + EXPECT_TRUE(enable_plus); + EXPECT_TRUE(enable_minus); + } chrome::Zoom(browser(), content::PAGE_ZOOM_RESET); } diff --git a/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.mm b/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.mm index bb87814..8f1cc87 100644 --- a/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.mm +++ b/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller.mm @@ -22,11 +22,6 @@ #import "chrome/browser/ui/cocoa/wrench_menu/recent_tabs_menu_model_delegate.h" #include "chrome/browser/ui/toolbar/recent_tabs_sub_menu_model.h" #include "chrome/browser/ui/toolbar/wrench_menu_model.h" -#include "content/public/browser/host_zoom_map.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_service.h" -#include "content/public/browser/notification_source.h" -#include "content/public/browser/notification_types.h" #include "content/public/browser/user_metrics.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" @@ -64,35 +59,36 @@ class AcceleratorDelegate : public ui::AcceleratorProvider { } }; -class ZoomLevelObserver : public content::NotificationObserver { +class ZoomLevelObserver { public: - explicit ZoomLevelObserver(WrenchMenuController* controller) - : controller_(controller) { - registrar_.Add( - this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, - content::NotificationService::AllBrowserContextsAndSources()); + ZoomLevelObserver(WrenchMenuController* controller, + content::HostZoomMap* map) + : callback_(base::Bind(&ZoomLevelObserver::OnZoomLevelChanged, + base::Unretained(this))), + controller_(controller), + map_(map) { + map_->AddZoomLevelChangedCallback(callback_); } - void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - DCHECK_EQ(type, content::NOTIFICATION_ZOOM_LEVEL_CHANGED); - WrenchMenuModel* wrenchMenuModel = [controller_ wrenchMenuModel]; - if (HostZoomMap::GetForBrowserContext( - wrenchMenuModel->browser()->profile()) != - content::Source<HostZoomMap>(source).ptr()) { - return; - } + ~ZoomLevelObserver() { + map_->RemoveZoomLevelChangedCallback(callback_); + } + private: + void OnZoomLevelChanged(const std::string& host) { + WrenchMenuModel* wrenchMenuModel = [controller_ wrenchMenuModel]; wrenchMenuModel->UpdateZoomControls(); const string16 level = wrenchMenuModel->GetLabelForCommandId(IDC_ZOOM_PERCENT_DISPLAY); [[controller_ zoomDisplay] setTitle:SysUTF16ToNSString(level)]; } - private: - content::NotificationRegistrar registrar_; + content::HostZoomMap::ZoomLevelChangedCallback callback_; + WrenchMenuController* controller_; // Weak; owns this. + content::HostZoomMap* map_; // Weak. + + DISALLOW_COPY_AND_ASSIGN(ZoomLevelObserver); }; } // namespace WrenchMenuControllerInternal @@ -102,7 +98,8 @@ class ZoomLevelObserver : public content::NotificationObserver { - (id)initWithBrowser:(Browser*)browser { if ((self = [super init])) { browser_ = browser; - observer_.reset(new WrenchMenuControllerInternal::ZoomLevelObserver(self)); + observer_.reset(new WrenchMenuControllerInternal::ZoomLevelObserver( + self, content::HostZoomMap::GetForBrowserContext(browser->profile()))); acceleratorDelegate_.reset( new WrenchMenuControllerInternal::AcceleratorDelegate()); [self createModel]; diff --git a/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller_unittest.mm b/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller_unittest.mm index f4f351b..a9aa99f 100644 --- a/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller_unittest.mm +++ b/chrome/browser/ui/cocoa/wrench_menu/wrench_menu_controller_unittest.mm @@ -44,7 +44,7 @@ class MockWrenchMenuModel : public WrenchMenuModel { class WrenchMenuControllerTest : public CocoaProfileTest { public: - virtual void SetUp() { + virtual void SetUp() OVERRIDE { CocoaProfileTest::SetUp(); ASSERT_TRUE(browser()); @@ -52,6 +52,12 @@ class WrenchMenuControllerTest : public CocoaProfileTest { fake_model_.reset(new MockWrenchMenuModel); } + virtual void TearDown() OVERRIDE { + fake_model_.reset(); + controller_.reset(); + CocoaProfileTest::TearDown(); + } + WrenchMenuController* controller() { return controller_.get(); } diff --git a/chrome/browser/ui/gtk/browser_toolbar_gtk.cc b/chrome/browser/ui/gtk/browser_toolbar_gtk.cc index 11e1b2b..45b4581 100644 --- a/chrome/browser/ui/gtk/browser_toolbar_gtk.cc +++ b/chrome/browser/ui/gtk/browser_toolbar_gtk.cc @@ -99,7 +99,9 @@ BrowserToolbarGtk::BrowserToolbarGtk(Browser* browser, BrowserWindowGtk* window) model_(browser->toolbar_model()), is_wrench_menu_model_valid_(true), browser_(browser), - window_(window) { + window_(window), + zoom_callback_(base::Bind(&BrowserToolbarGtk::OnZoomLevelChanged, + base::Unretained(this))) { wrench_menu_model_.reset(new WrenchMenuModel(this, browser_, false, false)); chrome::AddCommandObserver(browser_, IDC_BACK, this); @@ -124,6 +126,9 @@ BrowserToolbarGtk::~BrowserToolbarGtk() { offscreen_entry_.Destroy(); wrench_menu_.reset(); + + HostZoomMap::GetForBrowserContext( + browser()->profile())->RemoveZoomLevelChangedCallback(zoom_callback_); } void BrowserToolbarGtk::Init(GtkWindow* top_level_window) { @@ -241,9 +246,8 @@ void BrowserToolbarGtk::Init(GtkWindow* top_level_window) { // The bookmark menu model needs to be able to force the wrench menu to close. wrench_menu_model_->bookmark_sub_menu_model()->SetMenuGtk(wrench_menu_.get()); - registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, - content::Source<HostZoomMap>( - HostZoomMap::GetForBrowserContext(profile))); + HostZoomMap::GetForBrowserContext( + browser()->profile())->AddZoomLevelChangedCallback(zoom_callback_); if (ShouldOnlyShowLocation()) { gtk_widget_show(event_box_); @@ -416,18 +420,6 @@ void BrowserToolbarGtk::Observe(int type, } else if (type == chrome::NOTIFICATION_GLOBAL_ERRORS_CHANGED) { is_wrench_menu_model_valid_ = false; gtk_widget_queue_draw(wrench_menu_button_->widget()); - } else if (type == content::NOTIFICATION_ZOOM_LEVEL_CHANGED) { - // Since BrowserToolbarGtk create a new |wrench_menu_model_| in - // RebuildWrenchMenu(), the ordering of the observers of - // NOTIFICATION_ZOOM_LEVEL_CHANGED can change, and result in subtle bugs - // like http://crbug.com/118823. Rather than depending on the ordering - // of the notification observers, always update the WrenchMenuModel before - // updating the WrenchMenu. - wrench_menu_model_->UpdateZoomControls(); - - // If our zoom level changed, we need to tell the menu to update its state, - // since the menu could still be open. - wrench_menu_->UpdateMenu(); } else { NOTREACHED(); } @@ -449,6 +441,20 @@ bool BrowserToolbarGtk::IsWrenchMenuShowing() const { // BrowserToolbarGtk, private -------------------------------------------------- +void BrowserToolbarGtk::OnZoomLevelChanged(const std::string& host) { + // Since BrowserToolbarGtk create a new |wrench_menu_model_| in + // RebuildWrenchMenu(), the ordering of the observers of HostZoomMap + // can change, and result in subtle bugs like http://crbug.com/118823. + // Rather than depending on the ordering of the observers, always update + // the WrenchMenuModel before updating the WrenchMenu. + wrench_menu_model_->UpdateZoomControls(); + + // If our zoom level changed, we need to tell the menu to update its state, + // since the menu could still be open. + wrench_menu_->UpdateMenu(); +} + + void BrowserToolbarGtk::SetUpDragForHomeButton() { if (!home_page_.IsManaged() && !home_page_is_new_tab_page_.IsManaged()) { gtk_drag_dest_set(home_->widget(), GTK_DEST_DEFAULT_ALL, diff --git a/chrome/browser/ui/gtk/browser_toolbar_gtk.h b/chrome/browser/ui/gtk/browser_toolbar_gtk.h index 932d142..e988156 100644 --- a/chrome/browser/ui/gtk/browser_toolbar_gtk.h +++ b/chrome/browser/ui/gtk/browser_toolbar_gtk.h @@ -15,6 +15,7 @@ #include "chrome/browser/ui/gtk/custom_button.h" #include "chrome/browser/ui/gtk/menu_gtk.h" #include "chrome/browser/ui/toolbar/wrench_menu_model.h" +#include "content/public/browser/host_zoom_map.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "ui/base/accelerators/accelerator.h" @@ -112,6 +113,8 @@ class BrowserToolbarGtk : public CommandObserver, bool should_restore_state); private: + void OnZoomLevelChanged(const std::string& host); + // Connect/Disconnect signals for dragging a url onto the home button. void SetUpDragForHomeButton(); @@ -211,6 +214,7 @@ class BrowserToolbarGtk : public CommandObserver, StringPrefMember home_page_; BooleanPrefMember home_page_is_new_tab_page_; + content::HostZoomMap::ZoomLevelChangedCallback zoom_callback_; content::NotificationRegistrar registrar_; // A GtkEntry that isn't part of the hierarchy. We keep this for native diff --git a/chrome/browser/ui/gtk/location_bar_view_gtk_browsertest.cc b/chrome/browser/ui/gtk/location_bar_view_gtk_browsertest.cc index 770f56e..5c53cf5 100644 --- a/chrome/browser/ui/gtk/location_bar_view_gtk_browsertest.cc +++ b/chrome/browser/ui/gtk/location_bar_view_gtk_browsertest.cc @@ -5,6 +5,7 @@ #include <gtk/gtk.h> #include "base/string_number_conversions.h" +#include "chrome/browser/profiles/profile.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/browser_window.h" @@ -16,6 +17,7 @@ #include "chrome/browser/ui/zoom/zoom_controller.h" #include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/ui_test_utils.h" +#include "content/public/browser/host_zoom_map.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_types.h" #include "content/public/browser/web_contents.h" @@ -44,8 +46,13 @@ void ExpectAtDefaultZoom(content::WebContents* contents) { EXPECT_EQ(GetZoomPercent(contents), 100); } +void OnZoomLevelChanged(const base::Closure& callback, + const std::string& host) { + callback.Run(); } +} // namespace + class LocationBarViewGtkZoomTest : public InProcessBrowserTest { public: LocationBarViewGtkZoomTest() {} @@ -101,11 +108,16 @@ class LocationBarViewGtkZoomTest : public InProcessBrowserTest { } void WaitForZoom(content::PageZoom zoom_action) { - content::WindowedNotificationObserver zoom_observer( - content::NOTIFICATION_ZOOM_LEVEL_CHANGED, - content::NotificationService::AllSources()); + scoped_refptr<content::MessageLoopRunner> loop_runner( + new content::MessageLoopRunner); + content::HostZoomMap::ZoomLevelChangedCallback callback( + base::Bind(&OnZoomLevelChanged, loop_runner->QuitClosure())); + content::HostZoomMap::GetForBrowserContext( + browser()->profile())->AddZoomLevelChangedCallback(callback); chrome::Zoom(browser(), zoom_action); - zoom_observer.Wait(); + loop_runner->Run(); + content::HostZoomMap::GetForBrowserContext( + browser()->profile())->RemoveZoomLevelChangedCallback(callback); } DISALLOW_COPY_AND_ASSIGN(LocationBarViewGtkZoomTest); diff --git a/chrome/browser/ui/toolbar/wrench_menu_model.cc b/chrome/browser/ui/toolbar/wrench_menu_model.cc index 6956729..c24ce72 100644 --- a/chrome/browser/ui/toolbar/wrench_menu_model.cc +++ b/chrome/browser/ui/toolbar/wrench_menu_model.cc @@ -212,16 +212,17 @@ WrenchMenuModel::WrenchMenuModel(ui::AcceleratorProvider* provider, : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)), provider_(provider), browser_(browser), - tab_strip_model_(browser_->tab_strip_model()) { + tab_strip_model_(browser_->tab_strip_model()), + zoom_callback_(base::Bind(&WrenchMenuModel::OnZoomLevelChanged, + base::Unretained(this))) { Build(is_new_menu, supports_new_separators); UpdateZoomControls(); + HostZoomMap::GetForBrowserContext( + browser->profile())->AddZoomLevelChangedCallback(zoom_callback_); + tab_strip_model_->AddObserver(this); - registrar_.Add( - this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, - content::Source<HostZoomMap>( - HostZoomMap::GetForBrowserContext(browser_->profile()))); registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, content::NotificationService::AllSources()); } @@ -229,6 +230,11 @@ WrenchMenuModel::WrenchMenuModel(ui::AcceleratorProvider* provider, WrenchMenuModel::~WrenchMenuModel() { if (tab_strip_model_) tab_strip_model_->RemoveObserver(this); + + if (browser()) { + HostZoomMap::GetForBrowserContext( + browser()->profile())->RemoveZoomLevelChangedCallback(zoom_callback_); + } } bool WrenchMenuModel::DoesCommandIdDismissMenu(int command_id) const { @@ -421,14 +427,8 @@ void WrenchMenuModel::TabStripModelDeleted() { void WrenchMenuModel::Observe(int type, const content::NotificationSource& source, const content::NotificationDetails& details) { - switch (type) { - case content::NOTIFICATION_ZOOM_LEVEL_CHANGED: - case content::NOTIFICATION_NAV_ENTRY_COMMITTED: - UpdateZoomControls(); - break; - default: - NOTREACHED(); - } + DCHECK(type == content::NOTIFICATION_NAV_ENTRY_COMMITTED); + UpdateZoomControls(); } // For testing. @@ -697,3 +697,7 @@ void WrenchMenuModel::UpdateZoomControls() { zoom_label_ = l10n_util::GetStringFUTF16( IDS_ZOOM_PERCENT, base::IntToString16(zoom_percent)); } + +void WrenchMenuModel::OnZoomLevelChanged(const std::string& host) { + UpdateZoomControls(); +} diff --git a/chrome/browser/ui/toolbar/wrench_menu_model.h b/chrome/browser/ui/toolbar/wrench_menu_model.h index 21bbdc2..b78ab62 100644 --- a/chrome/browser/ui/toolbar/wrench_menu_model.h +++ b/chrome/browser/ui/toolbar/wrench_menu_model.h @@ -8,6 +8,7 @@ #include "base/file_path.h" #include "base/memory/scoped_ptr.h" #include "chrome/browser/ui/tabs/tab_strip_model_observer.h" +#include "content/public/browser/host_zoom_map.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "ui/base/accelerators/accelerator.h" @@ -147,6 +148,8 @@ class WrenchMenuModel : public ui::SimpleMenuModel, // |new_menu| should be set to true. void CreateZoomMenu(bool new_menu); + void OnZoomLevelChanged(const std::string& host); + // Models for the special menu items with buttons. scoped_ptr<ui::ButtonMenuItemModel> edit_menu_item_model_; scoped_ptr<ui::ButtonMenuItemModel> zoom_menu_item_model_; @@ -168,6 +171,7 @@ class WrenchMenuModel : public ui::SimpleMenuModel, Browser* browser_; // weak TabStripModel* tab_strip_model_; // weak + content::HostZoomMap::ZoomLevelChangedCallback zoom_callback_; content::NotificationRegistrar registrar_; DISALLOW_COPY_AND_ASSIGN(WrenchMenuModel); diff --git a/chrome/browser/ui/views/wrench_menu.cc b/chrome/browser/ui/views/wrench_menu.cc index c7b65df..2b2ad2a 100644 --- a/chrome/browser/ui/views/wrench_menu.cc +++ b/chrome/browser/ui/views/wrench_menu.cc @@ -480,8 +480,7 @@ static const int kTouchZoomPadding = 14; // ZoomView contains the various zoom controls: two buttons to increase/decrease // the zoom, a label showing the current zoom percent, and a button to go // full-screen. -class WrenchMenu::ZoomView : public WrenchMenuView, - public content::NotificationObserver { +class WrenchMenu::ZoomView : public WrenchMenuView { public: ZoomView(WrenchMenu* menu, MenuModel* menu_model, @@ -490,11 +489,17 @@ class WrenchMenu::ZoomView : public WrenchMenuView, int fullscreen_index) : WrenchMenuView(menu, menu_model), fullscreen_index_(fullscreen_index), + zoom_callback_(base::Bind(&WrenchMenu::ZoomView::OnZoomLevelChanged, + base::Unretained(this))), increment_button_(NULL), zoom_label_(NULL), decrement_button_(NULL), fullscreen_button_(NULL), zoom_label_width_(0) { + HostZoomMap::GetForBrowserContext( + menu_->browser_->profile())->AddZoomLevelChangedCallback( + zoom_callback_); + decrement_button_ = CreateButtonWithAccName( IDS_ZOOM_MINUS2, MenuButtonBackground::LEFT_BUTTON, decrement_index, NULL, IDS_ACCNAME_ZOOM_MINUS2); @@ -555,11 +560,12 @@ class WrenchMenu::ZoomView : public WrenchMenuView, AddChildView(fullscreen_button_); UpdateZoomControls(); + } - registrar_.Add( - this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, - content::Source<HostZoomMap>( - HostZoomMap::GetForBrowserContext(menu->browser_->profile()))); + ~ZoomView() { + HostZoomMap::GetForBrowserContext( + menu_->browser_->profile())->RemoveZoomLevelChangedCallback( + zoom_callback_); } // Overridden from View. @@ -613,15 +619,11 @@ class WrenchMenu::ZoomView : public WrenchMenuView, } } - // Overridden from content::NotificationObserver. - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE { - DCHECK_EQ(content::NOTIFICATION_ZOOM_LEVEL_CHANGED, type); + private: + void OnZoomLevelChanged(const std::string& host) { UpdateZoomControls(); } - private: void UpdateZoomControls() { bool enable_increment = false; bool enable_decrement = false; @@ -669,6 +671,7 @@ class WrenchMenu::ZoomView : public WrenchMenuView, // Index of the fullscreen menu item in the model. const int fullscreen_index_; + content::HostZoomMap::ZoomLevelChangedCallback zoom_callback_; content::NotificationRegistrar registrar_; // Button for incrementing the zoom. diff --git a/chrome/browser/ui/zoom/zoom_controller.cc b/chrome/browser/ui/zoom/zoom_controller.cc index d17864f..4b9c041 100644 --- a/chrome/browser/ui/zoom/zoom_controller.cc +++ b/chrome/browser/ui/zoom/zoom_controller.cc @@ -24,7 +24,10 @@ DEFINE_WEB_CONTENTS_USER_DATA_KEY(ZoomController); ZoomController::ZoomController(content::WebContents* web_contents) : content::WebContentsObserver(web_contents), zoom_percent_(100), - observer_(NULL) { + observer_(NULL), + browser_context_(web_contents->GetBrowserContext()), + zoom_callback_(base::Bind(&ZoomController::OnZoomLevelChanged, + base::Unretained(this))) { Profile* profile = Profile::FromBrowserContext(web_contents->GetBrowserContext()); default_zoom_level_.Init(prefs::kDefaultZoomLevel, profile->GetPrefs(), @@ -32,15 +35,18 @@ ZoomController::ZoomController(content::WebContents* web_contents) base::Unretained(this), std::string())); - content::HostZoomMap* zoom_map = - content::HostZoomMap::GetForBrowserContext(profile); - registrar_.Add(this, content::NOTIFICATION_ZOOM_LEVEL_CHANGED, - content::Source<content::HostZoomMap>(zoom_map)); + content::HostZoomMap::GetForBrowserContext( + browser_context_)->AddZoomLevelChangedCallback( + zoom_callback_); UpdateState(std::string()); } -ZoomController::~ZoomController() {} +ZoomController::~ZoomController() { + content::HostZoomMap::GetForBrowserContext( + browser_context_)->RemoveZoomLevelChangedCallback( + zoom_callback_); +} bool ZoomController::IsAtDefaultZoom() const { return content::ZoomValuesEqual(web_contents()->GetZoomLevel(), @@ -61,11 +67,8 @@ void ZoomController::DidNavigateMainFrame( UpdateState(std::string()); } -void ZoomController::Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) { - DCHECK_EQ(content::NOTIFICATION_ZOOM_LEVEL_CHANGED, type); - UpdateState(*content::Details<std::string>(details).ptr()); +void ZoomController::OnZoomLevelChanged(const std::string& host) { + UpdateState(host); } void ZoomController::UpdateState(const std::string& host) { diff --git a/chrome/browser/ui/zoom/zoom_controller.h b/chrome/browser/ui/zoom/zoom_controller.h index 1dd7809..2dda110 100644 --- a/chrome/browser/ui/zoom/zoom_controller.h +++ b/chrome/browser/ui/zoom/zoom_controller.h @@ -8,8 +8,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" #include "base/prefs/public/pref_member.h" -#include "content/public/browser/notification_observer.h" -#include "content/public/browser/notification_registrar.h" +#include "content/public/browser/host_zoom_map.h" #include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_user_data.h" @@ -20,8 +19,7 @@ class WebContents; } // Per-tab class to manage the Omnibox zoom icon. -class ZoomController : public content::NotificationObserver, - public content::WebContentsObserver, +class ZoomController : public content::WebContentsObserver, public content::WebContentsUserData<ZoomController> { public: virtual ~ZoomController(); @@ -41,16 +39,13 @@ class ZoomController : public content::NotificationObserver, const content::LoadCommittedDetails& details, const content::FrameNavigateParams& params) OVERRIDE; - // content::NotificationObserver overrides: - virtual void Observe(int type, - const content::NotificationSource& source, - const content::NotificationDetails& details) OVERRIDE; - private: explicit ZoomController(content::WebContents* web_contents); friend class content::WebContentsUserData<ZoomController>; friend class ZoomControllerTest; + void OnZoomLevelChanged(const std::string& host); + // Updates the zoom icon and zoom percentage based on current values and // notifies the observer if changes have occurred. |host| may be empty, // meaning the change should apply to ~all sites. If it is not empty, the @@ -60,14 +55,16 @@ class ZoomController : public content::NotificationObserver, // The current zoom percentage. int zoom_percent_; - content::NotificationRegistrar registrar_; - // Used to access the default zoom level preference. DoublePrefMember default_zoom_level_; // Observer receiving notifications on state changes. ZoomObserver* observer_; + content::BrowserContext* browser_context_; + + content::HostZoomMap::ZoomLevelChangedCallback zoom_callback_; + DISALLOW_COPY_AND_ASSIGN(ZoomController); }; diff --git a/chrome/browser/ui/zoom/zoom_controller_unittest.cc b/chrome/browser/ui/zoom/zoom_controller_unittest.cc index cc5be54..f96cfb7 100644 --- a/chrome/browser/ui/zoom/zoom_controller_unittest.cc +++ b/chrome/browser/ui/zoom/zoom_controller_unittest.cc @@ -14,9 +14,6 @@ #include "content/public/browser/browser_thread.h" #include "content/public/browser/host_zoom_map.h" #include "content/public/browser/navigation_details.h" -#include "content/public/browser/notification_details.h" -#include "content/public/browser/notification_source.h" -#include "content/public/browser/notification_types.h" #include "content/public/common/frame_navigate_params.h" #include "content/public/test/test_browser_thread.h" #include "content/public/test/test_utils.h" @@ -71,11 +68,5 @@ TEST_F(ZoomControllerTest, Observe) { content::HostZoomMap::GetForBrowserContext( web_contents()->GetBrowserContext()); - content::WindowedNotificationObserver notification_observer( - content::NOTIFICATION_ZOOM_LEVEL_CHANGED, - content::NotificationService::AllSources()); - host_zoom_map->SetZoomLevel(std::string(), 110.0f); - - notification_observer.Wait(); } diff --git a/content/browser/host_zoom_map_impl.cc b/content/browser/host_zoom_map_impl.cc index 942d6f4..aa5a870 100644 --- a/content/browser/host_zoom_map_impl.cc +++ b/content/browser/host_zoom_map_impl.cc @@ -90,10 +90,8 @@ void HostZoomMapImpl::SetZoomLevel(const std::string& host, double level) { } } - NotificationService::current()->Notify( - NOTIFICATION_ZOOM_LEVEL_CHANGED, - Source<HostZoomMap>(this), - Details<const std::string>(&host)); + for (size_t i = 0; i < zoom_level_changed_callbacks_.size(); i++) + zoom_level_changed_callbacks_[i].Run(host); } double HostZoomMapImpl::GetDefaultZoomLevel() const { @@ -104,6 +102,22 @@ void HostZoomMapImpl::SetDefaultZoomLevel(double level) { default_zoom_level_ = level; } +void HostZoomMapImpl::AddZoomLevelChangedCallback( + const ZoomLevelChangedCallback& callback) { + zoom_level_changed_callbacks_.push_back(callback); +} + +void HostZoomMapImpl::RemoveZoomLevelChangedCallback( + const ZoomLevelChangedCallback& callback) { + for (size_t i = 0; i < zoom_level_changed_callbacks_.size(); i++) { + if (zoom_level_changed_callbacks_[i].Equals(callback)) { + zoom_level_changed_callbacks_.erase( + zoom_level_changed_callbacks_.begin() + i); + return; + } + } +} + double HostZoomMapImpl::GetTemporaryZoomLevel(int render_process_id, int render_view_id) const { base::AutoLock auto_lock(lock_); @@ -145,11 +159,8 @@ void HostZoomMapImpl::SetTemporaryZoomLevel(int render_process_id, } } - std::string host; - NotificationService::current()->Notify( - NOTIFICATION_ZOOM_LEVEL_CHANGED, - Source<HostZoomMap>(this), - Details<const std::string>(&host)); + for (size_t i = 0; i < zoom_level_changed_callbacks_.size(); i++) + zoom_level_changed_callbacks_[i].Run(std::string()); } void HostZoomMapImpl::Observe(int type, diff --git a/content/browser/host_zoom_map_impl.h b/content/browser/host_zoom_map_impl.h index 7840188..4e6eff4 100644 --- a/content/browser/host_zoom_map_impl.h +++ b/content/browser/host_zoom_map_impl.h @@ -34,6 +34,10 @@ class CONTENT_EXPORT HostZoomMapImpl : public NON_EXPORTED_BASE(HostZoomMap), virtual void SetZoomLevel(const std::string& host, double level) OVERRIDE; virtual double GetDefaultZoomLevel() const OVERRIDE; virtual void SetDefaultZoomLevel(double level) OVERRIDE; + virtual void AddZoomLevelChangedCallback( + const ZoomLevelChangedCallback& callback) OVERRIDE; + virtual void RemoveZoomLevelChangedCallback( + const ZoomLevelChangedCallback& callback) OVERRIDE; // Returns the temporary zoom level that's only valid for the lifetime of // the given WebContents (i.e. isn't saved and doesn't affect other @@ -59,6 +63,9 @@ class CONTENT_EXPORT HostZoomMapImpl : public NON_EXPORTED_BASE(HostZoomMap), private: typedef std::map<std::string, double> HostZoomLevels; + // Callbacks called when zoom level changes. + std::vector<ZoomLevelChangedCallback> zoom_level_changed_callbacks_; + // Copy of the pref data, so that we can read it on the IO thread. HostZoomLevels host_zoom_levels_; double default_zoom_level_; diff --git a/content/public/browser/host_zoom_map.h b/content/public/browser/host_zoom_map.h index 1e32e79..c399f69 100644 --- a/content/public/browser/host_zoom_map.h +++ b/content/public/browser/host_zoom_map.h @@ -10,6 +10,7 @@ #include <vector> #include "base/basictypes.h" +#include "base/callback.h" #include "content/common/content_export.h" namespace content { @@ -50,6 +51,14 @@ class HostZoomMap { virtual double GetDefaultZoomLevel() const = 0; virtual void SetDefaultZoomLevel(double level) = 0;; + typedef base::Callback<void(const std::string&)> ZoomLevelChangedCallback; + + // Add and remove zoom level changed callbacks. + virtual void AddZoomLevelChangedCallback( + const ZoomLevelChangedCallback& callback) = 0; + virtual void RemoveZoomLevelChangedCallback( + const ZoomLevelChangedCallback& callback) = 0; + protected: virtual ~HostZoomMap() {} }; diff --git a/content/public/browser/notification_types.h b/content/public/browser/notification_types.h index ced9dcf..4c3bd71 100644 --- a/content/public/browser/notification_types.h +++ b/content/public/browser/notification_types.h @@ -336,11 +336,6 @@ enum NotificationType { // The source is a NavigationController. NOTIFICATION_REPOST_WARNING_SHOWN, - // Sent when the zoom level changes. The source is the HostZoomMap. The - // details is a string of the hostname for which the zoom changed. In case - // of a temporary zoom level change, the details is an empty string. - NOTIFICATION_ZOOM_LEVEL_CHANGED, - // Custom notifications used by the embedder should start from here. NOTIFICATION_CONTENT_END, }; |