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

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

Issue 459003: Don't set referrers on outgoing plugin requests if the load_manually flag is ... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' 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 | Annotate | Revision Log
« 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"
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 472
473 WebPluginImpl::RoutingStatus WebPluginImpl::RouteToFrame( 473 WebPluginImpl::RoutingStatus WebPluginImpl::RouteToFrame(
474 const char *method, 474 const char *method,
475 bool is_javascript_url, 475 bool is_javascript_url,
476 const char* target, 476 const char* target,
477 unsigned int len, 477 unsigned int len,
478 const char* buf, 478 const char* buf,
479 bool is_file_data, 479 bool is_file_data,
480 bool notify_needed, 480 bool notify_needed,
481 intptr_t notify_data, 481 intptr_t notify_data,
482 const char* url) { 482 const char* url,
483 Referrer referrer_flag) {
483 // If there is no target, there is nothing to do 484 // If there is no target, there is nothing to do
484 if (!target) 485 if (!target)
485 return NOT_ROUTED; 486 return NOT_ROUTED;
486 487
487 // This could happen if the WebPluginContainer was already deleted. 488 // This could happen if the WebPluginContainer was already deleted.
488 if (!webframe_) 489 if (!webframe_)
489 return NOT_ROUTED; 490 return NOT_ROUTED;
490 491
491 WebString target_str = WebString::fromUTF8(target); 492 WebString target_str = WebString::fromUTF8(target);
492 493
(...skipping 22 matching lines...) Expand all
515 516
516 GURL complete_url = CompleteURL(url); 517 GURL complete_url = CompleteURL(url);
517 518
518 if (strcmp(method, "GET") != 0) { 519 if (strcmp(method, "GET") != 0) {
519 // We're only going to route HTTP/HTTPS requests 520 // We're only going to route HTTP/HTTPS requests
520 if (!(complete_url.SchemeIs("http") || complete_url.SchemeIs("https"))) 521 if (!(complete_url.SchemeIs("http") || complete_url.SchemeIs("https")))
521 return INVALID_URL; 522 return INVALID_URL;
522 } 523 }
523 524
524 WebURLRequest request(complete_url); 525 WebURLRequest request(complete_url);
526 SetReferrer(&request, referrer_flag);
527
525 request.setHTTPMethod(WebString::fromUTF8(method)); 528 request.setHTTPMethod(WebString::fromUTF8(method));
526 if (len > 0) { 529 if (len > 0) {
527 if (!is_file_data) { 530 if (!is_file_data) {
528 if (!SetPostData(&request, buf, len)) { 531 if (!SetPostData(&request, buf, len)) {
529 // Uhoh - we're in trouble. There isn't a good way 532 // Uhoh - we're in trouble. There isn't a good way
530 // to recover at this point. Break out. 533 // to recover at this point. Break out.
531 NOTREACHED(); 534 NOTREACHED();
532 return ROUTED; 535 return ROUTED;
533 } 536 }
534 } else { 537 } else {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 } 591 }
589 592
590 void WebPluginImpl::InvalidateRect(const gfx::Rect& rect) { 593 void WebPluginImpl::InvalidateRect(const gfx::Rect& rect) {
591 if (container_) 594 if (container_)
592 container_->invalidateRect(rect); 595 container_->invalidateRect(rect);
593 } 596 }
594 597
595 void WebPluginImpl::OnDownloadPluginSrcUrl() { 598 void WebPluginImpl::OnDownloadPluginSrcUrl() {
596 HandleURLRequestInternal("GET", false, NULL, 0, NULL, false, false, 599 HandleURLRequestInternal("GET", false, NULL, 0, NULL, false, false,
597 plugin_url_.spec().c_str(), NULL, false, 600 plugin_url_.spec().c_str(), NULL, false,
598 false); 601 DOCUMENT_URL);
599 } 602 }
600 603
601 WebPluginResourceClient* WebPluginImpl::GetClientFromLoader( 604 WebPluginResourceClient* WebPluginImpl::GetClientFromLoader(
602 WebURLLoader* loader) { 605 WebURLLoader* loader) {
603 ClientInfo* client_info = GetClientInfoFromLoader(loader); 606 ClientInfo* client_info = GetClientInfoFromLoader(loader);
604 if (client_info) 607 if (client_info)
605 return client_info->client; 608 return client_info->client;
606 return NULL; 609 return NULL;
607 } 610 }
608 611
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 TearDownPluginInstance(NULL); 789 TearDownPluginInstance(NULL);
787 container_ = container; 790 container_ = container;
788 } 791 }
789 792
790 void WebPluginImpl::HandleURLRequest(const char *method, 793 void WebPluginImpl::HandleURLRequest(const char *method,
791 bool is_javascript_url, 794 bool is_javascript_url,
792 const char* target, unsigned int len, 795 const char* target, unsigned int len,
793 const char* buf, bool is_file_data, 796 const char* buf, bool is_file_data,
794 bool notify, const char* url, 797 bool notify, const char* url,
795 intptr_t notify_data, bool popups_allowed) { 798 intptr_t notify_data, bool popups_allowed) {
799 // GetURL/PostURL requests initiated explicitly by plugins should specify the
800 // plugin SRC url as the referrer if it is available.
796 HandleURLRequestInternal(method, is_javascript_url, target, len, buf, 801 HandleURLRequestInternal(method, is_javascript_url, target, len, buf,
797 is_file_data, notify, url, notify_data, 802 is_file_data, notify, url, notify_data,
798 popups_allowed, true); 803 popups_allowed, PLUGIN_SRC);
799 } 804 }
800 805
801 void WebPluginImpl::HandleURLRequestInternal( 806 void WebPluginImpl::HandleURLRequestInternal(
802 const char *method, bool is_javascript_url, const char* target, 807 const char *method, bool is_javascript_url, const char* target,
803 unsigned int len, const char* buf, bool is_file_data, bool notify, 808 unsigned int len, const char* buf, bool is_file_data, bool notify,
804 const char* url, intptr_t notify_data, bool popups_allowed, 809 const char* url, intptr_t notify_data, bool popups_allowed,
805 bool use_plugin_src_as_referrer) { 810 Referrer referrer_flag) {
806 // For this request, we either route the output to a frame 811 // For this request, we either route the output to a frame
807 // because a target has been specified, or we handle the request 812 // because a target has been specified, or we handle the request
808 // here, i.e. by executing the script if it is a javascript url 813 // here, i.e. by executing the script if it is a javascript url
809 // or by initiating a download on the URL, etc. There is one special 814 // or by initiating a download on the URL, etc. There is one special
810 // case in that the request is a javascript url and the target is "_self", 815 // case in that the request is a javascript url and the target is "_self",
811 // in which case we route the output to the plugin rather than routing it 816 // in which case we route the output to the plugin rather than routing it
812 // to the plugin's frame. 817 // to the plugin's frame.
813 RoutingStatus routing_status = 818 RoutingStatus routing_status =
814 RouteToFrame(method, is_javascript_url, target, len, buf, is_file_data, 819 RouteToFrame(method, is_javascript_url, target, len, buf, is_file_data,
815 notify, notify_data, url); 820 notify, notify_data, url, referrer_flag);
816 if (routing_status == ROUTED) 821 if (routing_status == ROUTED)
817 return; 822 return;
818 823
819 if (is_javascript_url) { 824 if (is_javascript_url) {
820 GURL gurl(url); 825 GURL gurl(url);
821 WebString result = container_->executeScriptURL(gurl, popups_allowed); 826 WebString result = container_->executeScriptURL(gurl, popups_allowed);
822 827
823 // delegate_ could be NULL because executeScript caused the container to 828 // delegate_ could be NULL because executeScript caused the container to
824 // be deleted. 829 // be deleted.
825 if (delegate_) { 830 if (delegate_) {
(...skipping 17 matching lines...) Expand all
843 return; 848 return;
844 } 849 }
845 850
846 // CreateResourceClient() sends a synchronous IPC message so it's possible 851 // CreateResourceClient() sends a synchronous IPC message so it's possible
847 // that TearDownPluginInstance() may have been called in the nested 852 // that TearDownPluginInstance() may have been called in the nested
848 // message loop. If so, don't start the request. 853 // message loop. If so, don't start the request.
849 if (!delegate_) 854 if (!delegate_)
850 return; 855 return;
851 856
852 InitiateHTTPRequest(resource_id, resource_client, method, buf, len, 857 InitiateHTTPRequest(resource_id, resource_client, method, buf, len,
853 complete_url, NULL, use_plugin_src_as_referrer); 858 complete_url, NULL, referrer_flag);
854 } 859 }
855 } 860 }
856 861
857 int WebPluginImpl::GetNextResourceId() { 862 int WebPluginImpl::GetNextResourceId() {
858 static int next_id = 0; 863 static int next_id = 0;
859 return ++next_id; 864 return ++next_id;
860 } 865 }
861 866
862 bool WebPluginImpl::InitiateHTTPRequest(int resource_id, 867 bool WebPluginImpl::InitiateHTTPRequest(int resource_id,
863 WebPluginResourceClient* client, 868 WebPluginResourceClient* client,
864 const char* method, const char* buf, 869 const char* method, const char* buf,
865 int buf_len, 870 int buf_len,
866 const GURL& url, 871 const GURL& url,
867 const char* range_info, 872 const char* range_info,
868 bool use_plugin_src_as_referrer) { 873 Referrer referrer_flag) {
869 if (!client) { 874 if (!client) {
870 NOTREACHED(); 875 NOTREACHED();
871 return false; 876 return false;
872 } 877 }
873 878
874 ClientInfo info; 879 ClientInfo info;
875 info.id = resource_id; 880 info.id = resource_id;
876 info.client = client; 881 info.client = client;
877 info.request.initialize(); 882 info.request.initialize();
878 info.request.setURL(url); 883 info.request.setURL(url);
879 info.request.setRequestorProcessID(delegate_->GetProcessId()); 884 info.request.setRequestorProcessID(delegate_->GetProcessId());
880 info.request.setTargetType(WebURLRequest::TargetIsObject); 885 info.request.setTargetType(WebURLRequest::TargetIsObject);
881 info.request.setHTTPMethod(WebString::fromUTF8(method)); 886 info.request.setHTTPMethod(WebString::fromUTF8(method));
882 info.pending_failure_notification = false; 887 info.pending_failure_notification = false;
883 888
884 if (range_info) { 889 if (range_info) {
885 info.request.addHTTPHeaderField(WebString::fromUTF8("Range"), 890 info.request.addHTTPHeaderField(WebString::fromUTF8("Range"),
886 WebString::fromUTF8(range_info)); 891 WebString::fromUTF8(range_info));
887 } 892 }
888 893
889 if (strcmp(method, "POST") == 0) { 894 if (strcmp(method, "POST") == 0) {
890 // Adds headers or form data to a request. This must be called before 895 // Adds headers or form data to a request. This must be called before
891 // we initiate the actual request. 896 // we initiate the actual request.
892 SetPostData(&info.request, buf, buf_len); 897 SetPostData(&info.request, buf, buf_len);
893 } 898 }
894 899
895 // GetURL/PostURL requests initiated explicitly by plugins should specify the 900 SetReferrer(&info.request, referrer_flag);
896 // plugin SRC url as the referrer if it is available.
897 GURL referrer_url;
898 if (use_plugin_src_as_referrer && !plugin_url_.spec().empty())
899 referrer_url = plugin_url_;
900 webframe_->setReferrerForRequest(info.request, referrer_url);
901 901
902 // Sets the routing id to associate the ResourceRequest with the RenderView. 902 // Sets the routing id to associate the ResourceRequest with the RenderView.
903 webframe_->dispatchWillSendRequest(info.request); 903 webframe_->dispatchWillSendRequest(info.request);
904 904
905 info.loader.reset(WebKit::webKitClient()->createURLLoader()); 905 info.loader.reset(WebKit::webKitClient()->createURLLoader());
906 if (!info.loader.get()) 906 if (!info.loader.get())
907 return false; 907 return false;
908 info.loader->loadAsynchronously(info.request, this); 908 info.loader->loadAsynchronously(info.request, this);
909 909
910 clients_.push_back(info); 910 clients_.push_back(info);
(...skipping 12 matching lines...) Expand all
923 intptr_t existing_stream, 923 intptr_t existing_stream,
924 bool notify_needed, 924 bool notify_needed,
925 intptr_t notify_data) { 925 intptr_t notify_data) {
926 int resource_id = GetNextResourceId(); 926 int resource_id = GetNextResourceId();
927 GURL complete_url = CompleteURL(url); 927 GURL complete_url = CompleteURL(url);
928 928
929 WebPluginResourceClient* resource_client = delegate_->CreateResourceClient( 929 WebPluginResourceClient* resource_client = delegate_->CreateResourceClient(
930 resource_id, complete_url, notify_needed, notify_data, existing_stream); 930 resource_id, complete_url, notify_needed, notify_data, existing_stream);
931 InitiateHTTPRequest( 931 InitiateHTTPRequest(
932 resource_id, resource_client, "GET", NULL, 0, complete_url, range_info, 932 resource_id, resource_client, "GET", NULL, 0, complete_url, range_info,
933 true); 933 load_manually_ ? NO_REFERRER : PLUGIN_SRC);
934 } 934 }
935 935
936 void WebPluginImpl::SetDeferResourceLoading(int resource_id, bool defer) { 936 void WebPluginImpl::SetDeferResourceLoading(int resource_id, bool defer) {
937 std::vector<ClientInfo>::iterator client_index = clients_.begin(); 937 std::vector<ClientInfo>::iterator client_index = clients_.begin();
938 while (client_index != clients_.end()) { 938 while (client_index != clients_.end()) {
939 ClientInfo& client_info = *client_index; 939 ClientInfo& client_info = *client_index;
940 940
941 if (client_info.id == resource_id) { 941 if (client_info.id == resource_id) {
942 client_info.loader->setDefersLoading(defer); 942 client_info.loader->setDefersLoading(defer);
943 943
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
1058 1058
1059 client_index = clients_.erase(client_index); 1059 client_index = clients_.erase(client_index);
1060 } 1060 }
1061 1061
1062 // This needs to be called now and not in the destructor since the 1062 // This needs to be called now and not in the destructor since the
1063 // webframe_ might not be valid anymore. 1063 // webframe_ might not be valid anymore.
1064 webframe_ = NULL; 1064 webframe_ = NULL;
1065 method_factory_.RevokeAll(); 1065 method_factory_.RevokeAll();
1066 } 1066 }
1067 1067
1068 void WebPluginImpl::SetReferrer(WebKit::WebURLRequest* request,
1069 Referrer referrer_flag) {
1070 switch (referrer_flag) {
1071 case DOCUMENT_URL:
1072 webframe_->setReferrerForRequest(*request, GURL());
1073 break;
1074
1075 case PLUGIN_SRC:
1076 webframe_->setReferrerForRequest(*request, plugin_url_);
1077 break;
1078
1079 default:
1080 break;
1081 }
1082 }
1083
1068 } // namespace webkit_glue 1084 } // 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