mirror of
				https://bitbucket.org/chromiumembedded/cef
				synced 2025-06-05 21:39:12 +02:00 
			
		
		
		
	Fix decoding of about:credits HTML (issue #1980)
This commit is contained in:
		
							
								
								
									
										1
									
								
								BUILD.gn
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								BUILD.gn
									
									
									
									
									
								
							@@ -795,6 +795,7 @@ static_library("libcef_static") {
 | 
			
		||||
    "//skia",
 | 
			
		||||
    "//storage/browser",
 | 
			
		||||
    "//sync",
 | 
			
		||||
    "//third_party/brotli",
 | 
			
		||||
    "//third_party/cld_2",
 | 
			
		||||
    "//third_party/hunspell",
 | 
			
		||||
    "//third_party/leveldatabase",
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1
									
								
								cef.gyp
									
									
									
									
									
								
							
							
						
						
									
										1
									
								
								cef.gyp
									
									
									
									
									
								
							@@ -1037,6 +1037,7 @@
 | 
			
		||||
        '<(DEPTH)/skia/skia.gyp:skia',
 | 
			
		||||
        '<(DEPTH)/storage/storage_browser.gyp:storage',
 | 
			
		||||
        '<(DEPTH)/sync/sync.gyp:sync',
 | 
			
		||||
        '<(DEPTH)/third_party/brotli/brotli.gyp:brotli',
 | 
			
		||||
        '<(DEPTH)/third_party/cld_2/cld_2.gyp:cld_2',
 | 
			
		||||
        '<(DEPTH)/third_party/hunspell/hunspell.gyp:hunspell',
 | 
			
		||||
        '<(DEPTH)/third_party/libxml/libxml.gyp:libxml',
 | 
			
		||||
 
 | 
			
		||||
@@ -281,6 +281,7 @@ class Delegate : public InternalHandlerDelegate {
 | 
			
		||||
    } else {
 | 
			
		||||
      action->mime_type = "text/html";
 | 
			
		||||
      action->resource_id = IDR_ABOUT_UI_CREDITS_HTML;
 | 
			
		||||
      action->encoding = Action::ENCODING_BROTLI;
 | 
			
		||||
    }
 | 
			
		||||
    return true;
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -14,6 +14,7 @@
 | 
			
		||||
#include "base/strings/utf_string_conversions.h"
 | 
			
		||||
#include "base/threading/thread_restrictions.h"
 | 
			
		||||
#include "net/base/mime_util.h"
 | 
			
		||||
#include "third_party/brotli/dec/decode.h"
 | 
			
		||||
#include "ui/base/resource/resource_bundle.h"
 | 
			
		||||
 | 
			
		||||
namespace scheme {
 | 
			
		||||
@@ -28,7 +29,7 @@ base::FilePath FilePathFromASCII(const std::string& str) {
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static std::string GetMimeType(const std::string& filename) {
 | 
			
		||||
std::string GetMimeType(const std::string& filename) {
 | 
			
		||||
  // Requests should not block on the disk!  On POSIX this goes to disk.
 | 
			
		||||
  // http://code.google.com/p/chromium/issues/detail?id=59849
 | 
			
		||||
  base::ThreadRestrictions::ScopedAllowIO allow_io;
 | 
			
		||||
@@ -48,6 +49,24 @@ static std::string GetMimeType(const std::string& filename) {
 | 
			
		||||
  return "text/plain";
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool DecodeBrotli(const base::StringPiece& encoded,
 | 
			
		||||
                  std::string& decoded) {
 | 
			
		||||
  size_t decoded_size;
 | 
			
		||||
 | 
			
		||||
  const uint8_t* encoded_response_buffer =
 | 
			
		||||
      reinterpret_cast<const uint8_t*>(encoded.data());
 | 
			
		||||
  if (!BrotliDecompressedSize(encoded.size(), encoded_response_buffer,
 | 
			
		||||
                              &decoded_size)) {
 | 
			
		||||
    return false;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  decoded.resize(decoded_size);
 | 
			
		||||
  return BrotliDecompressBuffer(encoded.size(), encoded_response_buffer,
 | 
			
		||||
                               &decoded_size,
 | 
			
		||||
                               reinterpret_cast<uint8_t*>(&decoded[0])) ==
 | 
			
		||||
        BROTLI_RESULT_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class RedirectHandler : public CefResourceHandler {
 | 
			
		||||
 public:
 | 
			
		||||
  explicit RedirectHandler(const GURL& url)
 | 
			
		||||
@@ -153,6 +172,16 @@ class InternalHandlerFactory : public CefSchemeHandlerFactory {
 | 
			
		||||
        base::StringPiece piece = CefContentClient::Get()->GetDataResource(
 | 
			
		||||
            action.resource_id, ui::SCALE_FACTOR_NONE);
 | 
			
		||||
        if (!piece.empty()) {
 | 
			
		||||
          std::string decoded;
 | 
			
		||||
          if (action.encoding ==
 | 
			
		||||
                  InternalHandlerDelegate::Action::ENCODING_BROTLI &&
 | 
			
		||||
              !DecodeBrotli(piece, decoded)) {
 | 
			
		||||
            decoded = "Unable to decode content!";
 | 
			
		||||
          }
 | 
			
		||||
 | 
			
		||||
          if (!decoded.empty())
 | 
			
		||||
            piece = base::StringPiece(decoded);
 | 
			
		||||
 | 
			
		||||
          action.stream =
 | 
			
		||||
              CefStreamReader::CreateForData(const_cast<char*>(piece.data()),
 | 
			
		||||
                                             piece.size());
 | 
			
		||||
@@ -183,7 +212,8 @@ class InternalHandlerFactory : public CefSchemeHandlerFactory {
 | 
			
		||||
 | 
			
		||||
InternalHandlerDelegate::Action::Action()
 | 
			
		||||
    : stream_size(-1),
 | 
			
		||||
      resource_id(-1) {
 | 
			
		||||
      resource_id(-1),
 | 
			
		||||
      encoding(ENCODING_NONE) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
CefRefPtr<CefSchemeHandlerFactory> CreateInternalHandlerFactory(
 | 
			
		||||
 
 | 
			
		||||
@@ -28,8 +28,13 @@ class InternalHandlerDelegate {
 | 
			
		||||
    CefRefPtr<CefStreamReader> stream;
 | 
			
		||||
    int stream_size;
 | 
			
		||||
 | 
			
		||||
    // Option 2: Specify a resource id to load static content.
 | 
			
		||||
    // Option 2: Specify a resource id to load static content. May include an
 | 
			
		||||
    // optional encoding type.
 | 
			
		||||
    int resource_id;
 | 
			
		||||
    enum Encoding {
 | 
			
		||||
      ENCODING_NONE,
 | 
			
		||||
      ENCODING_BROTLI,
 | 
			
		||||
    } encoding;
 | 
			
		||||
 | 
			
		||||
    // Option 3: Redirect to the specified URL.
 | 
			
		||||
    GURL redirect_url;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user