Reduce window creation to one 25/193825/5
authorsurya.kumar7 <surya.kumar7@samsung.com>
Thu, 29 Nov 2018 16:12:14 +0000 (21:42 +0530)
committersurya.kumar7 <surya.kumar7@samsung.com>
Tue, 4 Dec 2018 14:46:03 +0000 (20:16 +0530)
Since app life cycle events are bound only to the first elm window
created, many side effects were observed. Restricted the elm windows to
one and mapped any web views being created to that.

Change-Id: I4fda238703ee3af82c1104512b5a14dfaec52a4a
Signed-off-by: surya.kumar7 <surya.kumar7@samsung.com>
atom/browser/atom_browser_client.cc
atom/browser/atom_browser_client.h
atom/browser/atom_javascript_modal_dialog_efl.cc
atom/browser/atom_javascript_modal_dialog_efl.h
atom/browser/native_window_efl.cc
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 dffa0c5c81705e308bbe37d9b1941ad2b33ee892..d41d5be70f2784fb31c079a334f41fad9cd6c3c7 100644 (file)
@@ -423,7 +423,7 @@ void AtomBrowserClient::RenderProcessHostDestroyed(
 #if defined(OS_TIZEN)
 content::WebContentsViewDelegate* AtomBrowserClient::GetWebContentsViewDelegate(
     content::WebContents* web_contents) {
-  auto tizen_view = new tizen::TizenWebContentsView(web_contents);
+  auto tizen_view = new tizen::TizenWebContentsView(web_contents, atom::Browser::Get()->window());
   std::unique_ptr<tizen::TizenWebContentsView> p(tizen_view);
   tizen_views_.push_back(std::move(p));
   return new tizen::TizenWebContentsViewDelegate(tizen_view);
@@ -438,7 +438,8 @@ void AtomBrowserClient::RemoveTizenWebContentsView(content::WebContents* web_con
       tizen_views_.end());
 }
 
-tizen::TizenWebContentsView* AtomBrowserClient::GetTizenWebContentsView(content::WebContents* web_contents) {
+tizen::TizenWebContentsView* AtomBrowserClient::GetTizenWebContentsView(
+    const content::WebContents* web_contents) {
   for (auto& it: tizen_views_) {
     if (it->web_contents() == web_contents)
       return it.get();
index efdf9577b0d9bc7818a6470ae3e4841e38a92714..8445b11552481289289e41cd72e0db4343e25819 100644 (file)
@@ -55,7 +55,7 @@ class AtomBrowserClient : public brightray::BrowserClient,
       const std::vector<std::string>& schemes);
 
 #if defined(OS_TIZEN)
-  static tizen::TizenWebContentsView* GetTizenWebContentsView(content::WebContents* web_contents);
+  static tizen::TizenWebContentsView* GetTizenWebContentsView(const content::WebContents* web_contents);
   static void RemoveTizenWebContentsView(content::WebContents* web_contents);
 #endif
 
index 83d1626f6a316f75533413c1d4bb144837ee97ae..c2611fb8f54da9d90f95fc1475faa4731a60146b 100644 (file)
@@ -3,6 +3,8 @@
 // found in the LICENSE file.
 
 #include "atom/browser/atom_javascript_modal_dialog_efl.h"
+#include "atom/browser/browser.h"
+#include "atom/browser/native_window_efl.h"
 #include "base/files/file_path.h"
 #include "base/path_service.h"
 #include "base/strings/utf_string_conversions.h"
@@ -42,8 +44,7 @@ AtomJavaScriptModalDialogEfl::AtomJavaScriptModalDialogEfl(
     const base::string16& message_text,
     const base::string16& default_prompt_text,
     const content::JavaScriptDialogManager::DialogClosedCallback& callback)
-    : web_view_(atom::NativeWindow::FromWebContents(web_contents)),
-      window_(nullptr),
+    : window_(nullptr),
       conformant_(nullptr),
       popup_(nullptr),
       prompt_entry_(nullptr),
@@ -73,7 +74,7 @@ static void PromptEnterKeyDownCallback(void* data,
 }
 
 bool AtomJavaScriptModalDialogEfl::ShowJavaScriptDialog() {
-  Evas_Object* top_window = static_cast<atom::NativeWindowEfl*>(web_view_)->evas_object();
+  Evas_Object* top_window = atom::Browser::Get()->window();
 
   popup_ = CreatePopupOnNewWindow(top_window);
   if (!popup_)
index 655fee648b11e9d9ff3aa069f36e8471c1a686a0..a3044722d84e4aa20fcd2a78001568d99400b325 100644 (file)
@@ -9,7 +9,6 @@
 #include <Evas.h>
 #include <string>
 
-#include "atom/browser/native_window_efl.h"
 #include "base/strings/string16.h"
 #include "content/public/browser/javascript_dialog_manager.h"
 #include "url/gurl.h"
@@ -70,7 +69,6 @@ class AtomJavaScriptModalDialogEfl {
                                    void* event_info);
   static void OkButtonCallback(void* data, Evas_Object* obj, void* event_info);
 
-  atom::NativeWindow* web_view_;
   Evas_Object* window_;
   Evas_Object* conformant_;
   Evas_Object* popup_;
index 1fac541876b23103d4298f7fdd18efcd7f20d23d..25feab1f76f76e2a897782da831feca6de35d75b 100644 (file)
@@ -13,6 +13,8 @@
 #include <watch_app_efl.h>
 #endif
 
+#include "atom/browser/browser.h"
+#include "atom/browser/atom_browser_client.h"
 #include "atom/common/options_switches.h"
 #include "base/command_line.h"
 #include "content/public/browser/web_contents.h"
@@ -35,7 +37,6 @@ namespace atom {
 
 namespace {
 
-std::map<const content::WebContents*, Evas_Object*> window_map_;
 int window_width_;
 int window_height_;
 
@@ -68,28 +69,7 @@ const char* kMenuKeyEventScript =
 
 Evas_Object* NativeWindowEfl::GetHostWindowDelegate(const content::WebContents* web_contents) {
   LOG(ERROR) << "NativeWindowEfl::GetHostWindowDelegate";
-  if (window_map_.find(web_contents) != window_map_.end())
-    return window_map_[web_contents];
-
-  Evas_Object* win = NULL;
-  auto app_data = common::ApplicationDataManager::GetCurrentAppData();
-#if !defined(OS_TIZEN_TV_PRODUCT)
-  if (app_data->app_type() == common::ApplicationData::WATCH) {
-    elm_config_accel_preference_set("opengl");
-    watch_app_get_elm_win(&win);
-    elm_win_alpha_set(win, EINA_TRUE);
-    evas_object_render_op_set(win, EVAS_RENDER_COPY);
-  }
-  else {
-#endif
-    win = elm_win_util_standard_add("", "");
-    elm_win_autodel_set(win, EINA_TRUE);
-#if !defined(OS_TIZEN_TV_PRODUCT)
-  }
-#endif
-
-  window_map_[web_contents] = win;
-  return win;
+  return atom::AtomBrowserClient::GetTizenWebContentsView(web_contents)->evas_object();
 }
 
 NativeWindowEfl::NativeWindowEfl(
@@ -103,21 +83,19 @@ NativeWindowEfl::NativeWindowEfl(
 
   DCHECK(window_);
 
-  elm_win_screen_size_get(window_, NULL, NULL, &window_width_, &window_height_);
+  atom::Browser::Get()->GetWindowDimensions(window_width_, window_height_);
   evas_object_smart_callback_add(window_, "delete,request",
       OnWindowDeleteRequest, this);
   evas_object_resize(window_, window_width_, window_height_);
 
-  Evas_Object* box = elm_box_add(window_);
-  evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
-  evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
-  elm_win_resize_object_add(window_, box);
-  evas_object_show(box);
+  evas_object_size_hint_align_set(window_, EVAS_HINT_FILL, EVAS_HINT_FILL);
+  evas_object_size_hint_weight_set(window_, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+  evas_object_show(window_);
 
   web_view_ = static_cast<Evas_Object*>(web_contents()->GetNativeView());
   evas_object_size_hint_align_set(web_view_, EVAS_HINT_FILL, EVAS_HINT_FILL);
   evas_object_size_hint_weight_set(web_view_, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
-  elm_box_pack_end(box, web_view_);
+  elm_box_pack_end(window_, web_view_);
 
   evas_object_resize(web_view_, window_width_, window_height_);
 
@@ -128,21 +106,6 @@ NativeWindowEfl::NativeWindowEfl(
       &HWBackKeyCallback, this);
   eext_object_event_callback_add(web_view_, EEXT_CALLBACK_MORE,
       &HWMoreKeyCallback, this);
-
-  if (elm_win_wm_rotation_supported_get(window_)) {
-    int rots[4] = {0, 90, 180, 270};
-    elm_win_wm_rotation_available_rotations_set(window_,
-        (const int *)(&rots), 4);
-
-    // Registering nullptr as Callback, but window will rotate without error.
-    // Is it right action?
-    evas_object_smart_callback_add(window_,
-                                   "wm,rotation,changed",
-                                   nullptr,
-                                   this);
-  } else {
-    LOG(ERROR) << __func__ << " Window does not support rotation";
-  }
 #endif
 
 #if defined(OS_TIZEN_TV_PRODUCT)
index 39b91b23c818e2f5cf9d94305518c199237a794e..e6fa1a999a009ef00fe86c2bdca7fef6df804176 100644 (file)
@@ -46,6 +46,8 @@ bool WindowList::IsEmpty() {
 // static
 void WindowList::AddWindow(NativeWindow* window) {
   DCHECK(window);
+  if (GetLastWindow())
+    GetLastWindow()->Hide();
   // Push |window| on the appropriate list instance.
   WindowVector& windows = GetInstance()->windows_;
   windows.push_back(window);
@@ -59,7 +61,8 @@ void WindowList::RemoveWindow(NativeWindow* window) {
   WindowVector& windows = GetInstance()->windows_;
   windows.erase(std::remove(windows.begin(), windows.end(), window),
                 windows.end());
-
+  if (GetLastWindow())
+    GetLastWindow()->Show();
   for (WindowListObserver& observer : observers_.Get())
     observer.OnWindowRemoved(window);
 
index e87d34d81512ad0ff41a14e9e8e534d459e07dac..e8292c36753c7710747fe9e3ebf6312a586f5d42 100644 (file)
  */
 
 #include <app.h>
+#include <Elementary.h>
+#if !defined(OS_TIZEN_TV_PRODUCT)
+#include <watch_app_efl.h>
+#endif
 
 #include "atom/common/api/api_messages.h"
 #include "common/string_utils.h"
@@ -68,6 +72,51 @@ TizenBrowserParts::TizenBrowserParts()
       is_suspended_(false) {
 }
 
+TizenBrowserParts::~TizenBrowserParts() {
+  evas_object_del(window_);
+  window_ = nullptr;
+}
+
+void TizenBrowserParts::InitializeWindow() {
+  auto app_data = common::ApplicationDataManager::GetCurrentAppData();
+#if !defined(OS_TIZEN_TV_PRODUCT)
+  if (app_data->app_type() == common::ApplicationData::WATCH) {
+    elm_config_accel_preference_set("opengl");
+    watch_app_get_elm_win(&window_);
+    elm_win_alpha_set(window_, EINA_TRUE);
+    evas_object_render_op_set(window_, EVAS_RENDER_COPY);
+  }
+  else {
+#endif
+    window_ = elm_win_util_standard_add("", "");
+    elm_win_autodel_set(window_, EINA_TRUE);
+#if !defined(OS_TIZEN_TV_PRODUCT)
+  }
+#endif
+  int window_width_, window_height_;
+  elm_win_screen_size_get(window_, NULL, NULL, &window_width_, &window_height_);
+  evas_object_resize(window_, window_width_, window_height_);
+  evas_object_show(window_);
+  if (elm_win_wm_rotation_supported_get(window_)) {
+    int rots[4] = {0, 90, 180, 270};
+    elm_win_wm_rotation_available_rotations_set(window_,
+        (const int *)(&rots), 4);
+
+    // Registering nullptr as Callback, but window will rotate without error.
+    // Is it right action?
+    evas_object_smart_callback_add(window_,
+                                   "wm,rotation,changed",
+                                   nullptr,
+                                   this);
+  } else {
+    LOG(ERROR) << __func__ << " Window does not support rotation";
+  }
+}
+
+void TizenBrowserParts::GetWindowDimensions(int& width, int& height) {
+  elm_win_screen_size_get(window_, NULL, NULL, &width, &height);
+}
+
 void TizenBrowserParts::Initialize() {
   app_data_ = common::ApplicationDataManager::GetCurrentAppData();
   resource_manager_.reset(new common::ResourceManager(app_data_, locale_manager_.get()));
@@ -107,6 +156,7 @@ void TizenBrowserParts::Initialize() {
   }
 
   tizen::VibrationManager::CreateInstance();
+  InitializeWindow();
 }
 
 void TizenBrowserParts::ClearCookie() {
index fcce2d944c544956eaba621852c607005bb8aa87..6d53d10c4dd20e85ea45133e891927002d437464 100644 (file)
@@ -17,6 +17,8 @@
 #ifndef TIZEN_BROWSER_TIZEN_BROWSER_PARTS_H_
 #define TIZEN_BROWSER_TIZEN_BROWSER_PARTS_H_
 
+#include <Evas.h>
+
 #include "content/public/browser/render_view_host.h"
 #include "tizen/common/app_control.h"
 #include "tizen/common/application_data.h"
@@ -39,6 +41,8 @@ class TizenBrowserParts {
   std::string GetEncodingType();
   bool ShouldAllowNavigation(const std::string &url);
   void Initialize();
+  void GetWindowDimensions(int& width, int& height);
+  Evas_Object* window() { return window_; }
 
   void ClearCookie();
   CookieManager* GetCookieManager() { return cookie_manager_; }
@@ -46,15 +50,16 @@ class TizenBrowserParts {
  protected:
   std::unique_ptr<common::LocaleManager> locale_manager_;
   std::unique_ptr<common::ResourceManager> resource_manager_;
-  virtual ~TizenBrowserParts() {}
+  virtual ~TizenBrowserParts();
 
  private:
 #if defined(TIZEN_VIDEO_HOLE)
   void EnableVideoHole(content::RenderViewHost* render_view_host);
 #endif
-
+  void InitializeWindow();
   void SetLongPollingTimeout(content::RenderViewHost* render_view_host);
 
+  Evas_Object* window_;
   common::ApplicationData* app_data_;
   CookieManager* cookie_manager_;
   int security_model_version_;
index 53a77c35e83f166ca741f54a33e7418e189be94b..f7b844b304a46ffa51c945441f5a8354e2fea781 100644 (file)
  *    limitations under the License.
  */
 
+#include <Elementary.h>
+
 #include "tizen_web_contents_view.h"
 
 namespace tizen {
 
-TizenWebContentsView::TizenWebContentsView(content::WebContents* web_contents)
-    : web_contents_(web_contents) {}
+TizenWebContentsView::TizenWebContentsView(content::WebContents* web_contents, Evas_Object* window)
+    : web_contents_(web_contents) {
+  evas_object_ = elm_box_add(window);
+  evas_object_size_hint_align_set(evas_object_, EVAS_HINT_FILL, EVAS_HINT_FILL);
+  evas_object_size_hint_weight_set(evas_object_, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+  elm_win_resize_object_add(window, evas_object_);
+}
 
 } // namespace tizen
index 0b5999f9353f096cd92f7873c7cd4d5124748af8..41c1edf6bf3161339577eb4f036b61feb1b0a1b3 100644 (file)
@@ -21,6 +21,8 @@
 #ifndef TIZEN_BROWSER_TIZEN_WEB_CONTENTS_VIEW_H_
 #define TIZEN_BROWSER_TIZEN_WEB_CONTENTS_VIEW_H_
 
+#include <Evas.h>
+
 #include "content/public/common/context_menu_params.h"
 #include "content/public/browser/web_contents.h"
 #include "ui/gfx/geometry/rect.h"
@@ -29,14 +31,16 @@ namespace tizen {
 
 class TizenWebContentsView {
  public:
-  TizenWebContentsView(content::WebContents* web_contents);
+  TizenWebContentsView(content::WebContents* web_contents, Evas_Object* window);
   content::WebContents* web_contents() { return web_contents_; }
   void HandleLongPressGesture(const content::ContextMenuParams&) {}
   void ShowContextMenu(const content::ContextMenuParams&) {}
   void OnSelectionRectReceived(const gfx::Rect& selection_rect) const {}
+  Evas_Object* evas_object() { return evas_object_; }
 
  private:
   content::WebContents* web_contents_;
+  Evas_Object* evas_object_;
 };
 
 } // namespace tizen