当前位置: 首页 > news >正文

奖励网站源码做网站4000-262-263

奖励网站源码,做网站4000-262-263,c2c模式的概念,湖南企业竞价优化为了能在WebContents中添加自定义数据先看下几个关键类的介绍。 一、WebContents 介绍: WebContents是content模块核心,是呈现 Web 内容(通常为 HTML)位于矩形区域中。 最直观的是一个浏览器标签对应一个WebContents&#xff0c…

为了能在WebContents中添加自定义数据先看下几个关键类的介绍。

一、WebContents 介绍:

  WebContents是content模块核心,是呈现 Web 内容(通常为 HTML)位于矩形区域中。

最直观的是一个浏览器标签对应一个WebContents,里面加载一个网页等。

二、看下WebContents定义:

content\public\browser\web_contents.h

{

WebContents具体实现在:

content\browser\web_contents\web_contents_impl.cc

content\browser\web_contents\web_contents_impl.h

}

WebContents继承自base::SupportsUserData

// WebContents is the core class in content/. A WebContents renders web content
// (usually HTML) in a rectangular area.
//
// Instantiating one is simple:
//   std::unique_ptr<content::WebContents> web_contents(
//       content::WebContents::Create(
//           content::WebContents::CreateParams(browser_context)));
//   gfx::NativeView view = web_contents->GetNativeView();
//   // |view| is an HWND, NSView*, etc.; insert it into the view hierarchy
//   // wherever it needs to go.
//
// That's it; go to your kitchen, grab a scone, and chill. WebContents will do
// all the multi-process stuff behind the scenes. More details are at
// https://www.chromium.org/developers/design-documents/multi-process-architecture
// .
//
// The owner of `std::unique_ptr<content::WebContents> web_contents` is
// responsible for ensuring that `web_contents` are destroyed (e.g. closed)
// *before* the corresponding `browser_context` is destroyed.
//
// Each WebContents has a `NavigationController`, which can be obtained from
// `GetController()`, and is used to load URLs into the WebContents, navigate
// it backwards/forwards, etc.
// See navigation_controller.h for more details.
class WebContents : public PageNavigator,public base::SupportsUserData {// Do not remove this macro!// The macro is maintained by the memory safety team.ADVANCED_MEMORY_SAFETY_CHECKS();public:struct CONTENT_EXPORT CreateParams {explicit CreateParams(BrowserContext* context,base::Location creator_location = base::Location::Current());CreateParams(BrowserContext* context,scoped_refptr<SiteInstance> site,base::Location creator_location = base::Location::Current());CreateParams(const CreateParams& other);~CreateParams();
..................................
};

三、base::SupportsUserData定义:

  base\supports_user_data.h

注意:看下这几个方法:

  Data* GetUserData(const void* key) const;
  [[nodiscard]] std::unique_ptr<Data> TakeUserData(const void* key);
  void SetUserData(const void* key, std::unique_ptr<Data> data);
  void RemoveUserData(const void* key);

