From cd8c88ae33a568451d25f62aaa35bcf33252076c Mon Sep 17 00:00:00 2001 From: Eurogiciel-BOT Date: Mon, 1 Dec 2014 17:37:30 +0000 Subject: [PATCH] Upstream version 11.39.256.0 Upstream commit-id 40851ba64b39fdbaafc05552cac664aaed3adc6d Change-Id: I3466f18e85eeec1b932f6f7a29fe738976066e7c Signed-off-by: Eurogiciel-BOT --- packaging/crosswalk.spec | 2 +- src/build/util/LASTCHANGE | 2 +- .../geolocation/location_arbitrator_impl.cc | 6 +- .../common/sandbox_linux/bpf_gpu_policy_linux.cc | 4 +- src/xwalk/CPPLINT.cfg | 2 + src/xwalk/DEPS.xwalk | 2 +- src/xwalk/VERSION | 2 +- src/xwalk/application/browser/application.cc | 61 ++-- src/xwalk/application/browser/application.h | 35 +-- .../application/browser/application_service.cc | 16 +- .../application/browser/application_service.h | 8 +- .../browser/application_service_tizen.cc | 12 +- .../browser/application_service_tizen.h | 2 +- .../application/browser/application_system.cc | 14 +- src/xwalk/application/browser/application_system.h | 11 +- .../browser/application_system_linux.cc | 4 +- .../application/browser/application_system_linux.h | 2 +- src/xwalk/application/browser/application_tizen.cc | 32 +- src/xwalk/application/browser/application_tizen.h | 6 +- .../common/application_manifest_constants.cc | 1 + .../common/application_manifest_constants.h | 1 + src/xwalk/application/common/id_util_unittest.cc | 68 ++++- .../tizen_navigation_handler_unittest.cc | 21 +- .../common/manifest_handlers/unittest_util.cc | 57 ++-- .../common/manifest_handlers/unittest_util.h | 12 +- .../manifest_handlers/warp_handler_unittest.cc | 59 ++-- .../common/manifest_handlers/widget_handler.cc | 14 + .../common/manifest_handlers/widget_handler.h | 3 + .../manifest_handlers/widget_handler_unittest.cc | 2 + .../common/tizen/application_storage_impl.cc | 69 +++-- .../application/common/tizen/cookie_manager.cc | 8 +- .../application/common/tizen/cookie_manager.h | 7 +- .../extension/application_widget_extension.cc | 2 +- .../tools/linux/xwalk_application_tools.gyp | 9 +- .../application/tools/linux/xwalk_launcher_main.cc | 2 +- src/xwalk/application/tools/linux/xwalkctl_main.cc | 15 +- src/xwalk/application/tools/tizen/xwalk_backend.cc | 8 +- .../application/tools/tizen/xwalk_tizen_tools.gyp | 1 + .../application/tools/tizen/xwalk_tizen_user.cc | 27 +- .../application/tools/tizen/xwalk_tizen_user.h | 4 +- src/xwalk/build/system.gyp | 23 +- .../native_file_system_api_browsertest.cc | 6 +- src/xwalk/extensions/common/xwalk_extension.cc | 4 +- src/xwalk/extensions/common/xwalk_extension.h | 9 +- .../extensions/common/xwalk_extension_server.cc | 24 +- .../extensions/common/xwalk_extension_server.h | 3 +- src/xwalk/extensions/test/bad_extension_test.cc | 15 +- .../extensions/test/conflicting_entry_points.cc | 13 +- src/xwalk/extensions/test/context_destruction.cc | 11 +- .../extensions/test/crash_extension_process.cc | 8 +- src/xwalk/extensions/test/export_object.cc | 6 +- src/xwalk/extensions/test/extension_in_iframe.cc | 27 +- src/xwalk/extensions/test/external_extension.cc | 45 +-- .../test/external_extension_multi_process.cc | 95 +----- .../test/in_process_threads_browsertest.cc | 8 +- .../test/internal_extension_browsertest.cc | 8 +- src/xwalk/extensions/test/namespace_read_only.cc | 15 +- src/xwalk/extensions/test/nested_namespace.cc | 19 +- src/xwalk/extensions/test/v8tools_module.cc | 10 +- .../test/xwalk_extensions_browsertest.cc | 33 +- src/xwalk/packaging/crosswalk.spec | 2 +- .../src/org/xwalk/core/internal/XWalkContent.java | 4 +- .../android/intercepted_request_data_impl.cc | 8 +- .../android/net/android_protocol_handler.cc | 8 +- .../renderer_host/xwalk_render_view_host_ext.cc | 4 +- src/xwalk/runtime/browser/android/xwalk_content.cc | 12 +- src/xwalk/runtime/browser/application_component.cc | 4 +- src/xwalk/runtime/browser/application_component.h | 4 +- .../browser/devtools/remote_debugging_server.cc | 6 +- .../browser/devtools/remote_debugging_server.h | 4 +- .../browser/devtools/xwalk_devtools_browsertest.cc | 17 +- .../browser/devtools/xwalk_devtools_delegate.cc | 29 +- .../browser/devtools/xwalk_devtools_delegate.h | 14 +- .../geolocation/tizen/location_provider_tizen.cc | 8 - src/xwalk/runtime/browser/runtime.cc | 121 ++++---- src/xwalk/runtime/browser/runtime.h | 47 ++- .../runtime/browser/runtime_defered_ui_strategy.cc | 31 -- .../runtime/browser/runtime_defered_ui_strategy.h | 37 --- .../runtime_geolocation_permission_context.h | 4 +- src/xwalk/runtime/browser/runtime_ui_delegate.cc | 125 ++++++++ src/xwalk/runtime/browser/runtime_ui_delegate.h | 59 ++++ src/xwalk/runtime/browser/runtime_ui_strategy.cc | 75 ----- src/xwalk/runtime/browser/runtime_ui_strategy.h | 23 -- .../runtime/browser/ui/native_app_window_aura.cc | 336 +++++++++++++++++++++ .../runtime/browser/ui/native_app_window_aura.h | 79 +++++ .../runtime/browser/ui/native_app_window_tizen.cc | 2 +- .../runtime/browser/xwalk_app_extension_bridge.cc | 34 +-- .../runtime/browser/xwalk_app_extension_bridge.h | 5 + ...runtime_context.cc => xwalk_browser_context.cc} | 64 ++-- .../{runtime_context.h => xwalk_browser_context.h} | 21 +- .../runtime/browser/xwalk_browser_main_parts.cc | 11 +- .../browser/xwalk_browser_main_parts_android.cc | 1 - .../browser/xwalk_content_browser_client.cc | 21 +- .../runtime/browser/xwalk_content_browser_client.h | 6 +- .../runtime/browser/xwalk_download_browsertest.cc | 16 +- .../browser/xwalk_form_input_browsertest.cc | 16 +- src/xwalk/runtime/browser/xwalk_runner.cc | 10 +- src/xwalk/runtime/browser/xwalk_runner.h | 6 +- .../runtime/browser/xwalk_runtime_browsertest.cc | 156 +++------- .../runtime/common/xwalk_notification_types.h | 10 +- src/xwalk/runtime/common/xwalk_paths.cc | 17 +- src/xwalk/sysapps/common/common_api_browsertest.cc | 6 +- .../device_capabilities_api_browsertest.cc | 6 +- .../raw_socket/raw_socket_api_browsertest.cc | 7 +- src/xwalk/test/base/in_process_browser_test.cc | 148 ++++----- src/xwalk/test/base/in_process_browser_test.h | 55 ++-- src/xwalk/xwalk.gyp | 35 +-- 107 files changed, 1514 insertions(+), 1195 deletions(-) create mode 100644 src/xwalk/CPPLINT.cfg delete mode 100644 src/xwalk/runtime/browser/runtime_defered_ui_strategy.cc delete mode 100644 src/xwalk/runtime/browser/runtime_defered_ui_strategy.h create mode 100644 src/xwalk/runtime/browser/runtime_ui_delegate.cc create mode 100644 src/xwalk/runtime/browser/runtime_ui_delegate.h delete mode 100644 src/xwalk/runtime/browser/runtime_ui_strategy.cc delete mode 100644 src/xwalk/runtime/browser/runtime_ui_strategy.h create mode 100644 src/xwalk/runtime/browser/ui/native_app_window_aura.cc create mode 100644 src/xwalk/runtime/browser/ui/native_app_window_aura.h rename src/xwalk/runtime/browser/{runtime_context.cc => xwalk_browser_context.cc} (81%) rename src/xwalk/runtime/browser/{runtime_context.h => xwalk_browser_context.h} (87%) diff --git a/packaging/crosswalk.spec b/packaging/crosswalk.spec index 12c5ffa..28c8490 100644 --- a/packaging/crosswalk.spec +++ b/packaging/crosswalk.spec @@ -24,7 +24,7 @@ %define _binary_payload w3.gzdio Name: crosswalk -Version: 11.39.252.0 +Version: 11.39.256.0 Release: 0 Summary: Chromium-based app runtime License: (BSD-3-Clause and LGPL-2.1+) diff --git a/src/build/util/LASTCHANGE b/src/build/util/LASTCHANGE index fe48b30..207e3ce 100644 --- a/src/build/util/LASTCHANGE +++ b/src/build/util/LASTCHANGE @@ -1 +1 @@ -LASTCHANGE=35b73bc7d43d8dcab600c2afedcdcf21de0651ee +LASTCHANGE=ea46c0b6279a60b0173a092f0e9f0403a2a047a9 diff --git a/src/content/browser/geolocation/location_arbitrator_impl.cc b/src/content/browser/geolocation/location_arbitrator_impl.cc index 09b6c10..ef20a0c 100644 --- a/src/content/browser/geolocation/location_arbitrator_impl.cc +++ b/src/content/browser/geolocation/location_arbitrator_impl.cc @@ -149,7 +149,7 @@ LocationProvider* LocationArbitratorImpl::NewNetworkLocationProvider( net::URLRequestContextGetter* context, const GURL& url, const base::string16& access_token) { -#if defined(OS_ANDROID) || defined(OS_TIZEN) +#if defined(OS_ANDROID) // Android uses its own SystemLocationProvider. return NULL; #else @@ -159,9 +159,7 @@ LocationProvider* LocationArbitratorImpl::NewNetworkLocationProvider( } LocationProvider* LocationArbitratorImpl::NewSystemLocationProvider() { -#if defined(OS_TIZEN) - return content::NewSystemLocationProvider(); -#elif defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) +#if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) return NULL; #else return content::NewSystemLocationProvider(); diff --git a/src/content/common/sandbox_linux/bpf_gpu_policy_linux.cc b/src/content/common/sandbox_linux/bpf_gpu_policy_linux.cc index dfc6b79..6f03711 100644 --- a/src/content/common/sandbox_linux/bpf_gpu_policy_linux.cc +++ b/src/content/common/sandbox_linux/bpf_gpu_policy_linux.cc @@ -226,9 +226,7 @@ bool GpuProcessPolicy::PreSandboxHook() { #if defined(OS_TIZEN) if (IsArchitectureX86_64()) { - // TODO(halton): Add 64-bit VA driver when 64-bit Tizen support - // is ready. - return false; + I965DrvVideoPath = "/usr/lib64/dri/i965_dri.so"; } else if (IsArchitectureI386()) { I965DrvVideoPath = "/usr/lib/dri/i965_dri.so"; } diff --git a/src/xwalk/CPPLINT.cfg b/src/xwalk/CPPLINT.cfg new file mode 100644 index 0000000..31b301b --- /dev/null +++ b/src/xwalk/CPPLINT.cfg @@ -0,0 +1,2 @@ +# Ignore errors about override vs OVERRIDE, see https://groups.google.com/a/chromium.org/forum/#!msg/chromium-dev/EW0wSDQQK8I/H0gsPtDtRmAJ +filter=-readability/inheritance diff --git a/src/xwalk/DEPS.xwalk b/src/xwalk/DEPS.xwalk index c5ad9ca..066189b 100644 --- a/src/xwalk/DEPS.xwalk +++ b/src/xwalk/DEPS.xwalk @@ -17,7 +17,7 @@ # Edit these when rolling DEPS.xwalk. # ----------------------------------- -chromium_crosswalk_rev = '35b73bc7d43d8dcab600c2afedcdcf21de0651ee' +chromium_crosswalk_rev = 'ea46c0b6279a60b0173a092f0e9f0403a2a047a9' v8_crosswalk_rev = '5b2efeab77f1cda6d70f98f20b393fe40ea6898a' ozone_wayland_rev = '6379cd118da098b55a5934ce1a90b377a177ed40' diff --git a/src/xwalk/VERSION b/src/xwalk/VERSION index 4d9f482..68e2c31 100644 --- a/src/xwalk/VERSION +++ b/src/xwalk/VERSION @@ -1,4 +1,4 @@ MAJOR=11 MINOR=39 -BUILD=252 +BUILD=256 PATCH=0 diff --git a/src/xwalk/application/browser/application.cc b/src/xwalk/application/browser/application.cc index ed9b1c0..64e85ea 100644 --- a/src/xwalk/application/browser/application.cc +++ b/src/xwalk/application/browser/application.cc @@ -22,8 +22,8 @@ #include "xwalk/application/common/constants.h" #include "xwalk/application/common/manifest_handlers/warp_handler.h" #include "xwalk/runtime/browser/runtime.h" -#include "xwalk/runtime/browser/runtime_context.h" -#include "xwalk/runtime/browser/runtime_defered_ui_strategy.h" +#include "xwalk/runtime/browser/runtime_ui_delegate.h" +#include "xwalk/runtime/browser/xwalk_browser_context.h" #include "xwalk/runtime/browser/xwalk_runner.h" #if defined(OS_TIZEN) @@ -74,7 +74,7 @@ namespace application { scoped_ptr Application::Create( scoped_refptr data, - RuntimeContext* context) { + XWalkBrowserContext* context) { #if defined(OS_TIZEN) return make_scoped_ptr(new ApplicationTizen(data, context)); #else @@ -84,17 +84,16 @@ scoped_ptr Application::Create( Application::Application( scoped_refptr data, - RuntimeContext* runtime_context) + XWalkBrowserContext* browser_context) : data_(data), render_process_host_(NULL), web_contents_(NULL), security_mode_enabled_(false), - runtime_context_(runtime_context), + browser_context_(browser_context), observer_(NULL), - ui_strategy_(new RuntimeDeferedUIStrategy), remote_debugging_enabled_(false), weak_factory_(this) { - DCHECK(runtime_context_); + DCHECK(browser_context_); DCHECK(data_.get()); } @@ -220,10 +219,10 @@ bool Application::Launch(const LaunchParams& launch_params) { return false; remote_debugging_enabled_ = launch_params.remote_debugging; - - Runtime* runtime = Runtime::Create( - runtime_context_, - this, content::SiteInstance::CreateForURL(runtime_context_, url)); + auto site = content::SiteInstance::CreateForURL(browser_context_, url); + Runtime* runtime = Runtime::Create(browser_context_, site); + runtime->set_observer(this); + runtimes_.push_back(runtime); render_process_host_ = runtime->GetRenderProcessHost(); render_process_host_->AddObserver(this); web_contents_ = runtime->web_contents(); @@ -233,13 +232,15 @@ bool Application::Launch(const LaunchParams& launch_params) { NativeAppWindow::CreateParams params; params.net_wm_pid = launch_params.launcher_pid; params.state = is_wgt ? - GetWindowShowState(launch_params): + GetWindowShowState(launch_params) : GetWindowShowState(launch_params); - window_show_params_.state = params.state; + window_show_params_ = params; + // Only the first runtime can have a launch screen. params.splash_screen_path = GetSplashScreenPath(); - - ui_strategy_->Show(runtime, params); + runtime->set_ui_delegate(DefaultRuntimeUIDelegate::Create(runtime, params)); + // We call "Show" after RP is initialized to reduce + // the application start up time. return true; } @@ -255,9 +256,9 @@ GURL Application::GetAbsoluteURLFromKey(const std::string& key) { } void Application::Terminate() { - std::set to_be_closed(runtimes_); - std::for_each(to_be_closed.begin(), to_be_closed.end(), - std::mem_fun(&Runtime::Close)); + std::vector to_be_closed(runtimes_.get()); + for (Runtime* runtime : to_be_closed) + runtime->Close(); } int Application::GetRenderProcessHostID() const { @@ -265,17 +266,20 @@ int Application::GetRenderProcessHostID() const { return render_process_host_->GetID(); } -void Application::OnRuntimeAdded(Runtime* runtime) { - DCHECK(runtime); +void Application::OnNewRuntimeAdded(Runtime* runtime) { runtime->set_remote_debugging_enabled(remote_debugging_enabled_); - if (!runtimes_.empty()) - ui_strategy_->Show(runtime, window_show_params_); - runtimes_.insert(runtime); + runtime->set_observer(this); + runtime->set_ui_delegate( + DefaultRuntimeUIDelegate::Create(runtime, window_show_params_)); + runtime->Show(); + runtimes_.push_back(runtime); } -void Application::OnRuntimeRemoved(Runtime* runtime) { - DCHECK(runtime); - runtimes_.erase(runtime); +void Application::OnRuntimeClosed(Runtime* runtime) { + auto found = std::find(runtimes_.begin(), runtimes_.end(), runtime); + CHECK(found != runtimes_.end()); + LOG(INFO) << "Application::OnRuntimeClosed " << runtime; + runtimes_.erase(found); if (runtimes_.empty()) base::MessageLoop::current()->PostTask(FROM_HERE, @@ -304,6 +308,11 @@ void Application::NotifyTermination() { observer_->OnApplicationTerminated(this); } +void Application::RenderChannelCreated() { + CHECK(!runtimes_.empty()); + runtimes_.front()->Show(); +} + bool Application::UseExtension(const std::string& extension_name) const { // TODO(Bai): Tells whether the application contains the specified extension return true; diff --git a/src/xwalk/application/browser/application.h b/src/xwalk/application/browser/application.h index b8ef3ea..38d24da 100644 --- a/src/xwalk/application/browser/application.h +++ b/src/xwalk/application/browser/application.h @@ -22,8 +22,6 @@ #include "xwalk/application/browser/application_security_policy.h" #include "xwalk/application/common/application_data.h" #include "xwalk/runtime/browser/runtime.h" -#include "xwalk/runtime/browser/runtime_ui_strategy.h" - namespace content { class RenderProcessHost; @@ -31,7 +29,8 @@ class RenderProcessHost; namespace xwalk { -class RuntimeContext; +class XWalkBrowserContext; +class XWalkAppExtensionBridge; namespace application { @@ -78,7 +77,7 @@ class Application : public Runtime::Observer, // immediately after its termination. void Terminate(); - const std::set& runtimes() const { return runtimes_; } + const std::vector& runtimes() const { return runtimes_.get(); } // Returns the unique application id which is used to distinguish the // application amoung both running applications and installed ones @@ -113,41 +112,41 @@ class Application : public Runtime::Observer, void set_observer(Observer* observer) { observer_ = observer; } - RuntimeUIStrategy* ui_strategy() { return ui_strategy_.get(); } + base::WeakPtr GetWeakPtr() { + return weak_factory_.GetWeakPtr(); + } protected: - Application(scoped_refptr data, RuntimeContext* context); + Application(scoped_refptr data, + XWalkBrowserContext* context); virtual bool Launch(const LaunchParams& launch_params); virtual void InitSecurityPolicy(); // Runtime::Observer implementation. - virtual void OnRuntimeAdded(Runtime* runtime) OVERRIDE; - virtual void OnRuntimeRemoved(Runtime* runtime) OVERRIDE; + virtual void OnNewRuntimeAdded(Runtime* runtime) override; + virtual void OnRuntimeClosed(Runtime* runtime) override; // Get the path of splash screen image. Return empty path by default. // Sub class can override it to return a specific path. virtual base::FilePath GetSplashScreenPath(); - std::set runtimes_; - RuntimeContext* runtime_context_; + XWalkBrowserContext* browser_context_; + ScopedVector runtimes_; scoped_refptr const data_; // The application's render process host. content::RenderProcessHost* render_process_host_; content::WebContents* web_contents_; bool security_mode_enabled_; - scoped_ptr ui_strategy_; - xwalk::NativeAppWindow::CreateParams window_show_params_; - - base::WeakPtr GetWeakPtr() { - return weak_factory_.GetWeakPtr(); - } + NativeAppWindow::CreateParams window_show_params_; private: // We enforce ApplicationService ownership. friend class ApplicationService; + // XWalkAppExtensionBridge gives notifications. + friend class xwalk::XWalkAppExtensionBridge; static scoped_ptr Create(scoped_refptr data, - RuntimeContext* context); + XWalkBrowserContext* context); // content::RenderProcessHostObserver implementation. virtual void RenderProcessExited(content::RenderProcessHost* host, @@ -167,6 +166,8 @@ class Application : public Runtime::Observer, GURL GetAbsoluteURLFromKey(const std::string& key); void NotifyTermination(); + // Notification from XWalkAppExtensionBridge. + void RenderChannelCreated(); Observer* observer_; diff --git a/src/xwalk/application/browser/application_service.cc b/src/xwalk/application/browser/application_service.cc index ac48734..2dbc11d 100644 --- a/src/xwalk/application/browser/application_service.cc +++ b/src/xwalk/application/browser/application_service.cc @@ -22,8 +22,8 @@ #include "xwalk/application/common/application_manifest_constants.h" #include "xwalk/application/common/application_file_util.h" #include "xwalk/application/common/id_util.h" -#include "xwalk/runtime/browser/runtime_context.h" #include "xwalk/runtime/browser/runtime.h" +#include "xwalk/runtime/browser/xwalk_browser_context.h" #include "xwalk/runtime/common/xwalk_paths.h" #if defined(OS_TIZEN) @@ -34,17 +34,17 @@ namespace xwalk { namespace application { -ApplicationService::ApplicationService(RuntimeContext* runtime_context) - : runtime_context_(runtime_context) { +ApplicationService::ApplicationService(XWalkBrowserContext* browser_context) + : browser_context_(browser_context) { } scoped_ptr ApplicationService::Create( - RuntimeContext* runtime_context) { + XWalkBrowserContext* browser_context) { #if defined(OS_TIZEN) return make_scoped_ptr( - new ApplicationServiceTizen(runtime_context)); + new ApplicationServiceTizen(browser_context)); #else - return make_scoped_ptr(new ApplicationService(runtime_context)); + return make_scoped_ptr(new ApplicationService(browser_context)); #endif } @@ -63,7 +63,7 @@ Application* ApplicationService::Launch( } Application* application = Application::Create(application_data, - runtime_context_).release(); + browser_context_).release(); ScopedVector::iterator app_iter = applications_.insert(applications_.end(), application); @@ -244,7 +244,7 @@ void ApplicationService::OnApplicationTerminated( // FIXME: So far we simply clean up all the app persistent data, // further we need to add an appropriate logic to handle it. content::BrowserContext::GarbageCollectStoragePartitions( - runtime_context_, + browser_context_, make_scoped_ptr(new base::hash_set()), base::Bind(&base::DoNothing)); } diff --git a/src/xwalk/application/browser/application_service.h b/src/xwalk/application/browser/application_service.h index c73712e..bc9c6fd 100644 --- a/src/xwalk/application/browser/application_service.h +++ b/src/xwalk/application/browser/application_service.h @@ -17,7 +17,7 @@ namespace xwalk { -class RuntimeContext; +class XWalkBrowserContext; namespace application { @@ -37,7 +37,7 @@ class ApplicationService : public Application::Observer { virtual ~ApplicationService(); static scoped_ptr Create( - RuntimeContext* runtime_context); + XWalkBrowserContext* browser_context); // Launch an unpacked application using path to the manifest file // of an unpacked application. @@ -81,7 +81,7 @@ class ApplicationService : public Application::Observer { const std::string& perm_table); protected: - explicit ApplicationService(RuntimeContext* runtime_context); + explicit ApplicationService(XWalkBrowserContext* browser_context); Application* Launch(scoped_refptr application_data, const Application::LaunchParams& launch_params); @@ -90,7 +90,7 @@ class ApplicationService : public Application::Observer { // Implementation of Application::Observer. virtual void OnApplicationTerminated(Application* app) OVERRIDE; - RuntimeContext* runtime_context_; + XWalkBrowserContext* browser_context_; ScopedVector applications_; ObserverList observers_; diff --git a/src/xwalk/application/browser/application_service_tizen.cc b/src/xwalk/application/browser/application_service_tizen.cc index 85e3556..17f93b2 100644 --- a/src/xwalk/application/browser/application_service_tizen.cc +++ b/src/xwalk/application/browser/application_service_tizen.cc @@ -10,7 +10,7 @@ #include "xwalk/application/browser/application.h" #include "xwalk/application/common/id_util.h" #include "xwalk/application/common/tizen/application_storage.h" -#include "xwalk/runtime/browser/runtime_context.h" +#include "xwalk/runtime/browser/xwalk_browser_context.h" namespace xwalk { @@ -26,7 +26,7 @@ base::FilePath GetStoragePartitionPath( return base_path.Append(kApplicationDataDirName).Append(app_id); } -void CollectUnusedStoragePartitions(RuntimeContext* context, +void CollectUnusedStoragePartitions(XWalkBrowserContext* context, ApplicationStorage* storage) { std::vector app_ids; if (!storage->GetInstalledApplicationIDs(app_ids)) @@ -47,10 +47,10 @@ void CollectUnusedStoragePartitions(RuntimeContext* context, } // namespace ApplicationServiceTizen::ApplicationServiceTizen( - RuntimeContext* runtime_context) - : ApplicationService(runtime_context), - application_storage_(new ApplicationStorage(runtime_context->GetPath())) { - CollectUnusedStoragePartitions(runtime_context, application_storage_.get()); + XWalkBrowserContext* browser_context) + : ApplicationService(browser_context), + application_storage_(new ApplicationStorage(browser_context->GetPath())) { + CollectUnusedStoragePartitions(browser_context, application_storage_.get()); } ApplicationServiceTizen::~ApplicationServiceTizen() { diff --git a/src/xwalk/application/browser/application_service_tizen.h b/src/xwalk/application/browser/application_service_tizen.h index 16f0424..85898e6 100644 --- a/src/xwalk/application/browser/application_service_tizen.h +++ b/src/xwalk/application/browser/application_service_tizen.h @@ -26,7 +26,7 @@ class ApplicationServiceTizen : public ApplicationService { private: friend class ApplicationService; - explicit ApplicationServiceTizen(RuntimeContext* runtime_context); + explicit ApplicationServiceTizen(XWalkBrowserContext* browser_context); // Note : do not export app storage from this class! We need consider // making ApplicationSystemTizen (owning the storage) instead. scoped_ptr application_storage_; diff --git a/src/xwalk/application/browser/application_system.cc b/src/xwalk/application/browser/application_system.cc index c2c44e0..2daba45 100644 --- a/src/xwalk/application/browser/application_system.cc +++ b/src/xwalk/application/browser/application_system.cc @@ -16,7 +16,7 @@ #include "xwalk/application/common/id_util.h" #include "xwalk/application/extension/application_runtime_extension.h" #include "xwalk/application/extension/application_widget_extension.h" -#include "xwalk/runtime/browser/runtime_context.h" +#include "xwalk/runtime/browser/xwalk_browser_context.h" #include "xwalk/runtime/common/xwalk_switches.h" #if defined(OS_LINUX) @@ -30,22 +30,22 @@ namespace xwalk { namespace application { -ApplicationSystem::ApplicationSystem(RuntimeContext* runtime_context) - : runtime_context_(runtime_context), +ApplicationSystem::ApplicationSystem(XWalkBrowserContext* browser_context) + : browser_context_(browser_context), application_service_(ApplicationService::Create( - runtime_context)) {} + browser_context)) {} ApplicationSystem::~ApplicationSystem() { } // static scoped_ptr ApplicationSystem::Create( - RuntimeContext* runtime_context) { + XWalkBrowserContext* browser_context) { scoped_ptr app_system; #if defined(OS_LINUX) - app_system.reset(new ApplicationSystemLinux(runtime_context)); + app_system.reset(new ApplicationSystemLinux(browser_context)); #else - app_system.reset(new ApplicationSystem(runtime_context)); + app_system.reset(new ApplicationSystem(browser_context)); #endif return app_system.Pass(); } diff --git a/src/xwalk/application/browser/application_system.h b/src/xwalk/application/browser/application_system.h index 4d88035..c787dbd 100644 --- a/src/xwalk/application/browser/application_system.h +++ b/src/xwalk/application/browser/application_system.h @@ -22,7 +22,7 @@ class RenderProcessHost; } namespace xwalk { -class RuntimeContext; +class XWalkBrowserContext; } namespace xwalk { @@ -33,12 +33,13 @@ class ApplicationService; // The ApplicationSystem manages the creation and destruction of services which // related to applications' runtime model. // There's one-to-one correspondence between ApplicationSystem and -// RuntimeContext. +// XWalkBrowserContext. class ApplicationSystem { public: virtual ~ApplicationSystem(); - static scoped_ptr Create(RuntimeContext* runtime_context); + static scoped_ptr Create( + XWalkBrowserContext* browser_context); // The ApplicationService is created at startup. ApplicationService* application_service() { @@ -67,11 +68,11 @@ class ApplicationSystem { extensions::XWalkExtensionVector* extensions); protected: - explicit ApplicationSystem(RuntimeContext* runtime_context); + explicit ApplicationSystem(XWalkBrowserContext* browser_context); private: // Note: initialization order matters. - RuntimeContext* runtime_context_; + XWalkBrowserContext* browser_context_; scoped_ptr application_service_; DISALLOW_COPY_AND_ASSIGN(ApplicationSystem); diff --git a/src/xwalk/application/browser/application_system_linux.cc b/src/xwalk/application/browser/application_system_linux.cc index 7f70fce..e8f0130 100644 --- a/src/xwalk/application/browser/application_system_linux.cc +++ b/src/xwalk/application/browser/application_system_linux.cc @@ -12,8 +12,8 @@ namespace xwalk { namespace application { -ApplicationSystemLinux::ApplicationSystemLinux(RuntimeContext* runtime_context) - : ApplicationSystem(runtime_context) { +ApplicationSystemLinux::ApplicationSystemLinux(XWalkBrowserContext* context) + : ApplicationSystem(context) { #if defined(SHARED_PROCESS_MODE) service_provider_.reset( new ApplicationServiceProviderLinux(application_service(), diff --git a/src/xwalk/application/browser/application_system_linux.h b/src/xwalk/application/browser/application_system_linux.h index 95db787..cba87e7 100644 --- a/src/xwalk/application/browser/application_system_linux.h +++ b/src/xwalk/application/browser/application_system_linux.h @@ -18,7 +18,7 @@ class ApplicationServiceProviderLinux; class ApplicationSystemLinux : public ApplicationSystem { public: - explicit ApplicationSystemLinux(RuntimeContext* runtime_context); + explicit ApplicationSystemLinux(XWalkBrowserContext* browser_context); virtual ~ApplicationSystemLinux(); DBusManager& dbus_manager(); diff --git a/src/xwalk/application/browser/application_tizen.cc b/src/xwalk/application/browser/application_tizen.cc index ff53eee..4d8d31f 100644 --- a/src/xwalk/application/browser/application_tizen.cc +++ b/src/xwalk/application/browser/application_tizen.cc @@ -16,7 +16,7 @@ #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/xwalk_browser_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" @@ -109,12 +109,11 @@ class ScreenOrientationProviderTizen : return; } request_id_ = request_id; - const std::set& runtimes = app_->runtimes(); + const std::vector& 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) { + for (auto it = runtimes.begin(); it != runtimes.end(); ++it) { NativeAppWindow* window = (*it)->window(); if (window && window->IsActive()) { ToNativeAppWindowTizen(window)->LockOrientation(lock); @@ -138,8 +137,8 @@ class ScreenOrientationProviderTizen : ApplicationTizen::ApplicationTizen( scoped_refptr data, - RuntimeContext* runtime_context) - : Application(data, runtime_context), + XWalkBrowserContext* browser_context) + : Application(data, browser_context), #if defined(OS_TIZEN_MOBILE) root_window_(NULL), #endif @@ -148,7 +147,7 @@ ApplicationTizen::ApplicationTizen( ui::PlatformEventSource::GetInstance()->AddPlatformEventObserver(this); #endif cookie_manager_ = scoped_ptr( - new CookieManager(id(), runtime_context_)); + new CookieManager(id(), browser_context_)); } ApplicationTizen::~ApplicationTizen() { @@ -159,8 +158,7 @@ ApplicationTizen::~ApplicationTizen() { void ApplicationTizen::Hide() { DCHECK(!runtimes_.empty()); - std::set::iterator it = runtimes_.begin(); - for (; it != runtimes_.end(); ++it) { + for (auto it = runtimes_.begin(); it != runtimes_.end(); ++it) { if ((*it)->window()) (*it)->window()->Minimize(); } @@ -237,8 +235,7 @@ void ApplicationTizen::Suspend() { render_process_host_->Send(new ViewMsg_SuspendJSEngine(true)); DCHECK(!runtimes_.empty()); - std::set::iterator it = runtimes_.begin(); - for (; it != runtimes_.end(); ++it) { + for (auto it = runtimes_.begin(); it != runtimes_.end(); ++it) { if ((*it)->web_contents()) (*it)->web_contents()->WasHidden(); } @@ -253,8 +250,7 @@ void ApplicationTizen::Resume() { render_process_host_->Send(new ViewMsg_SuspendJSEngine(false)); DCHECK(!runtimes_.empty()); - std::set::iterator it = runtimes_.begin(); - for (; it != runtimes_.end(); ++it) { + for (auto it = runtimes_.begin(); it != runtimes_.end(); ++it) { if ((*it)->web_contents()) (*it)->web_contents()->WasShown(); } @@ -286,7 +282,7 @@ void ApplicationTizen::DidProcessEvent( if (info && !info->hwkey_enabled()) return; - for (std::set::iterator it = runtimes_.begin(); + for (auto it = runtimes_.begin(); it != runtimes_.end(); ++it) { (*it)->web_contents()->GetRenderViewHost()->Send(new ViewMsg_HWKeyPressed( (*it)->web_contents()->GetRoutingID(), key_event->key_code())); @@ -303,18 +299,18 @@ void ApplicationTizen::SetUserAgentString( cookie_manager_->SetUserAgentString(render_process_host_, user_agent_string); } -void ApplicationTizen::OnRuntimeAdded(Runtime* runtime) { +void ApplicationTizen::OnNewRuntimeAdded(Runtime* runtime) { DCHECK(runtime); - Application::OnRuntimeAdded(runtime); + Application::OnNewRuntimeAdded(runtime); #if defined(OS_TIZEN_MOBILE) if (root_window_ && runtimes_.size() > 1) root_window_->Show(); #endif } -void ApplicationTizen::OnRuntimeRemoved(Runtime* runtime) { +void ApplicationTizen::OnRuntimeClosed(Runtime* runtime) { DCHECK(runtime); - Application::OnRuntimeRemoved(runtime); + Application::OnRuntimeClosed(runtime); #if defined(OS_TIZEN_MOBILE) if (runtimes_.empty() && root_window_) { root_window_->Close(); diff --git a/src/xwalk/application/browser/application_tizen.h b/src/xwalk/application/browser/application_tizen.h index ffeefa0..98e5b41 100644 --- a/src/xwalk/application/browser/application_tizen.h +++ b/src/xwalk/application/browser/application_tizen.h @@ -37,14 +37,14 @@ class ApplicationTizen : // NOLINT private: friend class Application; ApplicationTizen(scoped_refptr data, - RuntimeContext* context); + XWalkBrowserContext* context); virtual bool Launch(const LaunchParams& launch_params) OVERRIDE; virtual base::FilePath GetSplashScreenPath() OVERRIDE; // Runtime::Observer implementation. - virtual void OnRuntimeAdded(Runtime* runtime) OVERRIDE; - virtual void OnRuntimeRemoved(Runtime* runtime) OVERRIDE; + virtual void OnNewRuntimeAdded(Runtime* runtime) OVERRIDE; + virtual void OnRuntimeClosed(Runtime* runtime) OVERRIDE; #if defined(USE_OZONE) virtual void WillProcessEvent(const ui::PlatformEvent& event) OVERRIDE; diff --git a/src/xwalk/application/common/application_manifest_constants.cc b/src/xwalk/application/common/application_manifest_constants.cc index 1acd133..424a047 100644 --- a/src/xwalk/application/common/application_manifest_constants.cc +++ b/src/xwalk/application/common/application_manifest_constants.cc @@ -161,6 +161,7 @@ const char kTizenApplicationAppControlChildNameAttrKey[] = "@name"; } // namespace application_widget_keys +const char kW3CNamespaceKey[] = "widget.@namespace"; const char kW3CNamespacePrefix[] = "http://www.w3.org/ns/widgets"; #if defined(OS_TIZEN) const char kTizenNamespacePrefix[] = "http://tizen.org/ns/widgets"; diff --git a/src/xwalk/application/common/application_manifest_constants.h b/src/xwalk/application/common/application_manifest_constants.h index 06fef22..f1eab19 100644 --- a/src/xwalk/application/common/application_manifest_constants.h +++ b/src/xwalk/application/common/application_manifest_constants.h @@ -140,6 +140,7 @@ namespace application_widget_keys { #endif } // namespace application_widget_keys +extern const char kW3CNamespaceKey[]; extern const char kW3CNamespacePrefix[]; #if defined(OS_TIZEN) extern const char kTizenNamespacePrefix[]; diff --git a/src/xwalk/application/common/id_util_unittest.cc b/src/xwalk/application/common/id_util_unittest.cc index 051154c..f8adf3d 100644 --- a/src/xwalk/application/common/id_util_unittest.cc +++ b/src/xwalk/application/common/id_util_unittest.cc @@ -1,7 +1,9 @@ // Copyright (c) 2013 The Chromium Authors. 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. +#include #include "base/basictypes.h" #include "xwalk/application/common/id_util.h" #include "testing/gtest/include/gtest/gtest.h" @@ -9,6 +11,18 @@ namespace xwalk { namespace application { +namespace { + +std::string MakePlatformId(const std::string& arg) { +#if defined(OS_TIZEN) + return "xwalk." + arg; +#else + return arg; +#endif +} + +} // namespace + TEST(IDUtilTest, GenerateID) { const uint8 public_key_info[] = { 0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, @@ -29,27 +43,51 @@ TEST(IDUtilTest, GenerateID) { std::string application_id = GenerateId( std::string(reinterpret_cast(&public_key_info[0]), arraysize(public_key_info))); - EXPECT_EQ("melddjfinppjdikinhbgehiennejpfhp", application_id); - EXPECT_EQ("jpignaibiiemhngfjkcpokkamffknabf", GenerateId("test")); + EXPECT_EQ(MakePlatformId("melddjfinppjdikinhbgehiennejpfhp"), + application_id); - EXPECT_EQ("ncocknphbhhlhkikpnnlmbcnbgdempcd", GenerateId("_")); + EXPECT_EQ(MakePlatformId("jpignaibiiemhngfjkcpokkamffknabf"), + GenerateId("test")); - EXPECT_EQ("jimneklojkjdibfkgiiophfhjhbdgcfi", - GenerateId( - "this_string_is_longer_than_a_single_sha256_hash_digest")); + EXPECT_EQ(MakePlatformId("ncocknphbhhlhkikpnnlmbcnbgdempcd"), + GenerateId("_")); + + EXPECT_EQ(MakePlatformId("jimneklojkjdibfkgiiophfhjhbdgcfi"), + GenerateId("this_string_is_longer_than_a_single_sha256_hash_digest")); } TEST(IDUtilTest, IsValidApplicationID) { - EXPECT_TRUE(IsValidApplicationID("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")); - EXPECT_TRUE(IsValidApplicationID("pppppppppppppppppppppppppppppppp")); - EXPECT_TRUE(IsValidApplicationID("abcdefghijklmnopabcdefghijklmnop")); - EXPECT_TRUE(IsValidApplicationID("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP")); - EXPECT_FALSE(IsValidApplicationID("abcdefghijklmnopabcdefghijklmno")); - EXPECT_FALSE(IsValidApplicationID("abcdefghijklmnopabcdefghijklmnopa")); - EXPECT_FALSE(IsValidApplicationID("0123456789abcdef0123456789abcdef")); - EXPECT_FALSE(IsValidApplicationID("abcdefghijklmnopabcdefghijklmnoq")); - EXPECT_FALSE(IsValidApplicationID("abcdefghijklmnopabcdefghijklmno0")); + EXPECT_TRUE(IsValidApplicationID( + MakePlatformId("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))); + EXPECT_TRUE(IsValidApplicationID( + MakePlatformId("pppppppppppppppppppppppppppppppp"))); + EXPECT_TRUE(IsValidApplicationID( + MakePlatformId("abcdefghijklmnopabcdefghijklmnop"))); + EXPECT_FALSE(IsValidApplicationID( + MakePlatformId("abcdefghijklmnopabcdefghijklmno"))); + EXPECT_FALSE(IsValidApplicationID( + MakePlatformId("abcdefghijklmnopabcdefghijklmnopa"))); + EXPECT_FALSE(IsValidApplicationID( + MakePlatformId("0123456789abcdef0123456789abcdef"))); + EXPECT_FALSE(IsValidApplicationID( + MakePlatformId("abcdefghijklmnopabcdefghijklmnoq"))); + EXPECT_FALSE(IsValidApplicationID( + MakePlatformId("abcdefghijklmnopabcdefghijklmno0"))); + +// For Tizen platform upper case letters in application id are not allowed +// so we expect false unlike in the other platforms that accept them. +#if defined(OS_TIZEN) + EXPECT_FALSE(IsValidApplicationID( + MakePlatformId("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"))); +#else + EXPECT_TRUE(IsValidApplicationID( + MakePlatformId("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOP"))); +#endif + +#if defined(OS_TIZEN) + EXPECT_FALSE(IsValidApplicationID("abcdefghijklmnopabcdefghijklmnop")); +#endif } } // namespace application diff --git a/src/xwalk/application/common/manifest_handlers/tizen_navigation_handler_unittest.cc b/src/xwalk/application/common/manifest_handlers/tizen_navigation_handler_unittest.cc index 288c22c..590527c 100644 --- a/src/xwalk/application/common/manifest_handlers/tizen_navigation_handler_unittest.cc +++ b/src/xwalk/application/common/manifest_handlers/tizen_navigation_handler_unittest.cc @@ -1,16 +1,16 @@ // Copyright (c) 2014 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. -#include "xwalk/application/common/manifest_handlers/tizen_navigation_handler.h" - #include #include #include "base/memory/scoped_ptr.h" +#include "testing/gtest/include/gtest/gtest.h" #include "xwalk/application/common/application_manifest_constants.h" #include "xwalk/application/common/manifest.h" #include "xwalk/application/common/manifest_handlers/unittest_util.h" -#include "testing/gtest/include/gtest/gtest.h" +#include "xwalk/application/common/manifest_handlers/tizen_navigation_handler.h" namespace xwalk { @@ -33,16 +33,18 @@ class TizenNavigationHandlerTest: public testing::Test { }; TEST_F(TizenNavigationHandlerTest, NoNavigation) { - scoped_ptr manifest = CreateDefaultWGTManifest(); - scoped_refptr application = CreateApplication(*manifest); + scoped_ptr manifest = CreateDefaultWidgetConfig(); + scoped_refptr application = + CreateApplication(Manifest::TYPE_WIDGET, *manifest); EXPECT_TRUE(application.get()); EXPECT_FALSE(GetNavigationInfo(application)); } TEST_F(TizenNavigationHandlerTest, OneNavigation) { - scoped_ptr manifest = CreateDefaultWGTManifest(); + scoped_ptr manifest = CreateDefaultWidgetConfig(); manifest->SetString(keys::kAllowNavigationKey, "http://www.sample.com"); - scoped_refptr application = CreateApplication(*manifest); + scoped_refptr application = + CreateApplication(Manifest::TYPE_WIDGET, *manifest); EXPECT_TRUE(application.get()); EXPECT_EQ(application->GetManifest()->type(), Manifest::TYPE_WIDGET); const TizenNavigationInfo* info = GetNavigationInfo(application); @@ -52,10 +54,11 @@ TEST_F(TizenNavigationHandlerTest, OneNavigation) { } TEST_F(TizenNavigationHandlerTest, Navigations) { - scoped_ptr manifest = CreateDefaultWGTManifest(); + scoped_ptr manifest = CreateDefaultWidgetConfig(); manifest->SetString(keys::kAllowNavigationKey, "http://www.sample1.com www.sample2.com"); - scoped_refptr application = CreateApplication(*manifest); + scoped_refptr application = + CreateApplication(Manifest::TYPE_WIDGET, *manifest); EXPECT_TRUE(application.get()); EXPECT_EQ(application->GetManifest()->type(), Manifest::TYPE_WIDGET); const TizenNavigationInfo* info = GetNavigationInfo(application); diff --git a/src/xwalk/application/common/manifest_handlers/unittest_util.cc b/src/xwalk/application/common/manifest_handlers/unittest_util.cc index 478a277..581953c 100644 --- a/src/xwalk/application/common/manifest_handlers/unittest_util.cc +++ b/src/xwalk/application/common/manifest_handlers/unittest_util.cc @@ -6,11 +6,11 @@ #include #include "xwalk/application/common/application_manifest_constants.h" -#include "xwalk/application/common/manifest.h" namespace xwalk { -namespace keys = application_widget_keys; +namespace manifest_keys = application_manifest_keys; +namespace widget_keys = application_widget_keys; namespace application { @@ -33,61 +33,58 @@ std::string DotConnect(const std::string& first, const std::string& second) { } // namespace -scoped_ptr CreateDefaultW3CManifest() { +scoped_ptr CreateDefaultManifestConfig() { scoped_ptr manifest(new base::DictionaryValue()); - // widget attributes + manifest->SetString(manifest_keys::kXWalkVersionKey, kDefaultVersion); + manifest->SetString(manifest_keys::kNameKey, kDefaultName); - manifest->SetString( - DotConnect(keys::kWidgetKey, keys::kNamespaceKey), - kW3CNamespacePrefix); + return manifest.Pass(); +} - manifest->SetString(keys::kVersionKey, kDefaultVersion); +scoped_ptr CreateDefaultWidgetConfig() { + scoped_ptr manifest(new base::DictionaryValue()); - manifest->SetString(keys::kNameKey, kDefaultName); + // widget attributes - return manifest.Pass(); -} + manifest->SetString( + DotConnect(widget_keys::kWidgetKey, widget_keys::kNamespaceKey), + kW3CNamespacePrefix); + manifest->SetString(widget_keys::kVersionKey, kDefaultVersion); + manifest->SetString(widget_keys::kNameKey, kDefaultName); #if defined(OS_TIZEN) -scoped_ptr CreateDefaultWGTManifest() { - scoped_ptr manifest(CreateDefaultW3CManifest()); - // widget.application attributes manifest->SetString( - DotConnect(keys::kTizenApplicationKey, - keys::kNamespaceKey), + DotConnect(widget_keys::kTizenApplicationKey, + widget_keys::kNamespaceKey), kTizenNamespacePrefix); - manifest->SetString( - DotConnect(keys::kTizenApplicationKey, - keys::kTizenApplicationIdKey), + DotConnect(widget_keys::kTizenApplicationKey, + widget_keys::kTizenApplicationIdKey), DotConnect(kDefaultPackageId, kDefaultApplicationName)); - manifest->SetString( - DotConnect(keys::kTizenApplicationKey, - keys::kTizenApplicationPackageKey), + DotConnect(widget_keys::kTizenApplicationKey, + widget_keys::kTizenApplicationPackageKey), kDefaultPackageId); - manifest->SetString( - DotConnect(keys::kTizenApplicationKey, - keys::kTizenApplicationRequiredVersionKey), + DotConnect(widget_keys::kTizenApplicationKey, + widget_keys::kTizenApplicationRequiredVersionKey), kDefaultRequiredVersion); +#endif + return manifest.Pass(); } -#endif // defined(OS_TIZEN) - -scoped_refptr CreateApplication( +scoped_refptr CreateApplication(Manifest::Type type, const base::DictionaryValue& manifest) { std::string error; scoped_refptr application = ApplicationData::Create( base::FilePath(), std::string(), ApplicationData::LOCAL_DIRECTORY, - make_scoped_ptr(new Manifest(make_scoped_ptr(manifest.DeepCopy()), - Manifest::TYPE_WIDGET)), + make_scoped_ptr(new Manifest(make_scoped_ptr(manifest.DeepCopy()), type)), &error); return application; } diff --git a/src/xwalk/application/common/manifest_handlers/unittest_util.h b/src/xwalk/application/common/manifest_handlers/unittest_util.h index 249079b..a921cbf 100644 --- a/src/xwalk/application/common/manifest_handlers/unittest_util.h +++ b/src/xwalk/application/common/manifest_handlers/unittest_util.h @@ -9,19 +9,15 @@ #include "base/memory/scoped_ptr.h" #include "base/values.h" #include "xwalk/application/common/application_data.h" +#include "xwalk/application/common/manifest.h" namespace xwalk { namespace application { -scoped_ptr CreateDefaultW3CManifest(); +scoped_ptr CreateDefaultManifestConfig(); +scoped_ptr CreateDefaultWidgetConfig(); -#if defined(OS_TIZEN) - -scoped_ptr CreateDefaultWGTManifest(); - -#endif // defined(OS_TIZEN) - -scoped_refptr CreateApplication( +scoped_refptr CreateApplication(Manifest::Type type, const base::DictionaryValue& manifest); } // namespace application diff --git a/src/xwalk/application/common/manifest_handlers/warp_handler_unittest.cc b/src/xwalk/application/common/manifest_handlers/warp_handler_unittest.cc index aeda711..bdaacab 100644 --- a/src/xwalk/application/common/manifest_handlers/warp_handler_unittest.cc +++ b/src/xwalk/application/common/manifest_handlers/warp_handler_unittest.cc @@ -1,10 +1,12 @@ // 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. -#include "xwalk/application/common/manifest_handlers/warp_handler.h" - +#include "base/memory/scoped_ptr.h" #include "xwalk/application/common/application_manifest_constants.h" +#include "xwalk/application/common/manifest_handlers/unittest_util.h" +#include "xwalk/application/common/manifest_handlers/warp_handler.h" #include "testing/gtest/include/gtest/gtest.h" namespace xwalk { @@ -13,37 +15,26 @@ namespace keys = application_widget_keys; namespace application { +namespace { + +const WARPInfo* GetWARPInfo( + scoped_refptr application) { + const WARPInfo* info = static_cast( + application->GetManifestData(keys::kAccessKey)); + return info; +} + +} // namespace + class WARPHandlerTest: public testing::Test { - public: - virtual void SetUp() OVERRIDE { - manifest.SetString(keys::kNameKey, "no name"); - manifest.SetString(keys::kVersionKey, "0"); - } - - scoped_refptr CreateApplication() { - std::string error; - scoped_refptr application = ApplicationData::Create( - base::FilePath(), std::string(), ApplicationData::LOCAL_DIRECTORY, - make_scoped_ptr(new Manifest(make_scoped_ptr(manifest.DeepCopy()), - Manifest::TYPE_WIDGET)), - &error); - return application; - } - - const WARPInfo* GetWARPInfo( - scoped_refptr application) { - const WARPInfo* info = static_cast( - application->GetManifestData(keys::kAccessKey)); - return info; - } - - base::DictionaryValue manifest; }; // FIXME: the default WARP policy settings in WARP manifest handler // are temporally removed, since they had affected some tests and legacy apps. TEST_F(WARPHandlerTest, NoWARP) { - scoped_refptr application = CreateApplication(); + scoped_ptr manifest = CreateDefaultWidgetConfig(); + scoped_refptr application = + CreateApplication(Manifest::TYPE_WIDGET, *manifest); EXPECT_TRUE(application.get()); EXPECT_FALSE(GetWARPInfo(application)); } @@ -52,10 +43,11 @@ TEST_F(WARPHandlerTest, OneWARP) { base::DictionaryValue* warp = new base::DictionaryValue; warp->SetString(keys::kAccessOriginKey, "http://www.sample.com"); warp->SetBoolean(keys::kAccessSubdomainsKey, true); - manifest.Set(keys::kAccessKey, warp); - scoped_refptr application = CreateApplication(); + scoped_ptr manifest = CreateDefaultWidgetConfig(); + manifest->Set(keys::kAccessKey, warp); + scoped_refptr application = + CreateApplication(Manifest::TYPE_WIDGET, *manifest); EXPECT_TRUE(application.get()); - EXPECT_EQ(application->manifest_type(), Manifest::TYPE_WIDGET); const WARPInfo* info = GetWARPInfo(application); EXPECT_TRUE(info); scoped_ptr list(info->GetWARP()->DeepCopy()); @@ -75,11 +67,12 @@ TEST_F(WARPHandlerTest, WARPs) { base::ListValue* warp_list = new base::ListValue; warp_list->Append(warp1); warp_list->Append(warp2); - manifest.Set(keys::kAccessKey, warp_list); - scoped_refptr application = CreateApplication(); + scoped_ptr manifest = CreateDefaultWidgetConfig(); + manifest->Set(keys::kAccessKey, warp_list); + scoped_refptr application = + CreateApplication(Manifest::TYPE_WIDGET, *manifest); EXPECT_TRUE(application.get()); - EXPECT_EQ(application->manifest_type(), Manifest::TYPE_WIDGET); const WARPInfo* info = GetWARPInfo(application); EXPECT_TRUE(info); diff --git a/src/xwalk/application/common/manifest_handlers/widget_handler.cc b/src/xwalk/application/common/manifest_handlers/widget_handler.cc index 4fb5bbb..e6107dd 100644 --- a/src/xwalk/application/common/manifest_handlers/widget_handler.cc +++ b/src/xwalk/application/common/manifest_handlers/widget_handler.cc @@ -159,6 +159,20 @@ bool WidgetHandler::Parse(scoped_refptr application, return true; } +bool WidgetHandler::Validate( + scoped_refptr application, + std::string* error) const { + const Manifest* manifest = application->GetManifest(); + DCHECK(manifest); + std::string ns_value; + manifest->GetString(kW3CNamespaceKey, &ns_value); + if (base::strcasecmp(kW3CNamespacePrefix, ns_value.c_str()) != 0) { + *error = std::string("The widget namespace is invalid."); + return false; + } + return true; +} + bool WidgetHandler::AlwaysParseForType(Manifest::Type type) const { return true; } diff --git a/src/xwalk/application/common/manifest_handlers/widget_handler.h b/src/xwalk/application/common/manifest_handlers/widget_handler.h index 2e2ebb3..d7d92a1 100644 --- a/src/xwalk/application/common/manifest_handlers/widget_handler.h +++ b/src/xwalk/application/common/manifest_handlers/widget_handler.h @@ -46,6 +46,9 @@ class WidgetHandler : public ManifestHandler { virtual bool AlwaysParseForType(Manifest::Type type) const OVERRIDE; virtual std::vector Keys() const OVERRIDE; + virtual bool Validate(scoped_refptr application, + std::string* error) const OVERRIDE; + private: DISALLOW_COPY_AND_ASSIGN(WidgetHandler); }; diff --git a/src/xwalk/application/common/manifest_handlers/widget_handler_unittest.cc b/src/xwalk/application/common/manifest_handlers/widget_handler_unittest.cc index a2752c2..1e734df 100644 --- a/src/xwalk/application/common/manifest_handlers/widget_handler_unittest.cc +++ b/src/xwalk/application/common/manifest_handlers/widget_handler_unittest.cc @@ -93,6 +93,7 @@ class WidgetHandlerTest: public testing::Test { // No Preferences and full other information void SetAllInfoToManifest(base::DictionaryValue* manifest) { // Insert some key-value pairs into manifest use full key + manifest->SetString(kW3CNamespaceKey, kW3CNamespacePrefix); manifest->SetString(keys::kAuthorKey, author); manifest->SetString(keys::kDescriptionKey, decription); manifest->SetString(keys::kNameKey, name); @@ -123,6 +124,7 @@ class WidgetHandlerTest: public testing::Test { TEST_F(WidgetHandlerTest, ParseManifestWithOnlyNameAndVersion) { base::DictionaryValue manifest; + manifest.SetString(kW3CNamespaceKey, kW3CNamespacePrefix); manifest.SetString(keys::kNameKey, "no name"); manifest.SetString(keys::kVersionKey, "0"); diff --git a/src/xwalk/application/common/tizen/application_storage_impl.cc b/src/xwalk/application/common/tizen/application_storage_impl.cc index 102a3ba..3327672 100644 --- a/src/xwalk/application/common/tizen/application_storage_impl.cc +++ b/src/xwalk/application/common/tizen/application_storage_impl.cc @@ -10,6 +10,7 @@ #include #include +#include "base/macros.h" #include "base/file_util.h" #include "third_party/re2/re2/re2.h" #include "xwalk/application/common/application_file_util.h" @@ -31,7 +32,7 @@ ail_cb_ret_e appinfo_get_app_id_cb( return AIL_CB_RET_CONTINUE; } -const char kXWalkPackageType[] = "wgt"; +const char* kXWalkPackageTypes[] = {"wgt", "xpk"}; bool GetPackageType(const std::string& application_id, xwalk::application::Manifest::Type* package_type) { @@ -104,44 +105,48 @@ scoped_refptr ApplicationStorageImpl::GetApplicationData( bool ApplicationStorageImpl::GetInstalledApplicationIDs( std::vector& app_ids) { // NOLINT - ail_filter_h filter; - int count; uid_t uid = getuid(); - ail_error_e ret = ail_filter_new(&filter); - if (ret != AIL_ERROR_OK) { - LOG(ERROR) << "Failed to create AIL filter."; - return false; - } - // Filters out web apps (installed from WGT and XPK packages). - ret = ail_filter_add_str( - filter, AIL_PROP_X_SLP_PACKAGETYPE_STR, kXWalkPackageType); - if (ret != AIL_ERROR_OK) { - LOG(ERROR) << "Failed to init AIL filter."; - ail_filter_destroy(filter); - return false; - } + for (size_t i = 0; i < arraysize(kXWalkPackageTypes); ++i) { + int count = 0; + ail_filter_h filter; + ail_error_e ret = ail_filter_new(&filter); + if (ret != AIL_ERROR_OK) { + LOG(ERROR) << "Failed to create AIL filter."; + return false; + } + // Filters out web apps (installed from WGT and XPK packages). + ret = ail_filter_add_str( + filter, AIL_PROP_X_SLP_PACKAGETYPE_STR, kXWalkPackageTypes[i]); + if (ret != AIL_ERROR_OK) { + LOG(ERROR) << "Failed to init AIL filter."; + ail_filter_destroy(filter); + return false; + } - if (uid != GLOBAL_USER) - ret = ail_filter_count_usr_appinfo(filter, &count, uid); - else - ret = ail_filter_count_appinfo(filter, &count); - - if (ret != AIL_ERROR_OK) { - LOG(ERROR) << "Failed to count AIL app info."; - ail_filter_destroy(filter); - return false; - } - - if (count > 0) { if (uid != GLOBAL_USER) - ail_filter_list_usr_appinfo_foreach(filter, appinfo_get_app_id_cb, - &app_ids, uid); + ret = ail_filter_count_usr_appinfo(filter, &count, uid); else - ail_filter_list_appinfo_foreach(filter, appinfo_get_app_id_cb, &app_ids); + ret = ail_filter_count_appinfo(filter, &count); + + if (ret != AIL_ERROR_OK) { + LOG(ERROR) << "Failed to count AIL app info."; + ail_filter_destroy(filter); + return false; + } + + if (count > 0) { + if (uid != GLOBAL_USER) + ail_filter_list_usr_appinfo_foreach(filter, appinfo_get_app_id_cb, + &app_ids, uid); + else + ail_filter_list_appinfo_foreach( + filter, appinfo_get_app_id_cb, &app_ids); + } + + ail_filter_destroy(filter); } - ail_filter_destroy(filter); return true; } diff --git a/src/xwalk/application/common/tizen/cookie_manager.cc b/src/xwalk/application/common/tizen/cookie_manager.cc index 954fef5..53a22e0 100644 --- a/src/xwalk/application/common/tizen/cookie_manager.cc +++ b/src/xwalk/application/common/tizen/cookie_manager.cc @@ -19,9 +19,9 @@ namespace xwalk { CookieManager::CookieManager( const std::string& app_id, - RuntimeContext* runtime_context) + XWalkBrowserContext* browser_context) : app_id_(app_id), - runtime_context_(runtime_context) { + browser_context_(browser_context) { } void CookieManager::CookieDeleted(bool success) { @@ -31,7 +31,7 @@ void CookieManager::CookieDeleted(bool success) { void CookieManager::DeleteSessionOnlyOriginCookies( const net::CookieList& cookies) { - net::URLRequestContext* request_context = runtime_context_-> + net::URLRequestContext* request_context = browser_context_-> GetURLRequestContextGetterById( std::string(app_id_))->GetURLRequestContext(); if (!request_context) @@ -50,7 +50,7 @@ void CookieManager::DeleteCookiesOnIOThread( const std::string& url, const std::string& cookie_name) { DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); - net::URLRequestContext* request_context = runtime_context_-> + net::URLRequestContext* request_context = browser_context_-> GetURLRequestContextGetterById(app_id_)->GetURLRequestContext(); net::CookieStore* cookie_store = request_context->cookie_store(); cookie_store->GetCookieMonster()->GetAllCookiesAsync( diff --git a/src/xwalk/application/common/tizen/cookie_manager.h b/src/xwalk/application/common/tizen/cookie_manager.h index 05d472f..b973a3b 100644 --- a/src/xwalk/application/common/tizen/cookie_manager.h +++ b/src/xwalk/application/common/tizen/cookie_manager.h @@ -9,13 +9,14 @@ #include "net/cookies/canonical_cookie.h" -#include "xwalk/runtime/browser/runtime_context.h" +#include "xwalk/runtime/browser/xwalk_browser_context.h" namespace xwalk { class CookieManager { public: - CookieManager(const std::string& app_id, RuntimeContext* runtime_context); + CookieManager(const std::string& app_id, + XWalkBrowserContext* browser_context); void RemoveAllCookies(); void SetUserAgentString(content::RenderProcessHost* render_process_host, const std::string& user_agent_string); @@ -26,7 +27,7 @@ class CookieManager { const std::string& cookie_name); const std::string app_id_; - RuntimeContext* runtime_context_; + XWalkBrowserContext* browser_context_; }; } // namespace xwalk diff --git a/src/xwalk/application/extension/application_widget_extension.cc b/src/xwalk/application/extension/application_widget_extension.cc index 3dedd96..af28a65 100644 --- a/src/xwalk/application/extension/application_widget_extension.cc +++ b/src/xwalk/application/extension/application_widget_extension.cc @@ -20,7 +20,7 @@ #include "xwalk/application/common/manifest_handlers/widget_handler.h" #include "xwalk/application/extension/application_widget_storage.h" #include "xwalk/runtime/browser/runtime.h" -#include "xwalk/runtime/browser/runtime_context.h" +#include "xwalk/runtime/browser/xwalk_browser_context.h" #include "xwalk/runtime/browser/xwalk_runner.h" #include "xwalk/runtime/common/xwalk_paths.h" diff --git a/src/xwalk/application/tools/linux/xwalk_application_tools.gyp b/src/xwalk/application/tools/linux/xwalk_application_tools.gyp index 6d33f78..a70f1b4 100644 --- a/src/xwalk/application/tools/linux/xwalk_application_tools.gyp +++ b/src/xwalk/application/tools/linux/xwalk_application_tools.gyp @@ -1,5 +1,5 @@ { - 'targets': [ + 'targets': [ { 'target_name': 'xwalk_launcher', 'type': 'executable', @@ -9,6 +9,7 @@ ], 'dependencies': [ '../../../../base/third_party/dynamic_annotations/dynamic_annotations.gyp:dynamic_annotations', + '../../../build/system.gyp:gio', '../../../extensions/extensions.gyp:xwalk_extensions', '../../../application/common/xwalk_application_common.gypi:xwalk_application_common_lib', ], @@ -20,14 +21,8 @@ 'xwalk_launcher_main.cc', ], 'conditions' : [ - ['OS=="linux"', { - 'dependencies': [ - '../../../build/system.gyp:gio', - ], - }], ['tizen==1', { 'dependencies': [ - '../../../build/system.gyp:gio', '../../../build/system.gyp:tizen', '../../../build/system.gyp:tizen_appcore_common' ], diff --git a/src/xwalk/application/tools/linux/xwalk_launcher_main.cc b/src/xwalk/application/tools/linux/xwalk_launcher_main.cc index 1fe5674..46c956b 100644 --- a/src/xwalk/application/tools/linux/xwalk_launcher_main.cc +++ b/src/xwalk/application/tools/linux/xwalk_launcher_main.cc @@ -273,7 +273,7 @@ int main(int argc, char** argv) { #endif #if defined(OS_TIZEN) - if (xwalk_tizen_check_user_app()) + if (xwalk_tizen_check_group_users()) exit(1); #endif diff --git a/src/xwalk/application/tools/linux/xwalkctl_main.cc b/src/xwalk/application/tools/linux/xwalkctl_main.cc index 2cced6e..064869d 100644 --- a/src/xwalk/application/tools/linux/xwalkctl_main.cc +++ b/src/xwalk/application/tools/linux/xwalkctl_main.cc @@ -13,13 +13,16 @@ #include "base/path_service.h" #include "xwalk/application/common/tizen/application_storage.h" -#include "xwalk/application/tools/tizen/xwalk_tizen_user.h" #include "xwalk/runtime/common/xwalk_paths.h" #include "dbus/bus.h" #include "dbus/message.h" #include "dbus/object_proxy.h" +#if defined(OS_TIZEN) +#include "xwalk/application/tools/tizen/xwalk_tizen_user.h" +#endif + using xwalk::application::ApplicationData; using xwalk::application::ApplicationStorage; @@ -103,8 +106,8 @@ bool list_applications(ApplicationStorage* storage) { int main(int argc, char* argv[]) { #if defined(OS_TIZEN) - if (xwalk_tizen_check_user_for_xwalkctl()) - exit(1); + if (xwalk_tizen_check_group_users()) + return 1; #endif GOptionContext* context = g_option_context_new("- Crosswalk Setter"); g_option_context_add_main_entries(context, entries, NULL); @@ -112,14 +115,14 @@ int main(int argc, char* argv[]) { if (!g_option_context_parse(context, &argc, &argv, &error)) { g_print("option parsing failed: %s\n", error->message); g_option_context_free(context); - exit(1); + return 1; } g_option_context_free(context); base::AtExitManager at_exit; if (debugging_port != debugging_port_not_set) { if (!EnableRemoteDebugging(static_cast(debugging_port))) - exit(1); + return 1; } else { // FIXME : there should be a way to get application Id from platform, so // the below code should not be needed. @@ -128,7 +131,7 @@ int main(int argc, char* argv[]) { PathService::Get(xwalk::DIR_DATA_PATH, &data_path); scoped_ptr storage(new ApplicationStorage(data_path)); if (!list_applications(storage.get())) - exit(1); + return 1; } return 0; diff --git a/src/xwalk/application/tools/tizen/xwalk_backend.cc b/src/xwalk/application/tools/tizen/xwalk_backend.cc index dfc992e..3a30146 100644 --- a/src/xwalk/application/tools/tizen/xwalk_backend.cc +++ b/src/xwalk/application/tools/tizen/xwalk_backend.cc @@ -64,19 +64,19 @@ int main(int argc, char* argv[]) { g_type_init(); #endif - if (xwalk_tizen_check_user_for_xwalkctl()) - exit(1); + if (xwalk_tizen_check_user_for_xwalk_backend()) + return 1; context = g_option_context_new("- Crosswalk Application Management"); if (!context) { g_print("g_option_context_new failed\n"); - exit(1); + return 1; } g_option_context_add_main_entries(context, entries, NULL); if (!g_option_context_parse(context, &argc, &argv, &error)) { g_print("option parsing failed: %s\n", error->message); g_option_context_free(context); - exit(1); + return 1; } g_option_context_free(context); diff --git a/src/xwalk/application/tools/tizen/xwalk_tizen_tools.gyp b/src/xwalk/application/tools/tizen/xwalk_tizen_tools.gyp index f7e7ef5..ba5abfd 100644 --- a/src/xwalk/application/tools/tizen/xwalk_tizen_tools.gyp +++ b/src/xwalk/application/tools/tizen/xwalk_tizen_tools.gyp @@ -8,6 +8,7 @@ '../../../application/common/xwalk_application_common.gypi:xwalk_application_common_lib', '../../../build/system.gyp:gio', '../../../build/system.gyp:tizen', + '../../../build/system.gyp:tizen_tzplatform_config', ], 'include_dirs': [ '../../../..', diff --git a/src/xwalk/application/tools/tizen/xwalk_tizen_user.cc b/src/xwalk/application/tools/tizen/xwalk_tizen_user.cc index 43436ac..03a35e0 100644 --- a/src/xwalk/application/tools/tizen/xwalk_tizen_user.cc +++ b/src/xwalk/application/tools/tizen/xwalk_tizen_user.cc @@ -16,7 +16,7 @@ #include -int xwalk_tizen_check_user_app(void) { +int xwalk_tizen_check_group_users(void) { char* buffer = NULL; int err = 0; struct group grp; @@ -35,19 +35,19 @@ int xwalk_tizen_check_user_app(void) { free(buffer); return -EINVAL; } + if ((!current_g) || - (strcmp(current_g->gr_name, "users") && - strcmp(current_g->gr_name, "app"))) { - fprintf(stderr, "group '%s' is not allowed :", - current_g ? current_g->gr_name : ""); - fprintf(stderr, "launching an application will not work\n"); - free(buffer); - return -EINVAL; + strcmp(current_g->gr_name, "users")) { + fprintf(stderr, "group '%s' is not allowed :", + current_g ? current_g->gr_name : ""); + fprintf(stderr, "launching an application will not work\n"); + free(buffer); + return -EINVAL; } return 0; } -int xwalk_tizen_check_user_for_xwalkctl(void) { +int xwalk_tizen_check_user_for_xwalk_backend(void) { char* buffer = NULL; int err = 0; struct group grp; @@ -66,11 +66,10 @@ int xwalk_tizen_check_user_for_xwalkctl(void) { free(buffer); return -EINVAL; } - if ((!current_g) || - (strcmp(current_g->gr_name, "users") && - strcmp(current_g->gr_name, "app") && - (strcmp(current_g->gr_name, "root") && - getuid() == tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)))) { + + if ((!current_g) || ( + strcmp(current_g->gr_name, "users") && + getuid() != tzplatform_getuid(TZ_SYS_GLOBALAPP_USER))) { fprintf(stderr, "group '%s' is not allowed :", current_g ? current_g->gr_name : ""); fprintf(stderr, "launching an application will not work\n"); diff --git a/src/xwalk/application/tools/tizen/xwalk_tizen_user.h b/src/xwalk/application/tools/tizen/xwalk_tizen_user.h index 7da72e7..7cd8d01 100644 --- a/src/xwalk/application/tools/tizen/xwalk_tizen_user.h +++ b/src/xwalk/application/tools/tizen/xwalk_tizen_user.h @@ -11,7 +11,7 @@ // causes applications connecting to the session D-Bus bus to fail, for example. // This is a Tizen specific workaround. -int xwalk_tizen_check_user_app(void); -int xwalk_tizen_check_user_for_xwalkctl(void); +int xwalk_tizen_check_group_users(void); +int xwalk_tizen_check_user_for_xwalk_backend(void); #endif // XWALK_APPLICATION_TOOLS_TIZEN_XWALK_TIZEN_USER_H_ diff --git a/src/xwalk/build/system.gyp b/src/xwalk/build/system.gyp index bac9cff..23dfc03 100644 --- a/src/xwalk/build/system.gyp +++ b/src/xwalk/build/system.gyp @@ -29,6 +29,28 @@ ['tizen==1', { 'targets': [ { + 'target_name': 'tizen_tzplatform_config', + 'type': 'none', + 'variables': { + 'packages': [ + 'libtzplatform-config', + ], + }, + 'direct_dependent_settings': { + 'cflags': [ + 'web_contents(), passString); + xwalk::Runtime* runtime = CreateRuntime(); + content::TitleWatcher title_watcher(runtime->web_contents(), passString); title_watcher.AlsoWaitForTitle(failString); #if defined(OS_LINUX) @@ -34,6 +34,6 @@ IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, NativeFileSystem) { .Append(FILE_PATH_LITERAL("native_file_system")) .Append(FILE_PATH_LITERAL("native_file_system_api_browsertest.html")); - xwalk_test_utils::NavigateToURL(runtime(), net::FilePathToFileURL(test_file)); + xwalk_test_utils::NavigateToURL(runtime, net::FilePathToFileURL(test_file)); EXPECT_EQ(passString, title_watcher.WaitAndGetTitle()); } diff --git a/src/xwalk/extensions/common/xwalk_extension.cc b/src/xwalk/extensions/common/xwalk_extension.cc index 00c2ef4..f636957 100644 --- a/src/xwalk/extensions/common/xwalk_extension.cc +++ b/src/xwalk/extensions/common/xwalk_extension.cc @@ -4,8 +4,6 @@ #include "xwalk/extensions/common/xwalk_extension.h" -#include - #include "base/logging.h" namespace xwalk { @@ -25,7 +23,7 @@ XWalkExtension::XWalkExtension() : permissions_delegate_(NULL) {} XWalkExtension::~XWalkExtension() {} -const base::ListValue& XWalkExtension::entry_points() const { +const std::vector& XWalkExtension::entry_points() const { return entry_points_; } diff --git a/src/xwalk/extensions/common/xwalk_extension.h b/src/xwalk/extensions/common/xwalk_extension.h index d6b1ff4..a86f8db 100644 --- a/src/xwalk/extensions/common/xwalk_extension.h +++ b/src/xwalk/extensions/common/xwalk_extension.h @@ -54,7 +54,7 @@ class XWalkExtension { // Returns a list of entry points for which the extension should be loaded // when accessed. Entry points are used when the extension needs to have // objects outside the namespace that is implicitly created using its name. - virtual const base::ListValue& entry_points() const; + virtual const std::vector& entry_points() const; void set_permissions_delegate(XWalkExtension::PermissionsDelegate* delegate) { permissions_delegate_ = delegate; @@ -70,7 +70,8 @@ class XWalkExtension { javascript_api_ = javascript_api; } void set_entry_points(const std::vector& entry_points) { - entry_points_.AppendStrings(entry_points); + entry_points_.insert(entry_points_.end(), entry_points.begin(), + entry_points.end()); } private: @@ -82,9 +83,7 @@ class XWalkExtension { // message passing. std::string javascript_api_; - // FIXME(jeez): convert this to std::vector to avoid - // extra conversions later on. - base::ListValue entry_points_; + std::vector entry_points_; // Permission check delegate for both in and out of process extensions. PermissionsDelegate* permissions_delegate_; diff --git a/src/xwalk/extensions/common/xwalk_extension_server.cc b/src/xwalk/extensions/common/xwalk_extension_server.cc index 1350bad..3a00646 100644 --- a/src/xwalk/extensions/common/xwalk_extension_server.cc +++ b/src/xwalk/extensions/common/xwalk_extension_server.cc @@ -177,12 +177,9 @@ bool XWalkExtensionServer::RegisterExtension( return false; } - const base::ListValue& entry_points = extension->entry_points(); - base::ListValue::const_iterator it = entry_points.begin(); + const std::vector& entry_points = extension->entry_points(); - for (; it != entry_points.end(); ++it) { - std::string entry_point; - (*it)->GetAsString(&entry_point); + for (const std::string& entry_point : entry_points) { extension_symbols_.insert(entry_point); } @@ -280,14 +277,8 @@ void XWalkExtensionServer::DeleteInstanceMap() { } bool XWalkExtensionServer::ValidateExtensionEntryPoints( - const base::ListValue& entry_points) { - base::ListValue::const_iterator it = entry_points.begin(); - - for (; it != entry_points.end(); ++it) { - std::string entry_point; - - (*it)->GetAsString(&entry_point); - + const std::vector& entry_points) { + for (const std::string& entry_point : entry_points) { if (!ValidateExtensionIdentifier(entry_point)) return false; @@ -357,11 +348,8 @@ void XWalkExtensionServer::OnGetExtensions( extension_parameters.name = extension->name(); extension_parameters.js_api = extension->javascript_api(); - const base::ListValue& entry_points = extension->entry_points(); - base::ListValue::const_iterator entry_it = entry_points.begin(); - for (; entry_it != entry_points.end(); ++entry_it) { - std::string entry_point; - (*entry_it)->GetAsString(&entry_point); + const std::vector& entry_points = extension->entry_points(); + for (const std::string& entry_point : entry_points) { extension_parameters.entry_points.push_back(entry_point); } diff --git a/src/xwalk/extensions/common/xwalk_extension_server.h b/src/xwalk/extensions/common/xwalk_extension_server.h index e79fc48..5e4e869 100644 --- a/src/xwalk/extensions/common/xwalk_extension_server.h +++ b/src/xwalk/extensions/common/xwalk_extension_server.h @@ -101,7 +101,8 @@ class XWalkExtensionServer : public IPC::Listener, void DeleteInstanceMap(); - bool ValidateExtensionEntryPoints(const base::ListValue& entry_points); + bool ValidateExtensionEntryPoints( + const std::vector& entry_points); base::Lock sender_lock_; IPC::Sender* sender_; diff --git a/src/xwalk/extensions/test/bad_extension_test.cc b/src/xwalk/extensions/test/bad_extension_test.cc index bcb1ef8..90273b1 100644 --- a/src/xwalk/extensions/test/bad_extension_test.cc +++ b/src/xwalk/extensions/test/bad_extension_test.cc @@ -12,6 +12,7 @@ #include "content/public/test/browser_test_utils.h" #include "content/public/test/test_utils.h" +using xwalk::Runtime; using xwalk::extensions::XWalkExtensionService; class BadExtensionTest : public XWalkExtensionsTestBase { @@ -24,29 +25,29 @@ class BadExtensionTest : public XWalkExtensionsTestBase { }; IN_PROC_BROWSER_TEST_F(BadExtensionTest, DoNotCrash) { - content::RunAllPendingInMessageLoop(); LOG(WARNING) << "This test will produce a lot warnings which are expected." << " The goal is to not crash."; GURL url = GetExtensionsTestURL(base::FilePath(), base::FilePath().AppendASCII("bad.html")); - content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString); + Runtime* runtime = CreateRuntime(); + content::TitleWatcher title_watcher(runtime->web_contents(), kPassString); title_watcher.AlsoWaitForTitle(kFailString); - xwalk_test_utils::NavigateToURL(runtime(), url); + xwalk_test_utils::NavigateToURL(runtime, url); EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle()); } IN_PROC_BROWSER_TEST_F(BadExtensionTest, NavigateDoNotCrash) { - content::RunAllPendingInMessageLoop(); LOG(WARNING) << "This test will produce a lot warnings which are expected." << " The goal is to not crash."; GURL url = GetExtensionsTestURL(base::FilePath(), base::FilePath().AppendASCII("bad.html")); - content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString); + Runtime* runtime = CreateRuntime(); + content::TitleWatcher title_watcher(runtime->web_contents(), kPassString); title_watcher.AlsoWaitForTitle(kFailString); for (int i = 0; i < 5; i++) { - xwalk_test_utils::NavigateToURL(runtime(), url); - WaitForLoadStop(runtime()->web_contents()); + xwalk_test_utils::NavigateToURL(runtime, url); + WaitForLoadStop(runtime->web_contents()); EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle()); } } diff --git a/src/xwalk/extensions/test/conflicting_entry_points.cc b/src/xwalk/extensions/test/conflicting_entry_points.cc index 0766787..650230e 100644 --- a/src/xwalk/extensions/test/conflicting_entry_points.cc +++ b/src/xwalk/extensions/test/conflicting_entry_points.cc @@ -12,6 +12,7 @@ #include "xwalk/test/base/xwalk_test_utils.h" using namespace xwalk::extensions; // NOLINT +using xwalk::Runtime; namespace { @@ -106,14 +107,14 @@ class XWalkExtensionsConflictsWithEntryPointTest IN_PROC_BROWSER_TEST_F(XWalkExtensionsConflictsWithNameTest, OnlyCleanInstanceLoaded) { - content::RunAllPendingInMessageLoop(); + Runtime* runtime = CreateRuntime(); GURL url = GetExtensionsTestURL( base::FilePath(), base::FilePath().AppendASCII("conflicting_names.html")); - content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString); + content::TitleWatcher title_watcher(runtime->web_contents(), kPassString); title_watcher.AlsoWaitForTitle(kFailString); - xwalk_test_utils::NavigateToURL(runtime(), url); + xwalk_test_utils::NavigateToURL(runtime, url); EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle()); EXPECT_TRUE(g_clean_extension_loaded); @@ -122,14 +123,14 @@ IN_PROC_BROWSER_TEST_F(XWalkExtensionsConflictsWithNameTest, IN_PROC_BROWSER_TEST_F(XWalkExtensionsConflictsWithEntryPointTest, OnlyCleanInstanceLoaded) { - content::RunAllPendingInMessageLoop(); + Runtime* runtime = CreateRuntime(); GURL url = GetExtensionsTestURL( base::FilePath(), base::FilePath().AppendASCII("conflicting_names.html")); - content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString); + content::TitleWatcher title_watcher(runtime->web_contents(), kPassString); title_watcher.AlsoWaitForTitle(kFailString); - xwalk_test_utils::NavigateToURL(runtime(), url); + xwalk_test_utils::NavigateToURL(runtime, url); EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle()); EXPECT_TRUE(g_clean_extension_loaded); diff --git a/src/xwalk/extensions/test/context_destruction.cc b/src/xwalk/extensions/test/context_destruction.cc index cbc1246..6520338 100644 --- a/src/xwalk/extensions/test/context_destruction.cc +++ b/src/xwalk/extensions/test/context_destruction.cc @@ -15,6 +15,7 @@ #include "xwalk/test/base/xwalk_test_utils.h" using namespace xwalk::extensions; // NOLINT +using xwalk::Runtime; namespace { @@ -85,21 +86,21 @@ class XWalkExtensionsContextDestructionTest : public XWalkExtensionsTestBase { IN_PROC_BROWSER_TEST_F(XWalkExtensionsContextDestructionTest, ContextIsDestroyedWhenNavigating) { - content::RunAllPendingInMessageLoop(); + Runtime* runtime = CreateRuntime(); GURL url = GetExtensionsTestURL(base::FilePath(), base::FilePath().AppendASCII("context_destruction.html")); { - content::TitleWatcher title_watcher(runtime()->web_contents(), kFailString); + content::TitleWatcher title_watcher(runtime->web_contents(), kFailString); title_watcher.AlsoWaitForTitle(kPassString); - xwalk_test_utils::NavigateToURL(runtime(), url); + xwalk_test_utils::NavigateToURL(runtime, url); EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle()); } { - content::TitleWatcher title_watcher(runtime()->web_contents(), kFailString); + content::TitleWatcher title_watcher(runtime->web_contents(), kFailString); title_watcher.AlsoWaitForTitle(kPassString); - xwalk_test_utils::NavigateToURL(runtime(), url); + xwalk_test_utils::NavigateToURL(runtime, url); EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle()); } diff --git a/src/xwalk/extensions/test/crash_extension_process.cc b/src/xwalk/extensions/test/crash_extension_process.cc index da5fd40..0aefe90 100644 --- a/src/xwalk/extensions/test/crash_extension_process.cc +++ b/src/xwalk/extensions/test/crash_extension_process.cc @@ -13,6 +13,7 @@ #include "content/public/test/browser_test_utils.h" using xwalk::extensions::XWalkExtensionService; +using xwalk::Runtime; class CrashExtensionTest : public XWalkExtensionsTestBase { public: @@ -33,10 +34,11 @@ IN_PROC_BROWSER_TEST_F(CrashExtensionTest, CrashExtensionProcessKeepBPAlive) { GURL url = GetExtensionsTestURL(base::FilePath(), base::FilePath().AppendASCII("crash.html")); - content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString); + Runtime* runtime = CreateRuntime(); + content::TitleWatcher title_watcher(runtime->web_contents(), kPassString); - xwalk_test_utils::NavigateToURL(runtime(), url); - WaitForLoadStop(runtime()->web_contents()); + xwalk_test_utils::NavigateToURL(runtime, url); + WaitForLoadStop(runtime->web_contents()); EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle()); } diff --git a/src/xwalk/extensions/test/export_object.cc b/src/xwalk/extensions/test/export_object.cc index 1ef9166..3daf722 100644 --- a/src/xwalk/extensions/test/export_object.cc +++ b/src/xwalk/extensions/test/export_object.cc @@ -65,10 +65,10 @@ IN_PROC_BROWSER_TEST_F(XWalkExtensionsExportObjectTest, content::RunAllPendingInMessageLoop(); GURL url = GetExtensionsTestURL(base::FilePath(), base::FilePath().AppendASCII("test_export_object.html")); - - content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString); + xwalk::Runtime* runtime = CreateRuntime(); + content::TitleWatcher title_watcher(runtime->web_contents(), kPassString); title_watcher.AlsoWaitForTitle(kFailString); - xwalk_test_utils::NavigateToURL(runtime(), url); + xwalk_test_utils::NavigateToURL(runtime, url); EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle()); } diff --git a/src/xwalk/extensions/test/extension_in_iframe.cc b/src/xwalk/extensions/test/extension_in_iframe.cc index dc66ecf..3c5be22 100644 --- a/src/xwalk/extensions/test/extension_in_iframe.cc +++ b/src/xwalk/extensions/test/extension_in_iframe.cc @@ -15,6 +15,7 @@ #include "xwalk/test/base/xwalk_test_utils.h" using namespace xwalk::extensions; // NOLINT +using xwalk::Runtime; namespace { @@ -60,17 +61,17 @@ class XWalkExtensionsIFrameTest : public XWalkExtensionsTestBase { IN_PROC_BROWSER_TEST_F(XWalkExtensionsIFrameTest, ContextsAreCreatedForIFrames) { - content::RunAllPendingInMessageLoop(); + Runtime* runtime = CreateRuntime(); GURL url = GetExtensionsTestURL(base::FilePath(), base::FilePath().AppendASCII("counter_with_iframes.html")); - xwalk_test_utils::NavigateToURL(runtime(), url); + xwalk_test_utils::NavigateToURL(runtime, url); SPIN_FOR_1_SECOND_OR_UNTIL_TRUE(g_count == 3); ASSERT_EQ(g_count, 3); } IN_PROC_BROWSER_TEST_F(XWalkExtensionsIFrameTest, ContextsAreNotCreatedForIFramesWithBlankPages) { - content::RunAllPendingInMessageLoop(); + Runtime* runtime = CreateRuntime(); GURL url = GetExtensionsTestURL(base::FilePath(), base::FilePath().AppendASCII("blank_iframes.html")); @@ -78,10 +79,10 @@ IN_PROC_BROWSER_TEST_F(XWalkExtensionsIFrameTest, // full of blank iframes and afterwards we navigate to another page. // ModuleSystems should not be created and consequentially not deleted for the // blank iframes. - xwalk_test_utils::NavigateToURL(runtime(), url); - content::TitleWatcher title_watcher1(runtime()->web_contents(), kPassString); - xwalk_test_utils::NavigateToURL(runtime(), url); - content::TitleWatcher title_watcher2(runtime()->web_contents(), kPassString); + xwalk_test_utils::NavigateToURL(runtime, url); + content::TitleWatcher title_watcher1(runtime->web_contents(), kPassString); + xwalk_test_utils::NavigateToURL(runtime, url); + content::TitleWatcher title_watcher2(runtime->web_contents(), kPassString); } // This test reproduces the problem found in bug @@ -96,13 +97,13 @@ IN_PROC_BROWSER_TEST_F(XWalkExtensionsIFrameTest, // delete it when releasing the script context. IN_PROC_BROWSER_TEST_F(XWalkExtensionsIFrameTest, IFrameUsingDocumentWriteShouldNotCrash) { - content::RunAllPendingInMessageLoop(); + Runtime* runtime = CreateRuntime(); GURL url = GetExtensionsTestURL(base::FilePath(), base::FilePath().AppendASCII("iframe_using_document_write.html")); for (int i = 0; i < 5; i++) { - content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString); - xwalk_test_utils::NavigateToURL(runtime(), url); + content::TitleWatcher title_watcher(runtime->web_contents(), kPassString); + xwalk_test_utils::NavigateToURL(runtime, url); EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle()); } } @@ -113,13 +114,13 @@ IN_PROC_BROWSER_TEST_F(XWalkExtensionsIFrameTest, // iframe_keep_reference.html for more details. IN_PROC_BROWSER_TEST_F(XWalkExtensionsIFrameTest, KeepingReferenceToFunctionFromDestroyedIFrame) { - content::RunAllPendingInMessageLoop(); + Runtime* runtime = CreateRuntime(); GURL url = GetExtensionsTestURL( base::FilePath(), base::FilePath().AppendASCII("iframe_keep_reference.html")); - content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString); + content::TitleWatcher title_watcher(runtime->web_contents(), kPassString); title_watcher.AlsoWaitForTitle(kFailString); - xwalk_test_utils::NavigateToURL(runtime(), url); + xwalk_test_utils::NavigateToURL(runtime, url); EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle()); ASSERT_EQ(g_count, 1); } diff --git a/src/xwalk/extensions/test/external_extension.cc b/src/xwalk/extensions/test/external_extension.cc index 9ff4de1..a6f09bd 100644 --- a/src/xwalk/extensions/test/external_extension.cc +++ b/src/xwalk/extensions/test/external_extension.cc @@ -13,6 +13,7 @@ #include "content/public/test/test_utils.h" using xwalk::extensions::XWalkExtensionService; +using xwalk::Runtime; class ExternalExtensionTest : public XWalkExtensionsTestBase { public: @@ -43,81 +44,81 @@ class MultipleEntryPointsExtension : public XWalkExtensionsTestBase { }; IN_PROC_BROWSER_TEST_F(ExternalExtensionTest, ExternalExtension) { - content::RunAllPendingInMessageLoop(); + Runtime* runtime = CreateRuntime(); GURL url = GetExtensionsTestURL(base::FilePath(), base::FilePath().AppendASCII("echo.html")); - content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString); + content::TitleWatcher title_watcher(runtime->web_contents(), kPassString); title_watcher.AlsoWaitForTitle(kFailString); - xwalk_test_utils::NavigateToURL(runtime(), url); + xwalk_test_utils::NavigateToURL(runtime, url); EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle()); } IN_PROC_BROWSER_TEST_F(ExternalExtensionTest, NavigateWithExternalExtension) { - content::RunAllPendingInMessageLoop(); + Runtime* runtime = CreateRuntime(); GURL url = GetExtensionsTestURL(base::FilePath(), base::FilePath().AppendASCII("echo.html")); - content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString); + content::TitleWatcher title_watcher(runtime->web_contents(), kPassString); title_watcher.AlsoWaitForTitle(kFailString); for (int i = 0; i < 5; i++) { - xwalk_test_utils::NavigateToURL(runtime(), url); - WaitForLoadStop(runtime()->web_contents()); + xwalk_test_utils::NavigateToURL(runtime, url); + WaitForLoadStop(runtime->web_contents()); EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle()); } } IN_PROC_BROWSER_TEST_F(ExternalExtensionTest, ExternalExtensionSync) { - content::RunAllPendingInMessageLoop(); + Runtime* runtime = CreateRuntime(); GURL url = GetExtensionsTestURL( base::FilePath(), base::FilePath().AppendASCII("sync_echo.html")); - content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString); + content::TitleWatcher title_watcher(runtime->web_contents(), kPassString); title_watcher.AlsoWaitForTitle(kFailString); - xwalk_test_utils::NavigateToURL(runtime(), url); + xwalk_test_utils::NavigateToURL(runtime, url); EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle()); } IN_PROC_BROWSER_TEST_F(RuntimeInterfaceTest, GetRuntimeVariable) { - content::RunAllPendingInMessageLoop(); + Runtime* runtime = CreateRuntime(); GURL url = GetExtensionsTestURL( base::FilePath(), base::FilePath().AppendASCII("get_runtime_variable.html")); - content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString); + content::TitleWatcher title_watcher(runtime->web_contents(), kPassString); title_watcher.AlsoWaitForTitle(kFailString); - xwalk_test_utils::NavigateToURL(runtime(), url); + xwalk_test_utils::NavigateToURL(runtime, url); EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle()); } IN_PROC_BROWSER_TEST_F(MultipleEntryPointsExtension, MultipleEntryPoints) { - content::RunAllPendingInMessageLoop(); + Runtime* runtime = CreateRuntime(); GURL url = GetExtensionsTestURL( base::FilePath(), base::FilePath().AppendASCII("entry_points.html")); - content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString); + content::TitleWatcher title_watcher(runtime->web_contents(), kPassString); title_watcher.AlsoWaitForTitle(kFailString); - xwalk_test_utils::NavigateToURL(runtime(), url); + xwalk_test_utils::NavigateToURL(runtime, url); EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle()); } IN_PROC_BROWSER_TEST_F(MultipleEntryPointsExtension, SetterLoadsExtension) { - content::RunAllPendingInMessageLoop(); + Runtime* runtime = CreateRuntime(); GURL url = GetExtensionsTestURL( base::FilePath(), base::FilePath().AppendASCII("setter_callback_entry_point.html")); - content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString); + content::TitleWatcher title_watcher(runtime->web_contents(), kPassString); title_watcher.AlsoWaitForTitle(kFailString); - xwalk_test_utils::NavigateToURL(runtime(), url); + xwalk_test_utils::NavigateToURL(runtime, url); EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle()); } IN_PROC_BROWSER_TEST_F(MultipleEntryPointsExtension, ReplacementObjectIsUsed) { - content::RunAllPendingInMessageLoop(); + Runtime* runtime = CreateRuntime(); GURL url = GetExtensionsTestURL( base::FilePath(), base::FilePath().AppendASCII( "lazy_loaded_extension_overrides_object.html")); - content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString); + content::TitleWatcher title_watcher(runtime->web_contents(), kPassString); title_watcher.AlsoWaitForTitle(kFailString); - xwalk_test_utils::NavigateToURL(runtime(), url); + xwalk_test_utils::NavigateToURL(runtime, url); EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle()); } diff --git a/src/xwalk/extensions/test/external_extension_multi_process.cc b/src/xwalk/extensions/test/external_extension_multi_process.cc index 4c86808..494a157 100644 --- a/src/xwalk/extensions/test/external_extension_multi_process.cc +++ b/src/xwalk/extensions/test/external_extension_multi_process.cc @@ -16,57 +16,11 @@ using xwalk::NativeAppWindow; using xwalk::Runtime; using xwalk::extensions::XWalkExtensionVector; -namespace { -Runtime* CreateWithDefaultWindow( - xwalk::RuntimeContext* runtime_context, const GURL& url, - Runtime::Observer* observer = NULL) { - Runtime* runtime = Runtime::Create(runtime_context, observer); - runtime->LoadURL(url); -#if !defined(OS_ANDROID) - xwalk::RuntimeUIStrategy ui_strategy; - xwalk::NativeAppWindow::CreateParams params; - ui_strategy.Show(runtime, params); -#endif - return runtime; -} -} // namespace - class ExternalExtensionMultiProcessTest : public XWalkExtensionsTestBase { public: ExternalExtensionMultiProcessTest() : register_extensions_count_(0) {} - virtual ~ExternalExtensionMultiProcessTest() { - original_runtimes_.clear(); - notification_observer_.reset(); - } - - // SetUpOnMainThread is called after BrowserMainRunner was initialized and - // just before RunTestOnMainThread. - virtual void SetUpOnMainThread() OVERRIDE { - notification_observer_.reset( - new content::WindowedNotificationObserver( - xwalk::NOTIFICATION_RUNTIME_OPENED, - content::NotificationService::AllSources())); - original_runtimes_.assign(runtimes().begin(), runtimes().end()); - } - - // Block UI thread until a new Runtime instance is created. - Runtime* WaitForSingleNewRuntime() { - notification_observer_->Wait(); - for (RuntimeList::const_iterator it = runtimes().begin(); - it != runtimes().end(); ++it) { - RuntimeList::iterator target = - std::find(original_runtimes_.begin(), original_runtimes_.end(), *it); - // Not found means a new one. - if (target == original_runtimes_.end()) { - original_runtimes_.push_back(*it); - return *it; - } - } - return NULL; - } - // This will be called everytime a new RenderProcess has been created. virtual void CreateExtensionsForUIThread( XWalkExtensionVector* extensions) OVERRIDE { @@ -78,72 +32,55 @@ class ExternalExtensionMultiProcessTest : public XWalkExtensionsTestBase { } private: - RuntimeList original_runtimes_; - scoped_ptr notification_observer_; - int register_extensions_count_; }; IN_PROC_BROWSER_TEST_F(ExternalExtensionMultiProcessTest, OpenLinkInNewRuntimeAndSameRP) { - size_t len = runtimes().size(); - GURL url = GetExtensionsTestURL(base::FilePath(), base::FilePath().AppendASCII("same_rp.html")); - - xwalk_test_utils::NavigateToURL(runtime(), url); - WaitForLoadStop(runtime()->web_contents()); - + Runtime* runtime = CreateRuntime(url); + size_t len = runtimes().size(); EXPECT_EQ(1, CountRegisterExtensions()); - SimulateMouseClick(runtime()->web_contents(), 0, + SimulateMouseClick(runtime->web_contents(), 0, blink::WebMouseEvent::ButtonLeft); content::RunAllPendingInMessageLoop(); - Runtime* second = WaitForSingleNewRuntime(); - EXPECT_TRUE(NULL != second); - EXPECT_NE(runtime(), second); EXPECT_EQ(len + 1, runtimes().size()); + Runtime* second = runtimes().back(); + EXPECT_TRUE(NULL != second); + EXPECT_NE(runtime, second); EXPECT_EQ(1, CountRegisterExtensions()); } IN_PROC_BROWSER_TEST_F(ExternalExtensionMultiProcessTest, OpenLinkInNewRuntimeAndNewRP) { - size_t len = runtimes().size(); - GURL url = GetExtensionsTestURL(base::FilePath(), base::FilePath().AppendASCII("new_rp.html")); - - xwalk_test_utils::NavigateToURL(runtime(), url); - WaitForLoadStop(runtime()->web_contents()); - + Runtime* runtime = CreateRuntime(url); + size_t len = runtimes().size(); EXPECT_EQ(1, CountRegisterExtensions()); - SimulateMouseClick(runtime()->web_contents(), 0, + SimulateMouseClick(runtime->web_contents(), 0, blink::WebMouseEvent::ButtonLeft); content::RunAllPendingInMessageLoop(); - Runtime* second = WaitForSingleNewRuntime(); - EXPECT_TRUE(NULL != second); - EXPECT_NE(runtime(), second); EXPECT_EQ(len + 1, runtimes().size()); + Runtime* second = runtimes().back(); + EXPECT_TRUE(NULL != second); + EXPECT_NE(runtime, second); EXPECT_EQ(2, CountRegisterExtensions()); } IN_PROC_BROWSER_TEST_F(ExternalExtensionMultiProcessTest, CreateNewRuntimeAndNewRP) { - size_t len = runtimes().size(); - GURL url = GetExtensionsTestURL(base::FilePath(), base::FilePath().AppendASCII("new_rp.html")); - - xwalk_test_utils::NavigateToURL(runtime(), url); - WaitForLoadStop(runtime()->web_contents()); + Runtime* runtime = CreateRuntime(url); + size_t len = runtimes().size(); EXPECT_EQ(1, CountRegisterExtensions()); - Runtime* new_runtime = CreateWithDefaultWindow( - GetRuntimeContext(), url, runtime_registry()); - EXPECT_EQ(new_runtime, WaitForSingleNewRuntime()); - EXPECT_NE(runtime(), new_runtime); - content::RunAllPendingInMessageLoop(); + Runtime* new_runtime = CreateRuntime(url); + EXPECT_NE(runtime, new_runtime); EXPECT_EQ(len + 1, runtimes().size()); EXPECT_EQ(2, CountRegisterExtensions()); } diff --git a/src/xwalk/extensions/test/in_process_threads_browsertest.cc b/src/xwalk/extensions/test/in_process_threads_browsertest.cc index b3232f1..4d3132e 100644 --- a/src/xwalk/extensions/test/in_process_threads_browsertest.cc +++ b/src/xwalk/extensions/test/in_process_threads_browsertest.cc @@ -11,6 +11,7 @@ #include "xwalk/test/base/xwalk_test_utils.h" using namespace xwalk::extensions; // NOLINT +using xwalk::Runtime; const char kInProcessExtensionThread[] = "in_process_extension_thread"; const char kInProcessUIThread[] = "in_process_ui_thread"; @@ -77,14 +78,13 @@ class InProcessThreadsTest : public XWalkExtensionsTestBase { }; IN_PROC_BROWSER_TEST_F(InProcessThreadsTest, InProcessThreads) { - content::RunAllPendingInMessageLoop(); - - content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString); + Runtime* runtime = CreateRuntime(); + content::TitleWatcher title_watcher(runtime->web_contents(), kPassString); title_watcher.AlsoWaitForTitle(kFailString); GURL url = GetExtensionsTestURL(base::FilePath(), base::FilePath().AppendASCII("in_process_threads.html")); - xwalk_test_utils::NavigateToURL(runtime(), url); + xwalk_test_utils::NavigateToURL(runtime, url); EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle()); } diff --git a/src/xwalk/extensions/test/internal_extension_browsertest.cc b/src/xwalk/extensions/test/internal_extension_browsertest.cc index 2f8fb4f..4ea58dc 100644 --- a/src/xwalk/extensions/test/internal_extension_browsertest.cc +++ b/src/xwalk/extensions/test/internal_extension_browsertest.cc @@ -17,6 +17,7 @@ using namespace xwalk::extensions; // NOLINT using namespace xwalk::jsapi::test; // NOLINT +using xwalk::Runtime; TestExtension::TestExtension() { set_name("test"); @@ -162,14 +163,13 @@ class InternalExtensionTest : public XWalkExtensionsTestBase { }; IN_PROC_BROWSER_TEST_F(InternalExtensionTest, InternalExtension) { - content::RunAllPendingInMessageLoop(); - - content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString); + Runtime* runtime = CreateRuntime(); + content::TitleWatcher title_watcher(runtime->web_contents(), kPassString); title_watcher.AlsoWaitForTitle(kFailString); GURL url = GetExtensionsTestURL(base::FilePath(), base::FilePath().AppendASCII("test_internal_extension.html")); - xwalk_test_utils::NavigateToURL(runtime(), url); + xwalk_test_utils::NavigateToURL(runtime, url); EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle()); } diff --git a/src/xwalk/extensions/test/namespace_read_only.cc b/src/xwalk/extensions/test/namespace_read_only.cc index 545d264..8164aa3 100644 --- a/src/xwalk/extensions/test/namespace_read_only.cc +++ b/src/xwalk/extensions/test/namespace_read_only.cc @@ -13,6 +13,7 @@ #include "content/public/test/browser_test_utils.h" using xwalk::extensions::XWalkExtensionService; +using xwalk::Runtime; class NamespaceReadOnlyExtensionTest : public XWalkExtensionsTestBase { public: @@ -27,11 +28,12 @@ IN_PROC_BROWSER_TEST_F(NamespaceReadOnlyExtensionTest, NamespaceReadOnly) { GURL url = GetExtensionsTestURL(base::FilePath(), base::FilePath().AppendASCII( "namespace_read_only.html")); - content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString); + Runtime* runtime = CreateRuntime(); + content::TitleWatcher title_watcher(runtime->web_contents(), kPassString); title_watcher.AlsoWaitForTitle(kFailString); - xwalk_test_utils::NavigateToURL(runtime(), url); - WaitForLoadStop(runtime()->web_contents()); + xwalk_test_utils::NavigateToURL(runtime, url); + WaitForLoadStop(runtime->web_contents()); EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle()); } @@ -40,11 +42,12 @@ IN_PROC_BROWSER_TEST_F( NamespaceReadOnlyExtensionTest, NamespaceReadOnlyAfterEntryPointCalled) { GURL url = GetExtensionsTestURL(base::FilePath(), base::FilePath().AppendASCII("namespace_read_only_with_entrypoint.html")); - content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString); + Runtime* runtime = CreateRuntime(); + content::TitleWatcher title_watcher(runtime->web_contents(), kPassString); title_watcher.AlsoWaitForTitle(kFailString); - xwalk_test_utils::NavigateToURL(runtime(), url); - WaitForLoadStop(runtime()->web_contents()); + xwalk_test_utils::NavigateToURL(runtime, url); + WaitForLoadStop(runtime->web_contents()); EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle()); } diff --git a/src/xwalk/extensions/test/nested_namespace.cc b/src/xwalk/extensions/test/nested_namespace.cc index 3fae14f..be9159d 100644 --- a/src/xwalk/extensions/test/nested_namespace.cc +++ b/src/xwalk/extensions/test/nested_namespace.cc @@ -11,6 +11,7 @@ #include "xwalk/test/base/xwalk_test_utils.h" using namespace xwalk::extensions; // NOLINT +using xwalk::Runtime; namespace { @@ -107,13 +108,13 @@ class XWalkExtensionsTrampolinesForNested : public XWalkExtensionsTestBase { IN_PROC_BROWSER_TEST_F(XWalkExtensionsNestedNamespaceTest, InstanceCreatedForInnerExtension) { - content::RunAllPendingInMessageLoop(); + Runtime* runtime = CreateRuntime(); GURL url = GetExtensionsTestURL(base::FilePath(), base::FilePath().AppendASCII("inner_outer.html")); - content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString); + content::TitleWatcher title_watcher(runtime->web_contents(), kPassString); title_watcher.AlsoWaitForTitle(kFailString); - xwalk_test_utils::NavigateToURL(runtime(), url); + xwalk_test_utils::NavigateToURL(runtime, url); EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle()); EXPECT_TRUE(g_outer_extension_loaded); @@ -122,13 +123,13 @@ IN_PROC_BROWSER_TEST_F(XWalkExtensionsNestedNamespaceTest, IN_PROC_BROWSER_TEST_F(XWalkExtensionsNestedNamespaceTest, InstanceNotCreatedForUnusedInnerExtension) { - content::RunAllPendingInMessageLoop(); + Runtime* runtime = CreateRuntime(); GURL url = GetExtensionsTestURL(base::FilePath(), base::FilePath().AppendASCII("outer.html")); - content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString); + content::TitleWatcher title_watcher(runtime->web_contents(), kPassString); title_watcher.AlsoWaitForTitle(kFailString); - xwalk_test_utils::NavigateToURL(runtime(), url); + xwalk_test_utils::NavigateToURL(runtime, url); EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle()); EXPECT_TRUE(g_outer_extension_loaded); @@ -137,13 +138,13 @@ IN_PROC_BROWSER_TEST_F(XWalkExtensionsNestedNamespaceTest, IN_PROC_BROWSER_TEST_F(XWalkExtensionsTrampolinesForNested, InstanceCreatedForExtensionUsedByAnother) { - content::RunAllPendingInMessageLoop(); + Runtime* runtime = CreateRuntime(); GURL url = GetExtensionsTestURL(base::FilePath(), base::FilePath().AppendASCII("another.html")); - content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString); + content::TitleWatcher title_watcher(runtime->web_contents(), kPassString); title_watcher.AlsoWaitForTitle(kFailString); - xwalk_test_utils::NavigateToURL(runtime(), url); + xwalk_test_utils::NavigateToURL(runtime, url); EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle()); EXPECT_TRUE(g_another_extension_loaded); diff --git a/src/xwalk/extensions/test/v8tools_module.cc b/src/xwalk/extensions/test/v8tools_module.cc index f2a13d4..113b7e7 100644 --- a/src/xwalk/extensions/test/v8tools_module.cc +++ b/src/xwalk/extensions/test/v8tools_module.cc @@ -12,12 +12,10 @@ #include "xwalk/test/base/xwalk_test_utils.h" using namespace xwalk::extensions; // NOLINT +using xwalk::Runtime; class TestV8ToolsExtensionInstance : public XWalkExtensionInstance { public: - explicit TestV8ToolsExtensionInstance() { - } - virtual void HandleMessage(scoped_ptr msg) OVERRIDE {} }; @@ -51,13 +49,13 @@ class XWalkExtensionsV8ToolsTest : public XWalkExtensionsTestBase { IN_PROC_BROWSER_TEST_F(XWalkExtensionsV8ToolsTest, V8ToolsWorks) { - content::RunAllPendingInMessageLoop(); + Runtime* runtime = CreateRuntime(); GURL url = GetExtensionsTestURL(base::FilePath(), base::FilePath().AppendASCII("test_v8tools.html")); - content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString); + content::TitleWatcher title_watcher(runtime->web_contents(), kPassString); title_watcher.AlsoWaitForTitle(kFailString); - xwalk_test_utils::NavigateToURL(runtime(), url); + xwalk_test_utils::NavigateToURL(runtime, url); EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle()); } diff --git a/src/xwalk/extensions/test/xwalk_extensions_browsertest.cc b/src/xwalk/extensions/test/xwalk_extensions_browsertest.cc index 0feb263..6510755 100644 --- a/src/xwalk/extensions/test/xwalk_extensions_browsertest.cc +++ b/src/xwalk/extensions/test/xwalk_extensions_browsertest.cc @@ -14,6 +14,7 @@ #include "base/time/time.h" using namespace xwalk::extensions; // NOLINT +using xwalk::Runtime; namespace { @@ -46,8 +47,6 @@ class EchoContext : public XWalkExtensionInstance { class DelayedEchoContext : public XWalkExtensionInstance { public: - explicit DelayedEchoContext() { - } virtual void HandleMessage(scoped_ptr msg) OVERRIDE { PostMessageToJS(msg.Pass()); } @@ -168,22 +167,22 @@ class XWalkExtensionsDelayedTest : public XWalkExtensionsTestBase { }; IN_PROC_BROWSER_TEST_F(XWalkExtensionsTest, EchoExtension) { - content::RunAllPendingInMessageLoop(); GURL url = GetExtensionsTestURL(base::FilePath(), base::FilePath().AppendASCII("test_extension.html")); - content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString); + Runtime* runtime = CreateRuntime(); + content::TitleWatcher title_watcher(runtime->web_contents(), kPassString); title_watcher.AlsoWaitForTitle(kFailString); - xwalk_test_utils::NavigateToURL(runtime(), url); + xwalk_test_utils::NavigateToURL(runtime, url); EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle()); } IN_PROC_BROWSER_TEST_F(XWalkExtensionsTest, ExtensionWithInvalidNameIgnored) { - content::RunAllPendingInMessageLoop(); + Runtime* runtime = CreateRuntime(); GURL url = GetExtensionsTestURL(base::FilePath(), base::FilePath().AppendASCII("test_extension.html")); - content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString); + content::TitleWatcher title_watcher(runtime->web_contents(), kPassString); title_watcher.AlsoWaitForTitle(kFailString); - xwalk_test_utils::NavigateToURL(runtime(), url); + xwalk_test_utils::NavigateToURL(runtime, url); EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle()); EXPECT_TRUE(EchoExtension::s_instance_was_created); @@ -191,33 +190,33 @@ IN_PROC_BROWSER_TEST_F(XWalkExtensionsTest, ExtensionWithInvalidNameIgnored) { } IN_PROC_BROWSER_TEST_F(XWalkExtensionsTest, EchoExtensionSync) { - content::RunAllPendingInMessageLoop(); + Runtime* runtime = CreateRuntime(); GURL url = GetExtensionsTestURL(base::FilePath(), base::FilePath().AppendASCII( "sync_echo.html")); - content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString); + content::TitleWatcher title_watcher(runtime->web_contents(), kPassString); title_watcher.AlsoWaitForTitle(kFailString); - xwalk_test_utils::NavigateToURL(runtime(), url); + xwalk_test_utils::NavigateToURL(runtime, url); EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle()); } IN_PROC_BROWSER_TEST_F(XWalkExtensionsDelayedTest, EchoExtensionSync) { - content::RunAllPendingInMessageLoop(); + Runtime* runtime = CreateRuntime(); GURL url = GetExtensionsTestURL(base::FilePath(), base::FilePath().AppendASCII( "sync_echo.html")); - content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString); + content::TitleWatcher title_watcher(runtime->web_contents(), kPassString); title_watcher.AlsoWaitForTitle(kFailString); - xwalk_test_utils::NavigateToURL(runtime(), url); + xwalk_test_utils::NavigateToURL(runtime, url); EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle()); } IN_PROC_BROWSER_TEST_F(XWalkExtensionsTest, BulkDataExtension) { - content::RunAllPendingInMessageLoop(); + Runtime* runtime = CreateRuntime(); GURL url = GetExtensionsTestURL(base::FilePath(), base::FilePath().AppendASCII("bulk_data_transmission.html")); - content::TitleWatcher title_watcher(runtime()->web_contents(), kPassString); + content::TitleWatcher title_watcher(runtime->web_contents(), kPassString); title_watcher.AlsoWaitForTitle(kFailString); - xwalk_test_utils::NavigateToURL(runtime(), url); + xwalk_test_utils::NavigateToURL(runtime, url); EXPECT_EQ(kPassString, title_watcher.WaitAndGetTitle()); } diff --git a/src/xwalk/packaging/crosswalk.spec b/src/xwalk/packaging/crosswalk.spec index 12c5ffa..28c8490 100644 --- a/src/xwalk/packaging/crosswalk.spec +++ b/src/xwalk/packaging/crosswalk.spec @@ -24,7 +24,7 @@ %define _binary_payload w3.gzdio Name: crosswalk -Version: 11.39.252.0 +Version: 11.39.256.0 Release: 0 Summary: Chromium-based app runtime License: (BSD-3-Clause and LGPL-2.1+) diff --git a/src/xwalk/runtime/android/core_internal/src/org/xwalk/core/internal/XWalkContent.java b/src/xwalk/runtime/android/core_internal/src/org/xwalk/core/internal/XWalkContent.java index 4a1d043..b4c9adb 100644 --- a/src/xwalk/runtime/android/core_internal/src/org/xwalk/core/internal/XWalkContent.java +++ b/src/xwalk/runtime/android/core_internal/src/org/xwalk/core/internal/XWalkContent.java @@ -113,9 +113,9 @@ class XWalkContent extends FrameLayout implements XWalkPreferencesInternal.KeyVa MediaPlayerBridge.setResourceLoadingFilter( new XWalkMediaPlayerResourceLoadingFilter()); - XWalkPreferencesInternal.load(this); - setNativeContent(nativeInit()); + + XWalkPreferencesInternal.load(this); } private void setNativeContent(long newNativeContent) { diff --git a/src/xwalk/runtime/browser/android/intercepted_request_data_impl.cc b/src/xwalk/runtime/browser/android/intercepted_request_data_impl.cc index f64b8a8..2edb19f 100644 --- a/src/xwalk/runtime/browser/android/intercepted_request_data_impl.cc +++ b/src/xwalk/runtime/browser/android/intercepted_request_data_impl.cc @@ -14,7 +14,7 @@ #include "xwalk/runtime/browser/android/net/android_protocol_handler.h" #include "xwalk/runtime/browser/android/net/android_stream_reader_url_request_job.h" #include "xwalk/runtime/browser/android/net/input_stream_impl.h" -#include "xwalk/runtime/browser/runtime_context.h" +#include "xwalk/runtime/browser/xwalk_browser_context.h" #include "xwalk/runtime/browser/xwalk_runner.h" using base::android::ScopedJavaLocalRef; @@ -121,9 +121,9 @@ net::URLRequestJob* InterceptedRequestDataImpl::CreateJobFor( scoped_ptr stream_reader_job_delegate_impl(new StreamReaderJobDelegateImpl(this)); - RuntimeContext* runtime_context = - XWalkRunner::GetInstance()->runtime_context(); - std::string content_security_policy = runtime_context->GetCSPString(); + XWalkBrowserContext* browser_context = + XWalkRunner::GetInstance()->browser_context(); + std::string content_security_policy = browser_context->GetCSPString(); return new AndroidStreamReaderURLRequestJob( request, network_delegate, stream_reader_job_delegate_impl.Pass(), diff --git a/src/xwalk/runtime/browser/android/net/android_protocol_handler.cc b/src/xwalk/runtime/browser/android/net/android_protocol_handler.cc index 4a03420..297e864 100644 --- a/src/xwalk/runtime/browser/android/net/android_protocol_handler.cc +++ b/src/xwalk/runtime/browser/android/net/android_protocol_handler.cc @@ -24,7 +24,7 @@ #include "xwalk/runtime/browser/android/net/android_stream_reader_url_request_job.h" #include "xwalk/runtime/browser/android/net/input_stream_impl.h" #include "xwalk/runtime/browser/android/net/url_constants.h" -#include "xwalk/runtime/browser/runtime_context.h" +#include "xwalk/runtime/browser/xwalk_browser_context.h" #include "xwalk/runtime/browser/xwalk_runner.h" using base::android::AttachCurrentThread; @@ -253,9 +253,9 @@ net::URLRequestJob* AndroidRequestInterceptorBase::MaybeInterceptRequest( scoped_ptr reader_delegate( new AndroidStreamReaderURLRequestJobDelegateImpl()); - xwalk::RuntimeContext* runtime_context = - xwalk::XWalkRunner::GetInstance()->runtime_context(); - std::string content_security_policy = runtime_context->GetCSPString(); + xwalk::XWalkBrowserContext* browser_context = + xwalk::XWalkRunner::GetInstance()->browser_context(); + std::string content_security_policy = browser_context->GetCSPString(); return new AndroidStreamReaderURLRequestJob( request, diff --git a/src/xwalk/runtime/browser/android/renderer_host/xwalk_render_view_host_ext.cc b/src/xwalk/runtime/browser/android/renderer_host/xwalk_render_view_host_ext.cc index dc1d74c..f8f5061 100644 --- a/src/xwalk/runtime/browser/android/renderer_host/xwalk_render_view_host_ext.cc +++ b/src/xwalk/runtime/browser/android/renderer_host/xwalk_render_view_host_ext.cc @@ -13,7 +13,7 @@ #include "content/public/browser/web_contents.h" #include "content/public/common/frame_navigate_params.h" #include "xwalk/runtime/browser/android/xwalk_contents_client_bridge.h" -#include "xwalk/runtime/browser/runtime_context.h" +#include "xwalk/runtime/browser/xwalk_browser_context.h" #include "xwalk/runtime/common/android/xwalk_render_view_messages.h" namespace xwalk { @@ -110,7 +110,7 @@ void XWalkRenderViewHostExt::DidNavigateAnyFrame( const content::FrameNavigateParams& params) { DCHECK(CalledOnValidThread()); - RuntimeContext::FromWebContents(web_contents()) + XWalkBrowserContext::FromWebContents(web_contents()) ->AddVisitedURLs(params.redirects); } diff --git a/src/xwalk/runtime/browser/android/xwalk_content.cc b/src/xwalk/runtime/browser/android/xwalk_content.cc index 0054609..62074ce 100644 --- a/src/xwalk/runtime/browser/android/xwalk_content.cc +++ b/src/xwalk/runtime/browser/android/xwalk_content.cc @@ -34,8 +34,8 @@ #include "xwalk/runtime/browser/android/xwalk_contents_client_bridge_base.h" #include "xwalk/runtime/browser/android/xwalk_contents_io_thread_client_impl.h" #include "xwalk/runtime/browser/android/xwalk_web_contents_delegate.h" -#include "xwalk/runtime/browser/runtime_context.h" #include "xwalk/runtime/browser/runtime_resource_dispatcher_host_delegate_android.h" +#include "xwalk/runtime/browser/xwalk_browser_context.h" #include "xwalk/runtime/browser/xwalk_runner.h" #include "jni/XWalkContent_jni.h" @@ -283,10 +283,10 @@ jboolean XWalkContent::SetManifest(JNIEnv* env, std::string csp; ManifestGetString(manifest, keys::kCSPKey, keys::kDeprecatedCSPKey, &csp); - RuntimeContext* runtime_context = - XWalkRunner::GetInstance()->runtime_context(); - CHECK(runtime_context); - runtime_context->SetCSPString(csp); + XWalkBrowserContext* browser_context = + XWalkRunner::GetInstance()->browser_context(); + CHECK(browser_context); + browser_context->SetCSPString(csp); ScopedJavaLocalRef url_buffer = base::android::ConvertUTF8ToJavaString(env, url); @@ -408,7 +408,7 @@ jboolean XWalkContent::SetState(JNIEnv* env, jobject obj, jbyteArray state) { static jlong Init(JNIEnv* env, jobject obj) { scoped_ptr web_contents(content::WebContents::Create( content::WebContents::CreateParams( - XWalkRunner::GetInstance()->runtime_context()))); + XWalkRunner::GetInstance()->browser_context()))); return reinterpret_cast(new XWalkContent(web_contents.Pass())); } diff --git a/src/xwalk/runtime/browser/application_component.cc b/src/xwalk/runtime/browser/application_component.cc index fd4e839..140d9e8 100644 --- a/src/xwalk/runtime/browser/application_component.cc +++ b/src/xwalk/runtime/browser/application_component.cc @@ -9,8 +9,8 @@ namespace xwalk { ApplicationComponent::ApplicationComponent( - RuntimeContext* runtime_context) - : app_system_(application::ApplicationSystem::Create(runtime_context)), + XWalkBrowserContext* browser_context) + : app_system_(application::ApplicationSystem::Create(browser_context)), extensions_enabled_(true) {} ApplicationComponent::~ApplicationComponent() {} diff --git a/src/xwalk/runtime/browser/application_component.h b/src/xwalk/runtime/browser/application_component.h index 667bd5d..4d16780 100644 --- a/src/xwalk/runtime/browser/application_component.h +++ b/src/xwalk/runtime/browser/application_component.h @@ -10,7 +10,7 @@ namespace xwalk { -class RuntimeContext; +class XWalkBrowserContext; namespace application { class ApplicationSystem; @@ -21,7 +21,7 @@ class ApplicationSystem; // Applications being launched. class ApplicationComponent : public XWalkComponent { public: - explicit ApplicationComponent(RuntimeContext* runtime_context); + explicit ApplicationComponent(XWalkBrowserContext* browser_context); virtual ~ApplicationComponent(); // Used by Android since extensions for Application are not supported there. diff --git a/src/xwalk/runtime/browser/devtools/remote_debugging_server.cc b/src/xwalk/runtime/browser/devtools/remote_debugging_server.cc index b36285d..c5bc6e4 100644 --- a/src/xwalk/runtime/browser/devtools/remote_debugging_server.cc +++ b/src/xwalk/runtime/browser/devtools/remote_debugging_server.cc @@ -4,10 +4,10 @@ #include "xwalk/runtime/browser/devtools/remote_debugging_server.h" -#include "xwalk/runtime/browser/devtools/xwalk_devtools_delegate.h" -#include "xwalk/runtime/browser/runtime_context.h" #include "content/public/browser/devtools_http_handler.h" #include "net/socket/tcp_server_socket.h" +#include "xwalk/runtime/browser/devtools/xwalk_devtools_delegate.h" +#include "xwalk/runtime/browser/xwalk_browser_context.h" namespace xwalk { @@ -29,7 +29,7 @@ class TCPServerSocketFactory }; RemoteDebuggingServer::RemoteDebuggingServer( - RuntimeContext* runtime_context, + XWalkBrowserContext* browser_context, const std::string& ip, int port, const std::string& frontend_url) { diff --git a/src/xwalk/runtime/browser/devtools/remote_debugging_server.h b/src/xwalk/runtime/browser/devtools/remote_debugging_server.h index 27413a5..37328e5 100644 --- a/src/xwalk/runtime/browser/devtools/remote_debugging_server.h +++ b/src/xwalk/runtime/browser/devtools/remote_debugging_server.h @@ -15,11 +15,11 @@ class DevToolsHttpHandler; namespace xwalk { -class RuntimeContext; +class XWalkBrowserContext; class RemoteDebuggingServer { public: - RemoteDebuggingServer(RuntimeContext* runtime_context, + RemoteDebuggingServer(XWalkBrowserContext* browser_context, const std::string& ip, int port, const std::string& frontend_url); diff --git a/src/xwalk/runtime/browser/devtools/xwalk_devtools_browsertest.cc b/src/xwalk/runtime/browser/devtools/xwalk_devtools_browsertest.cc index c9a11e4..ba82550 100644 --- a/src/xwalk/runtime/browser/devtools/xwalk_devtools_browsertest.cc +++ b/src/xwalk/runtime/browser/devtools/xwalk_devtools_browsertest.cc @@ -16,20 +16,6 @@ #include "testing/gmock/include/gmock/gmock.h" using xwalk::Runtime; -namespace { -Runtime* CreateWithDefaultWindow( - xwalk::RuntimeContext* runtime_context, const GURL& url, - Runtime::Observer* observer = NULL) { - Runtime* runtime = Runtime::Create(runtime_context, observer); - runtime->LoadURL(url); -#if !defined(OS_ANDROID) - xwalk::RuntimeUIStrategy ui_strategy; - xwalk::NativeAppWindow::CreateParams params; - ui_strategy.Show(runtime, params); -#endif - return runtime; -} -} // namespace class XWalkDevToolsTest : public InProcessBrowserTest { public: @@ -44,8 +30,7 @@ class XWalkDevToolsTest : public InProcessBrowserTest { IN_PROC_BROWSER_TEST_F(XWalkDevToolsTest, RemoteDebugging) { GURL localhost_url("http://127.0.0.1:9222"); - Runtime* debugging_host = CreateWithDefaultWindow( - GetRuntimeContext(), localhost_url, runtime_registry()); + Runtime* debugging_host = CreateRuntime(localhost_url); content::WaitForLoadStop(debugging_host->web_contents()); base::string16 real_title = debugging_host->web_contents()->GetTitle(); base::string16 expected_title = base::ASCIIToUTF16("XWalk Remote Debugging"); diff --git a/src/xwalk/runtime/browser/devtools/xwalk_devtools_delegate.cc b/src/xwalk/runtime/browser/devtools/xwalk_devtools_delegate.cc index ca8c3f9..bdfec66 100644 --- a/src/xwalk/runtime/browser/devtools/xwalk_devtools_delegate.cc +++ b/src/xwalk/runtime/browser/devtools/xwalk_devtools_delegate.cc @@ -23,7 +23,6 @@ #include "net/socket/tcp_listen_socket.h" #include "ui/base/resource/resource_bundle.h" #include "ui/snapshot/snapshot.h" -#include "xwalk/runtime/browser/runtime.h" using content::DevToolsAgentHost; using content::RenderViewHost; @@ -124,14 +123,14 @@ namespace xwalk { namespace { Runtime* CreateWithDefaultWindow( - RuntimeContext* runtime_context, const GURL& url, - Runtime::Observer* observer = NULL) { - Runtime* runtime = Runtime::Create(runtime_context, observer); + XWalkBrowserContext* browser_context, const GURL& url, + Runtime::Observer* observer) { + Runtime* runtime = Runtime::Create(browser_context); + runtime->set_observer(observer); runtime->LoadURL(url); #if !defined(OS_ANDROID) - RuntimeUIStrategy ui_strategy; - NativeAppWindow::CreateParams params; - ui_strategy.Show(runtime, params); + runtime->set_ui_delegate(DefaultRuntimeUIDelegate::Create(runtime)); + runtime->Show(); #endif return runtime; } @@ -172,8 +171,8 @@ XWalkDevToolsHttpHandlerDelegate::CreateSocketForTethering( return scoped_ptr(); } -XWalkDevToolsDelegate::XWalkDevToolsDelegate(RuntimeContext* runtime_context) - : runtime_context_(runtime_context), +XWalkDevToolsDelegate::XWalkDevToolsDelegate(XWalkBrowserContext* context) + : browser_context_(context), weak_factory_(this) { } @@ -217,7 +216,7 @@ std::string XWalkDevToolsDelegate::GetPageThumbnailData(const GURL& url) { scoped_ptr XWalkDevToolsDelegate::CreateNewTarget(const GURL& url) { Runtime* runtime = CreateWithDefaultWindow( - runtime_context_, GURL(url::kAboutBlankURL)); + browser_context_, GURL(url::kAboutBlankURL), this); return scoped_ptr( new Target(DevToolsAgentHost::GetOrCreateFor(runtime->web_contents()))); } @@ -238,4 +237,14 @@ void XWalkDevToolsDelegate::EnumerateTargets(TargetCallback callback) { callback.Run(targets); } +void XWalkDevToolsDelegate::OnNewRuntimeAdded(Runtime* runtime) { + runtime->set_observer(this); + runtime->set_ui_delegate(DefaultRuntimeUIDelegate::Create(runtime)); + runtime->Show(); +} + +void XWalkDevToolsDelegate::OnRuntimeClosed(Runtime* runtime) { + delete runtime; +} + } // namespace xwalk diff --git a/src/xwalk/runtime/browser/devtools/xwalk_devtools_delegate.h b/src/xwalk/runtime/browser/devtools/xwalk_devtools_delegate.h index 2a35fd6..614348b 100644 --- a/src/xwalk/runtime/browser/devtools/xwalk_devtools_delegate.h +++ b/src/xwalk/runtime/browser/devtools/xwalk_devtools_delegate.h @@ -16,6 +16,7 @@ #include "content/public/browser/devtools_http_handler_delegate.h" #include "content/public/browser/devtools_manager_delegate.h" #include "url/gurl.h" +#include "xwalk/runtime/browser/runtime.h" namespace content { class DevToolsHttpHandler; @@ -23,7 +24,7 @@ class DevToolsHttpHandler; namespace xwalk { -class RuntimeContext; +class XWalkBrowserContext; class XWalkDevToolsHttpHandlerDelegate : public content::DevToolsHttpHandlerDelegate { @@ -43,9 +44,10 @@ class XWalkDevToolsHttpHandlerDelegate : DISALLOW_COPY_AND_ASSIGN(XWalkDevToolsHttpHandlerDelegate); }; -class XWalkDevToolsDelegate : public content::DevToolsManagerDelegate { +class XWalkDevToolsDelegate : public content::DevToolsManagerDelegate, + public Runtime::Observer { public: - explicit XWalkDevToolsDelegate(RuntimeContext* runtime_context); + explicit XWalkDevToolsDelegate(XWalkBrowserContext* browser_context); virtual ~XWalkDevToolsDelegate(); virtual void Inspect( @@ -65,9 +67,13 @@ class XWalkDevToolsDelegate : public content::DevToolsManagerDelegate { scoped_refptr png); private: + // Runtime::Observer + virtual void OnNewRuntimeAdded(Runtime* runtime) override; + virtual void OnRuntimeClosed(Runtime* runtime) override; + using ThumbnailMap = std::map; ThumbnailMap thumbnail_map_; - RuntimeContext* runtime_context_; + XWalkBrowserContext* browser_context_; base::WeakPtrFactory weak_factory_; DISALLOW_COPY_AND_ASSIGN(XWalkDevToolsDelegate); }; diff --git a/src/xwalk/runtime/browser/geolocation/tizen/location_provider_tizen.cc b/src/xwalk/runtime/browser/geolocation/tizen/location_provider_tizen.cc index 0ca65c4..41db2ab 100644 --- a/src/xwalk/runtime/browser/geolocation/tizen/location_provider_tizen.cc +++ b/src/xwalk/runtime/browser/geolocation/tizen/location_provider_tizen.cc @@ -131,11 +131,3 @@ void LocationProviderTizen::OnStateChanged(location_service_state_e state, } } // namespace xwalk - -namespace content { -__attribute__((visibility("default"))) content::LocationProvider* - NewSystemLocationProvider() { - return new xwalk::LocationProviderTizen; -} - -} // namespace content diff --git a/src/xwalk/runtime/browser/runtime.cc b/src/xwalk/runtime/browser/runtime.cc index 5f86702..7330c30 100644 --- a/src/xwalk/runtime/browser/runtime.cc +++ b/src/xwalk/runtime/browser/runtime.cc @@ -10,19 +10,9 @@ #include "base/command_line.h" #include "base/message_loop/message_loop.h" #include "base/strings/utf_string_conversions.h" -#include "xwalk/runtime/browser/image_util.h" -#include "xwalk/runtime/browser/media/media_capture_devices_dispatcher.h" -#include "xwalk/runtime/browser/runtime_context.h" -#include "xwalk/runtime/browser/runtime_file_select_helper.h" -#include "xwalk/runtime/browser/ui/color_chooser.h" -#include "xwalk/runtime/browser/xwalk_runner.h" -#include "xwalk/runtime/common/xwalk_notification_types.h" -#include "xwalk/runtime/common/xwalk_switches.h" #include "content/public/browser/navigation_entry.h" #include "content/public/browser/notification_details.h" #include "content/public/browser/notification_service.h" -#include "content/public/browser/notification_source.h" -#include "content/public/browser/notification_types.h" #include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_process_host.h" #include "content/public/browser/render_view_host.h" @@ -31,6 +21,14 @@ #include "ui/base/resource/resource_bundle.h" #include "ui/gfx/image/image_skia.h" #include "ui/gfx/native_widget_types.h" +#include "xwalk/runtime/browser/image_util.h" +#include "xwalk/runtime/browser/media/media_capture_devices_dispatcher.h" +#include "xwalk/runtime/browser/runtime_file_select_helper.h" +#include "xwalk/runtime/browser/ui/color_chooser.h" +#include "xwalk/runtime/browser/xwalk_browser_context.h" +#include "xwalk/runtime/browser/xwalk_runner.h" +#include "xwalk/runtime/common/xwalk_notification_types.h" +#include "xwalk/runtime/common/xwalk_switches.h" #if defined(OS_TIZEN) #include "content/public/browser/site_instance.h" @@ -40,7 +38,7 @@ #endif #if !defined(OS_ANDROID) -#include "xwalk/runtime/browser/runtime_ui_strategy.h" +#include "xwalk/runtime/browser/runtime_ui_delegate.h" #endif using content::FaviconURL; @@ -49,52 +47,32 @@ using content::WebContents; namespace xwalk { // static -Runtime* Runtime::Create(RuntimeContext* runtime_context, - Observer* observer, +Runtime* Runtime::Create(XWalkBrowserContext* browser_context, content::SiteInstance* site) { - WebContents::CreateParams params(runtime_context, site); + WebContents::CreateParams params(browser_context, site); params.routing_id = MSG_ROUTING_NONE; WebContents* web_contents = WebContents::Create(params); - return new Runtime(web_contents, observer); + return new Runtime(web_contents); } -Runtime::Runtime(content::WebContents* web_contents, Observer* observer) +Runtime::Runtime(content::WebContents* web_contents) : WebContentsObserver(web_contents), web_contents_(web_contents), - window_(NULL), - weak_ptr_factory_(this), fullscreen_options_(NO_FULLSCREEN), remote_debugging_enabled_(false), - observer_(observer) { + ui_delegate_(nullptr), + observer_(nullptr), + weak_ptr_factory_(this) { web_contents_->SetDelegate(this); - content::NotificationService::current()->Notify( - xwalk::NOTIFICATION_RUNTIME_OPENED, - content::Source(this), - content::NotificationService::NoDetails()); - if (observer_) - observer_->OnRuntimeAdded(this); -} - -Runtime::~Runtime() { - content::NotificationService::current()->Notify( - xwalk::NOTIFICATION_RUNTIME_CLOSED, - content::Source(this), - content::NotificationService::NoDetails()); - if (observer_) - observer_->OnRuntimeRemoved(this); -} - -void Runtime::EnableTitleUpdatedNotification() { registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, content::Source(web_contents_.get())); } -void Runtime::set_app_icon(const gfx::Image& app_icon) { - app_icon_ = app_icon; - if (window_ && !app_icon_.IsEmpty()) - window_->UpdateIcon(app_icon_); +Runtime::~Runtime() { + if (ui_delegate_) + ui_delegate_->DeleteDelegate(); } void Runtime::LoadURL(const GURL& url) { @@ -106,14 +84,19 @@ void Runtime::LoadURL(const GURL& url) { web_contents_->Focus(); } +void Runtime::Show() { + if (ui_delegate_) + ui_delegate_->Show(); +} + void Runtime::Close() { - if (window_) { - window_->Close(); - return; - } - // Runtime should not free itself on Close but be owned - // by Application. - delete this; + web_contents_->Close(); +} + +NativeAppWindow* Runtime::window() { + if (ui_delegate_) + return static_cast(ui_delegate_)->window(); + return nullptr; } content::RenderProcessHost* Runtime::GetRenderProcessHost() { @@ -156,12 +139,9 @@ void Runtime::ToggleFullscreenModeForTab(content::WebContents* web_contents, fullscreen_options_ |= FULLSCREEN_FOR_TAB; else fullscreen_options_ &= ~FULLSCREEN_FOR_TAB; - - if (enter_fullscreen) { - window_->SetFullscreen(true); - } else if (!fullscreen_options_ & FULLSCREEN_FOR_LAUNCH) { - window_->SetFullscreen(false); - } + if (ui_delegate_) + ui_delegate_->SetFullscreen( + enter_fullscreen || (fullscreen_options_ & FULLSCREEN_FOR_LAUNCH)); } bool Runtime::IsFullscreenForTabOrPending( @@ -176,7 +156,11 @@ void Runtime::RequestToLockMouse(content::WebContents* web_contents, } void Runtime::CloseContents(content::WebContents* source) { - window_->Close(); + if (ui_delegate_) + ui_delegate_->Close(); + + if (observer_) + observer_->OnRuntimeClosed(this); } bool Runtime::CanOverscrollContent() const { @@ -206,7 +190,10 @@ void Runtime::WebContentsCreated( const base::string16& frame_name, const GURL& target_url, content::WebContents* new_contents) { - new Runtime(new_contents, observer_); + if (observer_) + observer_->OnNewRuntimeAdded(new Runtime(new_contents)); + else + LOG(WARNING) << "New web contents is left unhandled."; } void Runtime::DidNavigateMainFramePostCommit( @@ -229,7 +216,13 @@ content::ColorChooser* Runtime::OpenColorChooser( content::WebContents* web_contents, SkColor initial_color, const std::vector& suggestions) { +#if defined(TOOLKIT_VIEWS) return xwalk::ShowColorChooser(web_contents, initial_color); +#else + return WebContentsDelegate::OpenColorChooser(web_contents, + initial_color, + suggestions); +#endif } void Runtime::RunFileChooser( @@ -283,7 +276,8 @@ void Runtime::DidDownloadFavicon(int id, if (bitmaps.empty()) return; app_icon_ = gfx::Image::CreateFrom1xBitmap(bitmaps[0]); - window_->UpdateIcon(app_icon_); + if (ui_delegate_) + ui_delegate_->UpdateIcon(app_icon_); } void Runtime::Observe(int type, @@ -294,19 +288,11 @@ void Runtime::Observe(int type, content::Details >( details).ptr(); - if (title->first) { - base::string16 text = title->first->GetTitle(); - window_->UpdateTitle(text); - } + if (title->first && ui_delegate_) + ui_delegate_->UpdateTitle(title->first->GetTitle()); } } -void Runtime::OnWindowDestroyed() { - // Runtime should not free itself on Close but be owned - // by Application. - delete this; -} - void Runtime::RequestMediaAccessPermission( content::WebContents* web_contents, const content::MediaStreamRequest& request, @@ -314,4 +300,5 @@ void Runtime::RequestMediaAccessPermission( XWalkMediaCaptureDevicesDispatcher::RunRequestMediaAccessPermission( web_contents, request, callback); } + } // namespace xwalk diff --git a/src/xwalk/runtime/browser/runtime.h b/src/xwalk/runtime/browser/runtime.h index f12dfdb..994c5ff 100644 --- a/src/xwalk/runtime/browser/runtime.h +++ b/src/xwalk/runtime/browser/runtime.h @@ -10,8 +10,7 @@ #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.h" -#include "xwalk/runtime/browser/runtime_ui_strategy.h" -#include "xwalk/runtime/browser/ui/native_app_window.h" +#include "xwalk/runtime/browser/runtime_ui_delegate.h" #include "content/public/browser/notification_observer.h" #include "content/public/browser/notification_registrar.h" #include "content/public/browser/web_contents_delegate.h" @@ -30,16 +29,14 @@ class WebContents; namespace xwalk { -class NativeAppWindow; -class RuntimeContext; +class XWalkBrowserContext; +class RuntimeUIDelegate; // Runtime represents the running environment for a web page. It is responsible -// for maintaning its owned WebContents and handling any communication between -// WebContents and native app window. +// for maintaning its owned WebContents. class Runtime : public content::WebContentsDelegate, public content::WebContentsObserver, - public content::NotificationObserver, - public NativeAppWindowDelegate { + public content::NotificationObserver { public: // New "Runtimes" are also created from Runtime::WebContentsCreated which // is overridden WebContentsDelegate method. The "observer" is needed to @@ -47,10 +44,10 @@ class Runtime : public content::WebContentsDelegate, class Observer { public: // Called when a new Runtime instance is added. - virtual void OnRuntimeAdded(Runtime* runtime) = 0; + virtual void OnNewRuntimeAdded(Runtime* new_runtime) = 0; // Called when a Runtime instance is removed. - virtual void OnRuntimeRemoved(Runtime* runtime) = 0; + virtual void OnRuntimeClosed(Runtime* runtime) = 0; protected: virtual ~Observer() {} @@ -64,22 +61,25 @@ class Runtime : public content::WebContentsDelegate, // Fullscreen entered by HTML requestFullscreen. FULLSCREEN_FOR_TAB = 1 << 1, }; + virtual ~Runtime(); - void SetObserver(Observer* observer) { observer_ = observer; } + void set_ui_delegate(RuntimeUIDelegate* ui_delegate) { + ui_delegate_ = ui_delegate; + } + void set_observer(Observer* observer) { observer_ = observer; } // Create a new Runtime instance with the given browsing context. - static Runtime* Create(RuntimeContext*, - Observer* = NULL, content::SiteInstance* = NULL); + static Runtime* Create(XWalkBrowserContext* context, + content::SiteInstance* site = nullptr); void LoadURL(const GURL& url); + void Show(); void Close(); content::WebContents* web_contents() const { return web_contents_.get(); } - NativeAppWindow* window() const { return window_; } - void set_window(NativeAppWindow* window) { window_ = window; } + // FIXME : This method should be removed. + NativeAppWindow* window(); gfx::Image app_icon() const { return app_icon_; } - void set_app_icon(const gfx::Image& app_icon); - void EnableTitleUpdatedNotification(); unsigned int fullscreen_options() { return fullscreen_options_; } void set_fullscreen_options(unsigned int options) { fullscreen_options_ = options; @@ -93,8 +93,7 @@ class Runtime : public content::WebContentsDelegate, bool remote_debugging_enabled() const { return remote_debugging_enabled_; } protected: - Runtime(content::WebContents* web_contents, Observer* observer); - virtual ~Runtime(); + explicit Runtime(content::WebContents* web_contents); // Overridden from content::WebContentsDelegate: virtual content::WebContents* OpenURLFromTab( @@ -160,25 +159,19 @@ class Runtime : public content::WebContentsDelegate, const content::NotificationSource& source, const content::NotificationDetails& details) OVERRIDE; - // NativeAppWindowDelegate implementation. - virtual void OnWindowDestroyed() OVERRIDE; - // Notification manager. content::NotificationRegistrar registrar_; // The WebContents owned by this runtime. scoped_ptr web_contents_; - NativeAppWindow* window_; - gfx::Image app_icon_; - base::WeakPtrFactory weak_ptr_factory_; - unsigned int fullscreen_options_; bool remote_debugging_enabled_; - + RuntimeUIDelegate* ui_delegate_; Observer* observer_; + base::WeakPtrFactory weak_ptr_factory_; }; } // namespace xwalk diff --git a/src/xwalk/runtime/browser/runtime_defered_ui_strategy.cc b/src/xwalk/runtime/browser/runtime_defered_ui_strategy.cc deleted file mode 100644 index 2cad3be..0000000 --- a/src/xwalk/runtime/browser/runtime_defered_ui_strategy.cc +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2014 Intel Corporation. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "xwalk/runtime/browser/runtime_defered_ui_strategy.h" - -#include "xwalk/runtime/browser/runtime.h" - -namespace xwalk { -RuntimeDeferedUIStrategy::RuntimeDeferedUIStrategy() - : defered_show_(true) {} - -RuntimeDeferedUIStrategy::~RuntimeDeferedUIStrategy() {} - -void RuntimeDeferedUIStrategy::Show( - Runtime* runtime, const NativeAppWindow::CreateParams& params) { - if (!defered_show_) { - RuntimeUIStrategy::Show(runtime, params); - return; - } - - runtime_map_[runtime] = params; -} - -void RuntimeDeferedUIStrategy::ShowStoredRuntimes() { - for (const auto& item : runtime_map_) { - RuntimeUIStrategy::Show(item.first, item.second); - } - defered_show_ = false; -} -} // namespace xwalk diff --git a/src/xwalk/runtime/browser/runtime_defered_ui_strategy.h b/src/xwalk/runtime/browser/runtime_defered_ui_strategy.h deleted file mode 100644 index 4ccd189..0000000 --- a/src/xwalk/runtime/browser/runtime_defered_ui_strategy.h +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2014 Intel Corporation. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef XWALK_RUNTIME_BROWSER_RUNTIME_DEFERED_UI_STRATEGY_H_ -#define XWALK_RUNTIME_BROWSER_RUNTIME_DEFERED_UI_STRATEGY_H_ - -#include - -#include "xwalk/runtime/browser/runtime_ui_strategy.h" -#include "xwalk/runtime/browser/ui/native_app_window.h" - -namespace xwalk { -class Runtime; - -class RuntimeDeferedUIStrategy : public RuntimeUIStrategy { - public: - RuntimeDeferedUIStrategy(); - virtual ~RuntimeDeferedUIStrategy(); - - // Override from RuntimeUIStrategy. - virtual void Show(Runtime* runtime, - const NativeAppWindow::CreateParams& params) OVERRIDE; - - void ShowStoredRuntimes(); - - private: - std::map runtime_map_; - bool defered_show_; -}; - -inline RuntimeDeferedUIStrategy* -ToRuntimeDeferedUIStrategy(RuntimeUIStrategy* ui_strategy) { - return static_cast(ui_strategy); -} -} // namespace xwalk -#endif // XWALK_RUNTIME_BROWSER_RUNTIME_DEFERED_UI_STRATEGY_H_ diff --git a/src/xwalk/runtime/browser/runtime_geolocation_permission_context.h b/src/xwalk/runtime/browser/runtime_geolocation_permission_context.h index 8f99d59..eea0376 100644 --- a/src/xwalk/runtime/browser/runtime_geolocation_permission_context.h +++ b/src/xwalk/runtime/browser/runtime_geolocation_permission_context.h @@ -11,12 +11,12 @@ class GURL; namespace content { - class WebContents; +class WebContents; } namespace xwalk { -class RuntimeContext; +class XWalkBrowserContext; class RuntimeGeolocationPermissionContext : public base::RefCountedThreadSafe { diff --git a/src/xwalk/runtime/browser/runtime_ui_delegate.cc b/src/xwalk/runtime/browser/runtime_ui_delegate.cc new file mode 100644 index 0000000..4c996be --- /dev/null +++ b/src/xwalk/runtime/browser/runtime_ui_delegate.cc @@ -0,0 +1,125 @@ +// Copyright (c) 2014 Intel Corporation. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "xwalk/runtime/browser/runtime_ui_delegate.h" + +#include "base/command_line.h" +#include "grit/xwalk_resources.h" +#include "ui/base/resource/resource_bundle.h" +#include "ui/gfx/image/image.h" +#include "xwalk/runtime/browser/image_util.h" +#include "xwalk/runtime/browser/runtime.h" +#include "xwalk/runtime/common/xwalk_switches.h" + +namespace xwalk { +// FIXME : Need to figure out what code paths are used by Android and not +// compile the unneeded files. +#if !defined(OS_ANDROID) +namespace { +// The default size for web content area size. +const int kDefaultWidth = 840; +const int kDefaultHeight = 600; + +NativeAppWindow* CreateWindow( + Runtime* runtime, const NativeAppWindow::CreateParams& params) { + NativeAppWindow* window = NativeAppWindow::Create(params); + // FIXME : Pass an App icon in params. + // Set the app icon if it is passed from command line. + CommandLine* command_line = CommandLine::ForCurrentProcess(); + gfx::Image app_icon; + if (command_line->HasSwitch(switches::kAppIcon)) { + base::FilePath icon_file = + command_line->GetSwitchValuePath(switches::kAppIcon); + app_icon = xwalk_utils::LoadImageFromFilePath(icon_file); + } else { + // Otherwise, use the default icon for Crosswalk app. + ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); + app_icon = rb.GetNativeImageNamed(IDR_XWALK_ICON_48); + } + + window->UpdateIcon(app_icon); + + 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); + + return window; +} + +} // namespace +#endif + +RuntimeUIDelegate* DefaultRuntimeUIDelegate::Create( + Runtime* runtime, const NativeAppWindow::CreateParams& params) { + return new DefaultRuntimeUIDelegate(runtime, params); +} + +DefaultRuntimeUIDelegate::DefaultRuntimeUIDelegate( + Runtime* runtime, const NativeAppWindow::CreateParams& params) + : runtime_(runtime), + window_params_(params), + window_(nullptr) { + DCHECK(runtime_); +} + +DefaultRuntimeUIDelegate::~DefaultRuntimeUIDelegate() { +} + +void DefaultRuntimeUIDelegate::Show() { +#if !defined(OS_ANDROID) + if (!window_) { + if (window_params_.bounds.IsEmpty()) + window_params_.bounds = gfx::Rect(0, 0, kDefaultWidth, kDefaultHeight); + window_params_.delegate = this; + window_params_.web_contents = runtime_->web_contents(); + window_ = CreateWindow(runtime_, window_params_); + } + window_->Show(); +#else + NOTIMPLEMENTED(); +#endif +} + +void DefaultRuntimeUIDelegate::UpdateTitle(const base::string16& text) { + if (window_) + window_->UpdateTitle(text); +} + +void DefaultRuntimeUIDelegate::UpdateIcon(const gfx::Image& image) { + if (window_) + window_->UpdateIcon(image); +} + +void DefaultRuntimeUIDelegate::SetFullscreen(bool enter_fullscreen) { + if (window_) + window_->SetFullscreen(enter_fullscreen); +} + +void DefaultRuntimeUIDelegate::Close() { + if (window_) + window_->Close(); +} + +void DefaultRuntimeUIDelegate::DeleteDelegate() { + runtime_ = nullptr; + if (window_) { + window_->Close(); + return; + } + delete this; +} + +void DefaultRuntimeUIDelegate::OnWindowDestroyed() { + window_ = nullptr; + if (runtime_) { + runtime_->Close(); + return; + } + delete this; +} + +} // namespace xwalk diff --git a/src/xwalk/runtime/browser/runtime_ui_delegate.h b/src/xwalk/runtime/browser/runtime_ui_delegate.h new file mode 100644 index 0000000..a65b769 --- /dev/null +++ b/src/xwalk/runtime/browser/runtime_ui_delegate.h @@ -0,0 +1,59 @@ +// Copyright (c) 2014 Intel Corporation. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef XWALK_RUNTIME_BROWSER_RUNTIME_UI_DELEGATE_H_ +#define XWALK_RUNTIME_BROWSER_RUNTIME_UI_DELEGATE_H_ + +#include "base/memory/scoped_ptr.h" +#include "xwalk/runtime/browser/ui/native_app_window.h" + +namespace xwalk { +class Runtime; + +class RuntimeUIDelegate { + public: + virtual ~RuntimeUIDelegate() {} + virtual void Show() = 0; + virtual void UpdateTitle(const base::string16& text) = 0; + virtual void UpdateIcon(const gfx::Image& image) = 0; + virtual void SetFullscreen(bool enter_fullscreen) = 0; + virtual void Close() = 0; + virtual void DeleteDelegate() = 0; +}; + +// The default implementation displays WebContents in a separate window. +class DefaultRuntimeUIDelegate : public RuntimeUIDelegate, + public NativeAppWindowDelegate { + public: + static RuntimeUIDelegate* Create( + Runtime* runtime, + const NativeAppWindow::CreateParams& params = + NativeAppWindow::CreateParams()); + virtual ~DefaultRuntimeUIDelegate(); + + NativeAppWindow* window() { return window_; } + + private: + DefaultRuntimeUIDelegate(Runtime* runtime, + const NativeAppWindow::CreateParams& params); + // RuntimeUIDelegate + virtual void Show() override; + virtual void UpdateTitle(const base::string16& text) override; + virtual void UpdateIcon(const gfx::Image& image) override; + virtual void SetFullscreen(bool enter_fullscreen) override; + virtual void Close() override; + virtual void DeleteDelegate() override; + // NativeAppWindowDelegate + virtual void OnWindowDestroyed() override; + + private: + Runtime* runtime_; + NativeAppWindow::CreateParams window_params_; + NativeAppWindow* window_; +}; + + +} // namespace xwalk + +#endif // XWALK_RUNTIME_BROWSER_RUNTIME_UI_DELEGATE_H_ diff --git a/src/xwalk/runtime/browser/runtime_ui_strategy.cc b/src/xwalk/runtime/browser/runtime_ui_strategy.cc deleted file mode 100644 index a2de96c..0000000 --- a/src/xwalk/runtime/browser/runtime_ui_strategy.cc +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) 2014 Intel Corporation. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "xwalk/runtime/browser/runtime_ui_strategy.h" - -#include "base/command_line.h" -#include "grit/xwalk_resources.h" -#include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/image/image.h" -#include "xwalk/runtime/browser/image_util.h" -#include "xwalk/runtime/browser/runtime.h" -#include "xwalk/runtime/common/xwalk_switches.h" - -namespace xwalk { -namespace { -#if !defined(OS_ANDROID) -// The default size for web content area size. -const int kDefaultWidth = 840; -const int kDefaultHeight = 600; - -void ApplyWindowDefaultParams(Runtime* runtime, - NativeAppWindow::CreateParams* params) { - if (!params->delegate) - params->delegate = runtime; - if (!params->web_contents) - params->web_contents = runtime->web_contents(); - if (params->bounds.IsEmpty()) - params->bounds = gfx::Rect(0, 0, kDefaultWidth, kDefaultHeight); - - 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); -} -#endif -} // namespace - -RuntimeUIStrategy::RuntimeUIStrategy() {} - -RuntimeUIStrategy::~RuntimeUIStrategy() {} - -void RuntimeUIStrategy::Show( - Runtime* runtime, const NativeAppWindow::CreateParams& params) { -#if defined(OS_ANDROID) - NOTIMPLEMENTED(); -#else - NativeAppWindow::CreateParams effective_params(params); - ApplyWindowDefaultParams(runtime, &effective_params); - - // Set the app icon if it is passed from command line. - CommandLine* command_line = CommandLine::ForCurrentProcess(); - gfx::Image app_icon; - if (command_line->HasSwitch(switches::kAppIcon)) { - base::FilePath icon_file = - command_line->GetSwitchValuePath(switches::kAppIcon); - app_icon = xwalk_utils::LoadImageFromFilePath(icon_file); - } else { - // Otherwise, use the default icon for Crosswalk app. - ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); - app_icon = rb.GetNativeImageNamed(IDR_XWALK_ICON_48); - } - - runtime->EnableTitleUpdatedNotification(); - - NativeAppWindow* window = NativeAppWindow::Create(effective_params); - runtime->set_window(window); - - runtime->set_app_icon(app_icon); - window->Show(); -#endif -} -} // namespace xwalk diff --git a/src/xwalk/runtime/browser/runtime_ui_strategy.h b/src/xwalk/runtime/browser/runtime_ui_strategy.h deleted file mode 100644 index e01705c..0000000 --- a/src/xwalk/runtime/browser/runtime_ui_strategy.h +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) 2014 Intel Corporation. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef XWALK_RUNTIME_BROWSER_RUNTIME_UI_STRATEGY_H_ -#define XWALK_RUNTIME_BROWSER_RUNTIME_UI_STRATEGY_H_ - -#include "xwalk/runtime/browser/ui/native_app_window.h" - -namespace xwalk { -class Runtime; - -class RuntimeUIStrategy { - public: - RuntimeUIStrategy(); - virtual ~RuntimeUIStrategy(); - virtual void Show(Runtime* runtime, - const NativeAppWindow::CreateParams& params); -}; - -} // namespace xwalk - -#endif // XWALK_RUNTIME_BROWSER_RUNTIME_UI_STRATEGY_H_ diff --git a/src/xwalk/runtime/browser/ui/native_app_window_aura.cc b/src/xwalk/runtime/browser/ui/native_app_window_aura.cc new file mode 100644 index 0000000..3b9ebf3 --- /dev/null +++ b/src/xwalk/runtime/browser/ui/native_app_window_aura.cc @@ -0,0 +1,336 @@ +// Copyright (c) 2014 Intel Corporation. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "xwalk/runtime/browser/ui/native_app_window_aura.h" + +#include "base/command_line.h" +#include "content/public/browser/web_contents.h" +#include "content/browser/web_contents/web_contents_view.h" +#include "ui/aura/client/aura_constants.h" +#include "ui/wm/core/default_activation_client.h" +#include "ui/aura/client/default_capture_client.h" +#include "ui/aura/env.h" +#include "ui/aura/layout_manager.h" +#include "ui/aura/test/test_focus_client.h" +#include "ui/aura/test/test_screen.h" +#include "ui/aura/test/test_window_tree_client.h" +#include "ui/aura/window.h" +#include "ui/aura/window_event_dispatcher.h" +#include "ui/base/cursor/cursor.h" +#include "ui/base/cursor/image_cursors.h" +#include "ui/base/ime/input_method.h" +#include "ui/base/ime/input_method_delegate.h" +#include "ui/base/ime/input_method_factory.h" +#include "ui/gfx/screen.h" +#include "ui/wm/core/cursor_manager.h" +#include "ui/wm/core/native_cursor_manager.h" +#include "ui/wm/core/native_cursor_manager_delegate.h" + +namespace xwalk { + +const int kDefaultTestWindowWidthDip = 800; +const int kDefaultTestWindowHeightDip = 600; + +const char kXwalkHostWindowBounds[] = "xwalk-host-window-bounds"; + +namespace { + +class FillLayout : public aura::LayoutManager { + public: + explicit FillLayout(aura::Window* root) + : root_(root) { + } + + virtual ~FillLayout() {} + + private: + // aura::LayoutManager: + virtual void OnWindowResized() override { + } + + virtual void OnWindowAddedToLayout(aura::Window* child) override { + child->SetBounds(root_->bounds()); + } + + virtual void OnWillRemoveWindowFromLayout(aura::Window* child) override { + } + + virtual void OnWindowRemovedFromLayout(aura::Window* child) override { + } + + virtual void OnChildWindowVisibilityChanged(aura::Window* child, + bool visible) override { + } + + virtual void SetChildBounds(aura::Window* child, + const gfx::Rect& requested_bounds) override { + SetChildBoundsDirect(child, requested_bounds); + } + + aura::Window* root_; + + DISALLOW_COPY_AND_ASSIGN(FillLayout); +}; + +// Taken from app_shell. +// A class that bridges the gap between CursorManager and Aura. It borrows +// heavily from AshNativeCursorManager. +class ShellNativeCursorManager : public wm::NativeCursorManager { + public: + explicit ShellNativeCursorManager(aura::WindowTreeHost* host) + : host_(host), + image_cursors_(new ui::ImageCursors) {} + virtual ~ShellNativeCursorManager() {} + + // wm::NativeCursorManager overrides. + virtual void SetDisplay( + const gfx::Display& display, + wm::NativeCursorManagerDelegate* delegate) override { + if (image_cursors_->SetDisplay(display, display.device_scale_factor())) + SetCursor(delegate->GetCursor(), delegate); + } + + virtual void SetCursor( + gfx::NativeCursor cursor, + wm::NativeCursorManagerDelegate* delegate) override { + image_cursors_->SetPlatformCursor(&cursor); + cursor.set_device_scale_factor(image_cursors_->GetScale()); + delegate->CommitCursor(cursor); + + if (delegate->IsCursorVisible()) + ApplyCursor(cursor); + } + + virtual void SetVisibility( + bool visible, + wm::NativeCursorManagerDelegate* delegate) override { + delegate->CommitVisibility(visible); + + if (visible) { + SetCursor(delegate->GetCursor(), delegate); + } else { + gfx::NativeCursor invisible_cursor(ui::kCursorNone); + image_cursors_->SetPlatformCursor(&invisible_cursor); + ApplyCursor(invisible_cursor); + } + } + + virtual void SetCursorSet( + ui::CursorSetType cursor_set, + wm::NativeCursorManagerDelegate* delegate) override { + image_cursors_->SetCursorSet(cursor_set); + delegate->CommitCursorSet(cursor_set); + if (delegate->IsCursorVisible()) + SetCursor(delegate->GetCursor(), delegate); + } + + virtual void SetMouseEventsEnabled( + bool enabled, + wm::NativeCursorManagerDelegate* delegate) override { + delegate->CommitMouseEventsEnabled(enabled); + SetVisibility(delegate->IsCursorVisible(), delegate); + } + + private: + // Sets |cursor| as the active cursor within Aura. + void ApplyCursor(gfx::NativeCursor cursor) { + host_->SetCursor(cursor); + } + + aura::WindowTreeHost* host_; // Not owned. + + scoped_ptr image_cursors_; + + DISALLOW_COPY_AND_ASSIGN(ShellNativeCursorManager); +}; + +class MinimalInputEventFilter : public ui::internal::InputMethodDelegate, + public ui::EventHandler { + public: + explicit MinimalInputEventFilter(aura::WindowTreeHost* host) + : host_(host), + input_method_(ui::CreateInputMethod(this, + gfx::kNullAcceleratedWidget)) { + input_method_->Init(true); + host_->window()->AddPreTargetHandler(this); + host_->window()->SetProperty(aura::client::kRootWindowInputMethodKey, + input_method_.get()); + } + + virtual ~MinimalInputEventFilter() { + host_->window()->RemovePreTargetHandler(this); + host_->window()->SetProperty(aura::client::kRootWindowInputMethodKey, + static_cast(NULL)); + } + + private: + // ui::EventHandler: + virtual void OnKeyEvent(ui::KeyEvent* event) override { + // See the comment in InputMethodEventFilter::OnKeyEvent() for details. + if (event->IsTranslated()) { + event->SetTranslated(false); + } else if (input_method_->DispatchKeyEvent(*event)) { + event->StopPropagation(); + } + } + + // ui::internal::InputMethodDelegate: + virtual bool DispatchKeyEventPostIME(const ui::KeyEvent& event) override { + // See the comment in InputMethodEventFilter::DispatchKeyEventPostIME() for + // details. + ui::KeyEvent aura_event(event); + aura_event.SetTranslated(true); + ui::EventDispatchDetails details = + host_->dispatcher()->OnEventFromSource(&aura_event); + return aura_event.handled() || details.dispatcher_destroyed; + } + + aura::WindowTreeHost* host_; + scoped_ptr input_method_; + + DISALLOW_COPY_AND_ASSIGN(MinimalInputEventFilter); +}; + +} // namespace + +// mimicking Shell::ShellPlatformDataAura +NativeAppWindowAura::NativeAppWindowAura( + const NativeAppWindow::CreateParams& create_params) + : web_contents_(create_params.web_contents) { + aura::Env::CreateInstance(true); + gfx::Size size; + + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); + if (command_line->HasSwitch(kXwalkHostWindowBounds)) { + const std::string size_str = + command_line->GetSwitchValueASCII(kXwalkHostWindowBounds); + int width, height; + if (sscanf(size_str.c_str(), "%d,%d", &width, &height) == 2) + size = gfx::Size(width, height); + } + + if (size.IsEmpty()) + size = gfx::Size(kDefaultTestWindowWidthDip, kDefaultTestWindowHeightDip); + + host_.reset(aura::WindowTreeHost::Create(gfx::Rect(size))); + host_->InitHost(); + host_->window()->SetLayoutManager(new FillLayout(host_->window())); + + focus_client_.reset(new aura::test::TestFocusClient()); + aura::client::SetFocusClient(host_->window(), focus_client_.get()); + + new wm::DefaultActivationClient(host_->window()); + capture_client_.reset( + new aura::client::DefaultCaptureClient(host_->window())); + window_tree_client_.reset( + new aura::test::TestWindowTreeClient(host_->window())); + ime_filter_.reset(new MinimalInputEventFilter(host_.get())); + + cursor_manager_.reset( + new wm::CursorManager(scoped_ptr( + new ShellNativeCursorManager(host_.get())))); + cursor_manager_->SetDisplay( + gfx::Screen::GetNativeScreen()->GetPrimaryDisplay()); + cursor_manager_->SetCursor(ui::kCursorPointer); + aura::client::SetCursorClient(host_->window(), cursor_manager_.get()); + + // mimicking Shell::PlatformSetContents + aura::Window* content = web_contents_->GetNativeView(); + aura::Window* parent = host_->window(); + if (!parent->Contains(content)) + parent->AddChild(content); + + content->Show(); + parent->Show(); + + web_contents_->Focus(); +} + +NativeAppWindowAura::~NativeAppWindowAura() { + aura::Env::DeleteInstance(); +} + +gfx::NativeWindow NativeAppWindowAura::GetNativeWindow() const { + return NULL; +} + +void NativeAppWindowAura::UpdateIcon(const gfx::Image& icon) { +} + +void NativeAppWindowAura::UpdateTitle(const base::string16& title) { +} + +gfx::Rect NativeAppWindowAura::GetRestoredBounds() const { + return gfx::Rect(); +} + +gfx::Rect NativeAppWindowAura::GetBounds() const { + return host_->GetBounds(); +} + +void NativeAppWindowAura::SetBounds(const gfx::Rect& bounds) { + host_->SetBounds(bounds); +} + +void NativeAppWindowAura::Focus() { +} + +void NativeAppWindowAura::Show() { + host_->Show(); +} + +void NativeAppWindowAura::Hide() { + host_->Hide(); +} + +void NativeAppWindowAura::Maximize() { +} + +void NativeAppWindowAura::Minimize() { +} + +void NativeAppWindowAura::SetFullscreen(bool fullscreen) { +} + +void NativeAppWindowAura::Restore() { +} + +void NativeAppWindowAura::FlashFrame(bool flash) { +} + +void NativeAppWindowAura::Close() { +} + +bool NativeAppWindowAura::IsActive() const { + return true; +} + +bool NativeAppWindowAura::IsMaximized() const { + return true; +} + +bool NativeAppWindowAura::IsMinimized() const { + return false; +} + +bool NativeAppWindowAura::IsFullscreen() const { + return true; +} + +// static +NativeAppWindow* NativeAppWindow::Create( + const NativeAppWindow::CreateParams& create_params) { + return new NativeAppWindowAura(create_params); +} + +// static +void NativeAppWindow::Initialize() { + // At least Athena, Content Shell and Chromecast use the "TestScreen" class + // not exactly for testing but production instead. So I think we are fine on + // using it as long they are using it as well. + aura::TestScreen* screen = aura::TestScreen::Create(gfx::Size()); + gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen); +} + +} // namespace xwalk diff --git a/src/xwalk/runtime/browser/ui/native_app_window_aura.h b/src/xwalk/runtime/browser/ui/native_app_window_aura.h new file mode 100644 index 0000000..5192c8d --- /dev/null +++ b/src/xwalk/runtime/browser/ui/native_app_window_aura.h @@ -0,0 +1,79 @@ +// Copyright (c) 2014 Intel Corporation. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef XWALK_RUNTIME_BROWSER_UI_NATIVE_APP_WINDOW_AURA_H_ +#define XWALK_RUNTIME_BROWSER_UI_NATIVE_APP_WINDOW_AURA_H_ + +#include + +#include "base/memory/scoped_ptr.h" +#include "ui/aura/window_tree_host.h" +#include "xwalk/runtime/browser/ui/native_app_window.h" + +namespace aura { +namespace client { +class DefaultCaptureClient; +class FocusClient; +class WindowTreeClient; +} +} + +namespace gfx { +class Size; +} + +namespace ui { +class EventHandler; +} + +namespace wm { +class CursorManager; +} + +namespace xwalk { + +class TopViewLayout; + +class NativeAppWindowAura : public NativeAppWindow { + public: + explicit NativeAppWindowAura(const NativeAppWindow::CreateParams& params); + virtual ~NativeAppWindowAura(); + + // NativeAppWindow implementation. + virtual gfx::NativeWindow GetNativeWindow() const override; + virtual void UpdateIcon(const gfx::Image& icon) override; + virtual void UpdateTitle(const base::string16& title) override; + virtual gfx::Rect GetRestoredBounds() const override; + virtual gfx::Rect GetBounds() const override; + virtual void SetBounds(const gfx::Rect& bounds) override; + virtual void Focus() override; + virtual void Show() override; + virtual void Hide() override; + virtual void Maximize() override; + virtual void Minimize() override; + virtual void SetFullscreen(bool fullscreen) override; + virtual void Restore() override; + virtual void FlashFrame(bool flash) override; + virtual void Close() override; + virtual bool IsActive() const override; + virtual bool IsMaximized() const override; + virtual bool IsMinimized() const override; + virtual bool IsFullscreen() const override; + + private: + scoped_ptr host_; + scoped_ptr focus_client_; + scoped_ptr cursor_manager_; + scoped_ptr capture_client_; + scoped_ptr window_tree_client_; + scoped_ptr ime_filter_; + + content::WebContents* web_contents_; + + DISALLOW_COPY_AND_ASSIGN(NativeAppWindowAura); +}; + +} // namespace xwalk + +#endif // XWALK_RUNTIME_BROWSER_UI_NATIVE_APP_WINDOW_AURA_H_ diff --git a/src/xwalk/runtime/browser/ui/native_app_window_tizen.cc b/src/xwalk/runtime/browser/ui/native_app_window_tizen.cc index 50ff11f..3dfbb44 100644 --- a/src/xwalk/runtime/browser/ui/native_app_window_tizen.cc +++ b/src/xwalk/runtime/browser/ui/native_app_window_tizen.cc @@ -41,7 +41,7 @@ static gfx::Display::Rotation ToDisplayRotation(gfx::Display display, if (display.bounds().width() > display.bounds().height()) { // Landscape devices have landscape-primary as default. - rot = static_cast((rot - 1) % 4); + rot = static_cast((rot + 3) % 4); } return rot; diff --git a/src/xwalk/runtime/browser/xwalk_app_extension_bridge.cc b/src/xwalk/runtime/browser/xwalk_app_extension_bridge.cc index 7b10e55..49dd0a3 100644 --- a/src/xwalk/runtime/browser/xwalk_app_extension_bridge.cc +++ b/src/xwalk/runtime/browser/xwalk_app_extension_bridge.cc @@ -7,6 +7,7 @@ #include #include "content/public/browser/browser_thread.h" +#include "content/public/browser/notification_service.h" #include "xwalk/application/browser/application.h" #include "xwalk/application/browser/application_service.h" #include "xwalk/application/browser/application_system.h" @@ -16,12 +17,15 @@ #include "xwalk/application/browser/application_service_provider_linux.h" #include "xwalk/application/browser/linux/running_application_object.h" #endif -#include "xwalk/runtime/browser/runtime_defered_ui_strategy.h" namespace xwalk { +using application::Application; +using application::ApplicationService; +using application::ApplicationSystem; + XWalkAppExtensionBridge::XWalkAppExtensionBridge() - : app_system_(NULL) { + : app_system_(nullptr) { } XWalkAppExtensionBridge::~XWalkAppExtensionBridge() {} @@ -66,10 +70,7 @@ void XWalkAppExtensionBridge::ExtensionProcessCreated( int render_process_id, const IPC::ChannelHandle& channel_handle) { #if defined(OS_LINUX) - CHECK(app_system_); - application::ApplicationService* service = app_system_->application_service(); - application::Application* app = - service->GetApplicationByRenderHostID(render_process_id); + Application* app = GetApplication(render_process_id); CHECK(app); application::ApplicationSystemLinux* app_system = @@ -83,19 +84,18 @@ void XWalkAppExtensionBridge::ExtensionProcessCreated( void XWalkAppExtensionBridge::RenderChannelCreated( int render_process_id) { - CHECK(app_system_); - application::ApplicationService *service = - app_system_->application_service(); - application::Application *app = - service->GetApplicationByRenderHostID(render_process_id); + Application* app = GetApplication(render_process_id); if (!app) return; + content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE, + base::Bind(&Application::RenderChannelCreated, app->GetWeakPtr())); +} - content::BrowserThread::PostTask( - content::BrowserThread::UI, - FROM_HERE, - base::Bind( - &RuntimeDeferedUIStrategy::ShowStoredRuntimes, - base::Unretained(ToRuntimeDeferedUIStrategy(app->ui_strategy())))); +Application* XWalkAppExtensionBridge::GetApplication(int render_process_id) { + CHECK(app_system_); + ApplicationService* service = + app_system_->application_service(); + return service->GetApplicationByRenderHostID(render_process_id); } + } // namespace xwalk diff --git a/src/xwalk/runtime/browser/xwalk_app_extension_bridge.h b/src/xwalk/runtime/browser/xwalk_app_extension_bridge.h index 73c019c..ec058c4 100644 --- a/src/xwalk/runtime/browser/xwalk_app_extension_bridge.h +++ b/src/xwalk/runtime/browser/xwalk_app_extension_bridge.h @@ -13,6 +13,10 @@ namespace xwalk { +namespace application { +class Application; +} + // The class is the main interface for co-operations between the two major // xwalk components -- the application subsystem and the extension subsystem. // Because of the dependency requirements two components cound not include @@ -45,6 +49,7 @@ class XWalkAppExtensionBridge virtual void RenderChannelCreated(int render_process_id) OVERRIDE; private: + application::Application* GetApplication(int render_process_id); application::ApplicationSystem* app_system_; DISALLOW_COPY_AND_ASSIGN(XWalkAppExtensionBridge); diff --git a/src/xwalk/runtime/browser/runtime_context.cc b/src/xwalk/runtime/browser/xwalk_browser_context.cc similarity index 81% rename from src/xwalk/runtime/browser/runtime_context.cc rename to src/xwalk/runtime/browser/xwalk_browser_context.cc index b422a13..892b11b 100644 --- a/src/xwalk/runtime/browser/runtime_context.cc +++ b/src/xwalk/runtime/browser/xwalk_browser_context.cc @@ -3,7 +3,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "xwalk/runtime/browser/runtime_context.h" +#include "xwalk/runtime/browser/xwalk_browser_context.h" #include #include @@ -41,7 +41,8 @@ using content::DownloadManager; namespace xwalk { -class RuntimeContext::RuntimeResourceContext : public content::ResourceContext { +class XWalkBrowserContext::RuntimeResourceContext : + public content::ResourceContext { public: RuntimeResourceContext() : getter_(NULL) {} virtual ~RuntimeResourceContext() {} @@ -66,7 +67,7 @@ class RuntimeContext::RuntimeResourceContext : public content::ResourceContext { DISALLOW_COPY_AND_ASSIGN(RuntimeResourceContext); }; -RuntimeContext::RuntimeContext() +XWalkBrowserContext::XWalkBrowserContext() : resource_context_(new RuntimeResourceContext) { InitWhileIOAllowed(); #if defined(OS_ANDROID) @@ -74,7 +75,7 @@ RuntimeContext::RuntimeContext() #endif } -RuntimeContext::~RuntimeContext() { +XWalkBrowserContext::~XWalkBrowserContext() { if (resource_context_.get()) { BrowserThread::DeleteSoon( BrowserThread::IO, FROM_HERE, resource_context_.release()); @@ -82,23 +83,24 @@ RuntimeContext::~RuntimeContext() { } // static -RuntimeContext* RuntimeContext::FromWebContents( +XWalkBrowserContext* XWalkBrowserContext::FromWebContents( content::WebContents* web_contents) { // This is safe; this is the only implementation of the browser context. - return static_cast(web_contents->GetBrowserContext()); + return static_cast( + web_contents->GetBrowserContext()); } -void RuntimeContext::InitWhileIOAllowed() { +void XWalkBrowserContext::InitWhileIOAllowed() { CommandLine* cmd_line = CommandLine::ForCurrentProcess(); if (cmd_line->HasSwitch(switches::kXWalkDataPath)) { base::FilePath path = cmd_line->GetSwitchValuePath(switches::kXWalkDataPath); PathService::OverrideAndCreateIfNeeded( - xwalk::DIR_DATA_PATH, path, false, true); + DIR_DATA_PATH, path, false, true); } } -base::FilePath RuntimeContext::GetPath() const { +base::FilePath XWalkBrowserContext::GetPath() const { base::FilePath result; #if defined(OS_ANDROID) CHECK(PathService::Get(base::DIR_ANDROID_APP_DATA, &result)); @@ -107,17 +109,18 @@ base::FilePath RuntimeContext::GetPath() const { result = result.Append( cmd_line->GetSwitchValuePath(switches::kXWalkProfileName)); #else - CHECK(PathService::Get(xwalk::DIR_DATA_PATH, &result)); + CHECK(PathService::Get(DIR_DATA_PATH, &result)); #endif return result; } -bool RuntimeContext::IsOffTheRecord() const { +bool XWalkBrowserContext::IsOffTheRecord() const { // We don't consider off the record scenario. return false; } -content::DownloadManagerDelegate* RuntimeContext::GetDownloadManagerDelegate() { +content::DownloadManagerDelegate* +XWalkBrowserContext::GetDownloadManagerDelegate() { content::DownloadManager* manager = BrowserContext::GetDownloadManager(this); if (!download_manager_delegate_.get()) { @@ -128,12 +131,12 @@ content::DownloadManagerDelegate* RuntimeContext::GetDownloadManagerDelegate() { return download_manager_delegate_.get(); } -net::URLRequestContextGetter* RuntimeContext::GetRequestContext() { +net::URLRequestContextGetter* XWalkBrowserContext::GetRequestContext() { return GetDefaultStoragePartition(this)->GetURLRequestContext(); } net::URLRequestContextGetter* - RuntimeContext::GetRequestContextForRenderProcess( + XWalkBrowserContext::GetRequestContextForRenderProcess( int renderer_child_id) { #if defined(OS_ANDROID) return GetRequestContext(); @@ -144,12 +147,12 @@ net::URLRequestContextGetter* #endif } -net::URLRequestContextGetter* RuntimeContext::GetMediaRequestContext() { +net::URLRequestContextGetter* XWalkBrowserContext::GetMediaRequestContext() { return GetRequestContext(); } net::URLRequestContextGetter* - RuntimeContext::GetMediaRequestContextForRenderProcess( + XWalkBrowserContext::GetMediaRequestContextForRenderProcess( int renderer_child_id) { #if defined(OS_ANDROID) return GetRequestContext(); @@ -161,7 +164,7 @@ net::URLRequestContextGetter* } net::URLRequestContextGetter* - RuntimeContext::GetMediaRequestContextForStoragePartition( + XWalkBrowserContext::GetMediaRequestContextForStoragePartition( const base::FilePath& partition_path, bool in_memory) { #if defined(OS_ANDROID) @@ -174,28 +177,29 @@ net::URLRequestContextGetter* #endif } -content::ResourceContext* RuntimeContext::GetResourceContext() { +content::ResourceContext* XWalkBrowserContext::GetResourceContext() { return resource_context_.get(); } content::BrowserPluginGuestManager* -RuntimeContext::GetGuestManager() { +XWalkBrowserContext::GetGuestManager() { return NULL; } -storage::SpecialStoragePolicy* RuntimeContext::GetSpecialStoragePolicy() { +storage::SpecialStoragePolicy* XWalkBrowserContext::GetSpecialStoragePolicy() { return NULL; } -content::PushMessagingService* RuntimeContext::GetPushMessagingService() { +content::PushMessagingService* XWalkBrowserContext::GetPushMessagingService() { return NULL; } -content::SSLHostStateDelegate* RuntimeContext::GetSSLHostStateDelegate() { +content::SSLHostStateDelegate* XWalkBrowserContext::GetSSLHostStateDelegate() { return NULL; } -RuntimeURLRequestContextGetter* RuntimeContext::GetURLRequestContextGetterById( +RuntimeURLRequestContextGetter* +XWalkBrowserContext::GetURLRequestContextGetterById( const std::string& pkg_id) { for (PartitionPathContextGetterMap::iterator it = context_getters_.begin(); it != context_getters_.end(); ++it) { @@ -205,7 +209,7 @@ RuntimeURLRequestContextGetter* RuntimeContext::GetURLRequestContextGetterById( return 0; } -net::URLRequestContextGetter* RuntimeContext::CreateRequestContext( +net::URLRequestContextGetter* XWalkBrowserContext::CreateRequestContext( content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector request_interceptors) { DCHECK(!url_request_getter_.get()); @@ -228,7 +232,7 @@ net::URLRequestContextGetter* RuntimeContext::CreateRequestContext( } net::URLRequestContextGetter* - RuntimeContext::CreateRequestContextForStoragePartition( + XWalkBrowserContext::CreateRequestContextForStoragePartition( const base::FilePath& partition_path, bool in_memory, content::ProtocolHandlerMap* protocol_handlers, @@ -269,7 +273,7 @@ net::URLRequestContextGetter* } #if defined(OS_ANDROID) -void RuntimeContext::SetCSPString(const std::string& csp) { +void XWalkBrowserContext::SetCSPString(const std::string& csp) { // Check format of csp string. std::vector policies; base::SplitString(csp, ';', &policies); @@ -283,22 +287,22 @@ void RuntimeContext::SetCSPString(const std::string& csp) { csp_ = csp; } -std::string RuntimeContext::GetCSPString() const { +std::string XWalkBrowserContext::GetCSPString() const { return csp_; } -void RuntimeContext::InitVisitedLinkMaster() { +void XWalkBrowserContext::InitVisitedLinkMaster() { visitedlink_master_.reset( new visitedlink::VisitedLinkMaster(this, this, false)); visitedlink_master_->Init(); } -void RuntimeContext::AddVisitedURLs(const std::vector& urls) { +void XWalkBrowserContext::AddVisitedURLs(const std::vector& urls) { DCHECK(visitedlink_master_.get()); visitedlink_master_->AddURLs(urls); } -void RuntimeContext::RebuildTable( +void XWalkBrowserContext::RebuildTable( const scoped_refptr& enumerator) { // XWalkView rebuilds from XWalkWebChromeClient.getVisitedHistory. The client // can change in the lifetime of this XWalkView and may not yet be set here. diff --git a/src/xwalk/runtime/browser/runtime_context.h b/src/xwalk/runtime/browser/xwalk_browser_context.h similarity index 87% rename from src/xwalk/runtime/browser/runtime_context.h rename to src/xwalk/runtime/browser/xwalk_browser_context.h index 84ea626..6bf775b 100644 --- a/src/xwalk/runtime/browser/runtime_context.h +++ b/src/xwalk/runtime/browser/xwalk_browser_context.h @@ -3,8 +3,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef XWALK_RUNTIME_BROWSER_RUNTIME_CONTEXT_H_ -#define XWALK_RUNTIME_BROWSER_RUNTIME_CONTEXT_H_ +#ifndef XWALK_RUNTIME_BROWSER_XWALK_BROWSER_CONTEXT_H_ +#define XWALK_RUNTIME_BROWSER_XWALK_BROWSER_CONTEXT_H_ #if defined(OS_ANDROID) #include @@ -38,19 +38,20 @@ namespace xwalk { class RuntimeDownloadManagerDelegate; class RuntimeURLRequestContextGetter; -class RuntimeContext +class XWalkBrowserContext : public content::BrowserContext #if defined(OS_ANDROID) , public visitedlink::VisitedLinkDelegate #endif { public: - RuntimeContext(); - virtual ~RuntimeContext(); + XWalkBrowserContext(); + virtual ~XWalkBrowserContext(); - // Convenience method to returns the RuntimeContext corresponding to the + // Convenience method to returns the XWalkBrowserContext corresponding to the // given WebContents. - static RuntimeContext* FromWebContents(content::WebContents* web_contents); + static XWalkBrowserContext* FromWebContents( + content::WebContents* web_contents); // BrowserContext implementation. virtual base::FilePath GetPath() const OVERRIDE; @@ -97,7 +98,7 @@ class RuntimeContext private: class RuntimeResourceContext; - // Performs initialization of the RuntimeContext while IO is still + // Performs initialization of the XWalkBrowserContext while IO is still // allowed on the current thread. void InitWhileIOAllowed(); @@ -119,9 +120,9 @@ class RuntimeContext PartitionPathContextGetterMap; PartitionPathContextGetterMap context_getters_; - DISALLOW_COPY_AND_ASSIGN(RuntimeContext); + DISALLOW_COPY_AND_ASSIGN(XWalkBrowserContext); }; } // namespace xwalk -#endif // XWALK_RUNTIME_BROWSER_RUNTIME_CONTEXT_H_ +#endif // XWALK_RUNTIME_BROWSER_XWALK_BROWSER_CONTEXT_H_ diff --git a/src/xwalk/runtime/browser/xwalk_browser_main_parts.cc b/src/xwalk/runtime/browser/xwalk_browser_main_parts.cc index 74f72b3..7f95b55 100644 --- a/src/xwalk/runtime/browser/xwalk_browser_main_parts.cc +++ b/src/xwalk/runtime/browser/xwalk_browser_main_parts.cc @@ -27,8 +27,6 @@ #include "xwalk/application/browser/application_system.h" #include "xwalk/extensions/browser/xwalk_extension_service.h" #include "xwalk/extensions/common/xwalk_extension_switches.h" -#include "xwalk/runtime/browser/runtime.h" -#include "xwalk/runtime/browser/runtime_context.h" #include "xwalk/runtime/browser/xwalk_runner.h" #include "xwalk/runtime/common/xwalk_runtime_features.h" #include "xwalk/runtime/common/xwalk_switches.h" @@ -40,10 +38,13 @@ #endif #if defined(USE_AURA) && defined(USE_X11) -#include "ui/base/ime/input_method_initializer.h" #include "ui/events/x/touch_factory_x11.h" #endif +#if !defined(OS_CHROMEOS) && defined(USE_AURA) && defined(OS_LINUX) +#include "ui/base/ime/input_method_initializer.h" +#endif + namespace { // FIXME: Compare with method in startup_browser_creator.cc. @@ -125,8 +126,8 @@ void XWalkBrowserMainParts::PostMainMessageLoopStart() { } void XWalkBrowserMainParts::PreEarlyInitialization() { -#if defined(USE_AURA) && defined(USE_X11) - ui::InitializeInputMethodForTesting(); +#if !defined(OS_CHROMEOS) && defined(USE_AURA) && defined(OS_LINUX) + ui::InitializeInputMethodForTesting(); #endif } diff --git a/src/xwalk/runtime/browser/xwalk_browser_main_parts_android.cc b/src/xwalk/runtime/browser/xwalk_browser_main_parts_android.cc index 24d5f6f..1010efd 100644 --- a/src/xwalk/runtime/browser/xwalk_browser_main_parts_android.cc +++ b/src/xwalk/runtime/browser/xwalk_browser_main_parts_android.cc @@ -33,7 +33,6 @@ #include "xwalk/extensions/common/xwalk_extension.h" #include "xwalk/extensions/common/xwalk_extension_switches.h" #include "xwalk/runtime/browser/android/cookie_manager.h" -#include "xwalk/runtime/browser/runtime_context.h" #include "xwalk/runtime/browser/xwalk_runner.h" #include "xwalk/runtime/common/xwalk_runtime_features.h" #include "xwalk/runtime/common/xwalk_switches.h" diff --git a/src/xwalk/runtime/browser/xwalk_content_browser_client.cc b/src/xwalk/runtime/browser/xwalk_content_browser_client.cc index f47ba1e..1288b51 100644 --- a/src/xwalk/runtime/browser/xwalk_content_browser_client.cc +++ b/src/xwalk/runtime/browser/xwalk_content_browser_client.cc @@ -31,9 +31,9 @@ #include "xwalk/runtime/browser/geolocation/xwalk_access_token_store.h" #include "xwalk/runtime/browser/media/media_capture_devices_dispatcher.h" #include "xwalk/runtime/browser/renderer_host/pepper/xwalk_browser_pepper_host_factory.h" -#include "xwalk/runtime/browser/runtime_context.h" #include "xwalk/runtime/browser/runtime_quota_permission_context.h" #include "xwalk/runtime/browser/speech/speech_recognition_manager_delegate.h" +#include "xwalk/runtime/browser/xwalk_browser_context.h" #include "xwalk/runtime/browser/xwalk_browser_main_parts.h" #include "xwalk/runtime/browser/xwalk_render_message_filter.h" #include "xwalk/runtime/browser/xwalk_runner.h" @@ -66,6 +66,7 @@ #if defined(OS_TIZEN) #include "xwalk/application/common/application_manifest_constants.h" +#include "xwalk/runtime/browser/geolocation/tizen/location_provider_tizen.h" #include "xwalk/runtime/browser/runtime_platform_util.h" #include "xwalk/runtime/browser/tizen/xwalk_web_contents_view_delegate.h" #include "xwalk/runtime/browser/xwalk_browser_main_parts_tizen.h" @@ -90,7 +91,7 @@ XWalkContentBrowserClient::XWalkContentBrowserClient(XWalkRunner* xwalk_runner) : xwalk_runner_(xwalk_runner), url_request_context_getter_(NULL), main_parts_(NULL), - runtime_context_(NULL) { + browser_context_(NULL) { DCHECK(!g_browser_client); g_browser_client = this; } @@ -119,8 +120,8 @@ net::URLRequestContextGetter* XWalkContentBrowserClient::CreateRequestContext( content::BrowserContext* browser_context, content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector request_interceptors) { - runtime_context_ = static_cast(browser_context); - url_request_context_getter_ = runtime_context_-> + browser_context_ = static_cast(browser_context); + url_request_context_getter_ = browser_context_-> CreateRequestContext(protocol_handlers, request_interceptors.Pass()); return url_request_context_getter_; } @@ -132,7 +133,7 @@ XWalkContentBrowserClient::CreateRequestContextForStoragePartition( bool in_memory, content::ProtocolHandlerMap* protocol_handlers, content::URLRequestInterceptorScopedVector request_interceptors) { - return static_cast(browser_context)-> + return static_cast(browser_context)-> CreateRequestContextForStoragePartition( partition_path, in_memory, protocol_handlers, request_interceptors.Pass()); @@ -400,6 +401,14 @@ bool XWalkContentBrowserClient::CanCreateWindow(const GURL& opener_url, } #endif +content::LocationProvider* +XWalkContentBrowserClient::OverrideSystemLocationProvider() { +#if defined(OS_TIZEN) + return new LocationProviderTizen(); +#else + return nullptr; +#endif +} void XWalkContentBrowserClient::GetStoragePartitionConfigForSite( content::BrowserContext* browser_context, @@ -420,7 +429,7 @@ void XWalkContentBrowserClient::GetStoragePartitionConfigForSite( content::DevToolsManagerDelegate* XWalkContentBrowserClient::GetDevToolsManagerDelegate() { - return new XWalkDevToolsDelegate(runtime_context_); + return new XWalkDevToolsDelegate(browser_context_); } } // namespace xwalk diff --git a/src/xwalk/runtime/browser/xwalk_content_browser_client.h b/src/xwalk/runtime/browser/xwalk_content_browser_client.h index 6018266..5f98c3b 100644 --- a/src/xwalk/runtime/browser/xwalk_content_browser_client.h +++ b/src/xwalk/runtime/browser/xwalk_content_browser_client.h @@ -29,7 +29,7 @@ class URLRequestContextGetter; namespace xwalk { -class RuntimeContext; +class XWalkBrowserContext; class XWalkBrowserMainParts; class XWalkRunner; @@ -141,6 +141,8 @@ class XWalkContentBrowserClient : public content::ContentBrowserClient { virtual void ResourceDispatcherHostCreated() OVERRIDE; #endif + virtual content::LocationProvider* OverrideSystemLocationProvider() override; + virtual void GetStoragePartitionConfigForSite( content::BrowserContext* browser_context, const GURL& site, @@ -166,7 +168,7 @@ class XWalkContentBrowserClient : public content::ContentBrowserClient { scoped_refptr geolocation_permission_context_; XWalkBrowserMainParts* main_parts_; - RuntimeContext* runtime_context_; + XWalkBrowserContext* browser_context_; scoped_ptr resource_dispatcher_host_delegate_; diff --git a/src/xwalk/runtime/browser/xwalk_download_browsertest.cc b/src/xwalk/runtime/browser/xwalk_download_browsertest.cc index dd97f9c..8d0b591 100644 --- a/src/xwalk/runtime/browser/xwalk_download_browsertest.cc +++ b/src/xwalk/runtime/browser/xwalk_download_browsertest.cc @@ -39,10 +39,15 @@ static DownloadManagerImpl* DownloadManagerForXWalk(Runtime* runtime) { class XWalkDownloadBrowserTest : public InProcessBrowserTest { public: + XWalkDownloadBrowserTest() + : InProcessBrowserTest(), + runtime_(nullptr) {} + virtual void SetUpOnMainThread() OVERRIDE { ASSERT_TRUE(downloads_directory_.CreateUniqueTempDir()); + runtime_ = CreateRuntime(GURL()); - DownloadManagerImpl* manager = DownloadManagerForXWalk(runtime()); + DownloadManagerImpl* manager = DownloadManagerForXWalk(runtime_); RuntimeDownloadManagerDelegate* delegate = static_cast(manager->GetDelegate()); delegate->SetDownloadBehaviorForTesting(downloads_directory_.path()); @@ -56,6 +61,9 @@ class XWalkDownloadBrowserTest : public InProcessBrowserTest { DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); } + protected: + Runtime* runtime_; + private: // Location of the downloads directory for these tests base::ScopedTempDir downloads_directory_; @@ -65,12 +73,12 @@ IN_PROC_BROWSER_TEST_F(XWalkDownloadBrowserTest, FileDownload) { GURL url = xwalk_test_utils::GetTestURL( base::FilePath().AppendASCII("download"), base::FilePath().AppendASCII("test.lib")); - scoped_ptr observer(CreateWaiter(runtime(), 1)); - xwalk_test_utils::NavigateToURL(runtime(), url); + scoped_ptr observer(CreateWaiter(runtime_, 1)); + xwalk_test_utils::NavigateToURL(runtime_, url); observer->WaitForFinished(); EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); std::vector downloads; - DownloadManagerForXWalk(runtime())->GetAllDownloads(&downloads); + DownloadManagerForXWalk(runtime_)->GetAllDownloads(&downloads); ASSERT_EQ(1u, downloads.size()); ASSERT_EQ(DownloadItem::COMPLETE, downloads[0]->GetState()); base::FilePath file(downloads[0]->GetFullPath()); diff --git a/src/xwalk/runtime/browser/xwalk_form_input_browsertest.cc b/src/xwalk/runtime/browser/xwalk_form_input_browsertest.cc index 11e9784..51c5517 100644 --- a/src/xwalk/runtime/browser/xwalk_form_input_browsertest.cc +++ b/src/xwalk/runtime/browser/xwalk_form_input_browsertest.cc @@ -100,16 +100,16 @@ IN_PROC_BROWSER_TEST_F(XWalkFormInputTest, DISABLED_FileSelector) { base::FilePath(), base::FilePath().AppendASCII("file_to_select"))); GURL url = xwalk_test_utils::GetTestURL( base::FilePath(), base::FilePath().AppendASCII("form_input.html")); - xwalk_test_utils::NavigateToURL(runtime(), url); - content::WaitForLoadStop(runtime()->web_contents()); + Runtime* runtime = CreateRuntime(url); + content::WaitForLoadStop(runtime->web_contents()); bool ret = content::ExecuteScript( - runtime()->web_contents(), "doSelectFile();"); + runtime->web_contents(), "doSelectFile();"); EXPECT_TRUE(ret); content::RunAllPendingInMessageLoop(); base::string16 expected_title = base::ASCIIToUTF16("file selected: "); expected_title.append( base::ASCIIToUTF16(g_file_selected_path.BaseName().MaybeAsASCII())); - content::TitleWatcher title_watcher(runtime()->web_contents(), + content::TitleWatcher title_watcher(runtime->web_contents(), expected_title); EXPECT_EQ(title_watcher.WaitAndGetTitle(), expected_title); } @@ -119,17 +119,17 @@ IN_PROC_BROWSER_TEST_F(XWalkFormInputTest, ColorChooser) { SetBrowserTestColor(r, g, b); GURL url = xwalk_test_utils::GetTestURL( base::FilePath(), base::FilePath().AppendASCII("form_input.html")); - xwalk_test_utils::NavigateToURL(runtime(), url); - content::WaitForLoadStop(runtime()->web_contents()); + Runtime* runtime = CreateRuntime(url); + content::WaitForLoadStop(runtime->web_contents()); bool ret = content::ExecuteScript( - runtime()->web_contents(), "doChooseColor();"); + runtime->web_contents(), "doChooseColor();"); EXPECT_TRUE(ret); content::RunAllPendingInMessageLoop(); base::string16 expected_title = base::ASCIIToUTF16("color chosen: "); char rgb[8]; base::snprintf(rgb, sizeof(rgb), "#%02x%02x%02x", r, g, b); expected_title.append(base::ASCIIToUTF16(rgb)); - content::TitleWatcher title_watcher(runtime()->web_contents(), + content::TitleWatcher title_watcher(runtime->web_contents(), expected_title); EXPECT_EQ(title_watcher.WaitAndGetTitle(), expected_title); } diff --git a/src/xwalk/runtime/browser/xwalk_runner.cc b/src/xwalk/runtime/browser/xwalk_runner.cc index ff13e26..423a64e 100644 --- a/src/xwalk/runtime/browser/xwalk_runner.cc +++ b/src/xwalk/runtime/browser/xwalk_runner.cc @@ -16,10 +16,10 @@ #include "xwalk/extensions/common/xwalk_extension_switches.h" #include "xwalk/runtime/browser/application_component.h" #include "xwalk/runtime/browser/devtools/remote_debugging_server.h" -#include "xwalk/runtime/browser/runtime_context.h" #include "xwalk/runtime/browser/storage_component.h" #include "xwalk/runtime/browser/sysapps_component.h" #include "xwalk/runtime/browser/xwalk_app_extension_bridge.h" +#include "xwalk/runtime/browser/xwalk_browser_context.h" #include "xwalk/runtime/browser/xwalk_browser_main_parts.h" #include "xwalk/runtime/browser/xwalk_component.h" #include "xwalk/runtime/browser/xwalk_content_browser_client.h" @@ -69,7 +69,7 @@ application::ApplicationSystem* XWalkRunner::app_system() { } void XWalkRunner::PreMainMessageLoopRun() { - runtime_context_.reset(new RuntimeContext); + browser_context_.reset(new XWalkBrowserContext); app_extension_bridge_.reset(new XWalkAppExtensionBridge()); CommandLine* cmd_line = CommandLine::ForCurrentProcess(); @@ -84,7 +84,7 @@ void XWalkRunner::PreMainMessageLoopRun() { void XWalkRunner::PostMainMessageLoopRun() { DestroyComponents(); extension_service_.reset(); - runtime_context_.reset(); + browser_context_.reset(); DisableRemoteDebugging(); } @@ -115,7 +115,7 @@ void XWalkRunner::AddComponent(scoped_ptr component) { } scoped_ptr XWalkRunner::CreateAppComponent() { - return make_scoped_ptr(new ApplicationComponent(runtime_context_.get())); + return make_scoped_ptr(new ApplicationComponent(browser_context_.get())); } scoped_ptr XWalkRunner::CreateSysAppsComponent() { @@ -176,7 +176,7 @@ void XWalkRunner::EnableRemoteDebugging(int port) { const char* local_ip = "0.0.0.0"; if (port > 0 && port < 65535) { remote_debugging_server_.reset( - new RemoteDebuggingServer(runtime_context(), + new RemoteDebuggingServer(browser_context(), local_ip, port, std::string())); } } diff --git a/src/xwalk/runtime/browser/xwalk_runner.h b/src/xwalk/runtime/browser/xwalk_runner.h index 5ff56c5..fe46163 100644 --- a/src/xwalk/runtime/browser/xwalk_runner.h +++ b/src/xwalk/runtime/browser/xwalk_runner.h @@ -22,10 +22,10 @@ class XWalkTestSuiteInitializer; namespace xwalk { -class RuntimeContext; class ApplicationComponent; class RemoteDebuggingServer; class SysAppsComponent; +class XWalkBrowserContext; class XWalkComponent; class XWalkContentBrowserClient; class XWalkAppExtensionBridge; @@ -68,7 +68,7 @@ class XWalkRunner { // - In situations where you don't control the creation of a certain // object. Certain APIs doesn't allow us to pass the dependencies, so we // need to reach them some way. - RuntimeContext* runtime_context() { return runtime_context_.get(); } + XWalkBrowserContext* browser_context() { return browser_context_.get(); } application::ApplicationSystem* app_system(); extensions::XWalkExtensionService* extension_service() { return extension_service_.get(); @@ -125,7 +125,7 @@ class XWalkRunner { content::ContentBrowserClient* GetContentBrowserClient(); scoped_ptr content_browser_client_; - scoped_ptr runtime_context_; + scoped_ptr browser_context_; scoped_ptr extension_service_; scoped_ptr app_extension_bridge_; diff --git a/src/xwalk/runtime/browser/xwalk_runtime_browsertest.cc b/src/xwalk/runtime/browser/xwalk_runtime_browsertest.cc index cd5186c..035f2e6 100644 --- a/src/xwalk/runtime/browser/xwalk_runtime_browsertest.cc +++ b/src/xwalk/runtime/browser/xwalk_runtime_browsertest.cc @@ -12,7 +12,7 @@ #include "base/strings/utf_string_conversions.h" #include "xwalk/runtime/browser/image_util.h" #include "xwalk/runtime/browser/runtime.h" -#include "xwalk/runtime/browser/runtime_ui_strategy.h" +#include "xwalk/runtime/browser/runtime_ui_delegate.h" #include "xwalk/runtime/common/xwalk_notification_types.h" #include "xwalk/test/base/in_process_browser_test.h" #include "xwalk/test/base/xwalk_test_utils.h" @@ -36,123 +36,40 @@ using xwalk::NativeAppWindow; using xwalk::Runtime; +using content::NotificationService; using content::WebContents; +using content::WindowedNotificationObserver; using testing::_; -namespace { -Runtime* CreateWithDefaultWindow( - xwalk::RuntimeContext* runtime_context, const GURL& url, - Runtime::Observer* observer = NULL) { - Runtime* runtime = Runtime::Create(runtime_context, observer); - runtime->LoadURL(url); -#if !defined(OS_ANDROID) - xwalk::RuntimeUIStrategy ui_strategy; - xwalk::NativeAppWindow::CreateParams params; - ui_strategy.Show(runtime, params); -#endif - return runtime; -} -} // namespace - -// Observer for NOTIFICATION_FULLSCREEN_CHANGED notifications. -class FullscreenNotificationObserver - : public content::WindowedNotificationObserver { - public: - FullscreenNotificationObserver() : WindowedNotificationObserver( - xwalk::NOTIFICATION_FULLSCREEN_CHANGED, - content::NotificationService::AllSources()) {} - private: - DISALLOW_COPY_AND_ASSIGN(FullscreenNotificationObserver); -}; - class XWalkRuntimeTest : public InProcessBrowserTest { - public: - XWalkRuntimeTest() {} - virtual ~XWalkRuntimeTest() { - original_runtimes_.clear(); - notification_observer_.reset(); - } - - void Relaunch(const CommandLine& new_command_line) { - base::LaunchProcess(new_command_line, base::LaunchOptions(), NULL); - } - - // SetUpOnMainThread is called after BrowserMainRunner was initialized and - // just before RunTestOnMainThread (aka. TestBody). - virtual void SetUpOnMainThread() OVERRIDE { - notification_observer_.reset( - new content::WindowedNotificationObserver( - xwalk::NOTIFICATION_RUNTIME_OPENED, - content::NotificationService::AllSources())); - original_runtimes_.assign(runtimes().begin(), runtimes().end()); - } - - // Block UI thread until a new Runtime instance is created. - Runtime* WaitForSingleNewRuntime() { - notification_observer_->Wait(); - const RuntimeList& runtime_list = runtimes(); - for (RuntimeList::const_iterator it = runtime_list.begin(); - it != runtime_list.end(); ++it) { - RuntimeList::iterator target = - std::find(original_runtimes_.begin(), original_runtimes_.end(), *it); - // Not found means a new one. - if (target == original_runtimes_.end()) { - original_runtimes_.push_back(*it); - return *it; - } - } - return NULL; - } - - private: - RuntimeList original_runtimes_; - scoped_ptr notification_observer_; }; -// FIXME(hmin): Since currently the browser process is not shared by multiple -// app launch, this test is disabled to avoid floody launches. -IN_PROC_BROWSER_TEST_F(XWalkRuntimeTest, DISABLED_SecondLaunch) { - Relaunch(GetCommandLineForRelaunch()); - - Runtime* second_runtime = NULL; - EXPECT_TRUE(second_runtime == WaitForSingleNewRuntime()); - ASSERT_EQ(2u, runtimes().size()); -} - IN_PROC_BROWSER_TEST_F(XWalkRuntimeTest, CreateAndCloseRuntime) { size_t len = runtimes().size(); - ASSERT_EQ(1, len); - // Create a new Runtime instance. GURL url(test_server()->GetURL("test.html")); - Runtime* new_runtime = CreateWithDefaultWindow( - GetRuntimeContext(), url, runtime_registry()); - EXPECT_TRUE(url == new_runtime->web_contents()->GetURL()); - EXPECT_EQ(new_runtime, WaitForSingleNewRuntime()); - content::RunAllPendingInMessageLoop(); + Runtime* runtime = CreateRuntime(url); + EXPECT_TRUE(url == runtime->web_contents()->GetURL()); EXPECT_EQ(len + 1, runtimes().size()); // Close the newly created Runtime instance. - new_runtime->Close(); + runtime->Close(); content::RunAllPendingInMessageLoop(); EXPECT_EQ(len, runtimes().size()); } IN_PROC_BROWSER_TEST_F(XWalkRuntimeTest, LoadURLAndClose) { GURL url(test_server()->GetURL("test.html")); + Runtime* runtime = CreateRuntime(url); size_t len = runtimes().size(); - runtime()->LoadURL(url); - content::RunAllPendingInMessageLoop(); - EXPECT_EQ(len, runtimes().size()); - runtime()->Close(); + runtime->Close(); content::RunAllPendingInMessageLoop(); EXPECT_EQ(len - 1, runtimes().size()); } IN_PROC_BROWSER_TEST_F(XWalkRuntimeTest, CloseNativeWindow) { GURL url(test_server()->GetURL("test.html")); - Runtime* new_runtime = CreateWithDefaultWindow( - GetRuntimeContext(), url, runtime_registry()); + Runtime* new_runtime = CreateRuntime(url); size_t len = runtimes().size(); new_runtime->window()->Close(); content::RunAllPendingInMessageLoop(); @@ -162,45 +79,44 @@ IN_PROC_BROWSER_TEST_F(XWalkRuntimeTest, CloseNativeWindow) { IN_PROC_BROWSER_TEST_F(XWalkRuntimeTest, LaunchWithFullscreenWindow) { GURL url(test_server()->GetURL("test.html")); - Runtime* new_runtime = Runtime::Create( - GetRuntimeContext(), runtime_registry()); - NativeAppWindow::CreateParams params; params.state = ui::SHOW_STATE_FULLSCREEN; - scoped_ptr ui_strategy( - new xwalk::RuntimeUIStrategy); - ui_strategy->Show(new_runtime, params); - xwalk_test_utils::NavigateToURL(new_runtime, url); + Runtime* new_runtime = CreateRuntime(url, params); EXPECT_TRUE(new_runtime->window()->IsFullscreen()); } IN_PROC_BROWSER_TEST_F(XWalkRuntimeTest, HTML5FullscreenAPI) { - size_t len = runtimes().size(); GURL url = xwalk_test_utils::GetTestURL( base::FilePath(), base::FilePath().AppendASCII("fullscreen.html")); - xwalk_test_utils::NavigateToURL(runtime(), url); - EXPECT_TRUE(false == runtime()->window()->IsFullscreen()); + Runtime* runtime = CreateRuntime(url); + EXPECT_TRUE(false == runtime->window()->IsFullscreen()); + + WindowedNotificationObserver enter_observer( + xwalk::NOTIFICATION_FULLSCREEN_CHANGED, + NotificationService::AllSources()); - FullscreenNotificationObserver enter_observer; bool ret = content::ExecuteScript( - runtime()->web_contents(), "doFullscreenClick();"); + runtime->web_contents(), "doFullscreenClick();"); EXPECT_TRUE(ret); content::RunAllPendingInMessageLoop(); enter_observer.Wait(); // Calling doFullscreenClick defined in fullscreen.html leads to enter into // fullscreen window state, so it's expected to be fullscreen. - EXPECT_TRUE(true == runtime()->window()->IsFullscreen()); + EXPECT_TRUE(true == runtime->window()->IsFullscreen()); + + WindowedNotificationObserver exit_observer( + xwalk::NOTIFICATION_FULLSCREEN_CHANGED, + NotificationService::AllSources()); - FullscreenNotificationObserver exit_observer; ret = content::ExecuteScript( - runtime()->web_contents(), "doExitFullscreenClick();"); + runtime->web_contents(), "doExitFullscreenClick();"); EXPECT_TRUE(ret); content::RunAllPendingInMessageLoop(); exit_observer.Wait(); // Calling doExitFullscreenClick defined in fullscreen.html leads to exit // fullscreen window state, so it's expected to be not fullscreen. - EXPECT_TRUE(false == runtime()->window()->IsFullscreen()); + EXPECT_TRUE(false == runtime->window()->IsFullscreen()); } @@ -209,30 +125,31 @@ IN_PROC_BROWSER_TEST_F(XWalkRuntimeTest, GetWindowTitle) { GURL url = xwalk_test_utils::GetTestURL( base::FilePath(), base::FilePath().AppendASCII("title.html")); base::string16 title = base::ASCIIToUTF16("Dummy Title"); - content::TitleWatcher title_watcher(runtime()->web_contents(), title); - xwalk_test_utils::NavigateToURL(runtime(), url); + Runtime* runtime = CreateRuntime(); + content::TitleWatcher title_watcher(runtime->web_contents(), title); + xwalk_test_utils::NavigateToURL(runtime, url); EXPECT_EQ(title, title_watcher.WaitAndGetTitle()); - NativeAppWindow* window = runtime()->window(); + NativeAppWindow* window = runtime->window(); base::string16 window_title = window->GetNativeWindow()->title(); EXPECT_EQ(title, window_title); } #endif IN_PROC_BROWSER_TEST_F(XWalkRuntimeTest, OpenLinkInNewRuntime) { - size_t len = runtimes().size(); GURL url = xwalk_test_utils::GetTestURL( base::FilePath(), base::FilePath().AppendASCII("new_target.html")); - xwalk_test_utils::NavigateToURL(runtime(), url); - bool ret = content::ExecuteScript(runtime()->web_contents(), "doClick();"); + Runtime* runtime = CreateRuntime(url); + size_t len = runtimes().size(); + bool ret = content::ExecuteScript(runtime->web_contents(), "doClick();"); EXPECT_TRUE(ret); content::RunAllPendingInMessageLoop(); // Calling doClick defined in new_target.html leads to open a href in a new // target window, and so it is expected to create a new Runtime instance. - Runtime* second = WaitForSingleNewRuntime(); - EXPECT_TRUE(NULL != second); - EXPECT_NE(runtime(), second); EXPECT_EQ(len + 1, runtimes().size()); + Runtime* second = runtimes().back(); + EXPECT_TRUE(NULL != second); + EXPECT_NE(runtime, second); } #if defined(OS_TIZEN) @@ -240,8 +157,9 @@ IN_PROC_BROWSER_TEST_F(XWalkRuntimeTest, LoadTizenWebUiFwFile) { GURL url = xwalk_test_utils::GetTestURL( base::FilePath(), base::FilePath().AppendASCII("tizenwebuifw.html")); base::string16 title = base::ASCIIToUTF16("Pass"); - content::TitleWatcher title_watcher(runtime()->web_contents(), title); - xwalk_test_utils::NavigateToURL(runtime(), url); + Runtime* runtime = CreateRuntime(); + content::TitleWatcher title_watcher(runtime->web_contents(), title); + xwalk_test_utils::NavigateToURL(runtime, url); EXPECT_EQ(title, title_watcher.WaitAndGetTitle()); } #endif diff --git a/src/xwalk/runtime/common/xwalk_notification_types.h b/src/xwalk/runtime/common/xwalk_notification_types.h index 0aea519..f18411f 100644 --- a/src/xwalk/runtime/common/xwalk_notification_types.h +++ b/src/xwalk/runtime/common/xwalk_notification_types.h @@ -13,16 +13,8 @@ namespace xwalk { enum NotificationType { NOTIFICATION_XWALK_START = content::NOTIFICATION_CONTENT_END, - // Notify that a new Runtime instance is created. The source is a - // Source containing the affected Runtime. No details is provided. - NOTIFICATION_RUNTIME_OPENED = NOTIFICATION_XWALK_START, - - // Notify that a Runtime instance is close. The source is a Source - // containing the affected Runtime. No details is provided. - NOTIFICATION_RUNTIME_CLOSED, - // Notify that fullscreen state of a NativeAppWindow is changed. - NOTIFICATION_FULLSCREEN_CHANGED, + NOTIFICATION_FULLSCREEN_CHANGED = NOTIFICATION_XWALK_START, NOTIFICATION_XWALK_END, }; diff --git a/src/xwalk/runtime/common/xwalk_paths.cc b/src/xwalk/runtime/common/xwalk_paths.cc index d8067e8..0971add 100644 --- a/src/xwalk/runtime/common/xwalk_paths.cc +++ b/src/xwalk/runtime/common/xwalk_paths.cc @@ -12,6 +12,8 @@ #if defined(OS_WIN) #include "base/base_paths_win.h" +#elif defined(OS_TIZEN) +#include #elif defined(OS_LINUX) #include "base/environment.h" #include "base/nix/xdg_util.h" @@ -65,7 +67,15 @@ base::FilePath GetFrameworkBundlePath() { const base::FilePath::CharType kInternalNaClPluginFileName[] = FILE_PATH_LITERAL("internal-nacl-plugin"); -#if defined(OS_LINUX) +#if defined(OS_TIZEN) +base::FilePath GetAppPath() { + const char* app_path = getuid() != tzplatform_getuid(TZ_SYS_GLOBALAPP_USER) ? + tzplatform_getenv(TZ_USER_APP) : + tzplatform_getenv(TZ_SYS_RW_APP); + return base::FilePath(app_path); +} + +#elif defined(OS_LINUX) base::FilePath GetConfigPath() { scoped_ptr env(base::Environment::Create()); return base::nix::GetXDGDirectory( @@ -86,7 +96,10 @@ bool GetXWalkDataPath(base::FilePath* path) { CHECK(PathService::Get(base::DIR_LOCAL_APP_DATA, &cur)); cur = cur.Append(xwalk_suffix); -#elif defined(OS_TIZEN) || defined(OS_LINUX) +#elif defined(OS_TIZEN) + cur = GetAppPath().Append(xwalk_suffix); + +#elif defined(OS_LINUX) cur = GetConfigPath().Append(xwalk_suffix); #elif defined(OS_MACOSX) diff --git a/src/xwalk/sysapps/common/common_api_browsertest.cc b/src/xwalk/sysapps/common/common_api_browsertest.cc index 01c6545..4e7d6d3 100644 --- a/src/xwalk/sysapps/common/common_api_browsertest.cc +++ b/src/xwalk/sysapps/common/common_api_browsertest.cc @@ -172,8 +172,8 @@ IN_PROC_BROWSER_TEST_F(SysAppsCommonTest, SysAppsCommon) { const base::string16 passString = base::ASCIIToUTF16("Pass"); const base::string16 failString = base::ASCIIToUTF16("Fail"); - content::RunAllPendingInMessageLoop(); - content::TitleWatcher title_watcher(runtime()->web_contents(), passString); + xwalk::Runtime* runtime = CreateRuntime(); + content::TitleWatcher title_watcher(runtime->web_contents(), passString); title_watcher.AlsoWaitForTitle(failString); base::FilePath test_file; @@ -184,6 +184,6 @@ IN_PROC_BROWSER_TEST_F(SysAppsCommonTest, SysAppsCommon) { .Append(FILE_PATH_LITERAL("common")) .Append(FILE_PATH_LITERAL("common_api_browsertest.html")); - xwalk_test_utils::NavigateToURL(runtime(), net::FilePathToFileURL(test_file)); + xwalk_test_utils::NavigateToURL(runtime, net::FilePathToFileURL(test_file)); EXPECT_EQ(passString, title_watcher.WaitAndGetTitle()); } diff --git a/src/xwalk/sysapps/device_capabilities/device_capabilities_api_browsertest.cc b/src/xwalk/sysapps/device_capabilities/device_capabilities_api_browsertest.cc index 520e8a7..7a02210 100644 --- a/src/xwalk/sysapps/device_capabilities/device_capabilities_api_browsertest.cc +++ b/src/xwalk/sysapps/device_capabilities/device_capabilities_api_browsertest.cc @@ -15,8 +15,8 @@ IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, SysAppsDeviceCapabilities) { const base::string16 passString = base::ASCIIToUTF16("Pass"); const base::string16 failString = base::ASCIIToUTF16("Fail"); - content::RunAllPendingInMessageLoop(); - content::TitleWatcher title_watcher(runtime()->web_contents(), passString); + xwalk::Runtime* runtime = CreateRuntime(); + content::TitleWatcher title_watcher(runtime->web_contents(), passString); title_watcher.AlsoWaitForTitle(failString); base::FilePath test_file; @@ -27,6 +27,6 @@ IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, SysAppsDeviceCapabilities) { .Append(FILE_PATH_LITERAL("device_capabilities")) .Append(FILE_PATH_LITERAL("device_capabilities_api_browsertest.html")); - xwalk_test_utils::NavigateToURL(runtime(), net::FilePathToFileURL(test_file)); + xwalk_test_utils::NavigateToURL(runtime, net::FilePathToFileURL(test_file)); EXPECT_EQ(passString, title_watcher.WaitAndGetTitle()); } diff --git a/src/xwalk/sysapps/raw_socket/raw_socket_api_browsertest.cc b/src/xwalk/sysapps/raw_socket/raw_socket_api_browsertest.cc index f657ff4..d8d701f 100644 --- a/src/xwalk/sysapps/raw_socket/raw_socket_api_browsertest.cc +++ b/src/xwalk/sysapps/raw_socket/raw_socket_api_browsertest.cc @@ -14,6 +14,7 @@ #include "xwalk/test/base/xwalk_test_utils.h" using namespace xwalk::extensions; // NOLINT +using xwalk::Runtime; namespace { @@ -57,8 +58,8 @@ IN_PROC_BROWSER_TEST_F(SysAppsRawSocketTest, SysAppsRawSocket) { const base::string16 passString = base::ASCIIToUTF16("Pass"); const base::string16 failString = base::ASCIIToUTF16("Fail"); - content::RunAllPendingInMessageLoop(); - content::TitleWatcher title_watcher(runtime()->web_contents(), passString); + Runtime* runtime = CreateRuntime(); + content::TitleWatcher title_watcher(runtime->web_contents(), passString); title_watcher.AlsoWaitForTitle(failString); base::FilePath test_file; @@ -69,6 +70,6 @@ IN_PROC_BROWSER_TEST_F(SysAppsRawSocketTest, SysAppsRawSocket) { .Append(FILE_PATH_LITERAL("raw_socket")) .Append(FILE_PATH_LITERAL("raw_socket_api_browsertest.html")); - xwalk_test_utils::NavigateToURL(runtime(), net::FilePathToFileURL(test_file)); + xwalk_test_utils::NavigateToURL(runtime, net::FilePathToFileURL(test_file)); EXPECT_EQ(passString, title_watcher.WaitAndGetTitle()); } diff --git a/src/xwalk/test/base/in_process_browser_test.cc b/src/xwalk/test/base/in_process_browser_test.cc index c1b10b3..3a2d1dd 100644 --- a/src/xwalk/test/base/in_process_browser_test.cc +++ b/src/xwalk/test/base/in_process_browser_test.cc @@ -16,6 +16,7 @@ #include "base/strings/string_number_conversions.h" #include "base/test/test_file_util.h" #include "content/public/browser/notification_service.h" +#include "content/public/browser/notification_source.h" #include "content/public/browser/notification_types.h" #include "content/public/common/content_switches.h" #include "content/public/test/browser_test_utils.h" @@ -38,6 +39,7 @@ using xwalk::Runtime; using xwalk::XWalkContentRendererClient; using xwalk::XWalkRunner; +using xwalk::NativeAppWindow; namespace { @@ -49,85 +51,36 @@ base::LazyInstance::Leaky base::LazyInstance::Leaky g_xwalk_content_renderer_client = LAZY_INSTANCE_INITIALIZER; #endif - -Runtime* CreateWithDefaultWindow( - xwalk::RuntimeContext* runtime_context, const GURL& url, - Runtime::Observer* observer = NULL) { - Runtime* runtime = Runtime::Create(runtime_context, observer); - runtime->LoadURL(url); -#if !defined(OS_ANDROID) - xwalk::RuntimeUIStrategy ui_strategy; - xwalk::NativeAppWindow::CreateParams params; - ui_strategy.Show(runtime, params); -#endif - return runtime; -} - -} // namespace - -RuntimeRegistry::RuntimeRegistry() { -} - -RuntimeRegistry::~RuntimeRegistry() { -} - -void RuntimeRegistry::CloseAll() { - if (runtimes_.empty()) - return; - - RuntimeList cached(runtimes_); - std::for_each(cached.begin(), cached.end(), std::mem_fun(&Runtime::Close)); - // Wait until all windows are closed. - content::RunAllPendingInMessageLoop(); - DCHECK(runtimes_.empty()) << runtimes_.size(); -} - -void RuntimeRegistry::OnRuntimeAdded(Runtime* runtime) { - DCHECK(runtime); - runtimes_.push_back(runtime); -} - -void RuntimeRegistry::OnRuntimeRemoved(Runtime* runtime) { - DCHECK(runtime); - RuntimeList::iterator it = - std::find(runtimes_.begin(), runtimes_.end(), runtime); - DCHECK(it != runtimes_.end()); - runtimes_.erase(it); - - if (runtimes_.empty()) - base::MessageLoop::current()->PostTask( - FROM_HERE, base::MessageLoop::QuitClosure()); -} - -InProcessBrowserTest::InProcessBrowserTest() - : runtime_registry_(new RuntimeRegistry), - runtime_(NULL) { - CreateTestServer(base::FilePath(FILE_PATH_LITERAL("xwalk/test/data"))); -} - -InProcessBrowserTest::~InProcessBrowserTest() { -} - -base::CommandLine InProcessBrowserTest::GetCommandLineForRelaunch() { +// Return a CommandLine object that is used to relaunch the browser_test +// binary as a browser process. +base::CommandLine GetCommandLineForRelaunch() { base::CommandLine new_command_line( base::CommandLine::ForCurrentProcess()->GetProgram()); CommandLine::SwitchMap switches = CommandLine::ForCurrentProcess()->GetSwitches(); new_command_line.AppendSwitch(content::kLaunchAsBrowser); - for (base::CommandLine::SwitchMap::const_iterator iter = switches.begin(); - iter != switches.end(); ++iter) { + for (auto iter = switches.begin(); iter != switches.end(); ++iter) { new_command_line.AppendSwitchNative((*iter).first, (*iter).second); } return new_command_line; } +} // namespace + +InProcessBrowserTest::InProcessBrowserTest() { + CreateTestServer(base::FilePath(FILE_PATH_LITERAL("xwalk/test/data"))); +} + +InProcessBrowserTest::~InProcessBrowserTest() { +} + void InProcessBrowserTest::SetUp() { base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); // Allow subclasses to change the command line before running any tests. SetUpCommandLine(command_line); // Add command line arguments that are used by all InProcessBrowserTests. - PrepareTestCommandLine(command_line); + xwalk_test_utils::PrepareBrowserCommandLineForTests(command_line); // Single-process mode is not set in BrowserMain, so process it explicitly, // and set up renderer. @@ -139,33 +92,23 @@ void InProcessBrowserTest::SetUp() { BrowserTestBase::SetUp(); } -xwalk::RuntimeContext* InProcessBrowserTest::GetRuntimeContext() const { - return XWalkRunner::GetInstance()->runtime_context(); -} - -void InProcessBrowserTest::PrepareTestCommandLine( - base::CommandLine* command_line) { - // Propagate commandline settings from test_launcher_utils. - xwalk_test_utils::PrepareBrowserCommandLineForTests(command_line); -} - -const InProcessBrowserTest::RuntimeList& InProcessBrowserTest::runtimes() - const { - return runtime_registry_->runtimes(); +Runtime* InProcessBrowserTest::CreateRuntime( + const GURL& url, const NativeAppWindow::CreateParams& params) { + Runtime* runtime = Runtime::Create( + XWalkRunner::GetInstance()->browser_context()); + runtime->set_observer(this); + runtimes_.push_back(runtime); + runtime->LoadURL(url); + content::WaitForLoadStop(runtime->web_contents()); + runtime->set_ui_delegate( + xwalk::DefaultRuntimeUIDelegate::Create(runtime, params)); + runtime->Show(); + return runtime; } void InProcessBrowserTest::RunTestOnMainThreadLoop() { // Pump startup related events. content::RunAllPendingInMessageLoop(); - // FIXME : Unfortunately too many tests now rely on the 'runtime()' - // method, instead they should just create runtimes themselves - // when needed and thus the 'runtime()' method should be removed - // as well as 'runtime_' initialization below. - runtime_ = CreateWithDefaultWindow( - GetRuntimeContext(), - GURL(), runtime_registry_.get()); - content::WaitForLoadStop(runtime_->web_contents()); - content::RunAllPendingInMessageLoop(); SetUpOnMainThread(); @@ -176,7 +119,39 @@ void InProcessBrowserTest::RunTestOnMainThreadLoop() { // gtest in that it invokes TearDown even if Setup fails. ProperMainThreadCleanup(); - runtime_registry_->CloseAll(); + CloseAll(); +} + +void InProcessBrowserTest::OnNewRuntimeAdded(Runtime* runtime) { + DCHECK(runtime); + runtimes_.push_back(runtime); + runtime->set_observer(this); + runtime->set_ui_delegate( + xwalk::DefaultRuntimeUIDelegate::Create(runtime)); + runtime->Show(); +} + +void InProcessBrowserTest::OnRuntimeClosed(Runtime* runtime) { + DCHECK(runtime); + auto it = std::find(runtimes_.begin(), runtimes_.end(), runtime); + DCHECK(it != runtimes_.end()); + runtimes_.erase(it); + + if (runtimes_.empty()) + base::MessageLoop::current()->PostTask( + FROM_HERE, base::MessageLoop::QuitClosure()); +} + +void InProcessBrowserTest::CloseAll() { + if (runtimes_.empty()) + return; + + RuntimeList to_be_closed(runtimes_.get()); + for (Runtime* runtime : to_be_closed) + runtime->Close(); + // Wait until all windows are closed. + content::RunAllPendingInMessageLoop(); + DCHECK(runtimes_.empty()) << runtimes_.size(); } bool InProcessBrowserTest::CreateDataPathDir() { @@ -195,3 +170,4 @@ bool InProcessBrowserTest::CreateDataPathDir() { } return xwalk_test_utils::OverrideDataPathDir(data_path_dir); } + diff --git a/src/xwalk/test/base/in_process_browser_test.h b/src/xwalk/test/base/in_process_browser_test.h index 04368d8..576a839 100644 --- a/src/xwalk/test/base/in_process_browser_test.h +++ b/src/xwalk/test/base/in_process_browser_test.h @@ -11,6 +11,7 @@ #include "base/files/scoped_temp_dir.h" #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" +#include "base/memory/scoped_vector.h" #include "content/public/test/browser_test.h" #include "content/public/test/browser_test_base.h" #include "testing/gtest/include/gtest/gtest.h" @@ -29,72 +30,50 @@ namespace net { class RuleBasedHostResolverProc; } -class RuntimeRegistry : public xwalk::Runtime::Observer { - public: - typedef std::vector RuntimeList; - RuntimeRegistry(); - virtual ~RuntimeRegistry(); - - void CloseAll(); - const RuntimeList& runtimes() const { return runtimes_; } - - private: - virtual void OnRuntimeAdded(xwalk::Runtime* runtime) OVERRIDE; - virtual void OnRuntimeRemoved(xwalk::Runtime* runtime) OVERRIDE; - - RuntimeList runtimes_; -}; - // Base class for tests wanting to bring up a runtime (aka. browser) in the // unit test process. // // Reference comments in chrome/test/base/in_process_browser_test.h file // about how to write a InProcessBrowserTest. // -class InProcessBrowserTest : public content::BrowserTestBase { +class InProcessBrowserTest : public content::BrowserTestBase, + public xwalk::Runtime::Observer { public: - typedef RuntimeRegistry::RuntimeList RuntimeList; + using RuntimeList = std::vector; InProcessBrowserTest(); virtual ~InProcessBrowserTest(); // Configures everything for an in process browser test, then invokes // BrowserMain. BrowserMain ends up invoking RunTestOnMainThreadLoop. - virtual void SetUp() OVERRIDE; + virtual void SetUp() override; protected: - // FIXME : Two following methods should be removed! - xwalk::Runtime* runtime() const { return runtime_; } - const RuntimeList& runtimes() const; - // Use this as an observer when create a 'Runtime' instance within a test. - RuntimeRegistry* runtime_registry() const { - return runtime_registry_.get(); } + const RuntimeList& runtimes() const { return runtimes_.get(); } - xwalk::RuntimeContext* GetRuntimeContext() const; + xwalk::Runtime* CreateRuntime( + const GURL& url = GURL(), + const xwalk::NativeAppWindow::CreateParams& params = + xwalk::NativeAppWindow::CreateParams()); // Override this to add any custom cleanup code that needs to be done on the // main thread before the browser is torn down. virtual void ProperMainThreadCleanup() {} // BrowserTestBase: - virtual void RunTestOnMainThreadLoop() OVERRIDE; - - // Return a CommandLine object that is used to relaunch the browser_test - // binary as a browser process. - base::CommandLine GetCommandLineForRelaunch(); + virtual void RunTestOnMainThreadLoop() override; private: + // xwalk::Runtime::Observer + virtual void OnNewRuntimeAdded(xwalk::Runtime* runtime) override; + virtual void OnRuntimeClosed(xwalk::Runtime* runtime) override; + + void CloseAll(); // Create data path directory for this test to avoid pollution in default // data path. Return true if success. bool CreateDataPathDir(); - // Prepare command line that will be used to launch the child browser process - // with an in-process test. - void PrepareTestCommandLine(base::CommandLine* command_line); - - scoped_ptr runtime_registry_; - // FIXME : Should be removed. - xwalk::Runtime* runtime_; + ScopedVector runtimes_; // Temporary data path directory. Used only when a data path directory is not // specified in the command line. diff --git a/src/xwalk/xwalk.gyp b/src/xwalk/xwalk.gyp index 50030ba..95d865f 100644 --- a/src/xwalk/xwalk.gyp +++ b/src/xwalk/xwalk.gyp @@ -69,6 +69,7 @@ 'experimental/native_file_system/native_file_system_extension.cc', 'experimental/native_file_system/native_file_system_extension.h', 'experimental/native_file_system/virtual_root_provider_mac.cc', + 'experimental/native_file_system/virtual_root_provider_tizen.cc', 'experimental/native_file_system/virtual_root_provider_win.cc', 'experimental/native_file_system/virtual_root_provider.cc', 'experimental/native_file_system/virtual_root_provider.h', @@ -152,10 +153,6 @@ 'runtime/browser/renderer_host/pepper/xwalk_browser_pepper_host_factory.h', 'runtime/browser/runtime.cc', 'runtime/browser/runtime.h', - 'runtime/browser/runtime_context.cc', - 'runtime/browser/runtime_context.h', - 'runtime/browser/runtime_defered_ui_strategy.cc', - 'runtime/browser/runtime_defered_ui_strategy.h', 'runtime/browser/runtime_download_manager_delegate.cc', 'runtime/browser/runtime_download_manager_delegate.h', 'runtime/browser/runtime_file_select_helper.cc', @@ -181,8 +178,8 @@ 'runtime/browser/runtime_resource_dispatcher_host_delegate_android.h', 'runtime/browser/runtime_select_file_policy.cc', 'runtime/browser/runtime_select_file_policy.h', - 'runtime/browser/runtime_ui_strategy.cc', - 'runtime/browser/runtime_ui_strategy.h', + 'runtime/browser/runtime_ui_delegate.cc', + 'runtime/browser/runtime_ui_delegate.h', 'runtime/browser/runtime_url_request_context_getter.cc', 'runtime/browser/runtime_url_request_context_getter.h', 'runtime/browser/speech/speech_recognition_manager_delegate.cc', @@ -198,6 +195,8 @@ 'runtime/browser/ui/color_chooser_mac.cc', 'runtime/browser/ui/native_app_window.cc', 'runtime/browser/ui/native_app_window.h', + 'runtime/browser/ui/native_app_window_aura.cc', + 'runtime/browser/ui/native_app_window_aura.h', 'runtime/browser/ui/native_app_window_android.cc', 'runtime/browser/ui/native_app_window_mac.h', 'runtime/browser/ui/native_app_window_mac.mm', @@ -217,6 +216,8 @@ 'runtime/browser/xwalk_app_extension_bridge.h', 'runtime/browser/xwalk_application_mac.h', 'runtime/browser/xwalk_application_mac.mm', + 'runtime/browser/xwalk_browser_context.cc', + 'runtime/browser/xwalk_browser_context.h', 'runtime/browser/xwalk_browser_main_parts.cc', 'runtime/browser/xwalk_browser_main_parts.h', 'runtime/browser/xwalk_browser_main_parts_android.cc', @@ -299,22 +300,14 @@ '../content/app/resources/content_resources.gyp:content_resources', '../ui/compositor/compositor.gyp:compositor', 'build/system.gyp:tizen_geolocation', + 'build/system.gyp:tizen_tzplatform_config', 'sysapps/sysapps_resources.gyp:xwalk_sysapps_resources', 'tizen/xwalk_tizen.gypi:xwalk_tizen_lib', '<(DEPTH)/third_party/jsoncpp/jsoncpp.gyp:jsoncpp', '../components/components.gyp:web_modal', '../components/components.gyp:renderer_context_menu', ], - 'cflags': [ - '