Beispiel #1
0
void XMLHttpRequest::open(const String& method, const URL& url, bool async, ExceptionCode& ec)
{
    if (!internalAbort())
        return;

    State previousState = m_state;
    m_state = UNSENT;
    m_error = false;
    m_uploadComplete = false;

    // clear stuff from possible previous load
    clearResponse();
    clearRequest();

    ASSERT(m_state == UNSENT);

    if (!isValidHTTPToken(method)) {
        ec = SYNTAX_ERR;
        return;
    }

    if (!isAllowedHTTPMethod(method)) {
        ec = SECURITY_ERR;
        return;
    }

    // FIXME: Convert this to check the isolated world's Content Security Policy once webkit.org/b/104520 is solved.
    bool shouldBypassMainWorldContentSecurityPolicy = false;
    if (is<Document>(*scriptExecutionContext())) {
        Document& document = downcast<Document>(*scriptExecutionContext());
        if (document.frame())
            shouldBypassMainWorldContentSecurityPolicy = document.frame()->script().shouldBypassMainWorldContentSecurityPolicy();
    }
    if (!shouldBypassMainWorldContentSecurityPolicy && !scriptExecutionContext()->contentSecurityPolicy()->allowConnectToSource(url)) {
        // FIXME: Should this be throwing an exception?
        ec = SECURITY_ERR;
        return;
    }

    if (!async && scriptExecutionContext()->isDocument()) {
        if (document()->settings() && !document()->settings()->syncXHRInDocumentsEnabled()) {
            logConsoleError(scriptExecutionContext(), "Synchronous XMLHttpRequests are disabled for this page.");
            ec = INVALID_ACCESS_ERR;
            return;
        }

        // Newer functionality is not available to synchronous requests in window contexts, as a spec-mandated
        // attempt to discourage synchronous XHR use. responseType is one such piece of functionality.
        // We'll only disable this functionality for HTTP(S) requests since sync requests for local protocols
        // such as file: and data: still make sense to allow.
        if (url.protocolIsInHTTPFamily() && m_responseTypeCode != ResponseTypeDefault) {
            logConsoleError(scriptExecutionContext(), "Synchronous HTTP(S) requests made from the window context cannot have XMLHttpRequest.responseType set.");
            ec = INVALID_ACCESS_ERR;
            return;
        }

#if ENABLE(XHR_TIMEOUT)
        // Similarly, timeouts are disabled for synchronous requests as well.
        if (m_timeoutMilliseconds > 0) {
            logConsoleError(scriptExecutionContext(), "Synchronous XMLHttpRequests must not have a timeout value set.");
            ec = INVALID_ACCESS_ERR;
            return;
        }
#endif
    }

    m_method = uppercaseKnownHTTPMethod(method);

    m_url = url;

    m_async = async;

    ASSERT(!m_loader);

    // Check previous state to avoid dispatching readyState event
    // when calling open several times in a row.
    if (previousState != OPENED)
        changeState(OPENED);
    else
        m_state = OPENED;
}
Beispiel #2
0
static unsigned logCanCacheFrameDecision(Frame& frame, DiagnosticLoggingClient& diagnosticLoggingClient, unsigned indentLevel)
{
    PCLOG("+---");
    if (!frame.isMainFrame() && frame.loader().state() == FrameStateProvisional) {
        PCLOG("   -Frame is in provisional load stage");
        logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::provisionalLoadKey());
        return 1 << IsInProvisionalLoadStage;
    }
    if (!frame.loader().documentLoader()) {
        PCLOG("   -There is no DocumentLoader object");
        logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::noDocumentLoaderKey());
        return 1 << NoDocumentLoader;
    }

    URL currentURL = frame.loader().documentLoader()->url();
    URL newURL = frame.loader().provisionalDocumentLoader() ? frame.loader().provisionalDocumentLoader()->url() : URL();
    if (!newURL.isEmpty())
        PCLOG(" Determining if frame can be cached navigating from (", currentURL.string(), ") to (", newURL.string(), "):");
    else
        PCLOG(" Determining if subframe with URL (", currentURL.string(), ") can be cached:");
     
    unsigned rejectReasons = 0;
    if (!frame.loader().documentLoader()->mainDocumentError().isNull()) {
        PCLOG("   -Main document has an error");
        logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::mainDocumentErrorKey());

        if (frame.loader().documentLoader()->mainDocumentError().isCancellation() && frame.loader().documentLoader()->subresourceLoadersArePageCacheAcceptable())
            PCLOG("    -But, it was a cancellation and all loaders during the cancelation were loading images or XHR.");
        else
            rejectReasons |= 1 << MainDocumentError;
    }
    if (frame.loader().documentLoader()->substituteData().isValid() && frame.loader().documentLoader()->substituteData().failingURL().isEmpty()) {
        PCLOG("   -Frame is an error page");
        logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::isErrorPageKey());
        rejectReasons |= 1 << IsErrorPage;
    }
    if (frame.loader().subframeLoader().containsPlugins() && !frame.page()->settings().pageCacheSupportsPlugins()) {
        PCLOG("   -Frame contains plugins");
        logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::hasPluginsKey());
        rejectReasons |= 1 << HasPlugins;
    }
    if (frame.isMainFrame() && frame.document()->url().protocolIs("https") && frame.loader().documentLoader()->response().cacheControlContainsNoStore()) {
        PCLOG("   -Frame is HTTPS, and cache control prohibits storing");
        logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::httpsNoStoreKey());
        rejectReasons |= 1 << IsHttpsAndCacheControlled;
    }
    if (frame.isMainFrame() && !frame.loader().history().currentItem()) {
        PCLOG("   -Main frame has no current history item");
        logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::noCurrentHistoryItemKey());
        rejectReasons |= 1 << NoHistoryItem;
    }
    if (frame.loader().quickRedirectComing()) {
        PCLOG("   -Quick redirect is coming");
        logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::quirkRedirectComingKey());
        rejectReasons |= 1 << QuickRedirectComing;
    }
    if (frame.loader().documentLoader()->isLoading()) {
        PCLOG("   -DocumentLoader is still loading");
        logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::isLoadingKey());
        rejectReasons |= 1 << IsLoading;
    }
    if (frame.loader().documentLoader()->isStopping()) {
        PCLOG("   -DocumentLoader is in the middle of stopping");
        logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::documentLoaderStoppingKey());
        rejectReasons |= 1 << IsStopping;
    }

    Vector<ActiveDOMObject*> unsuspendableObjects;
    if (!frame.document()->canSuspendActiveDOMObjectsForPageCache(&unsuspendableObjects)) {
        PCLOG("   -The document cannot suspend its active DOM Objects");
        for (auto* activeDOMObject : unsuspendableObjects) {
            PCLOG("    - Unsuspendable: ", activeDOMObject->activeDOMObjectName());
            diagnosticLoggingClient.logDiagnosticMessageWithValue(DiagnosticLoggingKeys::pageCacheKey(), DiagnosticLoggingKeys::unsuspendableDOMObjectKey(), activeDOMObject->activeDOMObjectName(), ShouldSample::Yes);
            UNUSED_PARAM(activeDOMObject);
        }
        logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::cannotSuspendActiveDOMObjectsKey());
        rejectReasons |= 1 << CannotSuspendActiveDOMObjects;
    }
    if (!frame.loader().documentLoader()->applicationCacheHost()->canCacheInPageCache()) {
        PCLOG("   -The DocumentLoader uses an application cache");
        logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::applicationCacheKey());
        rejectReasons |= 1 << DocumentLoaderUsesApplicationCache;
    }
    if (!frame.loader().client().canCachePage()) {
        PCLOG("   -The client says this frame cannot be cached");
        logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::deniedByClientKey());
        rejectReasons |= 1 << ClientDeniesCaching;
    }

    for (Frame* child = frame.tree().firstChild(); child; child = child->tree().nextSibling())
        rejectReasons |= logCanCacheFrameDecision(*child, diagnosticLoggingClient, indentLevel + 1);
    
    PCLOG(rejectReasons ? " Frame CANNOT be cached" : " Frame CAN be cached");
    PCLOG("+---");
    
    return rejectReasons;
}
Beispiel #3
0
void HistoryItem::setURL(const URL& url)
{
    pageCache()->remove(this);
    setURLString(url.string());
    clearDocumentState();
}
Beispiel #4
0
void IconController::commitToDatabase(const URL& icon)
{
    LOG(IconDatabase, "Committing iconURL %s to database for pageURLs %s and %s", icon.string().ascii().data(), m_frame->document()->url().string().ascii().data(), m_frame->loader().initialRequest().url().string().ascii().data());
    iconDatabase().setIconURLForPageURL(icon.string(), m_frame->document()->url().string());
    iconDatabase().setIconURLForPageURL(icon.string(), m_frame->loader().initialRequest().url().string());
}
void WebSocketHandshake::setURL(const URL& url)
{
    m_url = url.copy();
}
void HTMLLinkElement::process()
{
    if (!inDocument() || m_isInShadowTree) {
        ASSERT(!m_sheet);
        return;
    }

    URL url = getNonEmptyURLAttribute(hrefAttr);

    if (!m_linkLoader.loadLink(m_relAttribute, url, attributeWithoutSynchronization(asAttr), attributeWithoutSynchronization(crossoriginAttr), document()))
        return;

    bool treatAsStyleSheet = m_relAttribute.isStyleSheet
        || (document().settings() && document().settings()->treatsAnyTextCSSLinkAsStylesheet() && m_type.containsIgnoringASCIICase("text/css"));

    if (m_disabledState != Disabled && treatAsStyleSheet && document().frame() && url.isValid()) {
        AtomicString charset = attributeWithoutSynchronization(charsetAttr);
        if (charset.isEmpty() && document().frame())
            charset = document().charset();
        
        if (m_cachedSheet) {
            removePendingSheet();
            m_cachedSheet->removeClient(this);
            m_cachedSheet = nullptr;
        }

        if (!shouldLoadLink())
            return;

        m_loading = true;

        bool mediaQueryMatches = true;
        if (!m_media.isEmpty()) {
            Optional<RenderStyle> documentStyle;
            if (document().hasLivingRenderTree())
                documentStyle = Style::resolveForDocument(document());
            auto media = MediaQuerySet::createAllowingDescriptionSyntax(m_media);
            mediaQueryMatches = MediaQueryEvaluator { document().frame()->view()->mediaType(), document(), documentStyle ? &*documentStyle : nullptr }.evaluate(media.get());
        }

        // Don't hold up render tree construction and script execution on stylesheets
        // that are not needed for the rendering at the moment.
        bool isActive = mediaQueryMatches && !isAlternate();
        addPendingSheet(isActive ? ActiveSheet : InactiveSheet);

        // Load stylesheets that are not needed for the rendering immediately with low priority.
        Optional<ResourceLoadPriority> priority;
        if (!isActive)
            priority = ResourceLoadPriority::VeryLow;
        CachedResourceRequest request(url, charset, priority);
        request.setInitiator(this);

        if (document().contentSecurityPolicy()->allowStyleWithNonce(attributeWithoutSynchronization(HTMLNames::nonceAttr))) {
            ResourceLoaderOptions options = CachedResourceLoader::defaultCachedResourceOptions();
            options.contentSecurityPolicyImposition = ContentSecurityPolicyImposition::SkipPolicyCheck;
            request.setOptions(options);
        }
        request.setAsPotentiallyCrossOrigin(crossOrigin(), document());

        m_cachedSheet = document().cachedResourceLoader().requestCSSStyleSheet(request);

        if (m_cachedSheet)
            m_cachedSheet->addClient(this);
        else {
            // The request may have been denied if (for example) the stylesheet is local and the document is remote.
            m_loading = false;
            removePendingSheet();
        }
    } else if (m_sheet) {
        // we no longer contain a stylesheet, e.g. perhaps rel or type was changed
        clearSheet();
        document().styleResolverChanged(DeferRecalcStyle);
    }
}
Beispiel #7
0
/* virtual */ ES_PutState
JS_Location::PutName(OpAtom property_name, ES_Value* value, ES_Runtime* origining_runtime)
{
	if (GetName(property_name, NULL, origining_runtime) != GET_SUCCESS)
		return PUT_FAILED;

	FramesDocument *frames_doc = GetFramesDocument();
	if (!frames_doc)
		return PUT_SUCCESS;

	if (value->type != VALUE_STRING)
		return PUT_NEEDS_STRING;

	const uni_char *value_string = value->value.string;

	while (value_string[0] == ' ')
		++value_string;

	if (property_name == OP_ATOM_href)
		if (value_string[0] == '#')
			property_name = OP_ATOM_hash;
		else if (value_string[0] == '?')
			property_name = OP_ATOM_search;

	URL url;
	DocumentReferrer ref_url(GetStandardRefURL(frames_doc, origining_runtime));
	TempBuffer buffer;

	URL current_url = ref_url.url;
#ifdef SELFTEST
	if (!do_navigation)
		current_url = this->current_url;
#endif // SELFTEST

	switch (property_name)
	{
	case OP_ATOM_href:
	case OP_ATOM_protocol:
	case OP_ATOM_host:
	case OP_ATOM_hostname:
	case OP_ATOM_port:
	case OP_ATOM_pathname:
		BOOL allowed;
		if (OpStatus::IsError(OpSecurityManager::CheckSecurity(OpSecurityManager::DOM_ALLOWED_TO_NAVIGATE, static_cast<DOM_Runtime *>(origining_runtime), GetRuntime(), allowed)) ||
			!allowed)
			return PUT_SECURITY_VIOLATION;
	}

	switch (property_name)
	{
	case OP_ATOM_protocol:
	{
		unsigned length = uni_strlen(value_string);
		while (length > 0 && value_string[length - 1] == ':')
			length--;
		if (length > 0)
		{
			const uni_char *current_url_string = current_url.GetAttribute(URL::KUniName_Username_Password_NOT_FOR_UI).CStr();
			const uni_char *current_scheme_end = uni_strchr(current_url_string, ':');
			if (!current_scheme_end)
				return PUT_SUCCESS;

			PUT_FAILED_IF_ERROR(buffer.Append(value_string, length));
			PUT_FAILED_IF_ERROR(buffer.Append(current_scheme_end));

			url = GetEncodedURL(origining_runtime->GetFramesDocument(), buffer.GetStorage());

			BOOL allowed;
			if (url.Type() == URL_JAVASCRIPT)
				if (OpStatus::IsError(OpSecurityManager::CheckSecurity(OpSecurityManager::DOM_STANDARD, static_cast<DOM_Runtime *>(origining_runtime), GetRuntime(), allowed)) ||
				    !allowed)
					return PUT_SUCCESS;
		}
		break;
	}
	case OP_ATOM_host:
	{
		const uni_char *current_url_string = current_url.GetAttribute(URL::KUniName_Username_Password_NOT_FOR_UI).CStr();
		const uni_char *current_scheme_end = uni_strchr(current_url_string, ':');

		// URL must be an "authority-based URL"
		if (current_scheme_end && current_scheme_end[1] == '/' && current_scheme_end[2] == '/')
		{
			OpString hostname;
			PUT_FAILED_IF_ERROR(current_url.GetAttribute(URL::KUniHostName, hostname));
			/* Just bail if the URL doesn't have a hostname after all. */
			if (!hostname.CStr())
				return PUT_SUCCESS;

			uni_char *hostname_start = uni_strstr(current_url_string, hostname.CStr());
			OP_ASSERT(hostname_start);
			uni_char *hostname_end = hostname_start + hostname.Length();

			unsigned short port = current_url.GetAttribute(URL::KServerPort);
			if (port > 0 && *hostname_end == ':')
			{
				hostname_end++;
				while (uni_isdigit(*hostname_end))
					hostname_end++;
			}

			PUT_FAILED_IF_ERROR(buffer.Append(current_url_string, hostname_start - current_url_string));
			PUT_FAILED_IF_ERROR(buffer.Append(value_string));
			PUT_FAILED_IF_ERROR(buffer.Append(hostname_end));

			url = GetEncodedURL(origining_runtime->GetFramesDocument(), buffer.GetStorage());
		}
		break;
	}
	case OP_ATOM_hostname:
	{
		while (*value_string == '/')
			value_string++;

		const uni_char *current_url_string = current_url.GetAttribute(URL::KUniName_Username_Password_NOT_FOR_UI).CStr();
		const uni_char *current_scheme_end = uni_strchr(current_url_string, ':');

		// URL must be an "authority-based URL"
		if (*value_string && current_scheme_end && current_scheme_end[1] == '/' && current_scheme_end[2] == '/')
		{
			OpString hostname;
			PUT_FAILED_IF_ERROR(current_url.GetAttribute(URL::KUniHostName, hostname));
			/* Just bail if the URL doesn't have a hostname after all. */
			if (!hostname.CStr())
				return PUT_SUCCESS;

			uni_char *hostname_start = uni_strstr(current_url_string, hostname.CStr());
			OP_ASSERT(hostname_start);
			uni_char *hostname_end = hostname_start + hostname.Length();

			PUT_FAILED_IF_ERROR(buffer.Append(current_url_string, hostname_start - current_url_string));
			PUT_FAILED_IF_ERROR(buffer.Append(value_string));
			PUT_FAILED_IF_ERROR(buffer.Append(hostname_end));

			url = GetEncodedURL(origining_runtime->GetFramesDocument(), buffer.GetStorage());
		}
		break;
	}
	case OP_ATOM_port:
	{
		const uni_char *current_url_string = current_url.GetAttribute(URL::KUniName_Username_Password_NOT_FOR_UI).CStr();
		const uni_char *current_scheme_end = uni_strchr(current_url_string, ':');
		// URL must be an "authority-based URL"
		if (current_scheme_end && current_scheme_end[1] == '/' && current_scheme_end[2] == '/')
		{
			while (*value_string == '0')
				value_string++;

			int port = 0;
			if (uni_isdigit(*value_string))
				port = uni_atoi(value_string);

			if (port <= 0 || port > 65535)
				break;

			OpString hostname;
			PUT_FAILED_IF_ERROR(current_url.GetAttribute(URL::KUniHostName, hostname));
			/* Just bail if the URL doesn't have a hostname after all. */
			if (!hostname.CStr())
				return PUT_SUCCESS;

			uni_char *hostname_start = uni_strstr(current_scheme_end, hostname.CStr());
			OP_ASSERT(hostname_start);
			uni_char *hostname_end = hostname_start + hostname.Length();

			PUT_FAILED_IF_ERROR(buffer.Append(current_url_string, hostname_end - current_url_string));
			PUT_FAILED_IF_ERROR(buffer.Append(":"));
			if (*hostname_end == ':')
			{
				hostname_end++;
				while (uni_isdigit(*hostname_end))
					hostname_end++;
			}
			PUT_FAILED_IF_ERROR(buffer.AppendLong(port));
			PUT_FAILED_IF_ERROR(buffer.Append(hostname_end));

			url = GetEncodedURL(origining_runtime->GetFramesDocument(), buffer.GetStorage());
		}
		break;
	}
	case OP_ATOM_href:
	case OP_ATOM_pathname:
	{
		url = GetEncodedURL(origining_runtime->GetFramesDocument(), value_string);

		BOOL allowed;
		// Stricter security for javascript urls. It's possible this check should move into DocumentManager in the future.
		if (url.Type() == URL_JAVASCRIPT)
			if (OpStatus::IsError(OpSecurityManager::CheckSecurity(OpSecurityManager::DOM_STANDARD, static_cast<DOM_Runtime *>(origining_runtime), GetRuntime(), allowed)) ||
			    !allowed)
				return PUT_SUCCESS;

		break;
	}
	case OP_ATOM_search:
	{
		const uni_char *current_url_string = current_url.GetAttribute(URL::KUniName_Username_Password_NOT_FOR_UI).CStr();
		int current_len;

		const uni_char *current_search_start = uni_strchr(current_url_string, '?');
		if (current_search_start)
			current_len = current_search_start - current_url_string;
		else
			current_len = uni_strlen(current_url_string);

		if (value_string[0] == '?')
			++value_string;

		PUT_FAILED_IF_ERROR(buffer.Expand(current_len + uni_strlen(value_string) + 2));

		OpStatus::Ignore(buffer.Append(current_url_string, current_len)); // buffer is successfully expanded above
		OpStatus::Ignore(buffer.Append("?"));
		OpStatus::Ignore(buffer.Append(value_string));

		url = GetEncodedURL(origining_runtime->GetFramesDocument(), buffer.GetStorage());
		break;
	}
	case OP_ATOM_hash:
		if (value_string[0] == '#')
			++value_string;

		// Strip trailing whitespace
		if (unsigned length = uni_strlen(value_string))
		{
			if (value_string[length - 1] == ' ')
			{
				PUT_FAILED_IF_ERROR(buffer.Append(value_string));

				uni_char *string = buffer.GetStorage();

				while (length > 0 && string[length - 1] == ' ')
					--length;

				string[length] = 0;
				value_string = string;
			}
		}

#ifdef SELFTEST
		url = URL(!do_navigation ? current_url : frames_doc->GetURL(), value_string);
#else
		url = URL(frames_doc->GetURL(), value_string);
#endif // SELFTEST
		break;
	}

	if (url.Type() != URL_NULL_TYPE)
	{
#ifdef GADGET_SUPPORT
		switch (property_name)
		{
		case OP_ATOM_href:
		case OP_ATOM_protocol:
		case OP_ATOM_host:
		case OP_ATOM_hostname:
		case OP_ATOM_port:
		case OP_ATOM_pathname:
		{
			BOOL allowed;
			if (frames_doc->GetWindow()->GetGadget())
				if (OpStatus::IsError(OpSecurityManager::CheckSecurity(OpSecurityManager::GADGET_ALLOWED_TO_NAVIGATE, OpSecurityContext(frames_doc), url, allowed)) || !allowed)
					return PUT_SECURITY_VIOLATION;
		}
		}
#endif // GADGET_SUPPORT
		return SetTheURL(frames_doc, ref_url, url, GetCurrentThread(origining_runtime), property_name == OP_ATOM_hash);
	}
	else
		return PUT_SUCCESS;
}
Beispiel #8
0
bool u_test(URL test, string p, string h, string po, string d="", string u="", string pa="", string i="") {
  if(test.get_protocol() != p) { test.dump(); return fail("protocol", p, test.get_protocol()); }
  if(test.get_host() != h) { test.dump(); return fail("host", h, test.get_host()); }
  if(test.get_port() != po) { test.dump(); return fail("port", po, test.get_port()); }
  if(test.get_user() != u) { test.dump(); return fail("user", u, test.get_user()); }
  if(test.get_params() != pa) { test.dump(); return fail("params", pa, test.get_params()); }
  if(test.get_destination() != d) { test.dump(); return fail("destination/path", d, test.get_destination()); }
  if(test.get_index() != i) { test.dump(); return fail("index/hash", i, test.get_index()); }
}
void MixedContentChecker::logWarning(bool allowed, const String& action, const URL& target) const
{
    String message = makeString((allowed ? "" : "[blocked] "), "The page at ", m_frame.document()->url().stringCenterEllipsizedToLength(), " ", action, " insecure content from ", target.stringCenterEllipsizedToLength(), ".\n");
    m_frame.document()->addConsoleMessage(MessageSource::Security, MessageLevel::Warning, message);
}
OP_STATUS ContentBlockFilterCreation::CreateFilterFromURL(URL& homeurl, const uni_char *url, OpString& result)
{
	if(uni_stristr(url, (const char *)"*"))
	{
		return result.Set(url);
	}

	/*
	** Start of code to create patterned URLs to block
	*/
	// handle flash: http://flash.vg.no/annonser/startour/startour_restplass.swf
	const uni_char *swf = NULL;

	swf = uni_stristr(url, (const char *)"swf");
	if(swf == NULL)
	{
		swf = url + uni_strlen(url);
	}
	if(swf)
	{
		while(swf-- != url)
		{
			// search back to the last slash
			if(*swf == '/')
			{
				swf++;
				break;
			}
		}
		if(swf != url)
		{
			// we should now have http://flash.vg.no/annonser/startour/*
			// let's see if we can shorten it down a bit
			int count = CountCharacters(url, '/', swf - url);
			if(count > 4)
			{
				swf--;
				// too long path, let's shorten it down to 2 levels (after http://)
				while(swf-- != url)
				{
					// search back to the last slash
					if(*swf == '/')
					{
						if(--count == 4)
						{
							swf++;
							break;
						}
					}
				}
			}
			result.Empty();
			if(count < 4)
			{
				if(OpStatus::IsError(result.Append(url)))
				{
					return OpStatus::ERR_NO_MEMORY;
				}

			}
			else
			{
				if(OpStatus::IsError(result.Append(url, swf - url)))
				{
					return OpStatus::ERR_NO_MEMORY;
				}
			}
			BOOL go_on = TRUE;

			while(go_on)
			{
				OpString homeurl_string;
				RETURN_IF_ERROR(homeurl.GetAttribute(URL::KUniName_Username_Password_Hidden, homeurl_string));
				if(result.Compare(homeurl_string.CStr(), result.Length()) == 0)
				{
					BOOL slash_found = FALSE;
					// matches main page url, we can't have that
					while(*swf++)
					{
						// search back to the last slash
						if(*swf == '/')
						{
							swf++;
							result.Empty();
							if(OpStatus::IsError(result.Append(url, swf - url)))
							{
								return OpStatus::ERR_NO_MEMORY;
							}
							slash_found = TRUE;
							break;
						}
					}
					if(!slash_found)
					{
						result.Empty();
						if(OpStatus::IsError(result.Append(url, swf - url)))
						{
							return OpStatus::ERR_NO_MEMORY;
						}
						go_on = FALSE;
					}
				}
				else
				{
					go_on = FALSE;
				}

			}
		}
	}
	if(result[result.Length() - 1] != '*')
	{
		result.Append(UNI_L("*"));
	}
	return OpStatus::OK;
}
void CookieManager::getRawCookies(Vector<RefPtr<ParsedCookie> > &stackOfCookies, const URL& requestURL, CookieFilter filter) const
{
    // Force a sync load of the database
    if (!m_syncedWithDatabase && !m_privateMode)
        m_cookieBackingStore->openAndLoadDatabaseSynchronously(cookieJar());

    CookieLog("CookieManager - getRawCookies - processing url with domain - %s & protocol: %s & path: %s\n", requestURL.host().utf8().data(), requestURL.protocol().utf8().data(), requestURL.path().utf8().data());

    const bool invalidScheme = shouldIgnoreScheme(requestURL.protocol());
    const bool specialCaseForWebWorks = invalidScheme && m_shouldDumpAllCookies;
    const bool isConnectionSecure = requestURL.protocolIs("https") || requestURL.protocolIs("wss") || specialCaseForWebWorks;

    Vector<RefPtr<ParsedCookie> > cookieCandidates;
    Vector<CookieMap*> protocolsToSearch;

    // Special Case: If a server sets a "secure" cookie over a non-secure channel and tries to access the cookie
    // over a secure channel, it will not succeed because the secure protocol isn't mapped to the insecure protocol yet.
    // Set the map to the non-secure version, so it'll search the mapping for a secure cookie.
    CookieMap* targetMap = m_managerMap.get(requestURL.protocol());
    if (!targetMap && isConnectionSecure) {
        CookieLog("CookieManager - special case: secure protocol are not linked yet.");
        if (requestURL.protocolIs("https"))
            targetMap = m_managerMap.get("http");
        else if (requestURL.protocolIs("wss"))
            targetMap = m_managerMap.get("ws");
    }

    // Decide which scheme tree we should look at.
    // Return on invalid schemes. cookies are currently disabled on file and local.
    // We only want to enable them for WebWorks that enabled a special flag.
    if (specialCaseForWebWorks)
        copyValuesToVector(m_managerMap, protocolsToSearch);
    else if (invalidScheme)
        return;
    else {
        protocolsToSearch.append(targetMap);
        // FIXME: this is a hack for webworks apps; RFC 6265 says "Cookies do not provide isolation by scheme"
        // so we should not be checking protocols at all. See PR 135595
        if (m_shouldDumpAllCookies) {
            protocolsToSearch.append(m_managerMap.get("file"));
            protocolsToSearch.append(m_managerMap.get("local"));
        }
    }

    Vector<String> delimitedHost;

    // IP addresses are stored in a particular format (due to ipv6). Reduce the ip address so we can match
    // it with the one in memory.
    BlackBerry::Platform::String canonicalIP = BlackBerry::Platform::getCanonicalIPFormat(requestURL.host());
    if (!canonicalIP.empty())
        delimitedHost.append(String(canonicalIP.c_str()));
    else
        requestURL.host().lower().split(".", true, delimitedHost);

    // Go through all the protocol trees that we need to search for
    // and get all cookies that are valid for this domain
    for (size_t k = 0; k < protocolsToSearch.size(); k++) {
        CookieMap* currentMap = protocolsToSearch[k];

        // if no cookies exist for this protocol, break right away
        if (!currentMap)
            continue;

        CookieLog("CookieManager - looking at protocol map %s \n", currentMap->getName().utf8().data());

        // Special case for local and files - because WebApps expect to get ALL cookies from the backing-store on local protocol
        if (specialCaseForWebWorks) {
            CookieLog("CookieManager - special case find in protocol map - %s\n", currentMap->getName().utf8().data());
            currentMap->getAllChildCookies(&cookieCandidates);
        } else {
            // Get cookies from the null domain map
            currentMap->getAllCookies(&cookieCandidates);

            // Get cookies from Host-only cookies
            if (canonicalIP.empty()) {
                CookieLog("CookieManager - looking for host-only cookies for host - %s", requestURL.host().utf8().data());
                CookieMap* hostMap = currentMap->getSubdomainMap(requestURL.host());
                if (hostMap)
                    hostMap->getAllCookies(&cookieCandidates);
            }

            // Get cookies from the valid domain maps
            int i = delimitedHost.size() - 1;
            while (i >= 0) {
                CookieLog("CookieManager - finding %s in currentmap\n", delimitedHost[i].utf8().data());
                currentMap = currentMap->getSubdomainMap(delimitedHost[i]);
                // if this subdomain/domain does not exist in our mapping then we simply exit
                if (!currentMap) {
                    CookieLog("CookieManager - cannot find next map exiting the while loop.\n");
                    break;
                }
                CookieLog("CookieManager - found the map, grabbing cookies from this map\n");
                currentMap->getAllCookies(&cookieCandidates);
                i--;
            }
        }
    }

    CookieLog("CookieManager - there are %d cookies in candidate\n", cookieCandidates.size());

    for (size_t i = 0; i < cookieCandidates.size(); ++i) {
        RefPtr<ParsedCookie> cookie = cookieCandidates[i];

        // According to the path-matches rules in RFC6265, section 5.1.4,
        // we should add a '/' at the end of cookie-path for comparison if the cookie-path is not end with '/'.
        String path = cookie->path();
        CookieLog("CookieManager - comparing cookie path %s (len %d) to request path %s (len %d)", path.utf8().data(), path.length(), requestURL.path().utf8().data(), path.length());
        if (!equalIgnoringCase(path, requestURL.path()) && !path.endsWith("/", false))
            path = path + "/";

        // Only secure connections have access to secure cookies. Unless specialCaseForWebWorks is true.
        // Get the cookies filtering out HttpOnly cookies if requested.
        if (requestURL.path().startsWith(path, false) && (isConnectionSecure || !cookie->isSecure()) && (filter == WithHttpOnlyCookies || !cookie->isHttpOnly())) {
            CookieLog("CookieManager - cookie chosen - %s\n", cookie->toString().utf8().data());
            cookie->setLastAccessed(currentTime());
            stackOfCookies.append(cookie);
        }
    }

    std::stable_sort(stackOfCookies.begin(), stackOfCookies.end(), cookieSorter);
}
Beispiel #12
0
/**	Verify signed file
 *	The function will return FALSE if signature fails or if any errors occur,
 *
 *	@param	signed_file		URL containing the file to be verified. MUST be loaded,
 *							which can be accomplished with signed_file.QuickLoad(TRUE)
 *	@param	signature		Base64 encoded signature
 *
 *	@param	key				Pointer to buffer containing the DER encoded public key associated
 *							with the private key used to generate the signature, MUST be an
 *							X509_PUBKEY structure (openssl rsa -pubout ... command result)
 *	@param	key_len			Length of the public key buffer
 *
 *	@param  alg				Algorithm used to calculate signature. Default SSL_SHA
 *
 *	@return TRUE if the verification succeded, FALSE if there was any error.
 */
