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

Side by Side Diff: Source/core/inspector/InspectorCSSAgent.cpp

Issue 203113002: Revert of Reapply 169354 "DevTools: track stylesheets by document, not local frame" (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010, Google Inc. All rights reserved. 2 * Copyright (C) 2010, 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 void InspectorCSSAgent::restore() 428 void InspectorCSSAgent::restore()
429 { 429 {
430 if (m_state->getBoolean(CSSAgentState::cssAgentEnabled)) 430 if (m_state->getBoolean(CSSAgentState::cssAgentEnabled))
431 wasEnabled(nullptr); 431 wasEnabled(nullptr);
432 } 432 }
433 433
434 void InspectorCSSAgent::reset() 434 void InspectorCSSAgent::reset()
435 { 435 {
436 m_idToInspectorStyleSheet.clear(); 436 m_idToInspectorStyleSheet.clear();
437 m_cssStyleSheetToInspectorStyleSheet.clear(); 437 m_cssStyleSheetToInspectorStyleSheet.clear();
438 m_documentToCSSStyleSheets.clear(); 438 m_frameToCSSStyleSheets.clear();
439 m_nodeToInspectorStyleSheet.clear(); 439 m_nodeToInspectorStyleSheet.clear();
440 m_documentToViaInspectorStyleSheet.clear(); 440 m_documentToViaInspectorStyleSheet.clear();
441 resetNonPersistentData(); 441 resetNonPersistentData();
442 } 442 }
443 443
444 void InspectorCSSAgent::resetNonPersistentData() 444 void InspectorCSSAgent::resetNonPersistentData()
445 { 445 {
446 resetPseudoStates(); 446 resetPseudoStates();
447 } 447 }
448 448
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 483
484 void InspectorCSSAgent::wasEnabled(PassRefPtr<EnableCallback> callback) 484 void InspectorCSSAgent::wasEnabled(PassRefPtr<EnableCallback> callback)
485 { 485 {
486 if (!m_state->getBoolean(CSSAgentState::cssAgentEnabled)) { 486 if (!m_state->getBoolean(CSSAgentState::cssAgentEnabled)) {
487 // We were disabled while fetching resources. 487 // We were disabled while fetching resources.
488 return; 488 return;
489 } 489 }
490 490
491 m_instrumentingAgents->setInspectorCSSAgent(this); 491 m_instrumentingAgents->setInspectorCSSAgent(this);
492 Vector<Document*> documents = m_domAgent->documents(); 492 Vector<Document*> documents = m_domAgent->documents();
493 for (Vector<Document*>::iterator it = documents.begin(); it != documents.end (); ++it) 493 for (Vector<Document*>::iterator it = documents.begin(); it != documents.end (); ++it) {
494 updateActiveStyleSheets(*it, InitialFrontendLoad); 494 Document* document = *it;
495 updateActiveStyleSheetsForDocument(document, InitialFrontendLoad);
496 }
495 497
496 if (callback) 498 if (callback)
497 callback->sendSuccess(); 499 callback->sendSuccess();
498 } 500 }
499 501
500 void InspectorCSSAgent::disable(ErrorString*) 502 void InspectorCSSAgent::disable(ErrorString*)
501 { 503 {
502 m_instrumentingAgents->setInspectorCSSAgent(0); 504 m_instrumentingAgents->setInspectorCSSAgent(0);
503 m_state->setBoolean(CSSAgentState::cssAgentEnabled, false); 505 m_state->setBoolean(CSSAgentState::cssAgentEnabled, false);
504 } 506 }
505 507
506 void InspectorCSSAgent::didCommitLoad(LocalFrame* frame, DocumentLoader* loader) 508 void InspectorCSSAgent::didCommitLoad(LocalFrame* frame, DocumentLoader* loader)
507 { 509 {
508 if (loader->frame() == frame->page()->mainFrame()) { 510 if (loader->frame() == frame->page()->mainFrame()) {
509 reset(); 511 reset();
510 return; 512 return;
511 } 513 }
512 514
513 Vector<Document*> toDispose; 515 updateActiveStyleSheets(frame, Vector<CSSStyleSheet*>(), ExistingFrontendRef resh);
514 for (DocumentStyleSheets::iterator it = m_documentToCSSStyleSheets.begin(); it != m_documentToCSSStyleSheets.end(); ++it) {
515 Document* document = it->key;
516 if (!document->frame() || document->frame() == frame)
517 toDispose.append(document);
518 }
519 for (Vector<Document*>::iterator it = toDispose.begin(); it != toDispose.end (); ++it)
520 documentDisposed(*it);
521 } 516 }
522 517
523 void InspectorCSSAgent::mediaQueryResultChanged() 518 void InspectorCSSAgent::mediaQueryResultChanged()
524 { 519 {
525 if (m_frontend) 520 if (m_frontend)
526 m_frontend->mediaQueryResultChanged(); 521 m_frontend->mediaQueryResultChanged();
527 } 522 }
528 523
529 void InspectorCSSAgent::willMutateRules() 524 void InspectorCSSAgent::willMutateRules()
530 { 525 {
(...skipping 26 matching lines...) Expand all
557 Document* owner = parentSheet ? parentSheet->ownerDocument() : 0; 552 Document* owner = parentSheet ? parentSheet->ownerDocument() : 0;
558 if (owner) 553 if (owner)
559 owner->modifiedStyleSheet(parentSheet, RecalcStyleDeferred, FullStyl eUpdate); 554 owner->modifiedStyleSheet(parentSheet, RecalcStyleDeferred, FullStyl eUpdate);
560 } 555 }
561 } 556 }
562 557
563 void InspectorCSSAgent::activeStyleSheetsUpdated(Document* document) 558 void InspectorCSSAgent::activeStyleSheetsUpdated(Document* document)
564 { 559 {
565 if (styleSheetEditInProgress()) 560 if (styleSheetEditInProgress())
566 return; 561 return;
567 updateActiveStyleSheets(document, ExistingFrontendRefresh); 562 updateActiveStyleSheetsForDocument(document, ExistingFrontendRefresh);
568 } 563 }
569 564
570 void InspectorCSSAgent::updateActiveStyleSheets(Document* document, StyleSheetsU pdateType styleSheetsUpdateType) 565 void InspectorCSSAgent::updateActiveStyleSheetsForDocument(Document* document, S tyleSheetsUpdateType styleSheetsUpdateType)
571 { 566 {
567 LocalFrame* frame = document->frame();
568 if (!frame)
569 return;
572 Vector<CSSStyleSheet*> newSheetsVector; 570 Vector<CSSStyleSheet*> newSheetsVector;
573 collectAllDocumentStyleSheets(document, newSheetsVector); 571 collectAllDocumentStyleSheets(document, newSheetsVector);
574 setActiveStyleSheets(document, newSheetsVector, styleSheetsUpdateType); 572 updateActiveStyleSheets(frame, newSheetsVector, styleSheetsUpdateType);
575 } 573 }
576 574
577 void InspectorCSSAgent::setActiveStyleSheets(Document* document, const Vector<CS SStyleSheet*>& allSheetsVector, StyleSheetsUpdateType styleSheetsUpdateType) 575 void InspectorCSSAgent::updateActiveStyleSheets(LocalFrame* frame, const Vector< CSSStyleSheet*>& allSheetsVector, StyleSheetsUpdateType styleSheetsUpdateType)
578 { 576 {
579 bool isInitialFrontendLoad = styleSheetsUpdateType == InitialFrontendLoad; 577 bool isInitialFrontendLoad = styleSheetsUpdateType == InitialFrontendLoad;
580 578
581 HashSet<CSSStyleSheet*>* documentCSSStyleSheets = m_documentToCSSStyleSheets .get(document); 579 HashSet<CSSStyleSheet*>* frameCSSStyleSheets = m_frameToCSSStyleSheets.get(f rame);
582 if (!documentCSSStyleSheets) { 580 if (!frameCSSStyleSheets) {
583 documentCSSStyleSheets = new HashSet<CSSStyleSheet*>(); 581 frameCSSStyleSheets = new HashSet<CSSStyleSheet*>();
584 OwnPtr<HashSet<CSSStyleSheet*> > documentCSSStyleSheetsPtr = adoptPtr(do cumentCSSStyleSheets); 582 OwnPtr<HashSet<CSSStyleSheet*> > frameCSSStyleSheetsPtr = adoptPtr(frame CSSStyleSheets);
585 m_documentToCSSStyleSheets.set(document, documentCSSStyleSheetsPtr.relea se()); 583 m_frameToCSSStyleSheets.set(frame, frameCSSStyleSheetsPtr.release());
586 } 584 }
587 585
588 HashSet<CSSStyleSheet*> removedSheets(*documentCSSStyleSheets); 586 HashSet<CSSStyleSheet*> removedSheets;
587 for (HashSet<CSSStyleSheet*>::iterator it = frameCSSStyleSheets->begin(); it != frameCSSStyleSheets->end(); ++it)
588 removedSheets.add(*it);
589 589
590 HashSet<CSSStyleSheet*> addedSheets; 590 HashSet<CSSStyleSheet*> addedSheets;
591 for (Vector<CSSStyleSheet*>::const_iterator it = allSheetsVector.begin(); it != allSheetsVector.end(); ++it) { 591 for (Vector<CSSStyleSheet*>::const_iterator it = allSheetsVector.begin(); it != allSheetsVector.end(); ++it) {
592 CSSStyleSheet* cssStyleSheet = *it; 592 CSSStyleSheet* cssStyleSheet = *it;
593 if (removedSheets.contains(cssStyleSheet)) { 593 if (removedSheets.contains(cssStyleSheet)) {
594 removedSheets.remove(cssStyleSheet); 594 removedSheets.remove(cssStyleSheet);
595 if (isInitialFrontendLoad) 595 if (isInitialFrontendLoad)
596 addedSheets.add(cssStyleSheet); 596 addedSheets.add(cssStyleSheet);
597 } else { 597 } else {
598 addedSheets.add(cssStyleSheet); 598 addedSheets.add(cssStyleSheet);
599 } 599 }
600 } 600 }
601 601
602 for (HashSet<CSSStyleSheet*>::iterator it = removedSheets.begin(); it != rem ovedSheets.end(); ++it) { 602 for (HashSet<CSSStyleSheet*>::iterator it = removedSheets.begin(); it != rem ovedSheets.end(); ++it) {
603 CSSStyleSheet* cssStyleSheet = *it; 603 CSSStyleSheet* cssStyleSheet = *it;
604 RefPtr<InspectorStyleSheet> inspectorStyleSheet = m_cssStyleSheetToInspe ctorStyleSheet.get(cssStyleSheet); 604 RefPtr<InspectorStyleSheet> inspectorStyleSheet = m_cssStyleSheetToInspe ctorStyleSheet.get(cssStyleSheet);
605 ASSERT(inspectorStyleSheet); 605 ASSERT(inspectorStyleSheet);
606 606
607 documentCSSStyleSheets->remove(cssStyleSheet);
608 if (m_idToInspectorStyleSheet.contains(inspectorStyleSheet->id())) { 607 if (m_idToInspectorStyleSheet.contains(inspectorStyleSheet->id())) {
609 String id = unbindStyleSheet(inspectorStyleSheet.get()); 608 String id = unbindStyleSheet(inspectorStyleSheet.get());
609 frameCSSStyleSheets->remove(cssStyleSheet);
610 if (m_frontend && !isInitialFrontendLoad) 610 if (m_frontend && !isInitialFrontendLoad)
611 m_frontend->styleSheetRemoved(id); 611 m_frontend->styleSheetRemoved(id);
612 } 612 }
613 } 613 }
614 614
615 for (HashSet<CSSStyleSheet*>::iterator it = addedSheets.begin(); it != added Sheets.end(); ++it) { 615 for (HashSet<CSSStyleSheet*>::iterator it = addedSheets.begin(); it != added Sheets.end(); ++it) {
616 CSSStyleSheet* cssStyleSheet = *it; 616 CSSStyleSheet* cssStyleSheet = *it;
617 bool isNew = isInitialFrontendLoad || !m_cssStyleSheetToInspectorStyleSh eet.contains(cssStyleSheet); 617 bool isNew = isInitialFrontendLoad || !m_cssStyleSheetToInspectorStyleSh eet.contains(cssStyleSheet);
618 if (isNew) { 618 if (isNew) {
619 InspectorStyleSheet* newStyleSheet = bindStyleSheet(cssStyleSheet); 619 InspectorStyleSheet* newStyleSheet = bindStyleSheet(cssStyleSheet);
620 documentCSSStyleSheets->add(cssStyleSheet); 620 frameCSSStyleSheets->add(cssStyleSheet);
621 if (m_frontend) 621 if (m_frontend)
622 m_frontend->styleSheetAdded(newStyleSheet->buildObjectForStyleSh eetInfo()); 622 m_frontend->styleSheetAdded(newStyleSheet->buildObjectForStyleSh eetInfo());
623 } 623 }
624 } 624 }
625 625
626 if (documentCSSStyleSheets->isEmpty()) 626 if (frameCSSStyleSheets->isEmpty())
627 m_documentToCSSStyleSheets.remove(document); 627 m_frameToCSSStyleSheets.remove(frame);
628 }
629
630 void InspectorCSSAgent::documentDisposed(Document* document)
631 {
632 setActiveStyleSheets(document, Vector<CSSStyleSheet*>(), ExistingFrontendRef resh);
633 } 628 }
634 629
635 void InspectorCSSAgent::frameDetachedFromParent(LocalFrame* frame) 630 void InspectorCSSAgent::frameDetachedFromParent(LocalFrame* frame)
636 { 631 {
637 documentDisposed(frame->document()); 632 updateActiveStyleSheets(frame, Vector<CSSStyleSheet*>(), ExistingFrontendRef resh);
638 } 633 }
639 634
640 bool InspectorCSSAgent::forcePseudoState(Element* element, CSSSelector::PseudoTy pe pseudoType) 635 bool InspectorCSSAgent::forcePseudoState(Element* element, CSSSelector::PseudoTy pe pseudoType)
641 { 636 {
642 if (m_nodeIdToForcedPseudoState.isEmpty()) 637 if (m_nodeIdToForcedPseudoState.isEmpty())
643 return false; 638 return false;
644 639
645 int nodeId = m_domAgent->boundNodeId(element); 640 int nodeId = m_domAgent->boundNodeId(element);
646 if (!nodeId) 641 if (!nodeId)
647 return false; 642 return false;
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 documentsToChange.add(element->ownerDocument()); 1337 documentsToChange.add(element->ownerDocument());
1343 } 1338 }
1344 1339
1345 m_nodeIdToForcedPseudoState.clear(); 1340 m_nodeIdToForcedPseudoState.clear();
1346 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu mentsToChange.end(); it != end; ++it) 1341 for (HashSet<Document*>::iterator it = documentsToChange.begin(), end = docu mentsToChange.end(); it != end; ++it)
1347 (*it)->setNeedsStyleRecalc(SubtreeStyleChange); 1342 (*it)->setNeedsStyleRecalc(SubtreeStyleChange);
1348 } 1343 }
1349 1344
1350 } // namespace WebCore 1345 } // namespace WebCore
1351 1346
OLDNEW
« no previous file with comments | « Source/core/inspector/InspectorCSSAgent.h ('k') | Source/core/inspector/InspectorInstrumentation.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698