JoshEngebretson пре 9 година
родитељ
комит
05715f4f04

+ 1 - 1
Source/Atomic/IPC/IPCBroker.cpp

@@ -62,7 +62,7 @@ void IPCBroker::ThreadFunction()
         }
 
         // sleep thread a bit so we don't gobble CPU
-        Time::Sleep(100);
+        Time::Sleep(10);
     }
 
     shouldRun_ = false;

+ 1 - 1
Source/Atomic/IPC/IPCWindows.cpp

@@ -220,7 +220,7 @@ void PipeWin::ReaderThread::ThreadFunction()
             readSize_ = (unsigned) bytesRead;
         }
 
-        Time::Sleep(50);
+        Time::Sleep(10);
 
     }
 }

+ 1 - 1
Source/Atomic/IPC/IPCWorker.cpp

@@ -117,7 +117,7 @@ void IPCWorker::ThreadFunction()
            break;
         }
 
-        Time::Sleep(100);
+        Time::Sleep(10);
     }
 
     shouldRun_ = false;

+ 9 - 0
Source/AtomicWebView/Internal/WebAppBrowser.cpp

@@ -110,10 +110,19 @@ void WebAppBrowser::OnRenderProcessThreadCreated(CefRefPtr<CefListValue> extra_i
 {
     // We're not on main thread here, we're on IO thread
     CefRefPtr<CefDictionaryValue> globalProps;
+
     if (CreateGlobalProperties(globalProps))
     {
         extra_info->SetDictionary(0, globalProps);
     }
+    else
+    {
+        extra_info->SetNull(0);
+    }
+
+    extra_info->SetString(1, WebBrowserHost::GetJSMessageQueryFunctionName().CString());
+    extra_info->SetString(2, WebBrowserHost::GetJSMessageQueryCancelFunctionName().CString());
+
 
 }
 

+ 21 - 4
Source/AtomicWebView/Internal/WebAppRenderer.cpp

@@ -37,6 +37,8 @@ class WebRenderDelegate : public WebAppRenderer::Delegate
 public:
 
     static CefRefPtr<CefDictionaryValue> globalProperties_;
+    static CefString jsMessageQueryFunctionName_;
+    static CefString jsMessageQueryCancelFunctionName_;
 
     WebRenderDelegate()
         : last_node_is_editable_(false)
@@ -48,8 +50,8 @@ public:
     {
         // Create the renderer-side router for query handling.
         CefMessageRouterConfig config;
-        config.js_query_function = "atomicQuery";
-        config.js_cancel_function = "atomicQueryCancel";
+        config.js_query_function = jsMessageQueryFunctionName_.length() ? jsMessageQueryFunctionName_ : "atomicQuery";
+        config.js_cancel_function = jsMessageQueryCancelFunctionName_.length() ? jsMessageQueryCancelFunctionName_ : "atomicQueryCancel";
 
         message_router_ = CefMessageRouterRendererSide::Create(config);
     }
@@ -59,10 +61,23 @@ public:
     {
         // extra info comes from void WebAppBrowser::OnRenderProcessThreadCreated(CefRefPtr<CefListValue> extra_info)
 
+        // index 0 is global properties
         if (extra_info->GetSize() > 0)
         {
-            // index 0 is global properties
-            globalProperties_ = extra_info->GetDictionary(0)->Copy(false);
+            if (extra_info->GetType(0) == CefValueType::VTYPE_DICTIONARY)
+                globalProperties_ = extra_info->GetDictionary(0)->Copy(false);            
+        }
+
+        // index 1 is name for jsMessageQuery function
+        if (extra_info->GetSize() > 1)
+        {            
+            jsMessageQueryFunctionName_ = extra_info->GetString(1);
+        }
+
+        // index 2 is name for jsMessageQueryCancel function
+        if (extra_info->GetSize() > 2)
+        {
+            jsMessageQueryCancelFunctionName_ = extra_info->GetString(2);
         }
 
     }
@@ -237,6 +252,8 @@ private:
 };
 
 CefRefPtr<CefDictionaryValue> WebRenderDelegate::globalProperties_;
