From 08923900ea8c54f7fd42a85ace2bff2fa7fa08fb Mon Sep 17 00:00:00 2001 From: deepti Date: Fri, 11 May 2018 16:39:46 +0530 Subject: [PATCH] Initial Implementation of AppControl Function Handled condition of resetting app. Implemented SendAppControlEvent() for execution of AppControlEventscript. Change-Id: I98b9420a6f5076de598dbdbbdd0968806fc1f34f Signed-off-by: deepti --- atom/browser/browser.cc | 51 ++++++++++++++++++++++++++++++++++++++++++--- atom/browser/browser.h | 1 + atom/browser/window_list.cc | 7 +++++++ atom/browser/window_list.h | 2 +- 4 files changed, 57 insertions(+), 4 deletions(-) diff --git a/atom/browser/browser.cc b/atom/browser/browser.cc index 3ebba72..9efce42 100644 --- a/atom/browser/browser.cc +++ b/atom/browser/browser.cc @@ -14,9 +14,12 @@ #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 appcontrol) { std::unique_ptr 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 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 appcontrol) { launched_ = true; //To do:Implementation of relaunching of app } - #if defined(OS_TIZEN) void Browser::SetSplashScreen() { common::CommandLine* runtime_cmd = common::CommandLine::ForCurrentProcess(); diff --git a/atom/browser/browser.h b/atom/browser/browser.h index 362bfaf..c089fff 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -125,6 +125,7 @@ class Browser : public WindowListObserver { void Show(); void AppControl(std::unique_ptr appcontrol); void Launch(std::unique_ptr appcontrol); + void SendAppControlEvent(); #if defined(OS_TIZEN) void SetSplashScreen(); void HideSplashScreen(int reason); diff --git a/atom/browser/window_list.cc b/atom/browser/window_list.cc index 374389e..39b91b2 100644 --- a/atom/browser/window_list.cc +++ b/atom/browser/window_list.cc @@ -32,6 +32,13 @@ WindowList::WindowVector WindowList::GetWindows() { } // static +NativeWindow* WindowList::GetLastWindow() { + if (!IsEmpty()) + return GetInstance()->windows_.back(); + else return NULL; +} + +// static bool WindowList::IsEmpty() { return GetInstance()->windows_.empty(); } diff --git a/atom/browser/window_list.h b/atom/browser/window_list.h index e336c80..bffac13 100644 --- a/atom/browser/window_list.h +++ b/atom/browser/window_list.h @@ -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); -- 2.7.4