diff --git a/atom/browser/browser.cc b/atom/browser/browser.cc index 31e354c7d409..0b20d4f226c9 100644 --- a/atom/browser/browser.cc +++ b/atom/browser/browser.cc @@ -7,6 +7,7 @@ #include #include "atom/browser/atom_browser_main_parts.h" +#include "atom/browser/browser_observer.h" #include "atom/browser/native_window.h" #include "atom/browser/window_list.h" #include "base/files/file_util.h" @@ -82,7 +83,8 @@ void Browser::Shutdown() { is_shutdown_ = true; is_quiting_ = true; - FOR_EACH_OBSERVER(BrowserObserver, observers_, OnQuit()); + for (BrowserObserver& observer : observers_) + observer.OnQuit(); if (base::MessageLoop::current()) { base::ThreadTaskRunnerHandle::Get()->PostTask( @@ -127,25 +129,25 @@ int Browser::GetBadgeCount() { bool Browser::OpenFile(const std::string& file_path) { bool prevent_default = false; - FOR_EACH_OBSERVER(BrowserObserver, - observers_, - OnOpenFile(&prevent_default, file_path)); + for (BrowserObserver& observer : observers_) + observer.OnOpenFile(&prevent_default, file_path); return prevent_default; } void Browser::OpenURL(const std::string& url) { - FOR_EACH_OBSERVER(BrowserObserver, observers_, OnOpenURL(url)); + for (BrowserObserver& observer : observers_) + observer.OnOpenURL(url); } void Browser::Activate(bool has_visible_windows) { - FOR_EACH_OBSERVER(BrowserObserver, - observers_, - OnActivate(has_visible_windows)); + for (BrowserObserver& observer : observers_) + observer.OnActivate(has_visible_windows); } void Browser::WillFinishLaunching() { - FOR_EACH_OBSERVER(BrowserObserver, observers_, OnWillFinishLaunching()); + for (BrowserObserver& observer : observers_) + observer.OnWillFinishLaunching(); } void Browser::DidFinishLaunching(const base::DictionaryValue& launch_info) { @@ -155,22 +157,20 @@ void Browser::DidFinishLaunching(const base::DictionaryValue& launch_info) { base::CreateDirectoryAndGetError(user_data, nullptr); is_ready_ = true; - FOR_EACH_OBSERVER(BrowserObserver, observers_, - OnFinishLaunching(launch_info)); + for (BrowserObserver& observer : observers_) + observer.OnFinishLaunching(launch_info); } void Browser::OnAccessibilitySupportChanged() { - FOR_EACH_OBSERVER(BrowserObserver, - observers_, - OnAccessibilitySupportChanged()); + for (BrowserObserver& observer : observers_) + observer.OnAccessibilitySupportChanged(); } void Browser::RequestLogin( LoginHandler* login_handler, std::unique_ptr request_details) { - FOR_EACH_OBSERVER(BrowserObserver, - observers_, - OnLogin(login_handler, *(request_details.get()))); + for (BrowserObserver& observer : observers_) + observer.OnLogin(login_handler, *(request_details.get())); } void Browser::NotifyAndShutdown() { @@ -178,7 +178,8 @@ void Browser::NotifyAndShutdown() { return; bool prevent_default = false; - FOR_EACH_OBSERVER(BrowserObserver, observers_, OnWillQuit(&prevent_default)); + for (BrowserObserver& observer : observers_) + observer.OnWillQuit(&prevent_default); if (prevent_default) { is_quiting_ = false; @@ -190,9 +191,8 @@ void Browser::NotifyAndShutdown() { bool Browser::HandleBeforeQuit() { bool prevent_default = false; - FOR_EACH_OBSERVER(BrowserObserver, - observers_, - OnBeforeQuit(&prevent_default)); + for (BrowserObserver& observer : observers_) + observer.OnBeforeQuit(&prevent_default); return !prevent_default; } @@ -205,12 +205,14 @@ void Browser::OnWindowCloseCancelled(NativeWindow* window) { } void Browser::OnWindowAllClosed() { - if (is_exiting_) + if (is_exiting_) { Shutdown(); - else if (is_quiting_) + } else if (is_quiting_) { NotifyAndShutdown(); - else - FOR_EACH_OBSERVER(BrowserObserver, observers_, OnWindowAllClosed()); + } else { + for (BrowserObserver& observer : observers_) + observer.OnWindowAllClosed(); + } } } // namespace atom diff --git a/atom/browser/browser_mac.mm b/atom/browser/browser_mac.mm index afb291bc3b33..c318cf850701 100644 --- a/atom/browser/browser_mac.mm +++ b/atom/browser/browser_mac.mm @@ -146,9 +146,8 @@ std::string Browser::GetCurrentActivityType() { bool Browser::ContinueUserActivity(const std::string& type, const base::DictionaryValue& user_info) { bool prevent_default = false; - FOR_EACH_OBSERVER(BrowserObserver, - observers_, - OnContinueUserActivity(&prevent_default, type, user_info)); + for (BrowserObserver& observer : observers_) + observer.OnContinueUserActivity(&prevent_default, type, user_info); return prevent_default; } diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index ccd9b619c213..1ef70f2c73dd 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -390,9 +390,8 @@ void NativeWindow::CloseFilePreview() { void NativeWindow::RequestToClosePage() { bool prevent_default = false; - FOR_EACH_OBSERVER(NativeWindowObserver, - observers_, - WillCloseWindow(&prevent_default)); + for (NativeWindowObserver& observer : observers_) + observer.WillCloseWindow(&prevent_default); if (prevent_default) { WindowList::WindowCloseCancelled(this); return; @@ -423,8 +422,8 @@ void NativeWindow::CloseContents(content::WebContents* source) { inspectable_web_contents_ = nullptr; Observe(nullptr); - FOR_EACH_OBSERVER(NativeWindowObserver, observers_, - WillDestroyNativeObject()); + for (NativeWindowObserver& observer : observers_) + observer.WillDestroyNativeObject(); // When the web contents is gone, close the window immediately, but the // memory will not be freed until you call delete. @@ -450,7 +449,8 @@ void NativeWindow::RendererUnresponsive(content::WebContents* source) { void NativeWindow::RendererResponsive(content::WebContents* source) { window_unresposive_closure_.Cancel(); - FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnRendererResponsive()); + for (NativeWindowObserver& observer : observers_) + observer.OnRendererResponsive(); } void NativeWindow::NotifyWindowClosed() { @@ -460,104 +460,116 @@ void NativeWindow::NotifyWindowClosed() { WindowList::RemoveWindow(this); is_closed_ = true; - FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowClosed()); + for (NativeWindowObserver& observer : observers_) + observer.OnWindowClosed(); } void NativeWindow::NotifyWindowBlur() { - FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowBlur()); + for (NativeWindowObserver& observer : observers_) + observer.OnWindowBlur(); } void NativeWindow::NotifyWindowFocus() { - FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowFocus()); + for (NativeWindowObserver& observer : observers_) + observer.OnWindowFocus(); } void NativeWindow::NotifyWindowShow() { - FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowShow()); + for (NativeWindowObserver& observer : observers_) + observer.OnWindowShow(); } void NativeWindow::NotifyWindowHide() { - FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowHide()); + for (NativeWindowObserver& observer : observers_) + observer.OnWindowHide(); } void NativeWindow::NotifyWindowMaximize() { - FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowMaximize()); + for (NativeWindowObserver& observer : observers_) + observer.OnWindowMaximize(); } void NativeWindow::NotifyWindowUnmaximize() { - FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowUnmaximize()); + for (NativeWindowObserver& observer : observers_) + observer.OnWindowUnmaximize(); } void NativeWindow::NotifyWindowMinimize() { - FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowMinimize()); + for (NativeWindowObserver& observer : observers_) + observer.OnWindowMinimize(); } void NativeWindow::NotifyWindowRestore() { - FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowRestore()); + for (NativeWindowObserver& observer : observers_) + observer.OnWindowRestore(); } void NativeWindow::NotifyWindowResize() { - FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowResize()); + for (NativeWindowObserver& observer : observers_) + observer.OnWindowResize(); } void NativeWindow::NotifyWindowMove() { - FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowMove()); + for (NativeWindowObserver& observer : observers_) + observer.OnWindowMove(); } void NativeWindow::NotifyWindowMoved() { - FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowMoved()); + for (NativeWindowObserver& observer : observers_) + observer.OnWindowMoved(); } void NativeWindow::NotifyWindowEnterFullScreen() { - FOR_EACH_OBSERVER(NativeWindowObserver, observers_, - OnWindowEnterFullScreen()); + for (NativeWindowObserver& observer : observers_) + observer.OnWindowEnterFullScreen(); } void NativeWindow::NotifyWindowScrollTouchBegin() { - FOR_EACH_OBSERVER(NativeWindowObserver, observers_, - OnWindowScrollTouchBegin()); + for (NativeWindowObserver& observer : observers_) + observer.OnWindowScrollTouchBegin(); } void NativeWindow::NotifyWindowScrollTouchEnd() { - FOR_EACH_OBSERVER(NativeWindowObserver, observers_, - OnWindowScrollTouchEnd()); + for (NativeWindowObserver& observer : observers_) + observer.OnWindowScrollTouchEdge(); } void NativeWindow::NotifyWindowScrollTouchEdge() { - FOR_EACH_OBSERVER(NativeWindowObserver, observers_, - OnWindowScrollTouchEdge()); + for (NativeWindowObserver& observer : observers_) + observer.OnWindowScrollTouchEdge(); } void NativeWindow::NotifyWindowSwipe(const std::string& direction) { - FOR_EACH_OBSERVER(NativeWindowObserver, observers_, - OnWindowSwipe(direction)); + for (NativeWindowObserver& observer : observers_) + observer.OnWindowSwipe(direction); } void NativeWindow::NotifyWindowLeaveFullScreen() { - FOR_EACH_OBSERVER(NativeWindowObserver, observers_, - OnWindowLeaveFullScreen()); + for (NativeWindowObserver& observer : observers_) + observer.OnWindowLeaveFullScreen(); } void NativeWindow::NotifyWindowEnterHtmlFullScreen() { - FOR_EACH_OBSERVER(NativeWindowObserver, observers_, - OnWindowEnterHtmlFullScreen()); + for (NativeWindowObserver& observer : observers_) + observer.OnWindowEnterHtmlFullScreen(); } void NativeWindow::NotifyWindowLeaveHtmlFullScreen() { - FOR_EACH_OBSERVER(NativeWindowObserver, observers_, - OnWindowLeaveHtmlFullScreen()); + for (NativeWindowObserver& observer : observers_) + observer.OnWindowLeaveHtmlFullScreen(); } void NativeWindow::NotifyWindowExecuteWindowsCommand( const std::string& command) { - FOR_EACH_OBSERVER(NativeWindowObserver, observers_, - OnExecuteWindowsCommand(command)); + for (NativeWindowObserver& observer : observers_) + observer.OnExecuteWindowsCommand(command); } #if defined(OS_WIN) void NativeWindow::NotifyWindowMessage( UINT message, WPARAM w_param, LPARAM l_param) { - FOR_EACH_OBSERVER(NativeWindowObserver, observers_, - OnWindowMessage(message, w_param, l_param)); + for (NativeWindowObserver& observer : observers_) + observer.OnWindowMessage(message, w_param, l_param); } #endif @@ -645,14 +657,15 @@ void NativeWindow::ScheduleUnresponsiveEvent(int ms) { void NativeWindow::NotifyWindowUnresponsive() { window_unresposive_closure_.Cancel(); - if (!is_closed_ && !IsUnresponsiveEventSuppressed() && IsEnabled()) - FOR_EACH_OBSERVER(NativeWindowObserver, - observers_, - OnRendererUnresponsive()); + if (!is_closed_ && !IsUnresponsiveEventSuppressed() && IsEnabled()) { + for (NativeWindowObserver& observer : observers_) + observer.OnRendererUnresponsive(); + } } void NativeWindow::NotifyReadyToShow() { - FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnReadyToShow()); + for (NativeWindowObserver& observer : observers_) + observer.OnReadyToShow(); } } // namespace atom diff --git a/atom/browser/net/atom_cookie_delegate.cc b/atom/browser/net/atom_cookie_delegate.cc index a03588913bb1..b94f396d981e 100644 --- a/atom/browser/net/atom_cookie_delegate.cc +++ b/atom/browser/net/atom_cookie_delegate.cc @@ -26,9 +26,8 @@ void AtomCookieDelegate::NotifyObservers( const net::CanonicalCookie& cookie, bool removed, net::CookieStore::ChangeCause cause) { - FOR_EACH_OBSERVER(Observer, - observers_, - OnCookieChanged(cookie, removed, cause)); + for (Observer& observer : observers_) + observer.OnCookieChanged(cookie, removed, cause); } void AtomCookieDelegate::OnCookieChanged( diff --git a/atom/browser/ui/atom_menu_model.cc b/atom/browser/ui/atom_menu_model.cc index b6a9ba6a7265..1ec6b3c09f5c 100644 --- a/atom/browser/ui/atom_menu_model.cc +++ b/atom/browser/ui/atom_menu_model.cc @@ -42,7 +42,8 @@ bool AtomMenuModel::GetAcceleratorAtWithParams( void AtomMenuModel::MenuWillClose() { ui::SimpleMenuModel::MenuWillClose(); - FOR_EACH_OBSERVER(Observer, observers_, MenuWillClose()); + for (Observer& observer : observers_) + observer.MenuWillClose(); } AtomMenuModel* AtomMenuModel::GetSubmenuModelAt(int index) { diff --git a/atom/browser/ui/tray_icon.cc b/atom/browser/ui/tray_icon.cc index 273f5c084391..882a2ba27a0f 100644 --- a/atom/browser/ui/tray_icon.cc +++ b/atom/browser/ui/tray_icon.cc @@ -35,53 +35,63 @@ gfx::Rect TrayIcon::GetBounds() { } void TrayIcon::NotifyClicked(const gfx::Rect& bounds, int modifiers) { - FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnClicked(bounds, modifiers)); + for (TrayIconObserver& observer : observers_) + observer.OnClicked(bounds, modifiers); } void TrayIcon::NotifyDoubleClicked(const gfx::Rect& bounds, int modifiers) { - FOR_EACH_OBSERVER(TrayIconObserver, observers_, - OnDoubleClicked(bounds, modifiers)); + for (TrayIconObserver& observer : observers_) + observer.OnDoubleClicked(bounds, modifiers); } void TrayIcon::NotifyBalloonShow() { - FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnBalloonShow()); + for (TrayIconObserver& observer : observers_) + observer.OnBalloonShow(); } void TrayIcon::NotifyBalloonClicked() { - FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnBalloonClicked()); + for (TrayIconObserver& observer : observers_) + observer.OnBalloonClicked(); } void TrayIcon::NotifyBalloonClosed() { - FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnBalloonClosed()); + for (TrayIconObserver& observer : observers_) + observer.OnBalloonClosed(); } void TrayIcon::NotifyRightClicked(const gfx::Rect& bounds, int modifiers) { - FOR_EACH_OBSERVER(TrayIconObserver, observers_, - OnRightClicked(bounds, modifiers)); + for (TrayIconObserver& observer : observers_) + observer.OnRightClicked(bounds, modifiers); } void TrayIcon::NotifyDrop() { - FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnDrop()); + for (TrayIconObserver& observer : observers_) + observer.OnDrop(); } void TrayIcon::NotifyDropFiles(const std::vector& files) { - FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnDropFiles(files)); + for (TrayIconObserver& observer : observers_) + observer.OnDropFiles(files); } void TrayIcon::NotifyDropText(const std::string& text) { - FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnDropText(text)); + for (TrayIconObserver& observer : observers_) + observer.OnDropText(text); } void TrayIcon::NotifyDragEntered() { - FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnDragEntered()); + for (TrayIconObserver& observer : observers_) + observer.OnDragEntered(); } void TrayIcon::NotifyDragExited() { - FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnDragExited()); + for (TrayIconObserver& observer : observers_) + observer.OnDragExited(); } void TrayIcon::NotifyDragEnded() { - FOR_EACH_OBSERVER(TrayIconObserver, observers_, OnDragEnded()); + for (TrayIconObserver& observer : observers_) + observer.OnDragEnded(); } } // namespace atom diff --git a/atom/browser/window_list.cc b/atom/browser/window_list.cc index b8e5a8256530..b835e07e752a 100644 --- a/atom/browser/window_list.cc +++ b/atom/browser/window_list.cc @@ -33,8 +33,8 @@ void WindowList::AddWindow(NativeWindow* window) { WindowVector& windows = GetInstance()->windows_; windows.push_back(window); - FOR_EACH_OBSERVER(WindowListObserver, observers_.Get(), - OnWindowAdded(window)); + for (WindowListObserver& observer : observers_.Get()) + observer.OnWindowAdded(window); } // static @@ -43,18 +43,19 @@ void WindowList::RemoveWindow(NativeWindow* window) { windows.erase(std::remove(windows.begin(), windows.end(), window), windows.end()); - FOR_EACH_OBSERVER(WindowListObserver, observers_.Get(), - OnWindowRemoved(window)); + for (WindowListObserver& observer : observers_.Get()) + observer.OnWindowRemoved(window); - if (windows.size() == 0) - FOR_EACH_OBSERVER(WindowListObserver, observers_.Get(), - OnWindowAllClosed()); + if (windows.size() == 0) { + for (WindowListObserver& observer : observers_.Get()) + observer.OnWindowAllClosed(); + } } // static void WindowList::WindowCloseCancelled(NativeWindow* window) { - FOR_EACH_OBSERVER(WindowListObserver, observers_.Get(), - OnWindowCloseCancelled(window)); + for (WindowListObserver& observer : observers_.Get()) + observer.OnWindowCloseCancelled(window); } // static