No need to override TitleWasSet in NativeWindow
authorCheng Zhao <zcbenz@gmail.com>
Tue, 1 Dec 2015 09:51:09 +0000 (17:51 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 1 Dec 2015 09:51:09 +0000 (17:51 +0800)
atom/browser/api/atom_api_window.cc
atom/browser/api/atom_api_window.h
atom/browser/api/lib/browser-window.coffee
atom/browser/native_window.cc
atom/browser/native_window.h
atom/browser/native_window_observer.h

index a5aa4a1..5696405 100644 (file)
@@ -161,11 +161,6 @@ Window::~Window() {
     Destroy();
 }
 
-void Window::OnPageTitleUpdated(bool* prevent_default,
-                                const std::string& title) {
-  *prevent_default = Emit("page-title-updated", title);
-}
-
 void Window::WillCloseWindow(bool* prevent_default) {
   *prevent_default = Emit("close");
 }
index 757abd2..a04e00c 100644 (file)
@@ -54,8 +54,6 @@ class Window : public mate::TrackableObject<Window>,
   virtual ~Window();
 
   // NativeWindowObserver:
-  void OnPageTitleUpdated(bool* prevent_default,
-                          const std::string& title) override;
   void WillCloseWindow(bool* prevent_default) override;
   void OnWindowClosed() override;
   void OnWindowBlur() override;
index d693a6d..84c7690 100644 (file)
@@ -31,6 +31,11 @@ BrowserWindow::_init = ->
   @webContents.on 'crashed', =>
     @emit 'crashed'
 
+  # Change window title to page title.
+  @webContents.on 'page-title-set', (event, title, explicitSet) =>
+    @emit 'page-title-updated', event, title
+    @setTitle title unless event.defaultPrevented
+
   # Sometimes the webContents doesn't get focus when window is shown, so we have
   # to force focusing on webContents in this case. The safest way is to focus it
   # when we first start to load URL, if we do it earlier it won't have effect,
index ad7a6c4..a3df240 100644 (file)
@@ -505,17 +505,6 @@ void NativeWindow::BeforeUnloadDialogCancelled() {
   window_unresposive_closure_.Cancel();
 }
 
-void NativeWindow::TitleWasSet(content::NavigationEntry* entry,
-                               bool explicit_set) {
-  bool prevent_default = false;
-  std::string text = entry ? base::UTF16ToUTF8(entry->GetTitle()) : "";
-  FOR_EACH_OBSERVER(NativeWindowObserver,
-                    observers_,
-                    OnPageTitleUpdated(&prevent_default, text));
-  if (!prevent_default && !is_closed_)
-    SetTitle(text);
-}
-
 bool NativeWindow::OnMessageReceived(const IPC::Message& message) {
   bool handled = true;
   IPC_BEGIN_MESSAGE_MAP(NativeWindow, message)
index e32b948..0c918d9 100644 (file)
@@ -262,7 +262,6 @@ class NativeWindow : public base::SupportsUserData,
   // content::WebContentsObserver:
   void RenderViewCreated(content::RenderViewHost* render_view_host) override;
   void BeforeUnloadDialogCancelled() override;
-  void TitleWasSet(content::NavigationEntry* entry, bool explicit_set) override;
   bool OnMessageReceived(const IPC::Message& message) override;
 
  private:
index 54004a3..ce2d41c 100644 (file)
@@ -21,10 +21,6 @@ class NativeWindowObserver {
  public:
   virtual ~NativeWindowObserver() {}
 
-  // Called when the web page of the window has updated it's document title.
-  virtual void OnPageTitleUpdated(bool* prevent_default,
-                                  const std::string& title) {}
-
   // Called when the web page in window wants to create a popup window.
   virtual void WillCreatePopupWindow(const base::string16& frame_name,
                                      const GURL& target_url,