Initial Implementation of AppControl Function 20/178720/4
authordeepti <d.saraswat@samsung.com>
Fri, 11 May 2018 11:09:46 +0000 (16:39 +0530)
committerjaekuk lee <juku1999@samsung.com>
Wed, 16 May 2018 02:13:06 +0000 (02:13 +0000)
Handled condition of resetting app.
Implemented SendAppControlEvent() for execution of AppControlEventscript.

Change-Id: I98b9420a6f5076de598dbdbbdd0968806fc1f34f
Signed-off-by: deepti <d.saraswat@samsung.com>
atom/browser/browser.cc
atom/browser/browser.h
atom/browser/window_list.cc
atom/browser/window_list.h

index 3ebba72a142f20d8c9ae277a84405cdc7840aae5..9efce42a3f10b745e20808a1daa4f3042dc44bf7 100644 (file)
 #include "base/files/file_util.h"
 #include "base/path_service.h"
 #include "base/run_loop.h"
+#include "base/strings/string16.h"
+#include "base/strings/utf_string_conversions.h"
+#include "base/values.h"
 #include "base/threading/thread_task_runner_handle.h"
 #include "brightray/browser/brightray_paths.h"
-
+#include "content/public/browser/render_frame_host.h"
 #if defined(OS_TIZEN)
 #include "tizen/common/command_line.h"
 #include "tizen/common/application_data.h"
@@ -43,6 +46,19 @@ Browser::~Browser() {
   WindowList::RemoveObserver(this);
 }
 
+const char* kAppControlMain = "http://tizen.org/appcontrol/operation/main";
+const char* kAppControlEventScript =
+    "(function(){"
+    "var __event = document.createEvent(\"CustomEvent\");\n"
+    "__event.initCustomEvent(\"appcontrol\", true, true, null);\n"
+    "document.dispatchEvent(__event);\n"
+    "\n"
+    "for(var i=0; i < window.frames.length; i++)\n"
+    "{ window.frames[i].document.dispatchEvent(__event); }"
+    "})()";
+const char* kDefaultCSPRule =
+    "default-src *; script-src 'self'; style-src 'self'; object-src 'none';";
+
 // static
 Browser* Browser::Get() {
   if (AtomBrowserMainParts::Get())
@@ -276,14 +292,43 @@ void Browser::AppControl(std::unique_ptr<common::AppControl> appcontrol) {
   std::unique_ptr<common::ResourceManager::Resource> res =
       resource_manager_->GetStartResource(appcontrol.get());
   bool do_reset = res->should_reset();
-//To do: Implementation of reset case according to parsed config file parameter.
+  NativeWindow *last_window= WindowList::GetLastWindow();
+  std::string localized_page = res->uri();
+  if(!do_reset)
+  {
+  std::string current_page=last_window->web_contents()->GetURL().spec();
+  if (current_page != localized_page) {
+    do_reset = true;
+  } else {
+    SendAppControlEvent();
+  }
+  }
+  if (do_reset && (appcontrol->operation() == kAppControlMain)) {
+    do_reset = false;
+    SendAppControlEvent();
+  }
+  if (do_reset) {
+     //To do :Implementation of ClearViewStack(), SetupWebWindow(),SetupWebWindowCompatibilitySettings() function
+  }
+}
+
+void Browser::SendAppControlEvent() {
+  std::vector<NativeWindow*> WindowVector;
+  WindowVector=WindowList::GetWindows();
+  NativeWindow *last_window= WindowList::GetLastWindow();
+  if (WindowVector.size() > 0 && last_window != NULL) {
+      content::RenderFrameHost* rfh = last_window->web_contents()->GetMainFrame();
+  if (rfh) {
+      rfh->ExecuteJavaScriptWithUserGestureForTests(
+      base::UTF8ToUTF16(kAppControlEventScript));
+    }
+   }
 }
 
 void Browser::Launch(std::unique_ptr<common::AppControl> appcontrol) {
   launched_ = true;
 //To do:Implementation of relaunching of app
 }
-
 #if defined(OS_TIZEN)
 void Browser::SetSplashScreen() {
   common::CommandLine* runtime_cmd = common::CommandLine::ForCurrentProcess();
index 362bfaf1335b07112c81157a8f7342f6c13d845d..c089ffff05cc46a25268c0aa9be455af505b20b2 100644 (file)
@@ -125,6 +125,7 @@ class Browser : public WindowListObserver {
   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);
index 374389e0a78633e81a3971b97e5b64958b575d0d..39b91b23c818e2f5cf9d94305518c199237a794e 100644 (file)
@@ -31,6 +31,13 @@ WindowList::WindowVector WindowList::GetWindows() {
   return GetInstance()->windows_;
 }
 
+// static
+NativeWindow* WindowList::GetLastWindow() {
+  if (!IsEmpty())
+    return GetInstance()->windows_.back();
+  else return NULL;
+}
+
 // static
 bool WindowList::IsEmpty() {
   return GetInstance()->windows_.empty();
index e336c8073dc86e2a3124457afe009b703b667658..bffac133cc66010d9afef29e806e9f23bbf0c3c8 100644 (file)
@@ -22,7 +22,7 @@ class WindowList {
 
   static WindowVector GetWindows();
   static bool IsEmpty();
-
+  static NativeWindow* GetLastWindow();
   // Adds or removes |window| from the list it is associated with.
   static void AddWindow(NativeWindow* window);
   static void RemoveWindow(NativeWindow* window);