From: surya.kumar7 Date: Thu, 13 Dec 2018 11:02:19 +0000 (+0530) Subject: Alter visibility of a web page as per app loop callbacks X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=00537485fc30c619229b6db28e27f9438bc9c897;p=platform%2Fframework%2Fweb%2Fcrosswalk-tizen.git Alter visibility of a web page as per app loop callbacks The visibility state of a web page has to be communicated by sending 'visibilitychanged' event to the app when it is paused/resumed Change-Id: I8a274561a62c268dd63c2f9ec17341043ba3b63f Signed-off-by: surya.kumar7 --- diff --git a/atom/browser/browser.cc b/atom/browser/browser.cc index 09c330473..288038329 100644 --- a/atom/browser/browser.cc +++ b/atom/browser/browser.cc @@ -55,8 +55,12 @@ void Browser::Quit() { if (atom::WindowList::IsEmpty()) NotifyAndShutdown(); - else + else { +#if defined(OS_TIZEN) + tizen::TizenBrowserParts::Quit(); +#endif atom::WindowList::CloseAllWindows(); + } } void Browser::Exit(mate::Arguments* args) { diff --git a/atom/browser/browser.h b/atom/browser/browser.h index 94b0e267a..988cfd116 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -51,7 +51,11 @@ class Browser : public WindowListObserver static Browser* Get(); // Try to close all windows and quit the application. +#if defined(OS_TIZEN) + void Quit() override; +#else void Quit(); +#endif // Exit the application immediately and set exit code. void Exit(mate::Arguments* args); diff --git a/atom/browser/native_window_efl.cc b/atom/browser/native_window_efl.cc index 25feab1f7..954c8d9ae 100644 --- a/atom/browser/native_window_efl.cc +++ b/atom/browser/native_window_efl.cc @@ -19,6 +19,7 @@ #include "base/command_line.h" #include "content/public/browser/web_contents.h" #include "efl/window_factory.h" +#include "tizen/browser/tizen_web_contents_view.h" #include "tizen/common/application_data.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/size.h" @@ -68,8 +69,12 @@ const char* kMenuKeyEventScript = } Evas_Object* NativeWindowEfl::GetHostWindowDelegate(const content::WebContents* web_contents) { - LOG(ERROR) << "NativeWindowEfl::GetHostWindowDelegate"; - return atom::AtomBrowserClient::GetTizenWebContentsView(web_contents)->evas_object(); + auto web_contents_view = atom::AtomBrowserClient::GetTizenWebContentsView(web_contents); + if (!web_contents_view) { + LOG(ERROR) << "TizenWebContentsView should not be NULL; Exiting"; + exit(0); + } + return web_contents_view->evas_object(); } NativeWindowEfl::NativeWindowEfl( @@ -77,9 +82,12 @@ NativeWindowEfl::NativeWindowEfl( const mate::Dictionary& options, NativeWindow* parent) : NativeWindow(inspectable_web_contents, options, parent), + web_contents_view_(atom::AtomBrowserClient::GetTizenWebContentsView(web_contents())), fullscreenable_(true) { options.Get(options::kTitle, &title_); - window_ = efl::WindowFactory::GetHostWindow(web_contents()); + DCHECK(web_contents_view_); + + window_ = web_contents_view_->evas_object(); DCHECK(window_); @@ -182,6 +190,7 @@ void NativeWindowEfl::Show() { LOG(ERROR) << "There's no available window or webview."; evas_object_show(window_); evas_object_show(web_view_); + web_contents_view_->SetVisibility(true); visibilityStatus_ = true; } @@ -192,6 +201,7 @@ void NativeWindowEfl::ShowInactive() { void NativeWindowEfl::Hide() { evas_object_hide(web_view_); evas_object_hide(window_); + web_contents_view_->SetVisibility(false); visibilityStatus_ = false; } diff --git a/atom/browser/native_window_efl.h b/atom/browser/native_window_efl.h index 5d93937bb..7d91c63cb 100644 --- a/atom/browser/native_window_efl.h +++ b/atom/browser/native_window_efl.h @@ -14,11 +14,13 @@ #include namespace content { - class WebContents; - } // namespace content +namespace tizen { +class TizenWebContentsView; +} // namespace tizen + namespace atom { class NativeWindowEfl : public NativeWindow { @@ -112,6 +114,7 @@ class NativeWindowEfl : public NativeWindow { Evas_Object* window_; Evas_Object* web_view_; + tizen::TizenWebContentsView* web_contents_view_; std::string title_; bool fullscreenable_; diff --git a/atom/browser/window_list.cc b/atom/browser/window_list.cc index e6fa1a999..7b8677b23 100644 --- a/atom/browser/window_list.cc +++ b/atom/browser/window_list.cc @@ -12,6 +12,8 @@ namespace atom { +bool is_closing_ = false; + // static base::LazyInstance>::Leaky WindowList::observers_ = LAZY_INSTANCE_INITIALIZER; @@ -61,7 +63,7 @@ void WindowList::RemoveWindow(NativeWindow* window) { WindowVector& windows = GetInstance()->windows_; windows.erase(std::remove(windows.begin(), windows.end(), window), windows.end()); - if (GetLastWindow()) + if (!is_closing_ && GetLastWindow()) GetLastWindow()->Show(); for (WindowListObserver& observer : observers_.Get()) observer.OnWindowRemoved(window); @@ -90,6 +92,7 @@ void WindowList::RemoveObserver(WindowListObserver* observer) { // static void WindowList::CloseAllWindows() { + is_closing_ = true; WindowVector windows = GetInstance()->windows_; for (const auto& window : windows) if (!window->IsClosed()) @@ -98,6 +101,7 @@ void WindowList::CloseAllWindows() { // static void WindowList::DestroyAllWindows() { + is_closing_ = true; WindowVector windows = GetInstance()->windows_; for (const auto& window : windows) window->CloseContents(nullptr); // e.g. Destroy() diff --git a/tizen/browser/tizen_browser_parts.cc b/tizen/browser/tizen_browser_parts.cc index c8cfd6d8c..6e7673f36 100644 --- a/tizen/browser/tizen_browser_parts.cc +++ b/tizen/browser/tizen_browser_parts.cc @@ -263,15 +263,16 @@ std::string TizenBrowserParts::GetEncodingType() { // Function is same as suspend. This will be called from app lifecycle suspend void TizenBrowserParts::Suspend() { + atom::NativeWindow *last_window = atom::WindowList::GetLastWindow(); + if (!last_window) + return; + last_window->Hide(); + // If application is having background catagory enabled then do not suspend the app if (app_data_->setting_info() != NULL && app_data_->setting_info()->background_support_enabled()) { return; } - atom::NativeWindow *last_window = atom::WindowList::GetLastWindow(); - if (!last_window) - return; - last_window->NotifySuspend(); auto rvh = last_window->web_contents()->GetRenderViewHost(); SuspendRVH(rvh); @@ -279,14 +280,16 @@ void TizenBrowserParts::Suspend() { // Function is same as resume. This will be called from app lifecycle resume void TizenBrowserParts::Resume() { + atom::NativeWindow *last_window = atom::WindowList::GetLastWindow(); + if (!last_window) + return; + last_window->Show(); + // If application is having background catagory enabled then do not resume the app // as its has not suspend if (app_data_->setting_info() != NULL && app_data_->setting_info()->background_support_enabled()) { return; } - atom::NativeWindow *last_window = atom::WindowList::GetLastWindow(); - if (!last_window) - return; last_window->NotifyResume(); auto rvh = last_window->web_contents()->GetRenderViewHost(); @@ -358,5 +361,8 @@ void TizenBrowserParts::Launch(std::unique_ptr appcontrol) { tizen::NativeWebRuntime::GetInstance().StartApplication(); } +void TizenBrowserParts::Quit() { + atom::WindowList::GetLastWindow()->Hide(); +} } // namespace tizen diff --git a/tizen/browser/tizen_browser_parts.h b/tizen/browser/tizen_browser_parts.h index 3ec1f7924..951b7e7d3 100644 --- a/tizen/browser/tizen_browser_parts.h +++ b/tizen/browser/tizen_browser_parts.h @@ -55,6 +55,8 @@ class TizenBrowserParts { CookieManager* GetCookieManager() { return cookie_manager_; } protected: + virtual void Quit(); + std::unique_ptr locale_manager_; std::unique_ptr resource_manager_; virtual ~TizenBrowserParts(); diff --git a/tizen/browser/tizen_web_contents_view.cc b/tizen/browser/tizen_web_contents_view.cc index f7b844b30..50cd65989 100644 --- a/tizen/browser/tizen_web_contents_view.cc +++ b/tizen/browser/tizen_web_contents_view.cc @@ -28,4 +28,16 @@ TizenWebContentsView::TizenWebContentsView(content::WebContents* web_contents, E elm_win_resize_object_add(window, evas_object_); } +void TizenWebContentsView::SetVisibility(bool state) { + if (!rwhv()) + return; + + rwhv()->SetPageVisibility(state); +} + +content::RenderWidgetHostViewEfl* TizenWebContentsView::rwhv() const { + return static_cast( + web_contents_->GetRenderWidgetHostView()); +} + } // namespace tizen diff --git a/tizen/browser/tizen_web_contents_view.h b/tizen/browser/tizen_web_contents_view.h index 41c1edf6b..0ad2441ed 100644 --- a/tizen/browser/tizen_web_contents_view.h +++ b/tizen/browser/tizen_web_contents_view.h @@ -23,10 +23,15 @@ #include +#include "content/browser/renderer_host/render_widget_host_view_efl.h" #include "content/public/common/context_menu_params.h" #include "content/public/browser/web_contents.h" #include "ui/gfx/geometry/rect.h" +namespace content { +class RenderWidgetHostViewEfl; +} + namespace tizen { class TizenWebContentsView { @@ -36,9 +41,11 @@ class TizenWebContentsView { void HandleLongPressGesture(const content::ContextMenuParams&) {} void ShowContextMenu(const content::ContextMenuParams&) {} void OnSelectionRectReceived(const gfx::Rect& selection_rect) const {} + void SetVisibility(bool state); Evas_Object* evas_object() { return evas_object_; } private: + content::RenderWidgetHostViewEfl* rwhv() const; content::WebContents* web_contents_; Evas_Object* evas_object_; };