예제 #1
0
//----------------------------------------------------------------------------
//  Init
STDMETHODIMP CMagpieApplication::Init(const OLECHAR* lpszAppName)
{
  // shutdown if running
  Shutdown();

  // init script engine
  // First choice: Whatever we have in sCLSID_JScript
  HRESULT hr = m_ScriptEngine.Init(lpszAppName, sCLSID_JScript);
  if (FAILED(hr) && sCLSID_JScript == CLSID_JScript9) {
    // Second choice: If this wasn't jscript9 - try old version
    m_ScriptEngine.Shutdown();
    hr = m_ScriptEngine.Init(lpszAppName, CLSID_JScript);
  }
  IF_FAILED_RET(hr);

  // prepare CommonJS objects

  // console
  IF_FAILED_RET(m_Console->Init());
  CComQIPtr<IDispatch> console(&m_Console.m);
  ATLASSERT(console);
  IF_FAILED_RET(m_ScriptEngine.AddNamedItem(
    L"console", console, SCRIPTITEM_ISVISIBLE));

  return S_OK;
}
//---------------------------------------------------------------------------
// InternalAddURL
HRESULT CProtocolHandlerRegistrar::InternalAddResource(
  LPCWSTR lpszURL,
  LPCVOID lpData,
  DWORD dwLength,
  LPCWSTR lpszMimeType)
{
  // TODO: implement
  CComPtr<IUri> pURI;
  IF_FAILED_RET(::CreateUri(lpszURL, Uri_CREATE_CANONICALIZE, 0, &pURI));

  CritSectLock lock(m_CriticalSection);

  CComPtr<IClassFactory> pClassFactory;

  CComBSTR scheme, host;
  IF_FAILED_RET(pURI->GetSchemeName(&scheme));
  IF_FAILED_RET(pURI->GetHost(&host));

  // lookup class factory for lpszScheme
  if (!m_ClassFactories.Lookup(scheme, pClassFactory))
  {
    // a protocol handler for this scheme has to be registered first!
    return E_UNEXPECTED;
  }

  CComQIPtr<IProtocolMemoryResource> memoryResource(pClassFactory);
  if (!memoryResource) {
    // Class factory for this handler does not support memory based resources
    return E_NOINTERFACE;
  }

  // add the URL
  return memoryResource->AddResource(pURI, lpData, dwLength, lpszMimeType);
}
예제 #3
0
//----------------------------------------------------------------------------
//
HRESULT CAnchoAddonService::createTabImpl(CIDispatchHelper &aProperties, ATabCreatedCallback::Ptr aCallback, bool aInNewWindow)
{
  //CIDispatchHelper properties(aProperties);
  CComBSTR originalUrl;
  HRESULT hr = aProperties.Get<CComBSTR, VT_BSTR, BSTR>(L"url", originalUrl);
  if (hr != S_OK) {
    originalUrl = L"about:blank";
  }
  std::wstring url = std::wstring(originalUrl,SysStringLen(originalUrl));
  if (aCallback) {
    //TODO - use headers instead of url
    int requestID = m_NextRequestID++;
    std::wostringstream str;
    str << L'#' << requestID << '#';
    url = str.str() + url;

    m_CreateTabCallbacks[requestID] = aCallback;
  }

  LPUNKNOWN browser;
  IF_FAILED_RET(getActiveWebBrowser(&browser));
  if (aInNewWindow) {
    IF_FAILED_RET(navigateBrowser(browser, url, navOpenInNewWindow));
  } else {
    IF_FAILED_RET(navigateBrowser(browser, url, navOpenInNewTab));
  }
  return S_OK;
}
예제 #4
0
//----------------------------------------------------------------------------
//  
STDMETHODIMP CAnchoBackgroundAPI::startBackgroundWindow(BSTR bsPartialURL)
{
  // it's safe to call this method multiple times, anyhow the window
  // will be created only once
  if (m_BackgroundWindow)
  {
    return S_OK;
  }
  CStringW sURL(bsPartialURL);
  if (!GetURL(sURL))
  {
    return E_FAIL;
  }

  // get the main api module and inject it into the background page
  CComPtr<IMagpieModuleRestricted> mainModule;
  IF_FAILED_RET(m_Magpie->GetModuleObject((LPOLESTR)s_AnchoMainAPIModuleID, &mainModule));

  CComPtr<IDispatch> mainModuleExports;
  IF_FAILED_RET(mainModule->GetExportsObject(&mainModuleExports));

  CComVariant vt;
  IF_FAILED_RET(mainModuleExports.GetPropertyByName(s_AnchoBackgroundPageAPIName, &vt));
  if (vt.vt != VT_DISPATCH)
  {
    return E_FAIL;
  }

  IF_FAILED_RET(CBackgroundWindow::CreateBackgroundWindow(vt.pdispVal, sURL, &m_BackgroundWindow.p));
  return S_OK;
}
예제 #5
0
//----------------------------------------------------------------------------
//  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;
}
예제 #6
0
//----------------------------------------------------------------------------
//  LoadModule
HRESULT CMagpieApplication::LoadModule(
  CMagpieModule           *   pSrcModule,
  LPCOLESTR                   lpszModuleID,
  LPCOLESTR                   lpszModuleSource,
  BOOL                        aDecorateScript,
  CMagpieModuleComObject  *&  pRet)
{
  CString sModuleID;
  IF_FAILED_RET(ResolveModuleID(
    pSrcModule, lpszModuleID, sModuleID));

  CComPtr<IMagpieModule> module;

  // is the module already loaded?
  HRESULT hr = E_FAIL;
  if (SUCCEEDED(GetModule(sModuleID, module.p)))
  {
    // yes, return module
    pRet = static_cast<CMagpieModuleComObject*>(module.Detach());
    return S_FALSE;  // means: already loaded
  }

  // the selected script loader. can be NULL.
  CComPtr<IMagpieScriptLoader> scriptLoader;

  if (lpszModuleSource)
  {
    hr = S_OK;
  }
  else
  {
    // find a script loader
    size_t loaderCount = m_ScriptLoaders.GetCount();
    for(size_t n = 0; n < loaderCount; n++)
    {
      hr = m_ScriptLoaders[n]->HasModuleScript(lpszModuleID);
      if (S_OK == hr)
      {
        scriptLoader = m_ScriptLoaders[n];
        break;
      }
    }
  }
  // need either scriptLoader or lpszModuleSource
  if (scriptLoader || lpszModuleSource)
  {
    CMagpieModuleComObject * pModuleObject;
    IF_FAILED_RET(CMagpieModule::CreateObject(
      *this, sModuleID, scriptLoader, lpszModuleSource, aDecorateScript, pModuleObject));

    m_Modules[sModuleID] = pModuleObject;
    pRet = pModuleObject;
    return S_OK;
  }
  // no script found for this ID
  return E_FAIL;
}
HRESULT CProtocolHandlerRegistrar::RegisterTemporaryHandler(
  LPCWSTR lpszScheme,
  LPCWSTR lpszHost,
  RT      tResourceID)
{
  CritSectLock lock(m_CriticalSection);
  BOOL registered = FALSE;

  CComObject<CF> *pHandlerFactory = NULL;
  CComPtr<IClassFactory> pClassFactory;

  // lookup class factory for lpszScheme
  if (!m_ClassFactories.Lookup(lpszScheme, pClassFactory))
  {
    // don't have yet, create class factory object
    IF_FAILED_RET(CComObject<CF>
      ::CreateInstance(&pHandlerFactory));

    pClassFactory = pHandlerFactory;

    // init classfactory object
    IF_FAILED_RET(pHandlerFactory->Init(
      lpszScheme));
  }
  else
  {
    // have class factory
    registered = TRUE;
    pHandlerFactory = (CComObject<CF> *)pClassFactory.p;
  }

  // add the host
  IF_FAILED_RET(pHandlerFactory->AddHost(
    lpszHost, tResourceID));

  // register protocol handler
  if (!registered)
  {
    // get IInternetSession
    CComPtr<IInternetSession> pInternetSession;
    IF_FAILED_RET(CoInternetGetSession(0, &pInternetSession, 0));

    IF_FAILED_RET(pInternetSession->RegisterNameSpace(
      pClassFactory,
      CTemporaryProtocolFolderHandler::CLSID,
      lpszScheme,
      0, NULL, 0));

    // store classfactory object
    m_ClassFactories[lpszScheme] = pClassFactory;
  }

  return S_OK;
}
예제 #8
0
//----------------------------------------------------------------------------
//  
HRESULT CAnchoBackgroundAPI::GetMainModuleExportsScript(CIDispatchHelper & script)
{
  // get the main api module
  CComPtr<IMagpieModuleRestricted> mainModule;
  IF_FAILED_RET(m_Magpie->GetModuleObject((LPOLESTR)s_AnchoMainAPIModuleID, &mainModule));

  CComPtr<IDispatch> mainModuleExports;
  IF_FAILED_RET(mainModule->GetExportsObject(&mainModuleExports));

  script = mainModuleExports;
  return S_OK;
}
예제 #9
0
/**
 * Add CustomInternetSecurity to XMLHTTPRequest to allow cross-domain requests
 */