BOOL VerifySignedFile(URL &signed_file, const OpStringC8 &signature, const unsigned char *key, unsigned long key_len, SSL_HashAlgorithmType alg)
{

    if(signed_file.IsEmpty() || (URLStatus) signed_file.GetAttribute(URL::KLoadStatus) != URL_LOADED || key == NULL || key_len == 0)
        return FALSE;

    // Get The raw data
    OpAutoPtr<URL_DataDescriptor> desc(signed_file.GetDescriptor(NULL, TRUE, TRUE, TRUE));
    if(!desc.get())
        return FALSE;

    BOOL more = FALSE;
    unsigned long buf_len;

    if(desc->RetrieveData(more) == 0 || desc->GetBuffer() == NULL)
        return FALSE;

    if(desc->GetBufSize() == 0)
        return FALSE;

    if(signature.Length() <= 0)
        return FALSE;

    unsigned long signature_len = signature.Length();

    SSL_varvector32 signature_in;

    signature_in.Resize(signature_len);
    if(signature_in.Error())
        return FALSE;

    unsigned long read_len=0;
    BOOL warning= FALSE;
    buf_len = GeneralDecodeBase64((unsigned char *)signature.CStr(), signature_len, read_len, signature_in.GetDirect(), warning);

    if(warning || read_len != signature_len || buf_len == 0)
        return FALSE;

    signature_in.Resize(buf_len);

    SSL_Hash_Pointer digester(alg);
    if(digester.Error())
        return FALSE;

    digester->InitHash();

    do {
        more = FALSE;
        buf_len = desc->RetrieveData(more);

        digester->CalculateHash((unsigned char *)desc->GetBuffer(), buf_len);

        desc->ConsumeData(buf_len);
    } while(more);

    SSL_varvector32 signature_out;

    digester->ExtractHash(signature_out);

    if(digester->Error() || signature_out.Error())
        return FALSE;

    OpAutoPtr<SSL_PublicKeyCipher> signature_checker;

    OP_STATUS op_err = OpStatus::OK;
    signature_checker.reset(g_ssl_api->CreatePublicKeyCipher(SSL_RSA, op_err));

    if(OpStatus::IsError(op_err) || signature_checker.get() == NULL)
        return FALSE;

    SSL_varvector32 pubkey_bin_ex;

    pubkey_bin_ex.SetExternal((unsigned char *) key);
    pubkey_bin_ex.Resize(key_len);

    signature_checker->LoadAllKeys(pubkey_bin_ex);

    if(signature_checker->Error())
        return FALSE;

    if(alg == SSL_SHA)
    {
        if(!signature_checker->Verify(signature_out.GetDirect(), signature_out.GetLength(), signature_in.GetDirect(), signature_in.GetLength()))
            return FALSE;
    }
#ifdef USE_SSL_ASN1_SIGNING
    else
    {
        if(!signature_checker->VerifyASN1(digester, signature_in.GetDirect(), signature_in.GetLength()))
            return FALSE;
    }
#endif

    if(signature_checker->Error())
        return FALSE;

    return TRUE;
}
Beispiel #13
0
/**	Verify checksum
 *	The function will return FALSE if verification fails or if any errors occur,
 *
 *	@param	signed_file		URL containing the file to be verified. MUST be loaded,
 *							which can be accomplished with signed_file.QuickLoad(TRUE)
 *	@param	checksum		Base64 encoded checksum
 *
 *	@param  alg				Algorithm used to calculate checksum. Default SSL_SHA
 *
 *	@return TRUE if the verification succeded, FALSE if there was any error.
 */
