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

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

Issue 2800213002: Avoid duplicate functions/code in core/inspector.
Patch Set: Manual inlined urlWithoutFragment Created 3 years, 4 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
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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 #include "core/frame/LocalFrame.h" 42 #include "core/frame/LocalFrame.h"
43 #include "core/frame/LocalFrameClient.h" 43 #include "core/frame/LocalFrameClient.h"
44 #include "core/frame/LocalFrameView.h" 44 #include "core/frame/LocalFrameView.h"
45 #include "core/frame/Settings.h" 45 #include "core/frame/Settings.h"
46 #include "core/frame/VisualViewport.h" 46 #include "core/frame/VisualViewport.h"
47 #include "core/html/HTMLFrameOwnerElement.h" 47 #include "core/html/HTMLFrameOwnerElement.h"
48 #include "core/html/VoidCallback.h" 48 #include "core/html/VoidCallback.h"
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/AddStringToDigestor.h"
52 #include "core/inspector/IdentifiersFactory.h" 53 #include "core/inspector/IdentifiersFactory.h"
53 #include "core/inspector/InspectedFrames.h" 54 #include "core/inspector/InspectedFrames.h"
54 #include "core/inspector/InspectorCSSAgent.h" 55 #include "core/inspector/InspectorCSSAgent.h"
55 #include "core/inspector/InspectorResourceContentLoader.h" 56 #include "core/inspector/InspectorResourceContentLoader.h"
56 #include "core/inspector/V8InspectorString.h" 57 #include "core/inspector/V8InspectorString.h"
57 #include "core/loader/DocumentLoader.h" 58 #include "core/loader/DocumentLoader.h"
58 #include "core/loader/FrameLoader.h" 59 #include "core/loader/FrameLoader.h"
59 #include "core/loader/ScheduledNavigation.h" 60 #include "core/loader/ScheduledNavigation.h"
60 #include "core/loader/resource/CSSStyleSheetResource.h" 61 #include "core/loader/resource/CSSStyleSheetResource.h"
61 #include "core/loader/resource/ScriptResource.h" 62 #include "core/loader/resource/ScriptResource.h"
(...skipping 20 matching lines...) Expand all
82 namespace PageAgentState { 83 namespace PageAgentState {
83 static const char kPageAgentEnabled[] = "pageAgentEnabled"; 84 static const char kPageAgentEnabled[] = "pageAgentEnabled";
84 static const char kPageAgentScriptsToEvaluateOnLoad[] = 85 static const char kPageAgentScriptsToEvaluateOnLoad[] =
85 "pageAgentScriptsToEvaluateOnLoad"; 86 "pageAgentScriptsToEvaluateOnLoad";
86 static const char kScreencastEnabled[] = "screencastEnabled"; 87 static const char kScreencastEnabled[] = "screencastEnabled";
87 static const char kAutoAttachToCreatedPages[] = "autoAttachToCreatedPages"; 88 static const char kAutoAttachToCreatedPages[] = "autoAttachToCreatedPages";
88 } 89 }
89 90
90 namespace { 91 namespace {
91 92
92 KURL UrlWithoutFragment(const KURL& url) {
93 KURL result = url;
94 result.RemoveFragmentIdentifier();
95 return result;
96 }
97
98 String FrameId(LocalFrame* frame) {
99 return frame ? IdentifiersFactory::FrameId(frame) : "";
100 }
101
102 String DialogTypeToProtocol(ChromeClient::DialogType dialog_type) { 93 String DialogTypeToProtocol(ChromeClient::DialogType dialog_type) {
103 switch (dialog_type) { 94 switch (dialog_type) {
104 case ChromeClient::kAlertDialog: 95 case ChromeClient::kAlertDialog:
105 return protocol::Page::DialogTypeEnum::Alert; 96 return protocol::Page::DialogTypeEnum::Alert;
106 case ChromeClient::kConfirmDialog: 97 case ChromeClient::kConfirmDialog:
107 return protocol::Page::DialogTypeEnum::Confirm; 98 return protocol::Page::DialogTypeEnum::Confirm;
108 case ChromeClient::kPromptDialog: 99 case ChromeClient::kPromptDialog:
109 return protocol::Page::DialogTypeEnum::Prompt; 100 return protocol::Page::DialogTypeEnum::Prompt;
110 case ChromeClient::kHTMLDialog: 101 case ChromeClient::kHTMLDialog:
111 return protocol::Page::DialogTypeEnum::Beforeunload; 102 return protocol::Page::DialogTypeEnum::Beforeunload;
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 enable(); 422 enable();
432 } 423 }
433 424
434 Response InspectorPageAgent::enable() { 425 Response InspectorPageAgent::enable() {
435 enabled_ = true; 426 enabled_ = true;
436 state_->setBoolean(PageAgentState::kPageAgentEnabled, true); 427 state_->setBoolean(PageAgentState::kPageAgentEnabled, true);
437 instrumenting_agents_->addInspectorPageAgent(this); 428 instrumenting_agents_->addInspectorPageAgent(this);
438 429
439 // Tell the browser the ids for all existing frames. 430 // Tell the browser the ids for all existing frames.
440 for (LocalFrame* frame : *inspected_frames_) { 431 for (LocalFrame* frame : *inspected_frames_) {
441 frame->Client()->SetDevToolsFrameId(FrameId(frame)); 432 frame->Client()->SetDevToolsFrameId(IdentifiersFactory::FrameId(frame));
442 } 433 }
443 return Response::OK(); 434 return Response::OK();
444 } 435 }
445 436
446 Response InspectorPageAgent::disable() { 437 Response InspectorPageAgent::disable() {
447 enabled_ = false; 438 enabled_ = false;
448 state_->setBoolean(PageAgentState::kPageAgentEnabled, false); 439 state_->setBoolean(PageAgentState::kPageAgentEnabled, false);
449 state_->remove(PageAgentState::kPageAgentScriptsToEvaluateOnLoad); 440 state_->remove(PageAgentState::kPageAgentScriptsToEvaluateOnLoad);
450 script_to_evaluate_on_load_once_ = String(); 441 script_to_evaluate_on_load_once_ = String();
451 pending_script_to_evaluate_on_load_once_ = String(); 442 pending_script_to_evaluate_on_load_once_ = String();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
517 ? kFrameLoadTypeReloadBypassingCache 508 ? kFrameLoadTypeReloadBypassingCache
518 : kFrameLoadTypeReload, 509 : kFrameLoadTypeReload,
519 ClientRedirectPolicy::kNotClientRedirect); 510 ClientRedirectPolicy::kNotClientRedirect);
520 return Response::OK(); 511 return Response::OK();
521 } 512 }
522 513
523 Response InspectorPageAgent::navigate(const String& url, 514 Response InspectorPageAgent::navigate(const String& url,
524 Maybe<String> referrer, 515 Maybe<String> referrer,
525 Maybe<String> transitionType, 516 Maybe<String> transitionType,
526 String* out_frame_id) { 517 String* out_frame_id) {
527 *out_frame_id = FrameId(inspected_frames_->Root()); 518 *out_frame_id = IdentifiersFactory::FrameId(inspected_frames_->Root());
528 return Response::OK(); 519 return Response::OK();
529 } 520 }
530 521
531 Response InspectorPageAgent::stopLoading() { 522 Response InspectorPageAgent::stopLoading() {
532 return Response::OK(); 523 return Response::OK();
533 } 524 }
534 525
535 static void CachedResourcesForDocument(Document* document, 526 static void CachedResourcesForDocument(Document* document,
536 HeapVector<Member<Resource>>& result, 527 HeapVector<Member<Resource>>& result,
537 bool skip_xhrs) { 528 bool skip_xhrs) {
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 } 730 }
740 GetFrontend()->frameNavigated(BuildObjectForFrame(loader->GetFrame())); 731 GetFrontend()->frameNavigated(BuildObjectForFrame(loader->GetFrame()));
741 } 732 }
742 733
743 void InspectorPageAgent::FrameAttachedToParent(LocalFrame* frame) { 734 void InspectorPageAgent::FrameAttachedToParent(LocalFrame* frame) {
744 Frame* parent_frame = frame->Tree().Parent(); 735 Frame* parent_frame = frame->Tree().Parent();
745 if (!parent_frame->IsLocalFrame()) 736 if (!parent_frame->IsLocalFrame())
746 parent_frame = 0; 737 parent_frame = 0;
747 std::unique_ptr<SourceLocation> location = 738 std::unique_ptr<SourceLocation> location =
748 SourceLocation::CaptureWithFullStackTrace(); 739 SourceLocation::CaptureWithFullStackTrace();
749 String frame_id = FrameId(frame); 740 String frame_id = IdentifiersFactory::FrameId(frame);
750 frame->Client()->SetDevToolsFrameId(frame_id); 741 frame->Client()->SetDevToolsFrameId(frame_id);
751 GetFrontend()->frameAttached( 742 GetFrontend()->frameAttached(
752 frame_id, FrameId(ToLocalFrame(parent_frame)), 743 frame_id, IdentifiersFactory::FrameId(ToLocalFrame(parent_frame)),
753 location ? location->BuildInspectorObject() : nullptr); 744 location ? location->BuildInspectorObject() : nullptr);
754 } 745 }
755 746
756 void InspectorPageAgent::FrameDetachedFromParent(LocalFrame* frame) { 747 void InspectorPageAgent::FrameDetachedFromParent(LocalFrame* frame) {
757 GetFrontend()->frameDetached(FrameId(frame)); 748 GetFrontend()->frameDetached(IdentifiersFactory::FrameId(frame));
758 } 749 }
759 750
760 bool InspectorPageAgent::ScreencastEnabled() { 751 bool InspectorPageAgent::ScreencastEnabled() {
761 return enabled_ && 752 return enabled_ &&
762 state_->booleanProperty(PageAgentState::kScreencastEnabled, false); 753 state_->booleanProperty(PageAgentState::kScreencastEnabled, false);
763 } 754 }
764 755
765 void InspectorPageAgent::FrameStartedLoading(LocalFrame* frame, FrameLoadType) { 756 void InspectorPageAgent::FrameStartedLoading(LocalFrame* frame, FrameLoadType) {
766 GetFrontend()->frameStartedLoading(FrameId(frame)); 757 GetFrontend()->frameStartedLoading(IdentifiersFactory::FrameId(frame));
767 } 758 }
768 759
769 void InspectorPageAgent::FrameStoppedLoading(LocalFrame* frame) { 760 void InspectorPageAgent::FrameStoppedLoading(LocalFrame* frame) {
770 GetFrontend()->frameStoppedLoading(FrameId(frame)); 761 GetFrontend()->frameStoppedLoading(IdentifiersFactory::FrameId(frame));
771 } 762 }
772 763
773 void InspectorPageAgent::FrameScheduledNavigation( 764 void InspectorPageAgent::FrameScheduledNavigation(
774 LocalFrame* frame, 765 LocalFrame* frame,
775 ScheduledNavigation* scheduled_navigation) { 766 ScheduledNavigation* scheduled_navigation) {
776 GetFrontend()->frameScheduledNavigation( 767 GetFrontend()->frameScheduledNavigation(
777 FrameId(frame), scheduled_navigation->Delay(), 768 IdentifiersFactory::FrameId(frame), scheduled_navigation->Delay(),
778 ScheduledNavigationReasonToProtocol(scheduled_navigation->GetReason())); 769 ScheduledNavigationReasonToProtocol(scheduled_navigation->GetReason()));
779 } 770 }
780 771
781 void InspectorPageAgent::FrameClearedScheduledNavigation(LocalFrame* frame) { 772 void InspectorPageAgent::FrameClearedScheduledNavigation(LocalFrame* frame) {
782 GetFrontend()->frameClearedScheduledNavigation(FrameId(frame)); 773 GetFrontend()->frameClearedScheduledNavigation(
774 IdentifiersFactory::FrameId(frame));
783 } 775 }
784 776
785 void InspectorPageAgent::WillRunJavaScriptDialog( 777 void InspectorPageAgent::WillRunJavaScriptDialog(
786 const String& message, 778 const String& message,
787 ChromeClient::DialogType dialog_type) { 779 ChromeClient::DialogType dialog_type) {
788 GetFrontend()->javascriptDialogOpening(message, 780 GetFrontend()->javascriptDialogOpening(message,
789 DialogTypeToProtocol(dialog_type)); 781 DialogTypeToProtocol(dialog_type));
790 GetFrontend()->flush(); 782 GetFrontend()->flush();
791 } 783 }
792 784
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 } 818 }
827 819
828 void InspectorPageAgent::WindowCreated(LocalFrame* created) { 820 void InspectorPageAgent::WindowCreated(LocalFrame* created) {
829 if (enabled_ && 821 if (enabled_ &&
830 state_->booleanProperty(PageAgentState::kAutoAttachToCreatedPages, false)) 822 state_->booleanProperty(PageAgentState::kAutoAttachToCreatedPages, false))
831 client_->WaitForCreateWindow(created); 823 client_->WaitForCreateWindow(created);
832 } 824 }
833 825
834 std::unique_ptr<protocol::Page::Frame> InspectorPageAgent::BuildObjectForFrame( 826 std::unique_ptr<protocol::Page::Frame> InspectorPageAgent::BuildObjectForFrame(
835 LocalFrame* frame) { 827 LocalFrame* frame) {
828 KURL nofragment_document_url(frame->GetDocument()->Url());
829 nofragment_document_url.RemoveFragmentIdentifier();
836 std::unique_ptr<protocol::Page::Frame> frame_object = 830 std::unique_ptr<protocol::Page::Frame> frame_object =
837 protocol::Page::Frame::create() 831 protocol::Page::Frame::create()
838 .setId(FrameId(frame)) 832 .setId(IdentifiersFactory::FrameId(frame))
839 .setLoaderId( 833 .setLoaderId(
840 IdentifiersFactory::LoaderId(frame->Loader().GetDocumentLoader())) 834 IdentifiersFactory::LoaderId(frame->Loader().GetDocumentLoader()))
841 .setUrl(UrlWithoutFragment(frame->GetDocument()->Url()).GetString()) 835 .setUrl(nofragment_document_url.GetString())
842 .setMimeType(frame->Loader().GetDocumentLoader()->ResponseMIMEType()) 836 .setMimeType(frame->Loader().GetDocumentLoader()->ResponseMIMEType())
843 .setSecurityOrigin( 837 .setSecurityOrigin(
844 frame->GetDocument()->GetSecurityOrigin()->ToRawString()) 838 frame->GetDocument()->GetSecurityOrigin()->ToRawString())
845 .build(); 839 .build();
846 // FIXME: This doesn't work for OOPI. 840 // FIXME: This doesn't work for OOPI.
847 Frame* parent_frame = frame->Tree().Parent(); 841 Frame* parent_frame = frame->Tree().Parent();
848 if (parent_frame && parent_frame->IsLocalFrame()) 842 if (parent_frame && parent_frame->IsLocalFrame()) {
849 frame_object->setParentId(FrameId(ToLocalFrame(parent_frame))); 843 frame_object->setParentId(
844 IdentifiersFactory::FrameId(ToLocalFrame(parent_frame)));
845 }
850 if (frame->DeprecatedLocalOwner()) { 846 if (frame->DeprecatedLocalOwner()) {
851 AtomicString name = frame->DeprecatedLocalOwner()->GetNameAttribute(); 847 AtomicString name = frame->DeprecatedLocalOwner()->GetNameAttribute();
852 if (name.IsEmpty()) 848 if (name.IsEmpty())
853 name = frame->DeprecatedLocalOwner()->getAttribute(HTMLNames::idAttr); 849 name = frame->DeprecatedLocalOwner()->getAttribute(HTMLNames::idAttr);
854 frame_object->setName(name); 850 frame_object->setName(name);
855 } 851 }
856 if (frame->GetDocument() && frame->GetDocument()->Loader() && 852 if (frame->GetDocument() && frame->GetDocument()->Loader() &&
857 !frame->GetDocument()->Loader()->UnreachableURL().IsEmpty()) { 853 !frame->GetDocument()->Loader()->UnreachableURL().IsEmpty()) {
858 frame_object->setUnreachableUrl( 854 frame_object->setUnreachableUrl(
859 frame->GetDocument()->Loader()->UnreachableURL().GetString()); 855 frame->GetDocument()->Loader()->UnreachableURL().GetString());
860 } 856 }
861 return frame_object; 857 return frame_object;
862 } 858 }
863 859
864 std::unique_ptr<protocol::Page::FrameResourceTree> 860 std::unique_ptr<protocol::Page::FrameResourceTree>
865 InspectorPageAgent::BuildObjectForFrameTree(LocalFrame* frame) { 861 InspectorPageAgent::BuildObjectForFrameTree(LocalFrame* frame) {
866 std::unique_ptr<protocol::Page::Frame> frame_object = 862 std::unique_ptr<protocol::Page::Frame> frame_object =
867 BuildObjectForFrame(frame); 863 BuildObjectForFrame(frame);
868 std::unique_ptr<protocol::Array<protocol::Page::FrameResource>> subresources = 864 std::unique_ptr<protocol::Array<protocol::Page::FrameResource>> subresources =
869 protocol::Array<protocol::Page::FrameResource>::create(); 865 protocol::Array<protocol::Page::FrameResource>::create();
870 866
871 HeapVector<Member<Resource>> all_resources = 867 HeapVector<Member<Resource>> all_resources =
872 CachedResourcesForFrame(frame, true); 868 CachedResourcesForFrame(frame, true);
873 for (Resource* cached_resource : all_resources) { 869 for (Resource* cached_resource : all_resources) {
870 KURL nofragment_cached_resource_url(cached_resource->Url());
871 nofragment_cached_resource_url.RemoveFragmentIdentifier();
874 std::unique_ptr<protocol::Page::FrameResource> resource_object = 872 std::unique_ptr<protocol::Page::FrameResource> resource_object =
875 protocol::Page::FrameResource::create() 873 protocol::Page::FrameResource::create()
876 .setUrl(UrlWithoutFragment(cached_resource->Url()).GetString()) 874 .setUrl(nofragment_cached_resource_url.GetString())
877 .setType(CachedResourceTypeJson(*cached_resource)) 875 .setType(CachedResourceTypeJson(*cached_resource))
878 .setMimeType(cached_resource->GetResponse().MimeType()) 876 .setMimeType(cached_resource->GetResponse().MimeType())
879 .setContentSize(cached_resource->GetResponse().DecodedBodyLength()) 877 .setContentSize(cached_resource->GetResponse().DecodedBodyLength())
880 .build(); 878 .build();
881 double last_modified = cached_resource->GetResponse().LastModified(); 879 double last_modified = cached_resource->GetResponse().LastModified();
882 if (!std::isnan(last_modified)) 880 if (!std::isnan(last_modified))
883 resource_object->setLastModified(last_modified); 881 resource_object->setLastModified(last_modified);
884 if (cached_resource->WasCanceled()) 882 if (cached_resource->WasCanceled())
885 resource_object->setCanceled(true); 883 resource_object->setCanceled(true);
886 else if (cached_resource->GetStatus() == ResourceStatus::kLoadError) 884 else if (cached_resource->GetStatus() == ResourceStatus::kLoadError)
887 resource_object->setFailed(true); 885 resource_object->setFailed(true);
888 subresources->addItem(std::move(resource_object)); 886 subresources->addItem(std::move(resource_object));
889 } 887 }
890 888
891 HeapVector<Member<Document>> all_imports = 889 HeapVector<Member<Document>> all_imports =
892 InspectorPageAgent::ImportsForFrame(frame); 890 InspectorPageAgent::ImportsForFrame(frame);
893 for (Document* import : all_imports) { 891 for (Document* import : all_imports) {
892 KURL nofragment_import_url(import->Url());
893 nofragment_import_url.RemoveFragmentIdentifier();
894 std::unique_ptr<protocol::Page::FrameResource> resource_object = 894 std::unique_ptr<protocol::Page::FrameResource> resource_object =
895 protocol::Page::FrameResource::create() 895 protocol::Page::FrameResource::create()
896 .setUrl(UrlWithoutFragment(import->Url()).GetString()) 896 .setUrl(nofragment_import_url.GetString())
897 .setType(ResourceTypeJson(InspectorPageAgent::kDocumentResource)) 897 .setType(ResourceTypeJson(InspectorPageAgent::kDocumentResource))
898 .setMimeType(import->SuggestedMIMEType()) 898 .setMimeType(import->SuggestedMIMEType())
899 .build(); 899 .build();
900 subresources->addItem(std::move(resource_object)); 900 subresources->addItem(std::move(resource_object));
901 } 901 }
902 902
903 std::unique_ptr<protocol::Page::FrameResourceTree> result = 903 std::unique_ptr<protocol::Page::FrameResourceTree> result =
904 protocol::Page::FrameResourceTree::create() 904 protocol::Page::FrameResourceTree::create()
905 .setFrame(std::move(frame_object)) 905 .setFrame(std::move(frame_object))
906 .setResources(std::move(subresources)) 906 .setResources(std::move(subresources))
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 return Response::OK(); 1014 return Response::OK();
1015 } 1015 }
1016 1016
1017 DEFINE_TRACE(InspectorPageAgent) { 1017 DEFINE_TRACE(InspectorPageAgent) {
1018 visitor->Trace(inspected_frames_); 1018 visitor->Trace(inspected_frames_);
1019 visitor->Trace(inspector_resource_content_loader_); 1019 visitor->Trace(inspector_resource_content_loader_);
1020 InspectorBaseAgent::Trace(visitor); 1020 InspectorBaseAgent::Trace(visitor);
1021 } 1021 }
1022 1022
1023 } // namespace blink 1023 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698