1 // Copyright (c) 2013 Marshall A. Greenblatt. All rights reserved. 2 // 3 // Redistribution and use in source and binary forms, with or without 4 // modification, are permitted provided that the following conditions are 5 // met: 6 // 7 // * Redistributions of source code must retain the above copyright 8 // notice, this list of conditions and the following disclaimer. 9 // * Redistributions in binary form must reproduce the above 10 // copyright notice, this list of conditions and the following disclaimer 11 // in the documentation and/or other materials provided with the 12 // distribution. 13 // * Neither the name of Google Inc. nor the name Chromium Embedded 14 // Framework nor the names of its contributors may be used to endorse 15 // or promote products derived from this software without specific prior 16 // written permission. 17 // 18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 30 #ifndef CEF_INCLUDE_INTERNAL_CEF_TYPES_WRAPPERS_H_ 31 #define CEF_INCLUDE_INTERNAL_CEF_TYPES_WRAPPERS_H_ 32 #pragma once 33 34 #include "include/internal/cef_string.h" 35 #include "include/internal/cef_string_list.h" 36 #include "include/internal/cef_types.h" 37 38 /// 39 // Template class that provides common functionality for CEF structure wrapping. 40 /// 41 template <class traits> 42 class CefStructBase : public traits::struct_type { 43 public: 44 typedef typename traits::struct_type struct_type; 45 CefStructBase()46 CefStructBase() : attached_to_(NULL) { Init(); } ~CefStructBase()47 virtual ~CefStructBase() { 48 // Only clear this object's data if it isn't currently attached to a 49 // structure. 50 if (!attached_to_) 51 Clear(this); 52 } 53 CefStructBase(const CefStructBase & r)54 CefStructBase(const CefStructBase& r) { 55 Init(); 56 *this = r; 57 } CefStructBase(const struct_type & r)58 CefStructBase(const struct_type& r) { 59 Init(); 60 *this = r; 61 } 62 63 /// 64 // Clear this object's values. 65 /// Reset()66 void Reset() { 67 Clear(this); 68 Init(); 69 } 70 71 /// 72 // Attach to the source structure's existing values. DetachTo() can be called 73 // to insert the values back into the existing structure. 74 /// AttachTo(struct_type & source)75 void AttachTo(struct_type& source) { 76 // Only clear this object's data if it isn't currently attached to a 77 // structure. 78 if (!attached_to_) 79 Clear(this); 80 81 // This object is now attached to the new structure. 82 attached_to_ = &source; 83 84 // Transfer ownership of the values from the source structure. 85 memcpy(static_cast<struct_type*>(this), &source, sizeof(struct_type)); 86 } 87 88 /// 89 // Relinquish ownership of values to the target structure. 90 /// DetachTo(struct_type & target)91 void DetachTo(struct_type& target) { 92 if (attached_to_ != &target) { 93 // Clear the target structure's values only if we are not currently 94 // attached to that structure. 95 Clear(&target); 96 } 97 98 // Transfer ownership of the values to the target structure. 99 memcpy(&target, static_cast<struct_type*>(this), sizeof(struct_type)); 100 101 // Remove the references from this object. 102 Init(); 103 } 104 105 /// 106 // Set this object's values. If |copy| is true the source structure's values 107 // will be copied instead of referenced. 108 /// Set(const struct_type & source,bool copy)109 void Set(const struct_type& source, bool copy) { 110 traits::set(&source, this, copy); 111 } 112 113 CefStructBase& operator=(const CefStructBase& s) { 114 return operator=(static_cast<const struct_type&>(s)); 115 } 116 117 CefStructBase& operator=(const struct_type& s) { 118 Set(s, true); 119 return *this; 120 } 121 122 protected: Init()123 void Init() { 124 memset(static_cast<struct_type*>(this), 0, sizeof(struct_type)); 125 attached_to_ = NULL; 126 traits::init(this); 127 } 128 Clear(struct_type * s)129 static void Clear(struct_type* s) { traits::clear(s); } 130 131 struct_type* attached_to_; 132 }; 133 134 struct CefPointTraits { 135 typedef cef_point_t struct_type; 136 initCefPointTraits137 static inline void init(struct_type* s) {} clearCefPointTraits138 static inline void clear(struct_type* s) {} 139 setCefPointTraits140 static inline void set(const struct_type* src, 141 struct_type* target, 142 bool copy) { 143 *target = *src; 144 } 145 }; 146 147 /// 148 // Class representing a point. 149 /// 150 class CefPoint : public CefStructBase<CefPointTraits> { 151 public: 152 typedef CefStructBase<CefPointTraits> parent; 153 CefPoint()154 CefPoint() {} CefPoint(const cef_point_t & r)155 CefPoint(const cef_point_t& r) : parent(r) {} CefPoint(int x,int y)156 CefPoint(int x, int y) { Set(x, y); } 157 IsEmpty()158 bool IsEmpty() const { return x <= 0 && y <= 0; } Set(int x_val,int y_val)159 void Set(int x_val, int y_val) { x = x_val, y = y_val; } 160 }; 161 162 inline bool operator==(const CefPoint& a, const CefPoint& b) { 163 return a.x == b.x && a.y == b.y; 164 } 165 166 inline bool operator!=(const CefPoint& a, const CefPoint& b) { 167 return !(a == b); 168 } 169 170 struct CefRectTraits { 171 typedef cef_rect_t struct_type; 172 initCefRectTraits173 static inline void init(struct_type* s) {} clearCefRectTraits174 static inline void clear(struct_type* s) {} 175 setCefRectTraits176 static inline void set(const struct_type* src, 177 struct_type* target, 178 bool copy) { 179 *target = *src; 180 } 181 }; 182 183 /// 184 // Class representing a rectangle. 185 /// 186 class CefRect : public CefStructBase<CefRectTraits> { 187 public: 188 typedef CefStructBase<CefRectTraits> parent; 189 CefRect()190 CefRect() {} CefRect(const cef_rect_t & r)191 CefRect(const cef_rect_t& r) : parent(r) {} CefRect(int x,int y,int width,int height)192 CefRect(int x, int y, int width, int height) { Set(x, y, width, height); } 193 IsEmpty()194 bool IsEmpty() const { return width <= 0 || height <= 0; } Set(int x_val,int y_val,int width_val,int height_val)195 void Set(int x_val, int y_val, int width_val, int height_val) { 196 x = x_val, y = y_val, width = width_val, height = height_val; 197 } 198 199 // Returns true if the point identified by point_x and point_y falls inside 200 // this rectangle. The point (x, y) is inside the rectangle, but the 201 // point (x + width, y + height) is not. Contains(int point_x,int point_y)202 bool Contains(int point_x, int point_y) const { 203 return (point_x >= x) && (point_x < x + width) && (point_y >= y) && 204 (point_y < y + height); 205 } Contains(const CefPoint & point)206 bool Contains(const CefPoint& point) const { 207 return Contains(point.x, point.y); 208 } 209 }; 210 211 inline bool operator==(const CefRect& a, const CefRect& b) { 212 return a.x == b.x && a.y == b.y && a.width == b.width && a.height == b.height; 213 } 214 215 inline bool operator!=(const CefRect& a, const CefRect& b) { 216 return !(a == b); 217 } 218 219 struct CefSizeTraits { 220 typedef cef_size_t struct_type; 221 initCefSizeTraits222 static inline void init(struct_type* s) {} clearCefSizeTraits223 static inline void clear(struct_type* s) {} 224 setCefSizeTraits225 static inline void set(const struct_type* src, 226 struct_type* target, 227 bool copy) { 228 *target = *src; 229 } 230 }; 231 232 /// 233 // Class representing a size. 234 /// 235 class CefSize : public CefStructBase<CefSizeTraits> { 236 public: 237 typedef CefStructBase<CefSizeTraits> parent; 238 CefSize()239 CefSize() {} CefSize(const cef_size_t & r)240 CefSize(const cef_size_t& r) : parent(r) {} CefSize(int width,int height)241 CefSize(int width, int height) { Set(width, height); } 242 IsEmpty()243 bool IsEmpty() const { return width <= 0 || height <= 0; } Set(int width_val,int height_val)244 void Set(int width_val, int height_val) { 245 width = width_val, height = height_val; 246 } 247 }; 248 249 inline bool operator==(const CefSize& a, const CefSize& b) { 250 return a.width == b.width && a.height == b.height; 251 } 252 253 inline bool operator!=(const CefSize& a, const CefSize& b) { 254 return !(a == b); 255 } 256 257 struct CefRangeTraits { 258 typedef cef_range_t struct_type; 259 initCefRangeTraits260 static inline void init(struct_type* s) {} clearCefRangeTraits261 static inline void clear(struct_type* s) {} 262 setCefRangeTraits263 static inline void set(const struct_type* src, 264 struct_type* target, 265 bool copy) { 266 *target = *src; 267 } 268 }; 269 270 /// 271 // Class representing a range. 272 /// 273 class CefRange : public CefStructBase<CefRangeTraits> { 274 public: 275 typedef CefStructBase<CefRangeTraits> parent; 276 CefRange()277 CefRange() {} CefRange(const cef_range_t & r)278 CefRange(const cef_range_t& r) : parent(r) {} CefRange(int from,int to)279 CefRange(int from, int to) { Set(from, to); } 280 Set(int from_val,int to_val)281 void Set(int from_val, int to_val) { from = from_val, to = to_val; } 282 }; 283 284 inline bool operator==(const CefRange& a, const CefRange& b) { 285 return a.from == b.from && a.to == b.to; 286 } 287 288 inline bool operator!=(const CefRange& a, const CefRange& b) { 289 return !(a == b); 290 } 291 292 struct CefInsetsTraits { 293 typedef cef_insets_t struct_type; 294 initCefInsetsTraits295 static inline void init(struct_type* s) {} clearCefInsetsTraits296 static inline void clear(struct_type* s) {} 297 setCefInsetsTraits298 static inline void set(const struct_type* src, 299 struct_type* target, 300 bool copy) { 301 *target = *src; 302 } 303 }; 304 305 /// 306 // Class representing insets. 307 /// 308 class CefInsets : public CefStructBase<CefInsetsTraits> { 309 public: 310 typedef CefStructBase<CefInsetsTraits> parent; 311 CefInsets()312 CefInsets() {} CefInsets(const cef_insets_t & r)313 CefInsets(const cef_insets_t& r) : parent(r) {} CefInsets(int top,int left,int bottom,int right)314 CefInsets(int top, int left, int bottom, int right) { 315 Set(top, left, bottom, right); 316 } 317 Set(int top_val,int left_val,int bottom_val,int right_val)318 void Set(int top_val, int left_val, int bottom_val, int right_val) { 319 top = top_val, left = left_val, bottom = bottom_val, right = right_val; 320 } 321 }; 322 323 inline bool operator==(const CefInsets& a, const CefInsets& b) { 324 return a.top == b.top && a.left == b.left && a.bottom == b.bottom && 325 a.right == b.right; 326 } 327 328 inline bool operator!=(const CefInsets& a, const CefInsets& b) { 329 return !(a == b); 330 } 331 332 struct CefDraggableRegionTraits { 333 typedef cef_draggable_region_t struct_type; 334 initCefDraggableRegionTraits335 static inline void init(struct_type* s) {} clearCefDraggableRegionTraits336 static inline void clear(struct_type* s) {} 337 setCefDraggableRegionTraits338 static inline void set(const struct_type* src, 339 struct_type* target, 340 bool copy) { 341 *target = *src; 342 } 343 }; 344 345 /// 346 // Class representing a draggable region. 347 /// 348 class CefDraggableRegion : public CefStructBase<CefDraggableRegionTraits> { 349 public: 350 typedef CefStructBase<CefDraggableRegionTraits> parent; 351 CefDraggableRegion()352 CefDraggableRegion() {} CefDraggableRegion(const cef_draggable_region_t & r)353 CefDraggableRegion(const cef_draggable_region_t& r) : parent(r) {} CefDraggableRegion(const CefRect & bounds,bool draggable)354 CefDraggableRegion(const CefRect& bounds, bool draggable) { 355 Set(bounds, draggable); 356 } 357 Set(const CefRect & bounds_val,bool draggable_val)358 void Set(const CefRect& bounds_val, bool draggable_val) { 359 bounds = bounds_val, draggable = draggable_val; 360 } 361 }; 362 363 inline bool operator==(const CefDraggableRegion& a, 364 const CefDraggableRegion& b) { 365 return a.bounds == b.bounds && a.draggable == b.draggable; 366 } 367 368 inline bool operator!=(const CefDraggableRegion& a, 369 const CefDraggableRegion& b) { 370 return !(a == b); 371 } 372 373 struct CefScreenInfoTraits { 374 typedef cef_screen_info_t struct_type; 375 initCefScreenInfoTraits376 static inline void init(struct_type* s) {} 377 clearCefScreenInfoTraits378 static inline void clear(struct_type* s) {} 379 setCefScreenInfoTraits380 static inline void set(const struct_type* src, 381 struct_type* target, 382 bool copy) { 383 target->device_scale_factor = src->device_scale_factor; 384 target->depth = src->depth; 385 target->depth_per_component = src->depth_per_component; 386 target->is_monochrome = src->is_monochrome; 387 target->rect = src->rect; 388 target->available_rect = src->available_rect; 389 } 390 }; 391 392 /// 393 // Class representing the virtual screen information for use when window 394 // rendering is disabled. 395 /// 396 class CefScreenInfo : public CefStructBase<CefScreenInfoTraits> { 397 public: 398 typedef CefStructBase<CefScreenInfoTraits> parent; 399 CefScreenInfo()400 CefScreenInfo() {} CefScreenInfo(const cef_screen_info_t & r)401 CefScreenInfo(const cef_screen_info_t& r) : parent(r) {} CefScreenInfo(float device_scale_factor,int depth,int depth_per_component,bool is_monochrome,const CefRect & rect,const CefRect & available_rect)402 CefScreenInfo(float device_scale_factor, 403 int depth, 404 int depth_per_component, 405 bool is_monochrome, 406 const CefRect& rect, 407 const CefRect& available_rect) { 408 Set(device_scale_factor, depth, depth_per_component, is_monochrome, rect, 409 available_rect); 410 } 411 Set(float device_scale_factor_val,int depth_val,int depth_per_component_val,bool is_monochrome_val,const CefRect & rect_val,const CefRect & available_rect_val)412 void Set(float device_scale_factor_val, 413 int depth_val, 414 int depth_per_component_val, 415 bool is_monochrome_val, 416 const CefRect& rect_val, 417 const CefRect& available_rect_val) { 418 device_scale_factor = device_scale_factor_val; 419 depth = depth_val; 420 depth_per_component = depth_per_component_val; 421 is_monochrome = is_monochrome_val; 422 rect = rect_val; 423 available_rect = available_rect_val; 424 } 425 }; 426 427 struct CefKeyEventTraits { 428 typedef cef_key_event_t struct_type; 429 initCefKeyEventTraits430 static inline void init(struct_type* s) {} 431 clearCefKeyEventTraits432 static inline void clear(struct_type* s) {} 433 setCefKeyEventTraits434 static inline void set(const struct_type* src, 435 struct_type* target, 436 bool copy) { 437 target->type = src->type; 438 target->modifiers = src->modifiers; 439 target->windows_key_code = src->windows_key_code; 440 target->native_key_code = src->native_key_code; 441 target->is_system_key = src->is_system_key; 442 target->character = src->character; 443 target->unmodified_character = src->unmodified_character; 444 target->focus_on_editable_field = src->focus_on_editable_field; 445 } 446 }; 447 448 /// 449 // Class representing a a keyboard event. 450 /// 451 typedef CefStructBase<CefKeyEventTraits> CefKeyEvent; 452 453 struct CefMouseEventTraits { 454 typedef cef_mouse_event_t struct_type; 455 initCefMouseEventTraits456 static inline void init(struct_type* s) {} 457 clearCefMouseEventTraits458 static inline void clear(struct_type* s) {} 459 setCefMouseEventTraits460 static inline void set(const struct_type* src, 461 struct_type* target, 462 bool copy) { 463 target->x = src->x; 464 target->y = src->y; 465 target->modifiers = src->modifiers; 466 } 467 }; 468 469 /// 470 // Class representing a mouse event. 471 /// 472 typedef CefStructBase<CefMouseEventTraits> CefMouseEvent; 473 474 struct CefTouchEventTraits { 475 typedef cef_touch_event_t struct_type; 476 initCefTouchEventTraits477 static inline void init(struct_type* s) {} 478 clearCefTouchEventTraits479 static inline void clear(struct_type* s) {} 480 setCefTouchEventTraits481 static inline void set(const struct_type* src, 482 struct_type* target, 483 bool copy) { 484 *target = *src; 485 } 486 }; 487 488 /// 489 // Class representing a touch event. 490 /// 491 typedef CefStructBase<CefTouchEventTraits> CefTouchEvent; 492 493 struct CefPopupFeaturesTraits { 494 typedef cef_popup_features_t struct_type; 495 initCefPopupFeaturesTraits496 static inline void init(struct_type* s) { 497 s->menuBarVisible = true; 498 s->statusBarVisible = true; 499 s->toolBarVisible = true; 500 s->scrollbarsVisible = true; 501 } 502 clearCefPopupFeaturesTraits503 static inline void clear(struct_type* s) {} 504 setCefPopupFeaturesTraits505 static inline void set(const struct_type* src, 506 struct_type* target, 507 bool copy) { 508 target->x = src->x; 509 target->xSet = src->xSet; 510 target->y = src->y; 511 target->ySet = src->ySet; 512 target->width = src->width; 513 target->widthSet = src->widthSet; 514 target->height = src->height; 515 target->heightSet = src->heightSet; 516 target->menuBarVisible = src->menuBarVisible; 517 target->statusBarVisible = src->statusBarVisible; 518 target->toolBarVisible = src->toolBarVisible; 519 target->scrollbarsVisible = src->scrollbarsVisible; 520 } 521 }; 522 523 /// 524 // Class representing popup window features. 525 /// 526 typedef CefStructBase<CefPopupFeaturesTraits> CefPopupFeatures; 527 528 struct CefSettingsTraits { 529 typedef cef_settings_t struct_type; 530 initCefSettingsTraits531 static inline void init(struct_type* s) { s->size = sizeof(struct_type); } 532 clearCefSettingsTraits533 static inline void clear(struct_type* s) { 534 cef_string_clear(&s->browser_subprocess_path); 535 cef_string_clear(&s->framework_dir_path); 536 cef_string_clear(&s->main_bundle_path); 537 cef_string_clear(&s->cache_path); 538 cef_string_clear(&s->root_cache_path); 539 cef_string_clear(&s->user_data_path); 540 cef_string_clear(&s->user_agent); 541 cef_string_clear(&s->user_agent_product); 542 cef_string_clear(&s->locale); 543 cef_string_clear(&s->log_file); 544 cef_string_clear(&s->javascript_flags); 545 cef_string_clear(&s->resources_dir_path); 546 cef_string_clear(&s->locales_dir_path); 547 cef_string_clear(&s->accept_language_list); 548 cef_string_clear(&s->cookieable_schemes_list); 549 cef_string_clear(&s->application_client_id_for_file_scanning); 550 } 551 setCefSettingsTraits552 static inline void set(const struct_type* src, 553 struct_type* target, 554 bool copy) { 555 target->no_sandbox = src->no_sandbox; 556 cef_string_set(src->browser_subprocess_path.str, 557 src->browser_subprocess_path.length, 558 &target->browser_subprocess_path, copy); 559 cef_string_set(src->framework_dir_path.str, src->framework_dir_path.length, 560 &target->framework_dir_path, copy); 561 cef_string_set(src->main_bundle_path.str, src->main_bundle_path.length, 562 &target->main_bundle_path, copy); 563 target->chrome_runtime = src->chrome_runtime; 564 target->multi_threaded_message_loop = src->multi_threaded_message_loop; 565 target->external_message_pump = src->external_message_pump; 566 target->windowless_rendering_enabled = src->windowless_rendering_enabled; 567 target->command_line_args_disabled = src->command_line_args_disabled; 568 569 cef_string_set(src->cache_path.str, src->cache_path.length, 570 &target->cache_path, copy); 571 cef_string_set(src->root_cache_path.str, src->root_cache_path.length, 572 &target->root_cache_path, copy); 573 cef_string_set(src->user_data_path.str, src->user_data_path.length, 574 &target->user_data_path, copy); 575 target->persist_session_cookies = src->persist_session_cookies; 576 target->persist_user_preferences = src->persist_user_preferences; 577 578 cef_string_set(src->user_agent.str, src->user_agent.length, 579 &target->user_agent, copy); 580 cef_string_set(src->user_agent_product.str, src->user_agent_product.length, 581 &target->user_agent_product, copy); 582 cef_string_set(src->locale.str, src->locale.length, &target->locale, copy); 583 584 cef_string_set(src->log_file.str, src->log_file.length, &target->log_file, 585 copy); 586 target->log_severity = src->log_severity; 587 cef_string_set(src->javascript_flags.str, src->javascript_flags.length, 588 &target->javascript_flags, copy); 589 590 cef_string_set(src->resources_dir_path.str, src->resources_dir_path.length, 591 &target->resources_dir_path, copy); 592 cef_string_set(src->locales_dir_path.str, src->locales_dir_path.length, 593 &target->locales_dir_path, copy); 594 target->pack_loading_disabled = src->pack_loading_disabled; 595 target->remote_debugging_port = src->remote_debugging_port; 596 target->uncaught_exception_stack_size = src->uncaught_exception_stack_size; 597 target->background_color = src->background_color; 598 599 cef_string_set(src->accept_language_list.str, 600 src->accept_language_list.length, 601 &target->accept_language_list, copy); 602 603 cef_string_set(src->cookieable_schemes_list.str, 604 src->cookieable_schemes_list.length, 605 &target->cookieable_schemes_list, copy); 606 target->cookieable_schemes_exclude_defaults = 607 src->cookieable_schemes_exclude_defaults; 608 609 cef_string_set(src->application_client_id_for_file_scanning.str, 610 src->application_client_id_for_file_scanning.length, 611 &target->application_client_id_for_file_scanning, copy); 612 } 613 }; 614 615 /// 616 // Class representing initialization settings. 617 /// 618 typedef CefStructBase<CefSettingsTraits> CefSettings; 619 620 struct CefRequestContextSettingsTraits { 621 typedef cef_request_context_settings_t struct_type; 622 initCefRequestContextSettingsTraits623 static inline void init(struct_type* s) { s->size = sizeof(struct_type); } 624 clearCefRequestContextSettingsTraits625 static inline void clear(struct_type* s) { 626 cef_string_clear(&s->cache_path); 627 cef_string_clear(&s->accept_language_list); 628 cef_string_clear(&s->cookieable_schemes_list); 629 } 630 setCefRequestContextSettingsTraits631 static inline void set(const struct_type* src, 632 struct_type* target, 633 bool copy) { 634 cef_string_set(src->cache_path.str, src->cache_path.length, 635 &target->cache_path, copy); 636 target->persist_session_cookies = src->persist_session_cookies; 637 target->persist_user_preferences = src->persist_user_preferences; 638 cef_string_set(src->accept_language_list.str, 639 src->accept_language_list.length, 640 &target->accept_language_list, copy); 641 642 cef_string_set(src->cookieable_schemes_list.str, 643 src->cookieable_schemes_list.length, 644 &target->cookieable_schemes_list, copy); 645 target->cookieable_schemes_exclude_defaults = 646 src->cookieable_schemes_exclude_defaults; 647 } 648 }; 649 650 /// 651 // Class representing request context initialization settings. 652 /// 653 typedef CefStructBase<CefRequestContextSettingsTraits> 654 CefRequestContextSettings; 655 656 struct CefBrowserSettingsTraits { 657 typedef cef_browser_settings_t struct_type; 658 initCefBrowserSettingsTraits659 static inline void init(struct_type* s) { s->size = sizeof(struct_type); } 660 clearCefBrowserSettingsTraits661 static inline void clear(struct_type* s) { 662 cef_string_clear(&s->standard_font_family); 663 cef_string_clear(&s->fixed_font_family); 664 cef_string_clear(&s->serif_font_family); 665 cef_string_clear(&s->sans_serif_font_family); 666 cef_string_clear(&s->cursive_font_family); 667 cef_string_clear(&s->fantasy_font_family); 668 cef_string_clear(&s->default_encoding); 669 cef_string_clear(&s->accept_language_list); 670 } 671 setCefBrowserSettingsTraits672 static inline void set(const struct_type* src, 673 struct_type* target, 674 bool copy) { 675 target->windowless_frame_rate = src->windowless_frame_rate; 676 677 cef_string_set(src->standard_font_family.str, 678 src->standard_font_family.length, 679 &target->standard_font_family, copy); 680 cef_string_set(src->fixed_font_family.str, src->fixed_font_family.length, 681 &target->fixed_font_family, copy); 682 cef_string_set(src->serif_font_family.str, src->serif_font_family.length, 683 &target->serif_font_family, copy); 684 cef_string_set(src->sans_serif_font_family.str, 685 src->sans_serif_font_family.length, 686 &target->sans_serif_font_family, copy); 687 cef_string_set(src->cursive_font_family.str, 688 src->cursive_font_family.length, 689 &target->cursive_font_family, copy); 690 cef_string_set(src->fantasy_font_family.str, 691 src->fantasy_font_family.length, 692 &target->fantasy_font_family, copy); 693 694 target->default_font_size = src->default_font_size; 695 target->default_fixed_font_size = src->default_fixed_font_size; 696 target->minimum_font_size = src->minimum_font_size; 697 target->minimum_logical_font_size = src->minimum_logical_font_size; 698 699 cef_string_set(src->default_encoding.str, src->default_encoding.length, 700 &target->default_encoding, copy); 701 702 target->remote_fonts = src->remote_fonts; 703 target->javascript = src->javascript; 704 target->javascript_close_windows = src->javascript_close_windows; 705 target->javascript_access_clipboard = src->javascript_access_clipboard; 706 target->javascript_dom_paste = src->javascript_dom_paste; 707 target->plugins = src->plugins; 708 target->image_loading = src->image_loading; 709 target->image_shrink_standalone_to_fit = 710 src->image_shrink_standalone_to_fit; 711 target->text_area_resize = src->text_area_resize; 712 target->tab_to_links = src->tab_to_links; 713 target->local_storage = src->local_storage; 714 target->databases = src->databases; 715 target->webgl = src->webgl; 716 717 target->background_color = src->background_color; 718 719 cef_string_set(src->accept_language_list.str, 720 src->accept_language_list.length, 721 &target->accept_language_list, copy); 722 } 723 }; 724 725 /// 726 // Class representing browser initialization settings. 727 /// 728 typedef CefStructBase<CefBrowserSettingsTraits> CefBrowserSettings; 729 730 struct CefURLPartsTraits { 731 typedef cef_urlparts_t struct_type; 732 initCefURLPartsTraits733 static inline void init(struct_type* s) {} 734 clearCefURLPartsTraits735 static inline void clear(struct_type* s) { 736 cef_string_clear(&s->spec); 737 cef_string_clear(&s->scheme); 738 cef_string_clear(&s->username); 739 cef_string_clear(&s->password); 740 cef_string_clear(&s->host); 741 cef_string_clear(&s->port); 742 cef_string_clear(&s->origin); 743 cef_string_clear(&s->path); 744 cef_string_clear(&s->query); 745 cef_string_clear(&s->fragment); 746 } 747 setCefURLPartsTraits748 static inline void set(const struct_type* src, 749 struct_type* target, 750 bool copy) { 751 cef_string_set(src->spec.str, src->spec.length, &target->spec, copy); 752 cef_string_set(src->scheme.str, src->scheme.length, &target->scheme, copy); 753 cef_string_set(src->username.str, src->username.length, &target->username, 754 copy); 755 cef_string_set(src->password.str, src->password.length, &target->password, 756 copy); 757 cef_string_set(src->host.str, src->host.length, &target->host, copy); 758 cef_string_set(src->port.str, src->port.length, &target->port, copy); 759 cef_string_set(src->origin.str, src->origin.length, &target->origin, copy); 760 cef_string_set(src->path.str, src->path.length, &target->path, copy); 761 cef_string_set(src->query.str, src->query.length, &target->query, copy); 762 cef_string_set(src->fragment.str, src->fragment.length, &target->fragment, 763 copy); 764 } 765 }; 766 767 /// 768 // Class representing a URL's component parts. 769 /// 770 typedef CefStructBase<CefURLPartsTraits> CefURLParts; 771 772 struct CefTimeTraits { 773 typedef cef_time_t struct_type; 774 initCefTimeTraits775 static inline void init(struct_type* s) {} 776 clearCefTimeTraits777 static inline void clear(struct_type* s) {} 778 setCefTimeTraits779 static inline void set(const struct_type* src, 780 struct_type* target, 781 bool copy) { 782 *target = *src; 783 } 784 }; 785 786 /// 787 // Class representing a time. 788 /// 789 class CefTime : public CefStructBase<CefTimeTraits> { 790 public: 791 typedef CefStructBase<CefTimeTraits> parent; 792 CefTime()793 CefTime() {} CefTime(const cef_time_t & r)794 CefTime(const cef_time_t& r) : parent(r) {} CefTime(time_t r)795 explicit CefTime(time_t r) { SetTimeT(r); } CefTime(double r)796 explicit CefTime(double r) { SetDoubleT(r); } 797 798 // Converts to/from time_t. SetTimeT(time_t r)799 void SetTimeT(time_t r) { cef_time_from_timet(r, this); } GetTimeT()800 time_t GetTimeT() const { 801 time_t time = 0; 802 cef_time_to_timet(this, &time); 803 return time; 804 } 805 806 // Converts to/from a double which is the number of seconds since epoch 807 // (Jan 1, 1970). Webkit uses this format to represent time. A value of 0 808 // means "not initialized". SetDoubleT(double r)809 void SetDoubleT(double r) { cef_time_from_doublet(r, this); } GetDoubleT()810 double GetDoubleT() const { 811 double time = 0; 812 cef_time_to_doublet(this, &time); 813 return time; 814 } 815 816 // Set this object to now. Now()817 void Now() { cef_time_now(this); } 818 819 // Return the delta between this object and |other| in milliseconds. Delta(const CefTime & other)820 long long Delta(const CefTime& other) { 821 long long delta = 0; 822 cef_time_delta(this, &other, &delta); 823 return delta; 824 } 825 }; 826 827 struct CefCookieTraits { 828 typedef cef_cookie_t struct_type; 829 initCefCookieTraits830 static inline void init(struct_type* s) {} 831 clearCefCookieTraits832 static inline void clear(struct_type* s) { 833 cef_string_clear(&s->name); 834 cef_string_clear(&s->value); 835 cef_string_clear(&s->domain); 836 cef_string_clear(&s->path); 837 } 838 setCefCookieTraits839 static inline void set(const struct_type* src, 840 struct_type* target, 841 bool copy) { 842 cef_string_set(src->name.str, src->name.length, &target->name, copy); 843 cef_string_set(src->value.str, src->value.length, &target->value, copy); 844 cef_string_set(src->domain.str, src->domain.length, &target->domain, copy); 845 cef_string_set(src->path.str, src->path.length, &target->path, copy); 846 target->secure = src->secure; 847 target->httponly = src->httponly; 848 target->creation = src->creation; 849 target->last_access = src->last_access; 850 target->has_expires = src->has_expires; 851 target->expires = src->expires; 852 target->same_site = src->same_site; 853 target->priority = src->priority; 854 } 855 }; 856 857 /// 858 // Class representing a cookie. 859 /// 860 typedef CefStructBase<CefCookieTraits> CefCookie; 861 862 struct CefCursorInfoTraits { 863 typedef cef_cursor_info_t struct_type; 864 initCefCursorInfoTraits865 static inline void init(struct_type* s) {} 866 clearCefCursorInfoTraits867 static inline void clear(struct_type* s) {} 868 setCefCursorInfoTraits869 static inline void set(const struct_type* src, 870 struct_type* target, 871 bool copy) { 872 *target = *src; 873 } 874 }; 875 876 /// 877 // Class representing cursor information. 878 /// 879 typedef CefStructBase<CefCursorInfoTraits> CefCursorInfo; 880 881 struct CefPdfPrintSettingsTraits { 882 typedef cef_pdf_print_settings_t struct_type; 883 initCefPdfPrintSettingsTraits884 static inline void init(struct_type* s) {} 885 clearCefPdfPrintSettingsTraits886 static inline void clear(struct_type* s) { 887 cef_string_clear(&s->header_footer_title); 888 cef_string_clear(&s->header_footer_url); 889 } 890 setCefPdfPrintSettingsTraits891 static inline void set(const struct_type* src, 892 struct_type* target, 893 bool copy) { 894 cef_string_set(src->header_footer_title.str, 895 src->header_footer_title.length, 896 &target->header_footer_title, copy); 897 cef_string_set(src->header_footer_url.str, src->header_footer_url.length, 898 &target->header_footer_url, copy); 899 900 target->page_width = src->page_width; 901 target->page_height = src->page_height; 902 903 target->scale_factor = src->scale_factor; 904 905 target->margin_top = src->margin_top; 906 target->margin_right = src->margin_right; 907 target->margin_bottom = src->margin_bottom; 908 target->margin_left = src->margin_left; 909 target->margin_type = src->margin_type; 910 911 target->header_footer_enabled = src->header_footer_enabled; 912 target->selection_only = src->selection_only; 913 target->landscape = src->landscape; 914 target->backgrounds_enabled = src->backgrounds_enabled; 915 } 916 }; 917 918 /// 919 // Class representing PDF print settings 920 /// 921 typedef CefStructBase<CefPdfPrintSettingsTraits> CefPdfPrintSettings; 922 923 struct CefBoxLayoutSettingsTraits { 924 typedef cef_box_layout_settings_t struct_type; 925 initCefBoxLayoutSettingsTraits926 static inline void init(struct_type* s) {} 927 clearCefBoxLayoutSettingsTraits928 static inline void clear(struct_type* s) {} 929 setCefBoxLayoutSettingsTraits930 static inline void set(const struct_type* src, 931 struct_type* target, 932 bool copy) { 933 *target = *src; 934 } 935 }; 936 937 /// 938 // Class representing CefBoxLayout settings. 939 /// 940 typedef CefStructBase<CefBoxLayoutSettingsTraits> CefBoxLayoutSettings; 941 942 struct CefCompositionUnderlineTraits { 943 typedef cef_composition_underline_t struct_type; 944 initCefCompositionUnderlineTraits945 static inline void init(struct_type* s) {} 946 clearCefCompositionUnderlineTraits947 static inline void clear(struct_type* s) {} 948 setCefCompositionUnderlineTraits949 static inline void set(const struct_type* src, 950 struct_type* target, 951 bool copy) { 952 *target = *src; 953 } 954 }; 955 956 /// 957 // Class representing IME composition underline. 958 /// 959 typedef CefStructBase<CefCompositionUnderlineTraits> CefCompositionUnderline; 960 961 struct CefAudioParametersTraits { 962 typedef cef_audio_parameters_t struct_type; 963 initCefAudioParametersTraits964 static inline void init(struct_type* s) {} 965 clearCefAudioParametersTraits966 static inline void clear(struct_type* s) {} 967 setCefAudioParametersTraits968 static inline void set(const struct_type* src, 969 struct_type* target, 970 bool copy) { 971 *target = *src; 972 } 973 }; 974 975 /// 976 // Class representing CefAudioParameters settings 977 /// 978 typedef CefStructBase<CefAudioParametersTraits> CefAudioParameters; 979 980 struct CefMediaSinkDeviceInfoTraits { 981 typedef cef_media_sink_device_info_t struct_type; 982 initCefMediaSinkDeviceInfoTraits983 static inline void init(struct_type* s) {} 984 clearCefMediaSinkDeviceInfoTraits985 static inline void clear(struct_type* s) { 986 cef_string_clear(&s->ip_address); 987 cef_string_clear(&s->model_name); 988 } 989 setCefMediaSinkDeviceInfoTraits990 static inline void set(const struct_type* src, 991 struct_type* target, 992 bool copy) { 993 cef_string_set(src->ip_address.str, src->ip_address.length, 994 &target->ip_address, copy); 995 target->port = src->port; 996 cef_string_set(src->model_name.str, src->model_name.length, 997 &target->model_name, copy); 998 } 999 }; 1000 1001 /// 1002 // Class representing MediaSink device info. 1003 /// 1004 typedef CefStructBase<CefMediaSinkDeviceInfoTraits> CefMediaSinkDeviceInfo; 1005 1006 #endif // CEF_INCLUDE_INTERNAL_CEF_TYPES_WRAPPERS_H_ 1007