HRESULT CSalsitaFramework::AddCustomInternetSecurity(CComPtr<IXMLHttpRequest> pRequest)
{
  CComObject<CCustomInternetSecurityImpl>* pSecurityImpl = NULL;
  CComPtr<IUnknown> pUnkSecurity;
  CComPtr<IObjectWithSite> pObjWithSite;

  IF_FAILED_RET(CComObject<CCustomInternetSecurityImpl>::CreateInstance(&pSecurityImpl));
  IF_FAILED_RET(pSecurityImpl->QueryInterface(&pUnkSecurity));
  IF_FAILED_RET(pRequest->QueryInterface(&pObjWithSite));
  IF_FAILED_RET(pObjWithSite->SetSite(pUnkSecurity));

  return S_OK;
}
예제 #10
0
//----------------------------------------------------------------------------
//  RunModule
HRESULT CMagpieActiveScript::RunModule(
  CMagpieModule* pModule)
{
  CComPtr<IDispatch> pModuleRequireOb(pModule->GetRequire());
  if (!pModuleRequireOb)
  {
    return E_UNEXPECTED;
  }

  CString sFilename, sModuleID;
  pModule->GetID(sModuleID);
  pModule->GetFilename(sFilename);

  m_ScriptEngine->SetScriptState(SCRIPTSTATE_DISCONNECTED);

  // add namespace for module
  IF_FAILED_RET(m_ScriptEngine->AddNamedItem(sModuleID, SCRIPTITEM_CODEONLY));

  // dispatch for module's namespace
  CIDispatchHelper script;
  IF_FAILED_RET(m_ScriptEngine->GetScriptDispatch(sModuleID, &script));

  // create exports object
  CIDispatchHelper scriptGlobal;
  IF_FAILED_RET(m_ScriptEngine->GetScriptDispatch(NULL, &scriptGlobal));
  CComPtr<IDispatch> pModuleExportsOb;
  IF_FAILED_RET(scriptGlobal.CreateObject(L"Object", &pModuleExportsOb));

  // inject CommonJS objects
  script.SetPropertyByRef(L"require", CComVariant(pModuleRequireOb));
  script.SetPropertyByRef(L"module", CComVariant(pModule));
  script.SetPropertyByRef(L"exports", CComVariant(pModuleExportsOb));

  CComVariant vtSalsita;
  HRESULT hr = GetSalsitaObject(&vtSalsita);
  if (SUCCEEDED(hr))
  {
    script.SetPropertyByRef(L"salsita", vtSalsita);
  }

  // now run the module
  m_Application.EnterModule(sModuleID);
  hr = LoadScriptFile(sFilename, sModuleID);
  if (SUCCEEDED(hr))
  {
    m_ScriptEngine->SetScriptState(SCRIPTSTATE_CONNECTED);
  }
  m_Application.ExitModule();

  return S_OK;
}
//---------------------------------------------------------------------------
// Seek
STDMETHODIMP CTemporaryProtocolFolderHandler::Seek(
  LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
{
  if (m_SpecialURLResource.mData) {
    // have a special URL
    return m_SpecialURLResource.seek(dlibMove, dwOrigin, plibNewPosition);
  }
  // simply forward to file
  IF_FAILED_RET(m_File.Seek(dlibMove.QuadPart, dwOrigin));
  if (plibNewPosition) {
    IF_FAILED_RET(m_File.GetPosition(plibNewPosition->QuadPart));
  }
  return S_OK;
}
예제 #12
0
//----------------------------------------------------------------------------
//  Init
HRESULT CMagpieActiveScript::Init(CString &extensionId, CString &appId)
{
  m_ExtensionId = extensionId;

  IF_FAILED_RET(InitializeDebugInterface(appId));

  IF_FAILED_RET(LoadScriptEngine(CLSID_JScript));
  IF_FAILED_RET(m_ScriptEngine->SetScriptState(SCRIPTSTATE_INITIALIZED));

  // add salsitaFramework
  IF_FAILED_RET(CSalsitaFramework::CreateObject(m_SalsitaFramework.p, this));
  IF_FAILED_RET(AddNamedItem(L"salsitaFramework", m_SalsitaFramework, SCRIPTITEM_ISPERSISTENT|SCRIPTITEM_ISVISIBLE));
  return S_OK;
}
예제 #13
0
//----------------------------------------------------------------------------
//  
HRESULT CAnchoBackgroundAPI::ReleaseContentAPI(ULONG ulInstanceID)
{
  if (!m_Magpie)
  {
    return E_UNEXPECTED;
  }

  // get the main api module
  CIDispatchHelper script;
  IF_FAILED_RET(GetMainModuleExportsScript(script));

  CComVariant vtInstanceID(ulInstanceID);
  DISPPARAMS params = {&vtInstanceID, NULL, 1, 0};
  IF_FAILED_RET(script.Call((LPOLESTR)s_AnchoFnReleaseContentAPI, &params));
  return S_OK;
}
예제 #14
0
//----------------------------------------------------------------------------
//  GetExports
HRESULT CMagpieModule::GetExports(VARIANT * pvtExports)
{
  ENSURE_RETVAL(pvtExports);
  ATLASSERT(m_pApplication);
  CIDispatchHelper script;
  IF_FAILED_RET(m_pApplication->GetScriptEngine().GetScriptDispatch(m_sID, &script));
  return script.GetPropertyByName(L"exports", pvtExports);
}
예제 #15
0
//----------------------------------------------------------------------------
//  AddFilesystemScriptLoader
STDMETHODIMP CMagpieApplication::AddFilesystemScriptLoader(
  const OLECHAR* lpszRootPath)
{
  CComPtr<CMagpieFilesystemScriptLoaderComObject> loader;
  IF_FAILED_RET(CMagpieFilesystemScriptLoader::CreateObject(
    lpszRootPath, loader.p));
  m_ScriptLoaders.Add(loader.p);
  return S_OK;
}
예제 #16
0
//----------------------------------------------------------------------------
//  AddNamedItem
HRESULT CMagpieActiveScript::AddNamedItem(
  LPCOLESTR   pstrName,
  IDispatch * pDisp,
  DWORD       dwFlags)
{
  IF_FAILED_RET(m_ScriptEngine->AddNamedItem(pstrName, dwFlags));
  m_NamedItems[pstrName] = pDisp;
  return S_OK;
}
예제 #17
0
//----------------------------------------------------------------------------
//  AddResourceScriptLoader
STDMETHODIMP CMagpieApplication::AddResourceScriptLoader(
  HANDLE_PTR hModule)
{
  // see the bug mentioned in CMagpieActiveScript::RunModule
  CComPtr<CMagpieResourceScriptLoaderComObject> loader;
  IF_FAILED_RET(CMagpieResourceScriptLoader::CreateObject(
    (HMODULE)hModule, loader.p));
  m_ScriptLoaders.Add(loader.p);
  return S_OK;
}
예제 #18
0
//----------------------------------------------------------------------------
//  Init
STDMETHODIMP CMagpieApplication::Init(
  const OLECHAR* extensionId,
  const OLECHAR* lpszFolderName,
  VARIANT extensionTabId)
{
  m_ExtensionId = extensionId;

  // basic preparation
  CString sRootPath = lpszFolderName;
  if (sRootPath.IsEmpty() || !PathIsDirectory(sRootPath))
  {
    return E_INVALIDARG;
  }
  if (sRootPath[sRootPath.GetLength()-1] != _T('\\'))
  {
    sRootPath += _T('\\');
  }

  // shutdown if running
  Shutdown();

  CString appId;
  if (extensionTabId.vt == VT_INT)
  {
    appId.Format(_T("%s - %i"), extensionId, extensionTabId.intVal);
  } else {
    appId = extensionId;
  }

  // init script engine
  HRESULT hr = m_ScriptEngine.Init(m_ExtensionId, appId);
  IF_FAILED_RET(hr);

  // prepare CommonJS objects

  // console
  IF_FAILED_RET(m_Console.Init());
  IF_FAILED_RET(m_ScriptEngine.AddNamedItem(
    L"console", &m_Console, SCRIPTITEM_ISPERSISTENT|SCRIPTITEM_ISVISIBLE));

  m_RootPath = sRootPath;
  return S_OK;
}
예제 #19
0
STDMETHODIMP CSalsitaFramework::createXMLHTTPRequest(IDispatch** ppVal)
{
  ENSURE_RETVAL(ppVal);

  CComPtr<IXMLHttpRequest> pRequest;
  IF_FAILED_RET(pRequest.CoCreateInstance(__uuidof(XMLHTTPRequest)));

  // try to add the security object
  HRESULT hrAddSecurity = AddCustomInternetSecurity(pRequest);

  IF_FAILED_RET(pRequest->QueryInterface(IID_IDispatch, (void**)ppVal));

  if (FAILED(hrAddSecurity)) // if we fail to add the security object, return the XMLHTTPRequest anyway
  {
    return S_FALSE;
  } else {
    return S_OK;
  }
}
예제 #20
0
HRESULT CMagpieActiveScript::CreateSalsitaApi(INT tabId, LPUNKNOWN pSalsitaApi, VARIANT pContentApi)
{
  m_debugContextIdentifier.Format(_T("Tab id = %i"), tabId);

  IF_FAILED_RET(CSalsitaApiImpl::CreateObject(m_SalsitaApiImpl.p, tabId, pSalsitaApi));
  m_SalsitaApiImpl->m_ExtensionId = m_ExtensionId;
  m_SalsitaApiImpl->m_RootPath = m_Application.GetRootPath();

  m_ScriptEngine->SetScriptState(SCRIPTSTATE_DISCONNECTED);

  // add namespace for module
  IF_FAILED_RET(m_ScriptEngine->AddNamedItem(m_SalsitaApiModuleId, SCRIPTITEM_CODEONLY));

  // dispatch for module's namespace
  CIDispatchHelper script;
  IF_FAILED_RET(m_ScriptEngine->GetScriptDispatch(m_SalsitaApiModuleId, &script));

  // create salsita object
  CIDispatchHelper scriptGlobal;
  IF_FAILED_RET(m_ScriptEngine->GetScriptDispatch(NULL, &scriptGlobal));
  CComPtr<IDispatch> pSalsitaOb;
  IF_FAILED_RET(scriptGlobal.CreateObject(L"Object", &pSalsitaOb));

  script.SetPropertyByRef(L"_salsita_impl", CComVariant(m_SalsitaApiImpl));
  script.SetPropertyByRef(L"salsita", CComVariant(pSalsitaOb));

  if (pContentApi.vt == VT_DISPATCH)
  {
    m_SalsitaContentApi = pContentApi.pdispVal;
    script.SetPropertyByRef(L"_salsita_content_impl", CComVariant(m_SalsitaContentApi));
  }

  m_Application.EnterModule(m_SalsitaApiModuleId);
  HRESULT hr = LoadScriptResource(g_hDllInstance, L"salsita.js", m_SalsitaApiModuleId);
  if (SUCCEEDED(hr))
  {
    m_ScriptEngine->SetScriptState(SCRIPTSTATE_CONNECTED);
  }
  m_Application.ExitModule();

  return S_OK;
}
예제 #21
0
//----------------------------------------------------------------------------
//  
HRESULT CAnchoBackgroundAPI::GetContentAPI(ULONG ulInstanceID, LPDISPATCH* ppDisp)
{
  ENSURE_RETVAL(ppDisp);
  if (!m_Magpie)
  {
    return E_UNEXPECTED;
  }

  CIDispatchHelper script;
  IF_FAILED_RET(GetMainModuleExportsScript(script));

  CComVariant vtRet, vtInstanceID(ulInstanceID);
  DISPPARAMS params = {&vtInstanceID, NULL, 1, 0};
  IF_FAILED_RET(script.Call((LPOLESTR)s_AnchoFnGetContentAPI, &params, &vtRet));
  if (vtRet.vt != VT_DISPATCH)
  {
    return E_FAIL;
  }
  return vtRet.pdispVal->QueryInterface(IID_IDispatch, (void**)ppDisp);
}
예제 #22
0
//----------------------------------------------------------------------------
//  AddExtension
STDMETHODIMP CMagpieApplication::AddExtension(
  const OLECHAR* lpszExtensionName, IDispatch* pDispExtension)
{
  if (!lpszExtensionName || !pDispExtension || !wcslen(lpszExtensionName))
  {
    return E_INVALIDARG;
  }
  IF_FAILED_RET(m_ScriptEngine.AddNamedItem(
    lpszExtensionName, pDispExtension, SCRIPTITEM_ISPERSISTENT|SCRIPTITEM_ISVISIBLE));
  return S_OK;
}
예제 #23
0
//----------------------------------------------------------------------------
//  ExecuteGlobal
STDMETHODIMP CMagpieApplication::ExecuteGlobal(
  const OLECHAR* lpszModuleID, VARIANT *result)
{
  // load the module
  CComPtr<CMagpieModuleComObject> pModule;
  // note that scripts executed in global context DON'T GET WRAPPED!
  // 4th arg to LoadModule is FALSE for this reason.
  // See stdafx.h, gJscript9ModuleWrapperIntro and CMagpieModule::Init()
  IF_FAILED_RET(LoadModule(NULL, lpszModuleID, NULL, FALSE, pModule.p));

  return m_ScriptEngine.ExecuteGlobal((CMagpieModule*)pModule.p, result);
}
예제 #24
0
//----------------------------------------------------------------------------
//
HRESULT CAnchoAddonService::FinalConstruct()
{
  // Get and store the path, this will be used in some places (e.g. to load
  // additional DLLs).
  LPTSTR psc = m_sThisPath.GetBuffer(_MAX_PATH);
  GetModuleFileName(_AtlModule.m_hInstance, psc, _MAX_PATH);
  PathRemoveFileSpec(psc);
  PathAddBackslash(psc);
  m_sThisPath.ReleaseBuffer();

  CComObject<CIECookieManager> * pCookiesManager = NULL;
  IF_FAILED_RET(CComObject<CIECookieManager>::CreateInstance(&pCookiesManager));
  pCookiesManager->setNotificationCallback(ACookieCallbackFunctor::APtr(new CookieNotificationCallback(*this)));
  pCookiesManager->startWatching();

  m_Cookies = pCookiesManager;

  IF_FAILED_RET(SimpleJSArray::createInstance(m_BrowserActionInfos));

  return S_OK;
}
예제 #25
0
//----------------------------------------------------------------------------
//  LoadModule
HRESULT CMagpieApplication::LoadModule(
  CMagpieModule           *   pSrcModule,
  LPCOLESTR                   lpszModuleID,
  CMagpieModuleComObject  *&  pRet)
{
  CString sModuleID;
  IF_FAILED_RET(ResolveModuleID(
    pSrcModule, lpszModuleID, sModuleID));

  CComPtr<CMagpieModuleComObject> module;

  // is the module already loaded?
  HRESULT hr = E_FAIL;
  hr = GetModule(sModuleID, module.p);
  if (SUCCEEDED(hr))
  {
    // yes, return module
    pRet = module.Detach();
    return S_FALSE;  // means: already loaded
  }

  // create a real path from the module ID...
  CString sModulePath, sModuleIDPath(sModuleID);
  sModuleIDPath.Replace(_T('/'), _T('\\'));
  // ...assuming that the file type is always 'js'
  // @TODO: Might change in future.
  sModulePath = m_RootPath + sModuleIDPath + _T(".js");

  if (!PathFileExists(sModulePath))
  {
    return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
  }

  IF_FAILED_RET(CMagpieModule::CreateObject(
    *this, sModuleID, sModulePath, module.p));

  m_Modules[sModuleID] = module;
  pRet = module.Detach();
  return S_OK;
}
예제 #26
0
//----------------------------------------------------------------------------
//
STDMETHODIMP CAnchoAddonService::createPopupWindow(BSTR aUrl, INT aX, INT aY, LPDISPATCH aInjectedData, LPDISPATCH aCloseCallback)
{
  if (!aInjectedData || !aCloseCallback) {
    return E_INVALIDARG;
  }

  CIDispatchHelper injectedData(aInjectedData);
  CIDispatchHelper closeCallback(aCloseCallback);
  DispatchMap injectedDataMap;

  IDispatch* api;
  IF_FAILED_RET((injectedData.Get<IDispatch*, VT_DISPATCH>((LPOLESTR)s_AnchoBackgroundPageAPIName, api)));
  injectedDataMap[s_AnchoBackgroundPageAPIName] = api;

  IDispatch* console;
  IF_FAILED_RET((injectedData.Get<IDispatch*, VT_DISPATCH>((LPOLESTR)s_AnchoBackgroundConsoleObjectName, console)));
  injectedDataMap[s_AnchoBackgroundConsoleObjectName] = console;

  HWND hwnd = getCurrentWindowHWND();
  IF_FAILED_RET(CPopupWindow::CreatePopupWindow(hwnd, injectedDataMap, aUrl, aX, aY, closeCallback));
  return S_OK;
}
예제 #27
0
//----------------------------------------------------------------------------
//  Init
HRESULT CMagpieModule::Init(
  CMagpieApplication  & application,
  LPCOLESTR             lpsModuleID,
  LPCOLESTR             lpsFileName)
{
  m_pApplication = &application;
  m_sID = lpsModuleID;
  m_sFilename = lpsFileName;

  // create "require" object
  IF_FAILED_RET(CMagpieRequire::CreateObject(*this, m_Require.p));

  return S_OK;
}
예제 #28
0
//----------------------------------------------------------------------------
//  Run
HRESULT CMagpieModule::Run()
{
  if (m_bDidRun)
  {
    // we ran already.
    return S_FALSE;
  }
  ATLASSERT(m_pApplication);

  m_bDidRun = TRUE;
  IF_FAILED_RET(m_pApplication->GetScriptEngine().RunModule(this));

  return S_OK;
}
예제 #29
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;
}
예제 #30
0
HRESULT CSalsitaFramework::CreateObject(CSalsitaFrameworkComObject *& pRet, CMagpieActiveScript *magpieActiveScript)
{
  if (!magpieActiveScript)
  {
    return E_INVALIDARG;
  }

  CSalsitaFrameworkComObject *newObject = pRet = NULL;
  IF_FAILED_RET(CSalsitaFrameworkComObject::CreateInstance(&newObject));
  newObject->AddRef();
  newObject->m_MagpieActiveScript = magpieActiveScript;
  pRet = newObject;
  return S_OK;
}