Enable creating window with existing web contents.

This commit is contained in:
Cheng Zhao 2013-04-20 13:42:39 +08:00
parent 0b2b9d371e
commit 5fb5ce2251
6 changed files with 23 additions and 15 deletions

View file

@ -5,7 +5,6 @@
#include "browser/api/atom_api_window.h" #include "browser/api/atom_api_window.h"
#include "base/values.h" #include "base/values.h"
#include "browser/atom_browser_context.h"
#include "browser/native_window.h" #include "browser/native_window.h"
#include "common/v8_value_converter_impl.h" #include "common/v8_value_converter_impl.h"
#include "content/public/browser/navigation_entry.h" #include "content/public/browser/navigation_entry.h"
@ -33,7 +32,7 @@ v8::Handle<v8::String> UTF16ToV8String(const string16& s) {
Window::Window(v8::Handle<v8::Object> wrapper, base::DictionaryValue* options) Window::Window(v8::Handle<v8::Object> wrapper, base::DictionaryValue* options)
: EventEmitter(wrapper), : EventEmitter(wrapper),
window_(NativeWindow::Create(AtomBrowserContext::Get(), options)) { window_(NativeWindow::Create(options)) {
window_->InitFromOptions(options); window_->InitFromOptions(options);
window_->AddObserver(this); window_->AddObserver(this);
} }

View file

@ -11,6 +11,7 @@
#include "brightray/browser/browser_context.h" #include "brightray/browser/browser_context.h"
#include "brightray/browser/inspectable_web_contents.h" #include "brightray/browser/inspectable_web_contents.h"
#include "brightray/browser/inspectable_web_contents_view.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/navigation_entry.h"
#include "content/public/browser/notification_details.h" #include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_source.h" #include "content/public/browser/notification_source.h"
@ -24,12 +25,10 @@ using content::NavigationEntry;
namespace atom { namespace atom {
NativeWindow::NativeWindow(content::BrowserContext* browser_context, NativeWindow::NativeWindow(content::WebContents* web_contents,
base::DictionaryValue* options) base::DictionaryValue* options)
: inspectable_web_contents_(brightray::InspectableWebContents::Create( : inspectable_web_contents_(
content::WebContents::CreateParams(browser_context))) { brightray::InspectableWebContents::Create(web_contents)) {
content::WebContents* web_contents = GetWebContents();
web_contents->SetDelegate(this); web_contents->SetDelegate(this);
// Add window as an observer of the web contents. // Add window as an observer of the web contents.
@ -40,6 +39,12 @@ NativeWindow::NativeWindow(content::BrowserContext* browser_context,
NativeWindow::~NativeWindow() { 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) { void NativeWindow::InitFromOptions(base::DictionaryValue* options) {
// Setup window from options. // Setup window from options.
int x, y; int x, y;

View file

@ -42,9 +42,13 @@ class NativeWindow : public content::WebContentsDelegate,
public: public:
virtual ~NativeWindow(); virtual ~NativeWindow();
static NativeWindow* Create(content::BrowserContext* browser_context, // Create window with existing WebContents.
static NativeWindow* Create(content::WebContents* web_contents,
base::DictionaryValue* options); base::DictionaryValue* options);
// Create window with new WebContents.
static NativeWindow* Create(base::DictionaryValue* options);
void InitFromOptions(base::DictionaryValue* options); void InitFromOptions(base::DictionaryValue* options);
virtual void Close() = 0; virtual void Close() = 0;
@ -90,7 +94,7 @@ class NativeWindow : public content::WebContentsDelegate,
} }
protected: protected:
explicit NativeWindow(content::BrowserContext* browser_context, explicit NativeWindow(content::WebContents* web_contents,
base::DictionaryValue* options); base::DictionaryValue* options);
brightray::InspectableWebContents* inspectable_web_contents() const { brightray::InspectableWebContents* inspectable_web_contents() const {

View file

@ -14,7 +14,7 @@ namespace atom {
class NativeWindowMac : public NativeWindow { class NativeWindowMac : public NativeWindow {
public: public:
explicit NativeWindowMac(content::BrowserContext* browser_context, explicit NativeWindowMac(content::WebContents* web_contents,
base::DictionaryValue* options); base::DictionaryValue* options);
virtual ~NativeWindowMac(); virtual ~NativeWindowMac();

View file

@ -43,9 +43,9 @@
namespace atom { namespace atom {
NativeWindowMac::NativeWindowMac(content::BrowserContext* browser_context, NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
base::DictionaryValue* options) base::DictionaryValue* options)
: NativeWindow(browser_context, options), : NativeWindow(web_contents, options),
is_fullscreen_(false), is_fullscreen_(false),
is_kiosk_(false), is_kiosk_(false),
attention_request_id_(0) { attention_request_id_(0) {
@ -350,9 +350,9 @@ void NativeWindowMac::UninstallView() {
} }
// static // static
NativeWindow* NativeWindow::Create(content::BrowserContext* browser_context, NativeWindow* NativeWindow::Create(content::WebContents* web_contents,
base::DictionaryValue* options) { base::DictionaryValue* options) {
return new NativeWindowMac(browser_context, options); return new NativeWindowMac(web_contents, options);
} }
} // namespace atom } // namespace atom

2
vendor/brightray vendored

@ -1 +1 @@
Subproject commit be62b66f9a11660610ef08e6cd65d4f669d71e7f Subproject commit 5e5ac169db77ab49507ff474e54d73ab3e74ce38