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

Side by Side Diff: webkit/glue/webplugin_impl.cc

Issue 435044: Send resource load notifications from plugins to devtools agent (Closed)
Patch Set: Sync with trunk Created 11 years 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
« no previous file with comments | « webkit/glue/webplugin_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/gfx/rect.h" 5 #include "base/gfx/rect.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "net/base/escape.h" 10 #include "net/base/escape.h"
11 #include "net/base/net_errors.h" 11 #include "net/base/net_errors.h"
12 #include "skia/ext/platform_canvas.h" 12 #include "skia/ext/platform_canvas.h"
13 #include "third_party/WebKit/WebKit/chromium/public/WebConsoleMessage.h" 13 #include "third_party/WebKit/WebKit/chromium/public/WebConsoleMessage.h"
14 #include "third_party/WebKit/WebKit/chromium/public/WebCString.h" 14 #include "third_party/WebKit/WebKit/chromium/public/WebCString.h"
15 #include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h" 15 #include "third_party/WebKit/WebKit/chromium/public/WebCursorInfo.h"
16 #include "third_party/WebKit/WebKit/chromium/public/WebDevToolsAgent.h"
16 #include "third_party/WebKit/WebKit/chromium/public/WebData.h" 17 #include "third_party/WebKit/WebKit/chromium/public/WebData.h"
17 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h" 18 #include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
18 #include "third_party/WebKit/WebKit/chromium/public/WebHTTPBody.h" 19 #include "third_party/WebKit/WebKit/chromium/public/WebHTTPBody.h"
19 #include "third_party/WebKit/WebKit/chromium/public/WebHTTPHeaderVisitor.h" 20 #include "third_party/WebKit/WebKit/chromium/public/WebHTTPHeaderVisitor.h"
20 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" 21 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h"
21 #include "third_party/WebKit/WebKit/chromium/public/WebKit.h" 22 #include "third_party/WebKit/WebKit/chromium/public/WebKit.h"
22 #include "third_party/WebKit/WebKit/chromium/public/WebKitClient.h" 23 #include "third_party/WebKit/WebKit/chromium/public/WebKitClient.h"
23 #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h" 24 #include "third_party/WebKit/WebKit/chromium/public/WebPluginContainer.h"
24 #include "third_party/WebKit/WebKit/chromium/public/WebPluginParams.h" 25 #include "third_party/WebKit/WebKit/chromium/public/WebPluginParams.h"
25 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h" 26 #include "third_party/WebKit/WebKit/chromium/public/WebRect.h"
(...skipping 10 matching lines...) Expand all
36 #include "webkit/glue/webplugin_delegate.h" 37 #include "webkit/glue/webplugin_delegate.h"
37 #include "webkit/glue/webplugin_page_delegate.h" 38 #include "webkit/glue/webplugin_page_delegate.h"
38 #include "googleurl/src/gurl.h" 39 #include "googleurl/src/gurl.h"
39 40
40 using WebKit::WebCanvas; 41 using WebKit::WebCanvas;
41 using WebKit::WebConsoleMessage; 42 using WebKit::WebConsoleMessage;
42 using WebKit::WebCString; 43 using WebKit::WebCString;
43 using WebKit::WebCursorInfo; 44 using WebKit::WebCursorInfo;
44 using WebKit::WebData; 45 using WebKit::WebData;
45 using WebKit::WebDataSource; 46 using WebKit::WebDataSource;
47 using WebKit::WebDevToolsAgent;
46 using WebKit::WebFrame; 48 using WebKit::WebFrame;
47 using WebKit::WebHTTPBody; 49 using WebKit::WebHTTPBody;
48 using WebKit::WebHTTPHeaderVisitor; 50 using WebKit::WebHTTPHeaderVisitor;
49 using WebKit::WebInputEvent; 51 using WebKit::WebInputEvent;
50 using WebKit::WebKeyboardEvent; 52 using WebKit::WebKeyboardEvent;
51 using WebKit::WebMouseEvent; 53 using WebKit::WebMouseEvent;
52 using WebKit::WebPluginContainer; 54 using WebKit::WebPluginContainer;
53 using WebKit::WebPluginParams; 55 using WebKit::WebPluginParams;
54 using WebKit::WebRect; 56 using WebKit::WebRect;
55 using WebKit::WebString; 57 using WebKit::WebString;
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 420
419 GURL WebPluginImpl::CompleteURL(const char* url) { 421 GURL WebPluginImpl::CompleteURL(const char* url) {
420 if (!webframe_) { 422 if (!webframe_) {
421 NOTREACHED(); 423 NOTREACHED();
422 return GURL(); 424 return GURL();
423 } 425 }
424 // TODO(darin): Is conversion from UTF8 correct here? 426 // TODO(darin): Is conversion from UTF8 correct here?
425 return webframe_->completeURL(WebString::fromUTF8(url)); 427 return webframe_->completeURL(WebString::fromUTF8(url));
426 } 428 }
427 429
428 void WebPluginImpl::CancelResource(int id) { 430 void WebPluginImpl::CancelResource(unsigned long id) {
429 for (size_t i = 0; i < clients_.size(); ++i) { 431 for (size_t i = 0; i < clients_.size(); ++i) {
430 if (clients_[i].id == id) { 432 if (clients_[i].id == id) {
431 if (clients_[i].loader.get()) { 433 if (clients_[i].loader.get()) {
432 clients_[i].loader->setDefersLoading(false); 434 clients_[i].loader->setDefersLoading(false);
433 clients_[i].loader->cancel(); 435 clients_[i].loader->cancel();
434 RemoveClient(i); 436 RemoveClient(i);
435 } 437 }
436 return; 438 return;
437 } 439 }
438 } 440 }
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 // accept data 693 // accept data
692 loader->setDefersLoading(true); 694 loader->setDefersLoading(true);
693 695
694 client->DidReceiveResponse( 696 client->DidReceiveResponse(
695 response_info.mime_type, 697 response_info.mime_type,
696 GetAllHeaders(response), 698 GetAllHeaders(response),
697 response_info.expected_length, 699 response_info.expected_length,
698 response_info.last_modified, 700 response_info.last_modified,
699 request_is_seekable); 701 request_is_seekable);
700 702
703 if (WebDevToolsAgent* devtools_agent = webframe_->view()->devToolsAgent()) {
704 ClientInfo* client_info = GetClientInfoFromLoader(loader);
705 if (client_info)
706 devtools_agent->didReceiveResponse(client_info->id, response);
707 }
708
701 // Bug http://b/issue?id=925559. The flash plugin would not handle the HTTP 709 // Bug http://b/issue?id=925559. The flash plugin would not handle the HTTP
702 // error codes in the stream header and as a result, was unaware of the 710 // error codes in the stream header and as a result, was unaware of the
703 // fate of the HTTP requests issued via NPN_GetURLNotify. Webkit and FF 711 // fate of the HTTP requests issued via NPN_GetURLNotify. Webkit and FF
704 // destroy the stream and invoke the NPP_DestroyStream function on the 712 // destroy the stream and invoke the NPP_DestroyStream function on the
705 // plugin if the HTTP request fails. 713 // plugin if the HTTP request fails.
706 const GURL& url = response.url(); 714 const GURL& url = response.url();
707 if (url.SchemeIs("http") || url.SchemeIs("https")) { 715 if (url.SchemeIs("http") || url.SchemeIs("https")) {
708 if (response.httpStatusCode() < 100 || response.httpStatusCode() >= 400) { 716 if (response.httpStatusCode() < 100 || response.httpStatusCode() >= 400) {
709 // The plugin instance could be in the process of deletion here. 717 // The plugin instance could be in the process of deletion here.
710 // Verify if the WebPluginResourceClient instance still exists before 718 // Verify if the WebPluginResourceClient instance still exists before
(...skipping 15 matching lines...) Expand all
726 MultiPartResponseHandlerMap::iterator index = 734 MultiPartResponseHandlerMap::iterator index =
727 multi_part_response_map_.find(client); 735 multi_part_response_map_.find(client);
728 if (index != multi_part_response_map_.end()) { 736 if (index != multi_part_response_map_.end()) {
729 MultipartResponseDelegate* multi_part_handler = (*index).second; 737 MultipartResponseDelegate* multi_part_handler = (*index).second;
730 DCHECK(multi_part_handler != NULL); 738 DCHECK(multi_part_handler != NULL);
731 multi_part_handler->OnReceivedData(buffer, length); 739 multi_part_handler->OnReceivedData(buffer, length);
732 } else { 740 } else {
733 loader->setDefersLoading(true); 741 loader->setDefersLoading(true);
734 client->DidReceiveData(buffer, length, 0); 742 client->DidReceiveData(buffer, length, 0);
735 } 743 }
744
745 if (WebDevToolsAgent* devtools_agent = webframe_->view()->devToolsAgent()) {
746 ClientInfo* client_info = GetClientInfoFromLoader(loader);
747 if (client_info)
748 devtools_agent->didReceiveData(client_info->id, length);
749 }
736 } 750 }
737 751
738 void WebPluginImpl::didFinishLoading(WebURLLoader* loader) { 752 void WebPluginImpl::didFinishLoading(WebURLLoader* loader) {
739 ClientInfo* client_info = GetClientInfoFromLoader(loader); 753 ClientInfo* client_info = GetClientInfoFromLoader(loader);
740 if (client_info && client_info->client) { 754 if (client_info && client_info->client) {
741 MultiPartResponseHandlerMap::iterator index = 755 MultiPartResponseHandlerMap::iterator index =
742 multi_part_response_map_.find(client_info->client); 756 multi_part_response_map_.find(client_info->client);
743 if (index != multi_part_response_map_.end()) { 757 if (index != multi_part_response_map_.end()) {
744 delete (*index).second; 758 delete (*index).second;
745 multi_part_response_map_.erase(index); 759 multi_part_response_map_.erase(index);
746 if (page_delegate_) 760 if (page_delegate_)
747 page_delegate_->DidStopLoadingForPlugin(); 761 page_delegate_->DidStopLoadingForPlugin();
748 } 762 }
749 loader->setDefersLoading(true); 763 loader->setDefersLoading(true);
750 WebPluginResourceClient* resource_client = client_info->client; 764 WebPluginResourceClient* resource_client = client_info->client;
751 // The ClientInfo can get deleted in the call to DidFinishLoading below. 765 // The ClientInfo can get deleted in the call to DidFinishLoading below.
752 // It is not safe to access this structure after that. 766 // It is not safe to access this structure after that.
753 client_info->client = NULL; 767 client_info->client = NULL;
754 resource_client->DidFinishLoading(); 768 resource_client->DidFinishLoading();
769
770 if (WebDevToolsAgent* devtools_agent = webframe_->view()->devToolsAgent())
771 devtools_agent->didFinishLoading(client_info->id);
755 } 772 }
756 } 773 }
757 774
758 void WebPluginImpl::didFail(WebURLLoader* loader, 775 void WebPluginImpl::didFail(WebURLLoader* loader,
759 const WebURLError&) { 776 const WebURLError& error) {
760 ClientInfo* client_info = GetClientInfoFromLoader(loader); 777 ClientInfo* client_info = GetClientInfoFromLoader(loader);
761 if (client_info && client_info->client) { 778 if (client_info && client_info->client) {
762 loader->setDefersLoading(true); 779 loader->setDefersLoading(true);
763 WebPluginResourceClient* resource_client = client_info->client; 780 WebPluginResourceClient* resource_client = client_info->client;
764 // The ClientInfo can get deleted in the call to DidFail below. 781 // The ClientInfo can get deleted in the call to DidFail below.
765 // It is not safe to access this structure after that. 782 // It is not safe to access this structure after that.
766 client_info->client = NULL; 783 client_info->client = NULL;
767 resource_client->DidFail(); 784 resource_client->DidFail();
785
786 if (WebDevToolsAgent* devtools_agent = webframe_->view()->devToolsAgent())
787 devtools_agent->didFailLoading(client_info->id, error);
768 } 788 }
769 } 789 }
770 790
771 void WebPluginImpl::RemoveClient(size_t i) { 791 void WebPluginImpl::RemoveClient(size_t i) {
772 clients_.erase(clients_.begin() + i); 792 clients_.erase(clients_.begin() + i);
773 } 793 }
774 794
775 void WebPluginImpl::RemoveClient(WebURLLoader* loader) { 795 void WebPluginImpl::RemoveClient(WebURLLoader* loader) {
776 for (size_t i = 0; i < clients_.size(); ++i) { 796 for (size_t i = 0; i < clients_.size(); ++i) {
777 if (clients_[i].loader.get() == loader) { 797 if (clients_[i].loader.get() == loader) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 842
823 // delegate_ could be NULL because executeScript caused the container to 843 // delegate_ could be NULL because executeScript caused the container to
824 // be deleted. 844 // be deleted.
825 if (delegate_) { 845 if (delegate_) {
826 delegate_->SendJavaScriptStream( 846 delegate_->SendJavaScriptStream(
827 gurl, result.utf8(), !result.isNull(), notify, notify_data); 847 gurl, result.utf8(), !result.isNull(), notify, notify_data);
828 } 848 }
829 } else { 849 } else {
830 GURL complete_url = CompleteURL(url); 850 GURL complete_url = CompleteURL(url);
831 851
832 int resource_id = GetNextResourceId(); 852 unsigned long resource_id = GetNextResourceId();
853 if (!resource_id)
854 return;
855
833 WebPluginResourceClient* resource_client = delegate_->CreateResourceClient( 856 WebPluginResourceClient* resource_client = delegate_->CreateResourceClient(
834 resource_id, complete_url, notify, notify_data, NULL); 857 resource_id, complete_url, notify, notify_data, NULL);
835 if (!resource_client) 858 if (!resource_client)
836 return; 859 return;
837 860
838 // If the RouteToFrame call returned a failure then inform the result 861 // If the RouteToFrame call returned a failure then inform the result
839 // back to the plugin asynchronously. 862 // back to the plugin asynchronously.
840 if ((routing_status == INVALID_URL) || 863 if ((routing_status == INVALID_URL) ||
841 (routing_status == GENERAL_FAILURE)) { 864 (routing_status == GENERAL_FAILURE)) {
842 resource_client->DidFail(); 865 resource_client->DidFail();
843 return; 866 return;
844 } 867 }
845 868
846 // CreateResourceClient() sends a synchronous IPC message so it's possible 869 // CreateResourceClient() sends a synchronous IPC message so it's possible
847 // that TearDownPluginInstance() may have been called in the nested 870 // that TearDownPluginInstance() may have been called in the nested
848 // message loop. If so, don't start the request. 871 // message loop. If so, don't start the request.
849 if (!delegate_) 872 if (!delegate_)
850 return; 873 return;
851 874
852 InitiateHTTPRequest(resource_id, resource_client, method, buf, len, 875 InitiateHTTPRequest(resource_id, resource_client, method, buf, len,
853 complete_url, NULL, use_plugin_src_as_referrer); 876 complete_url, NULL, use_plugin_src_as_referrer);
854 } 877 }
855 } 878 }
856 879
857 int WebPluginImpl::GetNextResourceId() { 880 unsigned long WebPluginImpl::GetNextResourceId() {
858 static int next_id = 0; 881 if (!webframe_)
859 return ++next_id; 882 return 0;
883 WebView* view = webframe_->view();
884 if (!view)
885 return 0;
886 return view->createUniqueIdentifierForRequest();
860 } 887 }
861 888
862 bool WebPluginImpl::InitiateHTTPRequest(int resource_id, 889 bool WebPluginImpl::InitiateHTTPRequest(unsigned long resource_id,
863 WebPluginResourceClient* client, 890 WebPluginResourceClient* client,
864 const char* method, const char* buf, 891 const char* method, const char* buf,
865 int buf_len, 892 int buf_len,
866 const GURL& url, 893 const GURL& url,
867 const char* range_info, 894 const char* range_info,
868 bool use_plugin_src_as_referrer) { 895 bool use_plugin_src_as_referrer) {
869 if (!client) { 896 if (!client) {
870 NOTREACHED(); 897 NOTREACHED();
871 return false; 898 return false;
872 } 899 }
(...skipping 21 matching lines...) Expand all
894 921
895 // GetURL/PostURL requests initiated explicitly by plugins should specify the 922 // GetURL/PostURL requests initiated explicitly by plugins should specify the
896 // plugin SRC url as the referrer if it is available. 923 // plugin SRC url as the referrer if it is available.
897 GURL referrer_url; 924 GURL referrer_url;
898 if (use_plugin_src_as_referrer && !plugin_url_.spec().empty()) 925 if (use_plugin_src_as_referrer && !plugin_url_.spec().empty())
899 referrer_url = plugin_url_; 926 referrer_url = plugin_url_;
900 webframe_->setReferrerForRequest(info.request, referrer_url); 927 webframe_->setReferrerForRequest(info.request, referrer_url);
901 928
902 // Sets the routing id to associate the ResourceRequest with the RenderView. 929 // Sets the routing id to associate the ResourceRequest with the RenderView.
903 webframe_->dispatchWillSendRequest(info.request); 930 webframe_->dispatchWillSendRequest(info.request);
931 if (WebDevToolsAgent* devtools_agent = webframe_->view()->devToolsAgent()) {
932 devtools_agent->identifierForInitialRequest(resource_id, webframe_,
933 info.request);
934 devtools_agent->willSendRequest(resource_id, info.request);
935 }
904 936
905 info.loader.reset(WebKit::webKitClient()->createURLLoader()); 937 info.loader.reset(WebKit::webKitClient()->createURLLoader());
906 if (!info.loader.get()) 938 if (!info.loader.get())
907 return false; 939 return false;
908 info.loader->loadAsynchronously(info.request, this); 940 info.loader->loadAsynchronously(info.request, this);
909 941
910 clients_.push_back(info); 942 clients_.push_back(info);
911 return true; 943 return true;
912 } 944 }
913 945
914 void WebPluginImpl::CancelDocumentLoad() { 946 void WebPluginImpl::CancelDocumentLoad() {
915 if (webframe_) { 947 if (webframe_) {
916 ignore_response_error_ = true; 948 ignore_response_error_ = true;
917 webframe_->stopLoading(); 949 webframe_->stopLoading();
918 } 950 }
919 } 951 }
920 952
921 void WebPluginImpl::InitiateHTTPRangeRequest(const char* url, 953 void WebPluginImpl::InitiateHTTPRangeRequest(const char* url,
922 const char* range_info, 954 const char* range_info,
923 intptr_t existing_stream, 955 intptr_t existing_stream,
924 bool notify_needed, 956 bool notify_needed,
925 intptr_t notify_data) { 957 intptr_t notify_data) {
926 int resource_id = GetNextResourceId(); 958 unsigned long resource_id = GetNextResourceId();
959 if (!resource_id)
960 return;
961
927 GURL complete_url = CompleteURL(url); 962 GURL complete_url = CompleteURL(url);
928 963
929 WebPluginResourceClient* resource_client = delegate_->CreateResourceClient( 964 WebPluginResourceClient* resource_client = delegate_->CreateResourceClient(
930 resource_id, complete_url, notify_needed, notify_data, existing_stream); 965 resource_id, complete_url, notify_needed, notify_data, existing_stream);
931 InitiateHTTPRequest( 966 InitiateHTTPRequest(
932 resource_id, resource_client, "GET", NULL, 0, complete_url, range_info, 967 resource_id, resource_client, "GET", NULL, 0, complete_url, range_info,
933 true); 968 true);
934 } 969 }
935 970
936 void WebPluginImpl::SetDeferResourceLoading(int resource_id, bool defer) { 971 void WebPluginImpl::SetDeferResourceLoading(unsigned long resource_id,
972 bool defer) {
937 std::vector<ClientInfo>::iterator client_index = clients_.begin(); 973 std::vector<ClientInfo>::iterator client_index = clients_.begin();
938 while (client_index != clients_.end()) { 974 while (client_index != clients_.end()) {
939 ClientInfo& client_info = *client_index; 975 ClientInfo& client_info = *client_index;
940 976
941 if (client_info.id == resource_id) { 977 if (client_info.id == resource_id) {
942 client_info.loader->setDefersLoading(defer); 978 client_info.loader->setDefersLoading(defer);
943 979
944 // If we determined that the request had failed via the HTTP headers 980 // If we determined that the request had failed via the HTTP headers
945 // in the response then we send out a failure notification to the 981 // in the response then we send out a failure notification to the
946 // plugin process, as certain plugins don't handle HTTP failure codes 982 // plugin process, as certain plugins don't handle HTTP failure codes
947 // correctly. 983 // correctly.
948 if (!defer && client_info.client && 984 if (!defer && client_info.client &&
949 client_info.pending_failure_notification) { 985 client_info.pending_failure_notification) {
950 // The ClientInfo and the iterator can become invalid due to the call 986 // The ClientInfo and the iterator can become invalid due to the call
951 // to DidFail below. 987 // to DidFail below.
952 WebPluginResourceClient* resource_client = client_info.client; 988 WebPluginResourceClient* resource_client = client_info.client;
953 client_info.loader->cancel(); 989 client_info.loader->cancel();
954 clients_.erase(client_index++); 990 clients_.erase(client_index++);
955 resource_client->DidFail(); 991 resource_client->DidFail();
992
993 // Report that resource loading finished.
994 WebDevToolsAgent* devtools_agent = webframe_->view()->devToolsAgent();
995 if (devtools_agent)
996 devtools_agent->didFinishLoading(resource_id);
956 } 997 }
957 break; 998 break;
958 } 999 }
959 client_index++; 1000 client_index++;
960 } 1001 }
961 } 1002 }
962 1003
963 void WebPluginImpl::HandleHttpMultipartResponse( 1004 void WebPluginImpl::HandleHttpMultipartResponse(
964 const WebURLResponse& response, WebPluginResourceClient* client) { 1005 const WebURLResponse& response, WebPluginResourceClient* client) {
965 std::string multipart_boundary; 1006 std::string multipart_boundary;
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1059 client_index = clients_.erase(client_index); 1100 client_index = clients_.erase(client_index);
1060 } 1101 }
1061 1102
1062 // This needs to be called now and not in the destructor since the 1103 // This needs to be called now and not in the destructor since the
1063 // webframe_ might not be valid anymore. 1104 // webframe_ might not be valid anymore.
1064 webframe_ = NULL; 1105 webframe_ = NULL;
1065 method_factory_.RevokeAll(); 1106 method_factory_.RevokeAll();
1066 } 1107 }
1067 1108
1068 } // namespace webkit_glue 1109 } // namespace webkit_glue
OLDNEW
« no previous file with comments | « webkit/glue/webplugin_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698