BOOL VerifyChecksum(URL &signed_file, const OpStringC8 &checksum, SSL_HashAlgorithmType alg)
{

    if(signed_file.IsEmpty() || (URLStatus) signed_file.GetAttribute(URL::KLoadStatus) != URL_LOADED)
        return FALSE;

    // Get The raw data
    OpAutoPtr<URL_DataDescriptor> desc(signed_file.GetDescriptor(NULL, TRUE, TRUE, TRUE));
    if(!desc.get())
        return FALSE;

    BOOL more = FALSE;
    unsigned long buf_len;

    if(desc->RetrieveData(more) == 0 || desc->GetBuffer() == NULL)
        return FALSE;

    if(desc->GetBufSize() == 0)
        return FALSE;

    SSL_Hash_Pointer digester(alg);
    if(digester.Error())
        return FALSE;

    digester->InitHash();

    do {
        more = FALSE;
        buf_len = desc->RetrieveData(more);

        digester->CalculateHash((unsigned char *)desc->GetBuffer(), buf_len);

        desc->ConsumeData(buf_len);
    } while(more);

    SSL_varvector32 signature_out;

    digester->ExtractHash(signature_out);

    if(digester->Error() || signature_out.Error())
        return FALSE;

#ifdef _DEBUG
    OpString8 s8;
    OP_STATUS retval = ByteToHexStr(signature_out.GetDirect(), signature_out.GetLength(), s8);
    OP_ASSERT(retval == OpStatus::OK);
#endif

    byte* byte_buffer = NULL;
    unsigned int buffer_len = 0;
    OP_STATUS ret = HexStrToByte(checksum, byte_buffer, buffer_len);
    if(OpStatus::IsError(ret))
        return FALSE;

    SSL_varvector32 signature_in;
    signature_in.Set(byte_buffer, buffer_len);

    OP_DELETEA(byte_buffer);

    return signature_in == signature_out;
}
Beispiel #14
0
static void logCanCachePageDecision(Page& page)
{
    // Only bother logging for main frames that have actually loaded and have content.
    if (page.mainFrame().loader().stateMachine().creatingInitialEmptyDocument())
        return;
    URL currentURL = page.mainFrame().loader().documentLoader() ? page.mainFrame().loader().documentLoader()->url() : URL();
    if (currentURL.isEmpty())
        return;
    
    unsigned indentLevel = 0;
    PCLOG("--------\n Determining if page can be cached:");
    
    unsigned rejectReasons = 0;
    MainFrame& mainFrame = page.mainFrame();
    DiagnosticLoggingClient& diagnosticLoggingClient = mainFrame.diagnosticLoggingClient();
    unsigned frameRejectReasons = logCanCacheFrameDecision(mainFrame, diagnosticLoggingClient, indentLevel + 1);
    if (frameRejectReasons)
        rejectReasons |= 1 << FrameCannotBeInPageCache;
    
    if (!page.settings().usesPageCache()) {
        PCLOG("   -Page settings says b/f cache disabled");
        rejectReasons |= 1 << DisabledPageCache;
    }
#if ENABLE(DEVICE_ORIENTATION) && !PLATFORM(IOS)
    if (DeviceMotionController::isActiveAt(page)) {
        PCLOG("   -Page is using DeviceMotion");
        logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::deviceMotionKey());
        rejectReasons |= 1 << UsesDeviceMotion;
    }
    if (DeviceOrientationController::isActiveAt(page)) {
        PCLOG("   -Page is using DeviceOrientation");
        logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::deviceOrientationKey());
        rejectReasons |= 1 << UsesDeviceOrientation;
    }
