コード例 #1
0
    static void MergePyGlobalsWithContext(PyObject* globals, KObjectRef context)
    {
		// Avoid compiler warnings
		PyObject *items = PyObject_CallMethod(globals, (char*) "items", NULL);
		if (items == NULL)
			return;

		PyObject *iterator = PyObject_GetIter(items);
		if (iterator == NULL)
			return;

		PyObject *item;
		while ((item = PyIter_Next(iterator)))
		{
			PyObject* k = PyTuple_GetItem(item, 0);
			PyObject* v = PyTuple_GetItem(item, 1);
			std::string sk = PythonUtils::ToString(k);
			if (sk.find("__") != 0)
			{
				KValueRef newValue = PythonUtils::ToKrollValue(v);
				KValueRef existingValue = context->Get(sk.c_str());
				if (!newValue->Equals(existingValue))
				{
					context->Set(sk.c_str(), newValue);
				}
			}
			Py_DECREF(item);
		}
    }
コード例 #2
0
ファイル: ruby_module.cpp プロジェクト: mital/kroll
	void RubyModule::Stop()
	{
		KObjectRef global = this->host->GetGlobalObject();
		global->Set("Ruby", Value::Undefined);
		Script::GetInstance()->RemoveScriptEvaluator(this->binding);
		this->binding = NULL;
		RubyModule::instance_ = NULL;

		ruby_cleanup(0);
	}
コード例 #3
0
ファイル: php_module.cpp プロジェクト: toisoftware/TideSDK
void PHPModule::InitializeBinding()
{
    PHPModule::mimeType = SG(default_mimetype);

    KObjectRef global = this->host->GetGlobalObject();
    this->binding = new PHPEvaluator();
    global->Set("PHP", Value::NewObject(this->binding));
    Script::GetInstance()->AddScriptEvaluator(this->binding);

    zval *titaniumValue = PHPUtils::ToPHPValue(Value::NewObject(global));
    ZEND_SET_SYMBOL(&EG(symbol_table), PRODUCT_NAME, titaniumValue);
}
コード例 #4
0
ファイル: process.cpp プロジェクト: Val9/titanium_desktop
	KObjectRef Process::CloneEnvironment()
	{
		SharedStringList properties = environment->GetPropertyNames();
		KObjectRef clonedEnvironment = new StaticBoundObject();
		for (size_t i = 0; i < properties->size(); i++)
		{
			std::string property = *properties->at(i);
			std::string value = environment->Get(property.c_str())->ToString();
			clonedEnvironment->Set(property.c_str(), Value::NewString(value.c_str()));
		}
		return clonedEnvironment;
	}
コード例 #5
0
ファイル: ruby_module.cpp プロジェクト: mital/kroll
	void RubyModule::InitializeBinding()
	{
		// Expose the Ruby evaluator into Kroll
		KObjectRef global = this->host->GetGlobalObject();
		this->binding = new RubyEvaluator();
		global->Set("Ruby", Value::NewObject(binding));
		Script::GetInstance()->AddScriptEvaluator(this->binding);
		
		// Bind the API global constant
		VALUE ruby_api_val = RubyUtils::KObjectToRubyValue(Value::NewObject(global));
		rb_define_global_const(PRODUCT_NAME, ruby_api_val);
	}
コード例 #6
0
ファイル: php_module.cpp プロジェクト: toisoftware/TideSDK
void PHPModule::Stop()
{
    PHPModule::instance_ = NULL;

    KObjectRef global = this->host->GetGlobalObject();
    Script::GetInstance()->RemoveScriptEvaluator(this->binding);
    global->Set("PHP", Value::Undefined);
    this->binding->Set("evaluate", Value::Undefined);

    this->binding = 0;
    PHPModule::instance_ = 0;

    php_embed_shutdown(TSRMLS_C);
}
コード例 #7
0
 std::string RubyEvaluator::GetContextId(KObjectRef global)
 {
     static int nextId = 0;
     int cid = 0;
     KValueRef idv = global->Get("__ruby_module_id__");
     if (idv->IsUndefined())
     {
         cid = nextId++;
         global->Set("__ruby_module_id__", Value::NewInt(cid));
     }
     else
     {
         cid = idv->ToInt();
     }
     return std::string("$windowProc") + KList::IntToChars(cid);
 }
