1/* 2 * Copyright (C) 2012 Samsung Electronics 3 * Copyright (C) 2012 Intel Corporation. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' 15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 16 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 18 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 20 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 22 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 23 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 24 * THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#include "config.h" 28#include "ewk_settings.h" 29 30#include "EwkView.h" 31#include "WKAPICast.h" 32#include "WKPreferencesRef.h" 33#include "WKString.h" 34#include "WebPreferences.h" 35#include "ewk_settings_private.h" 36 37using namespace WebKit; 38 39Eina_Bool ewk_settings_fullscreen_enabled_set(Ewk_Settings* settings, Eina_Bool enable) 40{ 41#if ENABLE(FULLSCREEN_API) 42 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 43 WKPreferencesSetFullScreenEnabled(settings->preferences(), enable); 44 return true; 45#else 46 UNUSED_PARAM(settings); 47 UNUSED_PARAM(enable); 48 return false; 49#endif 50} 51 52Eina_Bool ewk_settings_fullscreen_enabled_get(const Ewk_Settings* settings) 53{ 54#if ENABLE(FULLSCREEN_API) 55 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 56 return WKPreferencesGetFullScreenEnabled(settings->preferences()); 57#else 58 UNUSED_PARAM(settings); 59 return false; 60#endif 61} 62 63Eina_Bool ewk_settings_javascript_enabled_set(Ewk_Settings* settings, Eina_Bool enable) 64{ 65 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 66 67 WKPreferencesSetJavaScriptEnabled(settings->preferences(), enable); 68 69 return true; 70} 71 72Eina_Bool ewk_settings_javascript_enabled_get(const Ewk_Settings* settings) 73{ 74 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 75 76 return WKPreferencesGetJavaScriptEnabled(settings->preferences()); 77} 78 79Eina_Bool ewk_settings_loads_images_automatically_set(Ewk_Settings* settings, Eina_Bool automatic) 80{ 81 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 82 83 WKPreferencesSetLoadsImagesAutomatically(settings->preferences(), automatic); 84 85 return true; 86} 87 88Eina_Bool ewk_settings_loads_images_automatically_get(const Ewk_Settings* settings) 89{ 90 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 91 92 return WKPreferencesGetLoadsImagesAutomatically(settings->preferences()); 93} 94 95Eina_Bool ewk_settings_developer_extras_enabled_set(Ewk_Settings* settings, Eina_Bool enable) 96{ 97 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 98 99 WKPreferencesSetDeveloperExtrasEnabled(settings->preferences(), enable); 100 101 return true; 102} 103 104Eina_Bool ewk_settings_developer_extras_enabled_get(const Ewk_Settings* settings) 105{ 106 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 107 108 return WKPreferencesGetDeveloperExtrasEnabled(settings->preferences()); 109} 110 111Eina_Bool ewk_settings_file_access_from_file_urls_allowed_set(Ewk_Settings* settings, Eina_Bool enable) 112{ 113 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 114 115 WKPreferencesSetFileAccessFromFileURLsAllowed(settings->preferences(), enable); 116 117 return true; 118} 119 120Eina_Bool ewk_settings_file_access_from_file_urls_allowed_get(const Ewk_Settings* settings) 121{ 122 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 123 124 return WKPreferencesGetFileAccessFromFileURLsAllowed(settings->preferences()); 125} 126 127Eina_Bool ewk_settings_frame_flattening_enabled_set(Ewk_Settings* settings, Eina_Bool enable) 128{ 129 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 130 131 WKPreferencesSetFrameFlatteningEnabled(settings->preferences(), enable); 132 133 return true; 134} 135 136Eina_Bool ewk_settings_frame_flattening_enabled_get(const Ewk_Settings* settings) 137{ 138 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 139 140 return WKPreferencesGetFrameFlatteningEnabled(settings->preferences()); 141} 142 143Eina_Bool ewk_settings_dns_prefetching_enabled_set(Ewk_Settings* settings, Eina_Bool enable) 144{ 145 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 146 147 WKPreferencesSetDNSPrefetchingEnabled(settings->preferences(), enable); 148 149 return true; 150} 151 152Eina_Bool ewk_settings_dns_prefetching_enabled_get(const Ewk_Settings* settings) 153{ 154 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 155 156 return WKPreferencesGetDNSPrefetchingEnabled(settings->preferences()); 157} 158 159Eina_Bool ewk_settings_encoding_detector_enabled_set(Ewk_Settings* settings, Eina_Bool enable) 160{ 161 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 162 163 WKPreferencesSetEncodingDetectorEnabled(settings->preferences(), enable); 164 165 return true; 166} 167 168Eina_Bool ewk_settings_encoding_detector_enabled_get(const Ewk_Settings* settings) 169{ 170 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 171 172 return WKPreferencesGetEncodingDetectorEnabled(settings->preferences()); 173} 174 175Eina_Bool ewk_settings_default_text_encoding_name_set(Ewk_Settings* settings, const char* encoding) 176{ 177 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 178 179 settings->setDefaultTextEncodingName(encoding); 180 181 return true; 182} 183 184const char* ewk_settings_default_text_encoding_name_get(const Ewk_Settings* settings) 185{ 186 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, nullptr); 187 188 return settings->defaultTextEncodingName(); 189} 190 191Eina_Bool ewk_settings_preferred_minimum_contents_width_set(Ewk_Settings *settings, unsigned width) 192{ 193 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 194 195 toImpl(settings->preferences())->setLayoutFallbackWidth(width); 196 197 return true; 198} 199 200unsigned ewk_settings_preferred_minimum_contents_width_get(const Ewk_Settings *settings) 201{ 202 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 203 204 return toImpl(settings->preferences())->layoutFallbackWidth(); 205} 206 207Eina_Bool ewk_settings_offline_web_application_cache_enabled_set(Ewk_Settings* settings, Eina_Bool enable) 208{ 209 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 210 211 WKPreferencesSetOfflineWebApplicationCacheEnabled(settings->preferences(), enable); 212 213 return true; 214} 215 216Eina_Bool ewk_settings_offline_web_application_cache_enabled_get(const Ewk_Settings* settings) 217{ 218 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 219 220 return WKPreferencesGetOfflineWebApplicationCacheEnabled(settings->preferences()); 221} 222 223Eina_Bool ewk_settings_scripts_can_open_windows_set(Ewk_Settings* settings, Eina_Bool enable) 224{ 225 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 226 227 WKPreferencesSetJavaScriptCanOpenWindowsAutomatically(settings->preferences(), enable); 228 229 return true; 230} 231 232Eina_Bool ewk_settings_scripts_can_open_windows_get(const Ewk_Settings* settings) 233{ 234 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 235 236 return WKPreferencesGetJavaScriptCanOpenWindowsAutomatically(settings->preferences()); 237} 238 239Eina_Bool ewk_settings_local_storage_enabled_set(Ewk_Settings* settings, Eina_Bool enable) 240{ 241 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 242 243 WKPreferencesSetLocalStorageEnabled(settings->preferences(), enable); 244 245 return true; 246} 247 248Eina_Bool ewk_settings_local_storage_enabled_get(const Ewk_Settings* settings) 249{ 250 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 251 252 return WKPreferencesGetLocalStorageEnabled(settings->preferences()); 253} 254 255Eina_Bool ewk_settings_plugins_enabled_set(Ewk_Settings* settings, Eina_Bool enable) 256{ 257 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 258 259 WKPreferencesSetPluginsEnabled(settings->preferences(), enable); 260 261 return true; 262} 263 264Eina_Bool ewk_settings_plugins_enabled_get(const Ewk_Settings* settings) 265{ 266 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 267 268 return WKPreferencesGetPluginsEnabled(settings->preferences()); 269} 270 271Eina_Bool ewk_settings_default_font_size_set(Ewk_Settings* settings, int size) 272{ 273 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 274 275 WKPreferencesSetDefaultFontSize(settings->preferences(), size); 276 277 return true; 278} 279 280int ewk_settings_default_font_size_get(const Ewk_Settings* settings) 281{ 282 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, 0); 283 284 return WKPreferencesGetDefaultFontSize(settings->preferences()); 285} 286 287Eina_Bool ewk_settings_private_browsing_enabled_set(Ewk_Settings* settings, Eina_Bool enable) 288{ 289 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 290 291 WKPreferencesSetPrivateBrowsingEnabled(settings->preferences(), enable); 292 293 return true; 294} 295 296Eina_Bool ewk_settings_private_browsing_enabled_get(const Ewk_Settings* settings) 297{ 298 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 299 300 return WKPreferencesGetPrivateBrowsingEnabled(settings->preferences()); 301} 302 303Eina_Bool ewk_settings_text_autosizing_enabled_set(Ewk_Settings* settings, Eina_Bool enable) 304{ 305#if ENABLE(TEXT_AUTOSIZING) 306 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 307 308 WKPreferencesSetTextAutosizingEnabled(settings->preferences(), enable); 309 310 return true; 311#else 312 UNUSED_PARAM(settings); 313 UNUSED_PARAM(enable); 314 return false; 315#endif 316} 317 318Eina_Bool ewk_settings_text_autosizing_enabled_get(const Ewk_Settings* settings) 319{ 320#if ENABLE(TEXT_AUTOSIZING) 321 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 322 323 return WKPreferencesGetTextAutosizingEnabled(settings->preferences()); 324#else 325 UNUSED_PARAM(settings); 326 return false; 327#endif 328} 329 330Eina_Bool ewk_settings_web_security_enabled_set(Ewk_Settings* settings, Eina_Bool enable) 331{ 332 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 333 334 WKPreferencesSetWebSecurityEnabled(settings->preferences(), enable); 335 336 return true; 337} 338 339Eina_Bool ewk_settings_web_security_enabled_get(const Ewk_Settings* settings) 340{ 341 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 342 343 return WKPreferencesGetWebSecurityEnabled(settings->preferences()); 344} 345 346Eina_Bool ewk_settings_spatial_navigation_enabled_set(Ewk_Settings* settings, Eina_Bool enable) 347{ 348 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 349 350 WKPreferencesSetSpatialNavigationEnabled(settings->preferences(), enable); 351 352 return true; 353} 354 355Eina_Bool ewk_settings_spatial_navigation_enabled_get(const Ewk_Settings* settings) 356{ 357 EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false); 358 359 return WKPreferencesGetSpatialNavigationEnabled(settings->preferences()); 360} 361 362void EwkSettings::setDefaultTextEncodingName(const char* name) 363{ 364 if (m_defaultTextEncodingName == name) 365 return; 366 367 WKPreferencesSetDefaultTextEncodingName(preferences(), WKStringCreateWithUTF8CString(name)); 368 m_defaultTextEncodingName = name; 369} 370 371const char* EwkSettings::defaultTextEncodingName() const 372{ 373 return m_defaultTextEncodingName; 374} 375