Implemented getting of start url from resource manager 26/182226/1
authorPrathmesh <prathmesh.m@samsung.com>
Fri, 15 Jun 2018 07:04:53 +0000 (12:34 +0530)
committerPrathmesh <prathmesh.m@samsung.com>
Thu, 21 Jun 2018 10:06:21 +0000 (15:36 +0530)
- Change the url load logic from window create to on appcontrol
- Pass the AppControl event to Window(On top)
- Make start url ready when getpath() is called
- Refactor code to move under OS_TIZEN macro

Change-Id: I95e3b467578f363a175efe6d2a04c500f6f6793d
Signed-off-by: Prathmesh <prathmesh.m@samsung.com>
12 files changed:
atom/browser/api/atom_api_window.cc
atom/browser/api/atom_api_window.h
atom/browser/browser.cc
atom/browser/browser.h
atom/browser/browser_observer.h
atom/browser/native_window.cc
atom/browser/native_window.h
atom/browser/native_window_observer.h
tizen/common/resource_manager.cc
tizen/src/browser/api/wrt_api_core.cc
tizen/src/wrt_main.cc
wrt/src/web_window.js

index f19fbda..db323ae 100644 (file)
@@ -310,7 +310,7 @@ void Window::OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) {
 }
 #endif
 
-#if defined(USE_EFL)
+#if defined(OS_TIZEN)
 void Window::OnSuspend() {
   Emit("app-on-suspend");
 }
