} // 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);
}
Destroy();
}
-void Window::AfterInit(v8::Isolate* isolate) {
- mate::TrackableObject<Window>::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);
"Cannot create BrowserWindow before app is ready");
return nullptr;
}
- return new Window(options);
+ return new Window(isolate, options);
}
void Window::Destroy() {
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;
} // 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),
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_);
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);
}
}
// 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) {
WindowList& window_list = *WindowList::GetInstance();
// 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);
}
brightray::InspectableWebContents* inspectable_web_contents() const {
- return managed_web_contents();
+ return inspectable_web_contents_;
}
bool has_frame() const { return has_frame_; }
}
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(
// Page's default zoom factor.
double zoom_factor_;
+ // The page this window is viewing.
+ brightray::InspectableWebContents* inspectable_web_contents_;
+
base::WeakPtrFactory<NativeWindow> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(NativeWindow);
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;
- (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();
}
} // 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) {
}
// 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
} // 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()),
}
// 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
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;