#include "xwalk/application/browser/application_system.h"
#include "xwalk/application/browser/installer/package.h"
#include "xwalk/application/common/application_file_util.h"
-#include "xwalk/application/common/application_manifest_constants.h"
#include "xwalk/application/common/event_names.h"
-#include "xwalk/application/common/id_util.h"
#include "xwalk/application/common/permission_policy_manager.h"
#include "xwalk/runtime/browser/runtime_context.h"
#include "xwalk/runtime/browser/runtime.h"
#include "xwalk/runtime/browser/xwalk_runner.h"
-#if defined(OS_TIZEN_MOBILE)
-#include "xwalk/application/browser/installer/tizen/package_installer.h"
+#if defined(OS_TIZEN)
#include "xwalk/application/browser/installer/tizen/service_package_installer.h"
#endif
-using xwalk::RuntimeContext;
+namespace xwalk {
+namespace application {
namespace {
void WaitForEventAndClose(
const std::string& app_id, const std::string& event_name,
- xwalk::application::ApplicationEventManager* event_manager) {
- class CloseOnEventArrived : public xwalk::application::EventObserver {
+ ApplicationEventManager* event_manager) {
+ class CloseOnEventArrived : public EventObserver {
public:
static CloseOnEventArrived* Create(const std::string& event_name,
- xwalk::application::ApplicationEventManager* event_manager) {
+ ApplicationEventManager* event_manager) {
return new CloseOnEventArrived(event_name, event_manager);
}
virtual void Observe(
const std::string& app_id,
- scoped_refptr<xwalk::application::Event> event) OVERRIDE {
- DCHECK(xwalk::application::kOnJavaScriptEventAck == event->name());
+ scoped_refptr<Event> event) OVERRIDE {
+ DCHECK(kOnJavaScriptEventAck == event->name());
std::string ack_event_name;
event->args()->GetString(0, &ack_event_name);
if (ack_event_name != event_name_)
private:
CloseOnEventArrived(
const std::string& event_name,
- xwalk::application::ApplicationEventManager* event_manager)
- : xwalk::application::EventObserver(event_manager),
+ ApplicationEventManager* event_manager)
+ : EventObserver(event_manager),
event_name_(event_name) {}
std::string event_name_;
CloseOnEventArrived* observer =
CloseOnEventArrived::Create(event_name, event_manager);
event_manager->AttachObserver(app_id,
- xwalk::application::kOnJavaScriptEventAck, observer);
+ kOnJavaScriptEventAck, observer);
}
void WaitForFinishLoad(
- scoped_refptr<xwalk::application::ApplicationData> application,
- xwalk::application::ApplicationEventManager* event_manager,
+ scoped_refptr<ApplicationData> application,
+ ApplicationEventManager* event_manager,
content::WebContents* contents) {
class CloseAfterLoadObserver : public content::WebContentsObserver {
public:
CloseAfterLoadObserver(
- scoped_refptr<xwalk::application::ApplicationData> application,
- xwalk::application::ApplicationEventManager* event_manager,
+ scoped_refptr<ApplicationData> application,
+ ApplicationEventManager* event_manager,
content::WebContents* contents)
: content::WebContentsObserver(contents),
application_(application),
const GURL& validate_url,
bool is_main_frame,
content::RenderViewHost* render_view_host) OVERRIDE {
- if (!IsEventHandlerRegistered(xwalk::application::kOnInstalled)) {
+ if (!IsEventHandlerRegistered(kOnInstalled)) {
CloseMessageLoop();
} else {
scoped_ptr<base::ListValue> event_args(new base::ListValue);
- scoped_refptr<xwalk::application::Event> event =
- xwalk::application::Event::CreateEvent(
- xwalk::application::kOnInstalled, event_args.Pass());
+ scoped_refptr<Event> event =
+ Event::CreateEvent(
+ kOnInstalled, event_args.Pass());
event_manager_->SendEvent(application_->ID(), event);
WaitForEventAndClose(
return events.find(event_name) != events.end();
}
- scoped_refptr<xwalk::application::ApplicationData> application_;
- xwalk::application::ApplicationEventManager* event_manager_;
+ scoped_refptr<ApplicationData> application_;
+ ApplicationEventManager* event_manager_;
};
// This object is self-destroyed when an event occurs.
}
void SaveSystemEventsInfo(
- xwalk::application::ApplicationService* application_service,
- scoped_refptr<xwalk::application::ApplicationData> application_data,
- xwalk::application::ApplicationEventManager* event_manager) {
+ ApplicationService* application_service,
+ scoped_refptr<ApplicationData> application_data,
+ ApplicationEventManager* event_manager) {
// We need to run main document after installation in order to
// register system events.
if (application_data->HasMainDocument()) {
- if (xwalk::application::Application* application =
+ if (Application* application =
application_service->Launch(application_data->ID())) {
WaitForFinishLoad(application->data(), event_manager,
application->GetMainDocumentRuntime()->web_contents());
}
}
-#if defined(OS_TIZEN_MOBILE)
-bool InstallPackageOnTizen(xwalk::application::ApplicationService* service,
- xwalk::application::ApplicationStorage* storage,
- xwalk::application::ApplicationData* application,
+#if defined(OS_TIZEN)
+bool InstallPackageOnTizen(ApplicationData* application_data,
const base::FilePath& data_dir) {
- if (xwalk::XWalkRunner::GetInstance()->is_running_as_service()) {
- return InstallApplicationForTizen(application, data_dir);
- }
-
- scoped_ptr<xwalk::application::PackageInstaller> installer =
- xwalk::application::PackageInstaller::Create(service, storage,
- application->ID(), data_dir);
- if (!installer || !installer->Install()) {
- LOG(ERROR) << "An error occurred during installation on Tizen.";
+ if (!XWalkRunner::GetInstance()->is_running_as_service()) {
+ LOG(ERROR) << "Installation on Tizen is only possible in"
+ << "service mode via 'xwalkctl' utility.";
return false;
}
- return true;
+
+ return InstallApplicationForTizen(application_data, data_dir);
}
-bool UninstallPackageOnTizen(xwalk::application::ApplicationService* service,
- xwalk::application::ApplicationStorage* storage,
- xwalk::application::ApplicationData* application,
+bool UninstallPackageOnTizen(ApplicationData* application_data,
const base::FilePath& data_dir) {
- if (xwalk::XWalkRunner::GetInstance()->is_running_as_service()) {
- return UninstallApplicationForTizen(application, data_dir);
- }
-
- scoped_ptr<xwalk::application::PackageInstaller> installer =
- xwalk::application::PackageInstaller::Create(service, storage,
- application->ID(), data_dir);
- if (!installer || !installer->Uninstall()) {
- LOG(ERROR) << "An error occurred during uninstallation on Tizen.";
+ if (!XWalkRunner::GetInstance()->is_running_as_service()) {
+ LOG(ERROR) << "Uninstallation on Tizen is only possible in"
+ << "service mode using 'xwalkctl' utility.";
return false;
}
- return true;
+
+ return UninstallApplicationForTizen(application_data, data_dir);
}
-#endif // OS_TIZEN_MOBILE
+#endif // OS_TIZEN
bool CopyDirectoryContents(const base::FilePath& from,
const base::FilePath& to) {
} // namespace
-namespace xwalk {
-namespace application {
-
const base::FilePath::CharType kApplicationsDir[] =
FILE_PATH_LITERAL("applications");
return false;
}
-#if defined(OS_TIZEN_MOBILE)
- if (!InstallPackageOnTizen(this, application_storage_,
- application_data.get(),
+#if defined(OS_TIZEN)
+ if (!InstallPackageOnTizen(application_data,
runtime_context_->GetPath())) {
application_storage_->RemoveApplication(application_data->ID());
return false;
return false;
}
-#if defined(OS_TIZEN_MOBILE)
- if (!UninstallPackageOnTizen(this, application_storage_,
- old_application.get(),
+#if defined(OS_TIZEN)
+ if (!UninstallPackageOnTizen(old_application,
runtime_context_->GetPath())) {
base::DeleteFile(app_dir, true);
base::Move(tmp_dir, app_dir);
LOG(ERROR) << "An Error occurred when updating the application.";
base::DeleteFile(app_dir, true);
base::Move(tmp_dir, app_dir);
-#if defined(OS_TIZEN_MOBILE)
- InstallPackageOnTizen(this, application_storage_,
- old_application.get(),
+#if defined(OS_TIZEN)
+ InstallPackageOnTizen(old_application,
runtime_context_->GetPath());
#endif
return false;
}
-#if defined(OS_TIZEN_MOBILE)
- if (!InstallPackageOnTizen(this, application_storage_,
- new_application.get(),
+#if defined(OS_TIZEN)
+ if (!InstallPackageOnTizen(new_application,
runtime_context_->GetPath()))
return false;
#endif
app->Terminate(Application::Immediate);
}
-#if defined(OS_TIZEN_MOBILE)
- if (!UninstallPackageOnTizen(this, application_storage_, application.get(),
+#if defined(OS_TIZEN)
+ if (!UninstallPackageOnTizen(application,
runtime_context_->GetPath()))
result = false;
#endif
}
Application* ApplicationService::Launch(
+ scoped_refptr<ApplicationData> application_data,
+ const Application::LaunchParams& launch_params) {
+ if (GetApplicationByID(application_data->ID()) != NULL) {
+ LOG(INFO) << "Application with id: " << application_data->ID()
+ << " is already running.";
+ // FIXME: we need to notify application that it had been attempted
+ // to invoke and let the application to define the further behavior.
+ return NULL;
+ }
+
+ event_manager_->AddEventRouterForApp(application_data);
+ Application* application(new Application(application_data,
+ runtime_context_,
+ this));
+ ScopedVector<Application>::iterator app_iter =
+ applications_.insert(applications_.end(), application);
+
+ if (!application->Launch(launch_params)) {
+ event_manager_->RemoveEventRouterForApp(application_data);
+ applications_.erase(app_iter);
+ return NULL;
+ }
+
+ FOR_EACH_OBSERVER(Observer, observers_,
+ DidLaunchApplication(application));
+
+ return application;
+}
+
+Application* ApplicationService::Launch(
const std::string& id, const Application::LaunchParams& params) {
scoped_refptr<ApplicationData> application_data =
application_storage_->GetApplicationData(id);
return Launch(application_data, params);
}
-Application* ApplicationService::Launch(const base::FilePath& path) {
+Application* ApplicationService::Launch(
+ const base::FilePath& path, const Application::LaunchParams& params) {
if (!base::DirectoryExists(path))
return NULL;
return NULL;
}
- return Launch(application_data, Application::LaunchParams());
-}
-
-Application* ApplicationService::Launch(const GURL& url) {
- namespace keys = xwalk::application_manifest_keys;
-
- const std::string& url_spec = url.spec();
- DCHECK(!url_spec.empty());
- const std::string& app_id = GenerateId(url_spec);
- // FIXME: we need to handle hash collisions.
- DCHECK(!application_storage_->GetApplicationData(app_id));
-
- base::DictionaryValue manifest;
- // FIXME: define permissions!
- manifest.SetString(keys::kURLKey, url_spec);
- manifest.SetString(keys::kNameKey, "XWalk Dummy App");
- manifest.SetString(keys::kVersionKey, "0");
- manifest.SetInteger(keys::kManifestVersionKey, 1);
- std::string error;
- scoped_refptr<ApplicationData> application_data = ApplicationData::Create(
- base::FilePath(), Manifest::COMMAND_LINE, manifest, app_id, &error);
- if (!application_data) {
- LOG(ERROR) << "Error occurred while trying to launch application: "
- << error;
- return NULL;
- }
-
- Application::LaunchParams launch_params;
- launch_params.entry_points = Application::URLKey;
- return Launch(application_data, launch_params);
+ return Launch(application_data, params);
}
namespace {
}
}
-Application* ApplicationService::Launch(
- scoped_refptr<ApplicationData> application_data,
- const Application::LaunchParams& launch_params) {
- if (GetApplicationByID(application_data->ID()) != NULL) {
- LOG(INFO) << "Application with id: " << application_data->ID()
- << " is already running.";
- // FIXME: we need to notify application that it had been attempted
- // to invoke and let the application to define the further behavior.
- return NULL;
- }
-
- event_manager_->AddEventRouterForApp(application_data);
- Application* application(new Application(application_data,
- runtime_context_,
- this));
- ScopedVector<Application>::iterator app_iter =
- applications_.insert(applications_.end(), application);
-
- if (!application->Launch(launch_params)) {
- event_manager_->RemoveEventRouterForApp(application_data);
- applications_.erase(app_iter);
- return NULL;
- }
-
- FOR_EACH_OBSERVER(Observer, observers_,
- DidLaunchApplication(application));
-
- return application;
-}
-
void ApplicationService::CheckAPIAccessControl(const std::string& app_id,
const std::string& extension_name,
const std::string& api_name, const PermissionCallback& callback) {