void LayoutTestController::setUserStyleSheetEnabled(bool flag) { userStyleSheetEnabled = flag; if (flag && userStyleSheet) getWebView()->setCustomUserAgent(userStyleSheet); else getWebView()->setCustomUserAgent(""); }
/** * Enable JavaScript to C++ communication. */ void HybridMoblet::enableWebViewMessages() { if (NULL == mWebViewListener) { mWebViewListener = new HybridMoblet_WebViewListener(this); getWebView()->addWebViewListener(mWebViewListener); getWebView()->enableWebViewMessages(); } }
/** * Disable JavaScript to C++ communication. */ void HybridMoblet::disableWebViewMessages() { if (NULL != mWebViewListener) { getWebView()->removeWebViewListener(mWebViewListener); getWebView()->disableWebViewMessages(); delete mWebViewListener; mWebViewListener = NULL; } }
/** * Display a NativeUI page. * @param url Url of NativeUI page to open. */ void HybridMoblet::showNativeUI(const MAUtil::String& url) { // Extract files system and perform other initialisation. initialize(); // In a NativeUI app we hide the main WebView and use NativeUI // to display widgets. getWebView()->setVisible(false); // Open the page. getWebView()->openURL(url); }
/** * Display a page in the WebView of this moblet. * @param url Url of page to open. */ void HybridMoblet::showPage(const MAUtil::String& url) { // Extract files system and perform other initialisation. initialize(); // Make the main WebView visible. getWebView()->setVisible(true); // Show the WebView screen. showWebView(); // Open the page. getWebView()->openURL(url); }
// Application controller static callback. static JSValueRef fillConfigurationFromFile(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception, ConfigFileType type) { if (argumentCount < 1) return JSValueMakeUndefined(context); JSRetainPtr<JSStringRef> fileNameJSString(Adopt, JSValueToStringCopy(context, arguments[0], exception)); //ASSERT(!*exception); ApplicationTestController* controller = static_cast<ApplicationTestController*>(JSObjectGetPrivate(thisObject)); char* relativeURL = JSStringCopyUTF8CString(fileNameJSString.get()); if (strncmp("http://", relativeURL, 7) != 0 && strncmp("https://", relativeURL, 8) != 0 && strncmp("data:", relativeURL, 5) != 0 && strncmp("file://", relativeURL, 7) != 0) { WebView* webView = getWebView(); string mainFrameURL = webView->mainFrameURL(); size_t pos = mainFrameURL.find_last_of("/"); string absoluteURL = mainFrameURL.substr(0, pos + 1); absoluteURL += relativeURL; size_t pos2 = absoluteURL.find_last_of("?"); if (pos2 == absoluteURL.size() - 1) absoluteURL = absoluteURL.substr(0, pos2); controller->fillConfigurationFromFile((char*)absoluteURL.c_str(), type); return JSValueMakeUndefined(context); } controller->fillConfigurationFromFile(relativeURL, type); return JSValueMakeUndefined(context); }
bool ScriptItem::invoke() const { char* scriptString = JSStringCopyUTF8CString(m_script.get()); getWebView()->executeScript(scriptString); free(scriptString); return true; }
/** * Handles HOOK_INVOKED events for WebViews in the app. * This code enables WebViews to send messages to each other. * * The only thing that work reliable from other WebViews than * the main one, are CallJS and calls that do not return anything, * like mosync.app.sendToBackground(). * * Apps are supposed to use the main WebView to for accessing the * fulll Wormhole JS API, and only use mosync.nativeui.callJS() * from other WebViews. This way, the main WebView becomes a * mediator, which is a good design because native access is * restricted to one point. */ void HybridMoblet::customEvent(const MAEvent& event) { if (EVENT_TYPE_WIDGET == event.type) { MAWidgetEventData* widgetEventData = (MAWidgetEventData*)event.data; MAWidgetHandle webViewHandle = widgetEventData->widgetHandle; // If target object is the main WebView, then we just return // because this is handled by the NativeUI library event processing, // which will invoke HybridMoblet::handleWebViewMessage(). if (getWebView()->getWidgetHandle() == webViewHandle) { return; } // Process HOOK_INVOKED messages. This makes CallJS messages work. if (MAW_EVENT_WEB_VIEW_HOOK_INVOKED == widgetEventData->eventType) { // We don't care about the hook type. // int hookType = widgetEventData->hookType; MAHandle data = widgetEventData->urlData; handleWebViewMessage(webViewHandle, data); // Free data. maDestroyPlaceholder(data); } } }
/** * Display the WebView. */ void WebAppMoblet::showWebView() { // Make sure the WebView is created. getWebView(); // Show the screen that contains the WebView. mScreen->show(); }
void AutofillPopupMenuClient::popupDidHide() { WebViewImpl* webView = getWebView(); if (!webView) return; webView->autofillPopupDidHide(); webView->autofillClient()->didClearAutofillSelection(WebNode(getTextField())); }
bool LoadItem::invoke() const { char* targetString = JSStringCopyUTF8CString(m_target.get()); WebFrame* targetFrame; if (!strlen(targetString)) targetFrame = getWebView()->mainFrame(); else targetFrame = getWebView()->mainFrame()->findFrameNamed(targetString); free(targetString); char* urlString = JSStringCopyUTF8CString(m_url.get()); targetFrame->loadURL(urlString); // WebKitNetworkRequest* request = webkit_network_request_new(urlString); free(urlString); // webkit_web_frame_load_request(targetFrame, request); // g_object_unref(request); return true; }
void AutofillPopupMenuClient::selectionChanged(unsigned listIndex, bool fireEvents) { WebViewImpl* webView = getWebView(); if (!webView) return; ASSERT_WITH_SECURITY_IMPLICATION(listIndex < m_names.size()); webView->autofillClient()->didSelectAutofillSuggestion(WebNode(getTextField()), m_names[listIndex], m_labels[listIndex], m_itemIDs[listIndex]); }
void AutofillPopupMenuClient::selectionChanged(unsigned listIndex, bool fireEvents) { WebViewImpl* webView = getWebView(); if (!webView) return; if (m_separatorIndex != -1 && listIndex > static_cast<unsigned>(m_separatorIndex)) --listIndex; ASSERT(listIndex < m_names.size()); webView->autofillClient()->didSelectAutofillSuggestion(WebNode(getTextField()), m_names[listIndex], m_labels[listIndex], m_uniqueIDs[listIndex]); }
/** * Display a page in the WebView of this moblet. * @param url Url of page to open. */ void WebAppMoblet::showPage(const MAUtil::String& url) { // Since extractFileSystem() is moved out of the constructor // into application code, make sure it has been called before // displaying the page. This makes the code updates backwards // compatible with old application code. if (!mFileSystemIsExtracted) { extractFileSystem(); } // Make sure the WebView is displayed. // It should do no harm to call this method multiple times. showWebView(); // Open the page. getWebView()->openURL(url); }
void LayoutTestController::clearBackForwardList() { WebView* webView = getWebView(); WebBackForwardList* backForwardList = webView->backForwardList(); if (!backForwardList) return; WebHistoryItem* item = backForwardList->currentItem(); if (item) return; // We clear the history by setting the back/forward list's capacity to 0 // then restoring it back and adding back the current item. int capacity = backForwardList->capacity(); backForwardList->setCapacity(0); backForwardList->setCapacity(capacity); backForwardList->addItem(item); backForwardList->goToItem(item); }
static JSValueRef setPermissionsForMainApplication(JSContextRef context, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { #if ENABLE(DAE_APPLICATION) if (argumentCount < 1) return JSValueMakeUndefined(context); JSRetainPtr<JSStringRef> permissions(Adopt, JSValueToStringCopy(context, arguments[0], exception)); //ASSERT(!*exception); #if ENABLE(DAE_PERMISSION) // Clear permissions. SharedPtr<WebApplication> webApp = webAppMgr().application(getWebView()); if (webApp) { webApp->setPermissions(0); webApp->setPermissions(JSStringCopyUTF8CString(permissions.get())); } #endif #endif return JSValueMakeUndefined(context); }
void AutofillPopupMenuClient::valueChanged(unsigned listIndex, bool fireEvents) { WebViewImpl* webView = getWebView(); if (!webView) return; ASSERT_WITH_SECURITY_IMPLICATION(listIndex < m_names.size()); if (m_useLegacyBehavior) { for (size_t i = 0; i < m_itemIDs.size(); ++i) { if (m_itemIDs[i] == WebAutofillClient::MenuItemIDSeparator) { if (listIndex > i) listIndex--; break; } } } webView->autofillClient()->didAcceptAutofillSuggestion(WebNode(getTextField()), m_names[listIndex], m_labels[listIndex], m_itemIDs[listIndex], listIndex); }
void AutofillPopupMenuClient::selectionCleared() { WebViewImpl* webView = getWebView(); if (webView) webView->autofillClient()->didClearAutofillSelection(WebNode(getTextField())); }
/** * Run JavaScript code in the main WebView * of this moblet. * @param script JavaScript code to evaluate. */ void HybridMoblet::callJS(const MAUtil::String& script) { getWebView()->callJS(script); }
bool ReloadItem::invoke() const { getWebView()->mainFrame()->reload(); return true; }
bool BackForwardItem::invoke() const { getWebView()->goBackOrForward(m_howFar); return true; }
unsigned LayoutTestController::numberOfActiveAnimations() const { return getWebView()->mainFrame()->numberOfActiveAnimations(); }
bool LayoutTestController::pauseTransitionAtTimeOnElementWithId(JSStringRef propertyName, double time, JSStringRef elementId) { char* name = JSStringCopyUTF8CString(propertyName); char* element = JSStringCopyUTF8CString(elementId); return getWebView()->mainFrame()->pauseTransition(name, time, element); }
//------------------------------------------------------------------------------------- void WebUIApp::go(void) { mResourcesCfg = "resources.cfg"; #ifdef _DEBUG mPluginsCfg = "plugins_d.cfg"; #else mPluginsCfg = "plugins.cfg"; #endif // construct Ogre::Root mRoot = OGRE_NEW Ogre::Root(mPluginsCfg); mWebPanelFactory = OGRE_NEW WebPanelOverlayElementFactory(); Ogre::OverlayManager::getSingleton().addOverlayElementFactory(mWebPanelFactory); //------------------------------------------------------------------------------------- // setup resources // Load resource paths from config file Ogre::ConfigFile cf; cf.load(mResourcesCfg); // Go through all sections & settings in the file Ogre::ConfigFile::SectionIterator seci = cf.getSectionIterator(); Ogre::String secName, typeName, archName; while (seci.hasMoreElements()) { secName = seci.peekNextKey(); Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext(); Ogre::ConfigFile::SettingsMultiMap::iterator i; for (i = settings->begin(); i != settings->end(); ++i) { typeName = i->first; archName = i->second; Ogre::ResourceGroupManager::getSingleton().addResourceLocation( archName, typeName, secName, true); } } //------------------------------------------------------------------------------------- // configure // Show the configuration dialog and initialise the system // You can skip this and use root.restoreConfig() to load configuration // settings if you were sure there are valid ones saved in ogre.cfg if(mRoot->showConfigDialog()) { ///WebKit does not support single-precision float Ogre::ConfigOptionMap& options = mRoot->getRenderSystem()->getConfigOptions(); options["Floating-point mode"].currentValue = "Consistent"; int w = atoi(options["Video Mode"].currentValue.c_str()); if (w < 1024) { if (strchr(options["Video Mode"].currentValue.c_str(), '@')) options["Video Mode"].currentValue = "1024 x 768 @ 32-bit colour"; else options["Video Mode"].currentValue = "1024 x 768"; } // If returned true, user clicked OK so initialise // Here we choose to let the system create a default rendering window by passing 'true' mWindow = mRoot->initialise(true, "OgreWebKit"); if (!mRoot) return; } else { return; } //------------------------------------------------------------------------------------- // choose scenemanager // Get the SceneManager, in this case a generic one mSceneMgr = mRoot->createSceneManager(Ogre::ST_GENERIC); //------------------------------------------------------------------------------------- // create camera // Create the camera mCamera = mSceneMgr->createCamera("PlayerCam"); // Position it at 500 in Z direction mCamera->setPosition(Ogre::Vector3(0,0,80)); // Look back along -Z mCamera->lookAt(Ogre::Vector3(0,0,-300)); mCamera->setNearClipDistance(5); mCameraMan = new OgreBites::SdkCameraMan(mCamera); //------------------------------------------------------------------------------------- // create viewports // Create one viewport, entire window Ogre::Viewport* vp = mWindow->addViewport(mCamera); vp->setBackgroundColour(Ogre::ColourValue(0,0,0)); // Alter the camera aspect ratio to match the viewport mCamera->setAspectRatio( Ogre::Real(vp->getActualWidth()) / Ogre::Real(vp->getActualHeight())); //------------------------------------------------------------------------------------- // Set default mipmap level (NB some APIs ignore this) Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5); //------------------------------------------------------------------------------------- // load resources Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); mSceneMgr->setSkyBox(true, "Examples/EveningSkyBox"); // dim orange ambient and two bright orange lights to match the skybox mSceneMgr->setAmbientLight(Ogre::ColourValue(0.3f, 0.2f, 0)); Ogre::Light* light = mSceneMgr->createLight(); light->setPosition(2000, 1000, -1000); light->setDiffuseColour(1, 0.5f, 0); light = mSceneMgr->createLight(); light->setPosition(-2000, 1000, 1000); light->setDiffuseColour(1, 0.5, 0); mPivot = mSceneMgr->getRootSceneNode()->createChildSceneNode(); // create a pivot node // create a child node and attach an ogre head and some smoke to it Ogre::SceneNode* headNode = mPivot->createChildSceneNode(Ogre::Vector3(100, 0, 0)); headNode->attachObject(mSceneMgr->createEntity("Head", "ogrehead.mesh")); headNode->attachObject(mSceneMgr->createParticleSystem("Smoke", "Examples/Smoke")); mCamera->setPosition(0, 30, 350); //------------------------------------------------------------------------------------- //create FrameListener Ogre::LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***"); OIS::ParamList pl; size_t windowHnd = 0; std::ostringstream windowHndStr; mWindow->getCustomAttribute("WINDOW", &windowHnd); windowHndStr << windowHnd; pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); pl.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND" ))); pl.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE"))); pl.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_FOREGROUND"))); pl.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_NONEXCLUSIVE"))); mInputManager = OIS::InputManager::createInputSystem( pl ); mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject( OIS::OISKeyboard, true )); mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject( OIS::OISMouse, true )); mMouse->setEventCallback(this); mKeyboard->setEventCallback(this); //Register as a Window listener Ogre::WindowEventUtilities::addWindowEventListener(mWindow, this); mWebBrowser = getWebBrowser(); mWebBrowser->show(); mAddressBar = getAddressBar(); mAddressBar->loadFile("html/addressbar.html"); mWebView = getWebView(); mWebView->setWebTransparent(true); mWebView->loadFile("html/mac-osx-lion.html"); clientHandler.onTitleChanged = onTitleChanged; clientHandler.onURLChanged = onURLChanged; mWebView->setClientHandler(&clientHandler); //Set initial mouse clipping size windowResized(mWindow); mRoot->addFrameListener(this); mRoot->startRendering(); }
void LayoutTestController::setAcceptsEditing(bool acceptsEditing) { getWebView()->mainFrame()->setEditable(acceptsEditing); }