Esempio n. 1
0
void ScriptRunner::notifyScriptReady(ScriptLoader* scriptLoader,
                                     AsyncExecutionType executionType) {
  SECURITY_CHECK(scriptLoader);
  switch (executionType) {
    case Async:
      // RELEASE_ASSERT makes us crash in a controlled way in error cases
      // where the ScriptLoader is associated with the wrong ScriptRunner
      // (otherwise we'd cause a use-after-free in ~ScriptRunner when it tries
      // to detach).
      SECURITY_CHECK(m_pendingAsyncScripts.contains(scriptLoader));

      m_pendingAsyncScripts.remove(scriptLoader);
      m_asyncScriptsToExecuteSoon.append(scriptLoader);

      postTask(BLINK_FROM_HERE);

      break;

    case InOrder:
      SECURITY_CHECK(m_numberOfInOrderScriptsWithPendingNotification > 0);
      m_numberOfInOrderScriptsWithPendingNotification--;

      scheduleReadyInOrderScripts();

      break;
    case None:
      NOTREACHED();
      break;
  }
}
Esempio n. 2
0
File: Font.cpp Progetto: doorxp/seed
BOOL Font::Load(const char *filename, ResourceManager *res, IMemoryPool *pool)
{
	ASSERT_NULL(filename);
	ASSERT_NULL(res);
	ASSERT_NULL(pool);

	if (this->Unload())
	{
		this->pFilename = filename;
		this->pRes = res;
		this->pPool = pool;

		stFile.Close();
		SECURITY_CHECK(pFileSystem->Open(filename, &stFile, pool), "Could not open font file.");
		const u8 *ptr = static_cast<const u8 *>(stFile.GetData());
		ObjectHeader *block = NULL;
		READ_STRUCT(block, ObjectHeader, ptr);
		SECURITY_CHECK(seed_validate_block(&stFile, block, FONT_OBJECT_MAGIC, FONT_OBJECT_VERSION), "Invalid block header for font.");

		READ_F32(this->fTracking, ptr);
		READ_F32(this->fSpacing, ptr);
		READ_F32(this->fSpaceWidth, ptr);

	/*
		const char *file = NULL;
		READ_STR(file, ptr);
		ASSERT_NULL(file);

		const char *ext = NULL;
		READ_STR(ext, ptr);
	*/
		u32 file = 0;
		READ_U32(file, ptr);

		u32 ext = 0;
		READ_U32(ext, ptr);

		if (ext != SEED_INVALID_ID /*&& pSystem->GetLanguage() != Seed::en_US*/)
		{
			File extf;
			if (pFileSystem->Open(_F(ext), &extf, pool))
			{
				extf.Close();
				this->mFontExt.Load(_F(ext), res, pool);
				this->pGlyphs = pDictionary->GetGlyphTable(&this->iTotalGlyphs);
			}
		}

		this->mFont.Load(_F(file), res, pool);
		this->fHeight	= mFont.GetHeight();
		this->fWidth	= mFont.GetWidth();

		this->bLoaded	= TRUE;
	}

	return bLoaded;
}
Esempio n. 3
0
void SoundSource::Load(const char *filename, ResourceManager *res, IMemoryPool *pool)
{
	ASSERT_NULL(filename);
	ASSERT_NULL(pool);
	ASSERT_NULL(res);

	if (pSoundSystem->IsInitialized())
	{
		this->Unload();

		/* Open file .sound */
		SECURITY_CHECK(pFileSystem->Open(filename, &stFile, pool), "Sound object couldn't be opened");

		const u8 *ptr = static_cast<const u8 *>(stFile.GetData());
		ObjectHeader *block = NULL;
		READ_STRUCT(block, ObjectHeader, ptr);
		SECURITY_CHECK(seed_validate_block(&stFile, block, SOUND_OBJECT_MAGIC, SOUND_OBJECT_VERSION), "Invalid block header for sound.");

		u32 volume = 0;
		READ_U32(volume, ptr);
		this->fVolume  = volume / 100.0f;

		u32 flags = 0;
		READ_U32(flags, ptr);
		this->bLoop = ((flags & 0x01) == 0x01); // FIXME

		const char *fname = NULL;
		READ_STR(fname, ptr);
		ASSERT_NULL(fname);

		/* Get the resource */
		pSound = static_cast<Sound *>(res->Get(fname, Seed::ObjectSound, pool));

		if (iSource)
			alDeleteSources(1, &iSource);
		ALenum err = alGetError();

		alGenSources(1, &iSource);
		err = alGetError();
		if (err != AL_NO_ERROR)
			Info(TAG "Could not create OpenAL Source: %4x", err);

		const ALint *buffer = static_cast<const ALint *>(pSound->GetData());

		alSourcef(iSource, AL_PITCH, 1.0f);
		alSource3f(iSource, AL_POSITION, cPosition.x, cPosition.y, cPosition.z);
		alSource3f(iSource, AL_VELOCITY, cVelocity.x, cVelocity.y, cVelocity.z);
		alSourcei(iSource, AL_LOOPING, this->bLoop);
		alSourcei(iSource, AL_BUFFER, *buffer);
		this->SetVolume(this->fVolume);
	}
}
Esempio n. 4
0
BOOL Package::Load(const void *data, ResourceManager *res, IMemoryPool *pool)
{
	UNUSED(res);
	UNUSED(pool);

	this->pPool = pool;
	this->pRes = res;

	//BOOL result = FALSE;
	const u8 *ptr = static_cast<const u8 *>(data);

	stFile.SetData(data);
	ObjectHeader *block = NULL;
	READ_STRUCT(block, ObjectHeader, ptr);

	SECURITY_CHECK(seed_validate_block(&stFile, block, PACKAGE_OBJECT_MAGIC, PACKAGE_OBJECT_VERSION), "Invalid block header for font.");
	READ_U32(iFilesAmount, ptr);

	if (!iFilesAmount)
	{
		Log(TAG "Package %s is empty.", stFile.GetName());
		pFileSystem->Close(&stFile);
		bLoaded = FALSE;
	}
	else
	{
		bLoaded = TRUE;
	}

	return bLoaded;
}
Esempio n. 5
0
ImageData::ImageData(const IntSize& size, DOMUint8ClampedArray* byteArray)
    : m_size(size), m_data(byteArray) {
  DCHECK_GE(size.width(), 0);
  DCHECK_GE(size.height(), 0);
  SECURITY_CHECK(static_cast<unsigned>(size.width() * size.height() * 4) <=
                 m_data->length());
}
Esempio n. 6
0
bool ScriptRunner::removePendingInOrderScript(ScriptLoader* scriptLoader) {
  for (auto it = m_pendingInOrderScripts.begin();
       it != m_pendingInOrderScripts.end(); ++it) {
    if (*it == scriptLoader) {
      m_pendingInOrderScripts.remove(it);
      SECURITY_CHECK(m_numberOfInOrderScriptsWithPendingNotification > 0);
      m_numberOfInOrderScriptsWithPendingNotification--;
      return true;
    }
  }
  return false;
}
Esempio n. 7
0
void ScriptRunner::notifyScriptLoadError(ScriptLoader* scriptLoader,
                                         AsyncExecutionType executionType) {
  switch (executionType) {
    case Async: {
      // SECURITY_CHECK makes us crash in a controlled way in error cases
      // where the ScriptLoader is associated with the wrong ScriptRunner
      // (otherwise we'd cause a use-after-free in ~ScriptRunner when it tries
      // to detach).
      SECURITY_CHECK(m_pendingAsyncScripts.contains(scriptLoader));
      m_pendingAsyncScripts.remove(scriptLoader);
      break;
    }
    case InOrder:
      SECURITY_CHECK(removePendingInOrderScript(scriptLoader));
      scheduleReadyInOrderScripts();
      break;
    case None:
      NOTREACHED();
      break;
  }
  m_document->decrementLoadEventDelayCount();
}
Esempio n. 8
0
INLINE void Dictionary::SetLanguage(Seed::eLanguage lang, IMemoryPool *pool)
{
	// REQUIREMENT:
	/*
	The first file from filelist MUST BE strings.dict.
	This is because strings.dict is unique for each language, and we must know it's ID because
	currently we can only open "localized" files BY ID.

	A possible fix for this is that Dictionary can have an array of possible filenames to try and then open.
	*/
	this->Reset();
	this->pPool = pool;

	const char *file = _F(0);
	if (!file || !pFileSystem->Open(file, &stFile, pool))
	{
		Info(TAG, "strings.dict not found, skipping dictionary.");
		return;
	}

	const u8 *ptr = static_cast<const u8 *>(stFile.GetData());
	ObjectHeader *block = NULL;
	READ_STRUCT(block, ObjectHeader, ptr);
	SECURITY_CHECK(seed_validate_block(&stFile, block, DICT_OBJECT_MAGIC, DICT_OBJECT_VERSION), "Invalid block header for dictionary.");

	u32 code = 0;
	READ_U32(code, ptr);
	ASSERT_MSG(static_cast<u32>(lang) == code, "Dictionary has an invalid language code.");
	this->iLang = lang;

	READ_U32(this->iTotalGlyphs, ptr);
	READ_U32(this->iTotalStrings, ptr);

	if (this->iTotalGlyphs)
		this->pGlyphs = reinterpret_cast<const u16 *>(ptr);

	if (this->iTotalStrings)
		this->pStrings = reinterpret_cast<const u16 *>(ptr + iTotalGlyphs + iTotalGlyphs);

	// we can alloc a table for strings using a structure {u32, u16 *}
	// and map them on load too but I will not do it. Or, I can do
	// this table inside the file and update the pointers (take care
	// of 32bit-64bit portability) on load.
}
Esempio n. 9
0
void IFileSystem::BuildFileTable()
{
	if (!pFile)
	{
		pFile = New(File(FILESYSTEM_TABLE_FILE));
		//ASSERT_NULL(pFile->pData);
		if (pFile->pData)
		{
			const u8 *ptr = static_cast<const u8 *>(pFile->pData);
			ObjectHeader *block = NULL;
			READ_STRUCT(block, ObjectHeader, ptr);

			SECURITY_CHECK(seed_validate_block(pFile, block, FST_OBJECT_MAGIC, FST_OBJECT_VERSION), "Invalid block header for filelist.");
			READ_U32(iLangCount, ptr);
			READ_U32(iFileCount, ptr);

			pFileTable = (StringFile *)pMemoryManager->Alloc(iLangCount * iFileCount * sizeof(const char *));
			for (u32 l = 0; l < iLangCount; l++)
			{
				u32 lang = 0;
				READ_U32(lang, ptr);
				pLangTable[lang] = &pFileTable[l * iFileCount];

				for (u32 s = 0; s < iFileCount; s++)
				{
					char *str = NULL;
					READ_STR(str, ptr);
					pFileTable[(l*iFileCount)+s] = str;
				}
			}

			pOldTable = pCurrentTable = pLangTable[pSystem->GetLanguage()];
			pSystem->AddListener(this);
		}
		else
		{
			Info(TAG "Could not find %s, not using localization file table and file by id feature.", FILESYSTEM_TABLE_FILE);
		}
	}
}
Esempio n. 10
0
void DocumentThreadableLoader::start(const ResourceRequest& request) {
  // Setting an outgoing referer is only supported in the async code path.
  DCHECK(m_async || request.httpReferrer().isEmpty());

  m_sameOriginRequest =
      getSecurityOrigin()->canRequestNoSuborigin(request.url());
  m_requestContext = request.requestContext();
  m_redirectMode = request.fetchRedirectMode();

  if (!m_sameOriginRequest &&
      m_options.crossOriginRequestPolicy == DenyCrossOriginRequests) {
    InspectorInstrumentation::
        documentThreadableLoaderFailedToStartLoadingForClient(m_document,
                                                              m_client);
    ThreadableLoaderClient* client = m_client;
    clear();
    client->didFail(ResourceError(errorDomainBlinkInternal, 0,
                                  request.url().getString(),
                                  "Cross origin requests are not supported."));
    return;
  }

  m_requestStartedSeconds = monotonicallyIncreasingTime();

  // Save any headers on the request here. If this request redirects
  // cross-origin, we cancel the old request create a new one, and copy these
  // headers.
  m_requestHeaders = request.httpHeaderFields();

  // DocumentThreadableLoader is used by all javascript initiated fetch, so we
  // use this chance to record non-GET fetch script requests. However, this is
  // based on the following assumptions, so please be careful when adding
  // similar logic:
  // - ThreadableLoader is used as backend for all javascript initiated network
  //   fetches.
  // - Note that ThreadableLoader is also used for non-network fetch such as
  //   FileReaderLoader. However it emulates GET method so signal is not
  //   recorded here.
  // - ThreadableLoader w/ non-GET request is only created from javascript
  //   initiated fetch.
  // - Some non-script initiated fetches such as WorkerScriptLoader also use
  //   ThreadableLoader, but they are guaranteed to use GET method.
  if (request.httpMethod() != HTTPNames::GET) {
    if (Page* page = m_document->page())
      page->chromeClient().didObserveNonGetFetchFromScript();
  }

  ResourceRequest newRequest(request);
  if (m_requestContext != WebURLRequest::RequestContextFetch) {
    // When the request context is not "fetch", |crossOriginRequestPolicy|
    // represents the fetch request mode, and |credentialsRequested| represents
    // the fetch credentials mode. So we set those flags here so that we can see
    // the correct request mode and credentials mode in the service worker's
    // fetch event handler.
    switch (m_options.crossOriginRequestPolicy) {
      case DenyCrossOriginRequests:
        newRequest.setFetchRequestMode(
            WebURLRequest::FetchRequestModeSameOrigin);
        break;
      case UseAccessControl:
        if (m_options.preflightPolicy == ForcePreflight) {
          newRequest.setFetchRequestMode(
              WebURLRequest::FetchRequestModeCORSWithForcedPreflight);
        } else {
          newRequest.setFetchRequestMode(WebURLRequest::FetchRequestModeCORS);
        }
        break;
      case AllowCrossOriginRequests:
        SECURITY_CHECK(IsNoCORSAllowedContext(m_requestContext,
                                              request.skipServiceWorker()));
        newRequest.setFetchRequestMode(WebURLRequest::FetchRequestModeNoCORS);
        break;
    }
    if (m_resourceLoaderOptions.allowCredentials == AllowStoredCredentials) {
      newRequest.setFetchCredentialsMode(
          WebURLRequest::FetchCredentialsModeInclude);
    } else {
      newRequest.setFetchCredentialsMode(
          WebURLRequest::FetchCredentialsModeSameOrigin);
    }
  }

  // We assume that ServiceWorker is skipped for sync requests and unsupported
  // protocol requests by content/ code.
  if (m_async &&
      request.skipServiceWorker() == WebURLRequest::SkipServiceWorker::None &&
      SchemeRegistry::shouldTreatURLSchemeAsAllowingServiceWorkers(
          request.url().protocol()) &&
      m_document->fetcher()->isControlledByServiceWorker()) {
    if (newRequest.fetchRequestMode() == WebURLRequest::FetchRequestModeCORS ||
        newRequest.fetchRequestMode() ==
            WebURLRequest::FetchRequestModeCORSWithForcedPreflight) {
      m_fallbackRequestForServiceWorker = ResourceRequest(request);
      // m_fallbackRequestForServiceWorker is used when a regular controlling
      // service worker doesn't handle a cross origin request. When this happens
      // we still want to give foreign fetch a chance to handle the request, so
      // only skip the controlling service worker for the fallback request. This
      // is currently safe because of http://crbug.com/604084 the
      // wasFallbackRequiredByServiceWorker flag is never set when foreign fetch
      // handled a request.
      m_fallbackRequestForServiceWorker.setSkipServiceWorker(
          WebURLRequest::SkipServiceWorker::Controlling);
    }
    loadRequest(newRequest, m_resourceLoaderOptions);
    return;
  }

  dispatchInitialRequest(newRequest);
}
Esempio n. 11
0
void NodeRareData::incrementConnectedSubframeCount() {
    SECURITY_CHECK((m_connectedFrameCount + 1) <= FrameHost::maxNumberOfFrames);
    ++m_connectedFrameCount;
}
Esempio n. 12
0
BOOL Button::Load(const char *filename, ResourceManager *res, IMemoryPool *pool)
{
	ASSERT_NULL(filename);
	ASSERT_NULL(res);
	ASSERT_NULL(pool);

	if (this->Unload())
	{
		pRes = res;
		pPool = pool;
		pFilename = filename;

		/* Isso deveria ser um objeto como SpriteObject -> ButtonObject, para que o .button seja reaproveitado. */
		SECURITY_CHECK(pFileSystem->Open(filename, &stFile, pool), "Could not open button file.");

		const u8 *ptr = static_cast<const u8 *>(stFile.GetData());
		ObjectHeader *block = NULL;
		READ_STRUCT(block, ObjectHeader, ptr);
		SECURITY_CHECK(seed_validate_block(&stFile, block, BUTTON_OBJECT_MAGIC, BUTTON_OBJECT_VERSION), "Invalid block header for button.");

		/*
		We check if any property is already set so we WON'T change it. This will allow the user to do Set* things befora doing the Load.
		If the user want that the object properties are loaded it will need call Reset before Load.
		*/
		if (!iId)
			READ_U32(iId, ptr);

		if (!iPriority)
			READ_U32(iPriority, ptr);

		f32 x = 0;
		f32 y = 0;

		READ_F32(x, ptr);
		READ_F32(y, ptr);

		if (!this->GetX())
			this->SetX(x);

		if (!this->GetY())
			this->SetY(y);

		u32 masktype = 0;
		READ_U32(masktype, ptr);

		u32 labelid = 0;
		READ_U32(labelid, ptr);

		//const char *sprite = NULL;
		//READ_STR(sprite, ptr);
		u32 sprFileId = 0;
		READ_U32(sprFileId, ptr);
		if (sprFileId != SEED_INVALID_ID)
			this->SetSprite(_F(sprFileId), res, pool);

		u32 mask = 0;
		if (masktype == 1)
		{
			READ_U32(mask, ptr);
			if (mask != SEED_INVALID_ID && eButtonCollision == CollisionNone)
				this->SetMask(_F(mask), res, pool);
		}

		bLoaded = TRUE;
	}

	return bLoaded;
}