コード例 #1
0
ファイル: AnchoAddon.cpp プロジェクト: yuriMalakhov/ancho
//----------------------------------------------------------------------------
//  InitializeContentScripting
STDMETHODIMP CAnchoAddon::InitializeContentScripting(IWebBrowser2* pBrowser, BSTR bstrUrl, documentLoadPhase aPhase)
{
  IF_FAILED_RET(initializeEnvironment());

  // content script handling happens here

  // no frame handling
  // TODO: decide how to handle frames
  if (!m_pWebBrowser.IsEqualObject(pBrowser)) {
    return S_OK;
  }

  if (aPhase != documentLoadEnd) {
    return S_OK;
  }

  cleanupScripting();

  // get content our API
  IF_FAILED_RET(m_pAddonBackground->GetContentInfo(m_InstanceID, bstrUrl, &m_pContentInfo));

  CString s;
  s.Format(_T("Ancho content [%s] [%i]"), m_sExtensionName, m_InstanceID);
  IF_FAILED_RET(m_Magpie->Init((LPWSTR)(LPCWSTR)s));

  // add a loader for scripts in the extension filesystem
  IF_FAILED_RET(m_Magpie->AddFilesystemScriptLoader((LPWSTR)(LPCWSTR)m_sExtensionPath));

  // inject items: chrome, console and window with global members
  CComQIPtr<IWebBrowser2> pWebBrowser(pBrowser);
  ATLASSERT(pWebBrowser);

  CIDispatchHelper contentInfo(m_pContentInfo);
  CComVariant jsObj;
  IF_FAILED_RET((contentInfo.Get<CComVariant, VT_DISPATCH, IDispatch*>(L"api", jsObj)));
  IF_FAILED_RET(DOMWindowWrapper::createInstance(pWebBrowser, m_wrappedWindow));
  m_Magpie->AddNamedItem(L"chrome", jsObj.pdispVal, SCRIPTITEM_ISVISIBLE|SCRIPTITEM_CODEONLY);
  m_Magpie->AddNamedItem(L"window", m_wrappedWindow, SCRIPTITEM_ISVISIBLE|SCRIPTITEM_GLOBALMEMBERS);

  CIDispatchHelper window = m_wrappedWindow;
  CComPtr<IDispatchEx> pRequest;
  IF_FAILED_RET(pRequest.CoCreateInstance(__uuidof(AnchoXmlHttpRequest)));

  IF_FAILED_RET(window.SetProperty((LPOLESTR)L"XMLHttpRequest", CComVariant(pRequest.p)));
  m_Magpie->AddNamedItem(L"XMLHttpRequest", pRequest, SCRIPTITEM_ISVISIBLE|SCRIPTITEM_CODEONLY);

  // get the name(s) of content scripts from manifest and run them in order
  IF_FAILED_RET((contentInfo.Get<CComVariant, VT_DISPATCH, IDispatch*>(L"scripts", jsObj)));

  VariantVector scripts;
  IF_FAILED_RET(addJSArrayToVariantVector(jsObj.pdispVal, scripts));

  for(VariantVector::iterator it = scripts.begin(); it != scripts.end(); ++it) {
    if( it->vt == VT_BSTR ) {
      m_Magpie->ExecuteGlobal(it->bstrVal);
    }
  }
  return S_OK;
}
コード例 #2
0
//----------------------------------------------------------------------------
//
HRESULT CAnchoAddonService::removeTabs(LPDISPATCH aTabs, LPDISPATCH aCallback)
{
  VariantVector tabs;

  IF_FAILED_RET(addJSArrayToVariantVector(aTabs, tabs));
  for(VariantVector::iterator it = tabs.begin(); it != tabs.end(); ++it) {
    if( it->vt == VT_I4 ) {
      removeTab(it->intVal, aCallback);
    } else {
      ATLTRACE(L"Problem with specified tabId - not an integer\n");
    }
  }
  return S_OK;
}
コード例 #3
0
ファイル: XMLElement.cpp プロジェクト: rokups/Urho3D
bool XMLElement::SetVariantVector(const VariantVector& value)
{
    // Must remove all existing variant child elements (if they exist) to not cause confusion
    if (!RemoveChildren("variant"))
        return false;

    for (auto i = value.begin(); i != value.end(); ++i)
    {
        XMLElement variantElem = CreateChild("variant");
        if (!variantElem)
            return false;
        variantElem.SetVariant(*i);
    }

    return true;
}
コード例 #4
0
/**
 *
 * Executes a query and returns the result
 *
 * @param VariantVector arguments The query arguments. The first argument should
 * be the query and any subsequent arguments are the bind parameters
 *
 * @return The results from the query
 */
