diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 86399ce057d..9869e36cbad 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -38,8 +38,16 @@ void OnCapturePageDone( } // namespace -Window::Window(const mate::Dictionary& options) - : window_(NativeWindow::Create(options)) { +Window::Window(v8::Isolate* isolate, const mate::Dictionary& options) { + // Creates the WebContents used by BrowserWindow. + mate::Dictionary web_contents_options(isolate, v8::Object::New(isolate)); + auto web_contents = WebContents::Create(isolate, web_contents_options); + web_contents_.Reset(isolate, web_contents.ToV8()); + + // Creates BrowserWindow. + window_.reset(NativeWindow::Create(web_contents->managed_web_contents(), + options)); + web_contents->SetOwnerWindow(window_.get()); window_->InitFromOptions(options); window_->AddObserver(this); } @@ -49,13 +57,6 @@ Window::~Window() { Destroy(); } -void Window::AfterInit(v8::Isolate* isolate) { - mate::TrackableObject::AfterInit(isolate); - auto web_contents = window_->managed_web_contents(); - auto handle = WebContents::CreateFrom(isolate, web_contents); - web_contents_.Reset(isolate, handle.ToV8()); -} - void Window::OnPageTitleUpdated(bool* prevent_default, const std::string& title) { *prevent_default = Emit("page-title-updated", title); @@ -173,7 +174,7 @@ mate::Wrappable* Window::New(v8::Isolate* isolate, "Cannot create BrowserWindow before app is ready"); return nullptr; } - return new Window(options); + return new Window(isolate, options); } void Window::Destroy() { diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index a0403dde54f..f6c99ebda3f 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -45,12 +45,9 @@ class Window : public mate::TrackableObject, NativeWindow* window() const { return window_.get(); } protected: - explicit Window(const mate::Dictionary& options); + Window(v8::Isolate* isolate, const mate::Dictionary& options); virtual ~Window(); - // mate::Wrappable: - void AfterInit(v8::Isolate* isolate) override; - // NativeWindowObserver: void OnPageTitleUpdated(bool* prevent_default, const std::string& title) override; diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 4d85f7cc623..fc32ee71377 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -83,9 +83,10 @@ std::string RemoveWhitespace(const std::string& str) { } // namespace -NativeWindow::NativeWindow(content::WebContents* web_contents, - const mate::Dictionary& options) - : content::WebContentsObserver(web_contents), +NativeWindow::NativeWindow( + brightray::InspectableWebContents* inspectable_web_contents, + const mate::Dictionary& options) + : content::WebContentsObserver(inspectable_web_contents->GetWebContents()), has_frame_(true), transparent_(false), enable_larger_than_screen_(false), @@ -94,9 +95,6 @@ NativeWindow::NativeWindow(content::WebContents* web_contents, has_dialog_attached_(false), zoom_factor_(1.0), weak_factory_(this) { - InitWithWebContents(web_contents); - SetOwnerWindow(this); - options.Get(switches::kFrame, &has_frame_); options.Get(switches::kTransparent, &transparent_); options.Get(switches::kEnableLargerThanScreen, &enable_larger_than_screen_); @@ -137,7 +135,7 @@ NativeWindow::NativeWindow(content::WebContents* web_contents, RemoveWhitespace(browser->GetName()).c_str(), browser->GetVersion().c_str(), CHROME_VERSION_STRING); - web_contents->GetMutableRendererPrefs()->user_agent_override = + web_contents()->GetMutableRendererPrefs()->user_agent_override = content::BuildUserAgentFromProduct(product_name); } @@ -147,13 +145,6 @@ NativeWindow::~NativeWindow() { NotifyWindowClosed(); } -// static -NativeWindow* NativeWindow::Create(const mate::Dictionary& options) { - auto browser_context = AtomBrowserMainParts::Get()->browser_context(); - content::WebContents::CreateParams create_params(browser_context); - return Create(content::WebContents::Create(create_params), options); -} - // static NativeWindow* NativeWindow::FromWebContents( content::WebContents* web_contents) { diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 8f3a04c8866..0f061456896 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -77,12 +77,9 @@ class NativeWindow : public CommonWebContentsDelegate, // Create window with existing WebContents, the caller is responsible for // managing the window's live. - static NativeWindow* Create(content::WebContents* web_contents, - const mate::Dictionary& options); - - // Create window with new WebContents, the caller is responsible for - // managing the window's live. - static NativeWindow* Create(const mate::Dictionary& options); + static NativeWindow* Create( + brightray::InspectableWebContents* inspectable_web_contents, + const mate::Dictionary& options); // Find a window from its WebContents static NativeWindow* FromWebContents(content::WebContents* web_contents); @@ -200,7 +197,7 @@ class NativeWindow : public CommonWebContentsDelegate, } brightray::InspectableWebContents* inspectable_web_contents() const { - return managed_web_contents(); + return inspectable_web_contents_; } bool has_frame() const { return has_frame_; } @@ -210,8 +207,8 @@ class NativeWindow : public CommonWebContentsDelegate, } protected: - explicit NativeWindow(content::WebContents* web_contents, - const mate::Dictionary& options); + NativeWindow(brightray::InspectableWebContents* inspectable_web_contents, + const mate::Dictionary& options); // Called when the window needs to update its draggable region. virtual void UpdateDraggableRegions( @@ -300,6 +297,9 @@ class NativeWindow : public CommonWebContentsDelegate, // Page's default zoom factor. double zoom_factor_; + // The page this window is viewing. + brightray::InspectableWebContents* inspectable_web_contents_; + base::WeakPtrFactory weak_factory_; DISALLOW_COPY_AND_ASSIGN(NativeWindow); diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index 8a6d141c34b..7f9272bea72 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -23,9 +23,9 @@ namespace atom { class NativeWindowMac : public NativeWindow { public: - explicit NativeWindowMac(content::WebContents* web_contents, - const mate::Dictionary& options); - virtual ~NativeWindowMac(); + NativeWindowMac(brightray::InspectableWebContents* inspectable_web_contents, + const mate::Dictionary& options); + ~NativeWindowMac() override; // NativeWindow implementation. void Close() override; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 8130d2c0fed..093b1832224 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -104,7 +104,7 @@ static const CGFloat kAtomWindowCornerRadius = 4.0; - (void)windowDidMove:(NSNotification*)notification { // TODO(zcbenz): Remove the alias after figuring out a proper - // way to disptach move. + // way to disptach move. shell_->NotifyWindowMove(); shell_->NotifyWindowMoved(); } @@ -303,8 +303,9 @@ SkRegion* DraggableRegionsToSkRegion( } // namespace -NativeWindowMac::NativeWindowMac(content::WebContents* web_contents, - const mate::Dictionary& options) +NativeWindowMac::NativeWindowMac( + brightray::InspectableWebContents* web_contents, + const mate::Dictionary& options) : NativeWindow(web_contents, options), is_kiosk_(false), attention_request_id_(0) { @@ -834,9 +835,10 @@ void NativeWindowMac::InstallDraggableRegionView() { } // static -NativeWindow* NativeWindow::Create(content::WebContents* web_contents, - const mate::Dictionary& options) { - return new NativeWindowMac(web_contents, options); +NativeWindow* NativeWindow::Create( + brightray::InspectableWebContents* inspectable_web_contents, + const mate::Dictionary& options) { + return new NativeWindowMac(inspectable_web_contents, options); } } // namespace atom diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 52309ba2977..4c7700d3f2b 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -142,8 +142,9 @@ class NativeWindowClientView : public views::ClientView { } // namespace -NativeWindowViews::NativeWindowViews(content::WebContents* web_contents, - const mate::Dictionary& options) +NativeWindowViews::NativeWindowViews( + brightray::InspectableWebContents* web_contents, + const mate::Dictionary& options) : NativeWindow(web_contents, options), window_(new views::Widget), web_view_(inspectable_web_contents()->GetView()->GetView()), @@ -973,9 +974,10 @@ ui::WindowShowState NativeWindowViews::GetRestoredState() { } // static -NativeWindow* NativeWindow::Create(content::WebContents* web_contents, - const mate::Dictionary& options) { - return new NativeWindowViews(web_contents, options); +NativeWindow* NativeWindow::Create( + brightray::InspectableWebContents* inspectable_web_contents, + const mate::Dictionary& options) { + return new NativeWindowViews(inspectable_web_contents, options); } } // namespace atom diff --git a/atom/browser/native_window_views.h b/atom/browser/native_window_views.h index becd1b9f9f2..621122566e6 100644 --- a/atom/browser/native_window_views.h +++ b/atom/browser/native_window_views.h @@ -28,9 +28,9 @@ class NativeWindowViews : public NativeWindow, public views::WidgetDelegateView, public views::WidgetObserver { public: - explicit NativeWindowViews(content::WebContents* web_contents, - const mate::Dictionary& options); - virtual ~NativeWindowViews(); + NativeWindowViews(brightray::InspectableWebContents* inspectable_web_contents, + const mate::Dictionary& options); + ~NativeWindowViews() override; // NativeWindow: void Close() override;