Alter visibility of a web page as per app loop callbacks 34/195434/2
authorsurya.kumar7 <surya.kumar7@samsung.com>
Thu, 13 Dec 2018 11:02:19 +0000 (16:32 +0530)
committersurya.kumar7 <surya.kumar7@samsung.com>
Thu, 13 Dec 2018 11:50:43 +0000 (17:20 +0530)
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 <surya.kumar7@samsung.com>
atom/browser/browser.cc
atom/browser/browser.h
atom/browser/native_window_efl.cc
atom/browser/native_window_efl.h
atom/browser/window_list.cc
tizen/browser/tizen_browser_parts.cc
tizen/browser/tizen_browser_parts.h
tizen/browser/tizen_web_contents_view.cc
tizen/browser/tizen_web_contents_view.h

index 09c330473e22555abe1229454ca8c869eb38c0ea..288038329dedd4b0a93ef855c13a36f0cf5c6627 100644 (file)
@@ -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) {
index 94b0e267a903b6c58375b840f7b9b76d72133e59..988cfd1166cf10b8d0b9b49874c52931f852635a 100644 (file)
@@ -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);
index 25feab1f76f76e2a897782da831feca6de35d75b..954c8d9aeae57676501296cc1304a821c5548528 100644 (file)
@@ -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;
 }
 
index 5d93937bb1dc3bdfd3d4a4641e9e6b321613d1e1..7d91c63cb80f80949527df0a58d826bbfe724a22 100644 (file)
 #include <vector>
 
 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_;
index e6fa1a999a009ef00fe86c2bdca7fef6df804176..7b8677b23ae63ff07e8e0e5bb1e2f053859e0edf 100644 (file)
@@ -12,6 +12,8 @@
 
 namespace atom {
 
+bool is_closing_ = false;
+
 // static
 base::LazyInstance<base::ObserverList<WindowListObserver>>::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()
index c8cfd6d8cb2f1fe236bc8a4a86b37f616e72c8e3..6e7673f36860cf1a3fd05988fcd973d9f9b4f248 100644 (file)
@@ -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<common::AppControl> appcontrol) {
   tizen::NativeWebRuntime::GetInstance().StartApplication();
 }
 
+void TizenBrowserParts::Quit() {
+  atom::WindowList::GetLastWindow()->Hide();
+}
 
 } // namespace tizen
index 3ec1f79243b3b551a9586ed5bfbb00f69ccb4a8b..951b7e7d39ae3773b66fc573e78c191b7c572d38 100644 (file)
@@ -55,6 +55,8 @@ class TizenBrowserParts {
   CookieManager* GetCookieManager() { return cookie_manager_; }
 
  protected:
+  virtual void Quit();
+
   std::unique_ptr<common::LocaleManager> locale_manager_;
   std::unique_ptr<common::ResourceManager> resource_manager_;
   virtual ~TizenBrowserParts();
index f7b844b304a46ffa51c945441f5a8354e2fea781..50cd6598956b119445c793e415af1d427e14b497 100644 (file)
@@ -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<content::RenderWidgetHostViewEfl*>(
+      web_contents_->GetRenderWidgetHostView());
+}
+
 } // namespace tizen
index 41c1edf6bf3161339577eb4f036b61feb1b0a1b3..0ad2441edf14f3e2898235a5bd4c858e2bbf06c6 100644 (file)
 
 #include <Evas.h>
 
+#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_;
 };