bool MediaPlayer::load(const KURL& url, const ContentType& contentType) { String type = contentType.type().lower(); String typeCodecs = contentType.parameter(codecs()); String urlString = url.string(); // If the MIME type is missing or is not meaningful, try to figure it out from the URL. if (type.isEmpty() || type == applicationOctetStream() || type == textPlain()) { if (protocolIs(urlString, "data")) type = mimeTypeFromDataURL(urlString); else { String lastPathComponent = url.lastPathComponent(); size_t pos = lastPathComponent.reverseFind('.'); if (pos != notFound) { String extension = lastPathComponent.substring(pos + 1); String mediaType = MIMETypeRegistry::getMediaMIMETypeForExtension(extension); if (!mediaType.isEmpty()) type = mediaType; } } } m_url = urlString; m_contentMIMEType = type; m_contentTypeCodecs = typeCodecs; loadWithNextMediaEngine(0); return m_currentMediaEngine; }
static inline String pathExtension(const KURL& url) { String extension; String filename = url.lastPathComponent(); if (!filename.endsWith('/')) { int extensionPos = filename.reverseFind('.'); if (extensionPos != -1) extension = filename.substring(extensionPos + 1); } return extension; }
File::File(const KURL& fileSystemURL, const FileMetadata& metadata, UserVisibility userVisibility) : Blob(BlobDataHandle::create( createBlobDataForFileSystemURL(fileSystemURL, metadata), metadata.length)), m_hasBackingFile(false), m_userVisibility(userVisibility), m_name(decodeURLEscapeSequences(fileSystemURL.lastPathComponent())), m_fileSystemURL(fileSystemURL), m_snapshotSize(metadata.length), m_snapshotModificationTimeMS(metadata.modificationTime) {}
void Pasteboard::writeURL(const KURL& url, const String& titleStr, Frame* frame) { ASSERT(!url.isEmpty()); String title(titleStr); if (title.isEmpty()) { title = url.lastPathComponent(); if (title.isEmpty()) title = url.host(); } ChromiumBridge::clipboardWriteURL(url, title); }
void Pasteboard::writeURL(const KURL& url, const String& titleStr, Frame* frame) { ASSERT(!url.isEmpty()); String title(titleStr); if (title.isEmpty()) { title = url.lastPathComponent(); if (title.isEmpty()) title = url.host(); } WebKit::Platform::current()->clipboard()->writeURL(url, title); }
/** * webkit_download_get_suggested_filename: * @download: the #WebKitDownload * * Retrieves the filename that was suggested by the server, or the one * derived by WebKit from the URI. * * Returns: the suggested filename * * Since: 1.1.2 */ const gchar* webkit_download_get_suggested_filename(WebKitDownload* download) { g_return_val_if_fail(WEBKIT_IS_DOWNLOAD(download), NULL); WebKitDownloadPrivate* priv = download->priv; if (priv->suggestedFilename) return priv->suggestedFilename; KURL url = KURL(KURL(), webkit_network_request_get_uri(priv->networkRequest)); url.setQuery(String()); url.removeFragmentIdentifier(); priv->suggestedFilename = g_strdup(decodeURLEscapeSequences(url.lastPathComponent()).utf8().data()); return priv->suggestedFilename; }
static void writeImageToDataObject(DataObject* dataObject, Element* element, const KURL& url) { // Shove image data into a DataObject for use as a file ImageResourceContent* cachedImage = getImageResourceContent(element); if (!cachedImage || !cachedImage->getImage() || !cachedImage->isLoaded()) return; RefPtr<SharedBuffer> imageBuffer = cachedImage->getImage()->data(); if (!imageBuffer || !imageBuffer->size()) return; String imageExtension = cachedImage->getImage()->filenameExtension(); ASSERT(!imageExtension.isEmpty()); // Determine the filename for the file contents of the image. String filename = cachedImage->response().suggestedFilename(); if (filename.isEmpty()) filename = url.lastPathComponent(); String fileExtension; if (filename.isEmpty()) { filename = element->getAttribute(HTMLNames::altAttr); } else { // Strip any existing extension. Assume that alt text is usually not a // filename. int extensionIndex = filename.reverseFind('.'); if (extensionIndex != -1) { fileExtension = filename.substring(extensionIndex + 1); filename.truncate(extensionIndex); } } if (!fileExtension.isEmpty() && fileExtension != imageExtension) { String imageMimeType = MIMETypeRegistry::getMIMETypeForExtension(imageExtension); ASSERT(imageMimeType.startsWith("image/")); // Use the file extension only if it has imageMimeType: it's untrustworthy // otherwise. if (imageMimeType == MIMETypeRegistry::getMIMETypeForExtension(fileExtension)) imageExtension = fileExtension; } imageExtension = "." + imageExtension; validateFilename(filename, imageExtension); dataObject->addSharedBuffer(filename + imageExtension, imageBuffer); }
void didReceiveResponse(ResourceHandle*, const ResourceResponse& response) { m_response = adoptGRef(response.toSoupMessage()); m_download->didReceiveResponse(response); if (response.httpStatusCode() >= 400) { downloadFailed(platformDownloadNetworkError(response.httpStatusCode(), response.url().string(), response.httpStatusText())); return; } String suggestedFilename = response.suggestedFilename(); if (suggestedFilename.isEmpty()) { KURL url = response.url(); url.setQuery(String()); url.removeFragmentIdentifier(); suggestedFilename = decodeURLEscapeSequences(url.lastPathComponent()); } bool overwrite; String destinationURI = m_download->decideDestinationWithSuggestedFilename(suggestedFilename, overwrite); if (destinationURI.isEmpty()) { #if PLATFORM(GTK) GOwnPtr<char> buffer(g_strdup_printf(_("Cannot determine destination URI for download with suggested filename %s"), suggestedFilename.utf8().data())); String errorMessage = String::fromUTF8(buffer.get()); #else String errorMessage = makeString("Cannot determine destination URI for download with suggested filename ", suggestedFilename); #endif downloadFailed(platformDownloadDestinationError(response, errorMessage)); return; } GRefPtr<GFile> file = adoptGRef(g_file_new_for_uri(destinationURI.utf8().data())); GOwnPtr<GError> error; m_outputStream = adoptGRef(g_file_replace(file.get(), 0, TRUE, G_FILE_CREATE_NONE, 0, &error.outPtr())); if (!m_outputStream) { downloadFailed(platformDownloadDestinationError(response, error->message)); return; } GRefPtr<GFileInfo> info = adoptGRef(g_file_info_new()); g_file_info_set_attribute_string(info.get(), "metadata::download-uri", response.url().string().utf8().data()); g_file_set_attributes_async(file.get(), info.get(), G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, 0, 0, 0); m_download->didCreateDestination(destinationURI); }
static bool writeURL(WCDataObject *data, const KURL& url, String title, bool withPlainText, bool withHTML) { ASSERT(data); if (url.isEmpty()) return false; if (title.isEmpty()) { title = url.lastPathComponent(); if (title.isEmpty()) title = url.host(); } STGMEDIUM medium = {0}; medium.tymed = TYMED_HGLOBAL; medium.hGlobal = createGlobalData(url, title); bool success = false; if (medium.hGlobal && FAILED(data->SetData(urlWFormat(), &medium, TRUE))) ::GlobalFree(medium.hGlobal); else success = true; if (withHTML) { Vector<char> cfhtmlData; markupToCF_HTML(urlToMarkup(url, title), "", cfhtmlData); medium.hGlobal = createGlobalData(cfhtmlData); if (medium.hGlobal && FAILED(data->SetData(htmlFormat(), &medium, TRUE))) ::GlobalFree(medium.hGlobal); else success = true; } if (withPlainText) { medium.hGlobal = createGlobalData(url.string()); if (medium.hGlobal && FAILED(data->SetData(plainTextWFormat(), &medium, TRUE))) ::GlobalFree(medium.hGlobal); else success = true; } return success; }
void Pasteboard::writeURL(const KURL& url, const String& titleStr, Frame* frame) { ASSERT(!url.isEmpty()); clear(); String title(titleStr); if (title.isEmpty()) { title = url.lastPathComponent(); if (title.isEmpty()) title = url.host(); } // write to clipboard in format com.apple.safari.bookmarkdata to be able to paste into the bookmarks view with appropriate title if (::OpenClipboard(m_owner)) { HGLOBAL cbData = createGlobalData(url, title); if (!::SetClipboardData(BookmarkClipboardFormat, cbData)) ::GlobalFree(cbData); ::CloseClipboard(); } // write to clipboard in format CF_HTML to be able to paste into contenteditable areas as a link if (::OpenClipboard(m_owner)) { Vector<char> data; markupToCFHTML(urlToMarkup(url, title), "", data); HGLOBAL cbData = createGlobalData(data); if (!::SetClipboardData(HTMLClipboardFormat, cbData)) ::GlobalFree(cbData); ::CloseClipboard(); } // bare-bones CF_UNICODETEXT support if (::OpenClipboard(m_owner)) { HGLOBAL cbData = createGlobalData(url.string()); if (!::SetClipboardData(CF_UNICODETEXT, cbData)) ::GlobalFree(cbData); ::CloseClipboard(); } }
static String pathSuitableForTestResult(const char* uriString) { KURL uri = KURL(ParsedURLString, uriString); if (uri.isEmpty()) return "(null)"; if (!uri.isLocalFile()) return uri.string(); KURL mainFrameURL = KURL(ParsedURLString, ewk_frame_uri_get(browser->mainFrame())); if (mainFrameURL.isEmpty()) mainFrameURL = DumpRenderTreeSupportEfl::provisionalURL(browser->mainFrame()); String mainFrameUrlPathString = mainFrameURL.path(); String pathString = uri.path(); String basePath = mainFrameUrlPathString.substring(0, mainFrameUrlPathString.reverseFind('/') + 1); if (!basePath.isEmpty() && pathString.startsWith(basePath)) return pathString.substring(basePath.length()); return uri.lastPathComponent(); }
ObjectContentType FrameLoaderClientImpl::getObjectContentType( const KURL& url, const String& explicitMimeType, bool shouldPreferPlugInsForImages) { // This code is based on Apple's implementation from // WebCoreSupport/WebFrameBridge.mm. String mimeType = explicitMimeType; if (mimeType.isEmpty()) { // Try to guess the MIME type based off the extension. String filename = url.lastPathComponent(); int extensionPos = filename.reverseFind('.'); if (extensionPos >= 0) { String extension = filename.substring(extensionPos + 1); mimeType = MIMETypeRegistry::getWellKnownMIMETypeForExtension(extension); } if (mimeType.isEmpty()) return ObjectContentFrame; } // If Chrome is started with the --disable-plugins switch, pluginData is 0. PluginData* pluginData = m_webFrame->frame()->pluginData(); bool plugInSupportsMIMEType = pluginData && pluginData->supportsMimeType(mimeType); if (MIMETypeRegistry::isSupportedImageMIMEType(mimeType)) return shouldPreferPlugInsForImages && plugInSupportsMIMEType ? ObjectContentNetscapePlugin : ObjectContentImage; if (plugInSupportsMIMEType) return ObjectContentNetscapePlugin; if (MIMETypeRegistry::isSupportedNonImageMIMEType(mimeType)) return ObjectContentFrame; return ObjectContentNone; }
void didReceiveResponse(ResourceHandle*, const ResourceResponse& response) { m_response = adoptGRef(response.toSoupMessage()); m_download->didReceiveResponse(response); if (response.httpStatusCode() >= 400) { downloadFailed(downloadNetworkError(ResourceError(errorDomainDownload, response.httpStatusCode(), response.url().string(), response.httpStatusText()))); return; } String suggestedFilename = response.suggestedFilename(); if (suggestedFilename.isEmpty()) { KURL url = response.url(); url.setQuery(String()); url.removeFragmentIdentifier(); suggestedFilename = decodeURLEscapeSequences(url.lastPathComponent()); } bool overwrite; String destinationURI = m_download->decideDestinationWithSuggestedFilename(suggestedFilename.utf8().data(), overwrite); if (destinationURI.isEmpty()) { GOwnPtr<char> errorMessage(g_strdup_printf(_("Cannot determine destination URI for download with suggested filename %s"), suggestedFilename.utf8().data())); downloadFailed(downloadDestinationError(response, errorMessage.get())); return; } GRefPtr<GFile> file = adoptGRef(g_file_new_for_uri(destinationURI.utf8().data())); GOwnPtr<GError> error; m_outputStream = adoptGRef(g_file_replace(file.get(), 0, TRUE, G_FILE_CREATE_NONE, 0, &error.outPtr())); if (!m_outputStream) { downloadFailed(downloadDestinationError(response, error->message)); return; } m_download->didCreateDestination(destinationURI); }
static void writeImageToDataObject(ChromiumDataObject* dataObject, Element* element, const KURL& url) { // Shove image data into a DataObject for use as a file CachedImage* cachedImage = getCachedImage(element); if (!cachedImage || !cachedImage->imageForRenderer(element->renderer()) || !cachedImage->isLoaded()) return; SharedBuffer* imageBuffer = cachedImage->imageForRenderer(element->renderer())->data(); if (!imageBuffer || !imageBuffer->size()) return; dataObject->setFileContent(imageBuffer); // Determine the filename for the file contents of the image. String filename = cachedImage->response().suggestedFilename(); if (filename.isEmpty()) filename = url.lastPathComponent(); if (filename.isEmpty()) filename = element->getAttribute(altAttr); else { // Strip any existing extension. Assume that alt text is usually not a filename. int extensionIndex = filename.reverseFind('.'); if (extensionIndex != -1) filename.truncate(extensionIndex); } String extension = MIMETypeRegistry::getPreferredExtensionForMIMEType( cachedImage->response().mimeType()); extension = extension.isEmpty() ? emptyString() : "." + extension; ClipboardChromium::validateFilename(filename, extension); dataObject->setFileContentFilename(filename + extension); dataObject->setFileExtension(extension); }