#endif
#if ENABLE(PROXIMITY_EVENTS)
    if (DeviceProximityController::isActiveAt(page)) {
        PCLOG("   -Page is using DeviceProximity");
        logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, deviceProximityKey);
        rejectReasons |= 1 << UsesDeviceMotion;
    }
#endif
    FrameLoadType loadType = page.mainFrame().loader().loadType();
    if (loadType == FrameLoadType::Reload) {
        PCLOG("   -Load type is: Reload");
        logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::reloadKey());
        rejectReasons |= 1 << IsReload;
    }
    if (loadType == FrameLoadType::ReloadFromOrigin) {
        PCLOG("   -Load type is: Reload from origin");
        logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::reloadFromOriginKey());
        rejectReasons |= 1 << IsReloadFromOrigin;
    }
    if (loadType == FrameLoadType::Same) {
        PCLOG("   -Load type is: Same");
        logPageCacheFailureDiagnosticMessage(diagnosticLoggingClient, DiagnosticLoggingKeys::sameLoadKey());
        rejectReasons |= 1 << IsSameLoad;
    }
    
    if (rejectReasons)
        PCLOG(" Page CANNOT be cached\n--------");
    else
        PCLOG(" Page CAN be cached\n--------");

    diagnosticLoggingClient.logDiagnosticMessageWithResult(DiagnosticLoggingKeys::pageCacheKey(), emptyString(), rejectReasons ? DiagnosticLoggingResultFail : DiagnosticLoggingResultPass, ShouldSample::Yes);
}
Beispiel #15
0
// TODO(bmahler): Leverage process::http::URL for equality.
bool operator==(const URL& left, const URL& right)
{
  return left.SerializeAsString() == right.SerializeAsString();
}
Beispiel #16
0
  bool JobControllerPluginEMIES::GetURLToJobResource(const Job& job, Job::ResourceType resource, URL& url) const {
    if (resource == Job::JOBDESCRIPTION) {
      return false;
    }
    
    // Obtain information about staging urls
    EMIESJob ejob;
    ejob = job;
    URL stagein;
    URL stageout;
    URL session;
    // TODO: currently using first valid URL. Need support for multiple.
    for(std::list<URL>::iterator s = ejob.stagein.begin();s!=ejob.stagein.end();++s) {
      if(*s) { stagein = *s; break; }
    }
    for(std::list<URL>::iterator s = ejob.stageout.begin();s!=ejob.stageout.end();++s) {
      if(*s) { stageout = *s; break; }
    }
    for(std::list<URL>::iterator s = ejob.session.begin();s!=ejob.session.end();++s) {
      if(*s) { session = *s; break; }
    }

    if ((resource != Job::STAGEINDIR  || !stagein)  &&
        (resource != Job::STAGEOUTDIR || !stageout) &&
        (resource != Job::SESSIONDIR  || !session)) {
      // If there is no needed URL provided try to fetch it from server
      MCCConfig cfg;
      usercfg.ApplyToConfig(cfg);
      Job tjob;
      AutoPointer<EMIESClient> ac(((EMIESClients&)clients).acquire(ejob.manager));
      if (!ac->info(ejob, tjob)) {
        ((EMIESClients&)clients).release(ac.Release());
        logger.msg(INFO, "Failed retrieving information for job: %s", job.JobID);
        return false;
      }
      for(std::list<URL>::iterator s = ejob.stagein.begin();s!=ejob.stagein.end();++s) {
        if(*s) { stagein = *s; break; }
      }
      for(std::list<URL>::iterator s = ejob.stageout.begin();s!=ejob.stageout.end();++s) {
        if(*s) { stageout = *s; break; }
      }
      for(std::list<URL>::iterator s = ejob.session.begin();s!=ejob.session.end();++s) {
        if(*s) { session = *s; break; }
      }
      // Choose url by state
      // TODO: maybe this method should somehow know what is purpose of URL
      // TODO: state attributes would be more suitable
      // TODO: library need to be etended to allow for multiple URLs
      if((tjob.State == JobState::ACCEPTED) ||
         (tjob.State == JobState::PREPARING)) {
        url = stagein;
      } else if((tjob.State == JobState::DELETED) ||
                (tjob.State == JobState::FAILED) ||
                (tjob.State == JobState::KILLED) ||
                (tjob.State == JobState::FINISHED) ||
                (tjob.State == JobState::FINISHING)) {
        url = stageout;
      } else {
        url = session;
      }
      // If no url found by state still try to get something
      if(!url) {
        if(session)  url = session;
        if(stagein)  url = stagein;
        if(stageout) url = stageout;
      }
      ((EMIESClients&)clients).release(ac.Release());
    }
    
    switch (resource) {
    case Job::STDIN:
      url.ChangePath(url.Path() + '/' + job.StdIn);
      break;
    case Job::STDOUT:
      url.ChangePath(url.Path() + '/' + job.StdOut);
      break;
    case Job::STDERR:
      url.ChangePath(url.Path() + '/' + job.StdErr);
      break;
    case Job::JOBLOG:
      url.ChangePath(url.Path() + "/" + job.LogDir + "/errors");
      break;
    case Job::STAGEINDIR:
      if(stagein) url = stagein;
      break;
    case Job::STAGEOUTDIR:
      if(stageout) url = stageout;
      break;
    case Job::SESSIONDIR:
      if(session) url = session;
      break;
    default:
      break;
    }
    if(url && ((url.Protocol() == "https") || (url.Protocol() == "http"))) {
      url.AddOption("threads=2",false);
      url.AddOption("encryption=optional",false);
      // url.AddOption("httpputpartial=yes",false); - TODO: use for A-REX
    }

    return true;
  }
