Remove usages of NotificationObserver
authorCheng Zhao <zcbenz@gmail.com>
Wed, 24 Jun 2015 12:16:51 +0000 (20:16 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Wed, 24 Jun 2015 12:16:51 +0000 (20:16 +0800)
atom/browser/native_window.cc
atom/browser/native_window.h

index a8b8e26..00142ad 100644 (file)
@@ -30,9 +30,6 @@
 #include "brightray/browser/inspectable_web_contents_view.h"
 #include "content/browser/renderer_host/render_widget_host_impl.h"
 #include "content/public/browser/navigation_entry.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/browser/plugin_service.h"
 #include "content/public/browser/render_process_host.h"
 #include "content/public/browser/render_view_host.h"
@@ -140,10 +137,6 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
       CHROME_VERSION_STRING);
   web_contents->GetMutableRendererPrefs()->user_agent_override =
       content::BuildUserAgentFromProduct(product_name);
-
-  // Get notified of title updated message.
-  registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
-      content::Source<content::WebContents>(web_contents));
 }
 
 NativeWindow::~NativeWindow() {
@@ -430,10 +423,6 @@ void NativeWindow::NotifyWindowClosed() {
   is_closed_ = true;
   FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnWindowClosed());
 
-  // Do not receive any notification after window has been closed, there is a
-  // crash that seems to be caused by this: http://git.io/YqMG5g.
-  registrar_.RemoveAll();
-
   WindowList::RemoveWindow(this);
 }
 
@@ -605,6 +594,17 @@ void NativeWindow::BeforeUnloadFired(const base::TimeTicks& proceed_time) {
   // there are two virtual functions named BeforeUnloadFired.
 }
 
+void NativeWindow::TitleWasSet(content::NavigationEntry* entry,
+                               bool explicit_set) {
+  bool prevent_default = false;
+  std::string text = base::UTF16ToUTF8(entry->GetTitle());
+  FOR_EACH_OBSERVER(NativeWindowObserver,
+                    observers_,
+                    OnPageTitleUpdated(&prevent_default, text));
+  if (!prevent_default)
+    SetTitle(text);
+}
+
 bool NativeWindow::OnMessageReceived(const IPC::Message& message) {
   bool handled = true;
   IPC_BEGIN_MESSAGE_MAP(NativeWindow, message)
@@ -616,26 +616,6 @@ bool NativeWindow::OnMessageReceived(const IPC::Message& message) {
   return handled;
 }
 
-void NativeWindow::Observe(int type,
-                           const content::NotificationSource& source,
-                           const content::NotificationDetails& details) {
-  if (type == content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED) {
-    std::pair<NavigationEntry*, bool>* title =
-        content::Details<std::pair<NavigationEntry*, bool>>(details).ptr();
-
-    if (title->first) {
-      bool prevent_default = false;
-      std::string text = base::UTF16ToUTF8(title->first->GetTitle());
-      FOR_EACH_OBSERVER(NativeWindowObserver,
-                        observers_,
-                        OnPageTitleUpdated(&prevent_default, text));
-
-      if (!prevent_default)
-        SetTitle(text);
-    }
-  }
-}
-
 void NativeWindow::DevToolsFocused() {
   FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnDevToolsFocus());
 }
index 0dfc9e0..642eb0c 100644 (file)
@@ -16,8 +16,6 @@
 #include "base/memory/scoped_ptr.h"
 #include "base/memory/weak_ptr.h"
 #include "base/observer_list.h"
-#include "content/public/browser/notification_registrar.h"
-#include "content/public/browser/notification_observer.h"
 #include "content/public/browser/readback_types.h"
 #include "native_mate/persistent_dictionary.h"
 #include "ui/gfx/image/image.h"
@@ -51,8 +49,7 @@ namespace atom {
 struct DraggableRegion;
 
 class NativeWindow : public CommonWebContentsDelegate,
-                     public content::WebContentsObserver,
-                     public content::NotificationObserver {
+                     public content::WebContentsObserver {
  public:
   typedef base::Callback<void(const SkBitmap& bitmap)> CapturePageCallback;
 
@@ -244,13 +241,9 @@ class NativeWindow : public CommonWebContentsDelegate,
   // Implementations of content::WebContentsObserver.
   void RenderViewCreated(content::RenderViewHost* render_view_host) override;
   void BeforeUnloadFired(const base::TimeTicks& proceed_time) override;
+  void TitleWasSet(content::NavigationEntry* entry, bool explicit_set) override;
   bool OnMessageReceived(const IPC::Message& message) override;
 
-  // Implementations of content::NotificationObserver.
-  void Observe(int type,
-               const content::NotificationSource& source,
-               const content::NotificationDetails& details) override;
-
   // Implementations of brightray::InspectableWebContentsDelegate.
   void DevToolsFocused() override;
   void DevToolsOpened() override;
@@ -280,9 +273,6 @@ class NativeWindow : public CommonWebContentsDelegate,
                          const SkBitmap& bitmap,
                          content::ReadbackResponse response);
 
-  // Notification manager.
-  content::NotificationRegistrar registrar_;
-
   // Observers of this window.
   ObserverList<NativeWindowObserver> observers_;