namespace base {// This is a helper for classes that want to allow users to stash random data by
// key. At destruction all the objects will be destructed.
class BASE_EXPORT SupportsUserData {public:SupportsUserData();SupportsUserData(SupportsUserData&&);SupportsUserData& operator=(SupportsUserData&&);SupportsUserData(const SupportsUserData&) = delete;SupportsUserData& operator=(const SupportsUserData&) = delete;// Derive from this class and add your own data members to associate extra// information with this object. Alternatively, add this as a public base// class to any class with a virtual destructor.class BASE_EXPORT Data {public:virtual ~Data() = default;// Returns a copy of |this|; null if copy is not supported.virtual std::unique_ptr<Data> Clone();};// The user data allows the clients to associate data with this object.// |key| must not be null--that value is too vulnerable for collision.// NOTE: SetUserData() with an empty unique_ptr behaves the same as// RemoveUserData().Data* GetUserData(const void* key) const;[[nodiscard]] std::unique_ptr<Data> TakeUserData(const void* key);void SetUserData(const void* key, std::unique_ptr<Data> data);void RemoveUserData(const void* key);// Adds all data from |other|, that is clonable, to |this|. That is, this// iterates over the data in |other|, and any data that returns non-null from// Clone() is added to |this|.void CloneDataFrom(const SupportsUserData& other);// SupportsUserData is not thread-safe, and on debug build will assert it is// only used on one execution sequence. Calling this method allows the caller// to hand the SupportsUserData instance across execution sequences. Use only// if you are taking full control of the synchronization of that hand over.void DetachFromSequence();protected:virtual ~SupportsUserData();// Clear all user data from this object. This can be used if the subclass// needs to provide reset functionality.void ClearAllUserData();private:// Externally-defined data accessible by key.absl::flat_hash_map<const void*, std::unique_ptr<Data>> user_data_;bool in_destructor_ = false;// Guards usage of |user_data_|SEQUENCE_CHECKER(sequence_checker_);
};// Adapter class that releases a refcounted object when the
// SupportsUserData::Data object is deleted.
template <typename T>
class UserDataAdapter : public SupportsUserData::Data {public:static T* Get(const SupportsUserData* supports_user_data, const void* key) {UserDataAdapter* data =static_cast<UserDataAdapter*>(supports_user_data->GetUserData(key));return data ? static_cast<T*>(data->object_.get()) : nullptr;}explicit UserDataAdapter(T* object) : object_(object) {}UserDataAdapter(const UserDataAdapter&) = delete;UserDataAdapter& operator=(const UserDataAdapter&) = delete;~UserDataAdapter() override = default;T* release() { return object_.release(); }private:scoped_refptr<T> const object_;
};}  // namespace base

四、在WebContents添加数据定义:

   由于WebContents继承自base::SupportsUserData,所以只需要调用

base::SupportsUserData::SetUserData 方法即可。

1、需要定义一个类AwSettingsUserData 继承自base::SupportsUserData::Data

class AwSettingsUserData : public base::SupportsUserData::Data {public://添加自己的数据private:};

2、base::SupportsUserData::SetUserData设置数据:

  web_contents->SetUserData(kAwSettingsUserDataKey,

                            std::make_unique<AwSettingsUserData>(this));

3、base::SupportsUserData::GetUserData获取数据:

 AwSettingsUserData* data = static_cast<AwSettingsUserData*>(

        web_contents->GetUserData(kAwSettingsUserDataKey));

总结:至此在WebContents添加自定义数据方法介绍完毕。

添加自定义数据主要是为了标记WebContents 可以根据此标记对标签进行特殊处理。

http://www.yayakq.cn/news/487724/

相关文章:

  • 南京网站公司哪家好wordpress for sae 4.0
  • 内蒙古建设厅官网站wordpress 主题预览空白
  • 高端企业网站建设蓦然郑州网站建设多种语言网站怎么做
  • 个人业务网站源码海外网络是什么意思
  • 网站建设如何定位百度快速收录软件
  • 北京建设部网站职称seo关键词优化公司哪家好
  • 长白山网站学做管理wordpress 文章 数据库
  • 北京微信网站建设费用优化大师 win10下载
  • 网站设计的留言怎么做wordpress 微信 商城模板
  • 怎么建自己的网站?用数字做域名的网站
  • 网站开发的软件环境有哪些望城经开区建设开发公司门户网站
  • 无锡网站建设方案托管世界十大营销策划公司
  • 广东网站备案进度查询百度怎么发布短视频
  • 建设联结是不是正规网站3d建模素材网站
  • 扬中网站建设效果wordpress 安装 godaddy在哪里 上传的根目录
  • 苏州晶体公司网站建设手机网站 qq代码
  • 内蒙建设厅网站怎么查建筑电工证大型网站服务器价格
  • 建设一个公司网站多少钱房产网站加盟
  • 各种浏览器网站大全wordpress 微官网主题下载
  • 如何做一元购网站全站加速 wordpress
  • 网站设计培训班前台项目实施方案
  • 如何让商家建设网站如何速发布wordpress
  • 建设实木餐桌椅移动网站许昌河南网站建设
  • 创建网站的流程是什么一般做网站的在哪里找
  • 沈阳城市建设学院官网网站阜宁县建设局网站
  • 温州网上推广什么网站好wordpress主题游戏cms
  • 小型网站如何做后台管理系统页面模板
  • 宁波网站建设方案联系方式nginx wordpress优化
  • 沈阳红方城网站建设重庆网站建设公司联系方式
  • 线上购物网站建设成本找人做seo要给网站程序