Beispiel #17
0
RefPtr<LegacyWebArchive> LegacyWebArchive::create(const String& markupString, Frame& frame, const Vector<Node*>& nodes, std::function<bool (Frame&)> frameFilter)
{
    const ResourceResponse& response = frame.loader().documentLoader()->response();
    URL responseURL = response.url();
    
    // it's possible to have a response without a URL here
    // <rdar://problem/5454935>
    if (responseURL.isNull())
        responseURL = URL(ParsedURLString, emptyString());

    RefPtr<ArchiveResource> mainResource = ArchiveResource::create(utf8Buffer(markupString), responseURL, response.mimeType(), "UTF-8", frame.tree().uniqueName());
    if (!mainResource)
        return nullptr;

    Vector<RefPtr<LegacyWebArchive>> subframeArchives;
    Vector<RefPtr<ArchiveResource>> subresources;
    HashSet<URL> uniqueSubresources;

    size_t nodesSize = nodes.size();    
    for (size_t i = 0; i < nodesSize; ++i) {
        Node& node = *nodes[i];
        Frame* childFrame;
        if ((is<HTMLFrameElementBase>(node) || is<HTMLObjectElement>(node))
            && (childFrame = downcast<HTMLFrameOwnerElement>(node).contentFrame())) {
            if (frameFilter && !frameFilter(*childFrame))
                continue;
                
            if (RefPtr<LegacyWebArchive> subframeArchive = create(*childFrame->document(), frameFilter))
                subframeArchives.append(WTFMove(subframeArchive));
            else
                LOG_ERROR("Unabled to archive subframe %s", childFrame->tree().uniqueName().string().utf8().data());

        } else {
            ListHashSet<URL> subresourceURLs;
            node.getSubresourceURLs(subresourceURLs);
            
            DocumentLoader* documentLoader = frame.loader().documentLoader();

            for (const auto& subresourceURL : subresourceURLs) {
                if (uniqueSubresources.contains(subresourceURL))
                    continue;

                uniqueSubresources.add(subresourceURL);

                if (RefPtr<ArchiveResource> resource = documentLoader->subresource(subresourceURL)) {
                    subresources.append(WTFMove(resource));
                    continue;
                }

                ResourceRequest request(subresourceURL);
#if ENABLE(CACHE_PARTITIONING)
                request.setDomainForCachePartition(frame.document()->topOrigin()->domainForCachePartition());
#endif
                CachedResource* cachedResource = MemoryCache::singleton().resourceForRequest(request, frame.page()->sessionID());
                if (cachedResource) {
                    if (RefPtr<ArchiveResource> resource = ArchiveResource::create(cachedResource->resourceBuffer(), subresourceURL, cachedResource->response())) {
                        subresources.append(WTFMove(resource));
                        continue;
                    }
                }

                // FIXME: should do something better than spew to console here
                LOG_ERROR("Failed to archive subresource for %s", subresourceURL.string().utf8().data());
            }
        }
    }

    // Add favicon if one exists for this page, if we are archiving the entire page.
    if (nodesSize && nodes[0]->isDocumentNode() && iconDatabase().isEnabled()) {
        const String& iconURL = iconDatabase().synchronousIconURLForPageURL(responseURL);
        if (!iconURL.isEmpty() && iconDatabase().synchronousIconDataKnownForIconURL(iconURL)) {
            if (Image* iconImage = iconDatabase().synchronousIconForPageURL(responseURL, IntSize(16, 16))) {
                if (RefPtr<ArchiveResource> resource = ArchiveResource::create(iconImage->data(), URL(ParsedURLString, iconURL), "image/x-icon", "", ""))
                    subresources.append(resource.release());
            }
        }
    }

    return create(WTFMove(mainResource), WTFMove(subresources), WTFMove(subframeArchives));
}
Beispiel #18
0
static inline void addVisitedLink(Page* page, const URL& url)
{
    platformStrategies()->visitedLinkStrategy()->addVisitedLink(page, visitedLinkHash(url.string()));
}
Beispiel #19
0
/* virtual */ ES_GetState
JS_Location::GetName(OpAtom property_name, ES_Value* value, ES_Runtime* origining_runtime)
{
	TempBuffer *buffer = GetEmptyTempBuf();
	URL url;

	if (fakewindow)
		url = fakewindow->GetURL();
#ifdef SELFTEST
	else if (!do_navigation)
		url = current_url;
#endif // SELFTEST
	else if (FramesDocument *frames_doc = GetFramesDocument())
	{
		url = frames_doc->GetURL();

		// The anchors (hash) might be better in DocumentManager
		URL doc_man_url = frames_doc->GetDocManager()->GetCurrentURL();
		if (doc_man_url == url) // Doesn't compare anchors
			url = doc_man_url;
	}
#ifdef DOM_WEBWORKERS_SUPPORT
	/* No FramesDocument to query, so consult the origin DocumentManager for the Worker */
	if (!GetFramesDocument())
	{
		DOM_WebWorkerController *web_workers = GetEnvironment()->GetWorkerController();
		if (DOM_WebWorker *ww = web_workers->GetWorkerObject())
			url = ww->GetLocationURL();
		else if (DocumentManager *doc = web_workers->GetWorkerDocManager())
			url = doc->GetCurrentURL();
		OP_ASSERT(!url.IsEmpty());
	}
#endif // DOM_WEBWORKERS_SUPPORT

	switch (property_name)
	{
	case OP_ATOM_href:
		DOMSetString(value, url.GetAttribute(URL::KUniName_With_Fragment_Escaped).CStr());
		return GET_SUCCESS;

	case OP_ATOM_protocol:
		if (value)
		{
			const char *protocol = url.GetAttribute(URL::KProtocolName).CStr();
			if (protocol)
			{
				GET_FAILED_IF_ERROR(buffer->Append(protocol));
				GET_FAILED_IF_ERROR(buffer->Append(":"));
			}

			DOMSetString(value, buffer);
		}
		return GET_SUCCESS;

	case OP_ATOM_host:
	case OP_ATOM_hostname:
		if (value)
		{
			const uni_char *name = url.GetServerName() ? url.GetServerName()->UniName() : NULL;

			if (property_name == OP_ATOM_host)
			{
				unsigned short port = url.GetServerPort();
				if (port)
				{
					GET_FAILED_IF_ERROR(buffer->Append(name));
					GET_FAILED_IF_ERROR(buffer->Append(":"));
					GET_FAILED_IF_ERROR(buffer->AppendUnsignedLong(port));
					name = buffer->GetStorage();
				}
			}

			DOMSetString(value, name);
		}
		return GET_SUCCESS;

	case OP_ATOM_port:
		if (value)
		{
			unsigned short port = url.GetServerPort();
			if (port)
				GET_FAILED_IF_ERROR(buffer->AppendUnsignedLong(port));

			DOMSetString(value, buffer);
		}
		return GET_SUCCESS;

	case OP_ATOM_pathname:
		if (value)
		{
			const uni_char *path = url.GetAttribute(URL::KUniPath).CStr();

			if (path)
			{
				GET_FAILED_IF_ERROR(buffer->Append(path));
				uni_char *path_tmp = buffer->GetStorage();

				/* It isn't obvious from the JS spec and the relevant RFC, but in
				   Javascript the 'pathname' excludes any arguments passed to the page. */
				if (uni_char *query_start = uni_strchr(path_tmp, '?'))
				{
					path = path_tmp;
					*query_start = 0;
				}
			}

			DOMSetString(value, path);
		}
		return GET_SUCCESS;

	case OP_ATOM_search:
		if (value)
		{
			const uni_char *name = url.GetAttribute(URL::KUniName).CStr();

			if (name)
				name = uni_strchr(name, '?');

			DOMSetString(value, name);
		}
		return GET_SUCCESS;

	case OP_ATOM_hash:
		if (value)
		{
			const uni_char *fragment = url.UniRelName();

			// MSIE emits "#" for the empty fragment (as in http://www.opera.com/# ) but no other
			// browser does that and neither will we.
			if (fragment && *fragment)
			{
				GET_FAILED_IF_ERROR(buffer->Append('#'));
				GET_FAILED_IF_ERROR(buffer->Append(fragment));
				fragment = buffer->GetStorage();
			}

			DOMSetString(value, fragment);
		}
		return GET_SUCCESS;
	}

	return GET_FAILED;
}
bool DirectShowComponent::loadMovie (const URL& videoURL)
{
    return loadMovie (videoURL.toString (false));
}
Beispiel #21
0
BOOL
JS_Location::OpenURL(URL &url, DocumentReferrer ref_url, BOOL is_reload, BOOL is_replace, ES_Thread* origin_thread)
{
	if (fakewindow)
	{
		fakewindow->SetURL(url, ref_url);
		return TRUE;
	}
#ifdef SELFTEST
	if (!do_navigation)
	{
		current_url = url;
		return TRUE;
	}
#endif // SELFTEST

	if (FramesDocument *frames_doc = GetFramesDocument())
	{
		if (frames_doc->IsRestoringFormState(origin_thread))
			/* We really do not want this to submit the form as a side-effect. */
			return TRUE;

		frames_doc->SignalFormChangeSideEffect(origin_thread);

		EnteredByUser entered_by_user;

		if (url.Type() == URL_JAVASCRIPT)
		{
			/* ESOpenURL will do nothing when a javascript URL is reloaded.
		       If is_replace is TRUE however, this was a call to location.replace,
		       and is_reload is set there because that works a little better, the
		       user/script didn't actually request a reload. */
			if (is_replace)
				is_reload = FALSE;

			/* Note: Using WasEnteredByUser here to bypass incompetent security
			   check in ESOpenURL; we've already performed a more competent
			   security check and concluded the operation is permissable. */
			entered_by_user = WasEnteredByUser;
		}
		else
			entered_by_user = NotEnteredByUser;

		// Sandboxed documents may not navigate anywhere.
		if (ref_url.origin && ref_url.origin->IsUniqueOrigin())
			return TRUE;

		if (JS_Window::IsUnrequestedPopup(origin_thread))
			switch (url.Type())
			{
			case URL_MAILTO:
				return TRUE;
			}

		ES_ThreadInfo info = origin_thread->GetOriginInfo();
		BOOL user_initiated = info.is_user_requested && !info.has_opened_url;
		origin_thread->SetHasOpenedURL(); // It has now consumed its chance to be bad

		/* Automatically replace if an inline script or window.onload event handler
		 * redirects via location.href/location.assign(), but only if it comes from the same thread
		 * as the origin, to prevent things like an iframe redirecting the parent and losing the
		 * original history position. */
		if (!is_reload && !is_replace && origin_thread == frames_doc->GetESScheduler()->GetCurrentThread())
		{
			// Reuse the current history position if this is done during the load phase.
			if (DOM_Utils::IsInlineScriptOrWindowOnLoad(origin_thread))
				is_replace = TRUE;
		}

		DocumentManager::OpenURLOptions options;
		options.user_initiated = user_initiated;
		options.entered_by_user = entered_by_user;
		options.is_walking_in_history = FALSE;
		options.origin_thread = origin_thread;
		if (OpStatus::IsMemoryError(frames_doc->ESOpenURL(url, ref_url, TRUE, is_reload, is_replace, options)))
			return FALSE;
	}

	return TRUE;
}
Beispiel #22
0
void HTMLLinkElement::process()
{
    if (!inDocument() || m_isInShadowTree) {
        ASSERT(!m_sheet);
        return;
    }

    String type = m_type.lower();
    URL url = getNonEmptyURLAttribute(hrefAttr);

    if (!m_linkLoader.loadLink(m_relAttribute, type, m_sizes->toString(), url, &document()))
        return;

    bool acceptIfTypeContainsTextCSS = document().page() && document().page()->settings().treatsAnyTextCSSLinkAsStylesheet();

    if (m_disabledState != Disabled && (m_relAttribute.m_isStyleSheet || (acceptIfTypeContainsTextCSS && type.contains("text/css")))
        && document().frame() && url.isValid()) {
        
        String charset = getAttribute(charsetAttr);
        if (charset.isEmpty() && document().frame())
            charset = document().charset();
        
        if (m_cachedSheet) {
            removePendingSheet();
            m_cachedSheet->removeClient(this);
            m_cachedSheet = 0;
        }

        if (!shouldLoadLink())
            return;

        m_loading = true;

        bool mediaQueryMatches = true;
        if (!m_media.isEmpty()) {
            RefPtr<RenderStyle> documentStyle = Style::resolveForDocument(document());
            RefPtr<MediaQuerySet> media = MediaQuerySet::createAllowingDescriptionSyntax(m_media);
            MediaQueryEvaluator evaluator(document().frame()->view()->mediaType(), document().frame(), documentStyle.get());
            mediaQueryMatches = evaluator.eval(media.get());
        }

        // Don't hold up render tree construction and script execution on stylesheets
        // that are not needed for the rendering at the moment.
        bool isActive = mediaQueryMatches && !isAlternate();
        addPendingSheet(isActive ? ActiveSheet : InactiveSheet);

        // Load stylesheets that are not needed for the rendering immediately with low priority.
        ResourceLoadPriority priority = isActive ? ResourceLoadPriorityUnresolved : ResourceLoadPriorityVeryLow;
        CachedResourceRequest request(ResourceRequest(document().completeURL(url)), charset, priority);
        request.setInitiator(this);
        m_cachedSheet = document().cachedResourceLoader()->requestCSSStyleSheet(request);
        
        if (m_cachedSheet)
            m_cachedSheet->addClient(this);
        else {
            // The request may have been denied if (for example) the stylesheet is local and the document is remote.
            m_loading = false;
            removePendingSheet();
        }
    } else if (m_sheet) {
        // we no longer contain a stylesheet, e.g. perhaps rel or type was changed
        clearSheet();
        document().styleResolverChanged(DeferRecalcStyle);
    }
}
Beispiel #23
0
IconURL IconController::defaultURL(IconType iconType)
{
    // Don't return a favicon iconURL unless we're http or https
    URL documentURL = m_frame->document()->url();
    if (!documentURL.protocolIsInHTTPFamily())
        return IconURL();

    URL url;
    bool couldSetProtocol = url.setProtocol(documentURL.protocol());
    ASSERT_UNUSED(couldSetProtocol, couldSetProtocol);
    url.setHost(documentURL.host());
    if (documentURL.hasPort())
        url.setPort(documentURL.port());

    if (iconType == Favicon) {
        url.setPath("/favicon.ico");
        return IconURL::defaultIconURL(url, Favicon);
    }
#if ENABLE(TOUCH_ICON_LOADING)
    if (iconType == TouchPrecomposedIcon) {
        url.setPath("/apple-touch-icon-precomposed.png");
        return IconURL::defaultIconURL(url, TouchPrecomposedIcon);
    }
    if (iconType == TouchIcon) {
        url.setPath("/apple-touch-icon.png");
        return IconURL::defaultIconURL(url, TouchIcon);
    }
#endif
    return IconURL();
}
void HTMLPlugInImageElement::subframeLoaderWillCreatePlugIn(const URL& url)
{
    LOG(Plugins, "%p Plug-in URL: %s", this, m_url.utf8().data());
    LOG(Plugins, "   Actual URL: %s", url.string().utf8().data());
    LOG(Plugins, "   MIME type: %s", loadedMimeType().utf8().data());

    m_loadedUrl = url;
    m_plugInWasCreated = false;
    m_deferredPromotionToPrimaryPlugIn = false;

    if (!document().page() || !document().page()->settings().plugInSnapshottingEnabled()) {
        m_snapshotDecision = NeverSnapshot;
        return;
    }

    if (displayState() == Restarting) {
        LOG(Plugins, "%p Plug-in is explicitly restarting", this);
        m_snapshotDecision = NeverSnapshot;
        setDisplayState(Playing);
        return;
    }

    if (displayState() == RestartingWithPendingMouseClick) {
        LOG(Plugins, "%p Plug-in is explicitly restarting but also waiting for a click", this);
        m_snapshotDecision = NeverSnapshot;
        return;
    }

    if (m_snapshotDecision == NeverSnapshot) {
        LOG(Plugins, "%p Plug-in is blessed, allow it to start", this);
        return;
    }

    bool inMainFrame = document().frame()->isMainFrame();

    if (document().isPluginDocument() && inMainFrame) {
        LOG(Plugins, "%p Plug-in document in main frame", this);
        m_snapshotDecision = NeverSnapshot;
        return;
    }

    if (ScriptController::processingUserGesture()) {
        LOG(Plugins, "%p Script is currently processing user gesture, set to play", this);
        m_snapshotDecision = NeverSnapshot;
        return;
    }

    if (m_createdDuringUserGesture) {
        LOG(Plugins, "%p Plug-in was created when processing user gesture, set to play", this);
        m_snapshotDecision = NeverSnapshot;
        return;
    }

    if (documentHadRecentUserGesture(document())) {
        LOG(Plugins, "%p Plug-in was created shortly after a user gesture, set to play", this);
        m_snapshotDecision = NeverSnapshot;
        return;
    }

    if (document().page()->settings().snapshotAllPlugIns()) {
        LOG(Plugins, "%p Plug-in forced to snapshot by user preference", this);
        m_snapshotDecision = Snapshotted;
        setDisplayState(WaitingForSnapshot);
        return;
    }

    if (document().page()->settings().autostartOriginPlugInSnapshottingEnabled() && document().page()->plugInClient() && document().page()->plugInClient()->shouldAutoStartFromOrigin(document().page()->mainFrame().document()->baseURL().host(), url.host(), loadedMimeType())) {
        LOG(Plugins, "%p Plug-in from (%s, %s) is marked to auto-start, set to play", this, document().page()->mainFrame().document()->baseURL().host().utf8().data(), url.host().utf8().data());
        m_snapshotDecision = NeverSnapshot;
        return;
    }

    if (m_loadedUrl.isEmpty() && !loadedMimeType().isEmpty()) {
        LOG(Plugins, "%p Plug-in has no src URL but does have a valid mime type %s, set to play", this, loadedMimeType().utf8().data());
        m_snapshotDecision = MaySnapshotWhenContentIsSet;
        return;
    }

    if (!SchemeRegistry::shouldTreatURLSchemeAsLocal(m_loadedUrl.protocol()) && !m_loadedUrl.host().isEmpty() && m_loadedUrl.host() == document().page()->mainFrame().document()->baseURL().host()) {
        LOG(Plugins, "%p Plug-in is served from page's domain, set to play", this);
        m_snapshotDecision = NeverSnapshot;
        return;
    }
    
    auto& renderer = downcast<RenderEmbeddedObject>(*this->renderer());
    LayoutRect contentRect = renderer.contentBoxRect();
    int contentWidth = contentRect.width();
    int contentHeight = contentRect.height();
    
    m_plugInDimensionsSpecified = renderer.style().logicalWidth().isSpecified() || renderer.style().logicalHeight().isSpecified();
    
    if (isTopLevelFullPagePlugin(renderer)) {
        LOG(Plugins, "%p Plug-in is top level full page, set to play", this);
        m_snapshotDecision = NeverSnapshot;
        return;
    }

    if (isSmallerThanTinySizingThreshold(renderer)) {
        LOG(Plugins, "%p Plug-in is very small %dx%d, set to play", this, contentWidth, contentHeight);
        m_sizeWhenSnapshotted = IntSize(contentWidth, contentHeight);
        m_snapshotDecision = MaySnapshotWhenResized;
        return;
    }

    if (!document().page()->plugInClient()) {
        LOG(Plugins, "%p There is no plug-in client. Set to wait for snapshot", this);
        m_snapshotDecision = NeverSnapshot;
        setDisplayState(WaitingForSnapshot);
        return;
    }

    LOG(Plugins, "%p Plug-in from (%s, %s) is not auto-start, sized at %dx%d, set to wait for snapshot", this, document().topDocument().baseURL().host().utf8().data(), url.host().utf8().data(), contentWidth, contentHeight);
    m_snapshotDecision = Snapshotted;
    setDisplayState(WaitingForSnapshot);
}
Beispiel #25
0
        void IRUS::setup() {
            // Load scenario.
            const URL urlOfSCNXFile(m_kvc.getValue<string>("global.scenario"));
            if (urlOfSCNXFile.isValid()) {
                SCNXArchive &scnxArchive = SCNXArchiveFactory::getInstance().getSCNXArchive(urlOfSCNXFile);

                opendlv::data::scenario::Scenario &scenario = scnxArchive.getScenario();

                const opendlv::data::scenario::Surroundings &surroundings = scenario.getGround().getSurroundings();
                const vector<opendlv::data::scenario::Shape*> &listOfShapes = surroundings.getListOfShapes();
                vector<opendlv::data::scenario::Shape*>::const_iterator it = listOfShapes.begin();
                while (it != listOfShapes.end()) {
                    opendlv::data::scenario::Shape *shape = (*it++);
                    if (shape != NULL) {
                        if (shape->getType() == opendlv::data::scenario::Shape::POLYGON) {
                            opendlv::data::scenario::Polygon *polygon = dynamic_cast<opendlv::data::scenario::Polygon*>(shape);
                            if (polygon != NULL) {
                                Polygon p;
                                m_numberOfPolygons++;

                                const vector<opendlv::data::scenario::Vertex3> &listOfVertices = polygon->getListOfVertices();
                                vector<opendlv::data::scenario::Vertex3>::const_iterator jt = listOfVertices.begin();
                                while (jt != listOfVertices.end()) {
                                    p.add(*jt++);
                                }
                                m_mapOfPolygons[m_numberOfPolygons] = p;

                                cerr << "[IRUS] Found polygon: " << p.toString() << endl;
                            }
                        }
                    }
                }
            }

            // Setup all point sensors.
            for (uint32_t i = 0; i < m_kvc.getValue<uint32_t>("odsimirus.numberOfSensors"); i++) {
                stringstream sensorID;
                sensorID << "odsimirus.sensor" << i << ".id";
                uint16_t id(m_kvc.getValue<uint16_t>(sensorID.str()));

                stringstream sensorName;
                sensorName << "odsimirus.sensor" << i << ".name";
                string name(m_kvc.getValue<string>(sensorName.str()));
                
                stringstream sensorTranslation;
                sensorTranslation << "odsimirus.sensor" << i << ".translation";
                Point3 translation(m_kvc.getValue<string>(sensorTranslation.str()));

                stringstream sensorRotZ;
                sensorRotZ << "odsimirus.sensor" << i << ".rotZ";
                const double rotZ = m_kvc.getValue<double>(sensorRotZ.str());
                
                stringstream sensorAngleFOV;
                sensorAngleFOV << "odsimirus.sensor" << i << ".angleFOV";
                const double angleFOV = m_kvc.getValue<double>(sensorAngleFOV.str());
                
                stringstream sensorDistanceFOV;
                sensorDistanceFOV << "odsimirus.sensor" << i << ".distanceFOV";
                const double distanceFOV = m_kvc.getValue<double>(sensorDistanceFOV.str());
                
                stringstream sensorClampDistance;
                sensorClampDistance << "odsimirus.sensor" << i << ".clampDistance";
                const double clampDistance = m_kvc.getValue<double>(sensorClampDistance.str());
                
                stringstream sensorShowFOV;
                sensorShowFOV << "odsimirus.sensor" << i << ".showFOV";
                const bool showFOV = m_kvc.getValue<bool>(sensorShowFOV.str());

                // Don't skip any values as default.
                double faultModelSkip = 0;
                try {
                    stringstream faultModelSkipStr;
                    faultModelSkipStr << "odsimirus.sensor" << i << ".faultModel.skip";
                    faultModelSkip = m_kvc.getValue<double>(faultModelSkipStr.str());

                    if (faultModelSkip < 0) {
                        faultModelSkip = 0;
                    }
                    if (faultModelSkip > 1) {
                        faultModelSkip = 1;
                    }
                }
                catch (const odcore::exceptions::ValueForKeyNotFoundException &e) {
                }

                // Don't add any noise as default.
                double faultModelNoise = 0;
                try {
                    stringstream faultModelNoiseStr;
                    faultModelNoiseStr << "odsimirus.sensor" << i << ".faultModel.noise";
                    faultModelNoise = m_kvc.getValue<double>(faultModelNoiseStr.str());
                }
                catch (const odcore::exceptions::ValueForKeyNotFoundException &e) {
                }

                PointSensor *ps = new PointSensor(id, name, translation, rotZ, angleFOV, distanceFOV, clampDistance, showFOV, faultModelSkip, faultModelNoise);

                if (ps != NULL) {
                    // Save for later.
                    m_mapOfPointSensors[ps->getName()] = ps;

                    // Initialize distance map entry.
                    m_distances[ps->getName()] = -1;

                    // Initialize FOV map entry.
                    Polygon f;
                    m_FOVs[ps->getName()] = f;

                    cout << "[IRUS] Registered point sensor " << ps->toString() << "." << endl;
                }
            }
        }