+CefString WebRenderDelegate::jsMessageQueryFunctionName_;
+CefString WebRenderDelegate::jsMessageQueryCancelFunctionName_;
 
 
 WebAppRenderer::WebAppRenderer() {

+ 55 - 1
Source/AtomicWebView/WebBrowserHost.cpp

@@ -32,6 +32,7 @@
 #include <Atomic/Core/ProcessUtils.h>
 #include <Atomic/Core/CoreEvents.h>
 #include <Atomic/IO/Log.h>
+#include <Atomic/IO/FileSystem.h>
 
 #include <Atomic/Graphics/Graphics.h>
 
@@ -97,9 +98,16 @@ private:
 
 GlobalPropertyMap WebBrowserHost::globalProperties_;
 WeakPtr<WebBrowserHost> WebBrowserHost::instance_;
+String WebBrowserHost::rootCacheFolder_;
+String WebBrowserHost::cacheName_;
 String WebBrowserHost::userAgent_;
 String WebBrowserHost::productVersion_;
+String WebBrowserHost::jsMessageQueryFunctionName_ = "atomicQuery";
+String WebBrowserHost::jsMessageQueryCancelFunctionName_ = "atomicQueryCancel";
+
 int WebBrowserHost::debugPort_ = 3335;
+bool WebBrowserHost::webSecurity_ = true;
+
 
 WebBrowserHost::WebBrowserHost(Context* context) : Object (context)
 {
@@ -142,7 +150,25 @@ WebBrowserHost::WebBrowserHost(Context* context) : Object (context)
     {
         CefString(&settings.user_agent).FromASCII(userAgent_.CString());
     }
-    
+
+    FileSystem* fs = GetSubsystem<FileSystem>();
+
+    String fullPath;
+
+    // If we've specified the absolute path to a root cache folder, use it
+    if (rootCacheFolder_.Length() && cacheName_.Length())
+    {        
+        fullPath = rootCacheFolder_ + "/" + cacheName_;
+        CefString(&settings.cache_path).FromASCII(fullPath.CString());
+    }
+    else
+    {
+        fullPath = fs->GetAppPreferencesDir(cacheName_.CString(), "WebCache");
+    }
+
+
+    CefString(&settings.cache_path).FromASCII(fullPath.CString());
+
     settings.remote_debugging_port = debugPort_;
 
     d_ = new WebBrowserHostPrivate(this);
@@ -156,6 +182,9 @@ WebBrowserHost::WebBrowserHost(Context* context) : Object (context)
 
     RegisterWebSchemeHandlers(this);
 
+    // Ensure cookie manager is created
+    CefCookieManager::GetGlobalManager(nullptr);
+
     SubscribeToEvent(E_UPDATE, HANDLER(WebBrowserHost, HandleUpdate));
 
     instance_ = this;
@@ -165,6 +194,13 @@ WebBrowserHost::WebBrowserHost(Context* context) : Object (context)
 WebBrowserHost::~WebBrowserHost()
 {
     instance_ = 0;
+
+    // TODO: Better place for this?  If there are issues with cookies not persisting
+    // it is possible the async nature of this call could be a culprit
+    CefRefPtr<CefCookieManager> manager = CefCookieManager::GetGlobalManager(nullptr);
+    if (manager.get())
+        manager->FlushStore(nullptr);
+
     CefClearSchemeHandlerFactories();
     CefShutdown();
 }
@@ -201,4 +237,22 @@ void WebBrowserHost::HandleUpdate(StringHash eventType, VariantMap& eventData)
     CefDoMessageLoopWork();
 }
 
+void WebBrowserHost::ClearCookies(const String& url, const String& cookieName)
+{
+    CefRefPtr<CefCookieManager> manager = CefCookieManager::GetGlobalManager(nullptr);
+
+    if (!manager.get())
+        return;
+
+    CefString cefUrl;
+    cefUrl.FromASCII(url.CString());
+
+    CefString cefCookieName;
+    cefCookieName.FromASCII(cookieName.CString());
+
+    manager->DeleteCookies(cefUrl, cefCookieName, nullptr);
+
+}
+
+
 }

+ 41 - 1
Source/AtomicWebView/WebBrowserHost.h

@@ -43,6 +43,8 @@ public:
     /// Destruct.
     virtual ~WebBrowserHost();
 
+    void ClearCookies(const String& url = String::EMPTY, const String& cookieName = String::EMPTY);
+
     /// Set global property object values, available as read only on page
     static void SetGlobalBoolProperty(const String& globalVar, const String& property, bool value);
     static void SetGlobalStringProperty(const String& globalVar, const String& property, const String& value);