QueryResult DatabaseConnection::execute(VariantVector arguments)
{
    int i;
    int count;
    QueryResult result;
    ResultSet *sqlResult;
    ResultSetMetaData *sqlMetadata;

    result = connect();
    if (result.error.isError) {

        // There was an error connecting. Return the result.
        return result;
    }

    PreparedStatement *sqlStatement = nullptr;

    try {

        // Prepare query
        sqlStatement = connection->prepareStatement(
            arguments.front().toString());

        if (arguments.size() > 1) {

            // Bind arguments
            int i = 1;
            for (auto it = arguments.begin() + 1; it != arguments.end(); ++it) {

                sqlStatement->setString(i, it->toString());

                i++;
            }
        }

        // Execute query
        sqlStatement->execute();

        // Fetch results
        sqlResult = sqlStatement->getResultSet();
    } catch (SQLException &e) {

        if (sqlStatement != nullptr) {

            // Free memory
            delete sqlStatement;
        }

        result.error.isError = true;
        result.error.code = e.getErrorCode();
        result.error.string = e.getSQLState() + ": " + e.what();

        return result;
    }

    sqlMetadata = sqlResult->getMetaData();

    count = sqlMetadata->getColumnCount();

    for (i = 1; i <= count; i++) {

        // Add to collection
        result.columns.push_back(sqlMetadata->getColumnName(i).asStdString());
    }

    // Read rows
    while (sqlResult->next()) {
        VariantVector row;
        for (i = 1; i <= count; i++) {
            Variant column;

            switch (sqlMetadata->getColumnType(i)) {
            default:
            case ::DataType::UNKNOWN:
            case ::DataType::CHAR:
            case ::DataType::VARCHAR:
            case ::DataType::LONGVARCHAR:
            case ::DataType::BINARY:
            case ::DataType::VARBINARY:
            case ::DataType::LONGVARBINARY:
            case ::DataType::TIMESTAMP:
            case ::DataType::DATE:
            case ::DataType::GEOMETRY:
            case ::DataType::ENUM:
            case ::DataType::SET:
            case ::DataType::BIGINT:
            case ::DataType::REAL:
            case ::DataType::DOUBLE:
            case ::DataType::DECIMAL:
                // @TODO: store binary, timestamp, date, & geometry differently
                // Also numeric types (need to be added to Variant class)
                column = sqlResult->getString(i).asStdString();
                break;
            case ::DataType::SQLNULL:
                column = Variant();
                break;
            case ::DataType::BIT:
            case ::DataType::TINYINT:
            case ::DataType::SMALLINT:
            case ::DataType::MEDIUMINT:
            case ::DataType::INTEGER:
            case ::DataType::NUMERIC:
                column = sqlResult->getInt(i);
                break;
            case ::DataType::YEAR:
                column = static_cast<unsigned short>(sqlResult->getUInt(i));
                break;
            }

            // Add column to collection
            row.push_back(column);
        }

        // Add row to collection
        result.rows.push_back(row);
    }

    // Free memory
    delete sqlResult;
    delete sqlStatement;

    return result;
}
コード例 #5
0
//! push astNode into nodeList if its variantT type match one of those from targetVariantVector
void
pushNewNode ( NodeQuerySynthesizedAttributeType* nodeList, 
              const VariantVector & targetVariantVector,
              SgNode * astNode )
   {
  // Supporting function for querySolverGrammarElementFromVariantVector

  // Allow input of a NULL pointer but don't add it to the list
     if (astNode != NULL)
        {
          for (vector<VariantT>::const_iterator i = targetVariantVector.begin(); i != targetVariantVector.end(); i++)
             {
            // printf ("Loop over target node vector: node = %s \n",getVariantName(*i).c_str());
               if (astNode->variantT() == *i)
                  {
                  //printf ("Adding node to list! \n");
                    nodeList->push_back(astNode);
                  }
             }
        }
   }