Don't create WebContents in NativeWindow
This commit is contained in:
parent
081a4597e9
commit
5236b0c067
8 changed files with 47 additions and 54 deletions
|
@ -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<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);
|
||||
|
@ -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() {
|
||||
|
|
|
@ -45,12 +45,9 @@ class Window : public mate::TrackableObject<Window>,
|
|||
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;
|
||||
|
|
|
@ -83,9 +83,10 @@ std::string RemoveWhitespace(const std::string& str) {
|
|||
|
||||
} // namespace
|
||||
|
||||
NativeWindow::NativeWindow(content::WebContents* web_contents,
|
||||
NativeWindow::NativeWindow(
|
||||
brightray::InspectableWebContents* inspectable_web_contents,
|
||||
const mate::Dictionary& options)
|
||||
: content::WebContentsObserver(web_contents),
|
||||
: 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) {
|
||||
|
|
|
@ -77,13 +77,10 @@ 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,
|
||||
static NativeWindow* Create(
|
||||
brightray::InspectableWebContents* inspectable_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);
|
||||
|
||||
// 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,7 +207,7 @@ class NativeWindow : public CommonWebContentsDelegate,
|
|||
}
|
||||
|
||||
protected:
|
||||
explicit NativeWindow(content::WebContents* web_contents,
|
||||
NativeWindow(brightray::InspectableWebContents* inspectable_web_contents,
|
||||
const mate::Dictionary& options);
|
||||
|
||||
// Called when the window needs to update its draggable region.
|
||||
|
@ -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<NativeWindow> weak_factory_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(NativeWindow);
|
||||
|
|
|
@ -23,9 +23,9 @@ namespace atom {
|
|||
|
||||
class NativeWindowMac : public NativeWindow {
|
||||
public:
|
||||
explicit NativeWindowMac(content::WebContents* web_contents,
|
||||
NativeWindowMac(brightray::InspectableWebContents* inspectable_web_contents,
|
||||
const mate::Dictionary& options);
|
||||
virtual ~NativeWindowMac();
|
||||
~NativeWindowMac() override;
|
||||
|
||||
// NativeWindow implementation.
|
||||
void Close() override;
|
||||
|
|
|
@ -303,7 +303,8 @@ SkRegion* DraggableRegionsToSkRegion(
|
|||
|
||||
} // namespace
|
||||
|
||||
NativeWindowMac::NativeWindowMac(content::WebContents* web_contents,
|
||||
NativeWindowMac::NativeWindowMac(
|
||||
brightray::InspectableWebContents* web_contents,
|
||||
const mate::Dictionary& options)
|
||||
: NativeWindow(web_contents, options),
|
||||
is_kiosk_(false),
|
||||
|
@ -834,9 +835,10 @@ void NativeWindowMac::InstallDraggableRegionView() {
|
|||
}
|
||||
|
||||
// static
|
||||
NativeWindow* NativeWindow::Create(content::WebContents* web_contents,
|
||||
NativeWindow* NativeWindow::Create(
|
||||
brightray::InspectableWebContents* inspectable_web_contents,
|
||||
const mate::Dictionary& options) {
|
||||
return new NativeWindowMac(web_contents, options);
|
||||
return new NativeWindowMac(inspectable_web_contents, options);
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -142,7 +142,8 @@ class NativeWindowClientView : public views::ClientView {
|
|||
|
||||
} // namespace
|
||||
|
||||
NativeWindowViews::NativeWindowViews(content::WebContents* web_contents,
|
||||
NativeWindowViews::NativeWindowViews(
|
||||
brightray::InspectableWebContents* web_contents,
|
||||
const mate::Dictionary& options)
|
||||
: NativeWindow(web_contents, options),
|
||||
window_(new views::Widget),
|
||||
|
@ -973,9 +974,10 @@ ui::WindowShowState NativeWindowViews::GetRestoredState() {
|
|||
}
|
||||
|
||||
// static
|
||||
NativeWindow* NativeWindow::Create(content::WebContents* web_contents,
|
||||
NativeWindow* NativeWindow::Create(
|
||||
brightray::InspectableWebContents* inspectable_web_contents,
|
||||
const mate::Dictionary& options) {
|
||||
return new NativeWindowViews(web_contents, options);
|
||||
return new NativeWindowViews(inspectable_web_contents, options);
|
||||
}
|
||||
|
||||
} // namespace atom
|
||||
|
|
|
@ -28,9 +28,9 @@ class NativeWindowViews : public NativeWindow,
|
|||
public views::WidgetDelegateView,
|
||||
public views::WidgetObserver {
|
||||
public:
|
||||
explicit NativeWindowViews(content::WebContents* web_contents,
|
||||
NativeWindowViews(brightray::InspectableWebContents* inspectable_web_contents,
|
||||
const mate::Dictionary& options);
|
||||
virtual ~NativeWindowViews();
|
||||
~NativeWindowViews() override;
|
||||
|
||||
// NativeWindow:
|
||||
void Close() override;
|
||||
|
|
Loading…
Reference in a new issue