X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fxwalk%2Fapplication%2Fbrowser%2Fapplication_tizen.cc;h=ff53eee9476ddc5c1b178742dcaf7c72c0217c2e;hb=f5180d0a4dfe13ef74567dc9aa75047c1a9cd6de;hp=b62f94f59b6c4b154a68399ece95dfcfda2f5a73;hpb=004985e17e624662a4c85c76a7654039dc83f028;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/xwalk/application/browser/application_tizen.cc b/src/xwalk/application/browser/application_tizen.cc index b62f94f..ff53eee 100644 --- a/src/xwalk/application/browser/application_tizen.cc +++ b/src/xwalk/application/browser/application_tizen.cc @@ -1,4 +1,5 @@ // Copyright (c) 2013 Intel Corporation. All rights reserved. +// Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -8,10 +9,17 @@ #include #include +#include "content/browser/renderer_host/media/audio_renderer_host.h" +#include "content/browser/renderer_host/render_process_host_impl.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/render_process_host.h" +#include "content/public/browser/screen_orientation_dispatcher_host.h" +#include "content/public/browser/screen_orientation_provider.h" +#include "xwalk/runtime/browser/runtime_context.h" +#include "xwalk/runtime/browser/runtime_url_request_context_getter.h" #include "xwalk/runtime/browser/ui/native_app_window.h" +#include "xwalk/runtime/browser/ui/native_app_window_tizen.h" #include "xwalk/runtime/common/xwalk_common_messages.h" #if defined(USE_OZONE) @@ -20,60 +28,127 @@ #include "ui/events/event_constants.h" #include "ui/events/keycodes/keyboard_codes_posix.h" #include "ui/events/platform/platform_event_source.h" -#include "xwalk/application/common/manifest_handlers/tizen_setting_handler.h" #endif #include "xwalk/application/common/application_manifest_constants.h" -#include "xwalk/application/common/manifest_handlers/csp_handler.h" -#include "xwalk/application/common/manifest_handlers/navigation_handler.h" +#include "xwalk/application/common/manifest_handlers/tizen_setting_handler.h" +#include "xwalk/application/common/manifest_handlers/tizen_splash_screen_handler.h" namespace xwalk { +namespace keys = application_manifest_keys; namespace widget_keys = application_widget_keys; namespace application { +const char kDefaultMediaAppClass[] = "player"; namespace { -const char kAsterisk[] = "*"; - -const char kDirectiveValueSelf[] = "'self'"; -const char kDirectiveValueNone[] = "'none'"; - -const char kDirectiveNameDefault[] = "default-src"; -const char kDirectiveNameScript[] = "script-src"; -const char kDirectiveNameStyle[] = "style-src"; -const char kDirectiveNameObject[] = "object-src"; - -CSPInfo* GetDefaultCSPInfo() { - static CSPInfo default_csp_info; - if (default_csp_info.GetDirectives().empty()) { - std::vector directive_all; - std::vector directive_self; - std::vector directive_none; - directive_all.push_back(kAsterisk); - directive_self.push_back(kDirectiveValueSelf); - directive_none.push_back(kDirectiveValueNone); - - default_csp_info.SetDirective(kDirectiveNameDefault, directive_all); - default_csp_info.SetDirective(kDirectiveNameScript, directive_self); - default_csp_info.SetDirective(kDirectiveNameStyle, directive_self); - default_csp_info.SetDirective(kDirectiveNameObject, directive_none); - } - - return (new CSPInfo(default_csp_info)); +#if defined(OS_TIZEN_MOBILE) +void ApplyRootWindowParams(Runtime* runtime, + NativeAppWindow::CreateParams* params) { + if (!params->delegate) + params->delegate = runtime; + if (params->bounds.IsEmpty()) + params->bounds = gfx::Rect(0, 0, 840, 600); + + unsigned int fullscreen_options = runtime->fullscreen_options(); + if (params->state == ui::SHOW_STATE_FULLSCREEN) + fullscreen_options |= Runtime::FULLSCREEN_FOR_LAUNCH; + else + fullscreen_options &= ~Runtime::FULLSCREEN_FOR_LAUNCH; + runtime->set_fullscreen_options(fullscreen_options); } +NativeAppWindow* CreateRootWindow(Runtime* runtime, + const NativeAppWindow::CreateParams& params) { + NativeAppWindow::CreateParams effective_params(params); + ApplyRootWindowParams(runtime, &effective_params); + return NativeAppWindow::Create(effective_params); +} +#endif } // namespace +blink::WebScreenOrientationLockType GetDefaultOrientation( + const base::WeakPtr& app) { + TizenSettingInfo* info = static_cast( + app->data()->GetManifestData(widget_keys::kTizenSettingKey)); + if (!info) + return blink::WebScreenOrientationLockDefault; + switch (info->screen_orientation()) { + case TizenSettingInfo::PORTRAIT: + return blink::WebScreenOrientationLockPortrait; + case TizenSettingInfo::LANDSCAPE: + return blink::WebScreenOrientationLockLandscape; + case TizenSettingInfo::AUTO: + return blink::WebScreenOrientationLockAny; + default: + NOTREACHED(); + return blink::WebScreenOrientationLockDefault; + } +} + +class ScreenOrientationProviderTizen : + public content::ScreenOrientationProvider { + public: + ScreenOrientationProviderTizen( + const base::WeakPtr& app, + content::ScreenOrientationDispatcherHost* dispatcher) + : app_(app), + dispatcher_(dispatcher), + request_id_(0) { + DCHECK(dispatcher_); + } + + virtual void LockOrientation( + int request_id, + blink::WebScreenOrientationLockType lock) OVERRIDE { + if (!app_) { + dispatcher_->NotifyLockError( + request_id, + blink::WebLockOrientationError::WebLockOrientationErrorNotAvailable); + return; + } + request_id_ = request_id; + const std::set& runtimes = app_->runtimes(); + DCHECK(!runtimes.empty()); + // FIXME: Probably need better alignment with + // https://w3c.github.io/screen-orientation/#screen-orientation-lock-lifetime + std::set::iterator it = runtimes.begin(); + for (; it != runtimes.end(); ++it) { + NativeAppWindow* window = (*it)->window(); + if (window && window->IsActive()) { + ToNativeAppWindowTizen(window)->LockOrientation(lock); + break; + } + } + dispatcher_->NotifyLockSuccess(request_id); + } + + virtual void UnlockOrientation() OVERRIDE { + LockOrientation(request_id_, GetDefaultOrientation(app_)); + } + + virtual void OnOrientationChange() OVERRIDE {} + + private: + base::WeakPtr app_; + content::ScreenOrientationDispatcherHost* dispatcher_; + int request_id_; +}; ApplicationTizen::ApplicationTizen( scoped_refptr data, - RuntimeContext* runtime_context, - Application::Observer* observer) - : Application(data, runtime_context, observer) { + RuntimeContext* runtime_context) + : Application(data, runtime_context), +#if defined(OS_TIZEN_MOBILE) + root_window_(NULL), +#endif + is_suspended_(false) { #if defined(USE_OZONE) ui::PlatformEventSource::GetInstance()->AddPlatformEventObserver(this); #endif + cookie_manager_ = scoped_ptr( + new CookieManager(id(), runtime_context_)); } ApplicationTizen::~ApplicationTizen() { @@ -83,60 +158,107 @@ ApplicationTizen::~ApplicationTizen() { } void ApplicationTizen::Hide() { - DCHECK(runtimes_.size()); + DCHECK(!runtimes_.empty()); std::set::iterator it = runtimes_.begin(); for (; it != runtimes_.end(); ++it) { if ((*it)->window()) - (*it)->window()->Hide(); + (*it)->window()->Minimize(); } } -void ApplicationTizen::InitSecurityPolicy() { - // On Tizen, CSP mode has higher priority, and WARP will be disabled - // if the application is under CSP mode. - if (!data_->HasCSPDefined()) { - Application::InitSecurityPolicy(); - return; +void ApplicationTizen::Show() { + DCHECK(!runtimes_.empty()); + for (Runtime* runtime : runtimes_) { + if (auto window = runtime->window()) + window->Restore(); + } +} + +bool ApplicationTizen::Launch(const LaunchParams& launch_params) { + if (Application::Launch(launch_params)) { +#if defined(OS_TIZEN_MOBILE) + if (!runtimes_.empty()) { + root_window_ = CreateRootWindow(*(runtimes_.begin()), + window_show_params_); + window_show_params_.parent = root_window_->GetNativeWindow(); + root_window_->Show(); + } +#endif + DCHECK(web_contents_); + + // Get media class of application. + const Manifest* manifest = data_->GetManifest(); + std::string app_class; + manifest->GetString(keys::kXWalkMediaAppClass, &app_class); + if (app_class.empty()) + app_class = kDefaultMediaAppClass; + + // Set an application ID and class, which are needed to tag audio + // streams in pulseaudio/Murphy. + scoped_refptr audio_host = + static_cast(render_process_host_) + ->audio_renderer_host(); + if (audio_host.get()) + audio_host->SetMediaStreamProperties(id(), app_class); + + content::ScreenOrientationDispatcherHost* host = + web_contents_->GetScreenOrientationDispatcherHost(); + content::ScreenOrientationProvider* provider = + new ScreenOrientationProviderTizen(GetWeakPtr(), host); + host->SetProvider(provider); + + provider->LockOrientation(0, GetDefaultOrientation(GetWeakPtr())); + return true; + } + return false; +} + +base::FilePath ApplicationTizen::GetSplashScreenPath() { + if (TizenSplashScreenInfo* ss_info = static_cast( + data()->GetManifestData(widget_keys::kTizenSplashScreenKey))) { + return data()->path().Append(FILE_PATH_LITERAL(ss_info->src())); + } + return base::FilePath(); +} + +bool ApplicationTizen::CanBeSuspended() const { + if (TizenSettingInfo* setting = static_cast( + data()->GetManifestData(widget_keys::kTizenSettingKey))) { + return !setting->background_support_enabled(); } + return true; +} - if (data_->GetPackageType() != Package::WGT) +void ApplicationTizen::Suspend() { + if (is_suspended_ || !CanBeSuspended()) return; - CSPInfo* csp_info = - static_cast(data_->GetManifestData(widget_keys::kCSPKey)); - if (!csp_info || csp_info->GetDirectives().empty()) - data_->SetManifestData(widget_keys::kCSPKey, GetDefaultCSPInfo()); - - // Always enable security mode when under CSP mode. - security_mode_enabled_ = true; - NavigationInfo* info = static_cast( - data_->GetManifestData(widget_keys::kAllowNavigationKey)); - if (info) { - const std::vector& allowed_list = info->GetAllowedDomains(); - for (std::vector::const_iterator it = allowed_list.begin(); - it != allowed_list.end(); ++it) { - // If the policy is "*", it represents that any external link is allowed - // to navigate to. - if ((*it) == kAsterisk) { - security_mode_enabled_ = false; - return; - } + DCHECK(render_process_host_); + render_process_host_->Send(new ViewMsg_SuspendJSEngine(true)); - // If the policy start with "*.", like this: *.domain, - // means that can access to all subdomains for 'domain', - // otherwise, the host of request url should exactly the same - // as policy. - bool subdomains = ((*it).find("*.") == 0); - std::string host = subdomains ? (*it).substr(2) : (*it); - AddSecurityPolicy(GURL("http://" + host), subdomains); - AddSecurityPolicy(GURL("https://" + host), subdomains); - } + DCHECK(!runtimes_.empty()); + std::set::iterator it = runtimes_.begin(); + for (; it != runtimes_.end(); ++it) { + if ((*it)->web_contents()) + (*it)->web_contents()->WasHidden(); } + is_suspended_ = true; +} + +void ApplicationTizen::Resume() { + if (!is_suspended_ || !CanBeSuspended()) + return; + DCHECK(render_process_host_); - render_process_host_->Send( - new ViewMsg_EnableSecurityMode( - ApplicationData::GetBaseURLFromApplicationId(id()), - SecurityPolicy::CSP)); + render_process_host_->Send(new ViewMsg_SuspendJSEngine(false)); + + DCHECK(!runtimes_.empty()); + std::set::iterator it = runtimes_.begin(); + for (; it != runtimes_.end(); ++it) { + if ((*it)->web_contents()) + (*it)->web_contents()->WasShown(); + } + is_suspended_ = false; } #if defined(USE_OZONE) @@ -172,5 +294,34 @@ void ApplicationTizen::DidProcessEvent( } #endif +void ApplicationTizen::RemoveAllCookies() { + cookie_manager_->RemoveAllCookies(); +} + +void ApplicationTizen::SetUserAgentString( + const std::string& user_agent_string) { + cookie_manager_->SetUserAgentString(render_process_host_, user_agent_string); +} + +void ApplicationTizen::OnRuntimeAdded(Runtime* runtime) { + DCHECK(runtime); + Application::OnRuntimeAdded(runtime); +#if defined(OS_TIZEN_MOBILE) + if (root_window_ && runtimes_.size() > 1) + root_window_->Show(); +#endif +} + +void ApplicationTizen::OnRuntimeRemoved(Runtime* runtime) { + DCHECK(runtime); + Application::OnRuntimeRemoved(runtime); +#if defined(OS_TIZEN_MOBILE) + if (runtimes_.empty() && root_window_) { + root_window_->Close(); + root_window_ = NULL; + } +#endif +} + } // namespace application } // namespace xwalk