@@ -297,61 +297,31 @@ bool DocumentHost::IsHtmlPage(IHTMLDocument2* doc) {
297297 return false ;
298298 }
299299
300- std::wstring document_type_key_name= L" " ;
301- if ( RegistryUtilities::GetRegistryValue (HKEY_CURRENT_USER,
302- L" Software \\ Microsoft \\ Windows \\ Shell \\ Associations \\ UrlAssociations \\ http \\ UserChoice " ,
303- L" Progid " ,
304- &document_type_key_name)) {
305- // Look for the user-customization under Vista/Windows 7 first. If it's
306- // IE, set the document friendly name lookup key to 'htmlfile'. If not ,
307- // set it to blank so that we can look up the proper HTML type.
308- if (document_type_key_name == L" IE.HTTP " ) {
309- document_type_key_name = L" htmlfile " ;
310- } else {
311- LOG (DEBUG) << " Unable to support custom document type: " << LOGWSTRING (document_type_key_name);
312- document_type_key_name = L" " ;
313- }
314- } else {
315- LOG (DEBUG) << " Unable to read document type from registry " ;
316- }
300+ // Call once to get the required buffer size, then again to fill
301+ // the buffer.
302+ DWORD mime_type_name_buffer_size = 0 ;
303+ HRESULT hr = :: AssocQueryString ( 0 ,
304+ ASSOCSTR_FRIENDLYDOCNAME,
305+ L" .htm " ,
306+ NULL ,
307+ NULL ,
308+ &mime_type_name_buffer_size);
309+
310+ std::vector< wchar_t > mime_type_name_buffer (mime_type_name_buffer_size);
311+ hr = :: AssocQueryString ( 0 ,
312+ ASSOCSTR_FRIENDLYDOCNAME,
313+ L" .htm " ,
314+ NULL ,
315+ &mime_type_name_buffer[ 0 ],
316+ &mime_type_name_buffer_size);
317317
318- if (document_type_key_name == L" " ) {
319- // To be technically correct, we should look up the extension specified
320- // for the text/html MIME type first (located in the "Extension" value
321- // of HKEY_CLASSES_ROOT\MIME\Database\Content Type\text/html), but that
322- // should always resolve to ".htm" anyway. From the extension, we can
323- // find the browser-specific subkey of HKEY_CLASSES_ROOT, the default
324- // value of which should contain the browser-specific friendly name of
325- // the MIME type for HTML documents, which is what
326- // IHTMLDocument2::get_mimeType() returns.
327- if (!RegistryUtilities::GetRegistryValue (HKEY_CLASSES_ROOT,
328- L" .htm" ,
329- L" " ,
330- &document_type_key_name)) {
331- LOG (WARN) << " Unable to read document type from registry for '.htm'" ;
332- return false ;
333- }
334- }
335-
336- // First try the (default) value for the subkey. Some browsers (Opera)
337- // do not write this information in the (default) value, so if that fails,
338- // try the FriendlyTypeName value.
339- std::wstring mime_type_name;
340- if (!RegistryUtilities::GetRegistryValue (HKEY_CLASSES_ROOT,
341- document_type_key_name,
342- L" " ,
343- &mime_type_name)) {
344- if (!RegistryUtilities::GetRegistryValue (HKEY_CLASSES_ROOT,
345- document_type_key_name,
346- L" FriendlyTypeName" ,
347- &mime_type_name)) {
348- LOG (WARN) << " Unable to read mime type from registry for document type" ;
349- return false ;
350- }
318+ if (FAILED (hr)) {
319+ LOGHR (WARN, hr) << " Call to AssocQueryString failed in getting friendly name of .htm documents" ;
320+ return false ;
351321 }
352322
323+ std::wstring mime_type_name = &mime_type_name_buffer[0 ];
353324 std::wstring type_string = type;
354-
355325 if (type_string == mime_type_name) {
356326 return true ;
357327 }
@@ -364,7 +334,7 @@ bool DocumentHost::IsHtmlPage(IHTMLDocument2* doc) {
364334
365335 if (L" Firefox HTML Document" == mime_type_name) {
366336 LOG (INFO) << " It looks like Firefox was once the default browser. "
367- << " Guessing the page type from mime type alone" ;
337+ << " Guessing the page type from mime type alone" ;
368338 return true ;
369339 }
370340
0 commit comments