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

Side by Side Diff: extensions/browser/api/web_request/web_request_event_details.h

Issue 2002763003: webRequest: reliably determine tabId (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@webRequest-testing-unload
Patch Set: Last nits Created 4 years, 7 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_EVENT_DETAILS_H_ 5 #ifndef EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_EVENT_DETAILS_H_
6 #define EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_EVENT_DETAILS_H_ 6 #define EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_EVENT_DETAILS_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
(...skipping 18 matching lines...) Expand all
29 // This class provides setters that are aware of these rules. 29 // This class provides setters that are aware of these rules.
30 // 30 //
31 // Not all keys are managed by this class. Keys that do not require a special 31 // Not all keys are managed by this class. Keys that do not require a special
32 // treatment can be set using the generic SetBoolean / SetInteger / SetString 32 // treatment can be set using the generic SetBoolean / SetInteger / SetString
33 // methods (e.g. to set "error", "message", "redirectUrl", "stage" or "tabId"). 33 // methods (e.g. to set "error", "message", "redirectUrl", "stage" or "tabId").
34 // 34 //
35 // This class should be constructed on the IO thread. It can safely be used on 35 // This class should be constructed on the IO thread. It can safely be used on
36 // other threads, as long as there is no concurrent access. 36 // other threads, as long as there is no concurrent access.
37 class WebRequestEventDetails { 37 class WebRequestEventDetails {
38 public: 38 public:
39 using DeterminedFrameIdCallback = 39 using DeterminedFrameDataCallback =
40 base::Callback<void(std::unique_ptr<WebRequestEventDetails>)>; 40 base::Callback<void(std::unique_ptr<WebRequestEventDetails>)>;
41 41
42 // Create a WebRequestEventDetails with the following keys: 42 // Create a WebRequestEventDetails with the following keys:
43 // - method 43 // - method
44 // - requestId 44 // - requestId
45 // - tabId 45 // - tabId
46 // - timeStamp 46 // - timeStamp
47 // - type 47 // - type
48 // - url 48 // - url
49 WebRequestEventDetails(const net::URLRequest* request, int extra_info_spec); 49 WebRequestEventDetails(const net::URLRequest* request, int extra_info_spec);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 82
83 void SetInteger(const std::string& key, int value) { 83 void SetInteger(const std::string& key, int value) {
84 dict_.SetInteger(key, value); 84 dict_.SetInteger(key, value);
85 } 85 }
86 86
87 void SetString(const std::string& key, const std::string& value) { 87 void SetString(const std::string& key, const std::string& value) {
88 dict_.SetString(key, value); 88 dict_.SetString(key, value);
89 } 89 }
90 90
91 // Sets the following keys using information from constructor. 91 // Sets the following keys using information from constructor.
92 // - tabId
92 // - frameId 93 // - frameId
93 // - parentFrameId 94 // - parentFrameId
94 // This must be called from the UI thread. 95 // This must be called from the UI thread.
95 void DetermineFrameIdOnUI(); 96 void DetermineFrameDataOnUI();
96 97
97 // Sets the following keys using information from constructor. 98 // Sets the following keys using information from constructor.
99 // - tabId
98 // - frameId 100 // - frameId
99 // - parentFrameId 101 // - parentFrameId
100 // 102 //
101 // This method is more expensive than DetermineFrameIdOnUI because it may 103 // This method is more expensive than DetermineFrameDataOnUI because it may
102 // involve thread hops, so prefer using DetermineFrameIdOnUI() when possible. 104 // involve thread hops, so prefer using DetermineFrameDataOnUI() if possible.
103 // The callback is called as soon as these IDs are determined, which can be 105 // The callback is called as soon as these IDs are determined, which can be
104 // synchronous or asynchronous. 106 // synchronous or asynchronous.
105 // 107 //
106 // The caller must not use or delete this WebRequestEventDetails instance 108 // The caller must not use or delete this WebRequestEventDetails instance
107 // after calling this method. Ownership of this instance is transferred to 109 // after calling this method. Ownership of this instance is transferred to
108 // |callback|. 110 // |callback|.
109 void DetermineFrameIdOnIO(const DeterminedFrameIdCallback& callback); 111 void DetermineFrameDataOnIO(const DeterminedFrameDataCallback& callback);
110 112
111 // Create an event dictionary that contains all required keys, and also the 113 // Create an event dictionary that contains all required keys, and also the
112 // extra keys as specified by the |extra_info_spec| filter. 114 // extra keys as specified by the |extra_info_spec| filter.
113 // This can be called from any thread. 115 // This can be called from any thread.
114 std::unique_ptr<base::DictionaryValue> GetFilteredDict( 116 std::unique_ptr<base::DictionaryValue> GetFilteredDict(
115 int extra_info_spec) const; 117 int extra_info_spec) const;
116 118
117 // Get the internal dictionary, unfiltered. After this call, the internal 119 // Get the internal dictionary, unfiltered. After this call, the internal
118 // dictionary is empty. 120 // dictionary is empty.
119 std::unique_ptr<base::DictionaryValue> GetAndClearDict(); 121 std::unique_ptr<base::DictionaryValue> GetAndClearDict();
120 122
121 private: 123 private:
122 void OnDeterminedFrameId(std::unique_ptr<WebRequestEventDetails> self, 124 void OnDeterminedFrameData(
123 const DeterminedFrameIdCallback& callback, 125 std::unique_ptr<WebRequestEventDetails> self,
124 const ExtensionApiFrameIdMap::FrameData& frame_data); 126 const DeterminedFrameDataCallback& callback,
127 const ExtensionApiFrameIdMap::FrameData& frame_data);
125 128
126 // The details that are always included in a webRequest event object. 129 // The details that are always included in a webRequest event object.
127 base::DictionaryValue dict_; 130 base::DictionaryValue dict_;
128 131
129 // Extra event details: Only included when |extra_info_spec_| matches. 132 // Extra event details: Only included when |extra_info_spec_| matches.
130 std::unique_ptr<base::DictionaryValue> request_body_; 133 std::unique_ptr<base::DictionaryValue> request_body_;
131 std::unique_ptr<base::ListValue> request_headers_; 134 std::unique_ptr<base::ListValue> request_headers_;
132 std::unique_ptr<base::ListValue> response_headers_; 135 std::unique_ptr<base::ListValue> response_headers_;
133 136
134 int extra_info_spec_; 137 int extra_info_spec_;
135 138
136 // Used to determine the frameId and parentFrameId. 139 // Used to determine the tabId, frameId and parentFrameId.
137 int render_process_id_; 140 int render_process_id_;
138 int render_frame_id_; 141 int render_frame_id_;
139 142
140 DISALLOW_COPY_AND_ASSIGN(WebRequestEventDetails); 143 DISALLOW_COPY_AND_ASSIGN(WebRequestEventDetails);
141 }; 144 };
142 145
143 } // namespace extensions 146 } // namespace extensions
144 147
145 #endif // EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_EVENT_DETAILS_H_ 148 #endif // EXTENSIONS_BROWSER_API_WEB_REQUEST_WEB_REQUEST_EVENT_DETAILS_H_
OLDNEW
« no previous file with comments | « extensions/browser/api/web_request/web_request_api.cc ('k') | extensions/browser/api/web_request/web_request_event_details.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698