Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 603 return document_ ? document_->GetSecurityOrigin() : nullptr; | 603 return document_ ? document_->GetSecurityOrigin() : nullptr; |
| 604 } | 604 } |
| 605 | 605 |
| 606 void FrameFetchContext::ModifyRequestForCSP(ResourceRequest& resource_request) { | 606 void FrameFetchContext::ModifyRequestForCSP(ResourceRequest& resource_request) { |
| 607 // Record the latest requiredCSP value that will be used when sending this | 607 // Record the latest requiredCSP value that will be used when sending this |
| 608 // request. | 608 // request. |
| 609 GetFrame()->Loader().RecordLatestRequiredCSP(); | 609 GetFrame()->Loader().RecordLatestRequiredCSP(); |
| 610 GetFrame()->Loader().ModifyRequestForCSP(resource_request, GetDocument()); | 610 GetFrame()->Loader().ModifyRequestForCSP(resource_request, GetDocument()); |
| 611 } | 611 } |
| 612 | 612 |
| 613 float FrameFetchContext::ClientHintsDeviceRAM(int64_t physical_memory_mb) { | |
| 614 // TODO(fmeawad): The calculations in this method are still evolving as the | |
| 615 // spec gets updated: https://github.com/WICG/device-ram. The reported | |
| 616 // device-ram is rounded down to next power of 2 in GB. Ex. 3072MB will return | |
| 617 // 2, and 768MB will return 0.5. | |
| 618 DCHECK_GT(physical_memory_mb, 0); | |
| 619 int power = 0; // To compensate of the extra loop iteration. | |
|
Yoav Weiss
2017/05/26 20:48:15
The "compensate" comment seems out of place now
fmeawad
2017/05/30 17:20:59
Done.
| |
| 620 // Extract the MSB location. | |
| 621 while (physical_memory_mb > 1) { | |
| 622 physical_memory_mb >>= 1; | |
| 623 power++; | |
| 624 } | |
| 625 // Restore to the power of 2, and convert to GB. | |
| 626 return static_cast<float>(1 << power) / 1024.0; | |
| 627 } | |
| 628 | |
| 613 void FrameFetchContext::AddClientHintsIfNecessary( | 629 void FrameFetchContext::AddClientHintsIfNecessary( |
| 614 const ClientHintsPreferences& hints_preferences, | 630 const ClientHintsPreferences& hints_preferences, |
| 615 const FetchParameters::ResourceWidth& resource_width, | 631 const FetchParameters::ResourceWidth& resource_width, |
| 616 ResourceRequest& request) { | 632 ResourceRequest& request) { |
| 617 if (!RuntimeEnabledFeatures::clientHintsEnabled() || !GetDocument()) | 633 if (!RuntimeEnabledFeatures::clientHintsEnabled() || !GetDocument()) |
| 618 return; | 634 return; |
| 619 | 635 |
| 636 bool should_send_device_ram = | |
| 637 GetDocument()->GetClientHintsPreferences().ShouldSendDeviceRAM() || | |
| 638 hints_preferences.ShouldSendDeviceRAM(); | |
| 620 bool should_send_dpr = | 639 bool should_send_dpr = |
| 621 GetDocument()->GetClientHintsPreferences().ShouldSendDPR() || | 640 GetDocument()->GetClientHintsPreferences().ShouldSendDPR() || |
| 622 hints_preferences.ShouldSendDPR(); | 641 hints_preferences.ShouldSendDPR(); |
| 623 bool should_send_resource_width = | 642 bool should_send_resource_width = |
| 624 GetDocument()->GetClientHintsPreferences().ShouldSendResourceWidth() || | 643 GetDocument()->GetClientHintsPreferences().ShouldSendResourceWidth() || |
| 625 hints_preferences.ShouldSendResourceWidth(); | 644 hints_preferences.ShouldSendResourceWidth(); |
| 626 bool should_send_viewport_width = | 645 bool should_send_viewport_width = |
| 627 GetDocument()->GetClientHintsPreferences().ShouldSendViewportWidth() || | 646 GetDocument()->GetClientHintsPreferences().ShouldSendViewportWidth() || |
| 628 hints_preferences.ShouldSendViewportWidth(); | 647 hints_preferences.ShouldSendViewportWidth(); |
| 629 | 648 |
| 649 if (should_send_device_ram) { | |
| 650 int64_t physical_memory = MemoryCoordinator::GetPhysicalMemoryMB(); | |
| 651 request.AddHTTPHeaderField( | |
| 652 "device-ram", | |
| 653 AtomicString(String::Number(ClientHintsDeviceRAM(physical_memory)))); | |
| 654 } | |
| 655 | |
| 630 if (should_send_dpr) { | 656 if (should_send_dpr) { |
| 631 request.AddHTTPHeaderField( | 657 request.AddHTTPHeaderField( |
| 632 "DPR", AtomicString(String::Number(GetDocument()->DevicePixelRatio()))); | 658 "DPR", AtomicString(String::Number(GetDocument()->DevicePixelRatio()))); |
| 633 } | 659 } |
| 634 | 660 |
| 635 if (should_send_resource_width) { | 661 if (should_send_resource_width) { |
| 636 if (resource_width.is_set) { | 662 if (resource_width.is_set) { |
| 637 float physical_width = | 663 float physical_width = |
| 638 resource_width.width * GetDocument()->DevicePixelRatio(); | 664 resource_width.width * GetDocument()->DevicePixelRatio(); |
| 639 request.AddHTTPHeaderField( | 665 request.AddHTTPHeaderField( |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 806 return GetFrame()->CreateURLLoader(); | 832 return GetFrame()->CreateURLLoader(); |
| 807 } | 833 } |
| 808 | 834 |
| 809 DEFINE_TRACE(FrameFetchContext) { | 835 DEFINE_TRACE(FrameFetchContext) { |
| 810 visitor->Trace(document_loader_); | 836 visitor->Trace(document_loader_); |
| 811 visitor->Trace(document_); | 837 visitor->Trace(document_); |
| 812 BaseFetchContext::Trace(visitor); | 838 BaseFetchContext::Trace(visitor); |
| 813 } | 839 } |
| 814 | 840 |
| 815 } // namespace blink | 841 } // namespace blink |
| OLD | NEW |