コード例 #8
0
    static VALUE m_missing(int argc, VALUE* argv, VALUE self)
    {
        bool assignment = false;

        if (global_object.isNull())
            return Qnil;

        // store the method name and arguments in separate variables
        VALUE method_name, args;
        rb_scan_args(argc, argv, "1*", &method_name, &args);
        char* name = strdup(rb_id2name(SYM2ID(method_name)));

        // Check if this is an assignment
        if (name[strlen(name) - 1] == '=')
        {
            name[strlen(name) - 1] = '\0';
            assignment = true;
        }
        // If we can't find this property perhaps we should return
        // the same property name except capitalized.
        KValueRef v = global_object->Get(name);
        if (v->IsUndefined())
        {
            name[0] = toupper(name[0]);
            v = global_object->Get(name);
        }
        // Okay, maybe not
        if (v->IsUndefined())
            name[0] = tolower(name[0]);

        VALUE rval;
        if (assignment) // Assignment
        {
            rval = rb_ary_entry(args, 0);
            KValueRef val = RubyUtils::ToKrollValue(rval);
            global_object->Set(name, val);
        }
        else if (v->IsMethod()) // Method call
        {
            rval = RubyUtils::GenericKMethodCall(v->ToMethod(), args);
        }
        else // Plain old access
        {
            rval = RubyUtils::ToRubyValue(v);
        }
        return rval;
    }
