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

Side by Side Diff: content/browser/webui/url_data_manager_backend.cc

Issue 2393773002: Fix devtools unable to start a shared workers. (Closed)
Patch Set: Created 4 years, 2 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 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/webui/url_data_manager_backend.h" 5 #include "content/browser/webui/url_data_manager_backend.h"
6 6
7 #include <set> 7 #include <set>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 std::string origin = GetOriginHeaderValue(request); 690 std::string origin = GetOriginHeaderValue(request);
691 if (!origin.empty()) { 691 if (!origin.empty()) {
692 std::string header = 692 std::string header =
693 source->source()->GetAccessControlAllowOriginForOrigin(origin); 693 source->source()->GetAccessControlAllowOriginForOrigin(origin);
694 DCHECK(header.empty() || header == origin || header == "*" || 694 DCHECK(header.empty() || header == origin || header == "*" ||
695 header == "null"); 695 header == "null");
696 job->set_access_control_allow_origin(header); 696 job->set_access_control_allow_origin(header);
697 } 697 }
698 698
699 // Look up additional request info to pass down. 699 // Look up additional request info to pass down.
700 int child_id = -1;
700 ResourceRequestInfo::WebContentsGetter wc_getter; 701 ResourceRequestInfo::WebContentsGetter wc_getter;
701 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request); 702 const ResourceRequestInfo* info = ResourceRequestInfo::ForRequest(request);
702 if (info) 703 if (info) {
704 child_id = info->GetChildID();
703 wc_getter = info->GetWebContentsGetterForRequest(); 705 wc_getter = info->GetWebContentsGetterForRequest();
706 }
704 707
705 // Forward along the request to the data source. 708 // Forward along the request to the data source.
706 base::MessageLoop* target_message_loop = 709 base::MessageLoop* target_message_loop =
707 source->source()->MessageLoopForRequestPath(path); 710 source->source()->MessageLoopForRequestPath(path);
708 if (!target_message_loop) { 711 if (!target_message_loop) {
709 job->MimeTypeAvailable(source->source()->GetMimeType(path)); 712 job->MimeTypeAvailable(source->source()->GetMimeType(path));
710 // Eliminate potentially dangling pointer to avoid future use. 713 // Eliminate potentially dangling pointer to avoid future use.
711 job = nullptr; 714 job = nullptr;
712 715
713 // The DataSource is agnostic to which thread StartDataRequest is called 716 // The DataSource is agnostic to which thread StartDataRequest is called
714 // on for this path. Call directly into it from this thread, the IO 717 // on for this path. Call directly into it from this thread, the IO
715 // thread. 718 // thread.
716 source->source()->StartDataRequest( 719 source->source()->StartDataRequest(
717 path, wc_getter, 720 path, wc_getter,
718 base::Bind(&URLDataSourceImpl::SendResponse, source, request_id)); 721 base::Bind(&URLDataSourceImpl::SendResponse, source, request_id));
719 } else { 722 } else {
720 // URLRequestChromeJob should receive mime type before data. This 723 // URLRequestChromeJob should receive mime type before data. This
721 // is guaranteed because request for mime type is placed in the 724 // is guaranteed because request for mime type is placed in the
722 // message loop before request for data. And correspondingly their 725 // message loop before request for data. And correspondingly their
723 // replies are put on the IO thread in the same order. 726 // replies are put on the IO thread in the same order.
724 target_message_loop->task_runner()->PostTask( 727 target_message_loop->task_runner()->PostTask(
725 FROM_HERE, base::Bind(&GetMimeTypeOnUI, base::RetainedRef(source), path, 728 FROM_HERE, base::Bind(&GetMimeTypeOnUI, base::RetainedRef(source), path,
726 job->AsWeakPtr())); 729 job->AsWeakPtr()));
727 730
728 // The DataSource wants StartDataRequest to be called on a specific thread, 731 // The DataSource wants StartDataRequest to be called on a specific thread,
729 // usually the UI thread, for this path. 732 // usually the UI thread, for this path.
730 target_message_loop->task_runner()->PostTask( 733 target_message_loop->task_runner()->PostTask(
731 FROM_HERE, base::Bind(&URLDataManagerBackend::CallStartRequest, 734 FROM_HERE, base::Bind(&URLDataManagerBackend::CallStartRequest,
732 base::RetainedRef(source), path, 735 base::RetainedRef(source), path, child_id,
733 wc_getter, request_id)); 736 wc_getter, request_id));
734 } 737 }
735 return true; 738 return true;
736 } 739 }
737 740
738 URLDataSourceImpl* URLDataManagerBackend::GetDataSourceFromURL( 741 URLDataSourceImpl* URLDataManagerBackend::GetDataSourceFromURL(
739 const GURL& url) { 742 const GURL& url) {
740 // The input usually looks like: chrome://source_name/extra_bits?foo 743 // The input usually looks like: chrome://source_name/extra_bits?foo
741 // so do a lookup using the host of the URL. 744 // so do a lookup using the host of the URL.
742 DataSourceMap::iterator i = data_sources_.find(url.host()); 745 DataSourceMap::iterator i = data_sources_.find(url.host());
743 if (i != data_sources_.end()) 746 if (i != data_sources_.end())
744 return i->second.get(); 747 return i->second.get();
745 748
746 // No match using the host of the URL, so do a lookup using the scheme for 749 // No match using the host of the URL, so do a lookup using the scheme for
747 // URLs on the form source_name://extra_bits/foo . 750 // URLs on the form source_name://extra_bits/foo .
748 i = data_sources_.find(url.scheme() + "://"); 751 i = data_sources_.find(url.scheme() + "://");
749 if (i != data_sources_.end()) 752 if (i != data_sources_.end())
750 return i->second.get(); 753 return i->second.get();
751 754
752 // No matches found, so give up. 755 // No matches found, so give up.
753 return nullptr; 756 return nullptr;
754 } 757 }
755 758
756 void URLDataManagerBackend::CallStartRequest( 759 void URLDataManagerBackend::CallStartRequest(
757 scoped_refptr<URLDataSourceImpl> source, 760 scoped_refptr<URLDataSourceImpl> source,
758 const std::string& path, 761 const std::string& path,
762 int child_id,
759 const ResourceRequestInfo::WebContentsGetter& wc_getter, 763 const ResourceRequestInfo::WebContentsGetter& wc_getter,
760 int request_id) { 764 int request_id) {
761 if (BrowserThread::CurrentlyOn(BrowserThread::UI) && !wc_getter.is_null() && 765 if (BrowserThread::CurrentlyOn(BrowserThread::UI) && child_id != -1 &&
762 !wc_getter.Run()) { 766 !RenderProcessHost::FromID(child_id)) {
763 // Make the request fail if its initiating WebContents is no longer valid. 767 // Make the request fail if its initiating renderer is no longer valid.
764 // This can happen when the IO thread posts this task just before the 768 // This can happen when the IO thread posts this task just before the
765 // WebContents shuts down. 769 // renderer shuts down.
770 // Note we check the process id instead of wc_getter because requests from
771 // workers wouldn't have a WebContents.
766 source->SendResponse(request_id, nullptr); 772 source->SendResponse(request_id, nullptr);
767 return; 773 return;
768 } 774 }
769 source->source()->StartDataRequest( 775 source->source()->StartDataRequest(
770 path, 776 path,
771 wc_getter, 777 wc_getter,
772 base::Bind(&URLDataSourceImpl::SendResponse, source, request_id)); 778 base::Bind(&URLDataSourceImpl::SendResponse, source, request_id));
773 } 779 }
774 780
775 void URLDataManagerBackend::RemoveRequest(URLRequestChromeJob* job) { 781 void URLDataManagerBackend::RemoveRequest(URLRequestChromeJob* job) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 844
839 } // namespace 845 } // namespace
840 846
841 net::URLRequestJobFactory::ProtocolHandler* CreateDevToolsProtocolHandler( 847 net::URLRequestJobFactory::ProtocolHandler* CreateDevToolsProtocolHandler(
842 ResourceContext* resource_context, 848 ResourceContext* resource_context,
843 bool is_incognito) { 849 bool is_incognito) {
844 return new DevToolsJobFactory(resource_context, is_incognito); 850 return new DevToolsJobFactory(resource_context, is_incognito);
845 } 851 }
846 852
847 } // namespace content 853 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/webui/url_data_manager_backend.h ('k') | content/public/browser/url_data_source.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698