bool ProfileManager::has_user_ack(std::string profilename, FB::DOM::WindowPtr window) {
    
    try {
        if (window && window->getJSObject()->HasProperty("location")) {
            // Create a reference to the browswer console object
            FB::JSObjectPtr obj = window->getProperty<FB::JSObjectPtr>("location");
            
            std::string origin = obj->GetProperty("origin").convert_cast<std::string>();
            std::string href = obj->GetProperty("href").convert_cast<std::string>();
            
            // Return the result of authorized domain entry, if found
            std::map<std::string, bool>::iterator it = authorized_domains.find(origin);
            if (it != authorized_domains.end())
                return it->second;
            
            // Ask user
            FB::variant ack_result;
            std::stringstream ss;
            ss << "The following page requests access to the BroadMask profile ";
            ss << "'" << profilename << "' :" << endl;
            ss << href << endl << endl;
            ss << "Do you want to authorize the domain?";
            ack_result = window->getJSObject()->Invoke("confirm", FB::variant_list_of(ss.str()));
            
            bool ack = ack_result.convert_cast<bool>();
            
            if (ack == true) {
                authorized_domains.insert(std::pair<std::string, bool>(origin, true));
                return true;
            } else {
                return false;
            }
            
        }
    } catch (exception& e) {
        cerr << "[BroadMask ProfileManager] Error getting user ack: " << e.what() << endl;
        return false;
    }
    
    return false;
}
예제 #2
0
void FB::BrowserHost::AsyncHtmlLog(void *logReq)
{
    FB::AsyncLogRequest *req = (FB::AsyncLogRequest*)logReq;
    try {
        FB::DOM::WindowPtr window = req->m_host->getDOMWindow();

        if (window->getJSObject()->HasProperty("console")) {
            FB::JSObjectPtr obj = window->getProperty<FB::JSObjectPtr>("console");
            printf("Logging: %s\n", req->m_msg.c_str());
            obj->Invoke("log", FB::variant_list_of(req->m_msg));
        }
    } catch (const std::exception &) {
        // printf("Exception: %s\n", e.what());
        // Fail silently; logging should not require success.
        FBLOG_TRACE("BrowserHost", "Logging to browser console failed");
        return;
    }
    delete req;
}