| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CONTENT_BROWSER_TRANSITION_REQUEST_MANAGER_H_ | 5 #ifndef CONTENT_BROWSER_TRANSITION_REQUEST_MANAGER_H_ |
| 6 #define CONTENT_BROWSER_TRANSITION_REQUEST_MANAGER_H_ | 6 #define CONTENT_BROWSER_TRANSITION_REQUEST_MANAGER_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <map> |
| 9 #include <string> |
| 9 #include <utility> | 10 #include <utility> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 13 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 14 #include "content/common/content_export.h" | 15 #include "content/common/content_export.h" |
| 15 #include "url/gurl.h" | 16 #include "url/gurl.h" |
| 16 | 17 |
| 17 template <typename T> | 18 template <typename T> |
| 18 struct DefaultSingletonTraits; | 19 struct DefaultSingletonTraits; |
| 19 | 20 |
| 20 namespace net { | 21 namespace net { |
| 21 class HttpResponseHeaders; | 22 class HttpResponseHeaders; |
| 22 } | 23 } |
| 24 class GURL; |
| 23 | 25 |
| 24 namespace content { | 26 namespace content { |
| 25 | 27 |
| 28 // This struct passes data about an imminent transition between threads. |
| 29 struct TransitionLayerData { |
| 30 TransitionLayerData(); |
| 31 ~TransitionLayerData(); |
| 32 |
| 33 std::string markup; |
| 34 std::string css_selector; |
| 35 scoped_refptr<net::HttpResponseHeaders> response_headers; |
| 36 GURL request_url; |
| 37 }; |
| 38 |
| 26 // TransitionRequestManager is used to handle bookkeeping for transition | 39 // TransitionRequestManager is used to handle bookkeeping for transition |
| 27 // requests and responses. | 40 // requests and responses. |
| 28 // | 41 // |
| 29 // TransitionRequestManager is a singleton and should only be accessed on the IO | 42 // TransitionRequestManager is a singleton and should only be accessed on the IO |
| 30 // thread. | 43 // thread. |
| 31 // | 44 // |
| 32 class TransitionRequestManager { | 45 class TransitionRequestManager { |
| 33 public: | 46 public: |
| 34 // Returns the singleton instance. | 47 // Returns the singleton instance. |
| 35 CONTENT_EXPORT static TransitionRequestManager* GetInstance(); | 48 CONTENT_EXPORT static TransitionRequestManager* GetInstance(); |
| 36 | 49 |
| 37 // Parses out any transition-entering-stylesheet link headers from the | 50 // Parses out any transition-entering-stylesheet link headers from the |
| 38 // response headers. | 51 // response headers. |
| 39 CONTENT_EXPORT static void ParseTransitionStylesheetsFromHeaders( | 52 CONTENT_EXPORT static void ParseTransitionStylesheetsFromHeaders( |
| 40 const scoped_refptr<net::HttpResponseHeaders>& headers, | 53 const scoped_refptr<net::HttpResponseHeaders>& headers, |
| 41 std::vector<GURL>& entering_stylesheets, | 54 std::vector<GURL>& entering_stylesheets, |
| 42 const GURL& resolve_address); | 55 const GURL& resolve_address); |
| 43 | 56 |
| 44 // Returns whether the RenderFrameHost specified by the given IDs currently | 57 // Returns whether the RenderFrameHost specified by the given IDs currently |
| 45 // has a pending transition request. If so, we will have to delay the | 58 // has any pending transition request data. If so, we will have to delay the |
| 46 // response until the embedder resumes the request. | 59 // response until the embedder resumes the request. |
| 47 bool HasPendingTransitionRequest(int process_id, int render_frame_id); | 60 bool HasPendingTransitionRequest(int render_process_id, |
| 61 int render_frame_id, |
| 62 const GURL& request_url, |
| 63 TransitionLayerData* transition_data); |
| 48 | 64 |
| 49 // Sets whether the RenderFrameHost specified by the given IDs currently has a | 65 // Adds pending request data for a transition navigation for the |
| 50 // pending transition request. | 66 // RenderFrameHost specified by the given IDs. |
| 51 CONTENT_EXPORT void SetHasPendingTransitionRequest(int process_id, | 67 CONTENT_EXPORT void AddPendingTransitionRequestData( |
| 52 int render_frame_id, | 68 int render_process_id, |
| 53 bool has_pending); | 69 int render_frame_id, |
| 70 const std::string& allowed_destination_host_pattern, |
| 71 const std::string& css_selector, |
| 72 const std::string& markup); |
| 73 |
| 74 void ClearPendingTransitionRequestData(int render_process_id, |
| 75 int render_frame_id); |
| 54 | 76 |
| 55 private: | 77 private: |
| 78 class TransitionRequestData { |
| 79 public: |
| 80 TransitionRequestData(); |
| 81 ~TransitionRequestData(); |
| 82 void AddEntry(const std::string& allowed_destination_host_pattern, |
| 83 const std::string& selector, |
| 84 const std::string& markup); |
| 85 bool FindEntry(const GURL& request_url, |
| 86 TransitionLayerData* transition_data); |
| 87 |
| 88 private: |
| 89 struct AllowedEntry { |
| 90 // These strings could have originated from a compromised renderer, |
| 91 // and should not be trusted or assumed safe. They are only used within |
| 92 // a sandboxed iframe with scripts disabled. |
| 93 std::string allowed_destination_host_pattern; |
| 94 std::string css_selector; |
| 95 std::string markup; |
| 96 |
| 97 AllowedEntry(const std::string& allowed_destination_host_pattern, |
| 98 const std::string& css_selector, |
| 99 const std::string& markup) : |
| 100 allowed_destination_host_pattern(allowed_destination_host_pattern), |
| 101 css_selector(css_selector), |
| 102 markup(markup) {} |
| 103 }; |
| 104 std::vector<AllowedEntry> allowed_entries_; |
| 105 }; |
| 106 |
| 56 friend struct DefaultSingletonTraits<TransitionRequestManager>; | 107 friend struct DefaultSingletonTraits<TransitionRequestManager>; |
| 57 typedef std::set<std::pair<int, int> > RenderFrameSet; | 108 typedef std::map<std::pair<int, int>, TransitionRequestData> |
| 109 RenderFrameRequestDataMap; |
| 58 | 110 |
| 59 TransitionRequestManager(); | 111 TransitionRequestManager(); |
| 60 ~TransitionRequestManager(); | 112 ~TransitionRequestManager(); |
| 61 | 113 |
| 62 // Set of (render_process_host_id, render_frame_id) pairs of all | 114 // Map of (render_process_host_id, render_frame_id) pairs of all |
| 63 // RenderFrameHosts that have pending transition requests. Used to pass | 115 // RenderFrameHosts that have pending cross-site requests and their data. |
| 64 // information to the CrossSiteResourceHandler without doing a round-trip | 116 // Used to pass information to the CrossSiteResourceHandler without doing a |
| 65 // between IO->UI->IO threads. | 117 // round-trip between IO->UI->IO threads. |
| 66 RenderFrameSet pending_transition_frames_; | 118 RenderFrameRequestDataMap pending_transition_frames_; |
| 67 | 119 |
| 68 DISALLOW_COPY_AND_ASSIGN(TransitionRequestManager); | 120 DISALLOW_COPY_AND_ASSIGN(TransitionRequestManager); |
| 69 }; | 121 }; |
| 70 | 122 |
| 71 } // namespace content | 123 } // namespace content |
| 72 | 124 |
| 73 #endif // CONTENT_BROWSER_TRANSITION_REQUEST_MANAGER_H_ | 125 #endif // CONTENT_BROWSER_TRANSITION_REQUEST_MANAGER_H_ |
| OLD | NEW |