1 module awebview.wrapper.webpreferences;
2 
3 
4 import awebview.wrapper.cpp;
5 import awebview.wrapper.webstring : WebStringCpp;
6 
7 import carbon.memory;
8 
9 
10 shared static immutable defaultCSS = `* {
11 font-family:'ヒラギノ角ゴ Pro W3', 'Hiragino Kaku Gothic Pro', メイリオ, Meiryo, 'MS Pゴシック', sans-serif;
12 font-size: 11pt;
13 }`;
14 
15 
16 shared static immutable defaultScript = q{
17 function cssResize(doc, win, _sel_, _prop_, _expr_)
18 {
19     var _exprString_ = "e.style." + _prop_ + " = (" + _expr_ + ") + 'px'";
20     var _qs_ = doc.querySelectorAll(_sel_);
21 
22     var docElem = document.documentElement;
23     var body = document..body;
24 
25     for(var _i_ = 0, _len_ = _qs_.length; _i_ < _len_; ++_i_){
26         var e = _qs_[_i_];
27         eval(_exprString_);
28     }
29 }
30 };
31 
32 
33 struct WebPreferences
34 {
35     static WebPreferences opCall() nothrow @nogc
36     {
37         WebPreferences wp;
38         WebPreferencesMember.ctor(&wp._wp);
39         return wp;
40     }
41 
42 
43     static WebPreferences recommended() nothrow @nogc
44     {
45         auto pref = WebPreferences();
46         with(pref){
47             enableWebAudio = true;
48             enableWebGL = true;
49             enableGPUAcceleration = true;
50             enableJavascript = true;
51             enableDart = true;
52             userStylesheet = defaultCSS;
53             userScript = defaultScript;
54             enableSmoothScrolling = true;
55             enableRemoteFonts = true;
56             defaultEncoding = "utf-8";
57         }
58 
59         return pref;
60     }
61 
62 
63     this(this) nothrow @nogc
64     {
65         static void callPB(T)(ref T b)
66         {
67           static if(is(typeof(b.__postblit())))
68             b.__postblit();
69         }
70 
71         callPB(userStylesheet);
72         callPB(userScript);
73         callPB(proxyConfig);
74         callPB(acceptLanguage);
75         callPB(acceptCharset);
76         callPB(defaultEncoding);
77     }
78 
79 
80     ~this() nothrow @nogc
81     {
82         callAllDtor(userStylesheet);
83         callAllDtor(userScript);
84         callAllDtor(proxyConfig);
85         callAllDtor(acceptLanguage);
86         callAllDtor(acceptCharset);
87         callAllDtor(defaultEncoding);
88     }
89 
90 
91   @property inout pure nothrow @trusted @nogc
92   {
93     inout(awebview.wrapper.cpp.WebPreferences)* cppObj() @safe
94     { return &_wp; }
95 
96     ref inout(int) maxHttpCacheStorage()
97     { return _wp.max_http_cache_storage; }
98 
99     ref inout(bool) enableJavascript()
100     { return _wp.enable_javascript; }
101 
102     ref inout(bool) enableDart()
103     { return _wp.enable_dart; }
104 
105     ref inout(bool) enablePlugins()
106     { return _wp.enable_plugins; }
107 
108     ref inout(bool) enableLocalStorage()
109     { return _wp.enable_local_storage; }
110 
111     ref inout(bool) enableDatabases()
112     { return _wp.enable_databases; }
113 
114     ref inout(bool) enableAppCache()
115     { return _wp.enable_app_cache; }
116 
117     ref inout(bool) enableWebAudio()
118     { return _wp.enable_web_audio; }
119 
120     ref inout(bool) enableWebGL()
121     { return _wp.enable_web_gl; }
122 
123     ref inout(bool) enableWebSecurity()
124     { return _wp.enable_web_security; }
125 
126     ref inout(bool) enableRemoteFonts()
127     { return _wp.enable_remote_fonts; }
128 
129     ref inout(bool) enableSmoothScrolling()
130     { return _wp.enable_smooth_scrolling; }
131 
132     ref inout(bool) enableGPUAcceleration()
133     { return _wp.enable_gpu_acceleration; }
134 
135     ref inout(WebStringCpp) userStylesheet()
136     { return *cast(typeof(return)*)&_wp.user_stylesheet; }
137 
138     ref inout(WebStringCpp) userScript()
139     { return *cast(typeof(return)*)&_wp.user_script; }
140 
141     ref inout(WebStringCpp) proxyConfig()
142     { return *cast(typeof(return)*)&_wp.proxy_config; }
143 
144     ref inout(WebStringCpp) acceptLanguage()
145     { return *cast(typeof(return)*)&_wp.accept_language; }
146 
147     ref inout(WebStringCpp) acceptCharset()
148     { return *cast(typeof(return)*)&_wp.accept_charset; }
149 
150     ref inout(WebStringCpp) defaultEncoding()
151     { return *cast(typeof(return)*)&_wp.default_encoding; }
152 
153     ref inout(bool) shrinkStandaloneImagesToFit()
154     { return _wp.shrink_standalone_images_to_fit; }
155 
156     ref inout(bool) loadImagesAutomatically()
157     { return _wp.load_images_automatically; }
158 
159     ref inout(bool) allowScriptsToOpenWindows()
160     { return _wp.allow_scripts_to_open_windows; }
161 
162     ref inout(bool) allowScriptsToCloseWindows()
163     { return _wp.allow_scripts_to_close_windows; }
164 
165     ref inout(bool) allowScriptsToAccessClipboard()
166     { return _wp.allow_scripts_to_access_clipboard; }
167 
168     ref inout(bool) allowUniversalAccessFromFileURL()
169     { return _wp.allow_universal_access_from_file_url; }
170 
171     ref inout(bool) allowFileAccessFromFileURL()
172     { return _wp.allow_file_access_from_file_url; }
173 
174     ref inout(bool) allowRunningInsecureContent()
175     { return _wp.allow_running_insecure_content; }
176   }
177 
178 
179   private:
180     awebview.wrapper.cpp.WebPreferences _wp;
181 }