'browser/native_window.h',
'browser/native_window_mac.h',
'browser/native_window_mac.mm',
+ 'browser/native_window_observer.h',
'common/node_bindings.cc',
'common/node_bindings.h',
'common/node_bindings_mac.h',
#include <string>
+#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "brightray/browser/browser_context.h"
#include "brightray/browser/inspectable_web_contents.h"
#include "brightray/browser/inspectable_web_contents_view.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 "common/options_switches.h"
#include "ui/gfx/point.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
+using content::NavigationEntry;
+
namespace atom {
NativeWindow::NativeWindow(content::BrowserContext* browser_context,
base::DictionaryValue* options)
: inspectable_web_contents_(brightray::InspectableWebContents::Create(
content::WebContents::CreateParams(browser_context))) {
- GetWebContents()->SetDelegate(this);
+ content::WebContents* web_contents = GetWebContents();
+
+ web_contents->SetDelegate(this);
+
+ // Add window as an observer of the web contents.
+ registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED,
+ content::Source<content::WebContents>(web_contents));
}
NativeWindow::~NativeWindow() {
return inspectable_web_contents_->GetWebContents();
}
+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 = UTF16ToUTF8(title->first->GetTitle());
+ FOR_EACH_OBSERVER(NativeWindowObserver,
+ observers_,
+ OnPageTitleUpdated(&prevent_default, text));
+
+ if (!prevent_default)
+ SetTitle(text);
+ }
+ }
+}
+
} // namespace atom
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
+#include "base/observer_list.h"
+#include "browser/native_window_observer.h"
+#include "content/public/browser/notification_registrar.h"
+#include "content/public/browser/notification_observer.h"
#include "content/public/browser/web_contents_delegate.h"
namespace base {
namespace atom {
-class NativeWindow : public content::WebContentsDelegate {
+class NativeWindow : public content::WebContentsDelegate,
+ public content::NotificationObserver {
public:
virtual ~NativeWindow();
content::WebContents* GetWebContents() const;
+ void AddObserver(NativeWindowObserver* obs) {
+ observers_.AddObserver(obs);
+ }
+
+ void RemoveObserver(NativeWindowObserver* obs) {
+ observers_.RemoveObserver(obs);
+ }
+
protected:
explicit NativeWindow(content::BrowserContext* browser_context,
base::DictionaryValue* options);
return inspectable_web_contents_.get();
}
+ // Implementations of content::NotificationObserver
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) OVERRIDE;
+
private:
+ // Notification manager.
+ content::NotificationRegistrar registrar_;
+
+ // Observers of this window.
+ ObserverList<NativeWindowObserver> observers_;
+
scoped_ptr<brightray::InspectableWebContents> inspectable_web_contents_;
DISALLOW_COPY_AND_ASSIGN(NativeWindow);
--- /dev/null
+// Copyright (c) 2013 GitHub, Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ATOM_BROWSER_NATIVE_WINDOW_OBSERVER_H_
+#define ATOM_BROWSER_NATIVE_WINDOW_OBSERVER_H_
+
+#include <iosfwd>
+
+namespace atom {
+
+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) = 0;
+};
+
+} // namespace atom
+
+#endif // ATOM_BROWSER_NATIVE_WINDOW_OBSERVER_H_