#include "base/memory/ref_counted.h"
#include "base/memory/scoped_vector.h"
#include "base/observer_list.h"
+#include "ui/base/ui_base_types.h"
#include "xwalk/application/browser/event_observer.h"
#include "xwalk/application/common/application_data.h"
#include "xwalk/runtime/browser/runtime.h"
struct LaunchParams {
LaunchParams() :
- entry_points(Default) {}
+ entry_points(Default),
+ launcher_pid(0),
+ window_state(ui::SHOW_STATE_DEFAULT) {}
LaunchEntryPoints entry_points;
+
+ // Used only when running as service. Specifies the PID of the launcher
+ // process.
+ int32 launcher_pid;
+
+ // Sets the initial state for the application windows.
+ ui::WindowShowState window_state;
};
// Closes all the application's runtimes (application pages).
+ // NOTE: Application is terminated asynchronously.
+ // Please use ApplicationService::Observer::WillDestroyApplication()
+ // interface to be notified about actual app termination.
+ //
// NOTE: ApplicationService deletes an Application instance
// immediately after its termination.
- void Terminate();
+ enum TerminationMode {
+ Normal,
+ Immediate // Ignore OnSuspend event handler.
+ };
+ void Terminate(TerminationMode = Normal);
// Returns Runtime (application page) containing the application's
// 'main document'. The main document is the main entry point of
// application amoung both running applications and installed ones
// (ApplicationData objects).
std::string id() const { return application_data_->ID(); }
- bool HasMainDocument() const { return application_data_->HasMainDocument(); }
int GetRenderProcessHostID() const;
const ApplicationData* data() const { return application_data_; }
ApplicationData* data() { return application_data_; }
+ // Tells whether the application use the specified extension.
+ bool UseExtension(const std::string& extension_name) const;
+
+ // The runtime permission mapping is registered by extension which
+ // implements some specific API, for example:
+ // "bluetooth" -> "bluetooth.read, bluetooth.write, bluetooth.management"
+ // Whenever there comes a API permission request, we can tell whether
+ // this API is registered, if yes, return the according permission name.
+ bool RegisterPermissions(const std::string& extension_name,
+ const std::string& perm_table);
+ std::string GetRegisteredPermissionName(const std::string& extension_name,
+ const std::string& api_name) const;
+
+ StoredPermission GetPermission(PermissionType type,
+ std::string& permission_name) const;
+ bool SetPermission(PermissionType type,
+ const std::string& permission_name,
+ StoredPermission perm);
+
private:
+ bool HasMainDocument() const;
// Runtime::Observer implementation.
virtual void OnRuntimeAdded(Runtime* runtime) OVERRIDE;
virtual void OnRuntimeRemoved(Runtime* runtime) OVERRIDE;
Observer* observer);
bool Launch(const LaunchParams& launch_params);
- template<LaunchEntryPoint>
- bool TryLaunchAt();
+ // Try to extract the URL from different possible keys for entry points in the
+ // manifest, returns it and the entry point used.
+ GURL GetURLForLaunch(const LaunchParams& params, LaunchEntryPoint* used);
+
+ GURL GetURLFromAppMainKey();
+ GURL GetURLFromLocalPathKey();
+ GURL GetURLFromURLKey();
friend class FinishEventObserver;
void CloseMainDocument();
+ void NotifyTermination();
bool IsOnSuspendHandlerRegistered() const;
+ bool IsTerminating() const { return finish_observer_; }
RuntimeContext* runtime_context_;
const scoped_refptr<ApplicationData> application_data_;
std::set<Runtime*> runtimes_;
scoped_ptr<EventObserver> finish_observer_;
Observer* observer_;
+ // The entry point used as part of Launch().
+ LaunchEntryPoint entry_point_used_;
+ TerminationMode termination_mode_used_;
+ base::WeakPtrFactory<Application> weak_factory_;
+ std::map<std::string, std::string> name_perm_map_;
+ // Application's session permissions.
+ StoredPermissionMap permission_map_;
DISALLOW_COPY_AND_ASSIGN(Application);
};