コード例 #9
0
	UIBinding::UIBinding(Host *host) :
		KAccessorObject("UI"),
		host(host)
	{
		instance = this;

		// @tiproperty[Number, UI.CENTERED, since=0.6] The CENTERED event constant
		this->Set("CENTERED", Value::NewInt(UIBinding::CENTERED));

		/**
		 * @tiapi(method=True,name=UI.createMenu,since=0.6)
		 * @tiapi Create a new menu
		 * @tiresult[UI.Menu] A new menu
		 */
		this->SetMethod("createMenu", &UIBinding::_CreateMenu);

		/**
		 * @tiapi(method=True,name=UI.createMenuItem,since=0.6)
		 * @tiapi Create a new menu item.
		 * @tiarg[String, label] The label for this menu item
		 * @tiarg[Function, eventListener, optional=True] An event listener for this menu item
		 * @tiarg[String, iconURL, optional=True] A URL to an icon to use for this menu item
		 * @tiresult[UI.MenuItem] A new menu item
		 */
		this->SetMethod("createMenuItem", &UIBinding::_CreateMenuItem);

		/**
		 * @tiapi(method=True,name=UI.createCheckMenuItem,since=0.6)
		 * @tiapi Create a new CheckMenuItem object.
		 * @tiarg[String, label] The label for this menu item
		 * @tiarg[Function, eventListener, optional=True] An event listener for this menu item
		 * @tiresult[UI.CheckMenuItem] The new CheckMenuItem object
		 */
		this->SetMethod("createCheckMenuItem", &UIBinding::_CreateCheckMenuItem);

		/**
		 * @tiapi(method=True,name=UI.createSeperatorMenuItem,since=0.6)
		 * @tiapi Create a new separator menu item.
		 * @tiresult[UI.SeparatorMenuItem] A new separator menu item
		 */
		this->SetMethod("createSeparatorMenuItem", &UIBinding::_CreateSeparatorMenuItem);

		/**
		 * @tiapi(method=True,name=UI.setMenu,since=0.2) Set a menu for the application
		 * @tiarg[UI.Menu|null, menu] A Menu object to use as the menu or null to unset the menu
		 */
		this->SetMethod("setMenu", &UIBinding::_SetMenu);

		/**
		 * @tiapi(method=True,name=UI.getMenu,since=0.2) Returns the application's main MenuItem
		 * @tiresult[UI.Menu|null] The application's main menu
		 */
		this->SetMethod("getMenu", &UIBinding::_GetMenu);

		/**
		 * @tiapi(method=True,name=UI.setContextMenu,since=0.2) Set the application's context menu
		 * @tiarg(for=UI.setContextMenu,type=UI.Menu|null,name=menu) a MenuItem object or null to unset
		 */
		this->SetMethod("setContextMenu", &UIBinding::_SetContextMenu);

		/**
		 * @tiapi(method=True,name=UI.getContextMenu,since=0.2) Returns the application context menu
		 * @tiresult(for=UI.getContextMenu,type=UI.Menu|null) the application's context MenuItem object
		 */
		this->SetMethod("getContextMenu", &UIBinding::_GetContextMenu);

		/**
		 * @tiapi(method=True,name=UI.setIcon,since=0.2) Set the application's icon
		 * @tiarg(for=UI.setIcon,type=String,name=menu) path to the icon
		 */
		this->SetMethod("setIcon", &UIBinding::_SetIcon);

		/**
		 * @tiapi(method=True,name=UI.addTray,since=0.2)
		 * @tiapi Create and add a tray icon
		 * @tiarg[String, iconURL] URL to the icon to use for this tray item
		 * @tiarg[Function, eventListener, optional=True] Event listener to add for this item
		 * @tiresult(for=UI.addTray,type=UI.Tray|null) the application's Tray icon object
		 */
		this->SetMethod("addTray", &UIBinding::_AddTray);

		/**
		 * @tiapi(method=True,name=UI.clearTray,since=0.2)
		 * @tiapi Empty the tray of all this application's tray items
		 */
		this->SetMethod("clearTray", &UIBinding::_ClearTray);

		/**
		 * @tiapi(method=True,name=UI.setDockIcon,since=0.2) Set the dock icon
		 * @tiarg(for=UI.setDockIcon,type=String,name=icon) path to the icon
		 */
		this->SetMethod("setDockIcon", &UIBinding::_SetDockIcon);

		/**
		 * @tiapi(method=True,name=UI.setDockMenu,since=0.2) Set the dock menu
		 * @tiarg(for=UI.setDockMenu,type=UI.Menu,name=menu) The new menu for the dock
		 */
		this->SetMethod("setDockMenu", &UIBinding::_SetDockMenu);

		/**
		 * @tiapi(method=True,name=UI.setBadge,since=0.2,platforms=osx)
		 * @tiapi Set the application icon's badge text.
		 * @tiarg[String, text] The new badge text.
		 */
		this->SetMethod("setBadge", &UIBinding::_SetBadge);

		/**
		 * @tiapi(method=True,name=UI.setBadgeImage,since=0.2,platforms=osx)
		 * @tiapi Set the application icon's badge image.
		 * @tiarg[String, imageURL] URL to the new badge image.
		 */
		this->SetMethod("setBadgeImage", &UIBinding::_SetBadgeImage);

		/**
		 * @tiapi(method=True,name=UI.getIdleTime,since=0.2)
		 * @tiapi Returns the user's idle time (for the desktop, not just the application)
		 * @tiresult(for=UI.getIdleTime,type=Number) Number of milliseconds of idle time.
		 */
		this->SetMethod("getIdleTime", &UIBinding::_GetIdleTime);

		/**
		 * @tiapi(method=True,name=UI.getOpenWindows,version=0.4) Returns the list of currently open windows
		 * @tiresult(for=UI.getOpenWindows,type=Array<UI.UserWindow>) the list of open windows
		 */
		/**
		 * @tiapi(method=True,name=UI.getWindows,version=0.4) Returns the list of currently open windows
		 * @tiresult(for=UI.getWindows,type=Array<UI.UserWindow>) the list of open windows
		 */
		this->SetMethod("getOpenWindows", &UIBinding::_GetOpenWindows);
		this->SetMethod("getWindows", &UIBinding::_GetOpenWindows);

		/**
		 * @tiapi(method=True,name=UI.getMainWindow,since=0.6)
		 * @tiapi Return the application's main window
		 * @tiresult[UI.UserWindow] The main window for this application
		 */
		this->SetMethod("getMainWindow", &UIBinding::_GetMainWindow);

		this->Set("Clipboard", Value::NewObject(new Clipboard()));

		KObjectRef global = host->GetGlobalObject();
		KValueRef ui_binding_val = Value::NewObject(this);
		global->Set("UI", ui_binding_val);

		Logger::AddLoggerCallback(&UIBinding::Log);
	}
