CEF-81.3.10支持Flash自动播放代码修改

CEF-81.3.10支持Flash自动播放代码修改


由于项目的需求,自己手动编译了CEF-81.3.10(对应Chromium-81.0.4044.138内核),编译完成后,测试cefclient不支持FLASH,于是修改代码;通过下面的修改可以支持FLASH自动加载播放:

步骤一:
修改cef\tests\shared\browser\client_app_browser.cc中的OnBeforeCommandLineProcessing函数,代码如下;

void ClientAppBrowser::OnBeforeCommandLineProcessing(
    const CefString& process_type,
    CefRefPtr<CefCommandLine> command_line) {
  // Pass additional command-line flags to the browser process.
  if (process_type.empty()) {
    // Pass additional command-line flags when off-screen rendering is enabled.
    if (command_line->HasSwitch(switches::kOffScreenRenderingEnabled) &&
        !command_line->HasSwitch(switches::kSharedTextureEnabled)) {
      // Use software rendering and compositing (disable GPU) for increased FPS
      // and decreased CPU usage. This will also disable WebGL so remove these
      // switches if you need that capability.
      // See https://bitbucket.org/chromiumembedded/cef/issues/1257 for details.
      if (!command_line->HasSwitch(switches::kEnableGPU)) {
        command_line->AppendSwitch("disable-gpu");
        command_line->AppendSwitch("disable-gpu-compositing");
      }
    }

    if (command_line->HasSwitch(switches::kUseViews) &&
        !command_line->HasSwitch("top-chrome-md")) {
      // Use non-material mode on all platforms by default. Among other things
      // this causes menu buttons to show hover state. See usage of
      // MaterialDesignController::IsModeMaterial() in Chromium code.
      command_line->AppendSwitchWithValue("top-chrome-md", "non-material");
    }

    if (!command_line->HasSwitch(switches::kCachePath) &&
        !command_line->HasSwitch("disable-gpu-shader-disk-cache")) {
      // Don't create a "GPUCache" directory when cache-path is unspecified.
      command_line->AppendSwitch("disable-gpu-shader-disk-cache");
    }

	//---------------新追加代码开始---------------
	// enable system flash support
	if (!command_line->HasSwitch("enable-system-flash")) {
		command_line->AppendSwitch("enable-system-flash");
	}
	//---------------新追加代码结束---------------
	
#if defined(OS_MACOSX)
    // Disable the toolchain prompt on macOS.
    command_line->AppendSwitch("use-mock-keychain");
#endif

    DelegateSet::iterator it = delegates_.begin();
    for (; it != delegates_.end(); ++it)
      (*it)->OnBeforeCommandLineProcessing(this, command_line);
  }
}

步骤二:
修改cef\tests\cefclient\browser\root_window_manager.cc中的GetRequestContext函数,同时添加一个新函数EnableAutoFlashRun, 代码如下;

CefRefPtr<CefRequestContext> RootWindowManager::GetRequestContext(
    RootWindow* root_window) {
  REQUIRE_MAIN_THREAD();

  if (request_context_per_browser_) {
    // Create a new request context for each browser.
    CefRequestContextSettings settings;

    CefRefPtr<CefCommandLine> command_line =
        CefCommandLine::GetGlobalCommandLine();
    if (command_line->HasSwitch(switches::kCachePath)) {
      if (request_context_shared_cache_) {
        // Give each browser the same cache path. The resulting context objects
        // will share the same storage internally.
        CefString(&settings.cache_path) =
            command_line->GetSwitchValue(switches::kCachePath);
      } else {
        // Give each browser a unique cache path. This will create completely
        // isolated context objects.
        std::stringstream ss;
        ss << command_line->GetSwitchValue(switches::kCachePath).ToString()
           << file_util::kPathSep << time(NULL);
        CefString(&settings.cache_path) = ss.str();
      }
    }
	
	//---------------新修改代码开始---------------
	CefRefPtr<CefRequestContext> local_request_context_ = CefRequestContext::CreateContext(settings, new ClientRequestContextHandler);
	EnableAutoFlashRun(local_request_context_);
	return local_request_context_;
	//---------------新修改代码结束---------------
  }

  // All browsers will share the global request context.
  if (!shared_request_context_.get()) {
    shared_request_context_ = CefRequestContext::CreateContext(
        CefRequestContext::GetGlobalContext(), new ClientRequestContextHandler);
  }
  
  //---------------新追加代码开始---------------
  EnableAutoFlashRun(shared_request_context_);
  //---------------新追加代码结束---------------
  return shared_request_context_;
}
//---------------新追加代码开始---------------
// enable auto flash running feature
void RootWindowManager::EnableAutoFlashRun(CefRefPtr<CefRequestContext>& request_context_)
{
	CefString error;
	CefRefPtr<CefValue> value = CefValue::Create();
	value->SetInt(1);
	request_context_->SetPreference("profile.default_content_setting_values.plugins", value, error);
}
//---------------新追加代码结束---------------

修改cef\tests\cefclient\browser\root_window_manager.h,在头文件中添加
EnableAutoFlashRun函数定义,代码如下:

void NotifyExtensionsChanged();
//---------------新追加代码开始---------------
void EnableAutoFlashRun(CefRefPtr<CefRequestContext>& request_context_);
//---------------新追加代码结束---------------

说明:
1).通过上述修改,编译出来的cefclient可以支持Flash加载(系统必须安装Flash), 如果系统没有安装Flash,可以到下面地址下载安装:
https://www.flash.cn/
2).上述修改的git补丁可以到下面地址下载:
https://download.csdn.net/download/shinedeer_06/12673916

参考链接
[1]:https://magpcss.org/ceforum/viewtopic.php?p=43395#p43395

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值