@@ -50,9 +52,14 @@ public:
 
     static const GlobalPropertyMap& GetGlobalProperties() { return globalProperties_; }
 
-
     // Configuration settings that must be set before creating WebBrowserHost subsystem
 
+    /// Set the absolute root path for the cache, this is combined with the cache name to generate the full cache path
+    static void SetRootCacheFolder(const String& rootCacheFolder) { rootCacheFolder_ = rootCacheFolder; }
+
+    /// Set the cache name which is combined with the root cache folder to generate an absolute path to the browser cache
+    static void SetCacheName(const String& cacheName) { cacheName_ = cacheName; }
+
     /// Set value that will be returned as the User-Agent HTTP header.
     static void SetUserAgent(const String& userAgent) { userAgent_ = userAgent; }
 
@@ -62,12 +69,36 @@ public:
     /// Set to a value between 1024 and 65535 to enable remote debugging on the specified port
     static void SetDebugPort(int debugPort) { debugPort_ = debugPort; }
 
+    /// Set whether web security is enabled
+    static void SetWebSecurity(bool enabled) { webSecurity_ = enabled; }
+
+    /// Set the name of the function used for JavaScript message queries
+    static void SetJSMessageQueryFunctionName(const String& name) { jsMessageQueryFunctionName_ = name; }
+
+    /// Set the name of the function used to cancel JavaScript message queries
+    static void SetJSMessageQueryCancelFunctionName(const String& name) { jsMessageQueryCancelFunctionName_ = name; }
+
+    /// Get the absolute root path for the cache, this is combined with the cache name to generate the full cache path
+    static const String& GetRootCacheFolder() { return rootCacheFolder_; }
+
+    /// Get the cache name which is combined with the root cache folder to generate an absolute path to the browser cache
+    static const String& GetCacheName() { return cacheName_; }
+
     /// Get User-Agent of the HTTP header. If empty the default User-Agent string will be used
     static const String& GetUserAgent() { return userAgent_; }
 
     /// Get value that will be inserted as the product portion of the default User-Agent string.  If empty the Chromium product version will be used      
     static const String& GetProductVersion() { return productVersion_; }
 
+    /// Get whether web security is enabled
+    static bool GetWebSecurity() { return webSecurity_; }
+
+    /// Get the name of the function used for JavaScript message queries
+    static const String& GetJSMessageQueryFunctionName() { return jsMessageQueryFunctionName_; }
+
+    /// Get the name of the function used to cancel JavaScript message queries
+    static const String& GetJSMessageQueryCancelFunctionName() { return jsMessageQueryCancelFunctionName_; }
+
 
 private:
 
@@ -84,7 +115,16 @@ private:
     // configuration settings that must be set before WebBrowserHost subsystem is created
     static String userAgent_;
     static String productVersion_;
+
+    static String rootCacheFolder_;
+    static String cacheName_;
+
+    static String jsMessageQueryFunctionName_;
+    static String jsMessageQueryCancelFunctionName_;
+
     static int debugPort_;
+    static bool webSecurity_;
+
 
 };
 

+ 3 - 2
Source/AtomicWebView/WebClient.cpp

@@ -77,8 +77,8 @@ public:
         webBrowserHost_ = webClient_->GetSubsystem<WebBrowserHost>();
 
         CefMessageRouterConfig config;
-        config.js_query_function = "atomicQuery";
-        config.js_cancel_function = "atomicQueryCancel";
+        config.js_query_function = WebBrowserHost::GetJSMessageQueryFunctionName().CString();
+        config.js_cancel_function = WebBrowserHost::GetJSMessageQueryCancelFunctionName().CString();
         browserSideRouter_ = CefMessageRouterBrowserSide::Create(config);
 
     }
@@ -345,6 +345,7 @@ public:
         browserSettings.webgl = STATE_ENABLED;
         browserSettings.file_access_from_file_urls = STATE_ENABLED;
         browserSettings.universal_access_from_file_urls = STATE_ENABLED;
+        browserSettings.web_security = WebBrowserHost::GetWebSecurity() ? STATE_ENABLED : STATE_DISABLED;
 
         windowInfo.width = width;
         windowInfo.height = height;