webappmanager
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
WebAppManager.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2008-2012 Hewlett-Packard Development Company, L.P.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * LICENSE@@@ */
30 #ifndef BROWSERAPPMANAGER_H
31 #define BROWSERAPPMANAGER_H
32 
33 #include "Common.h"
34 
35 #include <map>
36 #include <list>
37 #include <string>
38 #include <QString>
39 
40 #include <QApplication>
41 
42 #include "SyncTask.h"
43 #include "Event.h"
44 #include "MemoryWatcher.h"
45 #include "SignalSlot.h"
46 #include "Timer.h"
47 #include "WindowTypes.h"
48 #include "WindowProperties.h"
49 #include "WebAppCache.h"
50 #include "HostBase.h"
51 #include "lunaservice.h"
52 #include <PIpcBuffer.h>
53 #include <PIpcClient.h>
54 #include <PIpcChannelListener.h>
55 #include <PIpcMessage.h>
56 
57 
58 class WebAppBase;
59 class ProcessBase;
60 class WindowedWebApp;
62 class PIpcChannel;
63 class PalmClipboard;
65 class SysMgrKeyEvent;
66 class SysMgrWebBridge;
68 
69 #define WEB_APP_MGR_IPC_NAME "WebAppManager"
70 
74 class WebAppManager : public SyncTask
75  , public Trackable
76  , public PIpcClient
77  , public PIpcChannelListener
78 {
79 public:
90  static WebAppManager* instance();
91 
103  static bool hasBeenInstanced();
104 
110  static const std::string getTimeZone();
111 
119  virtual ~WebAppManager();
120 
121  //Documented in parent
122  virtual void run();
123 
131  Event::Orientation orientation() const;
132 
143  std::list<const ProcessBase*> runningApps() ;
144 
156  std::list<const ProcessBase*> runningApps(WindowType::Type winType);
157 
164  WebAppBase* findApp(const QString& processId);
165 
172  WebAppBase* findAppById(const QString& appId);
173 
186  LSHandle* getStatsServiceHandle() const;
187 
195  void copiedToClipboard(const QString& appId);
196 
204  void pastedFromClipboard(const QString& appId);
205 
216  void closePageSoon(SysMgrWebBridge* page);
217 
223  void closePageRequest(SysMgrWebBridge* page);
224 
234  void onMessageReceived(const PIpcMessage& msg);
235 
242  void onDisconnected();
243 
251  void setJavascriptFlags( const std::string& flags );
252 
260  void sendAsyncMessage( PIpcMessage* msg);
261 
262  //Documented in parent.
263  //No idea why this is here.
264  using TaskBase::mainLoop;
265 
276 
282  void closeByProcessId( const std::string& processId );
283 
284  // Host Info data cache
299  const void setHostInfo(const HostInfo *hostInfo);
300 
312  const HostInfo& getHostInfo() const;
313 
322  void reportAppLaunched(const QString& appId, const QString& processId);
323 
332  void reportAppClosed(const QString& appId, const QString& processId);
333 
343  int currentUiWidth() { return m_uiWidth; }
344 
354  int currentUiHeight() { return m_uiHeight; }
355 
366  bool isDevicePortraitType() { return m_deviceIsPortraitType; }
367 
379  void disableAppCaching(bool disable);
380 
391 
400  void setInSimulatedMouseEvent(bool val) { m_inSimulatedMouseEvent = val; }
401 
410  bool inSimulatedMouseEvent() const { return m_inSimulatedMouseEvent; }
411  void setActiveAppId(const std::string& id) { m_activeAppId = id; }
412  const std::string& getActiveAppId() { return m_activeAppId; }
413 protected:
414  // IPC control message handlers
428  void onLaunchUrl(const std::string& url, int winType,
429  const std::string& appDesc, const std::string& procId,
430  const std::string& args, const std::string& launchingAppId,
431  const std::string& launchingProcId);
432 
450  void onLaunchUrlChild(const std::string& url, int winType,
451  const std::string& appDesc, const std::string& procId,
452  const std::string& args, const std::string& launchingAppId,
453  const std::string& launchingProcId, int& errorCode, bool isHeadless);
454 
470  void onRelaunchApp(const std::string& procId, const std::string& args,
471  const std::string& launchingAppId, const std::string& launchingProcId);
472 
473  //void onInputEvent(int ipcKey, const SysMgrEventWrapper& wrapper);
474 
484  void onSetOrientation(int orient);
485 
493  void onGlobalProperties(int key);
494 
504  void onInspectByProcessId( const std::string& processId );
505 
513  void performLowMemoryActions( const bool allowExpensive = false );
514 
525  void monitorNativeProcessMemory( const pid_t pid, const int maxMemory, pid_t updateFromPid = 0 );
526 
532  void clearWebkitCache();
533 
544  void enableDebugger( bool enable );
545 
556  void onShutdownEvent();
557 
568  bool onKillApp(const std::string& appId);
569 
588  void onSyncKillApp(const std::string& appId, bool* result);
589 
606  void onProcMgrLaunch(const std::string& appDescString, const std::string& params,
607  const std::string& launchingAppId, const std::string& launchingProcId);
608 
630  void onProcMgrLaunchChild(const std::string& appDescString, const std::string& params,
631  const std::string& launchingAppId, const std::string& launchingProcId, bool isHeadless, bool isParentPdk);
632 
643  void onProcMgrLaunchBootTimApp(const std::string& appDescString);
644 
665  void onListOfRunningAppsRequest(bool includeSysApps);
666 
687  void onDeleteHTML5Database(const std::string& domain);
688 
703  void inputEvent(int ipcKey, sptr<Event> e);
704 
713  void onUiDimensionsChanged(int width, int height);
714 
725  void onSuspendWebkitProcess(bool* result);
726 
727 protected:
769  virtual void threadStarting();
770 
776  virtual void threadStopping();
777 
793  virtual void handleEvent(sptr<Event>);
794 
804  virtual void windowedAppAdded(WindowedWebApp *app);
805 
816  virtual void windowedAppKeyChanged(WindowedWebApp *app, int oldKey);
817 
827  virtual void windowedAppRemoved(WindowedWebApp *app);
828 
829 private:
830  static gboolean BootupTimeoutCallback(gpointer);
831  static gboolean BootupIdleCallback(gpointer);
832  void bootFinished();
833 
834  static bool systemServiceConnectCallback(LSHandle *sh, LSMessage *message, void *ctx);
835  static bool activityManagerCallback(LSHandle* sh, LSMessage* message, void* ctx);
836  WebAppBase* launchUrlInternal(const std::string& url, WindowType::Type winType,
837  const std::string& appDesc, const std::string& procId,
838  const std::string& args, const std::string& launchingAppId,
839  const std::string& launchingProcId, int& errorCode, bool launchAsChild, bool ignoreLowMemory=false);
840  WebAppBase* launchWithPageInternal(SysMgrWebBridge* page, WindowType::Type winType, ApplicationDescription* parentDesc);
841  void closeAppInternal(WebAppBase* app);
842  void setOrientationInternal(Event::Orientation orient);
843 
844  void restartHeadLessBootApps();
845 
846  void webPageAdded(SysMgrWebBridge* page);
847  void webPageRemoved(SysMgrWebBridge* page);
848  void shellPageAdded(SysMgrWebBridge* page);
849 
850  // IME support
851  void launchIme();
852  void launchImePopup(const std::string&);
853 
854  bool preventAppUnderLowMemory(const std::string& appId, WindowType::Type winType, ApplicationDescription* appDesc) const;
855 
856  static bool sysServicePrefsCallback(LSHandle *lshandle, LSMessage *message, void *ctx);
857  static bool displayManagerConnectCallback(LSHandle* sh, LSMessage* message, void* ctx);
858  static bool displayManagerCallback(LSHandle* sh, LSMessage* message, void* ctx);
859 
860  void slotMemoryStateChanged(MemoryWatcher::MemState state);
861 
862  static gboolean deletePagesCallback(gpointer arg);
863  void deletePages();
864 
865  void mimeHandoffUrl(const char* mimeType, const char* url, const char* callerId=0);
866 
867  WindowedWebApp* appForIpcKey(int key);
868  SysMgrWebBridge* takeShellPageForApp(const std::string& appId);
869 
870  void addHeadlessAppToWatchList(WebAppBase* app);
871  void removeHeadlessAppFromWatchList(WebAppBase* app);
872  bool headlessAppWatchCallback();
873 
874  WebAppManager();
875 
876  virtual void serverConnected(PIpcChannel*);
877  virtual void serverDisconnected();
878 
879  virtual void setAppWindowProperties(int appIpcKey, WindowProperties &winProp);
880 
881  void startGcPowerdActivity();
882  void stopGcPowerdActivity();
883  bool gcPowerdActivtyTimerCallback();
884  bool isAppRunning(const std::string& appId);
885 
886  void appDeleted(WebAppBase* app);
887 
888  typedef std::pair<std::string, SysMgrWebBridge*> AppIdWebPagePair;
889  typedef std::multimap<std::string, SysMgrWebBridge*> AppIdWebPageMap;
890  typedef std::map<std::string, SysMgrWebBridge*> AppIdShellPageMap;
891  typedef std::list<WebAppBase*> AppList;
892  typedef std::list<SysMgrWebBridge*> PageList;
893  typedef std::map<WebAppBase*, uint32_t> AppLaunchTimeMap;
894 
895  AppIdShellPageMap m_shellPageMap;
896  AppList m_appList;
897  AppIdWebPageMap m_appPageMap;
898  AppLaunchTimeMap m_headlessAppLaunchTimeMap;
899 
900  Event::Orientation m_orientation;
901  LSPalmService* m_service;
902  LSHandle* m_servicePublic;
903  LSHandle* m_servicePrivate;
904  WebKitEventListener* m_wkEventListener;
905  PageList m_pagesToDeleteList;
906  bool m_deletingPages;
907  Timer<WebAppManager> m_headlessAppWatchTimer;
908 
909  bool m_displayOn;
910  std::string m_gcPowerdActivityId;
911  Timer<WebAppManager> m_gcPowerdActivityTimer;
912 
913  typedef std::map<int, WindowedWebApp*> AppWindowMap;
914  AppWindowMap m_appWinMap;
915 
916  HostInfo hostInfoCache;
917 
918  int m_uiWidth, m_uiHeight;
919  bool m_deviceIsPortraitType;
920  bool m_disableAppCaching;
921 
922  bool m_inSimulatedMouseEvent;
923 
924  QApplication *m_Application;
925 
926  std::string m_activeAppId;
927 
928  friend class SysMgrWebBridge;
929  friend class SysMgrWebPage;
930  friend class WebAppBase;
931  friend class WindowedWebApp;
932  friend class MemoryWatcher;
933  friend class PalmSystem;
934  friend class CardWebApp;
935  friend class AlertWebApp;
936  friend class DashboardWebApp;
937  friend class ProcessManager;
938 };
939 
940 #endif /* BROWSERAPPMANAGER_H */