Remove NativeWindow::GetWebContents
This commit is contained in:
parent
01dc0f973c
commit
9f52b11761
7 changed files with 25 additions and 44 deletions
|
@ -22,7 +22,7 @@ void MenuMac::Popup(Window* window) {
|
||||||
NativeWindow* native_window = window->window();
|
NativeWindow* native_window = window->window();
|
||||||
if (!native_window)
|
if (!native_window)
|
||||||
return;
|
return;
|
||||||
content::WebContents* web_contents = native_window->GetWebContents();
|
content::WebContents* web_contents = native_window->web_contents();
|
||||||
if (!web_contents)
|
if (!web_contents)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ void MenuMac::PopupAt(Window* window, int x, int y) {
|
||||||
NativeWindow* native_window = window->window();
|
NativeWindow* native_window = window->window();
|
||||||
if (!native_window)
|
if (!native_window)
|
||||||
return;
|
return;
|
||||||
content::WebContents* web_contents = native_window->GetWebContents();
|
content::WebContents* web_contents = native_window->web_contents();
|
||||||
if (!web_contents)
|
if (!web_contents)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@ void MenuViews::PopupAt(Window* window, int x, int y) {
|
||||||
NativeWindow* native_window = static_cast<NativeWindow*>(window->window());
|
NativeWindow* native_window = static_cast<NativeWindow*>(window->window());
|
||||||
if (!native_window)
|
if (!native_window)
|
||||||
return;
|
return;
|
||||||
content::WebContents* web_contents = native_window->GetWebContents();
|
content::WebContents* web_contents = native_window->web_contents();
|
||||||
if (!web_contents)
|
if (!web_contents)
|
||||||
return;
|
return;
|
||||||
content::RenderWidgetHostView* view = web_contents->GetRenderWidgetHostView();
|
content::RenderWidgetHostView* view = web_contents->GetRenderWidgetHostView();
|
||||||
|
|
|
@ -63,7 +63,7 @@ ProcessOwner GetProcessOwner(int process_id,
|
||||||
|
|
||||||
// First search for NativeWindow.
|
// First search for NativeWindow.
|
||||||
for (auto native_window : *WindowList::GetInstance())
|
for (auto native_window : *WindowList::GetInstance())
|
||||||
if (web_contents == native_window->GetWebContents()) {
|
if (web_contents == native_window->web_contents()) {
|
||||||
*window = native_window;
|
*window = native_window;
|
||||||
return OWNER_NATIVE_WINDOW;
|
return OWNER_NATIVE_WINDOW;
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,7 +153,7 @@ NativeWindow* NativeWindow::FromWebContents(
|
||||||
content::WebContents* web_contents) {
|
content::WebContents* web_contents) {
|
||||||
WindowList& window_list = *WindowList::GetInstance();
|
WindowList& window_list = *WindowList::GetInstance();
|
||||||
for (NativeWindow* window : window_list) {
|
for (NativeWindow* window : window_list) {
|
||||||
if (window->GetWebContents() == web_contents)
|
if (window->web_contents() == web_contents)
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -268,24 +268,22 @@ bool NativeWindow::HasModalDialog() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindow::FocusOnWebView() {
|
void NativeWindow::FocusOnWebView() {
|
||||||
GetWebContents()->GetRenderViewHost()->Focus();
|
web_contents()->GetRenderViewHost()->Focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindow::BlurWebView() {
|
void NativeWindow::BlurWebView() {
|
||||||
GetWebContents()->GetRenderViewHost()->Blur();
|
web_contents()->GetRenderViewHost()->Blur();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NativeWindow::IsWebViewFocused() {
|
bool NativeWindow::IsWebViewFocused() {
|
||||||
RenderWidgetHostView* host_view =
|
auto host_view = web_contents()->GetRenderViewHost()->GetView();
|
||||||
GetWebContents()->GetRenderViewHost()->GetView();
|
|
||||||
return host_view && host_view->HasFocus();
|
return host_view && host_view->HasFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindow::CapturePage(const gfx::Rect& rect,
|
void NativeWindow::CapturePage(const gfx::Rect& rect,
|
||||||
const CapturePageCallback& callback) {
|
const CapturePageCallback& callback) {
|
||||||
content::WebContents* contents = GetWebContents();
|
const auto view = web_contents()->GetRenderWidgetHostView();
|
||||||
RenderWidgetHostView* const view = contents->GetRenderWidgetHostView();
|
const auto host = view ? view->GetRenderWidgetHost() : nullptr;
|
||||||
RenderWidgetHost* const host = view ? view->GetRenderWidgetHost() : nullptr;
|
|
||||||
if (!view || !host) {
|
if (!view || !host) {
|
||||||
callback.Run(SkBitmap());
|
callback.Run(SkBitmap());
|
||||||
return;
|
return;
|
||||||
|
@ -315,13 +313,6 @@ void NativeWindow::CapturePage(const gfx::Rect& rect,
|
||||||
kBGRA_8888_SkColorType);
|
kBGRA_8888_SkColorType);
|
||||||
}
|
}
|
||||||
|
|
||||||
content::WebContents* NativeWindow::GetWebContents() const {
|
|
||||||
if (inspectable_web_contents_)
|
|
||||||
return inspectable_web_contents_->GetWebContents();
|
|
||||||
else
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void NativeWindow::RequestToClosePage() {
|
void NativeWindow::RequestToClosePage() {
|
||||||
bool prevent_default = false;
|
bool prevent_default = false;
|
||||||
FOR_EACH_OBSERVER(NativeWindowObserver,
|
FOR_EACH_OBSERVER(NativeWindowObserver,
|
||||||
|
@ -332,12 +323,6 @@ void NativeWindow::RequestToClosePage() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
content::WebContents* web_contents(GetWebContents());
|
|
||||||
if (!web_contents) {
|
|
||||||
CloseImmediately();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Assume the window is not responding if it doesn't cancel the close and is
|
// Assume the window is not responding if it doesn't cancel the close and is
|
||||||
// not closed in 5s, in this way we can quickly show the unresponsive
|
// not closed in 5s, in this way we can quickly show the unresponsive
|
||||||
// dialog when the window is busy executing some script withouth waiting for
|
// dialog when the window is busy executing some script withouth waiting for
|
||||||
|
@ -345,10 +330,10 @@ void NativeWindow::RequestToClosePage() {
|
||||||
if (window_unresposive_closure_.IsCancelled())
|
if (window_unresposive_closure_.IsCancelled())
|
||||||
ScheduleUnresponsiveEvent(5000);
|
ScheduleUnresponsiveEvent(5000);
|
||||||
|
|
||||||
if (web_contents->NeedToFireBeforeUnload())
|
if (web_contents()->NeedToFireBeforeUnload())
|
||||||
web_contents->DispatchBeforeUnload(false);
|
web_contents()->DispatchBeforeUnload(false);
|
||||||
else
|
else
|
||||||
web_contents->Close();
|
web_contents()->Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindow::CloseContents(content::WebContents* source) {
|
void NativeWindow::CloseContents(content::WebContents* source) {
|
||||||
|
@ -357,6 +342,7 @@ void NativeWindow::CloseContents(content::WebContents* source) {
|
||||||
|
|
||||||
inspectable_web_contents_->GetView()->SetDelegate(nullptr);
|
inspectable_web_contents_->GetView()->SetDelegate(nullptr);
|
||||||
inspectable_web_contents_ = nullptr;
|
inspectable_web_contents_ = nullptr;
|
||||||
|
Observe(nullptr);
|
||||||
|
|
||||||
// When the web contents is gone, close the window immediately, but the
|
// When the web contents is gone, close the window immediately, but the
|
||||||
// memory will not be freed until you call delete.
|
// memory will not be freed until you call delete.
|
||||||
|
|
|
@ -167,8 +167,6 @@ class NativeWindow : public content::WebContentsObserver,
|
||||||
return weak_factory_.GetWeakPtr();
|
return weak_factory_.GetWeakPtr();
|
||||||
}
|
}
|
||||||
|
|
||||||
content::WebContents* GetWebContents() const;
|
|
||||||
|
|
||||||
// Requests the WebContents to close, can be cancelled by the page.
|
// Requests the WebContents to close, can be cancelled by the page.
|
||||||
virtual void RequestToClosePage();
|
virtual void RequestToClosePage();
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,7 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)windowDidBecomeMain:(NSNotification*)notification {
|
- (void)windowDidBecomeMain:(NSNotification*)notification {
|
||||||
content::WebContents* web_contents = shell_->GetWebContents();
|
content::WebContents* web_contents = shell_->web_contents();
|
||||||
if (!web_contents)
|
if (!web_contents)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -82,7 +82,7 @@ static const CGFloat kAtomWindowCornerRadius = 4.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)windowDidResignMain:(NSNotification*)notification {
|
- (void)windowDidResignMain:(NSNotification*)notification {
|
||||||
content::WebContents* web_contents = shell_->GetWebContents();
|
content::WebContents* web_contents = shell_->web_contents();
|
||||||
if (!web_contents)
|
if (!web_contents)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -677,10 +677,9 @@ void NativeWindowMac::SetOverlayIcon(const gfx::Image& overlay,
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowMac::ShowDefinitionForSelection() {
|
void NativeWindowMac::ShowDefinitionForSelection() {
|
||||||
content::WebContents* web_contents = GetWebContents();
|
if (!web_contents())
|
||||||
if (!web_contents)
|
|
||||||
return;
|
return;
|
||||||
content::RenderWidgetHostView* rwhv = web_contents->GetRenderWidgetHostView();
|
auto rwhv = web_contents()->GetRenderWidgetHostView();
|
||||||
if (!rwhv)
|
if (!rwhv)
|
||||||
return;
|
return;
|
||||||
rwhv->ShowDefinitionForSelection();
|
rwhv->ShowDefinitionForSelection();
|
||||||
|
@ -704,10 +703,9 @@ bool NativeWindowMac::IsVisibleOnAllWorkspaces() {
|
||||||
bool NativeWindowMac::IsWithinDraggableRegion(NSPoint point) const {
|
bool NativeWindowMac::IsWithinDraggableRegion(NSPoint point) const {
|
||||||
if (!draggable_region_)
|
if (!draggable_region_)
|
||||||
return false;
|
return false;
|
||||||
content::WebContents* web_contents = GetWebContents();
|
if (!web_contents())
|
||||||
if (!web_contents)
|
|
||||||
return false;
|
return false;
|
||||||
NSView* webView = web_contents->GetNativeView();
|
NSView* webView = web_contents()->GetNativeView();
|
||||||
NSInteger webViewHeight = NSHeight([webView bounds]);
|
NSInteger webViewHeight = NSHeight([webView bounds]);
|
||||||
// |draggable_region_| is stored in local platform-indepdent coordiate system
|
// |draggable_region_| is stored in local platform-indepdent coordiate system
|
||||||
// while |point| is in local Cocoa coordinate system. Do the conversion
|
// while |point| is in local Cocoa coordinate system. Do the conversion
|
||||||
|
@ -814,16 +812,15 @@ void NativeWindowMac::UninstallView() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowMac::ClipWebView() {
|
void NativeWindowMac::ClipWebView() {
|
||||||
content::WebContents* web_contents = GetWebContents();
|
if (!web_contents())
|
||||||
if (!web_contents)
|
|
||||||
return;
|
return;
|
||||||
NSView* webView = web_contents->GetNativeView();
|
NSView* webView = web_contents()->GetNativeView();
|
||||||
webView.layer.masksToBounds = YES;
|
webView.layer.masksToBounds = YES;
|
||||||
webView.layer.cornerRadius = kAtomWindowCornerRadius;
|
webView.layer.cornerRadius = kAtomWindowCornerRadius;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowMac::InstallDraggableRegionView() {
|
void NativeWindowMac::InstallDraggableRegionView() {
|
||||||
NSView* webView = GetWebContents()->GetNativeView();
|
NSView* webView = web_contents()->GetNativeView();
|
||||||
base::scoped_nsobject<NSView> controlRegion(
|
base::scoped_nsobject<NSView> controlRegion(
|
||||||
[[ControlRegionView alloc] initWithShellWindow:this]);
|
[[ControlRegionView alloc] initWithShellWindow:this]);
|
||||||
[controlRegion setFrame:NSMakeRect(0, 0,
|
[controlRegion setFrame:NSMakeRect(0, 0,
|
||||||
|
|
|
@ -728,9 +728,9 @@ void NativeWindowViews::OnWidgetActivationChanged(
|
||||||
else
|
else
|
||||||
NotifyWindowBlur();
|
NotifyWindowBlur();
|
||||||
|
|
||||||
if (active && GetWebContents() &&
|
if (active && inspectable_web_contents() &&
|
||||||
!inspectable_web_contents()->IsDevToolsViewShowing())
|
!inspectable_web_contents()->IsDevToolsViewShowing())
|
||||||
GetWebContents()->Focus();
|
web_contents()->Focus();
|
||||||
|
|
||||||
// Hide menu bar when window is blured.
|
// Hide menu bar when window is blured.
|
||||||
if (!active && menu_bar_autohide_ && menu_bar_visible_)
|
if (!active && menu_bar_autohide_ && menu_bar_visible_)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue