From 5fb5ce22511356e269b5e871da74100799a91773 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Sat, 20 Apr 2013 13:42:39 +0800 Subject: [PATCH] Enable creating window with existing web contents. --- browser/api/atom_api_window.cc | 3 +-- browser/native_window.cc | 15 ++++++++++----- browser/native_window.h | 8 ++++++-- browser/native_window_mac.h | 2 +- browser/native_window_mac.mm | 8 ++++---- vendor/brightray | 2 +- 6 files changed, 23 insertions(+), 15 deletions(-) diff --git a/browser/api/atom_api_window.cc b/browser/api/atom_api_window.cc index 1ac41dde8066..7f86cbf7c3a2 100644 --- a/browser/api/atom_api_window.cc +++ b/browser/api/atom_api_window.cc @@ -5,7 +5,6 @@ #include "browser/api/atom_api_window.h" #include "base/values.h" -#include "browser/atom_browser_context.h" #include "browser/native_window.h" #include "common/v8_value_converter_impl.h" #include "content/public/browser/navigation_entry.h" @@ -33,7 +32,7 @@ v8::Handle UTF16ToV8String(const string16& s) { Window::Window(v8::Handle wrapper, base::DictionaryValue* options) : EventEmitter(wrapper), - window_(NativeWindow::Create(AtomBrowserContext::Get(), options)) { + window_(NativeWindow::Create(options)) { window_->InitFromOptions(options); window_->AddObserver(this); } diff --git a/browser/native_window.cc b/browser/native_window.cc index c76910736092..2dbcfd81f6bd 100644 --- a/browser/native_window.cc +++ b/browser/native_window.cc @@ -11,6 +11,7 @@ #include "brightray/browser/browser_context.h" #include "brightray/browser/inspectable_web_contents.h" #include "brightray/browser/inspectable_web_contents_view.h" +#include "browser/atom_browser_context.h" #include "content/public/browser/navigation_entry.h" #include "content/public/browser/notification_details.h" #include "content/public/browser/notification_source.h" @@ -24,12 +25,10 @@ using content::NavigationEntry; namespace atom { -NativeWindow::NativeWindow(content::BrowserContext* browser_context, +NativeWindow::NativeWindow(content::WebContents* web_contents, base::DictionaryValue* options) - : inspectable_web_contents_(brightray::InspectableWebContents::Create( - content::WebContents::CreateParams(browser_context))) { - content::WebContents* web_contents = GetWebContents(); - + : inspectable_web_contents_( + brightray::InspectableWebContents::Create(web_contents)) { web_contents->SetDelegate(this); // Add window as an observer of the web contents. @@ -40,6 +39,12 @@ NativeWindow::NativeWindow(content::BrowserContext* browser_context, NativeWindow::~NativeWindow() { } +// static +NativeWindow* NativeWindow::Create(base::DictionaryValue* options) { + content::WebContents::CreateParams create_params(AtomBrowserContext::Get()); + return Create(content::WebContents::Create(create_params), options); +} + void NativeWindow::InitFromOptions(base::DictionaryValue* options) { // Setup window from options. int x, y; diff --git a/browser/native_window.h b/browser/native_window.h index 239406a22577..de12f0fd67a2 100644 --- a/browser/native_window.h +++ b/browser/native_window.h @@ -42,9 +42,13 @@ class NativeWindow : public content::WebContentsDelegate, public: virtual ~NativeWindow(); - static NativeWindow* Create(content::BrowserContext* browser_context, + // Create window with existing WebContents. + static NativeWindow* Create(content::WebContents* web_contents, base::DictionaryValue* options); + // Create window with new WebContents. + static NativeWindow* Create(base::DictionaryValue* options); + void InitFromOptions(base::DictionaryValue* options); virtual void Close() = 0; @@ -90,7 +94,7 @@ class NativeWindow : public content::WebContentsDelegate, } protected: - explicit NativeWindow(content::BrowserContext* browser_context, + explicit NativeWindow(content::WebContents* web_contents, base::DictionaryValue* options); brightray::InspectableWebContents* inspectable_web_contents() const { diff --git a/browser/native_window_mac.h b/browser/native_window_mac.h index 2f9190f203af..87f5d9e94be5 100644 --- a/browser/native_window_mac.h +++ b/browser/native_window_mac.h @@ -14,7 +14,7 @@ namespace atom { class NativeWindowMac : public NativeWindow { public: - explicit NativeWindowMac(content::BrowserContext* browser_context, + explicit NativeWindowMac(content::WebContents* web_contents, base::DictionaryValue* options); virtual ~NativeWindowMac(); diff --git a/browser/native_window_mac.mm b/browser/native_window_mac.mm index 8e72cf75a889..f22989bd01c0 100644 --- a/browser/native_window_mac.mm +++ b/browser/native_window_mac.mm @@ -43,9 +43,9 @@ namespace atom { -NativeWindowMac::NativeWindowMac(content::BrowserContext* browser_context, +NativeWindowMac::NativeWindowMac(content::WebContents* web_contents, base::DictionaryValue* options) - : NativeWindow(browser_context, options), + : NativeWindow(web_contents, options), is_fullscreen_(false), is_kiosk_(false), attention_request_id_(0) { @@ -350,9 +350,9 @@ void NativeWindowMac::UninstallView() { } // static -NativeWindow* NativeWindow::Create(content::BrowserContext* browser_context, +NativeWindow* NativeWindow::Create(content::WebContents* web_contents, base::DictionaryValue* options) { - return new NativeWindowMac(browser_context, options); + return new NativeWindowMac(web_contents, options); } } // namespace atom diff --git a/vendor/brightray b/vendor/brightray index be62b66f9a11..5e5ac169db77 160000 --- a/vendor/brightray +++ b/vendor/brightray @@ -1 +1 @@ -Subproject commit be62b66f9a11660610ef08e6cd65d4f669d71e7f +Subproject commit 5e5ac169db77ab49507ff474e54d73ab3e74ce38