├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── base ├── BUILD.gn ├── singleton_fingerprint.cc └── singleton_fingerprint.h ├── cc └── base │ ├── switches.cc │ └── switches.h ├── chrome ├── BUILD.gn ├── VERSION ├── app │ ├── aes_diy_util.h │ ├── chrome_exe_main_win.cc │ ├── chrome_main.cc │ ├── fetch_http_response.h │ └── fingerprint_to-bean.h └── browser │ ├── BUILD.gn │ ├── chrome_browser_main.cc │ ├── chrome_content_browser_client.cc │ ├── fp_profile.h │ └── net │ ├── fp_proxying_url_loader_factory.cc │ └── fp_proxying_url_loader_factory.h ├── components ├── embedder_support │ ├── pf_user_agent_metadata.h │ └── user_agent_utils.cc ├── language │ └── core │ │ └── browser │ │ ├── fp_language.h │ │ └── language_prefs.cc └── permissions │ ├── permission_context_base.cc │ └── permission_context_base_fp.h ├── content ├── browser │ ├── renderer_host │ │ ├── dwrite_font_proxy_impl_win.cc │ │ ├── pf_font_find_family.h │ │ └── render_process_host_impl.cc │ └── web_contents │ │ └── web_contents_impl.cc ├── child │ └── dwrite_font_proxy │ │ ├── dwrite_font_proxy_win.cc │ │ └── fp_dwite_font.h ├── common │ └── renderer.mojom └── renderer │ ├── render_thread_impl.cc │ └── render_thread_impl.h ├── third_party ├── blink │ ├── common │ │ └── fingerprint │ │ │ ├── OWNERS │ │ │ └── fingerprint_mojom_traits.cc │ ├── public │ │ ├── common │ │ │ └── fingerprint │ │ │ │ ├── OWNERS │ │ │ │ ├── fingerprint.h │ │ │ │ └── fingerprint_mojom_traits.h │ │ └── mojom │ │ │ ├── BUILD.gn │ │ │ └── fingerprint │ │ │ └── fingerprint.mojom │ └── renderer │ │ ├── core │ │ ├── dom │ │ │ ├── element.cc │ │ │ └── element_fp.h │ │ ├── frame │ │ │ ├── fp_js_screen.h │ │ │ ├── navigator.cc │ │ │ ├── navigator_concurrent_hardware.cc │ │ │ ├── navigator_device_memory.cc │ │ │ └── screen.cc │ │ └── html │ │ │ ├── build.gni │ │ │ ├── canvas │ │ │ ├── canvas_rendering_context.h │ │ │ ├── fp_textMetrics.h │ │ │ ├── html_canvas_element.cc │ │ │ ├── html_canvas_element_fp.cc │ │ │ ├── html_canvas_element_fp.h │ │ │ └── text_metrics.cc │ │ │ ├── fp_elecment_offset.h │ │ │ └── html_element.cc │ │ ├── modules │ │ ├── canvas │ │ │ ├── BUILD.gn │ │ │ ├── canvas2d │ │ │ │ ├── canvas_rendering_context_2d.cc │ │ │ │ ├── canvas_rendering_context_2d.h │ │ │ │ ├── canvas_rendering_context_2d_fp.cc │ │ │ │ └── canvas_rendering_context_2d_fp.h │ │ │ └── offscreencanvas2d │ │ │ │ ├── offscreen_canvas_rendering_context_2d.cc │ │ │ │ └── offscreen_canvas_rendering_context_2d.h │ │ ├── geolocation │ │ │ ├── fp_geolocation.h │ │ │ └── geolocation.cc │ │ ├── mediastream │ │ │ ├── media_devices.cc │ │ │ ├── media_devices_fp.h │ │ │ ├── media_stream_track_impl.cc │ │ │ └── media_stream_track_impl_fp.h │ │ ├── speech │ │ │ ├── speech_synthesis.cc │ │ │ ├── speech_synthesis.h │ │ │ └── speech_synthesis_fp.h │ │ ├── webaudio │ │ │ ├── offline_audio_context.cc │ │ │ └── offline_audio_context_fp.h │ │ ├── webgl │ │ │ ├── webgl_rendering_context_base.cc │ │ │ └── webgl_rendering_context_base_fp.h │ │ └── webgpu │ │ │ ├── gpu_adapter.cc │ │ │ ├── gpu_adapter_fp.h │ │ │ ├── gpu_command_encoder.cc │ │ │ └── gpu_command_encoder_fp.h │ │ └── platform │ │ └── fonts │ │ └── win │ │ ├── font_cache_skia_win.cc │ │ └── font_cache_skia_win_fp.h └── webrtc │ └── pc │ ├── fp_web_rtc.h │ └── peer_connection.cc └── ui └── views └── win ├── fp_resolution.h ├── fp_resolution_full_screen.h ├── fullscreen_handler.cc └── hwnd_message_handler.cc /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | *.smod 22 | 23 | # Compiled Static libraries 24 | *.lai 25 | *.la 26 | *.a 27 | *.lib 28 | 29 | # Executables 30 | *.exe 31 | *.out 32 | *.app 33 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # openFpchromium 2 | # 指纹浏览器 3 | # fp-Browser 4 | 支持市面的所有的参数 5 | openFpchromium,基于v114 chromium 开发 开源指纹游览器 6 | -------------------------------------------------------------------------------- /base/singleton_fingerprint.cc: -------------------------------------------------------------------------------- 1 | #include "base/singleton_fingerprint.h" 2 | 3 | #include "base/check_op.h" 4 | #include 5 | #include "third_party/blink/public/common/fingerprint/fingerprint.h" 6 | #include "third_party/blink/public/common/user_agent/user_agent_metadata.h" 7 | 8 | 9 | namespace base{ 10 | 11 | 12 | SingletonFingerprint* SingletonFingerprint::singletonFingerprint_= nullptr; 13 | 14 | namespace { 15 | 16 | } // namespace 17 | 18 | SingletonFingerprint::SingletonFingerprint() = default; 19 | 20 | SingletonFingerprint::SingletonFingerprint(const SingletonFingerprint& other) = default; 21 | 22 | SingletonFingerprint& SingletonFingerprint::operator=(const SingletonFingerprint& other) = default; 23 | 24 | SingletonFingerprint::~SingletonFingerprint() = default; 25 | 26 | // static 27 | bool SingletonFingerprint::Init() { 28 | if (singletonFingerprint_) { 29 | return false; 30 | } 31 | singletonFingerprint_ = new SingletonFingerprint(); 32 | blink::fp::Fingerprint fingerprint; 33 | fingerprint.init = 0; 34 | singletonFingerprint_->fingerprint_ =fingerprint; 35 | singletonFingerprint_->init_ = true; 36 | return true; 37 | } 38 | 39 | // static 40 | bool SingletonFingerprint::Init(const blink::fp::Fingerprint& inputFingerprint) { 41 | if (!singletonFingerprint_) { 42 | singletonFingerprint_ = new SingletonFingerprint(); 43 | } 44 | singletonFingerprint_->fingerprint_ = inputFingerprint; 45 | singletonFingerprint_->init_ = true; 46 | return true; 47 | } 48 | 49 | // static 50 | SingletonFingerprint* SingletonFingerprint::ForCurrentProcess(){ 51 | /* if (singletonFingerprint_) { 52 | return singletonFingerprint_; 53 | } 54 | singletonFingerprint_ = new SingletonFingerprint(); 55 | blink::fp::Fingerprint fingerprint; 56 | fingerprint.init = 0; 57 | singletonFingerprint_->fingerprint_ = fingerprint; 58 | singletonFingerprint_->init_ = true;*/ 59 | DCHECK(singletonFingerprint_); 60 | return singletonFingerprint_; 61 | } 62 | 63 | } // namespace base 64 | 65 | -------------------------------------------------------------------------------- /base/singleton_fingerprint.h: -------------------------------------------------------------------------------- 1 | #ifndef BASE_SINGLETON_FINGERPRINT_H_ 2 | #define BASE_SINGLETON_FINGERPRINT_H_ 3 | 4 | #include 5 | #include "base/debug/debugging_buildflags.h" 6 | //#include "build/build_config.h" 7 | #include "third_party/blink/public/common/fingerprint/fingerprint.h" 8 | #include "base/base_export.h" 9 | 10 | 11 | namespace base { 12 | 13 | class BASE_EXPORT SingletonFingerprint { 14 | public: 15 | SingletonFingerprint(); 16 | SingletonFingerprint(const SingletonFingerprint& other); 17 | SingletonFingerprint& operator=(const SingletonFingerprint& other); 18 | ~SingletonFingerprint(); 19 | 20 | bool GetInit() const { return init_; } 21 | const blink::fp::Fingerprint& GetFingerprint() const { 22 | return fingerprint_; 23 | } 24 | 25 | bool setFontDefaultInfo(int index, std::string name){ 26 | fingerprint_.font.defaultId = index; 27 | fingerprint_.font.defaultName = name; 28 | return true; 29 | } 30 | 31 | static bool GetInit(SingletonFingerprint* singletonFingerprint){ 32 | if(!singletonFingerprint->GetInit()){ 33 | return false; 34 | } 35 | if(singletonFingerprint->GetFingerprint().init<2){ 36 | return false; 37 | } 38 | return true; 39 | 40 | } 41 | static bool Init(); 42 | static bool Init(const blink::fp::Fingerprint& inputFingerprint); 43 | static SingletonFingerprint* ForCurrentProcess(); 44 | 45 | 46 | private: 47 | bool init_ = false; 48 | blink::fp::Fingerprint fingerprint_; 49 | static SingletonFingerprint* singletonFingerprint_; 50 | //InstanceBoundSequenceChecker sequence_checker_; 51 | 52 | }; 53 | } // namespace base 54 | #endif // BASE_SINGLETON_FINGERPRINT_H_ 55 | 56 | -------------------------------------------------------------------------------- /cc/base/switches.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Chromium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "cc/base/switches.h" 6 | 7 | #include "base/command_line.h" 8 | 9 | namespace cc { 10 | namespace switches { 11 | 12 | const char kDisableThreadedAnimation[] = "disable-threaded-animation"; 13 | 14 | // Disables layer-edge anti-aliasing in the compositor. 15 | const char kDisableCompositedAntialiasing[] = 16 | "disable-composited-antialiasing"; 17 | 18 | // Disables sending the next BeginMainFrame before the previous commit 19 | // activates. Overrides the kEnableMainFrameBeforeActivation flag. 20 | const char kDisableMainFrameBeforeActivation[] = 21 | "disable-main-frame-before-activation"; 22 | 23 | // Enables sending the next BeginMainFrame before the previous commit activates. 24 | const char kEnableMainFrameBeforeActivation[] = 25 | "enable-main-frame-before-activation"; 26 | 27 | // Disabled defering all image decodes to the image decode service, ignoring 28 | // DecodingMode preferences specified on PaintImage. 29 | const char kDisableCheckerImaging[] = "disable-checker-imaging"; 30 | 31 | // Percentage of the browser controls need to be hidden before they will auto 32 | // hide. 33 | const char kBrowserControlsHideThreshold[] = "top-controls-hide-threshold"; 34 | 35 | // Percentage of the browser controls need to be shown before they will auto 36 | // show. 37 | const char kBrowserControlsShowThreshold[] = "top-controls-show-threshold"; 38 | 39 | // Re-rasters everything multiple times to simulate a much slower machine. 40 | // Give a scale factor to cause raster to take that many times longer to 41 | // complete, such as --slow-down-raster-scale-factor=25. 42 | const char kSlowDownRasterScaleFactor[] = "slow-down-raster-scale-factor"; 43 | 44 | // Checks damage early and aborts the frame if no damage, so that clients like 45 | // Android WebView don't invalidate unnecessarily. 46 | const char kCheckDamageEarly[] = "check-damage-early"; 47 | 48 | // Enables the GPU benchmarking extension 49 | const char kEnableGpuBenchmarking[] = "enable-gpu-benchmarking"; 50 | 51 | // Disables LayerTreeHost::OnMemoryPressure 52 | const char kDisableLayerTreeHostMemoryPressure[] = 53 | "disable-layer-tree-host-memory-pressure"; 54 | 55 | // Controls the number of threads to use for raster tasks. 56 | const char kNumRasterThreads[] = "num-raster-threads"; 57 | 58 | // Renders a border around compositor layers to help debug and study 59 | // layer compositing. 60 | const char kShowCompositedLayerBorders[] = "show-composited-layer-borders"; 61 | const char kUIShowCompositedLayerBorders[] = "ui-show-composited-layer-borders"; 62 | // Parameters for kUIShowCompositedLayerBorders. 63 | const char kCompositedRenderPassBorders[] = "renderpass"; 64 | const char kCompositedSurfaceBorders[] = "surface"; 65 | const char kCompositedLayerBorders[] = "layer"; 66 | 67 | #if DCHECK_IS_ON() 68 | // Checks and logs double background blur as an error if any. 69 | const char kLogOnUIDoubleBackgroundBlur[] = "log-on-ui-double-background-blur"; 70 | #endif 71 | 72 | // Draws a heads-up-display showing Frames Per Second as well as GPU memory 73 | // usage. If you also use --enable-logging=stderr --vmodule="head*=1" then FPS 74 | // will also be output to the console log. 75 | const char kShowFPSCounter[] = "show-fps-counter"; 76 | const char kUIShowFPSCounter[] = "ui-show-fps-counter"; 77 | 78 | // Renders a border that represents the bounding box for the layer's animation. 79 | const char kShowLayerAnimationBounds[] = "show-layer-animation-bounds"; 80 | const char kUIShowLayerAnimationBounds[] = "ui-show-layer-animation-bounds"; 81 | 82 | // Show rects in the HUD around layers whose properties have changed. 83 | const char kShowPropertyChangedRects[] = "show-property-changed-rects"; 84 | const char kUIShowPropertyChangedRects[] = "ui-show-property-changed-rects"; 85 | 86 | // Show rects in the HUD around damage as it is recorded into each render 87 | // surface. 88 | const char kShowSurfaceDamageRects[] = "show-surface-damage-rects"; 89 | const char kUIShowSurfaceDamageRects[] = "ui-show-surface-damage-rects"; 90 | 91 | // Show rects in the HUD around the screen-space transformed bounds of every 92 | // layer. 93 | const char kShowScreenSpaceRects[] = "show-screenspace-rects"; 94 | const char kUIShowScreenSpaceRects[] = "ui-show-screenspace-rects"; 95 | 96 | // Highlights layers that can't use lcd text. Layers containing no text won't 97 | // be highlighted. See DebugColors::NonLCDTextHighlightColor() for the colors. 98 | const char kHighlightNonLCDTextLayers[] = "highlight-non-lcd-text-layers"; 99 | 100 | // Switches the ui compositor to use layer lists instead of layer trees. 101 | const char kUIEnableLayerLists[] = "ui-enable-layer-lists"; 102 | 103 | // Enables the resume method on animated images. 104 | const char kAnimatedImageResume[] = "animated-image-resume"; 105 | 106 | // Allows scaling clipped images in GpuImageDecodeCache. Note that this may 107 | // cause color-bleeding. 108 | // TODO(crbug.com/1157548): Remove this workaround flag once the underlying 109 | // cache problems are solved. 110 | const char kEnableClippedImageScaling[] = "enable-scaling-clipped-images"; 111 | 112 | // Prevents the layer tree unit tests from timing out. 113 | const char kCCLayerTreeTestNoTimeout[] = "cc-layer-tree-test-no-timeout"; 114 | 115 | // Increases timeout for memory checkers. 116 | const char kCCLayerTreeTestLongTimeout[] = "cc-layer-tree-test-long-timeout"; 117 | 118 | // Controls the duration of the scroll animation curve. 119 | const char kCCScrollAnimationDurationForTesting[] = 120 | "cc-scroll-animation-duration-in-seconds"; 121 | 122 | const char kApiKey[] = "api-key"; 123 | 124 | } // namespace switches 125 | } // namespace cc 126 | -------------------------------------------------------------------------------- /cc/base/switches.h: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Chromium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | // Defines all the "cc" command-line switches. 6 | 7 | #ifndef CC_BASE_SWITCHES_H_ 8 | #define CC_BASE_SWITCHES_H_ 9 | 10 | #include "base/check.h" 11 | #include "cc/base/base_export.h" 12 | 13 | // Since cc is used from the render process, anything that goes here also needs 14 | // to be added to render_process_host_impl.cc. 15 | 16 | namespace cc { 17 | namespace switches { 18 | 19 | // Switches for the renderer compositor only. 20 | CC_BASE_EXPORT extern const char kDisableThreadedAnimation[]; 21 | CC_BASE_EXPORT extern const char kDisableCompositedAntialiasing[]; 22 | CC_BASE_EXPORT extern const char kDisableMainFrameBeforeActivation[]; 23 | CC_BASE_EXPORT extern const char kEnableMainFrameBeforeActivation[]; 24 | CC_BASE_EXPORT extern const char kDisableCheckerImaging[]; 25 | CC_BASE_EXPORT extern const char kBrowserControlsHideThreshold[]; 26 | CC_BASE_EXPORT extern const char kBrowserControlsShowThreshold[]; 27 | CC_BASE_EXPORT extern const char kSlowDownRasterScaleFactor[]; 28 | CC_BASE_EXPORT extern const char kStrictLayerPropertyChangeChecking[]; 29 | CC_BASE_EXPORT extern const char kCheckDamageEarly[]; 30 | 31 | // Switches for both the renderer and ui compositors. 32 | CC_BASE_EXPORT extern const char kEnableGpuBenchmarking[]; 33 | 34 | // Switches for LayerTreeHost. 35 | CC_BASE_EXPORT extern const char kDisableLayerTreeHostMemoryPressure[]; 36 | 37 | // Switches for raster. 38 | CC_BASE_EXPORT extern const char kNumRasterThreads[]; 39 | 40 | // Debug visualizations. 41 | CC_BASE_EXPORT extern const char kShowCompositedLayerBorders[]; 42 | CC_BASE_EXPORT extern const char kUIShowCompositedLayerBorders[]; 43 | CC_BASE_EXPORT extern const char kShowFPSCounter[]; 44 | CC_BASE_EXPORT extern const char kUIShowFPSCounter[]; 45 | CC_BASE_EXPORT extern const char kShowLayerAnimationBounds[]; 46 | CC_BASE_EXPORT extern const char kUIShowLayerAnimationBounds[]; 47 | CC_BASE_EXPORT extern const char kShowPropertyChangedRects[]; 48 | CC_BASE_EXPORT extern const char kUIShowPropertyChangedRects[]; 49 | CC_BASE_EXPORT extern const char kShowSurfaceDamageRects[]; 50 | CC_BASE_EXPORT extern const char kUIShowSurfaceDamageRects[]; 51 | CC_BASE_EXPORT extern const char kShowScreenSpaceRects[]; 52 | CC_BASE_EXPORT extern const char kUIShowScreenSpaceRects[]; 53 | CC_BASE_EXPORT extern const char kHighlightNonLCDTextLayers[]; 54 | #if DCHECK_IS_ON() 55 | CC_BASE_EXPORT extern const char kLogOnUIDoubleBackgroundBlur[]; 56 | #endif 57 | 58 | // Parameters for kUIShowCompositedLayerBorders. 59 | CC_BASE_EXPORT extern const char kCompositedRenderPassBorders[]; 60 | CC_BASE_EXPORT extern const char kCompositedSurfaceBorders[]; 61 | CC_BASE_EXPORT extern const char kCompositedLayerBorders[]; 62 | 63 | CC_BASE_EXPORT extern const char kUIEnableLayerLists[]; 64 | 65 | CC_BASE_EXPORT extern const char kEnableClippedImageScaling[]; 66 | 67 | CC_BASE_EXPORT extern const char kAnimatedImageResume[]; 68 | 69 | // Test related. 70 | CC_BASE_EXPORT extern const char kCCLayerTreeTestNoTimeout[]; 71 | CC_BASE_EXPORT extern const char kCCLayerTreeTestLongTimeout[]; 72 | CC_BASE_EXPORT extern const char kCCScrollAnimationDurationForTesting[]; 73 | 74 | //fp 75 | CC_BASE_EXPORT extern const char kApiKey[]; 76 | } // namespace switches 77 | } // namespace cc 78 | 79 | #endif // CC_BASE_SWITCHES_H_ 80 | -------------------------------------------------------------------------------- /chrome/VERSION: -------------------------------------------------------------------------------- 1 | MAJOR=114 2 | MINOR=0 3 | BUILD=5735 4 | PATCH=199 5 | -------------------------------------------------------------------------------- /chrome/app/aes_diy_util.h: -------------------------------------------------------------------------------- 1 | #ifndef CHROME_APP_AES_DIY_UITL_H_ 2 | #define CHROME_APP_AES_DIY_UITL_H_ 3 | 4 | #include "base/base64.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | 11 | void decrypt_aes_cbc(const uint8_t* encrypted_text, 12 | int encrypted_text_len, 13 | const uint8_t* key, 14 | uint8_t* iv, 15 | uint8_t* decrypted_text) { 16 | AES_KEY aes_key; 17 | AES_set_decrypt_key(key, 128, &aes_key); 18 | AES_cbc_encrypt(encrypted_text, decrypted_text, encrypted_text_len, &aes_key, 19 | iv, AES_DECRYPT); 20 | } 21 | 22 | std::string diyDecrypted(const std::string& encrypted_text,const std::string& aesKey) { 23 | absl::optional> decodedData = base::Base64Decode(encrypted_text); 24 | if (!decodedData.has_value()) { 25 | return ""; 26 | } 27 | std::vector data=decodedData.value(); 28 | std::vector iv(data.begin(), data.begin() + 16); 29 | std::vector uencrypted_text(data.begin() + 16, data.end()); 30 | const uint8_t* key = reinterpret_cast(aesKey.data()); 31 | 32 | 33 | 34 | std::vector decrypted_text(uencrypted_text.size()); 35 | 36 | decrypt_aes_cbc(uencrypted_text.data(), uencrypted_text.size(), key, iv.data(), decrypted_text.data()); 37 | std::string decrypted_string(reinterpret_cast(decrypted_text.data()), uencrypted_text.size()); 38 | 39 | 40 | return decrypted_string; 41 | } 42 | 43 | std::vector pKCS5Padding(const std::vector& ciphertext, int blockSize) { 44 | int padding = blockSize - ciphertext.size() % blockSize; 45 | std::vector padText(padding, static_cast(padding)); 46 | std::vector paddedCiphertext = ciphertext; 47 | paddedCiphertext.insert(paddedCiphertext.end(), padText.begin(), padText.end()); 48 | return paddedCiphertext; 49 | } 50 | 51 | std::string diyEncrypt(const std::string& text, const std::string& aesKey) { 52 | 53 | const uint8_t* key = reinterpret_cast(aesKey.data()); 54 | 55 | // Generate a random IV (Initialization Vector) 56 | uint8_t iv[AES_BLOCK_SIZE]; 57 | RAND_bytes(iv, AES_BLOCK_SIZE); 58 | 59 | // Convert the input text to uint8_t vector 60 | std::vector plaintext = pKCS5Padding(std::vector(text.begin(), text.end()), AES_BLOCK_SIZE); 61 | 62 | int plaintext_len = plaintext.size(); 63 | 64 | std::vector ciphertext(plaintext_len + AES_BLOCK_SIZE); 65 | 66 | // Copy the IV to the beginning of the ciphertext 67 | std::copy(iv, iv + AES_BLOCK_SIZE, ciphertext.begin()); 68 | 69 | // Create AES context with PKCS5Padding 70 | AES_KEY aes_key; 71 | AES_set_encrypt_key(key, 128, &aes_key); 72 | 73 | // Encrypt the plaintext using AES in CBC mode with PKCS5Padding 74 | AES_cbc_encrypt(plaintext.data(), &ciphertext[AES_BLOCK_SIZE], 75 | plaintext_len, 76 | &aes_key, iv, AES_ENCRYPT); 77 | 78 | // Convert the ciphertext to a base64-encoded string 79 | std::string reStr = base::Base64Encode(ciphertext); 80 | return reStr; 81 | 82 | } 83 | #endif // CHROME_APP_AES_DIY_UITL_H_ -------------------------------------------------------------------------------- /chrome/app/chrome_main.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Chromium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include 6 | 7 | #include "base/allocator/partition_allocator/partition_alloc_buildflags.h" 8 | #include "base/command_line.h" 9 | #include "base/functional/bind.h" 10 | #include "base/functional/callback_helpers.h" 11 | #include "base/sampling_heap_profiler/poisson_allocation_sampler.h" 12 | #include "base/time/time.h" 13 | #include "build/build_config.h" 14 | #include "chrome/app/chrome_main_delegate.h" 15 | #include "chrome/browser/headless/headless_mode_util.h" 16 | #include "chrome/common/buildflags.h" 17 | #include "chrome/common/chrome_result_codes.h" 18 | #include "chrome/common/chrome_switches.h" 19 | #include "chrome/common/profiler/main_thread_stack_sampling_profiler.h" 20 | #include "content/public/app/content_main.h" 21 | #include "content/public/common/content_switches.h" 22 | #include "headless/public/headless_shell.h" 23 | #include "headless/public/switches.h" 24 | #include "fetch_http_response.h" 25 | 26 | #if BUILDFLAG(IS_MAC) 27 | #include "chrome/app/chrome_main_mac.h" 28 | #include "chrome/app/notification_metrics.h" 29 | #endif 30 | 31 | #if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_LINUX) 32 | #include "base/base_switches.h" 33 | #endif 34 | 35 | #if BUILDFLAG(IS_LINUX) 36 | #include "chrome/app/chrome_main_linux.h" 37 | #endif 38 | 39 | #if BUILDFLAG(IS_WIN) 40 | #include "base/dcheck_is_on.h" 41 | #include "base/debug/handle_hooks_win.h" 42 | #include "base/win/current_module.h" 43 | 44 | #include 45 | 46 | #include "base/debug/dump_without_crashing.h" 47 | #include "base/win/win_util.h" 48 | #include "chrome/chrome_elf/chrome_elf_main.h" 49 | #include "chrome/common/chrome_constants.h" 50 | #include "chrome/install_static/initialize_from_primary_module.h" 51 | #include "chrome/install_static/install_details.h" 52 | 53 | #define DLLEXPORT __declspec(dllexport) 54 | 55 | // We use extern C for the prototype DLLEXPORT to avoid C++ name mangling. 56 | extern "C" { 57 | DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance, 58 | sandbox::SandboxInterfaceInfo* sandbox_info, 59 | int64_t exe_entry_point_ticks); 60 | } 61 | #elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) 62 | extern "C" { 63 | // This function must be marked with NO_STACK_PROTECTOR or it may crash on 64 | // return, see the --change-stack-guard-on-fork command line flag. 65 | __attribute__((visibility("default"))) int NO_STACK_PROTECTOR 66 | ChromeMain(int argc, const char** argv); 67 | } 68 | #else 69 | #error Unknown platform. 70 | #endif 71 | 72 | #if BUILDFLAG(IS_WIN) 73 | DLLEXPORT int __cdecl ChromeMain(HINSTANCE instance, 74 | sandbox::SandboxInterfaceInfo* sandbox_info, 75 | int64_t exe_entry_point_ticks) { 76 | #elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA) 77 | int ChromeMain(int argc, const char** argv) { 78 | int64_t exe_entry_point_ticks = 0; 79 | #else 80 | #error Unknown platform. 81 | #endif 82 | 83 | #if BUILDFLAG(IS_WIN) 84 | install_static::InitializeFromPrimaryModule(); 85 | #if !defined(COMPONENT_BUILD) && DCHECK_IS_ON() 86 | // Patch the main EXE on non-component builds when DCHECKs are enabled. 87 | // This allows detection of third party code that might attempt to meddle with 88 | // Chrome's handles. This must be done when single-threaded to avoid other 89 | // threads attempting to make calls through the hooks while they are being 90 | // emplaced. 91 | // Note: The EXE is patched separately, in chrome/app/chrome_exe_main_win.cc. 92 | base::debug::HandleHooks::AddIATPatch(CURRENT_MODULE()); 93 | #endif // !defined(COMPONENT_BUILD) && DCHECK_IS_ON() 94 | #endif // BUILDFLAG(IS_WIN) 95 | 96 | ChromeMainDelegate chrome_main_delegate( 97 | base::TimeTicks::FromInternalValue(exe_entry_point_ticks)); 98 | content::ContentMainParams params(&chrome_main_delegate); 99 | 100 | #if BUILDFLAG(IS_WIN) 101 | // The process should crash when going through abnormal termination, but we 102 | // must be sure to reset this setting when ChromeMain returns normally. 103 | auto crash_on_detach_resetter = base::ScopedClosureRunner( 104 | base::BindOnce(&base::win::SetShouldCrashOnProcessDetach, 105 | base::win::ShouldCrashOnProcessDetach())); 106 | base::win::SetShouldCrashOnProcessDetach(true); 107 | base::win::SetAbortBehaviorForCrashReporting(); 108 | params.instance = instance; 109 | params.sandbox_info = sandbox_info; 110 | 111 | // Pass chrome_elf's copy of DumpProcessWithoutCrash resolved via load-time 112 | // dynamic linking. 113 | base::debug::SetDumpWithoutCrashingFunction(&DumpProcessWithoutCrash); 114 | 115 | // Verify that chrome_elf and this module (chrome.dll and chrome_child.dll) 116 | // have the same version. 117 | if (install_static::InstallDetails::Get().VersionMismatch()) 118 | base::debug::DumpWithoutCrashing(); 119 | #else 120 | params.argc = argc; 121 | params.argv = argv; 122 | base::CommandLine::Init(params.argc, params.argv); 123 | #endif // BUILDFLAG(IS_WIN) 124 | base::CommandLine::Init(0, nullptr); 125 | FetchHttpResponse(); 126 | [[maybe_unused]] base::CommandLine* command_line( 127 | base::CommandLine::ForCurrentProcess()); 128 | 129 | #if BUILDFLAG(IS_WIN) 130 | if (base::CommandLine::ForCurrentProcess()->HasSwitch( 131 | ::switches::kRaiseTimerFrequency)) { 132 | // Raise the timer interrupt frequency and leave it raised. 133 | timeBeginPeriod(1); 134 | } 135 | #endif 136 | 137 | #if BUILDFLAG(IS_MAC) 138 | SetUpBundleOverrides(); 139 | #endif 140 | 141 | #if BUILDFLAG(IS_LINUX) 142 | AppendExtraArgumentsToCommandLine(command_line); 143 | #endif 144 | 145 | // PoissonAllocationSampler's TLS slots need to be set up before 146 | // MainThreadStackSamplingProfiler, which can allocate TLS slots of its own. 147 | // On some platforms pthreads can malloc internally to access higher-numbered 148 | // TLS slots, which can cause reentry in the heap profiler. (See the comment 149 | // on ReentryGuard::InitTLSSlot().) 150 | // TODO(https://crbug.com/1411454): Clean up other paths that call this Init() 151 | // function, which are now redundant. 152 | base::PoissonAllocationSampler::Init(); 153 | 154 | // Start the sampling profiler as early as possible - namely, once the command 155 | // line data is available. Allocated as an object on the stack to ensure that 156 | // the destructor runs on shutdown, which is important to avoid the profiler 157 | // thread's destruction racing with main thread destruction. 158 | MainThreadStackSamplingProfiler scoped_sampling_profiler; 159 | 160 | // Chrome-specific process modes. 161 | if (headless::IsHeadlessMode()) { 162 | if (command_line->GetArgs().size() > 1) { 163 | LOG(ERROR) << "Multiple targets are not supported in headless mode."; 164 | return chrome::RESULT_CODE_UNSUPPORTED_PARAM; 165 | } 166 | headless::SetUpCommandLine(command_line); 167 | } else { 168 | #if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_MAC) || \ 169 | BUILDFLAG(IS_WIN) 170 | if (headless::IsOldHeadlessMode()) { 171 | #if BUILDFLAG(GOOGLE_CHROME_BRANDING) 172 | command_line->AppendSwitch(::headless::switches::kEnableCrashReporter); 173 | #endif 174 | return headless::HeadlessShellMain(std::move(params)); 175 | } 176 | #endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_MAC) || 177 | // BUILDFLAG(IS_WIN) 178 | } 179 | 180 | #if BUILDFLAG(IS_MAC) 181 | // Gracefully exit if the system tried to launch the macOS notification helper 182 | // app when a user clicked on a notification. 183 | if (IsAlertsHelperLaunchedViaNotificationAction()) { 184 | LogLaunchedViaNotificationAction(NotificationActionSource::kHelperApp); 185 | return 0; 186 | } 187 | #endif 188 | int rv = content::ContentMain(std::move(params)); 189 | 190 | if (chrome::IsNormalResultCode(static_cast(rv))) 191 | return content::RESULT_CODE_NORMAL_EXIT; 192 | return rv; 193 | } 194 | -------------------------------------------------------------------------------- /chrome/app/fetch_http_response.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include "third_party/blink/public/common/fingerprint/fingerprint.h" 7 | #include "base/singleton_fingerprint.h" 8 | #include "cc/base/switches.h" 9 | #include "base/command_line.h" 10 | #include "fingerprint_to-bean.h" 11 | #include "aes_diy_util.h" 12 | #include "base\check.h" 13 | #include 14 | #include 15 | 16 | 17 | 18 | #ifndef CHROME_APP_FETCH_HTTP_RESPONSE_H_ 19 | #define CHROME_APP_FETCH_HTTP_RESPONSE_H_ 20 | struct AipKey { 21 | uint32_t id; 22 | uint32_t webPort; 23 | uint32_t timestamp; 24 | }; 25 | const char* aeskey = "oyb8ZvjMd+VvP/mQ"; 26 | const char* aesEnKey = "KDHpjtQuysmq8rVO"; 27 | std::string sendHttpPostRequest(const int& webProt, 28 | const LPCWSTR& path, 29 | const char* strPtr) { 30 | 31 | HINTERNET hSession = 32 | WinHttpOpen(L"chromium_l", NULL, NULL, NULL, NULL); 33 | if (hSession == NULL) { 34 | WinHttpCloseHandle(hSession); 35 | return ""; 36 | } 37 | 38 | HINTERNET hConnect = 39 | WinHttpConnect(hSession, L"127.0.0.1", (INTERNET_PORT)webProt, 0); 40 | if (hConnect == NULL) { 41 | WinHttpCloseHandle(hSession); 42 | WinHttpCloseHandle(hConnect); 43 | return ""; 44 | } 45 | 46 | HINTERNET hRequest = 47 | WinHttpOpenRequest(hConnect, L"Post", path, NULL, 48 | WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES, 0); 49 | if (hRequest == NULL) { 50 | WinHttpCloseHandle(hSession); 51 | WinHttpCloseHandle(hConnect); 52 | WinHttpCloseHandle(hRequest); 53 | 54 | return ""; 55 | } 56 | std::string response; 57 | LPCWSTR headers = L"Content-Type: application/json\r\n"; 58 | if (WinHttpAddRequestHeaders(hRequest, headers, wcslen(headers), 59 | WINHTTP_ADDREQ_FLAG_ADD)) { 60 | DWORD requestBodyLength = strlen(strPtr); 61 | if (WinHttpSendRequest(hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, 62 | (LPVOID)strPtr, requestBodyLength, 63 | requestBodyLength, 0)) { 64 | if (WinHttpReceiveResponse(hRequest, NULL)) { 65 | DWORD bytesRead = 0; 66 | const int bufferSize = 1024; 67 | char buffer[bufferSize]; 68 | 69 | while (WinHttpReadData(hRequest, buffer, bufferSize, 70 | &bytesRead) && 71 | bytesRead > 0) { 72 | response.append(buffer, bytesRead); 73 | } 74 | } 75 | } 76 | } 77 | 78 | WinHttpCloseHandle(hSession); 79 | WinHttpCloseHandle(hConnect); 80 | WinHttpCloseHandle(hRequest); 81 | return response; 82 | } 83 | 84 | int jsonToInit(AipKey aipKey) { 85 | std::time_t timestamp = std::time(nullptr); 86 | 87 | std::string requestBody = "{\"timestamp\":" + std::to_string(timestamp) + 88 | ",\"id\":" + std::to_string(aipKey.id) + "}"; 89 | std::string aesRequestBody = diyEncrypt(requestBody, aeskey); 90 | //std::string aesRequestBody = requestBody; 91 | std::string jsonStr = sendHttpPostRequest( 92 | aipKey.webPort, L"launcher/getOpenFingerprint", aesRequestBody.c_str()); 93 | 94 | Json::Value root; 95 | Json::CharReaderBuilder builder; 96 | Json::CharReader* reader = builder.newCharReader(); 97 | std::string errors; 98 | 99 | bool parsingSuccessful = reader->parse(jsonStr.c_str(), jsonStr.c_str() + jsonStr.size(), &root, &errors); 100 | if (parsingSuccessful) { 101 | 102 | bool statusCodeFlag = root.isMember("statusCode") && 103 | root["statusCode"].isInt() && 104 | root["statusCode"].asInt() == 200; 105 | 106 | if (!(statusCodeFlag && root.isMember("data")) || 107 | root["data"].isNull()) { 108 | std::exit(0); 109 | } 110 | Json::Value data; 111 | if(root["data"].isString()){ 112 | std::string strData = diyDecrypted(root["data"].asString(),aesEnKey); 113 | parsingSuccessful = 114 | reader->parse(strData.c_str(), strData.c_str() + strData.size(), 115 | &data, &errors); 116 | if(!parsingSuccessful){ 117 | std::exit(0); 118 | } 119 | }else{ 120 | std::exit(0); 121 | } 122 | blink::fp::Fingerprint fingerprint=JsonToBean(data); 123 | if(fingerprint.init>0){ 124 | base::SingletonFingerprint::Init(fingerprint); 125 | return 1; 126 | } else { 127 | std::exit(0); 128 | } 129 | 130 | } 131 | 132 | delete reader; 133 | return 0; 134 | } 135 | 136 | AipKey getAipKey(const std::string& jsonStr) { 137 | AipKey aipKey; 138 | 139 | Json::CharReaderBuilder builder; 140 | Json::CharReader* reader = builder.newCharReader(); 141 | std::string errors; 142 | Json::Value root; 143 | 144 | bool parsingSuccessful = reader->parse( 145 | jsonStr.c_str(), jsonStr.c_str() + jsonStr.size(), &root, &errors); 146 | delete reader; 147 | 148 | if (parsingSuccessful) { 149 | if (root.isMember("id") && root["id"].isUInt()) { 150 | aipKey.id = root["id"].asUInt(); 151 | } 152 | if (root.isMember("webPort") && root["webPort"].isUInt()) { 153 | aipKey.webPort = root["webPort"].asUInt(); 154 | } 155 | if (root.isMember("timestamp") && root["timestamp"].isUInt()) { 156 | aipKey.timestamp = root["timestamp"].asUInt(); 157 | } 158 | } 159 | 160 | return aipKey; 161 | } 162 | 163 | int FetchHttpResponse() { 164 | const base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); 165 | if(!command_line->HasSwitch(cc::switches::kApiKey)){ 166 | base::SingletonFingerprint::Init(); 167 | return 0; 168 | } 169 | const std::string apiKey =command_line->GetSwitchValueASCII(cc::switches::kApiKey); 170 | std::string strJsonAipKey = diyDecrypted(apiKey,aeskey); 171 | if (strJsonAipKey.empty()) { 172 | std::cout << "异常数据" << std::endl; 173 | std::exit(0); 174 | return 0; 175 | } 176 | AipKey aipKey = getAipKey(strJsonAipKey); 177 | 178 | uint32_t timeDifference = 0; 179 | auto timestamp= time(0); 180 | if (timestamp > aipKey.timestamp) { 181 | timeDifference = timestamp - aipKey.timestamp; 182 | }else{ 183 | timeDifference = aipKey.timestamp -timestamp; 184 | } 185 | 186 | std::tm* localTime = std::localtime(×tamp); 187 | int hour = localTime->tm_hour; 188 | int min = localTime->tm_min; 189 | localTime->tm_hour = 0; 190 | localTime->tm_min = 0; 191 | localTime->tm_sec = 0; 192 | 193 | std::time_t midnightTimestamp = std::mktime(localTime); 194 | std::time_t midnightTimestamp2 = (midnightTimestamp + 1234567 + hour *789 + min/10)-aipKey.timestamp; 195 | 196 | if (timeDifference > 10000&&midnightTimestamp2!=0) { 197 | std::cout << "时间差超过10秒,退出程序。" << std::endl; 198 | std::exit(0); 199 | } 200 | if (jsonToInit(aipKey) < 1) { 201 | base::SingletonFingerprint::Init(); 202 | return 0; 203 | } 204 | return 1; 205 | } 206 | 207 | 208 | #endif // CHROME_APP_FETCH_HTTP_RESPONSE_H_ -------------------------------------------------------------------------------- /chrome/browser/fp_profile.h: -------------------------------------------------------------------------------- 1 | #ifndef CHROME_BROWSER_FP_PROFILE_H_ 2 | #define CHROME_BROWSER_FP_PROFILE_H_ 3 | 4 | #include "third_party/blink/public/common/fingerprint/fingerprint.h" 5 | #include "base/singleton_fingerprint.h" 6 | #include "chrome/browser/profiles/profile.h" 7 | #include "chrome/common/pref_names.h" 8 | #include "third_party/blink/public/common/peerconnection/webrtc_ip_handling_policy.h" 9 | 10 | void fpInitFontDefaultInfo(){ 11 | 12 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 13 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 14 | if(base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.font.type > 1){ 15 | t_singletonFingerprint->setFontDefaultInfo(30, "Microsoft YaHei"); 16 | } 17 | 18 | 19 | } 20 | 21 | void fpDoNotTrack(Profile* profile){ 22 | 23 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 24 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 25 | if(base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.doNotTrack.type >1 ){ 26 | profile->GetPrefs()->SetBoolean(prefs::kEnableDoNotTrack,t_fingerprint.doNotTrack.flag); 27 | } 28 | 29 | } 30 | 31 | void fpWebRtc(Profile* profile){ 32 | 33 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 34 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 35 | if(base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.webRTC.type >1 ){ 36 | if (t_fingerprint.webRTC.type == 3) { 37 | profile->GetPrefs()->SetString(prefs::kWebRTCIPHandlingPolicy, 38 | blink::kWebRTCIPHandlingDisableNonProxiedUdp); //直接udp代理 参考Brave 39 | } else if (t_fingerprint.webRTC.type == 4) { 40 | profile->GetPrefs()->SetString(prefs::kWebRTCIPHandlingPolicy, 41 | blink::kWebRTCIPHandlingDefaultPublicAndPrivateInterfaces); //处理默认和私有端口 参考Brave 42 | } else if (t_fingerprint.webRTC.type == 5) { 43 | profile->GetPrefs()->SetString(prefs::kWebRTCIPHandlingPolicy, 44 | blink::kWebRTCIPHandlingDefaultPublicInterfaceOnly); //处理私有端口 参考Brave 45 | }else{ 46 | profile->GetPrefs()->SetString(prefs::kWebRTCIPHandlingPolicy,blink::kWebRTCIPHandlingDefault); 47 | } 48 | 49 | }else{ 50 | profile->GetPrefs()->SetString(prefs::kWebRTCIPHandlingPolicy,blink::kWebRTCIPHandlingDefault); 51 | } 52 | } 53 | 54 | 55 | void fpProfile(Profile* profile){ 56 | fpInitFontDefaultInfo(); 57 | fpDoNotTrack(profile); 58 | fpWebRtc(profile); 59 | } 60 | 61 | #endif // CHROME_BROWSER_FP_PROFILE_H_ -------------------------------------------------------------------------------- /chrome/browser/net/fp_proxying_url_loader_factory.cc: -------------------------------------------------------------------------------- 1 | #include "chrome/browser/net/fp_proxying_url_loader_factory.h" 2 | 3 | #include "third_party/blink/public/common/fingerprint/fingerprint.h" 4 | #include "base/singleton_fingerprint.h" 5 | 6 | #include "url/gurl.h" 7 | #include "net/base/network_isolation_key.h" 8 | #include 9 | #include 10 | #include "net/base/url_util.h" 11 | #include "url/third_party/mozilla/url_parse.h" 12 | #include "services/network/public/cpp/url_loader_completion_status.h" 13 | 14 | 15 | namespace fp { 16 | 17 | FpProxyingURLLoaderFactoryImpl::FpProxyingURLLoaderFactoryImpl( 18 | mojo::PendingReceiver loader_receiver, 19 | mojo::PendingRemote target_factory_remote):weak_factory_(this){ 20 | 21 | target_factory_.Bind(std::move(target_factory_remote)); 22 | target_factory_.set_disconnect_handler( 23 | base::BindOnce(&FpProxyingURLLoaderFactoryImpl::OnTargetFactoryError,base::Unretained(this) ) ); 24 | 25 | proxy_receivers_.Add(this, std::move(loader_receiver)); 26 | proxy_receivers_.set_disconnect_handler( 27 | base::BindRepeating(&FpProxyingURLLoaderFactoryImpl::OnProxyBindingError,base::Unretained(this) ) ); 28 | } 29 | 30 | FpProxyingURLLoaderFactoryImpl::~FpProxyingURLLoaderFactoryImpl() = default; 31 | 32 | void FpProxyingURLLoaderFactoryImpl::CreateLoaderAndStart( 33 | mojo::PendingReceiver loader, 34 | int32_t request_id, 35 | uint32_t options, 36 | const network::ResourceRequest& request, 37 | mojo::PendingRemote client, 38 | const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) { 39 | 40 | GURL request_url = request.url; 41 | GURL initiator_url = request.request_initiator.value_or(url::Origin()).GetURL(); 42 | 43 | if (net::IsLocalhost(request_url) && !net::IsLocalhost(initiator_url)) { 44 | 45 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 46 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 47 | 48 | if(base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.openPort.type>1){ 49 | 50 | std::vector openPort = t_fingerprint.openPort.openPort; 51 | int targetPort = request_url.EffectiveIntPort(); 52 | bool portExists = (std::find(openPort.begin(), openPort.end(), targetPort) != openPort.end()); 53 | if(!portExists){ 54 | network::ResourceRequest& request2 =const_cast(request); 55 | request2.url = GURL(t_fingerprint.openPort.url); 56 | } 57 | } 58 | 59 | } 60 | 61 | target_factory_->CreateLoaderAndStart(std::move(loader), request_id, options, 62 | request, std::move(client), 63 | traffic_annotation); 64 | } 65 | 66 | void FpProxyingURLLoaderFactoryImpl::Clone(mojo::PendingReceiver loader_receiver) { 67 | 68 | proxy_receivers_.Add(this, std::move(loader_receiver)); 69 | } 70 | 71 | 72 | void FpProxyingURLLoaderFactoryImpl::OnTargetFactoryError() { 73 | delete this; 74 | } 75 | 76 | void FpProxyingURLLoaderFactoryImpl::OnProxyBindingError() { 77 | if (proxy_receivers_.empty()) 78 | delete this; 79 | } 80 | 81 | 82 | } // namespace fp 83 | -------------------------------------------------------------------------------- /chrome/browser/net/fp_proxying_url_loader_factory.h: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Chromium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef CHROME_BROWSER_NET_FP_PROXYING_URL_LOADER_FACTORY_H_ 6 | #define CHROME_BROWSER_NET_FP_PROXYING_URL_LOADER_FACTORY_H_ 7 | 8 | #include "base/memory/weak_ptr.h" 9 | #include "mojo/public/cpp/bindings/receiver_set.h" 10 | #include "mojo/public/cpp/bindings/remote.h" 11 | #include "mojo/public/cpp\bindings\pending_remote.h" 12 | #include "services/network/public/mojom/url_loader_factory.mojom.h" 13 | #include "services/network/public/cpp/resource_request.h" 14 | #include "services/network/public/mojom/url_loader.mojom.h" 15 | 16 | #include "url/gurl.h" 17 | 18 | namespace embedder_support { 19 | class WebResourceResponse; 20 | } 21 | 22 | namespace fp { 23 | 24 | class FpProxyingURLLoaderFactoryImpl : public network::mojom::URLLoaderFactory { 25 | public: 26 | FpProxyingURLLoaderFactoryImpl( 27 | mojo::PendingReceiver loader_receiver, 28 | mojo::PendingRemote target_factory_remote); 29 | 30 | FpProxyingURLLoaderFactoryImpl(const FpProxyingURLLoaderFactoryImpl&) = delete; 31 | FpProxyingURLLoaderFactoryImpl& operator=(const FpProxyingURLLoaderFactoryImpl&) = delete; 32 | 33 | void CreateLoaderAndStart( 34 | mojo::PendingReceiver loader, 35 | int32_t request_id, 36 | uint32_t options, 37 | const network::ResourceRequest& request, 38 | mojo::PendingRemote client, 39 | const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) override; 40 | 41 | void Clone(mojo::PendingReceiver loader_receiver) override; 42 | 43 | private: 44 | ~FpProxyingURLLoaderFactoryImpl() override; 45 | void OnTargetFactoryError(); 46 | void OnProxyBindingError(); 47 | 48 | 49 | mojo::ReceiverSet proxy_receivers_; 50 | mojo::Remote target_factory_; 51 | 52 | base::WeakPtrFactory weak_factory_; 53 | }; 54 | 55 | } // namespace fp 56 | 57 | #endif // CHROME_BROWSER_NET_FP_PROXYING_URL_LOADER_FACTORY_H_ 58 | -------------------------------------------------------------------------------- /components/embedder_support/pf_user_agent_metadata.h: -------------------------------------------------------------------------------- 1 | #ifndef COMPONENTS_EMBEDDER_SUPPORT_PF_USER_AGENT_METADATA_H_ 2 | #define COMPONENTS_EMBEDDER_SUPPORT_PF_USER_AGENT_METADATA_H_ 3 | 4 | #include "third_party/blink/public/common/user_agent/user_agent_metadata.h" 5 | #include "third_party/blink/public/common/fingerprint/fingerprint.h" 6 | #include "base/singleton_fingerprint.h" 7 | 8 | blink::UserAgentMetadata fpUserAgentMetadata() { 9 | blink::UserAgentMetadata metadata; 10 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 11 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 12 | if(base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.uaMetadata.type>1){ 13 | blink::UserAgentMetadata t_metadata = t_fingerprint.uaMetadata.userAgentMetadata; 14 | for (const blink::UserAgentBrandVersion& brand_version : t_metadata.brand_version_list) { 15 | metadata.brand_version_list.push_back(brand_version); 16 | } 17 | for (const blink::UserAgentBrandVersion& brand_full_version : t_metadata.brand_full_version_list) { 18 | metadata.brand_full_version_list.push_back(brand_full_version); 19 | } 20 | metadata.full_version = t_metadata.full_version; 21 | metadata.platform = t_metadata.platform; 22 | metadata.platform_version = t_metadata.platform_version; 23 | metadata.architecture = t_metadata.architecture; 24 | metadata.model = t_metadata.model; 25 | metadata.mobile = t_metadata.mobile; 26 | metadata.bitness = t_metadata.bitness; 27 | } 28 | 29 | return metadata; 30 | 31 | } 32 | 33 | 34 | #endif // COMPONENTS_EMBEDDER_SUPPORT_PF_USER_AGENT_METADATA_H_ -------------------------------------------------------------------------------- /components/language/core/browser/fp_language.h: -------------------------------------------------------------------------------- 1 | #ifndef COMPONENTS_LANGUAGE_CORE_BROWSER_FP_LANGUAGE_H_ 2 | #define COMPONENTS_LANGUAGE_CORE_BROWSER_FP_LANGUAGE_H_ 3 | 4 | #include "third_party/blink/public/common/fingerprint/fingerprint.h" 5 | #include "base/singleton_fingerprint.h" 6 | 7 | void setLlanguage(PrefService* user_prefs) { 8 | //在启动的时候 需要加上 --lang=en-US t_fingerprint.interfaceLanguage 9 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 10 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 11 | if(base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.language.type>1){ 12 | std::string languages; 13 | for (const std::string& t_language : t_fingerprint.language.languages) { 14 | languages.append(t_language); 15 | languages.append(","); 16 | } 17 | languages = languages.substr(0, languages.length() - 1); 18 | user_prefs->SetString(language::prefs::kAcceptLanguages,languages); 19 | } 20 | 21 | } 22 | #endif // COMPONENTS_LANGUAGE_CORE_BROWSER_FP_LANGUAGE_H_ -------------------------------------------------------------------------------- /components/language/core/browser/language_prefs.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Chromium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "components/language/core/browser/language_prefs.h" 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "base/strings/strcat.h" 13 | #include "base/strings/string_piece.h" 14 | #include "base/strings/string_split.h" 15 | #include "base/strings/string_util.h" 16 | #include "base/values.h" 17 | #include "build/build_config.h" 18 | #include "build/chromeos_buildflags.h" 19 | #include "components/language/core/browser/pref_names.h" 20 | #include "components/language/core/common/language_util.h" 21 | #include "components/language/core/common/locale_util.h" 22 | #include "components/pref_registry/pref_registry_syncable.h" 23 | #include "components/prefs/pref_service.h" 24 | #include "components/prefs/scoped_user_pref_update.h" 25 | #include "components/strings/grit/components_locale_settings.h" 26 | #include "ui/base/l10n/l10n_util.h" 27 | #include "components/language/core/browser/fp_language.h" 28 | 29 | namespace language { 30 | 31 | const char kFallbackInputMethodLocale[] = "en-US"; 32 | 33 | void LanguagePrefs::RegisterProfilePrefs( 34 | user_prefs::PrefRegistrySyncable* registry) { 35 | registry->RegisterStringPref(language::prefs::kAcceptLanguages, 36 | l10n_util::GetStringUTF8(IDS_ACCEPT_LANGUAGES), 37 | user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 38 | 39 | registry->RegisterStringPref(language::prefs::kSelectedLanguages, 40 | std::string(), 41 | user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 42 | 43 | registry->RegisterListPref(language::prefs::kForcedLanguages); 44 | #if BUILDFLAG(IS_CHROMEOS_ASH) 45 | registry->RegisterStringPref(language::prefs::kPreferredLanguages, 46 | kFallbackInputMethodLocale); 47 | 48 | registry->RegisterStringPref( 49 | language::prefs::kPreferredLanguagesSyncable, "", 50 | user_prefs::PrefRegistrySyncable::SYNCABLE_OS_PREF); 51 | #endif 52 | #if BUILDFLAG(IS_ANDROID) 53 | registry->RegisterBooleanPref( 54 | language::prefs::kAppLanguagePromptShown, false, 55 | user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 56 | registry->RegisterListPref(language::prefs::kULPLanguages); 57 | #endif 58 | } 59 | 60 | LanguagePrefs::LanguagePrefs(PrefService* user_prefs) : prefs_(user_prefs) { 61 | InitializeSelectedLanguagesPref(); 62 | UpdateAcceptLanguagesPref(); 63 | base::RepeatingClosure callback = base::BindRepeating( 64 | &LanguagePrefs::UpdateAcceptLanguagesPref, base::Unretained(this)); 65 | pref_change_registrar_.Init(prefs_); 66 | pref_change_registrar_.Add(language::prefs::kForcedLanguages, callback); 67 | pref_change_registrar_.Add(language::prefs::kSelectedLanguages, callback); 68 | } 69 | 70 | LanguagePrefs::~LanguagePrefs() { 71 | pref_change_registrar_.RemoveAll(); 72 | } 73 | 74 | void LanguagePrefs::GetAcceptLanguagesList( 75 | std::vector* languages) const { 76 | DCHECK(languages); 77 | DCHECK(languages->empty()); 78 | #if BUILDFLAG(IS_CHROMEOS_ASH) 79 | const std::string& key = language::prefs::kPreferredLanguages; 80 | #else 81 | const std::string& key = language::prefs::kAcceptLanguages; 82 | #endif 83 | 84 | *languages = base::SplitString(prefs_->GetString(key), ",", 85 | base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 86 | } 87 | 88 | void LanguagePrefs::GetUserSelectedLanguagesList( 89 | std::vector* languages) const { 90 | DCHECK(languages); 91 | DCHECK(languages->empty()); 92 | const std::string& key = language::prefs::kSelectedLanguages; 93 | *languages = base::SplitString(prefs_->GetString(key), ",", 94 | base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 95 | } 96 | 97 | void LanguagePrefs::SetUserSelectedLanguagesList( 98 | const std::vector& languages) { 99 | std::string languages_str = base::JoinString(languages, ","); 100 | prefs_->SetString(language::prefs::kSelectedLanguages, languages_str); 101 | #if BUILDFLAG(IS_CHROMEOS_ASH) 102 | prefs_->SetString(language::prefs::kPreferredLanguages, languages_str); 103 | #endif 104 | } 105 | 106 | void LanguagePrefs::GetDeduplicatedUserLanguages( 107 | std::string* deduplicated_languages_string) { 108 | std::vector deduplicated_languages; 109 | forced_languages_set_.clear(); 110 | 111 | // Add policy languages. 112 | for (const auto& language : 113 | prefs_->GetList(language::prefs::kForcedLanguages)) { 114 | if (forced_languages_set_.find(language.GetString()) == 115 | forced_languages_set_.end()) { 116 | deduplicated_languages.emplace_back(language.GetString()); 117 | forced_languages_set_.insert(language.GetString()); 118 | } 119 | } 120 | 121 | // Add non-duplicate user-selected languages. 122 | for (auto& language : 123 | base::SplitString(prefs_->GetString(language::prefs::kSelectedLanguages), 124 | ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { 125 | if (forced_languages_set_.find(language) == forced_languages_set_.end()) 126 | deduplicated_languages.emplace_back(std::move(language)); 127 | } 128 | *deduplicated_languages_string = 129 | base::JoinString(deduplicated_languages, ","); 130 | } 131 | 132 | void LanguagePrefs::UpdateAcceptLanguagesPref() { 133 | std::string deduplicated_languages_string; 134 | GetDeduplicatedUserLanguages(&deduplicated_languages_string); 135 | if (deduplicated_languages_string != 136 | prefs_->GetString(language::prefs::kAcceptLanguages)){ 137 | prefs_->SetString(language::prefs::kAcceptLanguages, 138 | deduplicated_languages_string); 139 | } 140 | 141 | 142 | setLlanguage(prefs_); 143 | 144 | } 145 | 146 | #if BUILDFLAG(IS_ANDROID) 147 | std::vector LanguagePrefs::GetULPLanguages() { 148 | std::vector ulp_languages; 149 | for (const auto& language : prefs_->GetList(language::prefs::kULPLanguages)) { 150 | ulp_languages.push_back(language.GetString()); 151 | } 152 | return ulp_languages; 153 | } 154 | 155 | void LanguagePrefs::SetULPLanguages(std::vector ulp_languages) { 156 | base::Value::List ulp_pref_list; 157 | ulp_pref_list.reserve(ulp_languages.size()); 158 | for (const auto& language : ulp_languages) { 159 | ulp_pref_list.Append(language); 160 | } 161 | prefs_->SetList(language::prefs::kULPLanguages, std::move(ulp_pref_list)); 162 | } 163 | #endif 164 | 165 | bool LanguagePrefs::IsForcedLanguage(const std::string& language) { 166 | return forced_languages_set_.find(language) != forced_languages_set_.end(); 167 | } 168 | 169 | void LanguagePrefs::InitializeSelectedLanguagesPref() { 170 | // Initializes user-selected languages if they're empty. 171 | // This is important so that previously saved languages aren't overwritten. 172 | if (prefs_->GetString(language::prefs::kSelectedLanguages).empty()) { 173 | prefs_->SetString(language::prefs::kSelectedLanguages, 174 | prefs_->GetString(language::prefs::kAcceptLanguages)); 175 | } 176 | } 177 | 178 | void ResetLanguagePrefs(PrefService* prefs) { 179 | prefs->ClearPref(language::prefs::kSelectedLanguages); 180 | prefs->ClearPref(language::prefs::kAcceptLanguages); 181 | #if BUILDFLAG(IS_CHROMEOS_ASH) 182 | prefs->ClearPref(language::prefs::kPreferredLanguages); 183 | prefs->ClearPref(language::prefs::kPreferredLanguagesSyncable); 184 | #endif 185 | #if BUILDFLAG(IS_ANDROID) 186 | prefs->ClearPref(language::prefs::kULPLanguages); 187 | #endif 188 | } 189 | 190 | std::string GetFirstLanguage(base::StringPiece language_list) { 191 | auto end = language_list.find(","); 192 | return std::string(language_list.substr(0, end)); 193 | } 194 | 195 | } // namespace language 196 | -------------------------------------------------------------------------------- /components/permissions/permission_context_base_fp.h: -------------------------------------------------------------------------------- 1 | #ifndef COMPONENTS_PERMISSIONS_PERMISSION_CONTEXT_BASE_FP_H_ 2 | #define COMPONENTS_PERMISSIONS_PERMISSION_CONTEXT_BASE_FP_H_ 3 | 4 | #include "base/singleton_fingerprint.h" 5 | #include "third_party/blink/public/common/fingerprint/fingerprint.h" 6 | #include "third_party/blink/public/mojom/permissions_policy/permissions_policy_feature.mojom-forward.h" 7 | 8 | bool requestPermissionFp( 9 | blink::mojom::PermissionsPolicyFeature permissions_policy_feature_) { 10 | if (blink::mojom::PermissionsPolicyFeature::kGeolocation != permissions_policy_feature_) { 11 | return false; 12 | } 13 | 14 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 15 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 16 | 17 | if (base::SingletonFingerprint::GetInit(t_singletonFingerprint) && 18 | t_fingerprint.location.type > 1 && t_fingerprint.location.permissions) { 19 | return true; 20 | } 21 | return false; 22 | } 23 | 24 | #endif // COMPONENTS_PERMISSIONS_PERMISSION_CONTEXT_BASE_FP_H_ 25 | 26 | -------------------------------------------------------------------------------- /content/browser/renderer_host/pf_font_find_family.h: -------------------------------------------------------------------------------- 1 | #ifndef CONTENT_BROWSER_RENDERER_HOST_PF_FONT_FIND_FAMILY_H_ 2 | #define CONTENT_BROWSER_RENDERER_HOST_PF_FONT_FIND_FAMILY_H_ 3 | 4 | #include 5 | #include 6 | #include "base/containers/flat_map.h" 7 | #include "third_party/blink/public/common/fingerprint/fingerprint.h" 8 | #include "base/singleton_fingerprint.h" 9 | 10 | 11 | 12 | // #include 13 | // #include 14 | 15 | std::u16string toLower(const std::u16string& str) { 16 | std::u16string lowerStr; 17 | for (char16_t c : str) { 18 | if (c >= u'A' && c <= u'Z') { 19 | lowerStr.push_back(c + (u'a' - u'A')); 20 | } else if (c >= u'A' && c <= u'Z') { 21 | lowerStr.push_back(c + (u'a' - u'A')); 22 | } else { 23 | lowerStr.push_back(c); 24 | } 25 | } 26 | return lowerStr; 27 | } 28 | 29 | std::string U16StringToUTF8(const std::u16string& u16str) { 30 | std::u16string result = toLower(u16str); 31 | std::string str; 32 | base::UTF16ToUTF8(result.data(), result.size(), &str); 33 | return str; 34 | } 35 | 36 | 37 | 38 | UINT32 fpFindFamily(const std::u16string& family_name, UINT32 family_index) { 39 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 40 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 41 | if(base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.font.type > 1){ 42 | base::flat_map fontMap = t_fingerprint.font.fontMap; 43 | std::string font = U16StringToUTF8(family_name); 44 | auto iter = fontMap.find(font); 45 | if (iter != fontMap.end()) { 46 | blink::fp::FontInfo fontInfo = iter->second; 47 | if (fontInfo.id>-1) { 48 | return fontInfo.id; 49 | }else{ 50 | 51 | return family_index; 52 | } 53 | }else{ 54 | // if(family_index==51){ 55 | // std::ofstream outputFile("D://output.txt", std::ios::app); 56 | // if (outputFile.is_open()) { 57 | // outputFile <GetFingerprint(); 72 | // if(base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.font.type ==2){ 73 | // return t_fingerprint.font.maxId; 74 | // } 75 | return count; 76 | } 77 | 78 | 79 | UINT32 fpGetFontFileHandles(UINT32 index){ 80 | // if(UINT32_MAX==index){ 81 | // return UINT32_MAX; 82 | // } 83 | // base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 84 | // blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 85 | // if(base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.font.type ==2){ 86 | // base::flat_map fontIdMap = t_fingerprint.font.fontIdMap; 87 | // auto iter = fontIdMap.find(index); 88 | // if (iter != fontIdMap.end()) { 89 | // return (UINT32)t_fingerprint.font.defaultId; 90 | // }else{ 91 | // return index; 92 | // } 93 | // } 94 | return index; 95 | } 96 | 97 | #endif // CONTENT_BROWSER_RENDERER_HOST_PF_FONT_FIND_FAMILY_H_ 98 | /* 99 | #include 100 | #include 101 | std::ofstream outputFile("D://output.txt", std::ios::app); 102 | if (outputFile.is_open()) { 103 | outputFile << "\""+ font+"\":\"\"" << std::endl; 104 | outputFile.close(); } 105 | */ 106 | 107 | -------------------------------------------------------------------------------- /content/child/dwrite_font_proxy/fp_dwite_font.h: -------------------------------------------------------------------------------- 1 | #ifndef CONTENT_CHILD_DWRITE_FONT_PROXY_FP_DWITE_FONT_H_ 2 | #define CONTENT_CHILD_DWRITE_FONT_PROXY_FP_DWITE_FONT_H_ 3 | 4 | #include "third_party/blink/public/common/fingerprint/fingerprint.h" 5 | #include "base/singleton_fingerprint.h" 6 | 7 | void fpLoadFamilyCoreLockRequired(UINT32* index,std::u16string* name){ 8 | // base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 9 | // blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 10 | 11 | // if (base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.font.type ==3) { 12 | // base::flat_map& fontIdMap = t_fingerprint.font.fontIdMap; 13 | // auto iter = fontIdMap.find(*index); 14 | 15 | // if (iter != fontIdMap.end()) { 16 | // *index = static_cast(t_fingerprint.font.defaultId); 17 | // *name = std::u16string(t_fingerprint.font.defaultName.begin(), t_fingerprint.font.defaultName.end()); 18 | // } 19 | // } 20 | } 21 | #endif // CONTENT_CHILD_DWRITE_FONT_PROXY_FP_DWITE_FONT_H_ -------------------------------------------------------------------------------- /content/common/renderer.mojom: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Chromium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | module content.mojom; 6 | 7 | import "content/common/agent_scheduling_group.mojom"; 8 | import "content/common/native_types.mojom"; 9 | import "ipc/ipc.mojom"; 10 | import "mojo/public/mojom/base/generic_pending_receiver.mojom"; 11 | import "mojo/public/mojom/base/time.mojom"; 12 | import "services/network/public/mojom/network_types.mojom"; 13 | import "services/network/public/mojom/attribution.mojom"; 14 | import "skia/public/mojom/skcolor.mojom"; 15 | import "third_party/blink/public/mojom/browser_interface_broker.mojom"; 16 | import "third_party/blink/public/mojom/user_agent/user_agent_metadata.mojom"; 17 | import "ui/color/color_id.mojom"; 18 | import "third_party/blink/public/mojom/fingerprint/fingerprint.mojom"; 19 | 20 | struct UpdateScrollbarThemeParams { 21 | // TODO(avi): Update these to optional values when optional numeric types are 22 | // allowed. (https://crbug.com/657632) 23 | bool has_initial_button_delay; 24 | float initial_button_delay; 25 | bool has_autoscroll_button_delay; 26 | float autoscroll_button_delay; 27 | 28 | bool jump_on_track_click; 29 | ScrollerStyle preferred_scroller_style; 30 | bool redraw; 31 | 32 | bool scroll_view_rubber_banding; 33 | }; 34 | 35 | struct UpdateSystemColorInfoParams { 36 | bool is_dark_mode; 37 | bool forced_colors; 38 | 39 | // uint32 represents a SkColor in the map. 40 | // TODO(crbug.com/1251637): These colors should be consolidated into the 41 | // renderer's ColorProviders. 42 | map colors; 43 | 44 | // Maps used to reconstruct ColorProvider instances in the renderer. 45 | map light_colors; 46 | map dark_colors; 47 | }; 48 | 49 | // The background state for the render process. When backgrounded the process's 50 | // priority will be lower (via base::Process::SetProcessBackgrounded()) if 51 | // allowed on the current platform (as determined by 52 | // base::Process::CanBackgroundProcesses()). 53 | enum RenderProcessBackgroundState { 54 | // The renderer process has not been backgrounded, a hidden renderer may still 55 | // be foregrounded, e.g. when it is playing audio. 56 | kForegrounded, 57 | // The renderer process has been backgrounded, a visible renderer may still 58 | // be backgrounded, e.g. when it is hosting only low priority frames. 59 | kBackgrounded, 60 | }; 61 | 62 | // The visibility state for the renderer process, indicating whether or not any 63 | // of the frames associated with the renderer process are visible. 64 | enum RenderProcessVisibleState { 65 | kVisible, 66 | kHidden, 67 | }; 68 | 69 | // The primordial Channel-associated interface implemented by a render process. 70 | // This should be used for implementing browser-to-renderer control messages 71 | // which need to retain FIFO with respect to legacy IPC messages. 72 | interface Renderer { 73 | // Tells the renderer to create a new AgentSchedulingGroup, and initialize its 74 | // legacy IPC Channel using the pipe provided by `bootstrap`. The channel will 75 | // later be used to bind the mojom::AgentSchedulingGroup receiver, that 76 | // listens to messages sent by the host. 77 | // This will create an "independent" agent scheduling group that is not 78 | // associated with the process-wide or other groups' IPC channels, meaning 79 | // there is no guaranteed ordering between them. 80 | // `broker_remote` is the BrowserInterfaceBroker bound to the newly-created 81 | // AgentSchedulingGroup. 82 | CreateAgentSchedulingGroup( 83 | pending_receiver bootstrap, 84 | pending_remote broker_remote); 85 | 86 | // Tells the renderer to create a new AgentSchedulingGroup, that will 87 | // listen to messages sent by the host via the pending 88 | // |agent_scheduling_group|. 89 | // This will create an agent scheduling group that is associated with the 90 | // process-wide IPC channel, preserving message ordering across different 91 | // agent scheduling groups. 92 | // `broker_remote` is the BrowserInterfaceBroker bound to the newly-created 93 | // AgentSchedulingGroup. 94 | CreateAssociatedAgentSchedulingGroup( 95 | pending_associated_receiver agent_scheduling_group, 96 | pending_remote broker_remote); 97 | 98 | // Tells the renderer that the network type has changed so that 99 | // navigator.onLine and navigator.connection can be updated. 100 | OnNetworkConnectionChanged(NetworkConnectionType connection_type, 101 | double max_bandwidth_mbps); 102 | 103 | // Tells the renderer process that the network quality estimate has changed. 104 | // EffectiveConnectionType is the connection type whose typical performance is 105 | // most similar to the measured performance of the network in use. 106 | // The downstream throughput is computed in kilobits per second. If an 107 | // estimate of the HTTP or transport RTT is unavailable, it will be set to 108 | // net::nqe::internal::InvalidRTT(). If the throughput estimate is 109 | // unavailable, it will be set to net::nqe::internal::INVALID_RTT_THROUGHPUT. 110 | OnNetworkQualityChanged( 111 | network.mojom.EffectiveConnectionType effective_connection_type, 112 | mojo_base.mojom.TimeDelta http_rtt, 113 | mojo_base.mojom.TimeDelta transport_rtt, 114 | double bandwidth_kbps); 115 | 116 | // Tells the renderer to suspend/resume the webkit timers. Only for use on 117 | // Android. 118 | SetWebKitSharedTimersSuspended(bool suspend); 119 | 120 | // Tells the renderer about a scrollbar appearance change. Only for use on 121 | // OS X. 122 | UpdateScrollbarTheme(UpdateScrollbarThemeParams params); 123 | 124 | // Notification that the OS X Aqua color preferences changed. 125 | OnSystemColorsChanged(int32 aqua_color_variant); 126 | 127 | // Tells the renderer process the new system color info. 128 | UpdateSystemColorInfo(UpdateSystemColorInfoParams params); 129 | 130 | // Tells the renderer to empty its plugin list cache, optional reloading 131 | // pages containing plugins. 132 | PurgePluginListCache(bool reload_pages); 133 | 134 | 135 | // Tells the renderer process of a change in visibility or background state. 136 | SetProcessState(RenderProcessBackgroundState background_state, 137 | RenderProcessVisibleState visible_state); 138 | 139 | // Tells the renderer process that it has been locked to a site (i.e., a 140 | // scheme plus eTLD+1, such as https://google.com), or to a more specific 141 | // origin. 142 | SetIsLockedToSite(); 143 | 144 | // Write out the accumulated code profiling profile to the configured file. 145 | // The callback is invoked once the profile has been flushed to disk. 146 | [EnableIf=clang_profiling_inside_sandbox] 147 | WriteClangProfilingProfile() => (); 148 | 149 | // Set whether this renderer process is "cross-origin isolated". This 150 | // corresponds to agent cluster's "cross-origin isolated" concept. 151 | // TODO(yhirano): Have the spec URL. 152 | // This property is process global because we ensure that a renderer process 153 | // host only cross-origin isolated agents or only non-cross-origin isolated 154 | // agents, not both. 155 | // This is called at most once, prior to committing a navigation. 156 | SetIsCrossOriginIsolated(bool value); 157 | 158 | // Set whether this renderer process is allowed to use Isolated Context APIs. 159 | // Similarly to the `SetIsCrossOriginIsolated()` method above, this flag is 160 | // process global, and called at most once, prior to committing a navigation. 161 | // 162 | // TODO(crbug.com/1206150): We need a specification for this restriction. 163 | SetIsIsolatedContext(bool value); 164 | 165 | // Initialize renderer user agent string, user agent metadata and CORS exempt 166 | // header list on renderer startup. 167 | // 168 | // |user_agent| sets the user-agent string. This is needed because getting the 169 | // value in the renderer from the system leads to a wrong value due to 170 | // sandboxing. This must be called as early as possible, during the renderer 171 | // process initialization. 172 | // 173 | // |full_user_agent| sets the full user-agent with high-entropy information. 174 | // 175 | // |reduced_user_agent| sets a user-agent with high-entropy information 176 | // reduced to common values. 177 | // 178 | // |metadata| sets the user agent metadata. This will replace `SetUserAgent()` 179 | // if we decide to ship https://github.com/WICG/ua-client-hints. 180 | // 181 | // |cors_exempt_header_list| sets the CORS exempt header list for sanity 182 | // checking (e.g. DCHECKs). 183 | // 184 | // |attribution_support| sets whether web or OS-level Attribution Reporting is supported. 185 | InitializeRenderer(string user_agent, 186 | string full_user_agent, 187 | string reduced_user_agent, 188 | blink.mojom.Fingerprint fingerprint, 189 | blink.mojom.UserAgentMetadata metadata, 190 | array cors_exempt_header_list, 191 | network.mojom.AttributionSupport attribution_support); 192 | 193 | // Set whether web or OS-level Attribution Reporting is supported. 194 | [EnableIf=is_android] 195 | SetAttributionReportingSupport(network.mojom.AttributionSupport attribution_support); 196 | }; 197 | -------------------------------------------------------------------------------- /third_party/blink/common/fingerprint/OWNERS: -------------------------------------------------------------------------------- 1 | file://components/embedder_support/OWNERS 2 | 3 | per-file *.typemap=set noparent 4 | per-file *.typemap=file://ipc/SECURITY_OWNERS 5 | 6 | per-file *_mojom_traits*.*=set noparent 7 | per-file *_mojom_traits*.*=file://ipc/SECURITY_OWNERS 8 | -------------------------------------------------------------------------------- /third_party/blink/common/fingerprint/fingerprint_mojom_traits.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Chromium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "third_party/blink/public/common/fingerprint/fingerprint_mojom_traits.h" 6 | #include "third_party/blink/public/common/user_agent/user_agent_mojom_traits.h" 7 | #include 8 | 9 | namespace mojo { 10 | 11 | bool StructTraits::Read( 12 | blink::mojom::ConsistencyDataView data, ::blink::fp::Consistency* out) { 13 | 14 | out->type = data.type(); 15 | 16 | std::vector urlList; 17 | if (!data.ReadUrlList(&urlList)) { 18 | return false; 19 | } 20 | out->urlList = std::move(urlList); 21 | 22 | return true; 23 | } 24 | 25 | bool StructTraits::Read( 26 | blink::mojom::UADataView data, ::blink::fp::UA* out) { 27 | 28 | out->type = data.type(); 29 | 30 | if (!data.ReadUserAgent(&out->userAgent)) { 31 | return false; 32 | } 33 | 34 | return true; 35 | } 36 | 37 | bool StructTraits::Read( 38 | blink::mojom::UaMetadataDataView data, ::blink::fp::UaMetadata* out) { 39 | 40 | out->type = data.type(); 41 | 42 | if (!data.ReadUserAgentMetadata(&out->userAgentMetadata)) { 43 | return false; 44 | } 45 | 46 | return true; 47 | } 48 | 49 | bool StructTraits::Read( 50 | blink::mojom::WebRTCDataView data, ::blink::fp::WebRTC* out) { 51 | 52 | out->type = data.type(); 53 | 54 | if (!data.ReadPrivateIp(&out->privateIp)) { 55 | return false; 56 | } 57 | 58 | if (!data.ReadPublicIp(&out->publicIp)) { 59 | return false; 60 | } 61 | 62 | return true; 63 | } 64 | 65 | bool StructTraits::Read( 66 | blink::mojom::TimeZoneDataView data, ::blink::fp::TimeZone* out) { 67 | 68 | out->type = data.type(); 69 | 70 | if (!data.ReadGmt(&out->gmt)) { 71 | return false; 72 | } 73 | 74 | return true; 75 | } 76 | 77 | bool StructTraits::Read( 78 | blink::mojom::LocationDataView data, ::blink::fp::Location* out) { 79 | out->type = data.type(); 80 | out->permissions=data.permissions(); 81 | out->latitude = data.latitude(); 82 | 83 | out->longitude = data.longitude(); 84 | 85 | out->accuracy = data.accuracy(); 86 | 87 | return true; 88 | } 89 | 90 | bool StructTraits::Read( 91 | blink::mojom::LanguageDataView data, ::blink::fp::Language* out) { 92 | 93 | out->type = data.type(); 94 | 95 | if (!data.ReadInterfaceLanguage(&out->interfaceLanguage)) { 96 | return false; 97 | } 98 | 99 | std::vector languages; 100 | if (!data.ReadLanguages(&languages)) { 101 | return false; 102 | } 103 | out->languages = std::move(languages); 104 | 105 | return true; 106 | } 107 | 108 | bool StructTraits::Read( 109 | blink::mojom::ResolutionDataView data, ::blink::fp::Resolution* out) { 110 | 111 | out->type = data.type(); 112 | 113 | out->windowWidth = data.windowWidth(); 114 | 115 | out->windowHeight = data.windowHeight(); 116 | 117 | out->monitorWidth = data.monitorWidth(); 118 | 119 | out->monitorHeight = data.monitorHeight(); 120 | 121 | return true; 122 | } 123 | 124 | bool StructTraits::Read( 125 | blink::mojom::FontInfoDataView data, ::blink::fp::FontInfo* out) { 126 | 127 | out->id = data.id(); 128 | out->width = data.width(); 129 | out->height = data.height(); 130 | out->actualBoundingBoxAscent = data.actualBoundingBoxAscent(); 131 | out->actualBoundingBoxDescent = data.actualBoundingBoxDescent(); 132 | out->actualBoundingBoxLeft = data.actualBoundingBoxLeft(); 133 | out->actualBoundingBoxRight = data.actualBoundingBoxRight(); 134 | out->fontBoundingBoxAscent = data.fontBoundingBoxAscent(); 135 | out->fontBoundingBoxDescent = data.fontBoundingBoxDescent(); 136 | 137 | std::vector filePaths; 138 | if (!data.ReadFilePaths(&filePaths)) { 139 | return false; 140 | } 141 | out->filePaths = std::move(filePaths); 142 | 143 | return true; 144 | } 145 | 146 | bool StructTraits::Read( 147 | blink::mojom::FontDataView data, ::blink::fp::Font* out) { 148 | 149 | out->type = data.type(); 150 | out->maxId = data.maxId(); 151 | out->defaultId = data.defaultId(); 152 | if (!data.ReadDefaultName(&out->defaultName)) { 153 | return false; 154 | } 155 | std::vector filePaths; 156 | if (!data.ReadDefaultPaths(&filePaths)) { 157 | return false; 158 | } 159 | out->defaultPaths = std::move(filePaths); 160 | 161 | base::flat_map fontMap; 162 | if (!data.ReadFontMap(&fontMap)) { 163 | return false; 164 | } 165 | out->fontMap = std::move(fontMap); 166 | 167 | base::flat_map fontIdMap; 168 | if (!data.ReadFontIdMap(&fontIdMap)) { 169 | return false; 170 | } 171 | out->fontIdMap = std::move(fontIdMap); 172 | 173 | 174 | return true; 175 | } 176 | 177 | bool StructTraits::Read( 178 | blink::mojom::ColoredPointDataView data, ::blink::fp::ColoredPoint* out) { 179 | 180 | out->row = data.row(); 181 | 182 | out->column = data.column(); 183 | 184 | out->red = data.red(); 185 | 186 | out->green = data.green(); 187 | 188 | out->blue = data.blue(); 189 | 190 | out->alpha = data.alpha(); 191 | 192 | return true; 193 | } 194 | 195 | bool StructTraits::Read( 196 | blink::mojom::CanvasDataView data, ::blink::fp::Canvas* out) { 197 | 198 | out->type = data.type(); 199 | 200 | std::vector<::blink::fp::ColoredPoint> coloredPointList; 201 | if (!data.ReadColoredPointList(&coloredPointList)) { 202 | return false; 203 | } 204 | out->coloredPointList = std::move(coloredPointList); 205 | 206 | return true; 207 | } 208 | 209 | bool StructTraits::Read( 210 | blink::mojom::WebGLDeviceDataView data, ::blink::fp::WebGLDevice* out) { 211 | 212 | out->type = data.type(); 213 | 214 | if (!data.ReadVendors(&out->vendors)) { 215 | return false; 216 | } 217 | 218 | if (!data.ReadRenderer(&out->renderer)) { 219 | return false; 220 | } 221 | 222 | if (!data.ReadGpuVendors(&out->gpuVendors)) { 223 | return false; 224 | } 225 | 226 | if (!data.ReadGpuArchitecture(&out->gpuArchitecture)) { 227 | return false; 228 | } 229 | return true; 230 | } 231 | 232 | bool StructTraits::Read( 233 | blink::mojom::AudioContextDataView data, ::blink::fp::AudioContext* out) { 234 | out->type = data.type(); 235 | 236 | std::vector noise; 237 | if (!data.ReadNoise(&noise)) { 238 | return false; 239 | } 240 | out->noise = std::move(noise); 241 | 242 | return true; 243 | } 244 | 245 | bool StructTraits::Read( 246 | blink::mojom::MediaEquipmentInfoDataView data, ::blink::fp::MediaEquipmentInfo* out) { 247 | out->type = data.type(); 248 | if (!data.ReadLabel(&out->label)) { 249 | return false; 250 | } 251 | 252 | if (!data.ReadDeviceId(&out->deviceId)) { 253 | return false; 254 | } 255 | 256 | if (!data.ReadGroupId(&out->groupId)) { 257 | return false; 258 | } 259 | 260 | return true; 261 | } 262 | 263 | bool StructTraits::Read( 264 | blink::mojom::MediaEquipmentDataView data, ::blink::fp::MediaEquipment* out) { 265 | 266 | out->type = data.type(); 267 | 268 | std::vector<::blink::fp::MediaEquipmentInfo> list; 269 | if (!data.ReadList(&list)) { 270 | return false; 271 | } 272 | out->list = std::move(list); 273 | 274 | return true; 275 | } 276 | 277 | bool StructTraits::Read( 278 | blink::mojom::ClientRectsDataView data, ::blink::fp::ClientRects* out) { 279 | 280 | out->type = data.type(); 281 | 282 | out->x = data.x(); 283 | 284 | out->y = data.y(); 285 | 286 | out->width = data.width(); 287 | 288 | out->height = data.height(); 289 | 290 | return true; 291 | } 292 | 293 | bool StructTraits::Read( 294 | blink::mojom::SpeechVoicesInfoDataView data, ::blink::fp::SpeechVoicesInfo* out) { 295 | 296 | if (!data.ReadVoiceUri(&out->voiceUri)) { 297 | return false; 298 | } 299 | 300 | if (!data.ReadName(&out->name)) { 301 | return false; 302 | } 303 | 304 | if (!data.ReadLang(&out->lang)) { 305 | return false; 306 | } 307 | 308 | out->isLocalService = data.isLocalService(); 309 | 310 | out->isDefault = data.isDefault(); 311 | 312 | return true; 313 | } 314 | 315 | bool StructTraits::Read( 316 | blink::mojom::SpeechVoicesDataView data, ::blink::fp::SpeechVoices* out) { 317 | out->type = data.type(); 318 | 319 | std::vector<::blink::fp::SpeechVoicesInfo> list; 320 | if (!data.ReadList(&list)) { 321 | return false; 322 | } 323 | out->list = std::move(list); 324 | 325 | return true; 326 | } 327 | 328 | bool StructTraits::Read( 329 | blink::mojom::ResourceInfoDataView data, ::blink::fp::ResourceInfo* out) { 330 | out->type = data.type(); 331 | 332 | out->cpu = data.cpu(); 333 | 334 | out->memory = data.memory(); 335 | 336 | return true; 337 | } 338 | 339 | bool StructTraits::Read( 340 | blink::mojom::DoNotTrackDataView data, ::blink::fp::DoNotTrack* out) { 341 | out->type = data.type(); 342 | 343 | out->flag = data.flag(); 344 | 345 | return true; 346 | } 347 | 348 | bool StructTraits::Read( 349 | blink::mojom::OpenPortDataView data, ::blink::fp::OpenPort* out) { 350 | out->type = data.type(); 351 | 352 | std::vector openPort; 353 | if (!data.ReadOpenPort(&openPort)) { 354 | return false; 355 | } 356 | out->openPort = std::move(openPort); 357 | 358 | if (!data.ReadUrl(&out->url)) { 359 | return false; 360 | } 361 | 362 | return true; 363 | } 364 | 365 | 366 | bool StructTraits::Read( 367 | blink::mojom::FingerprintDataView data, ::blink::fp::Fingerprint* out) { 368 | out->init = data.init(); 369 | 370 | if (!data.ReadConsistency(&out->consistency)) { 371 | return false; 372 | } 373 | 374 | if (!data.ReadUa(&out->ua)) { 375 | return false; 376 | } 377 | 378 | if (!data.ReadUaMetadata(&out->uaMetadata)) { 379 | return false; 380 | } 381 | 382 | if (!data.ReadTimeZone(&out->timeZone)) { 383 | return false; 384 | } 385 | 386 | if (!data.ReadWebRtc(&out->webRTC)) { 387 | return false; 388 | } 389 | 390 | if (!data.ReadLocation(&out->location)) { 391 | return false; 392 | } 393 | 394 | if (!data.ReadLanguage(&out->language)) { 395 | return false; 396 | } 397 | 398 | if (!data.ReadResolution(&out->resolution)) { 399 | return false; 400 | } 401 | 402 | if (!data.ReadFont(&out->font)) { 403 | return false; 404 | } 405 | 406 | if (!data.ReadCanvas(&out->canvas)) { 407 | return false; 408 | } 409 | 410 | if (!data.ReadWebGl(&out->webGL)) { 411 | return false; 412 | } 413 | 414 | if (!data.ReadGupGl(&out->gupGL)) { 415 | return false; 416 | } 417 | 418 | if (!data.ReadWebGlDevice(&out->webGLDevice)) { 419 | return false; 420 | } 421 | 422 | if (!data.ReadAudioContext(&out->audioContext)) { 423 | return false; 424 | } 425 | 426 | if (!data.ReadMediaEquipment(&out->mediaEquipment)) { 427 | return false; 428 | } 429 | 430 | if (!data.ReadClientRects(&out->clientRects)) { 431 | return false; 432 | } 433 | 434 | if (!data.ReadSpeechVoices(&out->speechVoices)) { 435 | return false; 436 | } 437 | 438 | if (!data.ReadResourceInfo(&out->resourceInfo)) { 439 | return false; 440 | } 441 | 442 | if (!data.ReadDoNotTrack(&out->doNotTrack)) { 443 | return false; 444 | } 445 | 446 | if (!data.ReadOpenPort(&out->openPort)) { 447 | return false; 448 | } 449 | 450 | return true; 451 | } 452 | 453 | } // namespace mojo 454 | -------------------------------------------------------------------------------- /third_party/blink/public/common/fingerprint/OWNERS: -------------------------------------------------------------------------------- 1 | file://components/embedder_support/OWNERS 2 | 3 | per-file *_mojom_traits*.*=set noparent 4 | per-file *_mojom_traits*.*=file://ipc/SECURITY_OWNERS 5 | -------------------------------------------------------------------------------- /third_party/blink/public/common/fingerprint/fingerprint.h: -------------------------------------------------------------------------------- 1 | #ifndef THIRD_PARTY_BLINK_PUBLIC_COMMON_FINGERPRINT_FINGERPRINT_METADATA_H_ 2 | #define THIRD_PARTY_BLINK_PUBLIC_COMMON_FINGERPRINT_FINGERPRINT_METADATA_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include "base/containers/flat_map.h" 8 | 9 | #include "third_party/blink/public/common/user_agent/user_agent_metadata.h" 10 | 11 | 12 | #include "third_party/abseil-cpp/absl/types/optional.h" 13 | #include "third_party/blink/public/common/common_export.h" 14 | 15 | namespace blink { 16 | 17 | namespace fp { 18 | 19 | /* 0 跟随ip 1 关闭 2 噪音 3 噪音 0和1 都是关闭 20 | 后期启动的同步,用户画图和声音指纹 21 | Canvas canvas; 22 | Canvas webGL; 23 | Canvas gupGL; 24 | AudioContext audioContext; 25 | 暂时可以为空 26 | */ 27 | struct BLINK_COMMON_EXPORT Consistency { 28 | public: 29 | int type = 0; 30 | std::vector urlList; 31 | }; 32 | 33 | /* 0 跟随ip 1 关闭 2 噪音 3 噪音 34 | ua 默认不读取 只是正常传 35 | */ 36 | struct BLINK_COMMON_EXPORT UA{ 37 | public: 38 | int type = 0; 39 | std::string userAgent; 40 | }; 41 | 42 | /* 0 跟随ip 1 关闭 2 噪音 3 噪音 43 | */ 44 | struct BLINK_COMMON_EXPORT UaMetadata{ 45 | public: 46 | int type = 0; 47 | blink::UserAgentMetadata userAgentMetadata; 48 | }; 49 | 50 | struct BLINK_COMMON_EXPORT WebRTC { 51 | public: 52 | int type = 0; 53 | std::string privateIp; 54 | std::string publicIp; 55 | }; 56 | 57 | struct BLINK_COMMON_EXPORT TimeZone { 58 | public: 59 | int type = 0; 60 | std::string gmt; 61 | }; 62 | 63 | struct BLINK_COMMON_EXPORT Location { 64 | public: 65 | int type = 0; 66 | bool permissions; 67 | double latitude ; 68 | double longitude ; 69 | double accuracy ; 70 | }; 71 | 72 | struct BLINK_COMMON_EXPORT Language { 73 | public: 74 | int type = 0; 75 | std::string interfaceLanguage; 76 | std::vector languages; 77 | }; 78 | 79 | 80 | struct BLINK_COMMON_EXPORT Resolution { 81 | public: 82 | int type = 0; 83 | int windowWidth; 84 | int windowHeight; 85 | 86 | int monitorWidth; 87 | int monitorHeight; 88 | 89 | }; 90 | 91 | struct BLINK_COMMON_EXPORT FontInfo { 92 | public: 93 | int id = 0; 94 | double width; 95 | double height; 96 | double actualBoundingBoxAscent; 97 | double actualBoundingBoxDescent; 98 | double actualBoundingBoxLeft; 99 | double actualBoundingBoxRight; 100 | double fontBoundingBoxAscent; 101 | double fontBoundingBoxDescent; 102 | std::vector filePaths; 103 | }; 104 | 105 | struct BLINK_COMMON_EXPORT Font { 106 | public: 107 | int type = 0; 108 | int maxId = 0; 109 | int defaultId = 0; 110 | std::string defaultName; 111 | std::vector defaultPaths; 112 | base::flat_map fontMap; 113 | base::flat_map fontIdMap; 114 | }; 115 | 116 | struct BLINK_COMMON_EXPORT ColoredPoint{ 117 | public: 118 | int row; 119 | int column; 120 | int red; 121 | int green; 122 | int blue; 123 | int alpha; 124 | }; 125 | 126 | struct BLINK_COMMON_EXPORT Canvas { 127 | public: 128 | int type = 0; 129 | std::vector coloredPointList; 130 | 131 | }; 132 | 133 | struct BLINK_COMMON_EXPORT WebGLDevice { 134 | public: 135 | int type = 0; 136 | std::string vendors; 137 | std::string renderer; 138 | std::string gpuVendors; 139 | std::string gpuArchitecture; 140 | }; 141 | 142 | struct BLINK_COMMON_EXPORT AudioContext { 143 | public: 144 | int type = 0; 145 | std::vector noise; 146 | }; 147 | 148 | struct BLINK_COMMON_EXPORT MediaEquipmentInfo { 149 | public: 150 | int type = 0; //0 是麦克风   1 摄像头  2  音响 151 | std::string label; 152 | std::string deviceId; 153 | std::string groupId; 154 | 155 | }; 156 | 157 | struct BLINK_COMMON_EXPORT MediaEquipment { 158 | public: 159 | int type = 0; 160 | std::vector list; 161 | }; 162 | 163 | 164 | struct BLINK_COMMON_EXPORT ClientRects { 165 | public: 166 | int type = 0; // 0 默认 1.噪音 ,2. 系统默认, 3.关闭 167 | double x; //可以存任意的数字 这里放的是倍数,只影响小数后7位 168 | double y; 169 | double width; 170 | double height; 171 | }; 172 | 173 | struct BLINK_COMMON_EXPORT SpeechVoicesInfo { 174 | public: 175 | std::string voiceUri; 176 | std::string name; 177 | std::string lang; 178 | bool isLocalService; 179 | bool isDefault; 180 | }; 181 | 182 | struct BLINK_COMMON_EXPORT SpeechVoices { 183 | public: 184 | int type = 0; 185 | std::vector list; 186 | }; 187 | 188 | struct BLINK_COMMON_EXPORT ResourceInfo { 189 | public: 190 | int type = 0; 191 | int cpu; 192 | float memory; 193 | }; 194 | 195 | struct BLINK_COMMON_EXPORT DoNotTrack { 196 | public: 197 | int type = 0; 198 | bool flag; 199 | }; 200 | 201 | struct BLINK_COMMON_EXPORT OpenPort{ 202 | public: 203 | int type = 0; 204 | std::vector openPort; 205 | std::string url; 206 | }; 207 | 208 | 209 | 210 | struct BLINK_COMMON_EXPORT Fingerprint { 211 | public: 212 | int init = 0; //0 默认,1 关闭 2 噪音(启动) 0和1 都是关闭 其他都不会生效 213 | Consistency consistency; 214 | UA ua; 215 | UaMetadata uaMetadata; 216 | TimeZone timeZone; 217 | WebRTC webRTC; 218 | Location location; 219 | Language language; 220 | Resolution resolution; 221 | Font font; 222 | Canvas canvas; 223 | Canvas webGL; 224 | Canvas gupGL; 225 | WebGLDevice webGLDevice; 226 | AudioContext audioContext; 227 | MediaEquipment mediaEquipment; 228 | ClientRects clientRects; 229 | SpeechVoices speechVoices; 230 | ResourceInfo resourceInfo; 231 | DoNotTrack doNotTrack; 232 | OpenPort openPort; 233 | }; 234 | } // namespace pf 235 | } // namespace blink 236 | 237 | 238 | 239 | #endif // THIRD_PARTY_BLINK_PUBLIC_COMMON_FINGERPRINT_FINGERPRINT_METADATA_H_ -------------------------------------------------------------------------------- /third_party/blink/public/mojom/fingerprint/fingerprint.mojom: -------------------------------------------------------------------------------- 1 | module blink.mojom; 2 | import "third_party/blink/public/mojom/user_agent/user_agent_metadata.mojom"; 3 | 4 | struct Consistency { 5 | int32 type = 0; 6 | array urlList; 7 | }; 8 | 9 | struct UA { 10 | int32 type = 0; 11 | string userAgent; 12 | }; 13 | 14 | struct UaMetadata { 15 | int32 type = 0; 16 | blink.mojom.UserAgentMetadata userAgentMetadata; 17 | }; 18 | 19 | struct WebRTC { 20 | int32 type = 0; 21 | string privateIp; 22 | string publicIp; 23 | }; 24 | 25 | struct TimeZone { 26 | int32 type = 0; 27 | string gmt; 28 | }; 29 | 30 | 31 | struct Location { 32 | int32 type = 0; 33 | bool permissions; 34 | double latitude; 35 | double longitude; 36 | double accuracy; 37 | }; 38 | 39 | struct Language { 40 | int32 type = 0; 41 | string interfaceLanguage; 42 | array languages; 43 | }; 44 | 45 | struct Resolution { 46 | int32 type = 0; 47 | int32 windowWidth; 48 | int32 windowHeight; 49 | int32 monitorWidth; 50 | int32 monitorHeight; 51 | }; 52 | 53 | struct FontInfo { 54 | int32 id = 0; 55 | double width; 56 | double height; 57 | double actualBoundingBoxAscent; 58 | double actualBoundingBoxDescent; 59 | double actualBoundingBoxLeft; 60 | double actualBoundingBoxRight; 61 | double fontBoundingBoxAscent; 62 | double fontBoundingBoxDescent; 63 | array filePaths; 64 | }; 65 | 66 | struct Font { 67 | int32 type = 0; 68 | int32 maxId = 0; 69 | int32 defaultId = 0; 70 | string defaultName ; 71 | array defaultPaths; 72 | map fontMap; 73 | map fontIdMap; 74 | }; 75 | 76 | struct ColoredPoint{ 77 | int32 row; 78 | int32 column; 79 | int32 red; 80 | int32 green; 81 | int32 blue; 82 | int32 alpha; 83 | }; 84 | 85 | struct Canvas { 86 | int32 type = 0; 87 | array coloredPointList; 88 | }; 89 | 90 | struct WebGLDevice { 91 | int32 type = 0; 92 | string vendors; 93 | string renderer; 94 | string gpuVendors; 95 | string gpuArchitecture; 96 | }; 97 | 98 | struct AudioContext { 99 | int32 type = 0; 100 | array noise; 101 | }; 102 | 103 | struct MediaEquipmentInfo { 104 | int32 type = 0; 105 | string label; 106 | string deviceId; 107 | string groupId; 108 | }; 109 | 110 | struct MediaEquipment { 111 | int32 type = 0; // 0 默认 1.噪音 ,2. 系统默认, 3.关闭 112 | array list; 113 | }; 114 | 115 | struct ClientRects { 116 | int32 type = 0; // 0 默认 1.噪音 ,2. 系统默认, 3.关闭 117 | double x; 118 | double y; 119 | double width; 120 | double height; 121 | }; 122 | 123 | struct SpeechVoicesInfo { 124 | string voiceUri; 125 | string name; 126 | string lang; 127 | bool isLocalService; 128 | bool isDefault; 129 | }; 130 | 131 | struct SpeechVoices { 132 | int32 type = 0; 133 | array list; 134 | }; 135 | 136 | struct ResourceInfo { 137 | int32 type = 0; 138 | int32 cpu; 139 | float memory; 140 | }; 141 | 142 | struct DoNotTrack { 143 | int32 type = 0; 144 | bool flag; 145 | }; 146 | 147 | struct OpenPort{ 148 | int32 type = 0; 149 | array openPort; 150 | string url; 151 | }; 152 | 153 | struct Fingerprint { 154 | int32 init = 0; 155 | Consistency consistency; 156 | UA ua; 157 | UaMetadata uaMetadata; 158 | TimeZone timeZone; 159 | WebRTC webRTC; 160 | Location location; 161 | Language language; 162 | Resolution resolution; 163 | Font font; 164 | Canvas canvas; 165 | Canvas webGL; 166 | Canvas gupGL; 167 | WebGLDevice webGLDevice; 168 | AudioContext audioContext; 169 | MediaEquipment mediaEquipment; 170 | ClientRects clientRects; 171 | SpeechVoices speechVoices; 172 | ResourceInfo resourceInfo; 173 | DoNotTrack doNotTrack; 174 | OpenPort openPort; 175 | }; -------------------------------------------------------------------------------- /third_party/blink/renderer/core/dom/element_fp.h: -------------------------------------------------------------------------------- 1 | #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_DOM_ELEMENT_FP_H_ 2 | #define THIRD_PARTY_BLINK_RENDERER_CORE_DOM_ELEMENT_FP_H_ 3 | 4 | 5 | #include 6 | #include 7 | #include "third_party/blink/renderer/core/dom/element.h" 8 | #include "third_party/blink/renderer/core/geometry/dom_rect_list.h" 9 | #include "third_party/blink/public/common/fingerprint/fingerprint.h" 10 | #include "base/singleton_fingerprint.h" 11 | #include "ui/gfx/geometry/rect_f.h" 12 | 13 | 14 | double fpfracPart(double number, double fp) { 15 | if(!(number>0)||!(fp>0)){ 16 | return number; 17 | } 18 | 19 | double intPart; 20 | double fracPart = modf(number, &intPart); 21 | if (fracPart == 0.0) { 22 | return number; 23 | } 24 | double t_fracPart = floor(fracPart*pow(10,7))/pow(10,7); 25 | if(fracPart==t_fracPart){ 26 | return number; 27 | } 28 | 29 | double c_Number = number * 10000; 30 | 31 | number = intPart + t_fracPart; 32 | 33 | c_Number = modf(c_Number, &intPart); 34 | 35 | fracPart = modf(fp*(c_Number+0.123456789123456), &intPart); 36 | 37 | return number+(fracPart/pow(10,8)); 38 | } 39 | 40 | bool isTransform(blink::Element* element){ 41 | //旋转多次和 旋转角度 后续需要追加 42 | blink::Element* t_ele = element; 43 | while (t_ele) { 44 | const blink::ComputedStyle* style = t_ele->GetComputedStyle(); 45 | if (style) { 46 | if (style->HasTransform()) { 47 | return true; 48 | } 49 | } 50 | t_ele = t_ele->parentElement(); 51 | } 52 | return false; 53 | } 54 | 55 | void fpDOMRect(blink::DOMRect* dOMRect,blink::fp::ClientRects clientRects){ 56 | dOMRect->setX(fpfracPart(dOMRect->x(), clientRects.x)); 57 | dOMRect->setY(fpfracPart(dOMRect->y(), clientRects.y)); 58 | dOMRect->setWidth(fpfracPart(dOMRect->width(), clientRects.width)); 59 | dOMRect->setHeight(fpfracPart(dOMRect->height(), clientRects.height)); 60 | } 61 | 62 | void fpGetClientRects(blink::DOMRectList* domRectList, blink::Element* element){ 63 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 64 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 65 | if(base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.clientRects.type > 1 && 66 | isTransform(element)){ 67 | for (unsigned i = 0; i < domRectList->length(); ++i) { 68 | fpDOMRect(domRectList->item(i),t_fingerprint.clientRects); 69 | } 70 | } 71 | } 72 | 73 | void fpGetBoundingClientRect(blink::DOMRect* dOMRect, blink::Element* element){ 74 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 75 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 76 | if(base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.clientRects.type > 1 && 77 | isTransform(element)){ 78 | fpDOMRect(dOMRect,t_fingerprint.clientRects); 79 | } 80 | 81 | } 82 | 83 | 84 | 85 | 86 | 87 | 88 | #endif // THIRD_PARTY_BLINK_RENDERER_CORE_DOM_ELEMENT_FP_H_ 89 | -------------------------------------------------------------------------------- /third_party/blink/renderer/core/frame/fp_js_screen.h: -------------------------------------------------------------------------------- 1 | #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_FP_JS_SCREEN_H_ 2 | #define THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_FP_JS_SCREEN_H_ 3 | 4 | #include "ui/gfx/geometry/rect.h" 5 | #include "third_party/blink/public/common/fingerprint/fingerprint.h" 6 | #include "base/singleton_fingerprint.h" 7 | 8 | void fpJsGetRect(gfx::Rect& window_rect){ 9 | 10 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 11 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 12 | if(base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.resolution.type>1){ 13 | window_rect.set_width(t_fingerprint.resolution.monitorWidth); 14 | window_rect.set_height(t_fingerprint.resolution.monitorHeight); 15 | } 16 | 17 | } 18 | 19 | #endif // THIRD_PARTY_BLINK_RENDERER_CORE_FRAME_FP_JS_SCREEN_H_ -------------------------------------------------------------------------------- /third_party/blink/renderer/core/frame/navigator.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2000 Harri Porten (porten@kde.org) 3 | * Copyright (c) 2000 Daniel Molkentin (molkentin@kde.org) 4 | * Copyright (c) 2000 Stefan Schimanski (schimmi@kde.org) 5 | * Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc. 6 | * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 7 | * 8 | * This library is free software; you can redistribute it and/or 9 | * modify it under the terms of the GNU Lesser General Public 10 | * License as published by the Free Software Foundation; either 11 | * version 2 of the License, or (at your option) any later version. 12 | * 13 | * This library is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | * Lesser General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU Lesser General Public 19 | * License along with this library; if not, write to the Free Software 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 21 | * MA 02110-1301, USA 22 | */ 23 | 24 | #include "third_party/blink/renderer/core/frame/navigator.h" 25 | 26 | #include "third_party/blink/public/common/user_agent/user_agent_metadata.h" 27 | #include "third_party/blink/renderer/bindings/core/v8/script_controller.h" 28 | #include "third_party/blink/renderer/core/dom/document.h" 29 | #include "third_party/blink/renderer/core/execution_context/navigator_base.h" 30 | #include "third_party/blink/renderer/core/frame/local_dom_window.h" 31 | #include "third_party/blink/renderer/core/frame/local_frame.h" 32 | #include "third_party/blink/renderer/core/frame/settings.h" 33 | #include "third_party/blink/renderer/core/loader/frame_loader.h" 34 | #include "third_party/blink/renderer/core/page/chrome_client.h" 35 | #include "third_party/blink/renderer/core/page/page.h" 36 | #include "third_party/blink/renderer/core/probe/core_probes.h" 37 | #include "third_party/blink/renderer/platform/instrumentation/memory_pressure_listener.h" 38 | #include "third_party/blink/renderer/platform/language.h" 39 | 40 | namespace blink { 41 | 42 | Navigator::Navigator(ExecutionContext* context) : NavigatorBase(context) {} 43 | 44 | String Navigator::productSub() const { 45 | return "20030107"; 46 | } 47 | 48 | String Navigator::vendor() const { 49 | // Do not change without good cause. History: 50 | // https://code.google.com/p/chromium/issues/detail?id=276813 51 | // https://www.w3.org/Bugs/Public/show_bug.cgi?id=27786 52 | // https://groups.google.com/a/chromium.org/forum/#!topic/blink-dev/QrgyulnqvmE 53 | return "Google Inc."; 54 | } 55 | 56 | String Navigator::vendorSub() const { 57 | return ""; 58 | } 59 | 60 | String Navigator::platform() const { 61 | // TODO(955620): Consider changing devtools overrides to only allow overriding 62 | // the platform with a frozen platform to distinguish between 63 | // mobile and desktop when ReduceUserAgent is enabled. 64 | if (!DomWindow()) 65 | return NavigatorBase::platform(); 66 | const String& platform_override = 67 | DomWindow()->GetFrame()->GetSettings()->GetNavigatorPlatformOverride(); 68 | return platform_override.empty() ? NavigatorBase::platform() 69 | : platform_override; 70 | } 71 | 72 | bool Navigator::cookieEnabled() const { 73 | if (!DomWindow()) 74 | return false; 75 | 76 | Settings* settings = DomWindow()->GetFrame()->GetSettings(); 77 | if (!settings || !settings->GetCookieEnabled()) 78 | return false; 79 | 80 | return DomWindow()->document()->CookiesEnabled(); 81 | } 82 | 83 | bool Navigator::webdriver() const { 84 | // if (RuntimeEnabledFeatures::AutomationControlledEnabled()) 85 | // return true; 86 | 87 | // bool automation_enabled = false; 88 | // probe::ApplyAutomationOverride(GetExecutionContext(), automation_enabled); 89 | // return automation_enabled; 90 | return false; 91 | } 92 | 93 | String Navigator::GetAcceptLanguages() { 94 | if (!DomWindow()) 95 | return DefaultLanguage(); 96 | 97 | return DomWindow() 98 | ->GetFrame() 99 | ->GetPage() 100 | ->GetChromeClient() 101 | .AcceptLanguages(); 102 | } 103 | 104 | void Navigator::Trace(Visitor* visitor) const { 105 | NavigatorBase::Trace(visitor); 106 | Supplementable::Trace(visitor); 107 | } 108 | 109 | } // namespace blink 110 | -------------------------------------------------------------------------------- /third_party/blink/renderer/core/frame/navigator_concurrent_hardware.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Chromium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "third_party/blink/renderer/core/frame/navigator_concurrent_hardware.h" 6 | 7 | #include "base/system/sys_info.h" 8 | 9 | #include "third_party/blink/public/common/fingerprint/fingerprint.h" 10 | #include "base/singleton_fingerprint.h" 11 | 12 | namespace blink { 13 | 14 | unsigned NavigatorConcurrentHardware::hardwareConcurrency() const { 15 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 16 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 17 | if(base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.resourceInfo.type>1){ 18 | return static_cast(t_fingerprint.resourceInfo.cpu); 19 | } 20 | return static_cast(base::SysInfo::NumberOfProcessors()); 21 | } 22 | 23 | } // namespace blink 24 | -------------------------------------------------------------------------------- /third_party/blink/renderer/core/frame/navigator_device_memory.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Chromium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "third_party/blink/renderer/core/frame/navigator_device_memory.h" 6 | 7 | #include "third_party/blink/public/common/device_memory/approximated_device_memory.h" 8 | #include "third_party/blink/public/common/privacy_budget/identifiability_metric_builder.h" 9 | #include "third_party/blink/public/common/privacy_budget/identifiability_metrics.h" 10 | #include "third_party/blink/public/mojom/use_counter/metrics/web_feature.mojom-shared.h" 11 | #include "third_party/blink/renderer/core/dom/document.h" 12 | #include "third_party/blink/renderer/core/frame/local_dom_window.h" 13 | 14 | #include "third_party/blink/public/common/fingerprint/fingerprint.h" 15 | #include "base/singleton_fingerprint.h" 16 | 17 | namespace blink { 18 | 19 | float NavigatorDeviceMemory::deviceMemory() const { 20 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 21 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 22 | if(base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.resourceInfo.type>1){ 23 | return static_cast(t_fingerprint.resourceInfo.memory); 24 | } 25 | return ApproximatedDeviceMemory::GetApproximatedDeviceMemory(); 26 | } 27 | 28 | } // namespace blink 29 | -------------------------------------------------------------------------------- /third_party/blink/renderer/core/frame/screen.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 Apple Inc. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 14 | * its contributors may be used to endorse or promote products derived 15 | * from this software without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 18 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | */ 28 | 29 | #include "third_party/blink/renderer/core/frame/screen.h" 30 | 31 | #include "base/numerics/safe_conversions.h" 32 | #include "third_party/blink/public/mojom/permissions_policy/permissions_policy_feature.mojom-blink.h" 33 | #include "third_party/blink/renderer/core/event_target_names.h" 34 | #include "third_party/blink/renderer/core/frame/local_dom_window.h" 35 | #include "third_party/blink/renderer/core/frame/local_frame.h" 36 | #include "third_party/blink/renderer/core/frame/settings.h" 37 | #include "third_party/blink/renderer/core/page/chrome_client.h" 38 | #include "ui/display/screen_info.h" 39 | #include "ui/display/screen_infos.h" 40 | #include "third_party/blink/renderer/core/frame/fp_js_screen.h" 41 | 42 | namespace blink { 43 | 44 | namespace { 45 | 46 | } // namespace 47 | 48 | Screen::Screen(LocalDOMWindow* window, 49 | int64_t display_id, 50 | bool use_size_override) 51 | : ExecutionContextClient(window), 52 | display_id_(display_id), 53 | use_size_override_(use_size_override) {} 54 | 55 | // static 56 | bool Screen::AreWebExposedScreenPropertiesEqual( 57 | const display::ScreenInfo& prev, 58 | const display::ScreenInfo& current, 59 | bool use_size_override) { 60 | // height() and width() use rect.size() or size_override 61 | gfx::Size prev_size = prev.rect.size(); 62 | if (prev.size_override && use_size_override) 63 | prev_size = *prev.size_override; 64 | gfx::Size current_size = current.rect.size(); 65 | if (current.size_override && use_size_override) 66 | current_size = *current.size_override; 67 | if (prev_size != current_size) 68 | return false; 69 | 70 | // height() and width() use device_scale_factor 71 | // Note: comparing device_scale_factor is a bit of a lie as Screen only uses 72 | // this with the PhysicalPixelsQuirk (see width() / height() below). However, 73 | // this value likely changes rarely and should not throw many false positives. 74 | if (prev.device_scale_factor != current.device_scale_factor) 75 | return false; 76 | 77 | // availLeft() and availTop() use available_rect.origin() 78 | if (prev.available_rect.origin() != current.available_rect.origin()) 79 | return false; 80 | 81 | // availHeight() and availWidth() use available_rect.size() or size_override 82 | gfx::Size prev_avail_size = prev.available_rect.size(); 83 | if (prev.size_override && use_size_override) 84 | prev_avail_size = *prev.size_override; 85 | gfx::Size current_avail_size = current.available_rect.size(); 86 | if (current.size_override && use_size_override) 87 | current_avail_size = *current.size_override; 88 | if (prev_avail_size != current_avail_size) 89 | return false; 90 | 91 | // colorDepth() and pixelDepth() use depth 92 | if (prev.depth != current.depth) 93 | return false; 94 | 95 | // isExtended() 96 | if (prev.is_extended != current.is_extended) 97 | return false; 98 | 99 | if (RuntimeEnabledFeatures::CanvasHDREnabled()) { 100 | // (red|green|blue)Primary(X|Y) and whitePoint(X|Y). 101 | const auto& prev_dcs = prev.display_color_spaces; 102 | const auto& current_dcs = current.display_color_spaces; 103 | if (prev_dcs.GetPrimaries() != current_dcs.GetPrimaries()) 104 | return false; 105 | 106 | // highDynamicRangeHeadroom. 107 | if (prev_dcs.GetHDRMaxLuminanceRelative() != 108 | current_dcs.GetHDRMaxLuminanceRelative()) { 109 | return false; 110 | } 111 | } 112 | 113 | return true; 114 | } 115 | 116 | int Screen::height() const { 117 | if (!DomWindow()) 118 | return 0; 119 | return GetRect(/*available=*/false).height(); 120 | } 121 | 122 | int Screen::width() const { 123 | if (!DomWindow()) 124 | return 0; 125 | return GetRect(/*available=*/false).width(); 126 | } 127 | 128 | unsigned Screen::colorDepth() const { 129 | if (!DomWindow()) 130 | return 0; 131 | return base::saturated_cast(GetScreenInfo().depth); 132 | } 133 | 134 | unsigned Screen::pixelDepth() const { 135 | return colorDepth(); 136 | } 137 | 138 | int Screen::availLeft() const { 139 | if (!DomWindow()) 140 | return 0; 141 | return GetRect(/*available=*/true).x(); 142 | } 143 | 144 | int Screen::availTop() const { 145 | if (!DomWindow()) 146 | return 0; 147 | return GetRect(/*available=*/true).y(); 148 | } 149 | 150 | int Screen::availHeight() const { 151 | if (!DomWindow()) 152 | return 0; 153 | return GetRect(/*available=*/true).height(); 154 | } 155 | 156 | int Screen::availWidth() const { 157 | if (!DomWindow()) 158 | return 0; 159 | return GetRect(/*available=*/true).width(); 160 | } 161 | 162 | void Screen::Trace(Visitor* visitor) const { 163 | EventTargetWithInlineData::Trace(visitor); 164 | ExecutionContextClient::Trace(visitor); 165 | Supplementable::Trace(visitor); 166 | } 167 | 168 | const WTF::AtomicString& Screen::InterfaceName() const { 169 | return event_target_names::kScreen; 170 | } 171 | 172 | ExecutionContext* Screen::GetExecutionContext() const { 173 | return ExecutionContextClient::GetExecutionContext(); 174 | } 175 | 176 | bool Screen::isExtended() const { 177 | if (!DomWindow()) 178 | return false; 179 | auto* context = GetExecutionContext(); 180 | if (!context->IsFeatureEnabled( 181 | mojom::blink::PermissionsPolicyFeature::kWindowManagement)) { 182 | return false; 183 | } 184 | 185 | return GetScreenInfo().is_extended; 186 | } 187 | 188 | gfx::Rect Screen::GetRect(bool available) const { 189 | if (!DomWindow()) 190 | return gfx::Rect(); 191 | LocalFrame* frame = DomWindow()->GetFrame(); 192 | const display::ScreenInfo& screen_info = GetScreenInfo(); 193 | gfx::Rect rect = available ? screen_info.available_rect : screen_info.rect; 194 | if (screen_info.size_override && use_size_override_) 195 | rect.set_size(*screen_info.size_override); 196 | if (frame->GetSettings()->GetReportScreenSizeInPhysicalPixelsQuirk()) 197 | return gfx::ScaleToRoundedRect(rect, screen_info.device_scale_factor); 198 | fpJsGetRect(rect); 199 | return rect; 200 | } 201 | 202 | const display::ScreenInfo& Screen::GetScreenInfo() const { 203 | DCHECK(DomWindow()); 204 | LocalFrame* frame = DomWindow()->GetFrame(); 205 | 206 | const auto& screen_infos = frame->GetChromeClient().GetScreenInfos(*frame); 207 | for (const auto& screen : screen_infos.screen_infos) { 208 | if (screen.display_id == display_id_) 209 | return screen; 210 | } 211 | DEFINE_STATIC_LOCAL(display::ScreenInfo, kEmptyScreenInfo, ()); 212 | return kEmptyScreenInfo; 213 | } 214 | 215 | } // namespace blink 216 | -------------------------------------------------------------------------------- /third_party/blink/renderer/core/html/canvas/fp_textMetrics.h: -------------------------------------------------------------------------------- 1 | #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_HTML_CANVAS_FP_TEXTMETRICS_H_ 2 | #define THIRD_PARTY_BLINK_RENDERER_CORE_HTML_CANVAS_FP_TEXTMETRICS_H_ 3 | 4 | 5 | 6 | #include "ui/gfx/geometry/rect.h" 7 | #include "third_party/blink/renderer/platform/fonts/font.h" 8 | #include "third_party/blink/renderer/platform/fonts/font_family.h" 9 | #include "base/singleton_fingerprint.h" 10 | //#include "third_party/blink/renderer/core/html/canvas/text_metrics.h" 11 | 12 | namespace blink { 13 | 14 | namespace fp { 15 | 16 | struct FpTextMetrics { 17 | double actual_bounding_box_left_; 18 | double actual_bounding_box_right_; 19 | double font_bounding_box_ascent_; 20 | double font_bounding_box_descent_; 21 | double actual_bounding_box_ascent_; 22 | double actual_bounding_box_descent_; 23 | 24 | }; 25 | 26 | } 27 | } 28 | 29 | bool fpTextMetricsCypher(blink::fp::FpTextMetrics& textMetric, const blink::Font& font, gfx::RectF& glyph_bounds, float dx, 30 | float ascent, float descent, float baseline_y){ 31 | 32 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 33 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 34 | if(base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.font.type > 1){ 35 | base::flat_map fontMap = t_fingerprint.font.fontMap; 36 | const blink::FontFamily& fontFamily = font.GetFontDescription().FirstFamily(); 37 | std::string fontName = fontFamily.FamilyName().Utf8(); 38 | auto iter = fontMap.find(fontName); 39 | if (iter != fontMap.end()) { 40 | blink::fp::FontInfo fontInfo = iter->second; 41 | if (fontInfo.id>0) { 42 | glyph_bounds.set_x(glyph_bounds.x() * fontInfo.width); 43 | glyph_bounds.set_y(glyph_bounds.y() * fontInfo.height); 44 | glyph_bounds.set_height(glyph_bounds.height() * fontInfo.height); 45 | glyph_bounds.set_width(glyph_bounds.width() * fontInfo.width); 46 | 47 | dx = dx * fontInfo.width; 48 | 49 | textMetric.actual_bounding_box_left_ = -glyph_bounds.x() + dx+fontInfo.actualBoundingBoxLeft; 50 | textMetric.actual_bounding_box_right_ = glyph_bounds.right() - dx+fontInfo.actualBoundingBoxRight; 51 | 52 | ascent = ascent * fontInfo.height; 53 | 54 | textMetric.font_bounding_box_ascent_ = static_cast(ascent - baseline_y+fontInfo.fontBoundingBoxAscent); 55 | textMetric.font_bounding_box_descent_ = static_cast(descent + baseline_y+fontInfo.fontBoundingBoxDescent); 56 | textMetric.actual_bounding_box_ascent_ = static_cast(-glyph_bounds.y() - baseline_y+fontInfo.actualBoundingBoxAscent); 57 | textMetric.actual_bounding_box_descent_ = static_cast(glyph_bounds.bottom() + baseline_y+fontInfo.actualBoundingBoxDescent); 58 | 59 | return true; 60 | } 61 | } 62 | } 63 | return false; 64 | } 65 | 66 | 67 | 68 | 69 | #endif // THIRD_PARTY_BLINK_RENDERER_CORE_HTML_CANVAS_FP_TEXTMETRICS_H_ -------------------------------------------------------------------------------- /third_party/blink/renderer/core/html/canvas/html_canvas_element_fp.cc: -------------------------------------------------------------------------------- 1 | #include "third_party/blink/renderer/core/html/canvas/html_canvas_element_fp.h" 2 | 3 | #include "base/singleton_fingerprint.h" 4 | #include "third_party/blink/public/common/fingerprint/fingerprint.h" 5 | 6 | #include "base/memory/scoped_refptr.h" 7 | #include "third_party/skia/include/core/SkImageInfo.h" 8 | #include "third_party/blink/renderer/platform/graphics/image_data_buffer.h" 9 | #include "third_party/blink/renderer/platform/graphics/static_bitmap_image.h" 10 | #include "third_party/blink/renderer/core/html/canvas/canvas_rendering_context.h" 11 | 12 | namespace blink { 13 | 14 | 15 | 16 | 17 | void CanvasFpIng::fpPixel(unsigned char* mutablePixels,std::vector list,int bytesPerPixel,int width,int height) { 18 | 19 | int start=list[0].row; 20 | int end = start; 21 | for (std::size_t i = 0; i < list.size(); ++i) { 22 | blink::fp::ColoredPoint coloredPoint = list[0]; 23 | 24 | int zend = coloredPoint.row%height; 25 | if(zend>start&&zend>=end){ 26 | end=zend; 27 | }else if(zendend){ 28 | end=zend; 29 | }else if(zendend){ 30 | end=zend; 31 | } 32 | 33 | int index =coloredPoint.column%width; 34 | int cloumnStart=0; 35 | int cloumnEnd=width; 36 | int cloumnStep=1; 37 | 38 | if(index<0){ 39 | cloumnStart=width; 40 | cloumnEnd=0; 41 | cloumnStep=-1; 42 | index=-index; 43 | } 44 | 45 | int exist=-1; 46 | int endExist=-1; 47 | while(true){ 48 | 49 | 50 | while (cloumnStart!=cloumnEnd) 51 | { 52 | 53 | std::size_t pixelIndex= end * width* bytesPerPixel + cloumnStart* bytesPerPixel; 54 | for(int j=0;j0){ 56 | exist++; 57 | endExist=cloumnStart; 58 | break; 59 | } 60 | } 61 | if(index==exist){ 62 | break; 63 | } 64 | cloumnStart=cloumnStart+cloumnStep; 65 | } 66 | 67 | if(endExist!=-1){ 68 | break; 69 | } 70 | 71 | end=(end+1)%height; 72 | if (coloredPoint.column<0) { 73 | cloumnStart = width; 74 | } else { 75 | cloumnStart = 0; 76 | } 77 | if(start==end){ 78 | return; 79 | } 80 | 81 | } 82 | 83 | std::vector rgba = {coloredPoint.red,coloredPoint.green,coloredPoint.blue,coloredPoint.alpha}; 84 | 85 | for (int j = 0; j < bytesPerPixel; j++) 86 | { 87 | std::size_t pixelIndex= end * width* bytesPerPixel + cloumnStart * bytesPerPixel; 88 | int pixel=mutablePixels[pixelIndex+j]+rgba[j]; 89 | if(pixel>255||pixel<0){ 90 | pixel=mutablePixels[pixelIndex+j]-rgba[j]; 91 | } 92 | mutablePixels[pixelIndex+j]= static_cast(pixel); 93 | } 94 | 95 | end=(end+1)%height; 96 | if(start==end){ 97 | return; 98 | } 99 | } 100 | 101 | 102 | 103 | } 104 | 105 | 106 | void CanvasFpIng::fpToDataURLInternal(blink::ImageDataBuffer* data_buffer, blink::CanvasRenderingContext* canvasRenderingContext, 107 | SkImageInfo skImageInfo,blink::ImageEncodingMimeType encoding_mime_type, 108 | bool isCanvas, bool isWebGL, bool isGpuGL) { 109 | 110 | if (canvasRenderingContext==nullptr) { 111 | return; 112 | } 113 | if(encoding_mime_type != blink::ImageEncodingMimeType::kMimeTypePng ||!canvasRenderingContext->getFpCanvas()){ 114 | return; 115 | } 116 | if(!isCanvas&&!isWebGL&&!isGpuGL){ 117 | return; 118 | } 119 | int width = skImageInfo.width(); 120 | int height = skImageInfo.height(); 121 | if(width<11||height<11){ 122 | return; 123 | } 124 | 125 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 126 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 127 | if (base::SingletonFingerprint::GetInit(t_singletonFingerprint)) { 128 | 129 | std::vector coloredPointList; 130 | 131 | if(isCanvas&&t_fingerprint.canvas.type > 1){ 132 | coloredPointList=t_fingerprint.canvas.coloredPointList; 133 | }else if(isWebGL&&t_fingerprint.webGL.type > 1){ 134 | coloredPointList=t_fingerprint.webGL.coloredPointList; 135 | }else if(isGpuGL&&t_fingerprint.gupGL.type > 1){ 136 | coloredPointList=t_fingerprint.gupGL.coloredPointList; 137 | }else{ 138 | return; 139 | } 140 | 141 | const unsigned char* pixels = data_buffer->Pixels(); 142 | unsigned char* mutablePixels = const_cast(pixels); 143 | int bytesPerPixel = skImageInfo.bytesPerPixel(); 144 | 145 | fpPixel(mutablePixels,coloredPointList,bytesPerPixel,width,height); 146 | 147 | } 148 | 149 | } 150 | 151 | 152 | scoped_refptr CanvasFpIng::fpToBlob(scoped_refptr image_bitmap, blink::CanvasRenderingContext* canvasRenderingContext, 153 | blink::ImageEncodingMimeType encoding_mime_type, bool isCanvas, bool isWebGL, bool isGpuGL) { 154 | 155 | if(encoding_mime_type != blink::ImageEncodingMimeType::kMimeTypePng || !canvasRenderingContext->getFpCanvas()){ 156 | return image_bitmap; 157 | } 158 | if(!isCanvas&&!isWebGL&&!isGpuGL){ 159 | return image_bitmap; 160 | } 161 | SkImageInfo skImageInfo =image_bitmap->GetSkImageInfo(); 162 | int width = skImageInfo.width(); 163 | int height = skImageInfo.height(); 164 | if(width<11||height<11){ 165 | return image_bitmap; 166 | } 167 | 168 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 169 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 170 | if (base::SingletonFingerprint::GetInit(t_singletonFingerprint)) { 171 | 172 | std::vector coloredPointList; 173 | 174 | if(isCanvas&&t_fingerprint.canvas.type > 1){ 175 | coloredPointList=t_fingerprint.canvas.coloredPointList; 176 | }else if(isWebGL&&t_fingerprint.webGL.type > 1){ 177 | coloredPointList=t_fingerprint.webGL.coloredPointList; 178 | }else if(isGpuGL&&t_fingerprint.gupGL.type > 1){ 179 | coloredPointList=t_fingerprint.gupGL.coloredPointList; 180 | }else{ 181 | return image_bitmap; 182 | } 183 | std::vector* FpToBlob = canvasRenderingContext->getFpToBlob(); 184 | Vector list= image_bitmap->CopyImageData(skImageInfo,true); 185 | FpToBlob->clear(); 186 | FpToBlob->insert(FpToBlob->end(), list.begin(), list.end()); 187 | unsigned char* mutablePixels = FpToBlob->data(); 188 | int bytesPerPixel = skImageInfo.bytesPerPixel(); 189 | 190 | fpPixel(mutablePixels,coloredPointList,bytesPerPixel,width,height); 191 | sk_sp skiaData = SkData::MakeWithoutCopy(FpToBlob->data(), FpToBlob->size()); 192 | return blink::StaticBitmapImage::Create(std::move(skiaData), skImageInfo); 193 | 194 | } 195 | 196 | 197 | return image_bitmap; 198 | 199 | } 200 | 201 | } // namespace blink 202 | 203 | -------------------------------------------------------------------------------- /third_party/blink/renderer/core/html/canvas/html_canvas_element_fp.h: -------------------------------------------------------------------------------- 1 | #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_HTML_CANVAS_HTML_CANVAS_ELEMENT_FP_H_ 2 | #define THIRD_PARTY_BLINK_RENDERER_CORE_HTML_CANVAS_HTML_CANVAS_ELEMENT_FP_H_ 3 | 4 | 5 | #include "third_party/blink/public/platform/web_common.h" 6 | #include "third_party/blink/renderer/core/html/canvas/canvas_rendering_context.h" 7 | #include "third_party/blink/public/common/fingerprint/fingerprint.h" 8 | #include "third_party/blink/renderer/platform/graphics/image_data_buffer.h" 9 | 10 | 11 | 12 | namespace blink{ 13 | 14 | class BLINK_EXPORT CanvasFpIng{ 15 | public: 16 | static void fpPixel(unsigned char* mutablePixels, std::vector list, int bytesPerPixel, int width, int height); 17 | static void fpToDataURLInternal(ImageDataBuffer* data_buffer, CanvasRenderingContext* canvasRenderingContext, SkImageInfo skImageInfo, ImageEncodingMimeType encoding_mime_type, bool isCanvas, bool isWebGL, bool isGpuGL); 18 | static scoped_refptr fpToBlob(scoped_refptr image_bitmap, CanvasRenderingContext* canvasRenderingContext, ImageEncodingMimeType encoding_mime_type, bool isCanvas, bool isWebGL, bool isGpuGL); 19 | }; 20 | } // namespace blink 21 | 22 | #endif // THIRD_PARTY_BLINK_RENDERER_CORE_HTML_CANVAS_HTML_CANVAS_ELEMENT_FP_H_ 23 | -------------------------------------------------------------------------------- /third_party/blink/renderer/core/html/canvas/text_metrics.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Chromium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "third_party/blink/renderer/core/html/canvas/text_metrics.h" 6 | #include "third_party/blink/renderer/bindings/core/v8/v8_baselines.h" 7 | #include "third_party/blink/renderer/core/layout/ng/inline/ng_bidi_paragraph.h" 8 | #include "third_party/blink/renderer/platform/fonts/character_range.h" 9 | 10 | #include "third_party/blink/renderer/core/html/canvas/fp_textMetrics.h" 11 | 12 | namespace blink { 13 | 14 | constexpr int kHangingAsPercentOfAscent = 80; 15 | 16 | float TextMetrics::GetFontBaseline(const TextBaseline& text_baseline, 17 | const SimpleFontData& font_data) { 18 | FontMetrics font_metrics = font_data.GetFontMetrics(); 19 | switch (text_baseline) { 20 | case kTopTextBaseline: 21 | return font_data.NormalizedTypoAscent().ToFloat(); 22 | case kHangingTextBaseline: 23 | // According to 24 | // http://wiki.apache.org/xmlgraphics-fop/LineLayout/AlignmentHandling 25 | // "FOP (Formatting Objects Processor) puts the hanging baseline at 80% of 26 | // the ascender height" 27 | return font_metrics.FloatAscent() * kHangingAsPercentOfAscent / 100.0; 28 | case kIdeographicTextBaseline: 29 | return -font_metrics.FloatDescent(); 30 | case kBottomTextBaseline: 31 | return -font_data.NormalizedTypoDescent().ToFloat(); 32 | case kMiddleTextBaseline: { 33 | const FontHeight metrics = font_data.NormalizedTypoAscentAndDescent(); 34 | return (metrics.ascent.ToFloat() - metrics.descent.ToFloat()) / 2.0f; 35 | } 36 | case kAlphabeticTextBaseline: 37 | default: 38 | // Do nothing. 39 | break; 40 | } 41 | return 0; 42 | } 43 | 44 | void TextMetrics::Trace(Visitor* visitor) const { 45 | visitor->Trace(baselines_); 46 | ScriptWrappable::Trace(visitor); 47 | } 48 | 49 | TextMetrics::TextMetrics() : baselines_(Baselines::Create()) {} 50 | 51 | TextMetrics::TextMetrics(const Font& font, 52 | const TextDirection& direction, 53 | const TextBaseline& baseline, 54 | const TextAlign& align, 55 | const String& text) 56 | : TextMetrics() { 57 | Update(font, direction, baseline, align, text); 58 | } 59 | 60 | void TextMetrics::Update(const Font& font, 61 | const TextDirection& direction, 62 | const TextBaseline& baseline, 63 | const TextAlign& align, 64 | const String& text) { 65 | const SimpleFontData* font_data = font.PrimaryFont(); 66 | if (!font_data) 67 | return; 68 | 69 | { 70 | // TODO(kojii): Need to figure out the desired behavior of |advances| when 71 | // bidi reorder occurs. 72 | TextRun text_run( 73 | text, /* xpos */ 0, /* expansion */ 0, 74 | TextRun::kAllowTrailingExpansion | TextRun::kForbidLeadingExpansion, 75 | direction, false); 76 | text_run.SetNormalizeSpace(true); 77 | advances_ = font.IndividualCharacterAdvances(text_run); 78 | } 79 | 80 | // x direction 81 | // Run bidi algorithm on the given text. Step 5 of: 82 | // https://html.spec.whatwg.org/multipage/canvas.html#text-preparation-algorithm 83 | gfx::RectF glyph_bounds; 84 | String text16 = text; 85 | text16.Ensure16Bit(); 86 | NGBidiParagraph bidi; 87 | bidi.SetParagraph(text16, direction); 88 | NGBidiParagraph::Runs runs; 89 | bidi.GetLogicalRuns(text16, &runs); 90 | float xpos = 0; 91 | for (const auto& run : runs) { 92 | // Measure each run. 93 | TextRun text_run( 94 | StringView(text, run.start, run.Length()), xpos, /* expansion */ 0, 95 | TextRun::kAllowTrailingExpansion | TextRun::kForbidLeadingExpansion, 96 | run.Direction(), /* directional_override */ false); 97 | text_run.SetNormalizeSpace(true); 98 | gfx::RectF run_glyph_bounds; 99 | float run_width = font.Width(text_run, &run_glyph_bounds); 100 | 101 | // Accumulate the position and the glyph bounding box. 102 | run_glyph_bounds.Offset(xpos, 0); 103 | glyph_bounds.Union(run_glyph_bounds); 104 | xpos += run_width; 105 | } 106 | double real_width = xpos; 107 | width_ = real_width; 108 | 109 | float dx = 0.0f; 110 | if (align == kCenterTextAlign) 111 | dx = real_width / 2.0f; 112 | else if (align == kRightTextAlign || 113 | (align == kStartTextAlign && direction == TextDirection::kRtl) || 114 | (align == kEndTextAlign && direction != TextDirection::kRtl)) 115 | dx = real_width; 116 | actual_bounding_box_left_ = -glyph_bounds.x() + dx; 117 | actual_bounding_box_right_ = glyph_bounds.right() - dx; 118 | 119 | // y direction 120 | const FontMetrics& font_metrics = font_data->GetFontMetrics(); 121 | const float ascent = font_metrics.FloatAscent(); 122 | const float descent = font_metrics.FloatDescent(); 123 | const float baseline_y = GetFontBaseline(baseline, *font_data); 124 | font_bounding_box_ascent_ = ascent - baseline_y; 125 | font_bounding_box_descent_ = descent + baseline_y; 126 | actual_bounding_box_ascent_ = -glyph_bounds.y() - baseline_y; 127 | actual_bounding_box_descent_ = glyph_bounds.bottom() + baseline_y; 128 | 129 | blink::fp::FpTextMetrics fpTextMetrics; 130 | if (fpTextMetricsCypher(fpTextMetrics,font,glyph_bounds,dx,ascent,descent,baseline_y)) { 131 | actual_bounding_box_left_ = fpTextMetrics.actual_bounding_box_left_; 132 | actual_bounding_box_right_ = fpTextMetrics.actual_bounding_box_right_; 133 | font_bounding_box_ascent_ = fpTextMetrics.font_bounding_box_ascent_; 134 | font_bounding_box_descent_ = fpTextMetrics.font_bounding_box_descent_; 135 | actual_bounding_box_ascent_ = fpTextMetrics.actual_bounding_box_ascent_; 136 | actual_bounding_box_descent_ = fpTextMetrics.actual_bounding_box_descent_; 137 | 138 | } 139 | // TODO(kojii): We use normalized sTypoAscent/Descent here, but this should be 140 | // revisited when the spec evolves. 141 | const FontHeight normalized_typo_metrics = 142 | font_data->NormalizedTypoAscentAndDescent(); 143 | em_height_ascent_ = normalized_typo_metrics.ascent - baseline_y; 144 | em_height_descent_ = normalized_typo_metrics.descent + baseline_y; 145 | 146 | // TODO(fserb): hanging/ideographic baselines are broken. 147 | baselines_->setAlphabetic(-baseline_y); 148 | baselines_->setHanging(ascent * kHangingAsPercentOfAscent / 100.0f - 149 | baseline_y); 150 | baselines_->setIdeographic(-descent - baseline_y); 151 | } 152 | 153 | } // namespace blink 154 | -------------------------------------------------------------------------------- /third_party/blink/renderer/core/html/fp_elecment_offset.h: -------------------------------------------------------------------------------- 1 | #ifndef THIRD_PARTY_BLINK_RENDERER_CORE_HTML_FP_ELECMENT_OFFSET_H_ 2 | #define THIRD_PARTY_BLINK_RENDERER_CORE_HTML_FP_ELECMENT_OFFSET_H_ 3 | 4 | 5 | #include "third_party/blink/renderer/platform/fonts/font_family.h" 6 | #include "third_party/blink/renderer/core/layout/layout_box_model_object.h" 7 | #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" 8 | #include "third_party/blink/public/common/fingerprint/fingerprint.h" 9 | #include "base/singleton_fingerprint.h" 10 | 11 | 12 | int fpOffsetWidth(const blink::LayoutBoxModelObject* layout_object, String tagName,int result){ 13 | if(!tagName.EndsWithIgnoringCase("span")){ 14 | return result; 15 | } 16 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 17 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 18 | if(base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.font.type > 1){ 19 | base::flat_map fontMap = t_fingerprint.font.fontMap; 20 | const blink::FontFamily& fontFamily = layout_object->Style()->GetFont().GetFontDescription().FirstFamily(); 21 | std::string fontName = fontFamily.FamilyName().Utf8(); 22 | std::transform(fontName.begin(), fontName.end(), fontName.begin(), ::tolower); 23 | auto iter = fontMap.find(fontName); 24 | if (iter != fontMap.end()) { 25 | blink::fp::FontInfo fontInfo = iter->second; 26 | if (fontInfo.id>0) { 27 | return static_cast(result * fontInfo.width); 28 | } 29 | } 30 | } 31 | 32 | 33 | return result; 34 | } 35 | 36 | int fpOffsetHeight(const blink::LayoutBoxModelObject* layout_object, String tagName,int result){ 37 | 38 | if (!tagName.EndsWithIgnoringCase("span")) { 39 | return result; 40 | } 41 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 42 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 43 | if (base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.font.type > 1) { 44 | base::flat_map fontMap = t_fingerprint.font.fontMap; 45 | const blink::FontFamily& fontFamily = layout_object->Style()->GetFont().GetFontDescription().FirstFamily(); 46 | std::string fontName = fontFamily.FamilyName().Utf8(); 47 | std::transform(fontName.begin(), fontName.end(), fontName.begin(), ::tolower); 48 | auto iter = fontMap.find(fontName); 49 | if (iter != fontMap.end()) { 50 | blink::fp::FontInfo fontInfo = iter->second; 51 | if (fontInfo.id > 0) { 52 | return static_cast(result * fontInfo.height); 53 | } 54 | } 55 | } 56 | 57 | 58 | return result; 59 | } 60 | 61 | #endif // THIRD_PARTY_BLINK_RENDERER_CORE_HTML_FP_ELECMENT_OFFSET_H_ -------------------------------------------------------------------------------- /third_party/blink/renderer/modules/canvas/BUILD.gn: -------------------------------------------------------------------------------- 1 | # Copyright 2016 The Chromium Authors 2 | # Use of this source code is governed by a BSD-style license that can be 3 | # found in the LICENSE file. 4 | 5 | import("//testing/libfuzzer/fuzzer_test.gni") 6 | import("//third_party/blink/renderer/modules/modules.gni") 7 | 8 | blink_modules_sources("canvas") { 9 | sources = [ 10 | "canvas2d/base_rendering_context_2d.cc", 11 | "canvas2d/base_rendering_context_2d.h", 12 | "canvas2d/canvas_color_cache.cc", 13 | "canvas2d/canvas_color_cache.h", 14 | "canvas2d/canvas_filter.cc", 15 | "canvas2d/canvas_filter.h", 16 | "canvas2d/canvas_filter_operation_resolver.cc", 17 | "canvas2d/canvas_filter_operation_resolver.h", 18 | "canvas2d/canvas_gradient.cc", 19 | "canvas2d/canvas_gradient.h", 20 | "canvas2d/canvas_image_source_util.cc", 21 | "canvas2d/canvas_image_source_util.h", 22 | "canvas2d/canvas_path.cc", 23 | "canvas2d/canvas_path.h", 24 | "canvas2d/canvas_pattern.cc", 25 | "canvas2d/canvas_pattern.h", 26 | "canvas2d/canvas_rendering_context_2d.cc", 27 | "canvas2d/canvas_rendering_context_2d.h", 28 | "canvas2d/canvas_rendering_context_2d_state.cc", 29 | "canvas2d/canvas_rendering_context_2d_state.h", 30 | "canvas2d/canvas_style.cc", 31 | "canvas2d/canvas_style.h", 32 | "canvas2d/clip_list.cc", 33 | "canvas2d/clip_list.h", 34 | "canvas2d/identifiability_study_helper.cc", 35 | "canvas2d/identifiability_study_helper.h", 36 | "canvas2d/path_2d.cc", 37 | "canvas2d/path_2d.h", 38 | "canvas2d/v8_canvas_style.cc", 39 | "canvas2d/v8_canvas_style.h", 40 | "htmlcanvas/canvas_context_creation_attributes_helpers.cc", 41 | "htmlcanvas/canvas_context_creation_attributes_helpers.h", 42 | "htmlcanvas/html_canvas_element_module.cc", 43 | "htmlcanvas/html_canvas_element_module.h", 44 | "imagebitmap/image_bitmap_factories.cc", 45 | "imagebitmap/image_bitmap_factories.h", 46 | "imagebitmap/image_bitmap_rendering_context.cc", 47 | "imagebitmap/image_bitmap_rendering_context.h", 48 | "imagebitmap/image_bitmap_rendering_context_base.cc", 49 | "imagebitmap/image_bitmap_rendering_context_base.h", 50 | "offscreencanvas/offscreen_canvas_module.cc", 51 | "offscreencanvas/offscreen_canvas_module.h", 52 | "offscreencanvas2d/offscreen_canvas_rendering_context_2d.cc", 53 | "offscreencanvas2d/offscreen_canvas_rendering_context_2d.h", 54 | "testing/canvas_test_utils.cc", 55 | "canvas2d/canvas_rendering_context_2d_fp.h", 56 | "canvas2d/canvas_rendering_context_2d_fp.cc", 57 | ] 58 | 59 | deps = [ 60 | "//third_party/blink/renderer/modules/formatted_text", 61 | "//third_party/blink/renderer/modules/webcodecs", 62 | ] 63 | allow_circular_includes_from = 64 | [ "//third_party/blink/renderer/modules/webcodecs" ] 65 | } 66 | 67 | fuzzer_test("canvas_fuzzer") { 68 | sources = [ "canvas_fuzzer.cc" ] 69 | seed_corpuses = [ "//third_party/blink/web_tests/fast/canvas" ] 70 | deps = [ 71 | "../../platform:blink_fuzzer_test_support", 72 | "//base/test:test_support", 73 | "//third_party/blink/renderer/core", 74 | "//third_party/blink/renderer/core:testing", 75 | "//third_party/blink/renderer/platform:test_support", 76 | ] 77 | 78 | # Disabled due to many false positives (crbug.com/1124824). 79 | additional_configs = [ "//testing/libfuzzer:no_clusterfuzz" ] 80 | } 81 | -------------------------------------------------------------------------------- /third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2006, 2007, 2009, 2010, 2011, 2012 Apple Inc. All rights 3 | * reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 15 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 18 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 22 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | */ 26 | 27 | #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_CANVAS_CANVAS2D_CANVAS_RENDERING_CONTEXT_2D_H_ 28 | #define THIRD_PARTY_BLINK_RENDERER_MODULES_CANVAS_CANVAS2D_CANVAS_RENDERING_CONTEXT_2D_H_ 29 | 30 | #include "third_party/blink/renderer/bindings/modules/v8/v8_canvas_rendering_context_2d_settings.h" 31 | #include "third_party/blink/renderer/core/html/canvas/canvas_context_creation_attributes_core.h" 32 | #include "third_party/blink/renderer/core/html/canvas/canvas_rendering_context.h" 33 | #include "third_party/blink/renderer/core/html/canvas/canvas_rendering_context_factory.h" 34 | #include "third_party/blink/renderer/core/html/canvas/html_canvas_element.h" 35 | #include "third_party/blink/renderer/core/html/canvas/image_data.h" 36 | #include "third_party/blink/renderer/core/style/filter_operations.h" 37 | #include "third_party/blink/renderer/core/svg/svg_resource_client.h" 38 | #include "third_party/blink/renderer/modules/canvas/canvas2d/base_rendering_context_2d.h" 39 | #include "third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d_state.h" 40 | #include "third_party/blink/renderer/modules/canvas/canvas2d/identifiability_study_helper.h" 41 | #include "third_party/blink/renderer/modules/modules_export.h" 42 | #include "third_party/blink/renderer/platform/bindings/exception_state.h" 43 | #include "third_party/blink/renderer/platform/bindings/script_wrappable.h" 44 | #include "third_party/blink/renderer/platform/graphics/graphics_types.h" 45 | #include "third_party/blink/renderer/platform/heap/garbage_collected.h" 46 | #include "third_party/blink/renderer/platform/privacy_budget/identifiability_digest_helpers.h" 47 | #include "third_party/blink/renderer/platform/scheduler/public/thread.h" 48 | #include "third_party/blink/renderer/platform/wtf/linked_hash_set.h" 49 | #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" 50 | 51 | namespace cc { 52 | class Layer; 53 | } 54 | 55 | namespace blink { 56 | 57 | class FormattedText; 58 | class CanvasImageSource; 59 | class Element; 60 | class ExceptionState; 61 | class Font; 62 | class Path2D; 63 | class TextMetrics; 64 | 65 | class MODULES_EXPORT CanvasRenderingContext2D final 66 | : public CanvasRenderingContext, 67 | public BaseRenderingContext2D, 68 | public SVGResourceClient { 69 | DEFINE_WRAPPERTYPEINFO(); 70 | 71 | public: 72 | class Factory : public CanvasRenderingContextFactory { 73 | public: 74 | Factory() = default; 75 | 76 | Factory(const Factory&) = delete; 77 | Factory& operator=(const Factory&) = delete; 78 | 79 | ~Factory() override = default; 80 | 81 | CanvasRenderingContext* Create( 82 | CanvasRenderingContextHost* host, 83 | const CanvasContextCreationAttributesCore& attrs) override; 84 | 85 | CanvasRenderingContext::CanvasRenderingAPI GetRenderingAPI() 86 | const override { 87 | return CanvasRenderingContext::CanvasRenderingAPI::k2D; 88 | } 89 | }; 90 | 91 | CanvasRenderingContext2D(HTMLCanvasElement*, 92 | const CanvasContextCreationAttributesCore&); 93 | ~CanvasRenderingContext2D() override; 94 | 95 | HTMLCanvasElement* canvas() const { 96 | DCHECK(!Host() || !Host()->IsOffscreenCanvas()); 97 | return static_cast(Host()); 98 | } 99 | V8RenderingContext* AsV8RenderingContext() final; 100 | NoAllocDirectCallHost* AsNoAllocDirectCallHost() final; 101 | 102 | bool isContextLost() const final { 103 | return context_lost_mode_ != kNotLostContext; 104 | } 105 | 106 | bool ShouldAntialias() const override; 107 | void SetShouldAntialias(bool) override; 108 | 109 | void scrollPathIntoView(); 110 | void scrollPathIntoView(Path2D*); 111 | 112 | void clearRect(double x, double y, double width, double height); 113 | void ClearRect(double x, double y, double width, double height) override { 114 | clearRect(x, y, width, height); 115 | } 116 | 117 | void Reset() override; 118 | 119 | String font() const; 120 | void setFont(const String&) override; 121 | 122 | String direction() const; 123 | void setDirection(const String&); 124 | 125 | void setLetterSpacing(const String&); 126 | void setWordSpacing(const String&); 127 | void setTextRendering(const String&); 128 | 129 | void setFontKerning(const String&); 130 | void setFontStretch(const String&); 131 | void setFontVariantCaps(const String&); 132 | 133 | void fillText(const String& text, double x, double y); 134 | void fillText(const String& text, double x, double y, double max_width); 135 | void strokeText(const String& text, double x, double y); 136 | void strokeText(const String& text, double x, double y, double max_width); 137 | TextMetrics* measureText(const String& text); 138 | void drawFormattedText(FormattedText* formatted_text, 139 | double x, 140 | double y, 141 | ExceptionState&); 142 | 143 | CanvasRenderingContext2DSettings* getContextAttributes() const; 144 | 145 | void drawFocusIfNeeded(Element*); 146 | void drawFocusIfNeeded(Path2D*, Element*); 147 | 148 | void LoseContext(LostContextMode) override; 149 | void DidSetSurfaceSize() override; 150 | 151 | void RestoreCanvasMatrixClipStack(cc::PaintCanvas*) const override; 152 | 153 | // TaskObserver implementation 154 | void DidProcessTask(const base::PendingTask&) final; 155 | 156 | void StyleDidChange(const ComputedStyle* old_style, 157 | const ComputedStyle& new_style) override; 158 | 159 | // SVGResourceClient implementation 160 | void ResourceContentChanged(SVGResource*) override; 161 | 162 | void UpdateFilterReferences(const FilterOperations&); 163 | void ClearFilterReferences(); 164 | 165 | // BaseRenderingContext2D implementation 166 | bool OriginClean() const final; 167 | void SetOriginTainted() final; 168 | bool WouldTaintOrigin(CanvasImageSource* source) final { 169 | return CanvasRenderingContext::WouldTaintOrigin(source); 170 | } 171 | void DisableAcceleration() override; 172 | 173 | int Width() const final; 174 | int Height() const final; 175 | 176 | bool CanCreateCanvas2dResourceProvider() const final; 177 | 178 | RespectImageOrientationEnum RespectImageOrientation() const final; 179 | 180 | Color GetCurrentColor() const final; 181 | 182 | cc::PaintCanvas* GetOrCreatePaintCanvas() final; 183 | cc::PaintCanvas* GetPaintCanvas() final; 184 | void WillDraw(const SkIRect& dirty_rect, 185 | CanvasPerformanceMonitor::DrawType) final; 186 | 187 | SkColorInfo CanvasRenderingContextSkColorInfo() const override { 188 | return color_params_.GetSkColorInfo(); 189 | } 190 | scoped_refptr GetImage( 191 | CanvasResourceProvider::FlushReason) final; 192 | 193 | sk_sp StateGetFilter() final; 194 | void SnapshotStateForFilter() final; 195 | 196 | void ValidateStateStackWithCanvas(const cc::PaintCanvas*) const final; 197 | 198 | void FinalizeFrame(CanvasResourceProvider::FlushReason) override; 199 | 200 | CanvasRenderingContextHost* GetCanvasRenderingContextHost() override; 201 | ExecutionContext* GetTopExecutionContext() const override; 202 | 203 | bool IsPaintable() const final { 204 | return canvas() && canvas()->GetCanvas2DLayerBridge(); 205 | } 206 | 207 | void WillDrawImage(CanvasImageSource*) const final; 208 | 209 | void FlushCanvas(CanvasResourceProvider::FlushReason) override; 210 | 211 | void Trace(Visitor*) const override; 212 | 213 | ImageData* getImageDataInternal(int sx, 214 | int sy, 215 | int sw, 216 | int sh, 217 | ImageDataSettings*, 218 | ExceptionState&) final; 219 | 220 | IdentifiableToken IdentifiableTextToken() const override { 221 | return identifiability_study_helper_.GetToken(); 222 | } 223 | 224 | bool IdentifiabilityEncounteredSkippedOps() const override { 225 | return identifiability_study_helper_.encountered_skipped_ops(); 226 | } 227 | 228 | bool IdentifiabilityEncounteredSensitiveOps() const override { 229 | return identifiability_study_helper_.encountered_sensitive_ops(); 230 | } 231 | 232 | void SendContextLostEventIfNeeded() override; 233 | 234 | bool IdentifiabilityEncounteredPartiallyDigestedImage() const override { 235 | return identifiability_study_helper_.encountered_partially_digested_image(); 236 | } 237 | void fill(const String& winding = "nonzero"); 238 | void fill(Path2D*, const String& winding = "nonzero"); 239 | void stroke(); 240 | void stroke(Path2D*); 241 | void fillRect(double x, double y, double width, double height); 242 | void strokeRect(double x, double y, double width, double height); 243 | ImageData* getImageData(int sx, int sy, int sw, int sh, ExceptionState&); 244 | ImageData* getImageData(int sx, 245 | int sy, 246 | int sw, 247 | int sh, 248 | ImageDataSettings*, 249 | ExceptionState&); 250 | void putImageData(ImageData*, int dx, int dy, ExceptionState&); 251 | void putImageData(ImageData*, 252 | int dx, 253 | int dy, 254 | int dirty_x, 255 | int dirty_y, 256 | int dirty_width, 257 | int dirty_height, 258 | ExceptionState&); 259 | void drawImage(const V8CanvasImageSource* image_source, 260 | double x, 261 | double y, 262 | ExceptionState& exception_state); 263 | void drawImage(const V8CanvasImageSource* image_source, 264 | double x, 265 | double y, 266 | double width, 267 | double height, 268 | ExceptionState& exception_state); 269 | void drawImage(const V8CanvasImageSource* image_source, 270 | double sx, 271 | double sy, 272 | double sw, 273 | double sh, 274 | double dx, 275 | double dy, 276 | double dw, 277 | double dh, 278 | ExceptionState& exception_state); 279 | void drawImage(CanvasImageSource*, 280 | double sx, 281 | double sy, 282 | double sw, 283 | double sh, 284 | double dx, 285 | double dy, 286 | double dw, 287 | double dh, 288 | ExceptionState&); 289 | protected: 290 | PredefinedColorSpace GetDefaultImageDataColorSpace() const final { 291 | return color_params_.ColorSpace(); 292 | } 293 | bool WritePixels(const SkImageInfo& orig_info, 294 | const void* pixels, 295 | size_t row_bytes, 296 | int x, 297 | int y) override; 298 | void WillOverwriteCanvas() override; 299 | void TryRestoreContextEvent(TimerBase*) override; 300 | 301 | private: 302 | friend class CanvasRenderingContext2DAutoRestoreSkCanvas; 303 | 304 | void PruneLocalFontCache(size_t target_size); 305 | 306 | void ScrollPathIntoViewInternal(const Path&); 307 | 308 | void DrawTextInternal(const String&, 309 | double x, 310 | double y, 311 | CanvasRenderingContext2DState::PaintType, 312 | double* max_width = nullptr); 313 | 314 | const Font& AccessFont(); 315 | 316 | void DrawFocusIfNeededInternal( 317 | const Path&, 318 | Element*, 319 | IdentifiableToken path_hash = IdentifiableToken()); 320 | bool FocusRingCallIsValid(const Path&, Element*); 321 | void DrawFocusRing(const Path&, Element*); 322 | void UpdateElementAccessibility(const Path&, Element*); 323 | 324 | bool IsComposited() const override; 325 | bool IsAccelerated() const override; 326 | bool IsOriginTopLeft() const override; 327 | bool HasAlpha() const override { return CreationAttributes().alpha; } 328 | bool IsDesynchronized() const override { 329 | return CreationAttributes().desynchronized; 330 | } 331 | void SetIsInHiddenPage(bool) override; 332 | void SetIsBeingDisplayed(bool) override; 333 | void Stop() final; 334 | 335 | cc::Layer* CcLayer() const override; 336 | bool IsCanvas2DBufferValid() const override; 337 | 338 | void ColorSchemeMayHaveChanged() override; 339 | 340 | FilterOperations filter_operations_; 341 | HashMap fonts_resolved_using_current_style_; 342 | bool should_prune_local_font_cache_; 343 | LinkedHashSet font_lru_list_; 344 | 345 | CanvasColorParams color_params_; 346 | 347 | // For privacy reasons we need to delay contextLost events until the page is 348 | // visible. In order to do this we will hold on to a bool here 349 | bool needs_context_lost_event_ = false; 350 | }; 351 | 352 | } // namespace blink 353 | 354 | #endif // THIRD_PARTY_BLINK_RENDERER_MODULES_CANVAS_CANVAS2D_CANVAS_RENDERING_CONTEXT_2D_H_ 355 | -------------------------------------------------------------------------------- /third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d_fp.cc: -------------------------------------------------------------------------------- 1 | #include "third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d_fp.h" 2 | 3 | #include "base/singleton_fingerprint.h" 4 | #include "third_party/blink/public/common/fingerprint/fingerprint.h" 5 | #include "third_party/blink/renderer/core/html/canvas/html_canvas_element_fp.h" 6 | 7 | #include 8 | #include "third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d.h" 9 | #include "third_party/blink/renderer/bindings/core/v8/v8_union_float32array_uint16array_uint8clampedarray.h" 10 | #include "third_party/blink/renderer/bindings/modules/v8/v8_typedefs.h" 11 | 12 | 13 | namespace blink { 14 | 15 | namespace fp { 16 | 17 | void fpGetImageData(blink::ImageData* imageData,bool flag, 18 | double x, double y, double width, double height, 19 | int canvasX, int canvasY, int canvasWidth, int canvasHeight){ 20 | if(!flag){ 21 | return; 22 | } 23 | if(canvasX>0||canvasY>0||x>0||y>0||widthdata(); 30 | if (!v8data->IsUint8ClampedArray()) { 31 | return; 32 | } 33 | 34 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 35 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 36 | if (base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.canvas.type > 0) { 37 | std::vector coloredPointList= t_fingerprint.canvas.coloredPointList; 38 | const unsigned char* data = v8data->GetAsUint8ClampedArray()->Data(); 39 | unsigned char* mutablePixels = const_cast(data); 40 | CanvasFpIng::fpPixel(mutablePixels, coloredPointList, 4, canvasWidth, canvasHeight);//todo 41 | } 42 | 43 | } 44 | void fpFullCoverage(blink::CanvasRenderingContext* ctx , 45 | double x, double y, double width, double height, 46 | double canvasX, double canvasY,double canvasWidth, double canvasHeight) { 47 | if (!ctx->getFpCanvas()) { 48 | return; 49 | } 50 | if(canvasX>0.5||canvasY>0.5||x>0.5||y>0.5||widthsetFpCanvas(false); 54 | } 55 | 56 | 57 | bool fpValidLine(const SkPoint& startPoint, const SkPoint& endPoint) { 58 | if (startPoint.x()== endPoint.x()|| startPoint.y() == endPoint.y()) { 59 | return true; 60 | } 61 | float dx = endPoint.x() - startPoint.x(); 62 | float dy = endPoint.y() - startPoint.y(); 63 | float radians = std::atan2(dy, dx); 64 | float degrees = radians * 180.0 / M_PI; 65 | if (std::abs(degrees - 45.0 * std::round(degrees / 45.0)) > 0.01) { 66 | return false; 67 | } 68 | 69 | return true; 70 | } 71 | 72 | bool fpCanvas(blink::CanvasRenderingContext* ctx, const blink::CanvasRenderingContext2DState& state, bool isFill) { 73 | if (ctx->getFpCanvas()) { 74 | return true; 75 | } 76 | blink::CanvasStyle* style; 77 | if (isFill) { 78 | style = state.FillStyle(); 79 | }else { 80 | style = state.StrokeStyle(); 81 | } 82 | 83 | if (style->GetCanvasGradient()) { 84 | return true; 85 | } 86 | else if (style->GetCanvasPattern()) { 87 | return true; 88 | } 89 | 90 | if (!isFill) { 91 | double lineWidth = state.LineWidth(); 92 | if (lineWidth > 1) { 93 | blink::LineCap lineCap = state.GetLineCap(); 94 | if (lineCap == blink::LineCap::kRoundCap || lineCap == blink::LineCap::kSquareCap) { 95 | return true; 96 | } 97 | } 98 | 99 | blink::LineJoin lineJoin = state.GetLineJoin(); 100 | if (lineJoin == blink::LineJoin::kRoundJoin || lineJoin == blink::LineJoin::kBevelJoin) { 101 | return true; 102 | } 103 | 104 | } 105 | 106 | blink::AffineTransform t = state.GetTransform(); 107 | double rotation = std::atan2(t.B(), t.A()); 108 | double rotationDegrees = rotation * 180.0 / M_PI; 109 | if (std::abs(rotationDegrees - 45.0 * std::round(rotationDegrees / 45.0)) > 0.01) { 110 | return true; 111 | } 112 | 113 | bool hasShadow = state.ShouldDrawShadows(); 114 | if (hasShadow) { 115 | double shadowBlur = state.ShadowBlur(); 116 | if (shadowBlur > 0.001) { 117 | return true; 118 | } 119 | 120 | } 121 | 122 | return false; 123 | } 124 | 125 | bool fpCanvas(blink::CanvasRenderingContext* ctx, const blink::CanvasRenderingContext2DState& state, const blink::CanvasPath& path, bool isFill) { 126 | 127 | if (ctx->getFpCanvas()) { 128 | return true; 129 | } 130 | 131 | if (path.IsEmpty()) { 132 | return false; 133 | } 134 | 135 | gfx::RectF bounds(path.BoundingRect()); 136 | if (std::isnan(bounds.x()) || std::isnan(bounds.y()) || 137 | std::isnan(bounds.width()) || std::isnan(bounds.height())) { 138 | return false; 139 | } 140 | 141 | if (fpCanvas(ctx, state, isFill)) { 142 | return true; 143 | } 144 | 145 | if (!path.IsLine()) { 146 | return true; 147 | } 148 | 149 | SkPath skPath = path.GetPath().GetSkPath(); 150 | SkPath::Iter iter(skPath, true); 151 | 152 | SkPath::Verb verb; 153 | SkPoint pts[4]; 154 | 155 | while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { 156 | if (verb == SkPath::kQuad_Verb|| 157 | verb == SkPath::kConic_Verb || 158 | verb == SkPath::kCubic_Verb ) { 159 | return true; 160 | } 161 | } 162 | 163 | iter.setPath(skPath, true); 164 | while ((verb = iter.next(pts)) != SkPath::kDone_Verb) { 165 | if (verb == SkPath::kLine_Verb && !fpValidLine(pts[0], pts[1])) { 166 | return true; 167 | } 168 | } 169 | 170 | return false; 171 | } 172 | 173 | } // namespace fp 174 | 175 | } // namespace 176 | -------------------------------------------------------------------------------- /third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d_fp.h: -------------------------------------------------------------------------------- 1 | #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_CANVAS_CANVAS2D_CANVAS_RENDERING_CONTEXT_2D_FP_H_ 2 | #define THIRD_PARTY_BLINK_RENDERER_MODULES_CANVAS_CANVAS2D_CANVAS_RENDERING_CONTEXT_2D_FP_H_ 3 | 4 | #include "third_party/blink/renderer/core/html/canvas/html_canvas_element_fp.h" 5 | #include "third_party/blink/renderer/modules/canvas/canvas2d/path_2d.h" 6 | #include "third_party/blink/renderer/core/html/canvas/image_data.h" 7 | #include "third_party/blink/renderer/modules/canvas/canvas2d/canvas_rendering_context_2d_state.h" 8 | 9 | 10 | namespace blink { 11 | 12 | namespace fp { 13 | 14 | void fpGetImageData(blink::ImageData* imageData, bool flag, double x, double y, double width, double height, int canvasX, int canvasY, int canvasWidth, int canvasHeight); 15 | void fpFullCoverage(blink::CanvasRenderingContext* ctx, double x, double y, double width, double height, double canvasX, double canvasY, double canvasWidth, double canvasHeight); 16 | bool fpValidLine(const SkPoint& startPoint, const SkPoint& endPoint); 17 | bool fpCanvas(blink::CanvasRenderingContext* ctx, const blink::CanvasRenderingContext2DState& state, bool isFill); 18 | bool fpCanvas(blink::CanvasRenderingContext* ctx, const blink::CanvasRenderingContext2DState& state, const blink::CanvasPath& path, bool isFill); 19 | 20 | } // namespace fp 21 | 22 | } // namespace blink 23 | 24 | #endif // THIRD_PARTY_BLINK_RENDERER_MODULES_CANVAS_CANVAS2D_CANVAS_RENDERING_CONTEXT_2D_FP_H_ 25 | -------------------------------------------------------------------------------- /third_party/blink/renderer/modules/canvas/offscreencanvas2d/offscreen_canvas_rendering_context_2d.h: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Chromium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_CANVAS_OFFSCREENCANVAS2D_OFFSCREEN_CANVAS_RENDERING_CONTEXT_2D_H_ 6 | #define THIRD_PARTY_BLINK_RENDERER_MODULES_CANVAS_OFFSCREENCANVAS2D_OFFSCREEN_CANVAS_RENDERING_CONTEXT_2D_H_ 7 | 8 | #include "base/notreached.h" 9 | #include "third_party/blink/renderer/bindings/modules/v8/v8_typedefs.h" 10 | #include "third_party/blink/renderer/core/html/canvas/canvas_context_creation_attributes_core.h" 11 | #include "third_party/blink/renderer/core/html/canvas/canvas_rendering_context.h" 12 | #include "third_party/blink/renderer/core/html/canvas/canvas_rendering_context_factory.h" 13 | #include "third_party/blink/renderer/core/offscreencanvas/offscreen_canvas.h" 14 | #include "third_party/blink/renderer/modules/canvas/canvas2d/base_rendering_context_2d.h" 15 | #include "third_party/blink/renderer/modules/canvas/canvas2d/identifiability_study_helper.h" 16 | #include "third_party/blink/renderer/platform/graphics/canvas_resource_provider.h" 17 | #include "third_party/blink/renderer/platform/privacy_budget/identifiability_digest_helpers.h" 18 | 19 | namespace blink { 20 | 21 | class CanvasResourceProvider; 22 | class Font; 23 | class TextMetrics; 24 | 25 | class MODULES_EXPORT OffscreenCanvasRenderingContext2D final 26 | : public CanvasRenderingContext, 27 | public BaseRenderingContext2D { 28 | DEFINE_WRAPPERTYPEINFO(); 29 | 30 | public: 31 | class Factory : public CanvasRenderingContextFactory { 32 | public: 33 | Factory() = default; 34 | ~Factory() override = default; 35 | 36 | CanvasRenderingContext* Create( 37 | CanvasRenderingContextHost* host, 38 | const CanvasContextCreationAttributesCore& attrs) override; 39 | 40 | CanvasRenderingContext::CanvasRenderingAPI GetRenderingAPI() 41 | const override { 42 | return CanvasRenderingContext::CanvasRenderingAPI::k2D; 43 | } 44 | }; 45 | 46 | OffscreenCanvasRenderingContext2D( 47 | OffscreenCanvas*, 48 | const CanvasContextCreationAttributesCore& attrs); 49 | 50 | OffscreenCanvas* offscreenCanvasForBinding() const { 51 | DCHECK(!Host() || Host()->IsOffscreenCanvas()); 52 | return static_cast(Host()); 53 | } 54 | 55 | void commit(); 56 | 57 | // CanvasRenderingContext implementation 58 | ~OffscreenCanvasRenderingContext2D() override; 59 | bool IsComposited() const override { return false; } 60 | bool IsAccelerated() const override; 61 | NoAllocDirectCallHost* AsNoAllocDirectCallHost() final; 62 | V8RenderingContext* AsV8RenderingContext() final; 63 | V8OffscreenRenderingContext* AsV8OffscreenRenderingContext() final; 64 | void SetIsInHiddenPage(bool) final { NOTREACHED(); } 65 | void SetIsBeingDisplayed(bool) final { NOTREACHED(); } 66 | void Stop() final { NOTREACHED(); } 67 | 68 | void clearRect(double x, double y, double width, double height); 69 | void ClearRect(double x, double y, double width, double height) override { 70 | clearRect(x, y, width, height); 71 | } 72 | SkColorInfo CanvasRenderingContextSkColorInfo() const override { 73 | return color_params_.GetSkColorInfo(); 74 | } 75 | scoped_refptr GetImage( 76 | CanvasResourceProvider::FlushReason) final; 77 | void Reset() override; 78 | void RestoreCanvasMatrixClipStack(cc::PaintCanvas* c) const override { 79 | RestoreMatrixClipStack(c); 80 | } 81 | // CanvasRenderingContext - ActiveScriptWrappable 82 | // This method will avoid this class to be garbage collected, as soon as 83 | // HasPendingActivity returns true. 84 | bool HasPendingActivity() const final { 85 | if (!Host()) 86 | return false; 87 | DCHECK(Host()->IsOffscreenCanvas()); 88 | return static_cast(Host())->HasPlaceholderCanvas() && 89 | !dirty_rect_for_commit_.isEmpty(); 90 | } 91 | 92 | String font() const; 93 | void setFont(const String&) override; 94 | 95 | String direction() const; 96 | void setDirection(const String&); 97 | 98 | void setLetterSpacing(const String&); 99 | void setWordSpacing(const String&); 100 | void setTextRendering(const String&); 101 | void setFontKerning(const String&); 102 | void setFontStretch(const String&); 103 | void setFontVariantCaps(const String&); 104 | 105 | void fillText(const String& text, double x, double y); 106 | void fillText(const String& text, double x, double y, double max_width); 107 | void strokeText(const String& text, double x, double y); 108 | void strokeText(const String& text, double x, double y, double max_width); 109 | TextMetrics* measureText(const String& text); 110 | 111 | // BaseRenderingContext2D implementation 112 | bool OriginClean() const final; 113 | void SetOriginTainted() final; 114 | bool WouldTaintOrigin(CanvasImageSource*) final; 115 | 116 | int Width() const final; 117 | int Height() const final; 118 | 119 | bool CanCreateCanvas2dResourceProvider() const final; 120 | CanvasResourceProvider* GetOrCreateCanvasResourceProvider() const; 121 | CanvasResourceProvider* GetCanvasResourceProvider() const; 122 | 123 | // Offscreen canvas doesn't have any notion of image orientation. 124 | RespectImageOrientationEnum RespectImageOrientation() const final { 125 | return kRespectImageOrientation; 126 | } 127 | 128 | Color GetCurrentColor() const final; 129 | 130 | cc::PaintCanvas* GetOrCreatePaintCanvas() final; 131 | cc::PaintCanvas* GetPaintCanvas() final; 132 | void WillDraw(const SkIRect& dirty_rect, 133 | CanvasPerformanceMonitor::DrawType) final; 134 | 135 | sk_sp StateGetFilter() final; 136 | void SnapshotStateForFilter() final; 137 | 138 | void ValidateStateStackWithCanvas(const cc::PaintCanvas*) const final; 139 | 140 | bool HasAlpha() const final { return CreationAttributes().alpha; } 141 | bool IsDesynchronized() const final { 142 | return CreationAttributes().desynchronized; 143 | } 144 | bool isContextLost() const final { 145 | return context_lost_mode_ != kNotLostContext; 146 | } 147 | void LoseContext(LostContextMode) override; 148 | 149 | ImageBitmap* TransferToImageBitmap(ScriptState*) final; 150 | 151 | void Trace(Visitor*) const override; 152 | 153 | bool PushFrame() override; 154 | 155 | CanvasRenderingContextHost* GetCanvasRenderingContextHost() override; 156 | ExecutionContext* GetTopExecutionContext() const override; 157 | 158 | IdentifiableToken IdentifiableTextToken() const override { 159 | return identifiability_study_helper_.GetToken(); 160 | } 161 | 162 | bool IdentifiabilityEncounteredSkippedOps() const override { 163 | return identifiability_study_helper_.encountered_skipped_ops(); 164 | } 165 | 166 | bool IdentifiabilityEncounteredSensitiveOps() const override { 167 | return identifiability_study_helper_.encountered_sensitive_ops(); 168 | } 169 | 170 | bool IdentifiabilityEncounteredPartiallyDigestedImage() const override { 171 | return identifiability_study_helper_.encountered_partially_digested_image(); 172 | } 173 | 174 | void FlushCanvas(CanvasResourceProvider::FlushReason) override; 175 | void fill(const String& winding = "nonzero"); 176 | void fill(Path2D*, const String& winding = "nonzero"); 177 | void stroke(); 178 | void stroke(Path2D*); 179 | void fillRect(double x, double y, double width, double height); 180 | void strokeRect(double x, double y, double width, double height); 181 | ImageData* getImageData(int sx, int sy, int sw, int sh, ExceptionState&); 182 | ImageData* getImageData(int sx, 183 | int sy, 184 | int sw, 185 | int sh, 186 | ImageDataSettings*, 187 | ExceptionState&); 188 | void putImageData(ImageData*, int dx, int dy, ExceptionState&); 189 | void putImageData(ImageData*, 190 | int dx, 191 | int dy, 192 | int dirty_x, 193 | int dirty_y, 194 | int dirty_width, 195 | int dirty_height, 196 | ExceptionState&); 197 | void drawImage(const V8CanvasImageSource* image_source, 198 | double x, 199 | double y, 200 | ExceptionState& exception_state); 201 | void drawImage(const V8CanvasImageSource* image_source, 202 | double x, 203 | double y, 204 | double width, 205 | double height, 206 | ExceptionState& exception_state); 207 | void drawImage(const V8CanvasImageSource* image_source, 208 | double sx, 209 | double sy, 210 | double sw, 211 | double sh, 212 | double dx, 213 | double dy, 214 | double dw, 215 | double dh, 216 | ExceptionState& exception_state); 217 | void drawImage(CanvasImageSource*, 218 | double sx, 219 | double sy, 220 | double sw, 221 | double sh, 222 | double dx, 223 | double dy, 224 | double dw, 225 | double dh, 226 | ExceptionState&); 227 | protected: 228 | PredefinedColorSpace GetDefaultImageDataColorSpace() const final { 229 | return color_params_.ColorSpace(); 230 | } 231 | bool WritePixels(const SkImageInfo& orig_info, 232 | const void* pixels, 233 | size_t row_bytes, 234 | int x, 235 | int y) override; 236 | void WillOverwriteCanvas() override; 237 | void DispatchContextLostEvent(TimerBase*) override; 238 | void TryRestoreContextEvent(TimerBase*) override; 239 | 240 | private: 241 | void FinalizeFrame(CanvasResourceProvider::FlushReason) final; 242 | void FlushRecording(CanvasResourceProvider::FlushReason); 243 | 244 | bool IsPaintable() const final; 245 | bool IsCanvas2DBufferValid() const override; 246 | 247 | void DrawTextInternal(const String&, 248 | double, 249 | double, 250 | CanvasRenderingContext2DState::PaintType, 251 | double* max_width = nullptr); 252 | const Font& AccessFont(); 253 | 254 | scoped_refptr ProduceCanvasResource( 255 | CanvasResourceProvider::FlushReason); 256 | 257 | SkIRect dirty_rect_for_commit_; 258 | 259 | bool is_valid_size_ = false; 260 | 261 | CanvasColorParams color_params_; 262 | }; 263 | 264 | } // namespace blink 265 | 266 | #endif // THIRD_PARTY_BLINK_RENDERER_MODULES_CANVAS_OFFSCREENCANVAS2D_OFFSCREEN_CANVAS_RENDERING_CONTEXT_2D_H_ 267 | -------------------------------------------------------------------------------- /third_party/blink/renderer/modules/geolocation/fp_geolocation.h: -------------------------------------------------------------------------------- 1 | #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_GEOLOCATION_FP_GEOLOCATION_H_ 2 | #define THIRD_PARTY_BLINK_RENDERER_MODULES_GEOLOCATION_FP_GEOLOCATION_H_ 3 | 4 | #include "third_party/blink/public/common/fingerprint/fingerprint.h" 5 | #include "base/singleton_fingerprint.h" 6 | 7 | #include "third_party/blink/renderer/modules/geolocation/geoposition.h" 8 | #include "third_party/blink/renderer/platform/heap/garbage_collected.h" 9 | #include "third_party/blink/renderer/modules/geolocation/geolocation_coordinates.h" 10 | #include "third_party/blink/renderer/core/timing/epoch_time_stamp.h" 11 | #include "base/time/time.h" 12 | 13 | bool fpOnPositionUpdated(){ 14 | base::SingletonFingerprint* t_singletonFingerprint =base::SingletonFingerprint::ForCurrentProcess(); 15 | blink::fp::Fingerprint t_fingerprint =t_singletonFingerprint->GetFingerprint(); 16 | if (base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.location.type > 1) { 17 | return true; 18 | } 19 | return false; 20 | } 21 | 22 | 23 | blink::Geoposition* fpCreateGeoposition() { 24 | 25 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 26 | blink::fp::Fingerprint t_fingerprint =t_singletonFingerprint->GetFingerprint(); 27 | blink::fp::Location location = t_fingerprint.location; 28 | 29 | blink::GeolocationCoordinates* coordinates = blink::MakeGarbageCollected( 30 | location.latitude, location.longitude, false, 0.0, location.accuracy, 31 | false, 0.0, 32 | false, 0.0, 33 | false, 0.0); 34 | 35 | return blink::MakeGarbageCollected(coordinates, blink::ConvertTimeToEpochTimeStamp(base::Time::Now())); 36 | 37 | } 38 | 39 | #endif // THIRD_PARTY_BLINK_RENDERER_MODULES_GEOLOCATION_FP_GEOLOCATION_H_ 40 | -------------------------------------------------------------------------------- /third_party/blink/renderer/modules/mediastream/media_devices_fp.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIASTREAM_MEDIA_DEVICES_FP_H_ 3 | #define THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIASTREAM_MEDIA_DEVICES_FP_H_ 4 | 5 | 6 | 7 | #include "base/singleton_fingerprint.h" 8 | #include "third_party/blink/public/common/fingerprint/fingerprint.h" 9 | 10 | #include "third_party/blink/renderer/platform/wtf/vector.h" 11 | #include "third_party/blink/public/common/mediastream/media_devices.h" 12 | #include "third_party/blink/public/mojom/mediastream/media_devices.mojom-blink-forward.h" 13 | 14 | #include "third_party/blink/renderer/modules/mediastream/media_device_info.h" 15 | #include "third_party/blink/renderer/platform/heap/garbage_collected.h" 16 | #include "third_party/blink/renderer/modules/mediastream/input_device_info.h" 17 | 18 | void fpDevicesEnumerated(WTF::Vector 19 | video_input_capabilities, 20 | WTF::Vector 21 | audio_input_capabilities, 22 | blink::MediaDeviceInfoVector& media_devices1, 23 | blink::MediaDeviceInfoVector& media_devices2){ 24 | if (media_devices1.size()==1) { 25 | if (media_devices1[0]->label() == "" || 26 | media_devices1[0]->deviceId() == "" || 27 | media_devices1[0]->groupId() == "") { 28 | 29 | media_devices2.push_back(media_devices1[0]); 30 | return; 31 | 32 | } 33 | 34 | } 35 | 36 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 37 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 38 | if (base::SingletonFingerprint::GetInit(t_singletonFingerprint) && 39 | t_fingerprint.mediaEquipment.type > 1) { 40 | 41 | std::vector list = t_fingerprint.mediaEquipment.list; 42 | 43 | for (std::size_t i = 0; i < list.size(); ++i) 44 | { 45 | blink::fp::MediaEquipmentInfo t_tmp=list[i]; 46 | blink::mojom::blink::MediaDeviceType device_type=static_cast(t_tmp.type); 47 | blink::InputDeviceInfo* input_device_info = blink::MakeGarbageCollected( 48 | String::FromUTF8(t_tmp.deviceId), String::FromUTF8(t_tmp.label), 49 | String::FromUTF8(t_tmp.groupId), device_type); 50 | media_devices2.push_back(input_device_info); 51 | } 52 | } 53 | else { 54 | for (const auto& deviceInfo : media_devices1) { 55 | 56 | media_devices2.push_back(deviceInfo); 57 | } 58 | 59 | 60 | 61 | } 62 | 63 | 64 | } 65 | 66 | 67 | 68 | 69 | #endif // THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIASTREAM_MEDIA_DEVICES_FP_H_ 70 | -------------------------------------------------------------------------------- /third_party/blink/renderer/modules/mediastream/media_stream_track_impl_fp.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIASTREAM_MEDIA_STREAM_TRACK_IMPL_FP_H_ 3 | #define THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIASTREAM_MEDIA_STREAM_TRACK_IMPL_FP_H_ 4 | 5 | #include "base/singleton_fingerprint.h" 6 | #include "third_party/blink/public/common/fingerprint/fingerprint.h" 7 | #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" 8 | 9 | 10 | #include "third_party/blink/renderer/bindings/modules/v8/v8_media_track_settings.h" 11 | #include "third_party/blink/renderer/bindings/modules/v8/v8_media_track_capabilities.h" 12 | 13 | WTF::String fpLabel(WTF::String label,bool isAudio){ 14 | 15 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 16 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 17 | if(base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.mediaEquipment.type > 1 ){ 18 | std::vector< blink::fp::MediaEquipmentInfo> list=t_fingerprint.mediaEquipment.list; 19 | for(unsigned i=0;iGetFingerprint(); 32 | if(base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.mediaEquipment.type > 1 ){ 33 | std::vector< blink::fp::MediaEquipmentInfo> list=t_fingerprint.mediaEquipment.list; 34 | for(unsigned i=0;isetDeviceId(WTF::String(t_equipmentInfo.deviceId.c_str(), t_equipmentInfo.deviceId.length())); 38 | if(groupIdNotNull){ 39 | settings->setGroupId(WTF::String(t_equipmentInfo.groupId.c_str(), t_equipmentInfo.groupId.length())); 40 | } 41 | return ; 42 | } 43 | } 44 | } 45 | 46 | } 47 | 48 | 49 | void fpGetCapabilities(blink::MediaTrackCapabilities* capabilities,bool isAudio,bool groupIdNotNull){ 50 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 51 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 52 | if(base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.mediaEquipment.type > 1 ){ 53 | std::vector< blink::fp::MediaEquipmentInfo> list=t_fingerprint.mediaEquipment.list; 54 | for(unsigned i=0;isetDeviceId(WTF::String(t_equipmentInfo.deviceId.c_str(), t_equipmentInfo.deviceId.length())); 58 | if(groupIdNotNull){ 59 | capabilities->setGroupId(WTF::String(t_equipmentInfo.groupId.c_str(), t_equipmentInfo.groupId.length())); 60 | } 61 | return ; 62 | } 63 | } 64 | } 65 | 66 | } 67 | 68 | 69 | 70 | #endif // THIRD_PARTY_BLINK_RENDERER_MODULES_MEDIASTREAM_MEDIA_STREAM_TRACK_IMPL_FP_H_ 71 | -------------------------------------------------------------------------------- /third_party/blink/renderer/modules/speech/speech_synthesis.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Apple Inc. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | */ 25 | 26 | #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_SPEECH_SPEECH_SYNTHESIS_H_ 27 | #define THIRD_PARTY_BLINK_RENDERER_MODULES_SPEECH_SPEECH_SYNTHESIS_H_ 28 | 29 | #include "third_party/blink/public/mojom/speech/speech_synthesis.mojom-blink-forward.h" 30 | #include "third_party/blink/renderer/core/speech/speech_synthesis_base.h" 31 | #include "third_party/blink/renderer/modules/event_target_modules.h" 32 | #include "third_party/blink/renderer/modules/modules_export.h" 33 | #include "third_party/blink/renderer/modules/speech/speech_synthesis_utterance.h" 34 | #include "third_party/blink/renderer/modules/speech/speech_synthesis_voice.h" 35 | #include "third_party/blink/renderer/platform/heap/collection_support/heap_deque.h" 36 | #include "third_party/blink/renderer/platform/heap/collection_support/heap_vector.h" 37 | #include "third_party/blink/renderer/platform/heap/garbage_collected.h" 38 | #include "third_party/blink/renderer/platform/mojo/heap_mojo_receiver.h" 39 | #include "third_party/blink/renderer/platform/mojo/heap_mojo_remote.h" 40 | #include "third_party/blink/renderer/platform/supplementable.h" 41 | 42 | namespace blink { 43 | 44 | class LocalDOMWindow; 45 | 46 | class MODULES_EXPORT SpeechSynthesis final 47 | : public EventTargetWithInlineData, 48 | public SpeechSynthesisBase, 49 | public Supplement, 50 | public mojom::blink::SpeechSynthesisVoiceListObserver { 51 | DEFINE_WRAPPERTYPEINFO(); 52 | 53 | public: 54 | static const char kSupplementName[]; 55 | 56 | static SpeechSynthesisBase* Create(LocalDOMWindow&); 57 | static SpeechSynthesis* speechSynthesis(LocalDOMWindow&); 58 | static void CreateForTesting( 59 | LocalDOMWindow&, 60 | mojo::PendingRemote); 61 | 62 | explicit SpeechSynthesis(LocalDOMWindow&); 63 | 64 | bool pending() const; 65 | bool speaking() const { return Speaking(); } 66 | bool paused() const; 67 | 68 | // SpeechSynthesisBase 69 | void Speak(const String&, const String&) override; 70 | void Cancel() override; 71 | void Pause() override; 72 | void Resume() override; 73 | bool Speaking() const override; 74 | 75 | void speak(ScriptState*, SpeechSynthesisUtterance*); 76 | void cancel() { Cancel(); } 77 | void pause() { Pause(); } 78 | void resume() { Resume(); } 79 | 80 | const HeapVector>& getVoices(); 81 | 82 | DEFINE_ATTRIBUTE_EVENT_LISTENER(voiceschanged, kVoiceschanged) 83 | 84 | ExecutionContext* GetExecutionContext() const override; 85 | 86 | // GarbageCollected 87 | void Trace(Visitor*) const override; 88 | 89 | // mojom::blink::SpeechSynthesisVoiceListObserver 90 | void OnSetVoiceList( 91 | Vector voices) override; 92 | 93 | // These methods are called by SpeechSynthesisUtterance: 94 | void DidStartSpeaking(SpeechSynthesisUtterance*); 95 | void DidPauseSpeaking(SpeechSynthesisUtterance*); 96 | void DidResumeSpeaking(SpeechSynthesisUtterance*); 97 | void DidFinishSpeaking(SpeechSynthesisUtterance*, 98 | mojom::blink::SpeechSynthesisErrorCode); 99 | void SpeakingErrorOccurred(SpeechSynthesisUtterance*); 100 | void WordBoundaryEventOccurred(SpeechSynthesisUtterance*, 101 | unsigned char_index, 102 | unsigned char_length); 103 | void SentenceBoundaryEventOccurred(SpeechSynthesisUtterance*, 104 | unsigned char_index, 105 | unsigned char_length); 106 | 107 | mojom::blink::SpeechSynthesis* MojomSynthesis() { 108 | return mojom_synthesis_.get(); 109 | } 110 | 111 | private: 112 | void VoicesDidChange(); 113 | void StartSpeakingImmediately(); 114 | void HandleSpeakingCompleted( 115 | SpeechSynthesisUtterance*, 116 | mojom::blink::SpeechSynthesisErrorCode error_code); 117 | void FireEvent(const AtomicString& type, 118 | SpeechSynthesisUtterance*, 119 | uint32_t char_index, 120 | uint32_t char_length, 121 | const String& name); 122 | 123 | void FireErrorEvent(SpeechSynthesisUtterance*, 124 | uint32_t char_index, 125 | const String& error); 126 | 127 | // Returns the utterance at the front of the queue. 128 | SpeechSynthesisUtterance* CurrentSpeechUtterance() const; 129 | 130 | // Gets a timestamp in millis that is safe to expose to the web. 131 | // Returns false if it cannot get a timestamp. 132 | bool GetElapsedTimeMillis(double* millis); 133 | 134 | bool IsAllowedToStartByAutoplay() const; 135 | 136 | void RecordVoicesForIdentifiability() const; 137 | 138 | void SetMojomSynthesisForTesting( 139 | mojo::PendingRemote); 140 | mojom::blink::SpeechSynthesis* TryEnsureMojomSynthesis(); 141 | 142 | HeapMojoReceiver 144 | receiver_; 145 | HeapMojoRemote mojom_synthesis_; 146 | HeapVector> voice_list_; 147 | HeapVector> fp_voice_list_; 148 | HeapDeque> utterance_queue_; 149 | bool is_paused_ = false; 150 | 151 | // EventTarget 152 | const AtomicString& InterfaceName() const override; 153 | }; 154 | 155 | } // namespace blink 156 | 157 | #endif // THIRD_PARTY_BLINK_RENDERER_MODULES_SPEECH_SPEECH_SYNTHESIS_H_ 158 | -------------------------------------------------------------------------------- /third_party/blink/renderer/modules/speech/speech_synthesis_fp.h: -------------------------------------------------------------------------------- 1 | #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_SPEECH_SPEECH_SYNTHESIS_VOICE_FP_H_ 2 | #define THIRD_PARTY_BLINK_RENDERER_MODULES_SPEECH_SPEECH_SYNTHESIS_VOICE_FP_H_ 3 | 4 | #include "base/singleton_fingerprint.h" 5 | #include "third_party/blink/public/common/fingerprint/fingerprint.h" 6 | 7 | #include "third_party/blink/public/mojom/speech/speech_synthesis.mojom-blink-forward.h" 8 | #include "third_party/blink/renderer/modules/speech/speech_synthesis_voice.h" 9 | #include "third_party/blink/renderer/platform/heap/collection_support/heap_vector.h" 10 | #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" 11 | #include "third_party/blink/renderer/platform/heap/member.h" 12 | #include "third_party/blink/renderer/platform/heap/garbage_collected.h" 13 | 14 | 15 | bool fpGetVoices( 16 | blink::HeapVector>& voices, 17 | blink::HeapVector>& fpVoices){ 18 | 19 | 20 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 21 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 22 | if(base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.speechVoices.type > 1 ){ 23 | if(fpVoices.size() > 0){ 24 | return true; 25 | } 26 | std::vector list =t_fingerprint.speechVoices.list; 27 | for (std::size_t i = 0; i < list.size(); ++i) { 28 | const blink::fp::SpeechVoicesInfo& info = list[i]; 29 | 30 | blink::mojom::blink::SpeechSynthesisVoicePtr prt0= blink::mojom::blink::SpeechSynthesisVoice::New(); 31 | prt0->voice_uri=WTF::String(info.voiceUri.c_str(), info.voiceUri.length()); 32 | prt0->name = WTF::String(info.name.c_str(), info.name.length()); 33 | prt0->lang =WTF::String(info.lang.c_str(), info.lang.length()); 34 | prt0->is_local_service = info.isLocalService; 35 | prt0->is_default = info.isDefault; 36 | fpVoices.push_back(blink::MakeGarbageCollected(std::move(prt0))); 37 | } 38 | return true; 39 | } 40 | return false; 41 | } 42 | 43 | #endif // THIRD_PARTY_BLINK_RENDERER_MODULES_SPEECH_SPEECH_SYNTHESIS_VOICE_FP_H_ -------------------------------------------------------------------------------- /third_party/blink/renderer/modules/webaudio/offline_audio_context_fp.h: -------------------------------------------------------------------------------- 1 | #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_WEBAUDIO_OFFLINE_AUDIO_CONTEXT_FP_H_ 2 | #define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBAUDIO_OFFLINE_AUDIO_CONTEXT_FP_H_ 3 | 4 | #include 5 | #include "base/singleton_fingerprint.h" 6 | #include "third_party/blink/public/common/fingerprint/fingerprint.h" 7 | 8 | #include "third_party/blink/renderer/modules/webaudio/audio_buffer.h" 9 | #include "third_party/blink/renderer/core/typed_arrays/dom_typed_array.h" 10 | 11 | float fpfracPart(float number, float fp, uint32_t length) { 12 | 13 | 14 | if (number == 0.0f || fp == 0.0f) { 15 | return number; 16 | } 17 | 18 | float intPart; 19 | float fracPart = modf(number, &intPart); 20 | if (fracPart == 0.0) { 21 | return number; 22 | } 23 | 24 | float t_fracPart = floor(fracPart * 10000) / 10000; 25 | 26 | float c_Number = number * 10000; 27 | 28 | number = intPart + t_fracPart; 29 | 30 | c_Number = modf(c_Number, &intPart); 31 | 32 | 33 | 34 | fracPart = modf(fp * (c_Number + 0.264984637498f), &intPart); 35 | 36 | if (length % 79 == 0 && number < 0.7f ) { 37 | number = number + 0.223456789123; 38 | } 39 | return number + (fracPart / pow(10, 6)); 40 | } 41 | 42 | 43 | void fpFireCompletionEvent(blink::AudioBuffer* rendered_buffer){ 44 | 45 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 46 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 47 | if(base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.audioContext.type > 1 ){ 48 | 49 | std::vector& noise = t_fingerprint.audioContext.noise; 50 | size_t noiseSize = noise.size(); 51 | for (unsigned int j = 0; j < rendered_buffer->length(); j++) { 52 | blink::DOMFloat32Array* arrayPtr =rendered_buffer->getChannelData(j).Get(); 53 | if (arrayPtr) { 54 | float* data = arrayPtr->Data(); 55 | for (size_t i = 0; i < arrayPtr->length(); ++i) { 56 | uint32_t noiseIndex = static_cast(i) % static_cast(noiseSize); 57 | data[i] = fpfracPart(data[i], noise[noiseIndex], static_cast(i)); 58 | } 59 | } 60 | } 61 | } 62 | 63 | 64 | } 65 | 66 | 67 | #endif // THIRD_PARTY_BLINK_RENDERER_MODULES_WEBAUDIO_OFFLINE_AUDIO_CONTEXT_FP_H_ 68 | -------------------------------------------------------------------------------- /third_party/blink/renderer/modules/webgl/webgl_rendering_context_base_fp.h: -------------------------------------------------------------------------------- 1 | #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_WEBGL_WEBGL_RENDERING_CONTEXT_BASE_FP_H_ 2 | #define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBGL_WEBGL_RENDERING_CONTEXT_BASE_FP_H_ 3 | 4 | #include "stdint.h" 5 | #include "third_party/khronos/GLES2/gl2.h" 6 | #include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer_view.h" 7 | #include "third_party/blink/renderer/core/html/canvas/html_canvas_element_fp.h" 8 | 9 | #include "base/singleton_fingerprint.h" 10 | #include "third_party/blink/public/common/fingerprint/fingerprint.h" 11 | 12 | void fpReadPixelsHelper(GLint x,GLint y, 13 | GLsizei width, GLsizei height, 14 | GLenum format,GLenum type, 15 | blink::DOMArrayBufferView* pixels,int64_t offset, 16 | int canvasWidth,int canvasHeight){ 17 | 18 | if(x>0||y>0||widthGetType(); 22 | if(format!=GL_RGBA||type!=GL_UNSIGNED_BYTE|| 23 | (bufferType != blink::DOMArrayBufferView::kTypeUint8 && bufferType != blink::DOMArrayBufferView::kTypeUint8Clamped)){ 24 | return; 25 | } 26 | 27 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 28 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 29 | if (base::SingletonFingerprint::GetInit(t_singletonFingerprint)&&t_fingerprint.webGL.type > 1) { 30 | base::CheckedNumeric offset_in_bytes = offset; 31 | uint8_t* data = static_cast(pixels->BaseAddressMaybeShared()) + offset_in_bytes.ValueOrDie(); 32 | if (strlen((char*)data)<32){ 33 | return; 34 | } 35 | std::vector coloredPointList= t_fingerprint.webGL.coloredPointList; 36 | blink::CanvasFpIng::fpPixel(data, coloredPointList, 4, canvasWidth, canvasHeight); 37 | 38 | } 39 | 40 | 41 | } 42 | 43 | #endif // THIRD_PARTY_BLINK_RENDERER_MODULES_WEBGL_WEBGL_RENDERING_CONTEXT_BASE_FP_H_ 44 | -------------------------------------------------------------------------------- /third_party/blink/renderer/modules/webgpu/gpu_adapter.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Chromium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "third_party/blink/renderer/modules/webgpu/gpu_adapter.h" 6 | #include "third_party/blink/renderer/modules/webgpu/gpu_adapter_fp.h" 7 | 8 | #include "services/metrics/public/cpp/ukm_builders.h" 9 | #include "third_party/blink/renderer/bindings/core/v8/script_promise_resolver.h" 10 | #include "third_party/blink/renderer/bindings/core/v8/v8_object_builder.h" 11 | #include "third_party/blink/renderer/bindings/modules/v8/v8_gpu_device_descriptor.h" 12 | #include "third_party/blink/renderer/bindings/modules/v8/v8_gpu_request_adapter_options.h" 13 | #include "third_party/blink/renderer/core/dom/dom_exception.h" 14 | #include "third_party/blink/renderer/core/frame/local_dom_window.h" 15 | #include "third_party/blink/renderer/core/frame/local_frame.h" 16 | #include "third_party/blink/renderer/core/inspector/console_message.h" 17 | #include "third_party/blink/renderer/modules/webgpu/dawn_enum_conversions.h" 18 | #include "third_party/blink/renderer/modules/webgpu/gpu.h" 19 | #include "third_party/blink/renderer/modules/webgpu/gpu_adapter_info.h" 20 | #include "third_party/blink/renderer/modules/webgpu/gpu_device.h" 21 | #include "third_party/blink/renderer/modules/webgpu/gpu_supported_features.h" 22 | #include "third_party/blink/renderer/modules/webgpu/gpu_supported_limits.h" 23 | #include "third_party/blink/renderer/modules/webgpu/string_utils.h" 24 | #include "third_party/blink/renderer/platform/heap/garbage_collected.h" 25 | 26 | namespace blink { 27 | 28 | namespace { 29 | 30 | absl::optional ToV8FeatureNameEnum(WGPUFeatureName f) { 31 | switch (f) { 32 | case WGPUFeatureName_Depth32FloatStencil8: 33 | return V8GPUFeatureName::Enum::kDepth32FloatStencil8; 34 | case WGPUFeatureName_TimestampQuery: 35 | return V8GPUFeatureName::Enum::kTimestampQuery; 36 | case WGPUFeatureName_TimestampQueryInsidePasses: 37 | return V8GPUFeatureName::Enum::kTimestampQueryInsidePasses; 38 | case WGPUFeatureName_PipelineStatisticsQuery: 39 | return V8GPUFeatureName::Enum::kPipelineStatisticsQuery; 40 | case WGPUFeatureName_TextureCompressionBC: 41 | return V8GPUFeatureName::Enum::kTextureCompressionBc; 42 | case WGPUFeatureName_TextureCompressionETC2: 43 | return V8GPUFeatureName::Enum::kTextureCompressionEtc2; 44 | case WGPUFeatureName_TextureCompressionASTC: 45 | return V8GPUFeatureName::Enum::kTextureCompressionAstc; 46 | case WGPUFeatureName_IndirectFirstInstance: 47 | return V8GPUFeatureName::Enum::kIndirectFirstInstance; 48 | case WGPUFeatureName_DepthClipControl: 49 | return V8GPUFeatureName::Enum::kDepthClipControl; 50 | case WGPUFeatureName_RG11B10UfloatRenderable: 51 | return V8GPUFeatureName::Enum::kRg11B10UfloatRenderable; 52 | case WGPUFeatureName_BGRA8UnormStorage: 53 | return V8GPUFeatureName::Enum::kBgra8UnormStorage; 54 | case WGPUFeatureName_ChromiumExperimentalDp4a: 55 | return V8GPUFeatureName::Enum::kChromiumExperimentalDp4A; 56 | case WGPUFeatureName_ShaderF16: 57 | return V8GPUFeatureName::Enum::kShaderF16; 58 | default: 59 | return absl::nullopt; 60 | } 61 | } 62 | 63 | } // anonymous namespace 64 | 65 | namespace { 66 | 67 | GPUSupportedFeatures* MakeFeatureNameSet(const DawnProcTable& procs, 68 | WGPUAdapter adapter) { 69 | GPUSupportedFeatures* features = MakeGarbageCollected(); 70 | DCHECK(features->FeatureNameSet().empty()); 71 | 72 | size_t feature_count = procs.adapterEnumerateFeatures(adapter, nullptr); 73 | DCHECK(feature_count <= std::numeric_limits::max()); 74 | 75 | Vector feature_names(static_cast(feature_count)); 76 | procs.adapterEnumerateFeatures(adapter, feature_names.data()); 77 | 78 | for (WGPUFeatureName f : feature_names) { 79 | auto feature_name_enum_optional = ToV8FeatureNameEnum(f); 80 | if (feature_name_enum_optional) { 81 | features->AddFeatureName( 82 | V8GPUFeatureName(feature_name_enum_optional.value())); 83 | } 84 | } 85 | return features; 86 | } 87 | 88 | } // anonymous namespace 89 | 90 | GPUAdapter::GPUAdapter( 91 | GPU* gpu, 92 | WGPUAdapter handle, 93 | scoped_refptr dawn_control_client) 94 | : DawnObjectBase(dawn_control_client), handle_(handle), gpu_(gpu) { 95 | WGPUAdapterProperties properties = {}; 96 | GetProcs().adapterGetProperties(handle_, &properties); 97 | is_fallback_adapter_ = properties.adapterType == WGPUAdapterType_CPU; 98 | backend_type_ = properties.backendType; 99 | 100 | vendor_ = properties.vendorName; 101 | architecture_ = properties.architecture; 102 | if (properties.deviceID <= 0xffff) { 103 | device_ = String::Format("0x%04x", properties.deviceID); 104 | } else { 105 | device_ = String::Format("0x%08x", properties.deviceID); 106 | } 107 | description_ = properties.name; 108 | driver_ = properties.driverDescription; 109 | 110 | WGPUSupportedLimits limits = {}; 111 | GetProcs().adapterGetLimits(handle_, &limits); 112 | limits_ = MakeGarbageCollected(limits); 113 | 114 | features_ = MakeFeatureNameSet(GetProcs(), handle_); 115 | } 116 | 117 | void GPUAdapter::AddConsoleWarning(ExecutionContext* execution_context, 118 | const char* message) { 119 | if (execution_context && allowed_console_warnings_remaining_ > 0) { 120 | auto* console_message = MakeGarbageCollected( 121 | mojom::blink::ConsoleMessageSource::kRendering, 122 | mojom::blink::ConsoleMessageLevel::kWarning, 123 | StringFromASCIIAndUTF8(message)); 124 | execution_context->AddConsoleMessage(console_message); 125 | 126 | allowed_console_warnings_remaining_--; 127 | if (allowed_console_warnings_remaining_ == 0) { 128 | auto* final_message = MakeGarbageCollected( 129 | mojom::blink::ConsoleMessageSource::kRendering, 130 | mojom::blink::ConsoleMessageLevel::kWarning, 131 | "WebGPU: too many warnings, no more warnings will be reported to the " 132 | "console for this GPUAdapter."); 133 | execution_context->AddConsoleMessage(final_message); 134 | } 135 | } 136 | } 137 | 138 | GPUSupportedFeatures* GPUAdapter::features() const { 139 | return features_; 140 | } 141 | 142 | bool GPUAdapter::isFallbackAdapter() const { 143 | return is_fallback_adapter_; 144 | } 145 | 146 | WGPUBackendType GPUAdapter::backendType() const { 147 | return backend_type_; 148 | } 149 | 150 | bool GPUAdapter::SupportsMultiPlanarFormats() const { 151 | return GetProcs().adapterHasFeature(handle_, 152 | WGPUFeatureName_DawnMultiPlanarFormats); 153 | } 154 | 155 | void GPUAdapter::OnRequestDeviceCallback(ScriptState* script_state, 156 | ScriptPromiseResolver* resolver, 157 | const GPUDeviceDescriptor* descriptor, 158 | WGPURequestDeviceStatus status, 159 | WGPUDevice dawn_device, 160 | const char* error_message) { 161 | switch (status) { 162 | case WGPURequestDeviceStatus_Success: { 163 | DCHECK(dawn_device); 164 | 165 | if (is_consumed_) { 166 | resolver->Reject(MakeGarbageCollected( 167 | DOMExceptionCode::kInvalidStateError, 168 | "The adapter is invalid because it has already been used to create " 169 | "a device. NOTE: The behavior in this error case may change in a " 170 | "future release.")); 171 | break; 172 | } 173 | is_consumed_ = true; 174 | 175 | ExecutionContext* execution_context = 176 | ExecutionContext::From(script_state); 177 | auto* device = MakeGarbageCollected( 178 | execution_context, GetDawnControlClient(), this, dawn_device, 179 | descriptor); 180 | resolver->Resolve(device); 181 | 182 | ukm::builders::ClientRenderingAPI(execution_context->UkmSourceID()) 183 | .SetGPUDevice(static_cast(true)) 184 | .Record(execution_context->UkmRecorder()); 185 | break; 186 | } 187 | 188 | case WGPURequestDeviceStatus_Error: 189 | case WGPURequestDeviceStatus_Unknown: 190 | DCHECK_EQ(dawn_device, nullptr); 191 | resolver->Reject(MakeGarbageCollected( 192 | DOMExceptionCode::kOperationError, 193 | StringFromASCIIAndUTF8(error_message))); 194 | break; 195 | default: 196 | NOTREACHED(); 197 | } 198 | } 199 | 200 | ScriptPromise GPUAdapter::requestDevice(ScriptState* script_state, 201 | GPUDeviceDescriptor* descriptor) { 202 | auto* resolver = MakeGarbageCollected( 203 | script_state, 204 | ExceptionContext(ExceptionContext::Context::kOperationInvoke, 205 | "GPUAdapter", "requestDevice")); 206 | ScriptPromise promise = resolver->Promise(); 207 | 208 | WGPUDeviceDescriptor dawn_desc = {}; 209 | 210 | WGPURequiredLimits required_limits = {}; 211 | if (descriptor->hasRequiredLimits()) { 212 | dawn_desc.requiredLimits = &required_limits; 213 | GPUSupportedLimits::MakeUndefined(&required_limits); 214 | DOMException* exception = GPUSupportedLimits::Populate( 215 | &required_limits, descriptor->requiredLimits()); 216 | if (exception) { 217 | resolver->Reject(exception); 218 | return promise; 219 | } 220 | } 221 | 222 | Vector required_features; 223 | if (descriptor->hasRequiredFeatures()) { 224 | // Insert features into a set to dedup them. 225 | HashSet required_features_set; 226 | for (const V8GPUFeatureName& f : descriptor->requiredFeatures()) { 227 | // If the feature is not a valid feature reject with a type error. 228 | if (!features_->has(f.AsEnum())) { 229 | resolver->RejectWithTypeError( 230 | String::Format("Unsupported feature: %s", f.AsCStr())); 231 | return promise; 232 | } 233 | required_features_set.insert(AsDawnEnum(f)); 234 | } 235 | 236 | // Then, push the deduped features into a vector. 237 | required_features.AppendRange(required_features_set.begin(), 238 | required_features_set.end()); 239 | dawn_desc.requiredFeatures = required_features.data(); 240 | dawn_desc.requiredFeaturesCount = required_features.size(); 241 | } 242 | 243 | auto* callback = BindWGPUOnceCallback( 244 | &GPUAdapter::OnRequestDeviceCallback, WrapPersistent(this), 245 | WrapPersistent(script_state), WrapPersistent(resolver), 246 | WrapPersistent(descriptor)); 247 | 248 | GetProcs().adapterRequestDevice( 249 | handle_, &dawn_desc, callback->UnboundCallback(), callback->AsUserdata()); 250 | EnsureFlush(ToEventLoop(script_state)); 251 | 252 | return promise; 253 | } 254 | 255 | ScriptPromise GPUAdapter::requestAdapterInfo( 256 | ScriptState* script_state, 257 | const Vector& unmask_hints) { 258 | auto* resolver = MakeGarbageCollected(script_state); 259 | ScriptPromise promise = resolver->Promise(); 260 | 261 | // If any unmask hints have been given, the method must also have been called 262 | // during user activation. If not, reject the promise. 263 | if (unmask_hints.size()) { 264 | LocalDOMWindow* domWindow = gpu_->DomWindow(); 265 | if (!domWindow || 266 | !LocalFrame::HasTransientUserActivation(domWindow->GetFrame())) { 267 | resolver->Reject(MakeGarbageCollected( 268 | DOMExceptionCode::kNotAllowedError, 269 | "requestAdapterInfo requires user activation if any unmaskHints are " 270 | "given.")); 271 | return promise; 272 | } 273 | 274 | // TODO(crbug.com/1405528): Handling unmask hints is not yet supported. 275 | resolver->Reject(MakeGarbageCollected( 276 | DOMExceptionCode::kNotSupportedError, 277 | "Passing unmaskHints to requestAdapterInfo is not yet implemented. In " 278 | "the future, doing so may trigger a permissions prompt.")); 279 | 280 | return promise; 281 | } 282 | 283 | GPUAdapterInfo* adapter_info; 284 | if (RuntimeEnabledFeatures::WebGPUDeveloperFeaturesEnabled()) { 285 | // If WebGPU developer features have been enabled then provide unmasked 286 | // versions of all available adapter info values, including some that are 287 | // only available when the flag is enabled. 288 | adapter_info = MakeGarbageCollected( 289 | vendor_, architecture_, device_, description_, driver_); 290 | } else { 291 | // TODO(dawn:1427): If unmask_hints are given ask the user for consent to 292 | // expose more information and, if given, include device_ and description_ 293 | // in the returned GPUAdapterInfo. 294 | adapter_info = MakeGarbageCollected(vendor_, architecture_); 295 | } 296 | adapter_info = fpRequestAdapterInfo(adapter_info,RuntimeEnabledFeatures::WebGPUDeveloperFeaturesEnabled()); 297 | resolver->Resolve(adapter_info); 298 | 299 | return promise; 300 | } 301 | 302 | void GPUAdapter::Trace(Visitor* visitor) const { 303 | visitor->Trace(gpu_); 304 | visitor->Trace(features_); 305 | visitor->Trace(limits_); 306 | ScriptWrappable::Trace(visitor); 307 | } 308 | 309 | } // namespace blink 310 | -------------------------------------------------------------------------------- /third_party/blink/renderer/modules/webgpu/gpu_adapter_fp.h: -------------------------------------------------------------------------------- 1 | #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_WEBGPU_GPU_ADAPTER_FP_H_ 2 | #define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBGPU_GPU_ADAPTER_FP_H_ 3 | 4 | #include "base/singleton_fingerprint.h" 5 | #include "third_party/blink/public/common/fingerprint/fingerprint.h" 6 | 7 | #include "third_party/blink/renderer/modules/webgpu/gpu_adapter_info.h" 8 | #include "third_party/blink/renderer/platform/heap/garbage_collected.h" 9 | #include "third_party/blink/renderer/platform/wtf/text/wtf_string.h" 10 | 11 | blink::GPUAdapterInfo* fpRequestAdapterInfo(blink::GPUAdapterInfo* adapter_info,bool flag){ 12 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 13 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 14 | if(base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.webGLDevice.type>1){ 15 | blink::GPUAdapterInfo* T_adapter_info; 16 | 17 | if (flag) { 18 | T_adapter_info = blink::MakeGarbageCollected( 19 | WTF::String(t_fingerprint.webGLDevice.gpuVendors.c_str(), t_fingerprint.webGLDevice.gpuVendors.length()), 20 | WTF::String(t_fingerprint.webGLDevice.gpuArchitecture.c_str(), t_fingerprint.webGLDevice.gpuArchitecture.length()), 21 | adapter_info->device(), adapter_info->description(), adapter_info->driver()); 22 | } else { 23 | T_adapter_info = blink::MakeGarbageCollected( 24 | WTF::String(t_fingerprint.webGLDevice.gpuVendors.c_str(), t_fingerprint.webGLDevice.gpuVendors.length()), 25 | WTF::String(t_fingerprint.webGLDevice.gpuArchitecture.c_str(), t_fingerprint.webGLDevice.gpuArchitecture.length()) 26 | ); 27 | } 28 | return T_adapter_info; 29 | } 30 | 31 | return adapter_info; 32 | 33 | } 34 | 35 | #endif // THIRD_PARTY_BLINK_RENDERER_MODULES_WEBGPU_GPU_ADAPTER_FP_H_ 36 | -------------------------------------------------------------------------------- /third_party/blink/renderer/modules/webgpu/gpu_command_encoder_fp.h: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Chromium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_WEBGPU_GPU_COMMAND_ENCODER_FP_H_ 6 | #define THIRD_PARTY_BLINK_RENDERER_MODULES_WEBGPU_GPU_COMMAND_ENCODER_FP_H_ 7 | 8 | void fpCopyTextureToBuffer(){ //todo 9 | // 暂时发现api可以直接读取临时暂存 10 | // const void* map_data_const = getProcs.bufferGetConstMappedRange(handle, 0, range_size); 11 | // if (!map_data_const) { 12 | // return; 13 | // } 14 | // uint8_t* map_data =const_cast(static_cast(map_data_const)); 15 | 16 | } 17 | 18 | #endif // THIRD_PARTY_BLINK_RENDERER_MODULES_WEBGPU_GPU_COMMAND_ENCODER_FP_H_ 19 | -------------------------------------------------------------------------------- /third_party/blink/renderer/platform/fonts/win/font_cache_skia_win_fp.h: -------------------------------------------------------------------------------- 1 | #ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_FONTS_WIN_FONT_CACHE_SKIA_WIN_FP_H_ 2 | #define THIRD_PARTY_BLINK_RENDERER_PLATFORM_FONTS_WIN_FONT_CACHE_SKIA_WIN_FP_H_ 3 | 4 | #include "base/singleton_fingerprint.h" 5 | #include "third_party/blink/public/common/fingerprint/fingerprint.h" 6 | #include "third_party/blink/renderer/platform/fonts/font_selection_types.h" 7 | 8 | 9 | void fpCreateFontPlatformData(blink::FontSelectionValue& variant_stretch, 10 | blink::FontSelectionValue Tvariant_stretch, 11 | std::string fontName ) { 12 | 13 | base::SingletonFingerprint* t_singletonFingerprint =base::SingletonFingerprint::ForCurrentProcess(); 14 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 15 | if (base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.font.type > 1) { 16 | base::flat_map fontMap =t_fingerprint.font.fontMap; 17 | std::transform(fontName.begin(), fontName.end(), fontName.begin(),::tolower); 18 | auto iter = fontMap.find(fontName); 19 | if (iter == fontMap.end()) { 20 | variant_stretch = Tvariant_stretch; 21 | } 22 | 23 | } 24 | 25 | } 26 | 27 | 28 | #endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_FONTS_WIN_FONT_CACHE_SKIA_WIN_FP_H_ 29 | -------------------------------------------------------------------------------- /third_party/webrtc/pc/fp_web_rtc.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef PC_FP_WEB_RTC_H_ 3 | #define PC_FP_WEB_RTC_H_ 4 | 5 | #include "rtc_base/socket_address.h" 6 | #include "rtc_base/ip_address.h" 7 | #include "rtc_base/string_encode.h" 8 | #include "p2p/base/ice_transport_internal.h" 9 | #include "third_party/blink/public/common/fingerprint/fingerprint.h" 10 | #include "base/singleton_fingerprint.h" 11 | 12 | 13 | cricket::Candidates FpWebRtc(const cricket::Candidates& candidates){ 14 | if(candidates.empty()||candidates.size()<1){ 15 | return candidates; 16 | } 17 | 18 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 19 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 20 | if(base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.webRTC.type==2){ 21 | 22 | cricket::Candidates candidates_proxy; 23 | for (const cricket::Candidate& candidate : candidates) { 24 | cricket::Candidate candidate2=cricket::Candidate(candidate); 25 | 26 | if(!candidate.related_address().IsNil()){ 27 | rtc::IPAddress ip_address; 28 | if (rtc::IPFromString(t_fingerprint.webRTC.publicIp, &ip_address)) { 29 | candidate2.set_address(rtc::SocketAddress(ip_address, candidate.address().port())); 30 | 31 | } 32 | rtc::IPAddress related_address; 33 | if (rtc::IPFromString(t_fingerprint.webRTC.privateIp, &related_address)) { 34 | candidate2.set_related_address(rtc::SocketAddress(related_address, candidate.related_address().port())); 35 | 36 | } 37 | }else{ 38 | rtc::IPAddress ip_address; 39 | if (rtc::IPFromString(t_fingerprint.webRTC.privateIp, &ip_address)) { 40 | candidate2.set_address(rtc::SocketAddress(ip_address, candidate.address().port())); 41 | 42 | } 43 | } 44 | candidates_proxy.push_back(candidate2); 45 | } 46 | return candidates_proxy; 47 | 48 | }else{ 49 | return candidates; 50 | } 51 | 52 | 53 | 54 | 55 | 56 | 57 | } 58 | #endif // PC_FP_WEB_RTC_H_ -------------------------------------------------------------------------------- /ui/views/win/fp_resolution.h: -------------------------------------------------------------------------------- 1 | #ifndef UI_VIEWS_WIN_FP_RESOLUTION_H_ 2 | #define UI_VIEWS_WIN_FP_RESOLUTION_H_ 3 | 4 | #include "ui/gfx/geometry/rect.h" 5 | #include "third_party/blink/public/common/fingerprint/fingerprint.h" 6 | #include "base/singleton_fingerprint.h" 7 | 8 | void fpMonitorAndRects(gfx::Rect* monitor_rect,gfx::Rect* work_area){ 9 | 10 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 11 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 12 | if(base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.resolution.type>1){ 13 | monitor_rect->set_width(t_fingerprint.resolution.monitorWidth); 14 | monitor_rect->set_height(t_fingerprint.resolution.monitorHeight); 15 | work_area->set_width(t_fingerprint.resolution.windowWidth); 16 | work_area->set_height(t_fingerprint.resolution.windowHeight); 17 | } 18 | 19 | } 20 | 21 | void pfIsFullscreen(gfx::Rect& monitor_rect) { 22 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 23 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 24 | if (base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.resolution.type > 1) { 25 | monitor_rect.set_width(t_fingerprint.resolution.monitorWidth); 26 | monitor_rect.set_height(t_fingerprint.resolution.monitorHeight); 27 | 28 | } 29 | } 30 | 31 | void pfIsMaximized(gfx::Rect& work_rect) { 32 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 33 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 34 | if (base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.resolution.type > 1) { 35 | work_rect.set_width(t_fingerprint.resolution.windowWidth); 36 | work_rect.set_height(t_fingerprint.resolution.windowHeight); 37 | } 38 | 39 | } 40 | 41 | void fpWindowPosChanging(WINDOWPOS* window_pos){ 42 | 43 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 44 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 45 | base::SingletonFingerprint::GetInit(t_singletonFingerprint); 46 | if (base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.resolution.type > 1) { 47 | 48 | if (window_pos->cx > t_fingerprint.resolution.windowWidth || window_pos->cy > t_fingerprint.resolution.windowHeight) { 49 | window_pos->cx = t_fingerprint.resolution.windowWidth; 50 | window_pos->cy = t_fingerprint.resolution.windowHeight; 51 | } 52 | 53 | } 54 | 55 | 56 | } 57 | 58 | 59 | #endif // UI_VIEWS_WIN_FP_RESOLUTION_H_ -------------------------------------------------------------------------------- /ui/views/win/fp_resolution_full_screen.h: -------------------------------------------------------------------------------- 1 | #ifndef UI_VIEWS_WIN_FP_RESOLUTION_FULL_SCREEN_H_ 2 | #define UI_VIEWS_WIN_FP_RESOLUTION_FULL_SCREEN_H_ 3 | 4 | #include "ui/gfx/geometry/rect.h" 5 | #include "third_party/blink/public/common/fingerprint/fingerprint.h" 6 | #include "base/singleton_fingerprint.h" 7 | 8 | void fpProcessFullscreen(gfx::Rect& window_rect){ 9 | 10 | base::SingletonFingerprint* t_singletonFingerprint = base::SingletonFingerprint::ForCurrentProcess(); 11 | blink::fp::Fingerprint t_fingerprint = t_singletonFingerprint->GetFingerprint(); 12 | if(base::SingletonFingerprint::GetInit(t_singletonFingerprint) && t_fingerprint.resolution.type>1){ 13 | window_rect.set_width(t_fingerprint.resolution.monitorWidth); 14 | window_rect.set_height(t_fingerprint.resolution.monitorHeight); 15 | } 16 | 17 | } 18 | 19 | 20 | #endif // UI_VIEWS_WIN_FP_RESOLUTION_FULL_SCREEN_H_ -------------------------------------------------------------------------------- /ui/views/win/fullscreen_handler.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Chromium Authors 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "ui/views/win/fullscreen_handler.h" 6 | 7 | #include 8 | 9 | #include "base/win/win_util.h" 10 | #include "ui/display/types/display_constants.h" 11 | #include "ui/display/win/screen_win.h" 12 | #include "ui/display/win/screen_win_display.h" 13 | #include "ui/gfx/geometry/rect.h" 14 | #include "ui/views/win/scoped_fullscreen_visibility.h" 15 | #include "ui/views/win/fp_resolution_full_screen.h" 16 | 17 | namespace views { 18 | 19 | //////////////////////////////////////////////////////////////////////////////// 20 | // FullscreenHandler, public: 21 | 22 | FullscreenHandler::FullscreenHandler() = default; 23 | 24 | FullscreenHandler::~FullscreenHandler() = default; 25 | 26 | void FullscreenHandler::SetFullscreen(bool fullscreen, 27 | int64_t target_display_id) { 28 | if (fullscreen_ == fullscreen && 29 | target_display_id == display::kInvalidDisplayId) { 30 | return; 31 | } 32 | 33 | ProcessFullscreen(fullscreen, target_display_id); 34 | } 35 | 36 | void FullscreenHandler::MarkFullscreen(bool fullscreen) { 37 | if (!task_bar_list_) { 38 | HRESULT hr = 39 | ::CoCreateInstance(CLSID_TaskbarList, nullptr, CLSCTX_INPROC_SERVER, 40 | IID_PPV_ARGS(&task_bar_list_)); 41 | if (SUCCEEDED(hr) && FAILED(task_bar_list_->HrInit())) 42 | task_bar_list_ = nullptr; 43 | } 44 | 45 | // As per MSDN marking the window as fullscreen should ensure that the 46 | // taskbar is moved to the bottom of the Z-order when the fullscreen window 47 | // is activated. If the window is not fullscreen, the Shell falls back to 48 | // heuristics to determine how the window should be treated, which means 49 | // that it could still consider the window as fullscreen. :( 50 | if (task_bar_list_) 51 | task_bar_list_->MarkFullscreenWindow(hwnd_, !!fullscreen); 52 | } 53 | 54 | gfx::Rect FullscreenHandler::GetRestoreBounds() const { 55 | return gfx::Rect(saved_window_info_.rect); 56 | } 57 | 58 | //////////////////////////////////////////////////////////////////////////////// 59 | // FullscreenHandler, private: 60 | 61 | void FullscreenHandler::ProcessFullscreen(bool fullscreen, 62 | int64_t target_display_id) { 63 | std::unique_ptr visibility; 64 | 65 | // Save current window state if not already fullscreen. 66 | if (!fullscreen_) { 67 | saved_window_info_.style = GetWindowLong(hwnd_, GWL_STYLE); 68 | saved_window_info_.ex_style = GetWindowLong(hwnd_, GWL_EXSTYLE); 69 | // Store the original window rect, DPI, and monitor info to detect changes 70 | // and more accurately restore window placements when exiting fullscreen. 71 | ::GetWindowRect(hwnd_, &saved_window_info_.rect); 72 | saved_window_info_.dpi = display::win::ScreenWin::GetDPIForHWND(hwnd_); 73 | saved_window_info_.monitor = 74 | MonitorFromWindow(hwnd_, MONITOR_DEFAULTTONEAREST); 75 | saved_window_info_.monitor_info.cbSize = 76 | sizeof(saved_window_info_.monitor_info); 77 | GetMonitorInfo(saved_window_info_.monitor, 78 | &saved_window_info_.monitor_info); 79 | } 80 | 81 | fullscreen_ = fullscreen; 82 | 83 | auto ref = weak_ptr_factory_.GetWeakPtr(); 84 | if (fullscreen_) { 85 | // Set new window style and size. 86 | SetWindowLong(hwnd_, GWL_STYLE, 87 | saved_window_info_.style & ~(WS_CAPTION | WS_THICKFRAME)); 88 | SetWindowLong( 89 | hwnd_, GWL_EXSTYLE, 90 | saved_window_info_.ex_style & ~(WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE | 91 | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE)); 92 | 93 | // Set the window rect to the rcMonitor of the targeted or current display. 94 | const display::win::ScreenWinDisplay screen_win_display = 95 | display::win::ScreenWin::GetScreenWinDisplayWithDisplayId( 96 | target_display_id); 97 | gfx::Rect window_rect = screen_win_display.screen_rect(); 98 | if (target_display_id == display::kInvalidDisplayId || 99 | screen_win_display.display().id() != target_display_id) { 100 | HMONITOR monitor = MonitorFromWindow(hwnd_, MONITOR_DEFAULTTONEAREST); 101 | MONITORINFO monitor_info; 102 | monitor_info.cbSize = sizeof(monitor_info); 103 | GetMonitorInfo(monitor, &monitor_info); 104 | window_rect = gfx::Rect(monitor_info.rcMonitor); 105 | } 106 | fpProcessFullscreen(window_rect); 107 | SetWindowPos(hwnd_, nullptr, window_rect.x(), window_rect.y(), 108 | window_rect.width(), window_rect.height(), 109 | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED); 110 | } else { 111 | // Restore the window style and bounds saved prior to entering fullscreen. 112 | // Making multiple window adjustments here is ugly, but if SetWindowPos() 113 | // doesn't redraw, the taskbar won't be repainted. 114 | SetWindowLong(hwnd_, GWL_STYLE, saved_window_info_.style); 115 | SetWindowLong(hwnd_, GWL_EXSTYLE, saved_window_info_.ex_style); 116 | 117 | gfx::Rect window_rect(saved_window_info_.rect); 118 | HMONITOR monitor = 119 | MonitorFromRect(&saved_window_info_.rect, MONITOR_DEFAULTTONEAREST); 120 | MONITORINFO monitor_info; 121 | monitor_info.cbSize = sizeof(monitor_info); 122 | GetMonitorInfo(monitor, &monitor_info); 123 | // Adjust the window bounds to restore, if displays were disconnected, 124 | // virtually rearranged, or otherwise changed metrics during fullscreen. 125 | if (monitor != saved_window_info_.monitor || 126 | gfx::Rect(saved_window_info_.monitor_info.rcWork) != 127 | gfx::Rect(monitor_info.rcWork)) { 128 | window_rect.AdjustToFit(gfx::Rect(monitor_info.rcWork)); 129 | } 130 | const int fullscreen_dpi = display::win::ScreenWin::GetDPIForHWND(hwnd_); 131 | 132 | SetWindowPos(hwnd_, nullptr, window_rect.x(), window_rect.y(), 133 | window_rect.width(), window_rect.height(), 134 | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED); 135 | 136 | const int final_dpi = display::win::ScreenWin::GetDPIForHWND(hwnd_); 137 | if (final_dpi != saved_window_info_.dpi || final_dpi != fullscreen_dpi) { 138 | // Reissue SetWindowPos if the DPI changed from saved or fullscreen DPIs. 139 | // The first call may misinterpret bounds spanning displays, if the 140 | // fullscreen display's DPI does not match the target display's DPI. 141 | // 142 | // Scale and clamp the bounds if the final DPI changed from the saved DPI. 143 | // This more accurately matches the original placement, while avoiding 144 | // unexpected offscreen placement in a recongifured multi-screen space. 145 | if (final_dpi != saved_window_info_.dpi) { 146 | gfx::SizeF size(window_rect.size()); 147 | size.Scale(final_dpi / static_cast(saved_window_info_.dpi)); 148 | window_rect.set_size(gfx::ToCeiledSize(size)); 149 | window_rect.AdjustToFit(gfx::Rect(monitor_info.rcWork)); 150 | } 151 | SetWindowPos(hwnd_, nullptr, window_rect.x(), window_rect.y(), 152 | window_rect.width(), window_rect.height(), 153 | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED); 154 | } 155 | } 156 | if (!ref) 157 | return; 158 | 159 | MarkFullscreen(fullscreen); 160 | } 161 | 162 | } // namespace views 163 | --------------------------------------------------------------------------------