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

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

Issue 1118963002: Revert of DevTools: remove dependency of most agents on InspectorPageAgent (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 7 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
« no previous file with comments | « Source/core/inspector/InspectorPageAgent.h ('k') | Source/core/inspector/InspectorResolver.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) 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 #include "core/html/imports/HTMLImportLoader.h" 49 #include "core/html/imports/HTMLImportLoader.h"
50 #include "core/html/imports/HTMLImportsController.h" 50 #include "core/html/imports/HTMLImportsController.h"
51 #include "core/html/parser/TextResourceDecoder.h" 51 #include "core/html/parser/TextResourceDecoder.h"
52 #include "core/inspector/ContentSearchUtils.h" 52 #include "core/inspector/ContentSearchUtils.h"
53 #include "core/inspector/DOMPatchSupport.h" 53 #include "core/inspector/DOMPatchSupport.h"
54 #include "core/inspector/InspectorCSSAgent.h" 54 #include "core/inspector/InspectorCSSAgent.h"
55 #include "core/inspector/InspectorDebuggerAgent.h" 55 #include "core/inspector/InspectorDebuggerAgent.h"
56 #include "core/inspector/InspectorIdentifiers.h" 56 #include "core/inspector/InspectorIdentifiers.h"
57 #include "core/inspector/InspectorInstrumentation.h" 57 #include "core/inspector/InspectorInstrumentation.h"
58 #include "core/inspector/InspectorOverlay.h" 58 #include "core/inspector/InspectorOverlay.h"
59 #include "core/inspector/InspectorResolver.h"
60 #include "core/inspector/InspectorResourceContentLoader.h" 59 #include "core/inspector/InspectorResourceContentLoader.h"
61 #include "core/inspector/InspectorState.h" 60 #include "core/inspector/InspectorState.h"
62 #include "core/inspector/InstrumentingAgents.h" 61 #include "core/inspector/InstrumentingAgents.h"
63 #include "core/loader/DocumentLoader.h" 62 #include "core/loader/DocumentLoader.h"
64 #include "core/loader/FrameLoader.h" 63 #include "core/loader/FrameLoader.h"
65 #include "platform/JSONValues.h" 64 #include "platform/JSONValues.h"
66 #include "platform/MIMETypeRegistry.h" 65 #include "platform/MIMETypeRegistry.h"
67 #include "platform/PlatformResourceLoader.h" 66 #include "platform/PlatformResourceLoader.h"
68 #include "platform/UserGestureIndicator.h" 67 #include "platform/UserGestureIndicator.h"
69 #include "platform/weborigin/SecurityOrigin.h" 68 #include "platform/weborigin/SecurityOrigin.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 return TextResourceDecoder::create("text/html", "UTF-8"); 192 return TextResourceDecoder::create("text/html", "UTF-8");
194 if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType) || DOMImplemen tation::isJSONMIMEType(mimeType)) 193 if (MIMETypeRegistry::isSupportedJavaScriptMIMEType(mimeType) || DOMImplemen tation::isJSONMIMEType(mimeType))
195 return TextResourceDecoder::create("text/plain", "UTF-8"); 194 return TextResourceDecoder::create("text/plain", "UTF-8");
196 if (DOMImplementation::isTextMIMEType(mimeType)) 195 if (DOMImplementation::isTextMIMEType(mimeType))
197 return TextResourceDecoder::create("text/plain", "ISO-8859-1"); 196 return TextResourceDecoder::create("text/plain", "ISO-8859-1");
198 return PassOwnPtr<TextResourceDecoder>(); 197 return PassOwnPtr<TextResourceDecoder>();
199 } 198 }
200 199
201 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)
202 { 201 {
202 DocumentLoader* loader = InspectorPageAgent::assertDocumentLoader(errorStrin g, frame);
203 if (!loader)
204 return;
205
203 if (!InspectorPageAgent::cachedResourceContent(InspectorPageAgent::cachedRes ource(frame, url), result, base64Encoded)) 206 if (!InspectorPageAgent::cachedResourceContent(InspectorPageAgent::cachedRes ource(frame, url), result, base64Encoded))
204 *errorString = "No resource with given URL found"; 207 *errorString = "No resource with given URL found";
205 } 208 }
206 209
207 static bool encodeCachedResourceContent(Resource* cachedResource, bool hasZeroSi ze, String* result, bool* base64Encoded) 210 static bool encodeCachedResourceContent(Resource* cachedResource, bool hasZeroSi ze, String* result, bool* base64Encoded)
208 { 211 {
209 *base64Encoded = true; 212 *base64Encoded = true;
210 RefPtr<SharedBuffer> buffer = hasZeroSize ? SharedBuffer::create() : cachedR esource->resourceBuffer(); 213 RefPtr<SharedBuffer> buffer = hasZeroSize ? SharedBuffer::create() : cachedR esource->resourceBuffer();
211 214
212 if (!buffer) 215 if (!buffer)
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 } 389 }
387 } 390 }
388 391
389 void InspectorPageAgent::enable(ErrorString*) 392 void InspectorPageAgent::enable(ErrorString*)
390 { 393 {
391 m_enabled = true; 394 m_enabled = true;
392 m_state->setBoolean(PageAgentState::pageAgentEnabled, true); 395 m_state->setBoolean(PageAgentState::pageAgentEnabled, true);
393 m_instrumentingAgents->setInspectorPageAgent(this); 396 m_instrumentingAgents->setInspectorPageAgent(this);
394 if (m_inspectorResourceContentLoader) 397 if (m_inspectorResourceContentLoader)
395 m_inspectorResourceContentLoader->dispose(); 398 m_inspectorResourceContentLoader->dispose();
396 m_inspectorResourceContentLoader = adoptPtrWillBeNoop(new InspectorResourceC ontentLoader(m_inspectedFrame)); 399 m_inspectorResourceContentLoader = adoptPtrWillBeNoop(new InspectorResourceC ontentLoader(inspectedFrame()));
397 } 400 }
398 401
399 void InspectorPageAgent::discardAgent() 402 void InspectorPageAgent::discardAgent()
400 { 403 {
401 if (!m_inspectorResourceContentLoader) 404 if (!m_inspectorResourceContentLoader)
402 return; 405 return;
403 m_inspectorResourceContentLoader->dispose(); 406 m_inspectorResourceContentLoader->dispose();
404 m_inspectorResourceContentLoader.clear(); 407 m_inspectorResourceContentLoader.clear();
405 } 408 }
406 409
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 } 451 }
449 scripts->remove(identifier); 452 scripts->remove(identifier);
450 } 453 }
451 454
452 void InspectorPageAgent::reload(ErrorString*, const bool* const optionalIgnoreCa che, const String* optionalScriptToEvaluateOnLoad) 455 void InspectorPageAgent::reload(ErrorString*, const bool* const optionalIgnoreCa che, const String* optionalScriptToEvaluateOnLoad)
453 { 456 {
454 m_pendingScriptToEvaluateOnLoadOnce = optionalScriptToEvaluateOnLoad ? *opti onalScriptToEvaluateOnLoad : ""; 457 m_pendingScriptToEvaluateOnLoadOnce = optionalScriptToEvaluateOnLoad ? *opti onalScriptToEvaluateOnLoad : "";
455 ErrorString unused; 458 ErrorString unused;
456 m_debuggerAgent->setSkipAllPauses(&unused, true); 459 m_debuggerAgent->setSkipAllPauses(&unused, true);
457 m_reloading = true; 460 m_reloading = true;
458 m_inspectedFrame->reload(asBool(optionalIgnoreCache) ? EndToEndReload : Norm alReload, NotClientRedirect); 461 inspectedFrame()->reload(asBool(optionalIgnoreCache) ? EndToEndReload : Norm alReload, NotClientRedirect);
459 } 462 }
460 463
461 void InspectorPageAgent::navigate(ErrorString*, const String& url, String* outFr ameId) 464 void InspectorPageAgent::navigate(ErrorString*, const String& url, String* outFr ameId)
462 { 465 {
463 *outFrameId = frameId(m_inspectedFrame); 466 *outFrameId = frameId(inspectedFrame());
464 } 467 }
465 468
466 static void cachedResourcesForDocument(Document* document, Vector<Resource*>& re sult, bool skipXHRs) 469 static void cachedResourcesForDocument(Document* document, Vector<Resource*>& re sult, bool skipXHRs)
467 { 470 {
468 const ResourceFetcher::DocumentResourceMap& allResources = document->fetcher ()->allResources(); 471 const ResourceFetcher::DocumentResourceMap& allResources = document->fetcher ()->allResources();
469 for (const auto& resource : allResources) { 472 for (const auto& resource : allResources) {
470 Resource* cachedResource = resource.value.get(); 473 Resource* cachedResource = resource.value.get();
471 474
472 switch (cachedResource->type()) { 475 switch (cachedResource->type()) {
473 case Resource::Image: 476 case Resource::Image:
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 520
518 cachedResourcesForDocument(rootDocument, result, skipXHRs); 521 cachedResourcesForDocument(rootDocument, result, skipXHRs);
519 for (size_t i = 0; i < loaders.size(); ++i) 522 for (size_t i = 0; i < loaders.size(); ++i)
520 cachedResourcesForDocument(loaders[i], result, skipXHRs); 523 cachedResourcesForDocument(loaders[i], result, skipXHRs);
521 524
522 return result; 525 return result;
523 } 526 }
524 527
525 void InspectorPageAgent::getResourceTree(ErrorString*, RefPtr<TypeBuilder::Page: :FrameResourceTree>& object) 528 void InspectorPageAgent::getResourceTree(ErrorString*, RefPtr<TypeBuilder::Page: :FrameResourceTree>& object)
526 { 529 {
527 object = buildObjectForFrameTree(m_inspectedFrame); 530 object = buildObjectForFrameTree(inspectedFrame());
528 } 531 }
529 532
530 void InspectorPageAgent::finishReload() 533 void InspectorPageAgent::finishReload()
531 { 534 {
532 if (!m_reloading) 535 if (!m_reloading)
533 return; 536 return;
534 m_reloading = false; 537 m_reloading = false;
535 ErrorString unused; 538 ErrorString unused;
536 m_debuggerAgent->setSkipAllPauses(&unused, false); 539 m_debuggerAgent->setSkipAllPauses(&unused, false);
537 } 540 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 return true; 581 return true;
579 } 582 }
580 } 583 }
581 return false; 584 return false;
582 } 585 }
583 586
584 void InspectorPageAgent::searchInResource(ErrorString*, const String& frameId, c onst String& url, const String& query, const bool* const optionalCaseSensitive, const bool* const optionalIsRegex, RefPtr<TypeBuilder::Array<TypeBuilder::Debugg er::SearchMatch>>& results) 587 void InspectorPageAgent::searchInResource(ErrorString*, const String& frameId, c onst String& url, const String& query, const bool* const optionalCaseSensitive, const bool* const optionalIsRegex, RefPtr<TypeBuilder::Array<TypeBuilder::Debugg er::SearchMatch>>& results)
585 { 588 {
586 results = TypeBuilder::Array<TypeBuilder::Debugger::SearchMatch>::create(); 589 results = TypeBuilder::Array<TypeBuilder::Debugger::SearchMatch>::create();
587 590
588 LocalFrame* frame = InspectorResolver::resolveFrame(m_inspectedFrame, frameI d); 591 LocalFrame* frame = frameForId(frameId);
589 KURL kurl(ParsedURLString, url); 592 KURL kurl(ParsedURLString, url);
590 593
591 FrameLoader* frameLoader = frame ? &frame->loader() : nullptr; 594 FrameLoader* frameLoader = frame ? &frame->loader() : nullptr;
592 DocumentLoader* loader = frameLoader ? frameLoader->documentLoader() : nullp tr; 595 DocumentLoader* loader = frameLoader ? frameLoader->documentLoader() : nullp tr;
593 if (!loader) 596 if (!loader)
594 return; 597 return;
595 598
596 String content; 599 String content;
597 bool success = false; 600 bool success = false;
598 Resource* resource = cachedResource(frame, kurl); 601 Resource* resource = cachedResource(frame, kurl);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 if (script.value->asString(&scriptText)) 634 if (script.value->asString(&scriptText))
632 frame->script().executeScriptInMainWorld(scriptText); 635 frame->script().executeScriptInMainWorld(scriptText);
633 } 636 }
634 } 637 }
635 if (!m_scriptToEvaluateOnLoadOnce.isEmpty()) 638 if (!m_scriptToEvaluateOnLoadOnce.isEmpty())
636 frame->script().executeScriptInMainWorld(m_scriptToEvaluateOnLoadOnce); 639 frame->script().executeScriptInMainWorld(m_scriptToEvaluateOnLoadOnce);
637 } 640 }
638 641
639 void InspectorPageAgent::domContentLoadedEventFired(LocalFrame* frame) 642 void InspectorPageAgent::domContentLoadedEventFired(LocalFrame* frame)
640 { 643 {
641 if (frame != m_inspectedFrame) 644 if (frame != inspectedFrame())
642 return; 645 return;
643 frontend()->domContentEventFired(monotonicallyIncreasingTime()); 646 frontend()->domContentEventFired(monotonicallyIncreasingTime());
644 } 647 }
645 648
646 void InspectorPageAgent::loadEventFired(LocalFrame* frame) 649 void InspectorPageAgent::loadEventFired(LocalFrame* frame)
647 { 650 {
648 if (frame != m_inspectedFrame) 651 if (frame != inspectedFrame())
649 return; 652 return;
650 frontend()->loadEventFired(monotonicallyIncreasingTime()); 653 frontend()->loadEventFired(monotonicallyIncreasingTime());
651 } 654 }
652 655
653 void InspectorPageAgent::didCommitLoad(LocalFrame*, DocumentLoader* loader) 656 void InspectorPageAgent::didCommitLoad(LocalFrame*, DocumentLoader* loader)
654 { 657 {
655 if (loader->frame() == m_inspectedFrame) { 658 if (loader->frame() == inspectedFrame()) {
656 finishReload(); 659 finishReload();
657 m_scriptToEvaluateOnLoadOnce = m_pendingScriptToEvaluateOnLoadOnce; 660 m_scriptToEvaluateOnLoadOnce = m_pendingScriptToEvaluateOnLoadOnce;
658 m_pendingScriptToEvaluateOnLoadOnce = String(); 661 m_pendingScriptToEvaluateOnLoadOnce = String();
659 if (m_inspectorResourceContentLoader) 662 if (m_inspectorResourceContentLoader)
660 m_inspectorResourceContentLoader->stop(); 663 m_inspectorResourceContentLoader->stop();
661 } 664 }
662 frontend()->frameNavigated(buildObjectForFrame(loader->frame())); 665 frontend()->frameNavigated(buildObjectForFrame(loader->frame()));
663 } 666 }
664 667
665 void InspectorPageAgent::frameAttachedToParent(LocalFrame* frame) 668 void InspectorPageAgent::frameAttachedToParent(LocalFrame* frame)
666 { 669 {
667 Frame* parentFrame = frame->tree().parent(); 670 Frame* parentFrame = frame->tree().parent();
668 if (!parentFrame->isLocalFrame()) 671 if (!parentFrame->isLocalFrame())
669 parentFrame = 0; 672 parentFrame = 0;
670 frontend()->frameAttached(frameId(frame), frameId(toLocalFrame(parentFrame)) ); 673 frontend()->frameAttached(frameId(frame), frameId(toLocalFrame(parentFrame)) );
671 } 674 }
672 675
673 void InspectorPageAgent::frameDetachedFromParent(LocalFrame* frame) 676 void InspectorPageAgent::frameDetachedFromParent(LocalFrame* frame)
674 { 677 {
675 frontend()->frameDetached(frameId(frame)); 678 frontend()->frameDetached(frameId(frame));
676 } 679 }
677 680
681 FrameHost* InspectorPageAgent::frameHost()
682 {
683 return m_inspectedFrame->host();
684 }
685
686 LocalFrame* InspectorPageAgent::frameForId(const String& frameId)
687 {
688 LocalFrame* frame = InspectorIdentifiers<LocalFrame>::lookup(frameId);
689 return frame && frame->instrumentingAgents() == m_inspectedFrame->instrument ingAgents() ? frame : nullptr;
690 }
691
692 LocalFrame* InspectorPageAgent::findFrameWithSecurityOrigin(const String& origin RawString)
693 {
694 for (Frame* frame = inspectedFrame(); frame; frame = frame->tree().traverseN ext(inspectedFrame())) {
695 if (!frame->isLocalFrame())
696 continue;
697 RefPtr<SecurityOrigin> documentOrigin = toLocalFrame(frame)->document()- >securityOrigin();
698 if (documentOrigin->toRawString() == originRawString)
699 return toLocalFrame(frame);
700 }
701 return nullptr;
702 }
703
678 LocalFrame* InspectorPageAgent::assertFrame(ErrorString* errorString, const Stri ng& frameId) 704 LocalFrame* InspectorPageAgent::assertFrame(ErrorString* errorString, const Stri ng& frameId)
679 { 705 {
680 LocalFrame* frame = InspectorResolver::resolveFrame(m_inspectedFrame, frameI d); 706 LocalFrame* frame = frameForId(frameId);
681 if (!frame) 707 if (!frame)
682 *errorString = "No frame for given id found"; 708 *errorString = "No frame for given id found";
683 return frame; 709 return frame;
684 } 710 }
685 711
686 bool InspectorPageAgent::screencastEnabled() 712 bool InspectorPageAgent::screencastEnabled()
687 { 713 {
688 return m_enabled && m_state->getBoolean(PageAgentState::screencastEnabled); 714 return m_enabled && m_state->getBoolean(PageAgentState::screencastEnabled);
689 } 715 }
690 716
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
691 void InspectorPageAgent::frameStartedLoading(LocalFrame* frame) 726 void InspectorPageAgent::frameStartedLoading(LocalFrame* frame)
692 { 727 {
693 frontend()->frameStartedLoading(frameId(frame)); 728 frontend()->frameStartedLoading(frameId(frame));
694 } 729 }
695 730
696 void InspectorPageAgent::frameStoppedLoading(LocalFrame* frame) 731 void InspectorPageAgent::frameStoppedLoading(LocalFrame* frame)
697 { 732 {
698 frontend()->frameStoppedLoading(frameId(frame)); 733 frontend()->frameStoppedLoading(frameId(frame));
699 } 734 }
700 735
(...skipping 25 matching lines...) Expand all
726 } 761 }
727 762
728 void InspectorPageAgent::didScroll() 763 void InspectorPageAgent::didScroll()
729 { 764 {
730 if (m_enabled) 765 if (m_enabled)
731 m_overlay->update(); 766 m_overlay->update();
732 } 767 }
733 768
734 void InspectorPageAgent::didResizeMainFrame() 769 void InspectorPageAgent::didResizeMainFrame()
735 { 770 {
736 if (!m_inspectedFrame->isMainFrame()) 771 if (!inspectedFrame()->isMainFrame())
737 return; 772 return;
738 #if !OS(ANDROID) 773 #if !OS(ANDROID)
739 if (m_enabled && m_state->getBoolean(PageAgentState::showSizeOnResize)) 774 if (m_enabled && m_state->getBoolean(PageAgentState::showSizeOnResize))
740 m_overlay->showAndHideViewSize(m_state->getBoolean(PageAgentState::showG ridOnResize)); 775 m_overlay->showAndHideViewSize(m_state->getBoolean(PageAgentState::showG ridOnResize));
741 #endif 776 #endif
742 frontend()->frameResized(); 777 frontend()->frameResized();
743 } 778 }
744 779
745 void InspectorPageAgent::didRecalculateStyle(int) 780 void InspectorPageAgent::didRecalculateStyle(int)
746 { 781 {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 { 873 {
839 visitor->trace(m_inspectedFrame); 874 visitor->trace(m_inspectedFrame);
840 visitor->trace(m_debuggerAgent); 875 visitor->trace(m_debuggerAgent);
841 visitor->trace(m_cssAgent); 876 visitor->trace(m_cssAgent);
842 visitor->trace(m_overlay); 877 visitor->trace(m_overlay);
843 visitor->trace(m_inspectorResourceContentLoader); 878 visitor->trace(m_inspectorResourceContentLoader);
844 InspectorBaseAgent::trace(visitor); 879 InspectorBaseAgent::trace(visitor);
845 } 880 }
846 881
847 } // namespace blink 882 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/inspector/InspectorPageAgent.h ('k') | Source/core/inspector/InspectorResolver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698