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