From: surya.kumar7 Date: Mon, 10 Dec 2018 15:43:15 +0000 (+0530) Subject: Refactor atom::Browser and move |OS_TIZEN| functions to tizen::TizenBrowserParts X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9eda43653b3bad48161bf085a30aba8d7936a3dc;p=platform%2Fframework%2Fweb%2Fcrosswalk-tizen.git Refactor atom::Browser and move |OS_TIZEN| functions to tizen::TizenBrowserParts atom::Browser has been relieved of having Tizen related implementations as tizen::TizenBrowserparts should be responsible for such tasks Fixed a few potential |!OS_TIZEN| macro related build errors Change-Id: I8e9a7995518a6512ac039f7d66f009245b926b10 Signed-off-by: surya.kumar7 --- diff --git a/atom/app/ui_runtime.cc b/atom/app/ui_runtime.cc index 694d72419..d80f4aae0 100644 --- a/atom/app/ui_runtime.cc +++ b/atom/app/ui_runtime.cc @@ -34,13 +34,7 @@ UiRuntime::~UiRuntime() {} bool UiRuntime::OnCreate() { LOG(INFO) << "OnCreate()"; - auto appdata = common::ApplicationDataManager::GetCurrentAppData(); - auto browser = atom::Browser::Get(); - browser->Initialize(); - if (appdata->splash_screen_info()) { - browser->SetSplashScreen(); - } - + atom::Browser::Get()->Initialize(); return true; } @@ -51,12 +45,12 @@ void UiRuntime::OnTerminate() { void UiRuntime::OnPause() { LOG(INFO) << "OnPause()"; - atom::Browser::Get()->Hide(); + atom::Browser::Get()->Suspend(); } void UiRuntime::OnResume() { LOG(INFO) << "OnResume()"; - atom::Browser::Get()->Show(); + atom::Browser::Get()->Resume(); } void UiRuntime::OnAppControl(app_control_h app_control) { diff --git a/atom/app/watch_runtime.cc b/atom/app/watch_runtime.cc index d32b51fd4..0a82781fd 100644 --- a/atom/app/watch_runtime.cc +++ b/atom/app/watch_runtime.cc @@ -35,11 +35,7 @@ WatchRuntime::~WatchRuntime() {} bool WatchRuntime::OnCreate() { LOG(INFO) << "OnCreate()"; - auto appdata = common::ApplicationDataManager::GetCurrentAppData(); - auto browser = atom::Browser::Get(); - if (appdata->splash_screen_info()) { - browser->SetSplashScreen(); - } + atom::Browser::Get()->Initialize(); return true; } @@ -49,12 +45,12 @@ void WatchRuntime::OnTerminate() { void WatchRuntime::OnPause() { LOG(INFO) << "OnPause()"; - atom::Browser::Get()->Hide(); + atom::Browser::Get()->Suspend(); } void WatchRuntime::OnResume() { LOG(INFO) << "OnResume()"; - atom::Browser::Get()->Show(); + atom::Browser::Get()->Resume(); } void WatchRuntime::OnAppControl(app_control_h app_control) { diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index b8eff8540..d1cb84376 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -97,8 +97,8 @@ class Window : public mate::TrackableObject, #endif #if defined(OS_TIZEN) - void OnSuspend(); - void OnResume(); + void OnSuspend() override; + void OnResume() override; void OnAppControl(); #endif diff --git a/atom/browser/browser.cc b/atom/browser/browser.cc index 155273777..09c330473 100644 --- a/atom/browser/browser.cc +++ b/atom/browser/browser.cc @@ -14,17 +14,11 @@ #include "base/files/file_util.h" #include "base/path_service.h" #include "base/run_loop.h" -#include "base/strings/utf_string_conversions.h" #include "base/threading/thread_task_runner_handle.h" #include "brightray/browser/brightray_paths.h" -#include "content/public/browser/render_frame_host.h" -#include "content/public/browser/render_view_host.h" #if defined(OS_TIZEN) -#include "tizen/common/application_data.h" -#include "tizen/src/browser/native_web_runtime.h" #include -#include "wgt_manifest_handlers/launch_screen_handler.h" #endif // defined(OS_TIZEN) #include "tizen/common/env_variables.h" @@ -33,9 +27,6 @@ namespace atom { Browser::Browser() : is_quiting_(false), -#if defined(OS_TIZEN) - launched_(false), -#endif is_exiting_(false), is_ready_(false), is_shutdown_(false) { @@ -46,21 +37,6 @@ Browser::~Browser() { WindowList::RemoveObserver(this); } -#if defined(OS_TIZEN) -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';"; -#endif - // static Browser* Browser::Get() { if (AtomBrowserMainParts::Get()) @@ -261,103 +237,4 @@ void Browser::OnWindowAllClosed() { #endif } -#if defined(OS_TIZEN) -// Function is same as suspend. This will be called from app lifecycle suspend -void Browser::Hide() { - // If application is having background catagory enabled then do not suspend the app - auto appdata = common::ApplicationDataManager::GetCurrentAppData(); - if (appdata->setting_info() != NULL && appdata->setting_info()->background_support_enabled()) { - return; - } - - NativeWindow *last_window = WindowList::GetLastWindow(); - if (!last_window) - return; - - last_window->NotifySuspend(); - auto rvh = last_window->web_contents()->GetRenderViewHost(); - atom::Browser::Get()->Suspend(rvh); -} - -// Function is same as resume. This will be called from app lifecycle resume -void Browser::Show() { - // If application is having background catagory enabled then do not resume the app - // as its has not suspend - auto appdata = common::ApplicationDataManager::GetCurrentAppData(); - if (appdata->setting_info() != NULL && appdata->setting_info()->background_support_enabled()) { - return; - } - NativeWindow *last_window = WindowList::GetLastWindow(); - if (!last_window) - return; - - last_window->NotifyResume(); - auto rvh = last_window->web_contents()->GetRenderViewHost(); - atom::Browser::Get()->Resume(rvh); -} - -void Browser::AppControl(std::unique_ptr appcontrol) { - std::unique_ptr res = - resource_manager_->GetStartResource(appcontrol.get()); - bool do_reset = res->should_reset(); - 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() { - NativeWindow *last_window = WindowList::GetLastWindow(); - - if (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 - std::unique_ptr res = - resource_manager_->GetStartResource(appcontrol.get()); - if (res) - start_url_ = res->uri(); - - tizen::NativeWebRuntime::GetInstance().StartApplication(); -} - -void Browser::SetSplashScreen() { - auto appdata = common::ApplicationDataManager::GetCurrentAppData(); - Evas_Object* window_ = elm_win_util_standard_add("", ""); - - splash_screen_.reset( - new SplashScreen( - window_, appdata->splash_screen_info(), appdata->application_path())); -} - -void Browser::HideSplashScreen(int reason) { - auto appdata = common::ApplicationDataManager::GetCurrentAppData(); - if (!appdata->splash_screen_info()) { - return; - } - - splash_screen_->HideSplashScreen(reason); -} -#endif // defined(OS_TIZEN) - } // namespace atom diff --git a/atom/browser/browser.h b/atom/browser/browser.h index 6c73a24d6..94b0e267a 100644 --- a/atom/browser/browser.h +++ b/atom/browser/browser.h @@ -17,12 +17,7 @@ #include "base/values.h" #include "native_mate/arguments.h" #if defined(OS_TIZEN) -#include "atom/browser/splash_screen.h" #include "tizen/browser/tizen_browser_parts.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" #endif // defined(OS_TIZEN) @@ -44,8 +39,11 @@ class AtomMenuModel; class LoginHandler; // This class is used for control application-wide operations. -class Browser : public WindowListObserver, - public tizen::TizenBrowserParts { +class Browser : public WindowListObserver +#if defined(OS_TIZEN) + , public tizen::TizenBrowserParts +#endif + { public: Browser(); ~Browser(); @@ -115,18 +113,6 @@ 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 appcontrol) override; - void Launch(std::unique_ptr appcontrol) override; - void SendAppControlEvent(); - 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) // Hide the application. void Hide(); @@ -255,12 +241,6 @@ class Browser : public WindowListObserver, // Observers of the browser. base::ObserverList observers_; -#if defined(OS_TIZEN) - std::unique_ptr splash_screen_; - std::string start_url_; - bool launched_; -#endif - // Whether `app.exit()` has been called bool is_exiting_; diff --git a/atom/browser/splash_screen.cc b/atom/browser/splash_screen.cc deleted file mode 100755 index d6c175109..000000000 --- a/atom/browser/splash_screen.cc +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "atom/browser/splash_screen.h" - -#include -#include -#include - -#include - -#include "tizen/common/logger.h" - -//using ScreenOrientation = runtime::NativeWindow::ScreenOrientation; - -namespace { - -enum class BorderOption { REPEAT = 1, STRETCH, ROUND }; - -// To do : The orientation will be implemented later. - -/*wgt::parse::ScreenOrientation ChooseOrientation( - const std::map& splash_map, - ScreenOrientation screen_orientation) { - auto orientation_pair = splash_map.end(); - - if (screen_orientation == - runtime::NativeWindow::ScreenOrientation::PORTRAIT_PRIMARY || - screen_orientation == - runtime::NativeWindow::ScreenOrientation::PORTRAIT_SECONDARY) { - orientation_pair = - splash_map.find(wgt::parse::ScreenOrientation::PORTRAIT); - } else { - orientation_pair = - splash_map.find(wgt::parse::ScreenOrientation::LANDSCAPE); - } - if (orientation_pair == splash_map.end()) - orientation_pair = splash_map.find(wgt::parse::ScreenOrientation::AUTO); - - if (orientation_pair != splash_map.end()) return orientation_pair->first; - return wgt::parse::ScreenOrientation::NONE; -}*/ - -bool ParseImageBorder(const std::vector& borders, - std::vector* border_values, - std::vector* border_options) { - std::map scaling_string; - scaling_string["repeat"] = BorderOption::REPEAT; - scaling_string["stretch"] = BorderOption::STRETCH; - scaling_string["round"] = BorderOption::ROUND; - - for (const auto& border : borders) { - std::string::size_type px_index = border.find("px"); - if (px_index != std::string::npos) { - std::string border_value(border.begin(), border.begin() + px_index); - border_values->push_back(std::atoi(border_value.c_str())); - } - for (const auto& border_string_val : scaling_string) { - std::string::size_type index = border.find(border_string_val.first); - if (index != std::string::npos) { - border_options->push_back(border_string_val.second); - } - } - } - - LOGGER(DEBUG) << "Image border values:"; - for (const auto& border_value : *border_values) { - LOGGER(DEBUG) << border_value; - } - LOGGER(DEBUG) << "Image border scaling values:"; - for (const auto& border_option : *border_options) { - LOGGER(DEBUG) << static_cast(border_option); - } - - return !border_values->empty() && !border_options->empty(); -} - -} // namespace - -namespace atom { - -SplashScreen::SplashScreen( - Evas_Object* window, - //runtime::NativeWindow* window, - std::shared_ptr ss_info, - const std::string& app_path) - : ss_info_(ss_info), - window_(window), - image_(nullptr), - background_(nullptr), - background_image_(nullptr), - is_active_(false) { - if (ss_info == nullptr) return; - - auto splash_map = ss_info->launch_screen_data(); - /*auto used_orientation = - ChooseOrientation(splash_map, window->orientation()); - if (used_orientation == wgt::parse::ScreenOrientation::NONE) return; */ - - auto dimensions = GetDimensions(window); - - // To do : The orientation will be implemented later. - SetBackground(splash_map[wgt::parse::ScreenOrientation::AUTO], window, - dimensions, app_path); - SetImage(splash_map[wgt::parse::ScreenOrientation::AUTO], window, - dimensions, app_path); - is_active_ = true; -} - -void SplashScreen::HideSplashScreen(int reason) { - - if (!is_active_) return; - if (reason == HideReason::RENDERED && - ss_info_->ready_when() != wgt::parse::ReadyWhen::FIRSTPAINT) { - return; - } - if (reason == HideReason::LOADFINISHED && - ss_info_->ready_when() != wgt::parse::ReadyWhen::COMPLETE) { - return; - } - if (reason == HideReason::CUSTOM && - ss_info_->ready_when() != wgt::parse::ReadyWhen::CUSTOM) { - return; - } - - evas_object_hide(background_); - evas_object_hide(image_); - evas_object_hide(window_); - evas_object_del(background_); - evas_object_del(image_); - evas_object_hide(window_); - background_ = nullptr; - image_ = nullptr; - window_ = nullptr; - is_active_ = false; -} - -std::pair SplashScreen::GetDimensions(Evas_Object* window) { - int w, h; - elm_win_screen_size_get(window, NULL, NULL, &w, &h); - evas_object_resize(background_, w, h); - return std::make_pair(w, h); -} - -void SplashScreen::SetBackground( - const wgt::parse::LaunchScreenData& splash_data, Evas_Object* parent, - const SplashScreenBound& bound, const std::string& app_path) { - background_ = elm_bg_add(parent); - if (!background_) return; - evas_object_resize(background_, bound.first, bound.second); - - if (splash_data.background_color != nullptr) { - elm_bg_color_set(background_, - splash_data.background_color->red, - splash_data.background_color->green, - splash_data.background_color->blue); - } - - std::vector border_values; - std::vector border_options; - - if (!splash_data.background_images.empty() && - ParseImageBorder( - splash_data.image_border, &border_values, &border_options)) { - const std::string& background_image_path = - splash_data.background_images.front().first; - - background_image_ = elm_image_add(background_); - evas_object_image_file_set(background_image_, - (app_path + background_image_path).c_str(), - NULL); - elm_image_aspect_fixed_set(background_image_, 0); - evas_object_image_border_center_fill_set(background_image_, - EVAS_BORDER_FILL_DEFAULT); - - evas_object_resize(background_image_, bound.first, bound.second); - - int border_l, border_r, border_t, border_b; - switch (border_values.size()) { - case 1: - border_l = border_r = border_t = border_b = -border_values[0]; - break; - case 2: - border_t = border_b = border_values[0]; - border_l = border_r = border_values[1]; - break; - case 4: - border_t = border_values[0]; - border_r = border_values[1]; - border_b = border_values[2]; - border_l = border_values[3]; - break; - default: - border_l = border_r = border_t = border_b = 0; - } - evas_object_image_border_set(background_image_, - border_l, - border_r, - border_t, - border_b); - // TODO(a.szulakiewi): add scaling of horizontal and vertical borders - } - - evas_object_show(background_); - evas_object_show(background_image_); - evas_object_show(parent); -} - -void SplashScreen::SetImage( - const wgt::parse::LaunchScreenData& splash_data, Evas_Object* parent, - const SplashScreenBound& bound, const std::string& app_path) { - if (!background_) return; - image_ = elm_image_add(background_); - if (!image_) return; - - if (splash_data.images.empty()) return; - - const std::string& image_path = splash_data.images.front().first; - elm_image_file_set(image_, (app_path + image_path).c_str(), NULL); - evas_object_resize(image_, bound.first, bound.second); - evas_object_show(image_); - evas_object_show(parent); -} -} // namespace atom diff --git a/atom/browser/splash_screen.h b/atom/browser/splash_screen.h deleted file mode 100755 index 593ff06c7..000000000 --- a/atom/browser/splash_screen.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef XWALK_RUNTIME_BROWSER_SPLASH_SCREEN_H_ -#define XWALK_RUNTIME_BROWSER_SPLASH_SCREEN_H_ - -#include -#include -#include -#include -#include - -#include -#include "wgt_manifest_handlers/launch_screen_handler.h" - -enum HideReason { RENDERED, LOADFINISHED, CUSTOM }; - -namespace atom { - -enum class ScreenOrientation { - PORTRAIT_PRIMARY = 0, - PORTRAIT_SECONDARY = 1, - LANDSCAPE_PRIMARY = 2, - LANDSCAPE_SECONDARY = 3, - NATURAL = 4, - ANY = 5 -}; - -class SplashScreen { - public: - typedef std::pair SplashScreenBound; - - SplashScreen(Evas_Object* window, - std::shared_ptr ss_info, - const std::string& app_path); - void HideSplashScreen(int reason); - - private: - std::pair GetDimensions(Evas_Object* window); - void SetBackground(const wgt::parse::LaunchScreenData& splash_data, - Evas_Object* parent, const SplashScreenBound& bound, - const std::string& app_path); - - void SetImage(const wgt::parse::LaunchScreenData& splash_data, - Evas_Object* parent, const SplashScreenBound& bound, - const std::string& app_path); - - std::shared_ptr ss_info_; - Evas_Object* window_; - Evas_Object* image_; - Evas_Object* background_; - Evas_Object* background_image_; - bool is_active_; -}; -} // namespace atom -#endif // XWALK_RUNTIME_BROWSER_SPLASH_SCREEN_H_ diff --git a/tizen/browser/splash_screen.cc b/tizen/browser/splash_screen.cc new file mode 100755 index 000000000..b528bb9e5 --- /dev/null +++ b/tizen/browser/splash_screen.cc @@ -0,0 +1,238 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include +#include +#include + +// #include // TODO: Why was it added in the first place? + +#include "tizen/browser/splash_screen.h" +#include "tizen/common/logger.h" + +//using ScreenOrientation = runtime::NativeWindow::ScreenOrientation; + +namespace { + +enum class BorderOption { REPEAT = 1, STRETCH, ROUND }; + +// TODO: The orientation will be implemented later. + +/*wgt::parse::ScreenOrientation ChooseOrientation( + const std::map& splash_map, + ScreenOrientation screen_orientation) { + auto orientation_pair = splash_map.end(); + + if (screen_orientation == + runtime::NativeWindow::ScreenOrientation::PORTRAIT_PRIMARY || + screen_orientation == + runtime::NativeWindow::ScreenOrientation::PORTRAIT_SECONDARY) { + orientation_pair = + splash_map.find(wgt::parse::ScreenOrientation::PORTRAIT); + } else { + orientation_pair = + splash_map.find(wgt::parse::ScreenOrientation::LANDSCAPE); + } + if (orientation_pair == splash_map.end()) + orientation_pair = splash_map.find(wgt::parse::ScreenOrientation::AUTO); + + if (orientation_pair != splash_map.end()) return orientation_pair->first; + return wgt::parse::ScreenOrientation::NONE; +}*/ + +bool ParseImageBorder(const std::vector& borders, + std::vector* border_values, + std::vector* border_options) { + std::map scaling_string; + scaling_string["repeat"] = BorderOption::REPEAT; + scaling_string["stretch"] = BorderOption::STRETCH; + scaling_string["round"] = BorderOption::ROUND; + + for (const auto& border : borders) { + std::string::size_type px_index = border.find("px"); + if (px_index != std::string::npos) { + std::string border_value(border.begin(), border.begin() + px_index); + border_values->push_back(std::atoi(border_value.c_str())); + } + for (const auto& border_string_val : scaling_string) { + std::string::size_type index = border.find(border_string_val.first); + if (index != std::string::npos) { + border_options->push_back(border_string_val.second); + } + } + } + + LOGGER(DEBUG) << "Image border values:"; + for (const auto& border_value : *border_values) { + LOGGER(DEBUG) << border_value; + } + LOGGER(DEBUG) << "Image border scaling values:"; + for (const auto& border_option : *border_options) { + LOGGER(DEBUG) << static_cast(border_option); + } + + return !border_values->empty() && !border_options->empty(); +} + +} // namespace + +namespace tizen { + +SplashScreen::SplashScreen( + Evas_Object* window, + //runtime::NativeWindow* window, + std::shared_ptr ss_info, + const std::string& app_path) + : ss_info_(ss_info), + window_(window), + image_(nullptr), + background_(nullptr), + background_image_(nullptr), + is_active_(false) { + if (ss_info == nullptr) return; + + auto splash_map = ss_info->launch_screen_data(); + /*auto used_orientation = + ChooseOrientation(splash_map, window->orientation()); + if (used_orientation == wgt::parse::ScreenOrientation::NONE) return; */ + + auto dimensions = GetDimensions(window); + + // TODO: The orientation will be implemented later. + SetBackground(splash_map[wgt::parse::ScreenOrientation::AUTO], window, + dimensions, app_path); + SetImage(splash_map[wgt::parse::ScreenOrientation::AUTO], window, + dimensions, app_path); + is_active_ = true; +} + +void SplashScreen::HideSplashScreen(int reason) { + + if (!is_active_) return; + if (reason == HideReason::RENDERED && + ss_info_->ready_when() != wgt::parse::ReadyWhen::FIRSTPAINT) { + return; + } + if (reason == HideReason::LOADFINISHED && + ss_info_->ready_when() != wgt::parse::ReadyWhen::COMPLETE) { + return; + } + if (reason == HideReason::CUSTOM && + ss_info_->ready_when() != wgt::parse::ReadyWhen::CUSTOM) { + return; + } + + evas_object_hide(background_); + evas_object_hide(image_); + evas_object_hide(window_); + evas_object_del(background_); + evas_object_del(image_); + evas_object_hide(window_); + background_ = nullptr; + image_ = nullptr; + window_ = nullptr; + is_active_ = false; +} + +std::pair SplashScreen::GetDimensions(Evas_Object* window) { + int w, h; + elm_win_screen_size_get(window, NULL, NULL, &w, &h); + evas_object_resize(background_, w, h); + return std::make_pair(w, h); +} + +void SplashScreen::SetBackground( + const wgt::parse::LaunchScreenData& splash_data, Evas_Object* parent, + const SplashScreenBound& bound, const std::string& app_path) { + background_ = elm_bg_add(parent); + if (!background_) return; + evas_object_resize(background_, bound.first, bound.second); + + if (splash_data.background_color != nullptr) { + elm_bg_color_set(background_, + splash_data.background_color->red, + splash_data.background_color->green, + splash_data.background_color->blue); + } + + std::vector border_values; + std::vector border_options; + + if (!splash_data.background_images.empty() && + ParseImageBorder( + splash_data.image_border, &border_values, &border_options)) { + const std::string& background_image_path = + splash_data.background_images.front().first; + + background_image_ = elm_image_add(background_); + evas_object_image_file_set(background_image_, + (app_path + background_image_path).c_str(), + NULL); + elm_image_aspect_fixed_set(background_image_, 0); + evas_object_image_border_center_fill_set(background_image_, + EVAS_BORDER_FILL_DEFAULT); + + evas_object_resize(background_image_, bound.first, bound.second); + + int border_l, border_r, border_t, border_b; + switch (border_values.size()) { + case 1: + border_l = border_r = border_t = border_b = -border_values[0]; + break; + case 2: + border_t = border_b = border_values[0]; + border_l = border_r = border_values[1]; + break; + case 4: + border_t = border_values[0]; + border_r = border_values[1]; + border_b = border_values[2]; + border_l = border_values[3]; + break; + default: + border_l = border_r = border_t = border_b = 0; + } + evas_object_image_border_set(background_image_, + border_l, + border_r, + border_t, + border_b); + // TODO(a.szulakiewi): add scaling of horizontal and vertical borders + } + + evas_object_show(background_); + evas_object_show(background_image_); + evas_object_show(parent); +} + +void SplashScreen::SetImage( + const wgt::parse::LaunchScreenData& splash_data, Evas_Object* parent, + const SplashScreenBound& bound, const std::string& app_path) { + if (!background_) return; + image_ = elm_image_add(background_); + if (!image_) return; + + if (splash_data.images.empty()) return; + + const std::string& image_path = splash_data.images.front().first; + elm_image_file_set(image_, (app_path + image_path).c_str(), NULL); + evas_object_resize(image_, bound.first, bound.second); + evas_object_show(image_); + evas_object_show(parent); +} +} // namespace tizen diff --git a/tizen/browser/splash_screen.h b/tizen/browser/splash_screen.h new file mode 100755 index 000000000..fc38190ca --- /dev/null +++ b/tizen/browser/splash_screen.h @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TIZEN_BROWSER_SPLASH_SCREEN_H_ +#define TIZEN_BROWSER_SPLASH_SCREEN_H_ + +#include +#include +#include +#include +#include + +#include +#include "wgt_manifest_handlers/launch_screen_handler.h" + +enum HideReason { RENDERED, LOADFINISHED, CUSTOM }; + +namespace tizen { + +enum class ScreenOrientation { + PORTRAIT_PRIMARY = 0, + PORTRAIT_SECONDARY = 1, + LANDSCAPE_PRIMARY = 2, + LANDSCAPE_SECONDARY = 3, + NATURAL = 4, + ANY = 5 +}; + +class SplashScreen { + public: + typedef std::pair SplashScreenBound; + + SplashScreen(Evas_Object* window, + std::shared_ptr ss_info, + const std::string& app_path); + void HideSplashScreen(int reason); + + private: + std::pair GetDimensions(Evas_Object* window); + void SetBackground(const wgt::parse::LaunchScreenData& splash_data, + Evas_Object* parent, const SplashScreenBound& bound, + const std::string& app_path); + + void SetImage(const wgt::parse::LaunchScreenData& splash_data, + Evas_Object* parent, const SplashScreenBound& bound, + const std::string& app_path); + + std::shared_ptr ss_info_; + Evas_Object* window_; + Evas_Object* image_; + Evas_Object* background_; + Evas_Object* background_image_; + bool is_active_; +}; +} // namespace tizen +#endif // TIZEN_BROWSER_SPLASH_SCREEN_H_ diff --git a/tizen/browser/tizen_browser_parts.cc b/tizen/browser/tizen_browser_parts.cc index e8292c367..c8cfd6d8c 100644 --- a/tizen/browser/tizen_browser_parts.cc +++ b/tizen/browser/tizen_browser_parts.cc @@ -20,15 +20,18 @@ #include #endif +#include "atom/browser/native_window_efl.h" +#include "atom/browser/window_list.h" #include "atom/common/api/api_messages.h" +#include "base/strings/utf_string_conversions.h" #include "common/string_utils.h" +#include "content/public/browser/render_frame_host.h" #include "tizen/browser/tizen_browser_parts.h" #include "tizen/browser/vibration_manager.h" +#include "tizen/src/browser/native_web_runtime.h" #include "tizen_src/ewk/efl_integration/text_encoding_map_efl.h" #if defined(TIZEN_VIDEO_HOLE) -#include "atom/browser/native_window_efl.h" -#include "atom/browser/window_list.h" #include "media/base/tizen/media_player_efl.h" #endif @@ -38,8 +41,18 @@ namespace { const std::string kDefaultEncoding = "UTF-8"; +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';"; + "default-src *; script-src 'self'; style-src 'self'; object-src 'none';"; static bool ProcessWellKnownScheme(const std::string& url) { if (common::utils::StartsWith(url, "file:") || @@ -69,7 +82,8 @@ static bool ProcessWellKnownScheme(const std::string& url) { TizenBrowserParts::TizenBrowserParts() : locale_manager_(new common::LocaleManager()), cookie_manager_(new CookieManager()), - is_suspended_(false) { + is_suspended_(false), + launched_(false) { } TizenBrowserParts::~TizenBrowserParts() { @@ -78,9 +92,8 @@ TizenBrowserParts::~TizenBrowserParts() { } void TizenBrowserParts::InitializeWindow() { - auto app_data = common::ApplicationDataManager::GetCurrentAppData(); #if !defined(OS_TIZEN_TV_PRODUCT) - if (app_data->app_type() == common::ApplicationData::WATCH) { + 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); @@ -157,6 +170,7 @@ void TizenBrowserParts::Initialize() { tizen::VibrationManager::CreateInstance(); InitializeWindow(); + SetSplashScreen(); } void TizenBrowserParts::ClearCookie() { @@ -202,7 +216,7 @@ void TizenBrowserParts::RenderViewCreated(content::RenderViewHost* render_view_h #endif } -void TizenBrowserParts::Suspend(content::RenderViewHost* rvh) { +void TizenBrowserParts::SuspendRVH(content::RenderViewHost* rvh) { if (is_suspended_ || !rvh) return; @@ -210,7 +224,7 @@ void TizenBrowserParts::Suspend(content::RenderViewHost* rvh) { rvh->Send(new WrtViewMsg_SuspendScheduledTask(rvh->GetRoutingID())); } -void TizenBrowserParts::Resume(content::RenderViewHost* rvh) { +void TizenBrowserParts::ResumeRVH(content::RenderViewHost* rvh) { if (!is_suspended_ || !rvh) return; @@ -247,4 +261,102 @@ std::string TizenBrowserParts::GetEncodingType() { else return kDefaultEncoding; } +// Function is same as suspend. This will be called from app lifecycle suspend +void TizenBrowserParts::Suspend() { + // 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); +} + +// Function is same as resume. This will be called from app lifecycle resume +void TizenBrowserParts::Resume() { + // 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(); + ResumeRVH(rvh); +} + +void TizenBrowserParts::SetSplashScreen() { + if (!app_data_->splash_screen_info()) { + return; + } + + Evas_Object* window_ = elm_win_util_standard_add("", ""); + + splash_screen_.reset( + new SplashScreen( + window_, app_data_->splash_screen_info(), app_data_->application_path())); +} + +void TizenBrowserParts::HideSplashScreen(int reason) { + if (!app_data_->splash_screen_info()) { + return; + } + + splash_screen_->HideSplashScreen(reason); +} + +void TizenBrowserParts::AppControl(std::unique_ptr appcontrol) { + std::unique_ptr res = + resource_manager_->GetStartResource(appcontrol.get()); + bool do_reset = res->should_reset(); + atom::NativeWindow *last_window = atom::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) { + //TODO: Implementation of ClearViewStack(), SetupWebWindow(),SetupWebWindowCompatibilitySettings() function + } +} + +void TizenBrowserParts::SendAppControlEvent() { + atom::NativeWindow *last_window = atom::WindowList::GetLastWindow(); + + if (last_window != NULL) { + content::RenderFrameHost* rfh = last_window->web_contents()->GetMainFrame(); + if (rfh) { + rfh->ExecuteJavaScriptWithUserGestureForTests( + base::UTF8ToUTF16(kAppControlEventScript)); + } + } +} + +void TizenBrowserParts::Launch(std::unique_ptr appcontrol) { + launched_ = true; +// TODO: Implementation of relaunching of app + std::unique_ptr res = + resource_manager_->GetStartResource(appcontrol.get()); + if (res) + start_url_ = res->uri(); + + tizen::NativeWebRuntime::GetInstance().StartApplication(); +} + + } // namespace tizen diff --git a/tizen/browser/tizen_browser_parts.h b/tizen/browser/tizen_browser_parts.h index 6d53d10c4..3ec1f7924 100644 --- a/tizen/browser/tizen_browser_parts.h +++ b/tizen/browser/tizen_browser_parts.h @@ -20,6 +20,7 @@ #include #include "content/public/browser/render_view_host.h" +#include "tizen/browser/splash_screen.h" #include "tizen/common/app_control.h" #include "tizen/common/application_data.h" #include "tizen/common/locale_manager.h" @@ -31,18 +32,24 @@ namespace tizen { class TizenBrowserParts { public: TizenBrowserParts(); - virtual void AppControl(std::unique_ptr appcontrol) = 0; - virtual void Launch(std::unique_ptr appcontrol) = 0; - virtual bool launched() const = 0; void RenderViewCreated(content::RenderViewHost* render_view_host); - void Suspend(content::RenderViewHost* rvh); - void Resume(content::RenderViewHost* rvh); + void SuspendRVH(content::RenderViewHost* rvh); + void ResumeRVH(content::RenderViewHost* rvh); void GetCSP(std::string& csp_rule, std::string& csp_report_rule); std::string GetEncodingType(); bool ShouldAllowNavigation(const std::string &url); void Initialize(); void GetWindowDimensions(int& width, int& height); + void Suspend(); + void Resume(); + void SetSplashScreen(); + void HideSplashScreen(int reason); + void AppControl(std::unique_ptr appcontrol); + void Launch(std::unique_ptr appcontrol); + void SendAppControlEvent(); Evas_Object* window() { return window_; } + bool launched() const { return launched_; } + std::string StartURL() const { return start_url_;} void ClearCookie(); CookieManager* GetCookieManager() { return cookie_manager_; } @@ -59,6 +66,8 @@ class TizenBrowserParts { void InitializeWindow(); void SetLongPollingTimeout(content::RenderViewHost* render_view_host); + std::unique_ptr splash_screen_; + Evas_Object* window_; common::ApplicationData* app_data_; CookieManager* cookie_manager_; @@ -66,6 +75,8 @@ class TizenBrowserParts { bool is_suspended_; std::string csp_rule_; std::string csp_report_rule_; + std::string start_url_; + bool launched_; }; } // namespace tizen diff --git a/tizen/src/browser/api/wrt_api_core.cc b/tizen/src/browser/api/wrt_api_core.cc index c63f6b800..ea6f6f749 100755 --- a/tizen/src/browser/api/wrt_api_core.cc +++ b/tizen/src/browser/api/wrt_api_core.cc @@ -93,8 +93,9 @@ bool WebRuntime::isElectronLaunch() const { } void WebRuntime::HideSplashScreen(int reason) { - atom::Browser* browser_model = atom::Browser::Get(); - browser_model->HideSplashScreen(reason); +#if defined(OS_TIZEN) + atom::Browser::Get()->HideSplashScreen(reason); +#endif } void WebRuntime::Log(const std::string& message) const { diff --git a/wrt.gyp b/wrt.gyp index 39a59697b..1b74d8a3e 100644 --- a/wrt.gyp +++ b/wrt.gyp @@ -116,8 +116,6 @@ 'atom/browser/native_browser_view_efl.h', 'atom/browser/native_window_efl.cc', 'atom/browser/native_window_efl.h', - 'atom/browser/splash_screen.h', - 'atom/browser/splash_screen.cc', 'atom/browser/ui/accelerator_util_efl.cc', 'atom/browser/ui/drag_util_efl.cc', 'atom/browser/ui/file_dialog_efl.cc', @@ -142,6 +140,8 @@ 'tizen/src/browser/wrt_ipc.h', 'tizen/src/browser/wrt_service.cc', 'tizen/src/browser/wrt_service.h', + 'tizen/browser/splash_screen.h', + 'tizen/browser/splash_screen.cc', 'tizen/browser/tizen_browser_parts.cc', 'tizen/browser/tizen_browser_parts.h', 'tizen/browser/tizen_web_contents_view_delegate.cc',