From e0a22fe9fa257805a0190d9d91d846ea28fb95c5 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Mon, 15 Aug 2016 12:30:17 +0300 Subject: [PATCH] Check that platform_delegate_ is non-NULL --- libcef/browser/browser_host_impl.cc | 74 ++++++++++++++++++----------- 1 file changed, 45 insertions(+), 29 deletions(-) diff --git a/libcef/browser/browser_host_impl.cc b/libcef/browser/browser_host_impl.cc index 43d216a8d..aac2148e1 100644 --- a/libcef/browser/browser_host_impl.cc +++ b/libcef/browser/browser_host_impl.cc @@ -596,7 +596,7 @@ void CefBrowserHostImpl::SetFocus(bool focus) { if (focus) OnSetFocus(FOCUS_SOURCE_SYSTEM); - else + else if (platform_delegate_) platform_delegate_->SendFocusEvent(false); } @@ -940,7 +940,7 @@ void CefBrowserHostImpl::WasResized() { return; } - if (!web_contents()) +if (!web_contents() || !platform_delegate_) return; platform_delegate_->WasResized(); @@ -958,7 +958,7 @@ void CefBrowserHostImpl::WasHidden(bool hidden) { return; } - if (!web_contents()) + if (!web_contents() || !platform_delegate_) return; platform_delegate_->WasHidden(hidden); @@ -976,7 +976,7 @@ void CefBrowserHostImpl::NotifyScreenInfoChanged() { return; } - if (!web_contents()) + if (!web_contents() || !platform_delegate_) return; platform_delegate_->NotifyScreenInfoChanged(); @@ -994,7 +994,7 @@ void CefBrowserHostImpl::Invalidate(PaintElementType type) { return; } - if (!web_contents()) + if (!web_contents() || !platform_delegate_) return; platform_delegate_->Invalidate(type); @@ -1007,7 +1007,7 @@ void CefBrowserHostImpl::SendKeyEvent(const CefKeyEvent& event) { return; } - if (!web_contents()) + if (!web_contents() || !platform_delegate_) return; content::NativeWebKeyboardEvent web_event; @@ -1024,7 +1024,7 @@ void CefBrowserHostImpl::SendMouseClickEvent(const CefMouseEvent& event, return; } - if (!web_contents()) + if (!web_contents() || !platform_delegate_) return; blink::WebMouseEvent web_event; @@ -1042,7 +1042,7 @@ void CefBrowserHostImpl::SendMouseMoveEvent(const CefMouseEvent& event, return; } - if (!web_contents()) + if (!web_contents() || !platform_delegate_) return; blink::WebMouseEvent web_event; @@ -1059,7 +1059,7 @@ void CefBrowserHostImpl::SendMouseWheelEvent(const CefMouseEvent& event, return; } - if (!web_contents()) + if (!web_contents() || !platform_delegate_) return; blink::WebMouseWheelEvent web_event; @@ -1078,7 +1078,7 @@ void CefBrowserHostImpl::SendCaptureLostEvent() { return; } - if (!web_contents()) + if (!web_contents() || !platform_delegate_) return; platform_delegate_->SendCaptureLostEvent(); @@ -1092,7 +1092,7 @@ void CefBrowserHostImpl::NotifyMoveOrResizeStarted() { return; } - if (!web_contents()) + if (!web_contents() || !platform_delegate_) return; platform_delegate_->NotifyMoveOrResizeStarted(); @@ -1118,7 +1118,9 @@ void CefBrowserHostImpl::SetWindowlessFrameRate(int frame_rate) { } settings_.windowless_frame_rate = frame_rate; - platform_delegate_->SetWindowlessFrameRate(frame_rate); + + if (platform_delegate_) + platform_delegate_->SetWindowlessFrameRate(frame_rate); } // CefBrowser methods. @@ -1421,12 +1423,14 @@ void CefBrowserHostImpl::DestroyBrowser() { #if defined(USE_AURA) views::Widget* CefBrowserHostImpl::GetWindowWidget() const { CEF_REQUIRE_UIT(); + if (!platform_delegate_) + return nullptr; return platform_delegate_->GetWindowWidget(); } CefRefPtr CefBrowserHostImpl::GetBrowserView() const { CEF_REQUIRE_UIT(); - if (IsViewsHosted()) + if (IsViewsHosted() && platform_delegate_) return platform_delegate_->GetBrowserView(); return nullptr; } @@ -1665,7 +1669,8 @@ void CefBrowserHostImpl::ViewText(const std::string& text) { return; } - platform_delegate_->ViewText(text); + if (platform_delegate_) + platform_delegate_->ViewText(text); } void CefBrowserHostImpl::HandleExternalProtocol(const GURL& url) { @@ -1678,7 +1683,7 @@ void CefBrowserHostImpl::HandleExternalProtocol(const GURL& url) { handler->OnProtocolExecution(this, url.spec(), allow_os_execution); } - if (allow_os_execution) + if (allow_os_execution && platform_delegate_) platform_delegate_->HandleExternalProtocol(url); } else { CEF_POST_TASK(CEF_UIT, @@ -1708,7 +1713,8 @@ void CefBrowserHostImpl::OnSetFocus(cef_focus_source_t source) { } } - platform_delegate_->SendFocusEvent(true); + if (platform_delegate_) + platform_delegate_->SendFocusEvent(true); } else { CEF_POST_TASK(CEF_UIT, base::Bind(&CefBrowserHostImpl::OnSetFocus, this, source)); @@ -1780,7 +1786,7 @@ CefTextInputContext CefBrowserHostImpl::GetNSTextInputContext() { return nullptr; } - if (!web_contents()) + if (!web_contents() || !platform_delegate_) return nullptr; return platform_delegate_->GetNSTextInputContext(); @@ -1802,7 +1808,7 @@ void CefBrowserHostImpl::HandleKeyEventBeforeTextInputClient( return; } - if (!web_contents()) + if (!web_contents() || !platform_delegate_) return; platform_delegate_->HandleKeyEventBeforeTextInputClient(keyEvent); @@ -1822,7 +1828,7 @@ void CefBrowserHostImpl::HandleKeyEventAfterTextInputClient( return; } - if (!web_contents()) + if (!web_contents() || !platform_delegate_) return; return platform_delegate_->HandleKeyEventAfterTextInputClient(keyEvent); @@ -1849,7 +1855,7 @@ void CefBrowserHostImpl::DragTargetDragEnter(CefRefPtr drag_data, return; } - if (!web_contents()) + if (!web_contents() || !platform_delegate_) return; platform_delegate_->DragTargetDragEnter(drag_data, event, allowed_ops); @@ -1869,7 +1875,7 @@ void CefBrowserHostImpl::DragTargetDragOver(const CefMouseEvent& event, return; } - if (!web_contents()) + if (!web_contents() || !platform_delegate_) return; platform_delegate_->DragTargetDragOver(event, allowed_ops); @@ -1887,7 +1893,7 @@ void CefBrowserHostImpl::DragTargetDragLeave() { return; } - if (!web_contents()) + if (!web_contents() || !platform_delegate_) return; platform_delegate_->DragTargetDragLeave(); @@ -1905,7 +1911,7 @@ void CefBrowserHostImpl::DragTargetDrop(const CefMouseEvent& event) { return; } - if (!web_contents()) + if (!web_contents() || !platform_delegate_) return; platform_delegate_->DragTargetDrop(event); @@ -1923,6 +1929,9 @@ void CefBrowserHostImpl::DragSourceSystemDragEnded() { return; } + if (!web_contents() || !platform_delegate_) + return; + platform_delegate_->DragSourceSystemDragEnded(); } @@ -1939,7 +1948,7 @@ void CefBrowserHostImpl::DragSourceEndedAt( return; } - if (!web_contents()) + if (!web_contents() || !platform_delegate_) return; platform_delegate_->DragSourceEndedAt(x, y, op); @@ -2109,6 +2118,9 @@ bool CefBrowserHostImpl::PreHandleKeyboardEvent( content::WebContents* source, const content::NativeWebKeyboardEvent& event, bool* is_keyboard_shortcut) { + if (!platform_delegate_) + return false; + if (client_.get()) { CefRefPtr handler = client_->GetKeyboardHandler(); if (handler.get()) { @@ -2134,6 +2146,9 @@ void CefBrowserHostImpl::HandleKeyboardEvent( if (event.skip_in_browser) return; + if (!platform_delegate_) + return; + if (client_.get()) { CefRefPtr handler = client_->GetKeyboardHandler(); if (handler.get()) { @@ -2235,7 +2250,7 @@ void CefBrowserHostImpl::DidNavigateMainFramePostCommit( content::JavaScriptDialogManager* CefBrowserHostImpl::GetJavaScriptDialogManager( content::WebContents* source) { - if (!javascript_dialog_manager_.get()) { + if (!javascript_dialog_manager_.get() && platform_delegate_) { javascript_dialog_manager_.reset( new CefJavaScriptDialogManager(this, platform_delegate_->CreateJavaScriptDialogRunner())); @@ -2254,7 +2269,7 @@ bool CefBrowserHostImpl::HandleContextMenu( content::WebContents* web_contents, const content::ContextMenuParams& params) { CEF_REQUIRE_UIT(); - if (!menu_manager_.get()) { + if (!menu_manager_.get() && platform_delegate_) { menu_manager_.reset( new CefMenuManager(this, platform_delegate_->CreateMenuRunner())); @@ -2266,7 +2281,8 @@ void CefBrowserHostImpl::UpdatePreferredSize(content::WebContents* source, const gfx::Size& pref_size) { #if defined(OS_WIN) || (defined(OS_POSIX) && !defined(OS_MACOSX)) CEF_REQUIRE_UIT(); - platform_delegate_->SizeTo(pref_size.width(), pref_size.height()); + if (platform_delegate_) + platform_delegate_->SizeTo(pref_size.width(), pref_size.height()); #endif } @@ -2932,7 +2948,7 @@ void CefBrowserHostImpl::SetFocusedFrame(int64 frame_id) { gfx::Point CefBrowserHostImpl::GetScreenPoint(const gfx::Point& view) const { CEF_REQUIRE_UIT(); - if (platform_delegate_.get()) + if (platform_delegate_) return platform_delegate_->GetScreenPoint(view); return gfx::Point(); } @@ -3018,7 +3034,7 @@ void CefBrowserHostImpl::OnDevToolsWebContentsDestroyed() { void CefBrowserHostImpl::EnsureFileDialogManager() { CEF_REQUIRE_UIT(); - if (!file_dialog_manager_.get()) { + if (!file_dialog_manager_.get() && platform_delegate_) { file_dialog_manager_.reset( new CefFileDialogManager(this, platform_delegate_->CreateFileDialogRunner()));