コード例 #10
0
void Win32UserWindow::InitWebKit()
{
	HRESULT hr = WebKitCreateInstance(CLSID_WebView, 0, IID_IWebView,
		(void**) &(this->webView));
	if (FAILED(hr))
		HandleHResultError("Error creating WebKitWebView", hr, true);

	// Set the custom user agent for Titanium
	const char *version = host->GetGlobalObject()->Get("version")->ToString();
	char userAgent[128];
	//TI-303 we need to add safari UA to our UA to resolve broken
	//sites that look at Safari and not WebKit for UA
	sprintf(userAgent, "Version/4.0 Safari/528.16 %s/%s", PRODUCT_NAME, version);
	_bstr_t ua(userAgent);
	webView->setApplicationNameForUserAgent(ua.copy());

	// place our user agent string in the global so we can later use it
	KObjectRef global = host->GetGlobalObject();
	if (global->Get("userAgent")->IsUndefined())
	{
		_bstr_t uaURL("http://titaniumapp.com");
		BSTR uaResp;
		webView->userAgentForURL(uaURL.copy(), &uaResp);
		std::string uaStr = _bstr_t(uaResp);
		global->Set("userAgent", Value::NewString(uaStr.c_str()));
	}

	frameLoadDelegate = new Win32WebKitFrameLoadDelegate(this);
	hr = webView->setFrameLoadDelegate(frameLoadDelegate);
	if (FAILED(hr))
		HandleHResultError("Error setting FrameLoadDelegate", hr, true);

	uiDelegate = new Win32WebKitUIDelegate(this);
	hr = webView->setUIDelegate(uiDelegate);
	if (FAILED(hr))
		HandleHResultError("Error setting UIDelegate", hr, true);

	policyDelegate = new Win32WebKitPolicyDelegate(this);
	hr = webView->setPolicyDelegate(policyDelegate);
	if (FAILED(hr))
		HandleHResultError("Error setting PolicyDelegate", hr, true);

	hr = webView->setHostWindow((OLE_HANDLE) windowHandle);
	if (FAILED(hr))
		HandleHResultError("Error setting host window", hr, true);

	RECT clientRect;
	GetClientRect(windowHandle, &clientRect);
	hr = webView->initWithFrame(clientRect, 0, 0);
	if (FAILED(hr))
		HandleHResultError("Could not intialize WebView with frame", hr, true);

	IWebPreferences *prefs = NULL;
	hr = WebKitCreateInstance(CLSID_WebPreferences, 0, IID_IWebPreferences,
		(void**) &prefs);
	if (FAILED(hr) || !prefs)
		HandleHResultError("Error getting IWebPreferences", hr, true);

	std::string appid(AppConfig::Instance()->GetAppID());
	_bstr_t pi(appid.c_str());
	prefs->initWithIdentifier(pi.copy(), &prefs);
	prefs->setCacheModel(WebCacheModelDocumentBrowser);
	prefs->setPlugInsEnabled(true);
	prefs->setJavaEnabled(true);
	prefs->setJavaScriptEnabled(true);
	prefs->setJavaScriptCanOpenWindowsAutomatically(true);
	prefs->setDOMPasteAllowed(true);

	IWebPreferencesPrivate* privatePrefs = NULL;
	hr = prefs->QueryInterface(IID_IWebPreferencesPrivate, (void**) &privatePrefs);
	if (FAILED(hr) || !privatePrefs)
		HandleHResultError("Error getting IWebPreferencesPrivate", hr, true);

	privatePrefs->setDeveloperExtrasEnabled(host->IsDebugMode());
	privatePrefs->setDatabasesEnabled(true);
	privatePrefs->setLocalStorageEnabled(true);
	privatePrefs->setOfflineWebApplicationCacheEnabled(true);
	privatePrefs->setAllowUniversalAccessFromFileURLs(true);
	_bstr_t dbPath(FileUtils::GetApplicationDataDirectory(appid).c_str());
	privatePrefs->setLocalStorageDatabasePath(dbPath.copy());
	privatePrefs->Release();

	webView->setPreferences(prefs);
	prefs->Release();

	// allow app:// and ti:// to run with local permissions (cross-domain ajax,etc)
	_bstr_t appProto("app");
	webView->registerURLSchemeAsLocal(appProto.copy());

	_bstr_t tiProto("ti");
	webView->registerURLSchemeAsLocal(tiProto.copy());

	IWebViewPrivate *webViewPrivate;
	hr = webView->QueryInterface(IID_IWebViewPrivate, (void**) &webViewPrivate);
	if (FAILED(hr))
		HandleHResultError("Error getting IWebViewPrivate", hr);

	// Get the WebView's HWND
	hr = webViewPrivate->viewWindow((OLE_HANDLE*) &viewWindowHandle);
	if (FAILED(hr))
		HandleHResultError("Error getting WebView HWND", hr);

	// Get the WebView's WebInspector
	hr = webViewPrivate->inspector(&webInspector);
	if (FAILED(hr) || !webInspector)
		HandleHResultError("Error getting WebInspector HWND", hr);

	webViewPrivate->Release();

	_bstr_t inspector_url("ti://runtime/WebKit.resources/inspector/inspector.html");
	webInspector->setInspectorURL(inspector_url.copy());

	hr = webView->mainFrame(&mainFrame);
	if (FAILED(hr) || !webInspector)
		HandleHResultError("Error getting WebView main frame", hr);
}