Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: third_party/WebKit/Source/core/frame/LocalDOMWindow.cpp

Issue 2610813006: Add UseCounters for alert(), confirm() and prompt() usage against site engagement. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/frame/UseCounter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after
738 738
739 if (document()->isSandboxed(SandboxModals)) { 739 if (document()->isSandboxed(SandboxModals)) {
740 UseCounter::count(document(), UseCounter::DialogInSandboxedContext); 740 UseCounter::count(document(), UseCounter::DialogInSandboxedContext);
741 frameConsole()->addMessage(ConsoleMessage::create( 741 frameConsole()->addMessage(ConsoleMessage::create(
742 SecurityMessageSource, ErrorMessageLevel, 742 SecurityMessageSource, ErrorMessageLevel,
743 "Ignored call to 'alert()'. The document is sandboxed, and the " 743 "Ignored call to 'alert()'. The document is sandboxed, and the "
744 "'allow-modals' keyword is not set.")); 744 "'allow-modals' keyword is not set."));
745 return; 745 return;
746 } 746 }
747 747
748 switch (document()->getEngagementLevel()) {
749 case mojom::blink::EngagementLevel::NONE:
750 UseCounter::count(document(), UseCounter::AlertEngagementNone);
751 break;
752 case mojom::blink::EngagementLevel::MINIMAL:
753 UseCounter::count(document(), UseCounter::AlertEngagementMinimal);
754 break;
755 case mojom::blink::EngagementLevel::LOW:
756 UseCounter::count(document(), UseCounter::AlertEngagementLow);
757 break;
758 case mojom::blink::EngagementLevel::MEDIUM:
759 UseCounter::count(document(), UseCounter::AlertEngagementMedium);
760 break;
761 case mojom::blink::EngagementLevel::HIGH:
762 UseCounter::count(document(), UseCounter::AlertEngagementHigh);
763 break;
764 case mojom::blink::EngagementLevel::MAX:
765 UseCounter::count(document(), UseCounter::AlertEngagementMax);
766 break;
767 }
768
748 if (v8::MicrotasksScope::IsRunningMicrotasks(scriptState->isolate())) { 769 if (v8::MicrotasksScope::IsRunningMicrotasks(scriptState->isolate())) {
749 UseCounter::count(document(), UseCounter::During_Microtask_Alert); 770 UseCounter::count(document(), UseCounter::During_Microtask_Alert);
750 } 771 }
751 772
752 document()->updateStyleAndLayoutTree(); 773 document()->updateStyleAndLayoutTree();
753 774
754 FrameHost* host = frame()->host(); 775 FrameHost* host = frame()->host();
755 if (!host) 776 if (!host)
756 return; 777 return;
757 778
758 UseCounter::countCrossOriginIframe(*document(), 779 UseCounter::countCrossOriginIframe(*document(),
759 UseCounter::CrossOriginWindowAlert); 780 UseCounter::CrossOriginWindowAlert);
760 781
761 host->chromeClient().openJavaScriptAlert(frame(), message); 782 host->chromeClient().openJavaScriptAlert(frame(), message);
762 } 783 }
763 784
764 bool LocalDOMWindow::confirm(ScriptState* scriptState, const String& message) { 785 bool LocalDOMWindow::confirm(ScriptState* scriptState, const String& message) {
765 if (!frame()) 786 if (!frame())
766 return false; 787 return false;
767 788
768 if (document()->isSandboxed(SandboxModals)) { 789 if (document()->isSandboxed(SandboxModals)) {
769 UseCounter::count(document(), UseCounter::DialogInSandboxedContext); 790 UseCounter::count(document(), UseCounter::DialogInSandboxedContext);
770 frameConsole()->addMessage(ConsoleMessage::create( 791 frameConsole()->addMessage(ConsoleMessage::create(
771 SecurityMessageSource, ErrorMessageLevel, 792 SecurityMessageSource, ErrorMessageLevel,
772 "Ignored call to 'confirm()'. The document is sandboxed, and the " 793 "Ignored call to 'confirm()'. The document is sandboxed, and the "
773 "'allow-modals' keyword is not set.")); 794 "'allow-modals' keyword is not set."));
774 return false; 795 return false;
775 } 796 }
776 797
798 switch (document()->getEngagementLevel()) {
799 case mojom::blink::EngagementLevel::NONE:
800 UseCounter::count(document(), UseCounter::ConfirmEngagementNone);
801 break;
802 case mojom::blink::EngagementLevel::MINIMAL:
803 UseCounter::count(document(), UseCounter::ConfirmEngagementMinimal);
804 break;
805 case mojom::blink::EngagementLevel::LOW:
806 UseCounter::count(document(), UseCounter::ConfirmEngagementLow);
807 break;
808 case mojom::blink::EngagementLevel::MEDIUM:
809 UseCounter::count(document(), UseCounter::ConfirmEngagementMedium);
810 break;
811 case mojom::blink::EngagementLevel::HIGH:
812 UseCounter::count(document(), UseCounter::ConfirmEngagementHigh);
813 break;
814 case mojom::blink::EngagementLevel::MAX:
815 UseCounter::count(document(), UseCounter::ConfirmEngagementMax);
816 break;
817 }
818
777 if (v8::MicrotasksScope::IsRunningMicrotasks(scriptState->isolate())) { 819 if (v8::MicrotasksScope::IsRunningMicrotasks(scriptState->isolate())) {
778 UseCounter::count(document(), UseCounter::During_Microtask_Confirm); 820 UseCounter::count(document(), UseCounter::During_Microtask_Confirm);
779 } 821 }
780 822
781 document()->updateStyleAndLayoutTree(); 823 document()->updateStyleAndLayoutTree();
782 824
783 FrameHost* host = frame()->host(); 825 FrameHost* host = frame()->host();
784 if (!host) 826 if (!host)
785 return false; 827 return false;
786 828
(...skipping 11 matching lines...) Expand all
798 840
799 if (document()->isSandboxed(SandboxModals)) { 841 if (document()->isSandboxed(SandboxModals)) {
800 UseCounter::count(document(), UseCounter::DialogInSandboxedContext); 842 UseCounter::count(document(), UseCounter::DialogInSandboxedContext);
801 frameConsole()->addMessage(ConsoleMessage::create( 843 frameConsole()->addMessage(ConsoleMessage::create(
802 SecurityMessageSource, ErrorMessageLevel, 844 SecurityMessageSource, ErrorMessageLevel,
803 "Ignored call to 'prompt()'. The document is sandboxed, and the " 845 "Ignored call to 'prompt()'. The document is sandboxed, and the "
804 "'allow-modals' keyword is not set.")); 846 "'allow-modals' keyword is not set."));
805 return String(); 847 return String();
806 } 848 }
807 849
850 switch (document()->getEngagementLevel()) {
851 case mojom::blink::EngagementLevel::NONE:
852 UseCounter::count(document(), UseCounter::PromptEngagementNone);
853 break;
854 case mojom::blink::EngagementLevel::MINIMAL:
855 UseCounter::count(document(), UseCounter::PromptEngagementMinimal);
856 break;
857 case mojom::blink::EngagementLevel::LOW:
858 UseCounter::count(document(), UseCounter::PromptEngagementLow);
859 break;
860 case mojom::blink::EngagementLevel::MEDIUM:
861 UseCounter::count(document(), UseCounter::PromptEngagementMedium);
862 break;
863 case mojom::blink::EngagementLevel::HIGH:
864 UseCounter::count(document(), UseCounter::PromptEngagementHigh);
865 break;
866 case mojom::blink::EngagementLevel::MAX:
867 UseCounter::count(document(), UseCounter::PromptEngagementMax);
868 break;
869 }
870
808 if (v8::MicrotasksScope::IsRunningMicrotasks(scriptState->isolate())) { 871 if (v8::MicrotasksScope::IsRunningMicrotasks(scriptState->isolate())) {
809 UseCounter::count(document(), UseCounter::During_Microtask_Prompt); 872 UseCounter::count(document(), UseCounter::During_Microtask_Prompt);
810 } 873 }
811 874
812 document()->updateStyleAndLayoutTree(); 875 document()->updateStyleAndLayoutTree();
813 876
814 FrameHost* host = frame()->host(); 877 FrameHost* host = frame()->host();
815 if (!host) 878 if (!host)
816 return String(); 879 return String();
817 880
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after
1570 1633
1571 LocalFrame* LocalDOMWindow::frame() const { 1634 LocalFrame* LocalDOMWindow::frame() const {
1572 // If the LocalDOMWindow still has a frame reference, that frame must point 1635 // If the LocalDOMWindow still has a frame reference, that frame must point
1573 // back to this LocalDOMWindow: otherwise, it's easy to get into a situation 1636 // back to this LocalDOMWindow: otherwise, it's easy to get into a situation
1574 // where script execution leaks between different LocalDOMWindows. 1637 // where script execution leaks between different LocalDOMWindows.
1575 SECURITY_DCHECK(!m_frame || m_frame->domWindow() == this); 1638 SECURITY_DCHECK(!m_frame || m_frame->domWindow() == this);
1576 return m_frame; 1639 return m_frame;
1577 } 1640 }
1578 1641
1579 } // namespace blink 1642 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/frame/UseCounter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698