diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 41457424345..695ac4346cd 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -55,7 +55,6 @@ #include "chrome/browser/ssl/security_state_tab_helper.h" #include "content/browser/renderer_host/render_widget_host_impl.h" #include "content/browser/renderer_host/render_widget_host_view_base.h" -#include "content/browser/web_contents/web_contents_impl.h" #include "content/common/view_messages.h" #include "content/public/browser/child_process_security_policy.h" #include "content/public/browser/favicon_status.h" @@ -1727,9 +1726,7 @@ void WebContents::StartPainting() { return; #if defined(ENABLE_OSR) - const auto* wc_impl = - reinterpret_cast(web_contents()); - auto* osr_wcv = static_cast(wc_impl->GetView()); + auto* osr_wcv = GetOffScreenWebContentsView(); if (osr_wcv) osr_wcv->SetPainting(true); #endif @@ -1740,9 +1737,7 @@ void WebContents::StopPainting() { return; #if defined(ENABLE_OSR) - const auto* wc_impl = - reinterpret_cast(web_contents()); - auto* osr_wcv = static_cast(wc_impl->GetView()); + auto* osr_wcv = GetOffScreenWebContentsView(); if (osr_wcv) osr_wcv->SetPainting(false); #endif @@ -1753,10 +1748,7 @@ bool WebContents::IsPainting() const { return false; #if defined(ENABLE_OSR) - const auto* wc_impl = - reinterpret_cast(web_contents()); - auto* osr_wcv = static_cast(wc_impl->GetView()); - + auto* osr_wcv = GetOffScreenWebContentsView(); return osr_wcv && osr_wcv->IsPainting(); #else return false; @@ -1768,10 +1760,7 @@ void WebContents::SetFrameRate(int frame_rate) { return; #if defined(ENABLE_OSR) - const auto* wc_impl = - reinterpret_cast(web_contents()); - auto* osr_wcv = static_cast(wc_impl->GetView()); - + auto* osr_wcv = GetOffScreenWebContentsView(); if (osr_wcv) osr_wcv->SetFrameRate(frame_rate); #endif @@ -1782,10 +1771,7 @@ int WebContents::GetFrameRate() const { return 0; #if defined(ENABLE_OSR) - const auto* wc_impl = - reinterpret_cast(web_contents()); - auto* osr_wcv = static_cast(wc_impl->GetView()); - + auto* osr_wcv = GetOffScreenWebContentsView(); return osr_wcv ? osr_wcv->GetFrameRate() : 0; #else return 0; diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 00e4b5a84a1..ceb0c75e7d8 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -48,6 +48,10 @@ class AtomJavaScriptDialogManager; class WebContentsZoomController; class WebViewGuestDelegate; +#if defined(ENABLE_OSR) +class OffScreenWebContentsView; +#endif + namespace api { // Certain events are only in WebContentsDelegate, provide our own Observer to @@ -393,6 +397,10 @@ class WebContents : public mate::TrackableObject, return ++request_id_; } +#if defined(ENABLE_OSR) + OffScreenWebContentsView* GetOffScreenWebContentsView() const; +#endif + // Called when we receive a CursorChange message from chromium. void OnCursorChange(const content::WebCursor& cursor); diff --git a/atom/browser/api/atom_api_web_contents_osr.cc b/atom/browser/api/atom_api_web_contents_osr.cc new file mode 100644 index 00000000000..be999c283f1 --- /dev/null +++ b/atom/browser/api/atom_api_web_contents_osr.cc @@ -0,0 +1,26 @@ +// Copyright (c) 2018 GitHub, Inc. +// Use of this source code is governed by the MIT license that can be +// found in the LICENSE file. + +#include "atom/browser/api/atom_api_web_contents.h" + +#include "atom/browser/osr/osr_web_contents_view.h" +#include "content/browser/web_contents/web_contents_impl.h" + +// Including both web_contents_impl.h and node.h would introduce a error, we +// have to isolate the usage of WebContentsImpl into a clean file to fix it: +// error C2371: 'ssize_t': redefinition; different basic types + +namespace atom { + +namespace api { + +OffScreenWebContentsView* WebContents::GetOffScreenWebContentsView() const { + const auto* impl = + static_cast(web_contents()); + return static_cast(impl->GetView()); +} + +} // namespace api + +} // namespace atom diff --git a/filenames.gypi b/filenames.gypi index bb6c40215c8..025469c73e8 100644 --- a/filenames.gypi +++ b/filenames.gypi @@ -712,6 +712,7 @@ }], # OS=="win" ['enable_osr==1', { 'lib_sources': [ + 'atom/browser/api/atom_api_web_contents_osr.cc', 'atom/browser/osr/osr_web_contents_view_mac.mm', 'atom/browser/osr/osr_web_contents_view.cc', 'atom/browser/osr/osr_web_contents_view.h',