static URL processAndCreateYouTubeURL(const URL& url, bool& isYouTubeShortenedURL)
{
    if (!url.protocolIs("http") && !url.protocolIs("https"))
        return URL();
    
    // Bail out early if we aren't even on www.youtube.com or youtube.com.
    if (!isYouTubeURL(url))
        return URL();
    
    const String& hostName = url.host().lower();
    
    bool isYouTubeMobileWebAppURL = hostName == "m.youtube.com";
    isYouTubeShortenedURL = hostName == "youtu.be";
    
    // Short URL of the form: http://youtu.be/v1d301D
    if (isYouTubeShortenedURL) {
        const String& videoID = url.lastPathComponent();
        if (videoID.isEmpty() || videoID == "/")
            return URL();
        
        return createYouTubeURL(videoID, emptyString());
    }
    
    String path = url.path();
    String query = url.query();
    String fragment = url.fragmentIdentifier();
    
    // On the YouTube mobile web app, the path and query string are put into the
    // fragment so that one web page is only ever loaded (see <rdar://problem/9550639>).
    if (isYouTubeMobileWebAppURL) {
        size_t location = fragment.find('?');
        if (location == notFound) {
            path = fragment;
            query = emptyString();
        } else {
            path = fragment.substring(0, location);
            query = fragment.substring(location + 1);
        }
        fragment = emptyString();
    }
    
    if (path.lower() == "/watch") {
        if (!query.isEmpty()) {
            const auto& queryDictionary = queryKeysAndValues(query);
            String videoID = valueForKey(queryDictionary, "v");
            
            if (!videoID.isEmpty()) {
                const auto& fragmentDictionary = queryKeysAndValues(url.fragmentIdentifier());
                String timeID = valueForKey(fragmentDictionary, "t");
                return createYouTubeURL(videoID, timeID);
            }
        }
        
        // May be a new-style link (see <rdar://problem/7733692>).
        if (fragment.startsWith('!')) {
            query = fragment.substring(1);
            
            if (!query.isEmpty()) {
                const auto& queryDictionary = queryKeysAndValues(query);
                String videoID = valueForKey(queryDictionary, "v");
                
                if (!videoID.isEmpty()) {
                    String timeID = valueForKey(queryDictionary, "t");
                    return createYouTubeURL(videoID, timeID);
                }
            }
        }
    } else if (hasCaseInsensitivePrefix(path, "/v/") || hasCaseInsensitivePrefix(path, "/e/")) {
        String videoID = url.lastPathComponent();
        
        // These URLs are funny - they don't have a ? for the first query parameter.
        // Strip all characters after and including '&' to remove extraneous parameters after the video ID.
        size_t ampersand = videoID.find('&');
        if (ampersand != notFound)
            videoID = videoID.substring(0, ampersand);
        
        if (!videoID.isEmpty())
            return createYouTubeURL(videoID, emptyString());
    }
    
    return URL();
}