[WRTjs] Refactor popup
[platform/framework/web/chromium-efl.git] / wrt / src / browser / native_web_runtime.h
1 #ifndef BROWSER_NATIVE_WEB_RUNTIME_H_
2 #define BROWSER_NATIVE_WEB_RUNTIME_H_
3
4 #include <memory>
5 #include <unordered_map>
6
7 #include <tts.h>
8
9 #include "base/observer_list.h"
10 #include "base/timer/timer.h"
11 #include "url/gurl.h"
12
13 namespace content {
14 class BrowserContext;
15 class BrowserMainRunner;
16 struct MainFunctionParams;
17 }
18
19 namespace wrt {
20
21 class NativeAppControl;
22 class NativeWebRuntimeObserver;
23 class ResourceManager;
24 class Runtime;
25 class WRTProfileDelegate;
26 class WRTSpecialStoragePolicy;
27
28 class NativeWebRuntime {
29  public:
30   ~NativeWebRuntime();
31
32   static NativeWebRuntime& GetInstance();
33   static content::BrowserContext* GetBrowserContext();
34
35   void CreateBrowserMainRunner(
36       content::MainFunctionParams main_function_params);
37   void Initialize();
38
39   int RuntimeMain(int argc, char** argv);
40   void RequestQuit();
41   void Finalize();
42   void ShutdownExtension();
43   void CheckAllWindowClosed();
44
45   void NotifyAppControl(std::unique_ptr<NativeAppControl> app_control);
46   void NotifySuspend();
47   void NotifyResume();
48   void NotifyLowMemory();
49   bool NotifyMessage(const std::string& type,
50                      const std::vector<std::string>& params);
51   void NotifyAmbientTick();
52   void NotifyAmbientChanged(bool ambient_mode);
53   void NotifyStatusChanged(const std::string& status);
54
55   void SetLanguage(const std::string& language);
56
57   std::string GetEncodingType();
58   bool ShouldAllowNavigation(const std::string& url);
59   bool IsTizenWebKitCompatibilityEnabled() const {
60     return tizenCompatibilitySettings_.enabled;
61   }
62   void GetTizenVersion(unsigned& major, unsigned& minor, unsigned& release) {
63     major = tizenCompatibilitySettings_.major;
64     minor = tizenCompatibilitySettings_.minor;
65     release = tizenCompatibilitySettings_.release;
66   }
67
68   void AddObserver(NativeWebRuntimeObserver* obs);
69   void RemoveObserver(NativeWebRuntimeObserver* obs);
70
71   static void HandleQuotaExceed(
72       const scoped_refptr<WRTSpecialStoragePolicy>& wrt_special_storage_policy,
73       const GURL& origin, int64_t current_quota);
74
75   bool GetPermissionPopupOption() { return permission_popup_option_; }
76   void SetPermissionPopupOption(bool permission) {
77     permission_popup_option_ = permission;
78   }
79   std::string GetRuntimeVariable(const std::string& name);
80   void SetRuntimeVariable(const std::string& name, const std::string& value);
81
82   tts_mode_e GetTTSMode();
83   void SetDelegate(WRTProfileDelegate* delegate) {
84     runtime_delegate_ = delegate;
85   }
86
87  private:
88   NativeWebRuntime();
89
90   void SetAppExtensibleDataInfo();
91   void SetLocaleDir();
92   void SetupTizenCompatibility();
93   void OverrideDataPath();
94   bool IsRunningAsBackground();
95
96   struct {
97     unsigned major;
98     unsigned minor;
99     unsigned release;
100     bool enabled;
101   } tizenCompatibilitySettings_;
102
103   std::unordered_map<std::string, std::string> runtime_variables_;
104   std::unique_ptr<content::BrowserMainRunner> browser_main_runner_;
105   std::unique_ptr<Runtime> runtime_;
106   std::unique_ptr<ResourceManager> resource_manager_;
107
108   bool permission_popup_option_;  // false, not show permission popup/ true,
109                                   // show permission popup
110   bool eventloop_is_running_ = true;
111   base::RepeatingTimer gc_timer_;
112
113   base::ObserverList<NativeWebRuntimeObserver> observers_;
114   WRTProfileDelegate* runtime_delegate_ = nullptr;
115 };
116
117 }  // namespace wrt
118
119 #endif  // BROWSER_NATIVE_WEB_RUNTIME_H_