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

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