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

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

Issue 1092123004: DevTools: remove dependency of most agents on InspectorPageAgent (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: further cuts on InspectorPageAgent inter-agents API Created 5 years, 8 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) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 return TextResourceDecoder::create("text/html", "UTF-8"); 192 return TextResourceDecoder::create("text/html", "UTF-8");
193 if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType) || DOMImplemen tation::isJSONMIMEType(mimeType)) 193 if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType) || DOMImplemen tation::isJSONMIMEType(mimeType))
194 return TextResourceDecoder::create("text/plain", "UTF-8"); 194 return TextResourceDecoder::create("text/plain", "UTF-8");
195 if (DOMImplementation::isTextMIMEType(mimeType)) 195 if (DOMImplementation::isTextMIMEType(mimeType))
196 return TextResourceDecoder::create("text/plain", "ISO-8859-1"); 196 return TextResourceDecoder::create("text/plain", "ISO-8859-1");
197 return PassOwnPtr<TextResourceDecoder>(); 197 return PassOwnPtr<TextResourceDecoder>();
198 } 198 }
199 199
200 static void resourceContent(ErrorString* errorString, LocalFrame* frame, const K URL& url, String* result, bool* base64Encoded) 200 static void resourceContent(ErrorString* errorString, LocalFrame* frame, const K URL& url, String* result, bool* base64Encoded)
201 { 201 {
202 DocumentLoader* loader = InspectorPageAgent::assertDocumentLoader(errorStrin g, frame);
203 if (!loader)
204 return;
205
206 if (!InspectorPageAgent::cachedResourceContent(InspectorPageAgent::cachedRes ource(frame, url), result, base64Encoded)) 202 if (!InspectorPageAgent::cachedResourceContent(InspectorPageAgent::cachedRes ource(frame, url), result, base64Encoded))
207 *errorString = "No resource with given URL found"; 203 *errorString = "No resource with given URL found";
208 } 204 }
209 205
210 static bool encodeCachedResourceContent(Resource* cachedResource, bool hasZeroSi ze, String* result, bool* base64Encoded) 206 static bool encodeCachedResourceContent(Resource* cachedResource, bool hasZeroSi ze, String* result, bool* base64Encoded)
211 { 207 {
212 *base64Encoded = true; 208 *base64Encoded = true;
213 RefPtr<SharedBuffer> buffer = hasZeroSize ? SharedBuffer::create() : cachedR esource->resourceBuffer(); 209 RefPtr<SharedBuffer> buffer = hasZeroSize ? SharedBuffer::create() : cachedR esource->resourceBuffer();
214 210
215 if (!buffer) 211 if (!buffer)
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 } 385 }
390 } 386 }
391 387
392 void InspectorPageAgent::enable(ErrorString*) 388 void InspectorPageAgent::enable(ErrorString*)
393 { 389 {
394 m_enabled = true; 390 m_enabled = true;
395 m_state->setBoolean(PageAgentState::pageAgentEnabled, true); 391 m_state->setBoolean(PageAgentState::pageAgentEnabled, true);
396 m_instrumentingAgents->setInspectorPageAgent(this); 392 m_instrumentingAgents->setInspectorPageAgent(this);
397 if (m_inspectorResourceContentLoader) 393 if (m_inspectorResourceContentLoader)
398 m_inspectorResourceContentLoader->dispose(); 394 m_inspectorResourceContentLoader->dispose();
399 m_inspectorResourceContentLoader = adoptPtrWillBeNoop(new InspectorResourceC ontentLoader(inspectedFrame())); 395 m_inspectorResourceContentLoader = adoptPtrWillBeNoop(new InspectorResourceC ontentLoader(m_inspectedFrame));
400 } 396 }
401 397
402 void InspectorPageAgent::discardAgent() 398 void InspectorPageAgent::discardAgent()
403 { 399 {
404 if (!m_inspectorResourceContentLoader) 400 if (!m_inspectorResourceContentLoader)
405 return; 401 return;
406 m_inspectorResourceContentLoader->dispose(); 402 m_inspectorResourceContentLoader->dispose();
407 m_inspectorResourceContentLoader.clear(); 403 m_inspectorResourceContentLoader.clear();
408 } 404 }
409 405
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 } 447 }
452 scripts->remove(identifier); 448 scripts->remove(identifier);
453 } 449 }
454 450
455 void InspectorPageAgent::reload(ErrorString*, const bool* const optionalIgnoreCa che, const String* optionalScriptToEvaluateOnLoad) 451 void InspectorPageAgent::reload(ErrorString*, const bool* const optionalIgnoreCa che, const String* optionalScriptToEvaluateOnLoad)
456 { 452 {
457 m_pendingScriptToEvaluateOnLoadOnce = optionalScriptToEvaluateOnLoad ? *opti onalScriptToEvaluateOnLoad : ""; 453 m_pendingScriptToEvaluateOnLoadOnce = optionalScriptToEvaluateOnLoad ? *opti onalScriptToEvaluateOnLoad : "";
458 ErrorString unused; 454 ErrorString unused;
459 m_debuggerAgent->setSkipAllPauses(&unused, true); 455 m_debuggerAgent->setSkipAllPauses(&unused, true);
460 m_reloading = true; 456 m_reloading = true;
461 inspectedFrame()->reload(asBool(optionalIgnoreCache) ? EndToEndReload : Norm alReload, NotClientRedirect); 457 m_inspectedFrame->reload(asBool(optionalIgnoreCache) ? EndToEndReload : Norm alReload, NotClientRedirect);
462 } 458 }
463 459
464 void InspectorPageAgent::navigate(ErrorString*, const String& url, String* outFr ameId) 460 void InspectorPageAgent::navigate(ErrorString*, const String& url, String* outFr ameId)
465 { 461 {
466 *outFrameId = frameId(inspectedFrame()); 462 *outFrameId = frameId(m_inspectedFrame);
467 } 463 }
468 464
469 static void cachedResourcesForDocument(Document* document, Vector<Resource*>& re sult, bool skipXHRs) 465 static void cachedResourcesForDocument(Document* document, Vector<Resource*>& re sult, bool skipXHRs)
470 { 466 {
471 const ResourceFetcher::DocumentResourceMap& allResources = document->fetcher ()->allResources(); 467 const ResourceFetcher::DocumentResourceMap& allResources = document->fetcher ()->allResources();
472 for (const auto& resource : allResources) { 468 for (const auto& resource : allResources) {
473 Resource* cachedResource = resource.value.get(); 469 Resource* cachedResource = resource.value.get();
474 470
475 switch (cachedResource->type()) { 471 switch (cachedResource->type()) {
476 case Resource::Image: 472 case Resource::Image:
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 516
521 cachedResourcesForDocument(rootDocument, result, skipXHRs); 517 cachedResourcesForDocument(rootDocument, result, skipXHRs);
522 for (size_t i = 0; i < loaders.size(); ++i) 518 for (size_t i = 0; i < loaders.size(); ++i)
523 cachedResourcesForDocument(loaders[i], result, skipXHRs); 519 cachedResourcesForDocument(loaders[i], result, skipXHRs);
524 520
525 return result; 521 return result;
526 } 522 }
527 523
528 void InspectorPageAgent::getResourceTree(ErrorString*, RefPtr<TypeBuilder::Page: :FrameResourceTree>& object) 524 void InspectorPageAgent::getResourceTree(ErrorString*, RefPtr<TypeBuilder::Page: :FrameResourceTree>& object)
529 { 525 {
530 object = buildObjectForFrameTree(inspectedFrame()); 526 object = buildObjectForFrameTree(m_inspectedFrame);
531 } 527 }
532 528
533 void InspectorPageAgent::finishReload() 529 void InspectorPageAgent::finishReload()
534 { 530 {
535 if (!m_reloading) 531 if (!m_reloading)
536 return; 532 return;
537 m_reloading = false; 533 m_reloading = false;
538 ErrorString unused; 534 ErrorString unused;
539 m_debuggerAgent->setSkipAllPauses(&unused, false); 535 m_debuggerAgent->setSkipAllPauses(&unused, false);
540 } 536 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 if (script.value->asString(&scriptText)) 630 if (script.value->asString(&scriptText))
635 frame->script().executeScriptInMainWorld(scriptText); 631 frame->script().executeScriptInMainWorld(scriptText);
636 } 632 }
637 } 633 }
638 if (!m_scriptToEvaluateOnLoadOnce.isEmpty()) 634 if (!m_scriptToEvaluateOnLoadOnce.isEmpty())
639 frame->script().executeScriptInMainWorld(m_scriptToEvaluateOnLoadOnce); 635 frame->script().executeScriptInMainWorld(m_scriptToEvaluateOnLoadOnce);
640 } 636 }
641 637
642 void InspectorPageAgent::domContentLoadedEventFired(LocalFrame* frame) 638 void InspectorPageAgent::domContentLoadedEventFired(LocalFrame* frame)
643 { 639 {
644 if (frame != inspectedFrame()) 640 if (frame != m_inspectedFrame)
645 return; 641 return;
646 frontend()->domContentEventFired(monotonicallyIncreasingTime()); 642 frontend()->domContentEventFired(monotonicallyIncreasingTime());
647 } 643 }
648 644
649 void InspectorPageAgent::loadEventFired(LocalFrame* frame) 645 void InspectorPageAgent::loadEventFired(LocalFrame* frame)
650 { 646 {
651 if (frame != inspectedFrame()) 647 if (frame != m_inspectedFrame)
652 return; 648 return;
653 frontend()->loadEventFired(monotonicallyIncreasingTime()); 649 frontend()->loadEventFired(monotonicallyIncreasingTime());
654 } 650 }
655 651
656 void InspectorPageAgent::didCommitLoad(LocalFrame*, DocumentLoader* loader) 652 void InspectorPageAgent::didCommitLoad(LocalFrame*, DocumentLoader* loader)
657 { 653 {
658 if (loader->frame() == inspectedFrame()) { 654 if (loader->frame() == m_inspectedFrame) {
659 finishReload(); 655 finishReload();
660 m_scriptToEvaluateOnLoadOnce = m_pendingScriptToEvaluateOnLoadOnce; 656 m_scriptToEvaluateOnLoadOnce = m_pendingScriptToEvaluateOnLoadOnce;
661 m_pendingScriptToEvaluateOnLoadOnce = String(); 657 m_pendingScriptToEvaluateOnLoadOnce = String();
662 if (m_inspectorResourceContentLoader) 658 if (m_inspectorResourceContentLoader)
663 m_inspectorResourceContentLoader->stop(); 659 m_inspectorResourceContentLoader->stop();
664 } 660 }
665 frontend()->frameNavigated(buildObjectForFrame(loader->frame())); 661 frontend()->frameNavigated(buildObjectForFrame(loader->frame()));
666 } 662 }
667 663
668 void InspectorPageAgent::frameAttachedToParent(LocalFrame* frame) 664 void InspectorPageAgent::frameAttachedToParent(LocalFrame* frame)
669 { 665 {
670 Frame* parentFrame = frame->tree().parent(); 666 Frame* parentFrame = frame->tree().parent();
671 if (!parentFrame->isLocalFrame()) 667 if (!parentFrame->isLocalFrame())
672 parentFrame = 0; 668 parentFrame = 0;
673 frontend()->frameAttached(frameId(frame), frameId(toLocalFrame(parentFrame)) ); 669 frontend()->frameAttached(frameId(frame), frameId(toLocalFrame(parentFrame)) );
674 } 670 }
675 671
676 void InspectorPageAgent::frameDetachedFromParent(LocalFrame* frame) 672 void InspectorPageAgent::frameDetachedFromParent(LocalFrame* frame)
677 { 673 {
678 frontend()->frameDetached(frameId(frame)); 674 frontend()->frameDetached(frameId(frame));
679 } 675 }
680 676
681 FrameHost* InspectorPageAgent::frameHost()
682 {
683 return m_inspectedFrame->host();
684 }
685
686 LocalFrame* InspectorPageAgent::frameForId(const String& frameId) 677 LocalFrame* InspectorPageAgent::frameForId(const String& frameId)
687 { 678 {
688 LocalFrame* frame = InspectorIdentifiers<LocalFrame>::lookup(frameId); 679 LocalFrame* frame = InspectorIdentifiers<LocalFrame>::lookup(frameId);
689 return frame && frame->instrumentingAgents() == m_inspectedFrame->instrument ingAgents() ? frame : nullptr; 680 return frame && frame->instrumentingAgents() == m_inspectedFrame->instrument ingAgents() ? frame : nullptr;
690 } 681 }
691 682
692 LocalFrame* InspectorPageAgent::findFrameWithSecurityOrigin(const String& origin RawString) 683 LocalFrame* InspectorPageAgent::findFrameWithSecurityOrigin(const String& origin RawString)
693 { 684 {
694 for (Frame* frame = inspectedFrame(); frame; frame = frame->tree().traverseN ext(inspectedFrame())) { 685 for (Frame* frame = m_inspectedFrame; frame; frame = frame->tree().traverseN ext(m_inspectedFrame)) {
695 if (!frame->isLocalFrame()) 686 if (!frame->isLocalFrame())
696 continue; 687 continue;
697 RefPtr<SecurityOrigin> documentOrigin = toLocalFrame(frame)->document()- >securityOrigin(); 688 RefPtr<SecurityOrigin> documentOrigin = toLocalFrame(frame)->document()- >securityOrigin();
698 if (documentOrigin->toRawString() == originRawString) 689 if (documentOrigin->toRawString() == originRawString)
699 return toLocalFrame(frame); 690 return toLocalFrame(frame);
700 } 691 }
701 return nullptr; 692 return nullptr;
702 } 693 }
703 694
704 LocalFrame* InspectorPageAgent::assertFrame(ErrorString* errorString, const Stri ng& frameId) 695 LocalFrame* InspectorPageAgent::assertFrame(ErrorString* errorString, const Stri ng& frameId)
705 { 696 {
706 LocalFrame* frame = frameForId(frameId); 697 LocalFrame* frame = frameForId(frameId);
707 if (!frame) 698 if (!frame)
708 *errorString = "No frame for given id found"; 699 *errorString = "No frame for given id found";
709 return frame; 700 return frame;
710 } 701 }
711 702
712 bool InspectorPageAgent::screencastEnabled() 703 bool InspectorPageAgent::screencastEnabled()
713 { 704 {
714 return m_enabled && m_state->getBoolean(PageAgentState::screencastEnabled); 705 return m_enabled && m_state->getBoolean(PageAgentState::screencastEnabled);
715 } 706 }
716 707
717 // static
718 DocumentLoader* InspectorPageAgent::assertDocumentLoader(ErrorString* errorStrin g, LocalFrame* frame)
719 {
720 DocumentLoader* documentLoader = frame->loader().documentLoader();
721 if (!documentLoader)
722 *errorString = "No documentLoader for given frame found";
723 return documentLoader;
724 }
725
726 void InspectorPageAgent::frameStartedLoading(LocalFrame* frame) 708 void InspectorPageAgent::frameStartedLoading(LocalFrame* frame)
727 { 709 {
728 frontend()->frameStartedLoading(frameId(frame)); 710 frontend()->frameStartedLoading(frameId(frame));
729 } 711 }
730 712
731 void InspectorPageAgent::frameStoppedLoading(LocalFrame* frame) 713 void InspectorPageAgent::frameStoppedLoading(LocalFrame* frame)
732 { 714 {
733 frontend()->frameStoppedLoading(frameId(frame)); 715 frontend()->frameStoppedLoading(frameId(frame));
734 } 716 }
735 717
(...skipping 25 matching lines...) Expand all
761 } 743 }
762 744
763 void InspectorPageAgent::didScroll() 745 void InspectorPageAgent::didScroll()
764 { 746 {
765 if (m_enabled) 747 if (m_enabled)
766 m_overlay->update(); 748 m_overlay->update();
767 } 749 }
768 750
769 void InspectorPageAgent::didResizeMainFrame() 751 void InspectorPageAgent::didResizeMainFrame()
770 { 752 {
771 if (!inspectedFrame()->isMainFrame()) 753 if (!m_inspectedFrame->isMainFrame())
772 return; 754 return;
773 #if !OS(ANDROID) 755 #if !OS(ANDROID)
774 if (m_enabled && m_state->getBoolean(PageAgentState::showSizeOnResize)) 756 if (m_enabled && m_state->getBoolean(PageAgentState::showSizeOnResize))
775 m_overlay->showAndHideViewSize(m_state->getBoolean(PageAgentState::showG ridOnResize)); 757 m_overlay->showAndHideViewSize(m_state->getBoolean(PageAgentState::showG ridOnResize));
776 #endif 758 #endif
777 frontend()->frameResized(); 759 frontend()->frameResized();
778 } 760 }
779 761
780 void InspectorPageAgent::didRecalculateStyle(int) 762 void InspectorPageAgent::didRecalculateStyle(int)
781 { 763 {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 { 855 {
874 visitor->trace(m_inspectedFrame); 856 visitor->trace(m_inspectedFrame);
875 visitor->trace(m_debuggerAgent); 857 visitor->trace(m_debuggerAgent);
876 visitor->trace(m_cssAgent); 858 visitor->trace(m_cssAgent);
877 visitor->trace(m_overlay); 859 visitor->trace(m_overlay);
878 visitor->trace(m_inspectorResourceContentLoader); 860 visitor->trace(m_inspectorResourceContentLoader);
879 InspectorBaseAgent::trace(visitor); 861 InspectorBaseAgent::trace(visitor);
880 } 862 }
881 863
882 } // namespace blink 864 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698