NS_IMETHODIMP Service::OpenDatabaseWithVFS(nsIFile *aDatabaseFile, const nsACString &aVFSName, mozIStorageConnection **_connection) { NS_ENSURE_ARG(aDatabaseFile); #ifdef NS_FUNCTION_TIMER nsCString leafname; (void)aDatabaseFile->GetNativeLeafName(leafname); NS_TIME_FUNCTION_FMT("mozIStorageService::OpenDatabaseWithVFS(%s)", leafname.get()); #endif // Always ensure that SQLITE_OPEN_CREATE is passed in for compatibility // reasons. int flags = SQLITE_OPEN_READWRITE | SQLITE_OPEN_SHAREDCACHE | SQLITE_OPEN_CREATE; nsRefPtr<Connection> msc = new Connection(this, flags); NS_ENSURE_TRUE(msc, NS_ERROR_OUT_OF_MEMORY); nsresult rv = msc->initialize(aDatabaseFile, PromiseFlatCString(aVFSName).get()); NS_ENSURE_SUCCESS(rv, rv); NS_ADDREF(*_connection = msc); return NS_OK; }
NS_IMETHODIMP nsContentDLF::CreateInstance(const char* aCommand, nsIChannel* aChannel, nsILoadGroup* aLoadGroup, const char* aContentType, nsISupports* aContainer, nsISupports* aExtraInfo, nsIStreamListener** aDocListener, nsIContentViewer** aDocViewer) { #ifdef NS_FUNCTION_TIMER nsCAutoString channelURL__("N/A"); nsCOMPtr<nsIURI> url__; if (aChannel && NS_SUCCEEDED(aChannel->GetURI(getter_AddRefs(url__)))) { url__->GetSpec(channelURL__); } NS_TIME_FUNCTION_FMT("%s (line %d) (url: %s)", MOZ_FUNCTION_NAME, __LINE__, channelURL__.get()); #endif // Declare "type" here. This is because although the variable itself only // needs limited scope, we need to use the raw string memory -- as returned // by "type.get()" farther down in the function. nsCAutoString type; // Are we viewing source? nsCOMPtr<nsIViewSourceChannel> viewSourceChannel = do_QueryInterface(aChannel); if (viewSourceChannel) { aCommand = "view-source"; // The parser freaks out when it sees the content-type that a // view-source channel normally returns. Get the actual content // type of the data. If it's known, use it; otherwise use // text/plain. viewSourceChannel->GetOriginalContentType(type); bool knownType = false; PRInt32 typeIndex; for (typeIndex = 0; gHTMLTypes[typeIndex] && !knownType; ++typeIndex) { if (type.Equals(gHTMLTypes[typeIndex]) && !type.EqualsLiteral(VIEWSOURCE_CONTENT_TYPE)) { knownType = PR_TRUE; } } for (typeIndex = 0; gXMLTypes[typeIndex] && !knownType; ++typeIndex) { if (type.Equals(gXMLTypes[typeIndex])) { knownType = PR_TRUE; } } for (typeIndex = 0; gSVGTypes[typeIndex] && !knownType; ++typeIndex) { if (type.Equals(gSVGTypes[typeIndex])) { knownType = PR_TRUE; } } for (typeIndex = 0; gXULTypes[typeIndex] && !knownType; ++typeIndex) { if (type.Equals(gXULTypes[typeIndex])) { knownType = PR_TRUE; } } if (knownType) { viewSourceChannel->SetContentType(type); } else if (IsImageContentType(type.get())) { // If it's an image, we want to display it the same way we normally would. // Also note the lifetime of "type" allows us to safely use "get()" here. aContentType = type.get(); } else { viewSourceChannel->SetContentType(NS_LITERAL_CSTRING(TEXT_PLAIN)); } } else if (0 == PL_strcmp(VIEWSOURCE_CONTENT_TYPE, aContentType)) { aChannel->SetContentType(NS_LITERAL_CSTRING(TEXT_PLAIN)); aContentType = TEXT_PLAIN; } // Try html int typeIndex=0; while(gHTMLTypes[typeIndex]) { if (0 == PL_strcmp(gHTMLTypes[typeIndex++], aContentType)) { return CreateDocument(aCommand, aChannel, aLoadGroup, aContainer, kHTMLDocumentCID, aDocListener, aDocViewer); } } // Try XML typeIndex = 0; while(gXMLTypes[typeIndex]) { if (0== PL_strcmp(gXMLTypes[typeIndex++], aContentType)) { return CreateDocument(aCommand, aChannel, aLoadGroup, aContainer, kXMLDocumentCID, aDocListener, aDocViewer); } } // Try SVG typeIndex = 0; while(gSVGTypes[typeIndex]) { if (!PL_strcmp(gSVGTypes[typeIndex++], aContentType)) { return CreateDocument(aCommand, aChannel, aLoadGroup, aContainer, kSVGDocumentCID, aDocListener, aDocViewer); } } // Try XUL typeIndex = 0; while (gXULTypes[typeIndex]) { if (0 == PL_strcmp(gXULTypes[typeIndex++], aContentType)) { if (!MayUseXULXBL(aChannel)) { return NS_ERROR_REMOTE_XUL; } return CreateXULDocument(aCommand, aChannel, aLoadGroup, aContentType, aContainer, aExtraInfo, aDocListener, aDocViewer); } } #ifdef MOZ_MEDIA if (nsHTMLMediaElement::ShouldHandleMediaType(aContentType)) { return CreateDocument(aCommand, aChannel, aLoadGroup, aContainer, kVideoDocumentCID, aDocListener, aDocViewer); } #endif // Try image types if (IsImageContentType(aContentType)) { return CreateDocument(aCommand, aChannel, aLoadGroup, aContainer, kImageDocumentCID, aDocListener, aDocViewer); } nsCOMPtr<nsIPluginHost> pluginHostCOM(do_GetService(MOZ_PLUGIN_HOST_CONTRACTID)); nsPluginHost *pluginHost = static_cast<nsPluginHost*>(pluginHostCOM.get()); if(pluginHost && NS_SUCCEEDED(pluginHost->IsPluginEnabledForType(aContentType))) { return CreateDocument(aCommand, aChannel, aLoadGroup, aContainer, kPluginDocumentCID, aDocListener, aDocViewer); } // If we get here, then we weren't able to create anything. Sorry! return NS_ERROR_FAILURE; }