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

Side by Side Diff: Source/core/frame/UseCounter.cpp

Issue 707333003: Update UsageCounter methods to be callable on Frames. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add missing null check Created 6 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/frame/UseCounter.h ('k') | no next file » | 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 /* 2 /*
3 * Copyright (C) 2012 Google, Inc. All rights reserved. 3 * Copyright (C) 2012 Google, Inc. All rights reserved.
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 13 matching lines...) Expand all
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 #include "config.h" 27 #include "config.h"
28 #include "core/frame/UseCounter.h" 28 #include "core/frame/UseCounter.h"
29 29
30 #include "core/css/CSSStyleSheet.h" 30 #include "core/css/CSSStyleSheet.h"
31 #include "core/css/StyleSheetContents.h" 31 #include "core/css/StyleSheetContents.h"
32 #include "core/dom/Document.h" 32 #include "core/dom/Document.h"
33 #include "core/dom/ExecutionContext.h" 33 #include "core/dom/ExecutionContext.h"
34 #include "core/frame/LocalDOMWindow.h"
35 #include "core/frame/FrameConsole.h" 34 #include "core/frame/FrameConsole.h"
36 #include "core/frame/FrameHost.h" 35 #include "core/frame/FrameHost.h"
37 #include "core/frame/LocalFrame.h" 36 #include "core/frame/LocalFrame.h"
38 #include "core/inspector/ConsoleMessage.h" 37 #include "core/inspector/ConsoleMessage.h"
39 #include "core/workers/WorkerGlobalScope.h" 38 #include "core/workers/WorkerGlobalScope.h"
40 #include "public/platform/Platform.h" 39 #include "public/platform/Platform.h"
41 40
42 namespace blink { 41 namespace blink {
43 42
44 static int totalPagesMeasuredCSSSampleId() { return 1; } 43 static int totalPagesMeasuredCSSSampleId() { return 1; }
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 blink::Platform::current()->histogramEnumeration("WebCore.FeatureObserve r.CSSProperties", totalPagesMeasuredCSSSampleId(), maximumCSSSampleId()); 569 blink::Platform::current()->histogramEnumeration("WebCore.FeatureObserve r.CSSProperties", totalPagesMeasuredCSSSampleId(), maximumCSSSampleId());
571 570
572 m_CSSFeatureBits.clearAll(); 571 m_CSSFeatureBits.clearAll();
573 } 572 }
574 573
575 void UseCounter::didCommitLoad() 574 void UseCounter::didCommitLoad()
576 { 575 {
577 updateMeasurements(); 576 updateMeasurements();
578 } 577 }
579 578
580 void UseCounter::count(const Document& document, Feature feature) 579 void UseCounter::count(const Frame* frame, Feature feature)
581 { 580 {
582 FrameHost* host = document.frameHost(); 581 if (!frame)
582 return;
583 FrameHost* host = frame->host();
583 if (!host) 584 if (!host)
584 return; 585 return;
585 586
586 ASSERT(host->useCounter().deprecationMessage(feature).isEmpty()); 587 ASSERT(host->useCounter().deprecationMessage(feature).isEmpty());
587 host->useCounter().recordMeasurement(feature); 588 host->useCounter().recordMeasurement(feature);
588 } 589 }
589 590
591 void UseCounter::count(const Document& document, Feature feature)
592 {
593 count(document.frame(), feature);
594 }
595
590 void UseCounter::count(const ExecutionContext* context, Feature feature) 596 void UseCounter::count(const ExecutionContext* context, Feature feature)
591 { 597 {
592 if (!context) 598 if (!context)
593 return; 599 return;
594 if (context->isDocument()) { 600 if (context->isDocument()) {
595 count(*toDocument(context), feature); 601 count(*toDocument(context), feature);
596 return; 602 return;
597 } 603 }
598 if (context->isWorkerGlobalScope()) 604 if (context->isWorkerGlobalScope())
599 toWorkerGlobalScope(context)->countFeature(feature); 605 toWorkerGlobalScope(context)->countFeature(feature);
600 } 606 }
601 607
608 void UseCounter::countIfNotPrivateScript(v8::Isolate* isolate, const Frame* fram e, Feature feature)
609 {
610 if (DOMWrapperWorld::current(isolate).isPrivateScriptIsolatedWorld())
611 return;
612 UseCounter::count(frame, feature);
613 }
614
602 void UseCounter::countIfNotPrivateScript(v8::Isolate* isolate, const Document& d ocument, Feature feature) 615 void UseCounter::countIfNotPrivateScript(v8::Isolate* isolate, const Document& d ocument, Feature feature)
603 { 616 {
604 if (DOMWrapperWorld::current(isolate).isPrivateScriptIsolatedWorld()) 617 if (DOMWrapperWorld::current(isolate).isPrivateScriptIsolatedWorld())
605 return; 618 return;
606 UseCounter::count(document, feature); 619 UseCounter::count(document, feature);
607 } 620 }
608 621
609 void UseCounter::countIfNotPrivateScript(v8::Isolate* isolate, const ExecutionCo ntext* context, Feature feature) 622 void UseCounter::countIfNotPrivateScript(v8::Isolate* isolate, const ExecutionCo ntext* context, Feature feature)
610 { 623 {
611 if (DOMWrapperWorld::current(isolate).isPrivateScriptIsolatedWorld()) 624 if (DOMWrapperWorld::current(isolate).isPrivateScriptIsolatedWorld())
612 return; 625 return;
613 UseCounter::count(context, feature); 626 UseCounter::count(context, feature);
614 } 627 }
615 628
629 void UseCounter::countDeprecation(const LocalFrame* frame, Feature feature)
630 {
631 if (!frame)
632 return;
633 FrameHost* host = frame->host();
634 if (!host)
635 return;
636
637 if (host->useCounter().recordMeasurement(feature)) {
638 ASSERT(!host->useCounter().deprecationMessage(feature).isEmpty());
639 frame->console().addMessage(ConsoleMessage::create(DeprecationMessageSou rce, WarningMessageLevel, host->useCounter().deprecationMessage(feature)));
640 }
641 }
642
616 void UseCounter::countDeprecation(ExecutionContext* context, Feature feature) 643 void UseCounter::countDeprecation(ExecutionContext* context, Feature feature)
617 { 644 {
618 if (!context) 645 if (!context)
619 return; 646 return;
620 if (context->isDocument()) { 647 if (context->isDocument()) {
621 UseCounter::countDeprecation(*toDocument(context), feature); 648 UseCounter::countDeprecation(*toDocument(context), feature);
622 return; 649 return;
623 } 650 }
624 if (context->isWorkerGlobalScope()) 651 if (context->isWorkerGlobalScope())
625 toWorkerGlobalScope(context)->countDeprecation(feature); 652 toWorkerGlobalScope(context)->countDeprecation(feature);
626 } 653 }
627 654
628 void UseCounter::countDeprecation(const LocalDOMWindow* window, Feature feature)
629 {
630 if (!window || !window->document())
631 return;
632 UseCounter::countDeprecation(*window->document(), feature);
633 }
634
635 void UseCounter::countDeprecation(const Document& document, Feature feature) 655 void UseCounter::countDeprecation(const Document& document, Feature feature)
636 { 656 {
637 FrameHost* host = document.frameHost(); 657 UseCounter::countDeprecation(document.frame(), feature);
638 LocalFrame* frame = document.frame();
639 if (!host || !frame)
640 return;
641
642 if (host->useCounter().recordMeasurement(feature)) {
643 ASSERT(!host->useCounter().deprecationMessage(feature).isEmpty());
644 frame->console().addMessage(ConsoleMessage::create(DeprecationMessageSou rce, WarningMessageLevel, host->useCounter().deprecationMessage(feature)));
645 }
646 } 658 }
647 659
648 void UseCounter::countDeprecationIfNotPrivateScript(v8::Isolate* isolate, Execut ionContext* context, Feature feature) 660 void UseCounter::countDeprecationIfNotPrivateScript(v8::Isolate* isolate, Execut ionContext* context, Feature feature)
649 { 661 {
650 if (DOMWrapperWorld::current(isolate).isPrivateScriptIsolatedWorld()) 662 if (DOMWrapperWorld::current(isolate).isPrivateScriptIsolatedWorld())
651 return; 663 return;
652 UseCounter::countDeprecation(context, feature); 664 UseCounter::countDeprecation(context, feature);
653 } 665 }
654 666
655 // FIXME: Update other UseCounter::deprecationMessage() cases to use this. 667 // FIXME: Update other UseCounter::deprecationMessage() cases to use this.
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 UseCounter* UseCounter::getFrom(const StyleSheetContents* sheetContents) 863 UseCounter* UseCounter::getFrom(const StyleSheetContents* sheetContents)
852 { 864 {
853 // FIXME: We may want to handle stylesheets that have multiple owners 865 // FIXME: We may want to handle stylesheets that have multiple owners
854 // http://crbug.com/242125 866 // http://crbug.com/242125
855 if (sheetContents && sheetContents->hasSingleOwnerNode()) 867 if (sheetContents && sheetContents->hasSingleOwnerNode())
856 return getFrom(sheetContents->singleOwnerDocument()); 868 return getFrom(sheetContents->singleOwnerDocument());
857 return 0; 869 return 0;
858 } 870 }
859 871
860 } // namespace blink 872 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/frame/UseCounter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698