@@ -318,6 +318,10 @@ void Window::OnSuspend() {
 void Window::OnResume() {
   Emit("app-on-resume");
 }
+
+void Window::OnAppControl() {
+  Emit("app-on-appcontrol");
+}
 #endif
 
 // static
index 91b5633..b8eff85 100644 (file)
@@ -96,9 +96,10 @@ class Window : public mate::TrackableObject<Window>,
   void OnWindowMessage(UINT message, WPARAM w_param, LPARAM l_param) override;
   #endif
 
-#if defined(USE_EFL)
+#if defined(OS_TIZEN)
   void OnSuspend();
   void OnResume();
+  void OnAppControl();
 #endif
 
  private:
index 1110602..aca2f68 100644 (file)
@@ -44,6 +44,7 @@ Browser::~Browser() {
   WindowList::RemoveObserver(this);
 }
 
+#if defined(OS_TIZEN)
 const char* kAppControlMain = "http://tizen.org/appcontrol/operation/main";
 const char* kAppControlEventScript =
     "(function(){"
@@ -56,6 +57,7 @@ const char* kAppControlEventScript =
     "})()";
 const char* kDefaultCSPRule =
     "default-src *; script-src 'self'; style-src 'self'; object-src 'none';";
+#endif
 
 // static
 Browser* Browser::Get() {
@@ -260,19 +262,23 @@ void Browser::OnWindowAllClosed() {
   }
 }
 
+#if defined(OS_TIZEN)
 void Browser::Hide() {
-  for (BrowserObserver& observer : observers_)
-    observer.OnSuspend();
+  NativeWindow *last_window = WindowList::GetLastWindow();
+  if (last_window)
+    last_window->NotifySuspend();
 }
 
 void Browser::Show() {
-  for (BrowserObserver& observer : observers_)
-    observer.OnResume();
+  NativeWindow *last_window = WindowList::GetLastWindow();
+  if (last_window)
+    last_window->NotifyResume();
 }
 
 void Browser::Initialize() {
   auto appdata = common::ApplicationDataManager::GetCurrentAppData();
   resource_manager_.reset(new common::ResourceManager(appdata, locale_manager_.get()));
+  resource_manager_->set_base_resource_path(appdata->application_path());
 }
 
 void Browser::AppControl(std::unique_ptr<common::AppControl> appcontrol) {
@@ -312,9 +318,16 @@ void Browser::SendAppControlEvent() {
 void Browser::Launch(std::unique_ptr<common::AppControl> appcontrol) {
   launched_ = true;
 //To do:Implementation of relaunching of app
+  std::unique_ptr<common::ResourceManager::Resource> res =
+      resource_manager_->GetStartResource(appcontrol.get());
+  if (res)
+    start_url_ = resource_manager_->GetLocalizedPath(res->uri());
+
+  NativeWindow *last_window = WindowList::GetLastWindow();
+  if (last_window)
+    last_window->NotifyAppControl();
 }
 
-#if defined(OS_TIZEN)
 void Browser::SetSplashScreen() {
   auto appdata = common::ApplicationDataManager::GetCurrentAppData();
   Evas_Object* window_ = elm_win_util_standard_add("", "");
index 0e759e6..48365b8 100644 (file)
 #include "base/strings/string16.h"
 #include "base/values.h"
 #include "native_mate/arguments.h"
+#if defined(OS_TIZEN)
+#include "atom/browser/splash_screen.h"
 #include "tizen/common/app_control.h"
 #include "tizen/common/application_data.h"
 #include "tizen/common/resource_manager.h"
 #include "tizen/common/locale_manager.h"
-#if defined(OS_TIZEN)
-#include "atom/browser/splash_screen.h"
 #endif  // defined(OS_TIZEN)
 
 
@@ -98,7 +98,7 @@ class Browser : public WindowListObserver {
 
   // Set/Get the badge count.
   bool SetBadgeCount(int count);
-  bool launched() const { return launched_; }
+
   int GetBadgeCount();
 
   // Set/Get the login item settings of the app
@@ -114,14 +114,16 @@ class Browser : public WindowListObserver {
   void SetLoginItemSettings(LoginItemSettings settings);
   LoginItemSettings GetLoginItemSettings(const LoginItemSettings& options);
 
+#if defined(OS_TIZEN)
   void Hide();
   void Show();
   void AppControl(std::unique_ptr<common::AppControl> appcontrol);
   void Launch(std::unique_ptr<common::AppControl> appcontrol);
   void SendAppControlEvent();
-#if defined(OS_TIZEN)
   void SetSplashScreen();
   void HideSplashScreen(int reason);
+  bool launched() const { return launched_; }
+  std::string StartURL() const { return start_url_;}
 #endif  // defined(OS_TIZEN)
 
 #if defined(OS_MACOSX)
@@ -263,6 +265,7 @@ class Browser : public WindowListObserver {
   std::unique_ptr<common::ResourceManager> resource_manager_;
   std::unique_ptr<common::LocaleManager> locale_manager_;
   std::unique_ptr<SplashScreen> splash_screen_;
+  std::string start_url_;
   bool launched_;
   bool is_electron_launch_;
 #endif
index b5760ec..88a50a9 100644 (file)
@@ -55,8 +55,6 @@ class BrowserObserver {
   // The browser's accessibility suppport has changed.
   virtual void OnAccessibilitySupportChanged() {}
 
-  virtual void OnSuspend() {}
-  virtual void OnResume() {}
 #if defined(OS_MACOSX)
   // The browser wants to resume a user activity via handoff. (macOS only)
   virtual void OnContinueUserActivity(
index 9e2c11a..4320eb8 100644 (file)
@@ -605,6 +605,26 @@ void NativeWindow::NotifyWindowMessage(
 }
 #endif
 
+#if defined(OS_TIZEN)
+void NativeWindow::NotifySuspend()
+{
+  for (NativeWindowObserver& observer : observers_)
+    observer.OnSuspend();
+}
+
+void NativeWindow::NotifyResume()
+{
+  for (NativeWindowObserver& observer : observers_)
+    observer.OnResume();
+}
+
+void NativeWindow::NotifyAppControl()
+{
+  for (NativeWindowObserver& observer : observers_)
+    observer.OnAppControl();
+}
+#endif
+
 std::unique_ptr<SkRegion> NativeWindow::DraggableRegionsToSkRegion(
     const std::vector<DraggableRegion>& regions) {
   std::unique_ptr<SkRegion> sk_region(new SkRegion);
index 654b68e..0e07787 100644 (file)
@@ -248,6 +248,11 @@ class NativeWindow : public base::SupportsUserData,
   void NotifyWindowMessage(UINT message, WPARAM w_param, LPARAM l_param);
   #endif
 
+#if defined(OS_TIZEN)
+  void NotifySuspend();
+  void NotifyResume();
+  void NotifyAppControl();
+#endif
   void AddObserver(NativeWindowObserver* obs) {
     observers_.AddObserver(obs);
   }
index 8c908dc..96ac375 100644 (file)
@@ -92,6 +92,13 @@ class NativeWindowObserver {
 
   // Called on Windows when App Commands arrive (WM_APPCOMMAND)
   virtual void OnExecuteWindowsCommand(const std::string& command_name) {}
+
+#if defined(OS_TIZEN)
+  // Tizen
+  virtual void OnSuspend() {}
+  virtual void OnResume() {}
+  virtual void OnAppControl() {}
+#endif
 };
 
 }  // namespace atom
index e177ab5..22fa8bf 100644 (file)
@@ -258,6 +258,12 @@ std::unique_ptr<ResourceManager::Resource> ResourceManager::GetMatchedResource(
 
 std::unique_ptr<ResourceManager::Resource> ResourceManager::GetStartResource(
     const AppControl* app_control) {
+
+  if (!app_control) {
+    LOGGER(ERROR) << "ERROR: No app control";
+    return GetDefaultResource();
+  }
+
   std::string operation = app_control->operation();
   if (operation.empty()) {
     LOGGER(ERROR) << "operation(mandatory) is NULL";
index c185cc9..5e1a0d5 100644 (file)
@@ -31,16 +31,28 @@ std::string WebRuntime::GetMessage() const {
 }
 
 std::string WebRuntime::GetPath() const {
+  atom::Browser* browser_model = atom::Browser::Get();
+  if (browser_model) {
+    std::string res = browser_model->StartURL();
+    if (!res.empty()) {
+      LOG(ERROR) << "PWRT Start URL = " << res;
+      return res;
+    }
+  }
+
+  // Fall back: This code must ideally not execute
   auto app_data = common::ApplicationDataManager::GetCurrentAppData();
   if (!app_data) {
     return std::string();
   }
-  std::string checkpath = app_data->content_info()->src();
-  if (std::string::npos != checkpath.find("http")) {
-    return checkpath;
-  }
 
-  // TODO: Use resource-manager's GetStartResource() for localized urls
+  if (app_data->content_info()) {
+    std::string checkpath = app_data->content_info()->src();
+    if (std::string::npos != checkpath.find("http")) {
+      LOG(ERROR) << "PWRT Start Url = " << checkpath;
+      return checkpath;
+    }
+  }
   base::FilePath path(app_data->application_path());
   if (app_data->content_info()) {
     path = path.Append(app_data->content_info()->src());
@@ -48,6 +60,7 @@ std::string WebRuntime::GetPath() const {
     path = path.Append("index.html");
   }
   std::string app_path = "file://" + path.value();
+  LOG(ERROR) << "PWRT Start Url = " << app_path;
   return app_path;
 }
 
index fc0320d..3bfb612 100644 (file)
@@ -53,6 +53,9 @@ bool hasTizenPackageID(int argc, const char* const* argv) {
     if (0 == strncmp(argv[0], "/opt/usr/globalapps/", strlen("/opt/usr/globalapps/"))) {
       return true;
     }
+    if (0 == strncmp(argv[0], "/opt/usr/apps/", strlen("/opt/usr/apps/"))) {
+      return true;
+    }
   }
   return false;
 }
index fe6c3b9..039b294 100644 (file)
@@ -24,7 +24,6 @@ class WebWindow {
         this.handleEvents(winopt);
         this.appID = options.appID;
         webwindow_debug('this.appID ' + this.appID);
-        this.setUrl(options.path);
     }
     getBrowserWindowOption() {
         return {
@@ -120,6 +119,10 @@ class WebWindow {
             webwindow_debug('WebWindow : app-on-resume');
             events.emit(WAS_EVENT.WEBAPPLICATION.RESUME, 'web_window', self.mainWindow.id);
         });
+        this.mainWindow.on('app-on-appcontrol', function() {
+            webwindow_debug('WebWindow : app-on-appcontrol');
+            self.setUrl('');
+        });
         this.mainWindow.webContents.on('crashed', function() {
             webwindow_debug('WebWindow : webContents crashed');
             self.webApplication.exit(100);
@@ -219,6 +222,7 @@ class WebWindow {
         });
     }
     setUrl(path) {
+        webwindow_debug('WebWindow : Set URL');
         if (path && (path.trim() != '')) {
             this.mainWindow.loadURL(path);
         } else {