Changeset 221319 in webkit
- Timestamp:
- Aug 29, 2017 3:49:50 PM (7 years ago)
- Location:
- trunk/Source/WebKit
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r221315 r221319 1 2017-08-29 Alex Christensen <achristensen@webkit.org> 2 3 Begin transition to modern IPC decoding 4 https://bugs.webkit.org/show_bug.cgi?id=176043 5 6 Reviewed by JF Bastien. 7 8 Right now, if a class is decoded from IPC we must have a default constructor. 9 This prevents us from having Ref or C++ references in such types, which is cluttering up our code. 10 This is because IPC::decode makes a default-constructed object, fills it, and returns a bool indicating success. 11 Making IPC::decode instead return a std::optional makes it so we do not need to call an empty constructor. 12 This could also enable us to add IPC::Decoder::operator>> and other fun things! 13 I also modernized two arbitrary classes, WebsitePolicies and WebPageGroupData with more to come. 14 There's no good way to update the actual generated IPC code until each class has been transitioned. 15 16 * Platform/IPC/ArgumentCoder.h: 17 (IPC::ArgumentCoder::decode): 18 * Platform/IPC/Decoder.h: 19 (IPC::Decoder::decode): 20 * Shared/WebPageCreationParameters.cpp: 21 (WebKit::WebPageCreationParameters::decode): 22 * Shared/WebPageCreationParameters.h: 23 * Shared/WebPageGroupData.cpp: 24 (WebKit::WebPageGroupData::decode): 25 * Shared/WebPageGroupData.h: 26 * Shared/WebsitePolicies.h: 27 (WebKit::WebsitePolicies::decode): 28 1 29 2017-08-29 Youenn Fablet <youenn@apple.com> 2 30 -
trunk/Source/WebKit/Platform/IPC/ArgumentCoder.h
r204668 r221319 24 24 */ 25 25 26 #ifndef ArgumentCoder_h 27 #define ArgumentCoder_h 26 #pragma once 27 28 #include <wtf/Optional.h> 28 29 29 30 namespace IPC { … … 32 33 class Encoder; 33 34 35 template <typename... T> using IsUsingModernDecoder = void; 36 template <typename T, typename = void> struct UsesModernDecoder : std::false_type { }; 37 template <typename T> struct UsesModernDecoder<T, IsUsingModernDecoder<typename T::ModernDecoder>> : std::true_type { }; 38 34 39 template<typename T> struct ArgumentCoder { 35 40 static void encode(Encoder& encoder, const T& t) … … 38 43 } 39 44 40 static bool decode(Decoder& decoder, T& t) 45 template<typename U = T, std::enable_if_t<!UsesModernDecoder<U>::value>* = nullptr> 46 static bool decode(Decoder& decoder, U& u) 41 47 { 42 return T::decode(decoder, t); 48 return U::decode(decoder, u); 49 } 50 51 template<typename U = T, std::enable_if_t<UsesModernDecoder<U>::value>* = nullptr> 52 static std::optional<U> decode(Decoder& decoder) 53 { 54 return U::decode(decoder); 43 55 } 44 56 }; 45 57 46 58 } 47 48 #endif // ArgumentCoder_h -
trunk/Source/WebKit/Platform/IPC/ArgumentCoders.h
r220917 r221319 134 134 } 135 135 136 template<typename U = typename std::remove_reference<typename std::tuple_element<sizeof...(Elements) - index, std::tuple<Elements...>>::type>::type, std::enable_if_t<!UsesModernDecoder<U>::value>* = nullptr> 136 137 static bool decode(Decoder& decoder, std::tuple<Elements...>& tuple) 137 138 { 138 139 if (!decoder.decode(std::get<sizeof...(Elements) - index>(tuple))) 139 140 return false; 141 return TupleCoder<index - 1, Elements...>::decode(decoder, tuple); 142 } 143 144 template<typename U = typename std::remove_reference<typename std::tuple_element<sizeof...(Elements) - index, std::tuple<Elements...>>::type>::type, std::enable_if_t<UsesModernDecoder<U>::value>* = nullptr> 145 static bool decode(Decoder& decoder, std::tuple<Elements...>& tuple) 146 { 147 std::optional<U> optional; 148 decoder >> optional; 149 if (!optional) 150 return false; 151 std::get<sizeof...(Elements) - index>(tuple) = WTFMove(*optional); 140 152 return TupleCoder<index - 1, Elements...>::decode(decoder, tuple); 141 153 } -
trunk/Source/WebKit/Platform/IPC/Decoder.h
r209407 r221319 124 124 } 125 125 126 template<typename T >127 auto decode(T& t) -> std::enable_if_t<!std::is_enum<T>::value, bool>126 template<typename T, std::enable_if_t<!std::is_enum<T>::value && !UsesModernDecoder<T>::value>* = nullptr> 127 bool decode(T& t) 128 128 { 129 129 return ArgumentCoder<T>::decode(*this, t); 130 } 131 132 template<typename T, std::enable_if_t<UsesModernDecoder<T>::value>* = nullptr> 133 Decoder& operator>>(std::optional<T>& t) 134 { 135 t = ArgumentCoder<T>::decode(*this); 136 return *this; 130 137 } 131 138 -
trunk/Source/WebKit/Shared/API/APIPageGroupHandle.cpp
r204668 r221319 53 53 bool PageGroupHandle::decode(IPC::Decoder& decoder, RefPtr<Object>& result) 54 54 { 55 WebKit::WebPageGroupData webPageGroupData; 56 if (!decoder.decode(webPageGroupData)) 55 std::optional<WebKit::WebPageGroupData> webPageGroupData; 56 decoder >> webPageGroupData; 57 if (!webPageGroupData) 57 58 return false; 58 59 59 result = create(WTFMove( webPageGroupData));60 result = create(WTFMove(*webPageGroupData)); 60 61 return true; 61 62 } -
trunk/Source/WebKit/Shared/WebPageCreationParameters.cpp
r218528 r221319 109 109 } 110 110 111 bool WebPageCreationParameters::decode(IPC::Decoder& decoder, WebPageCreationParameters& parameters)111 std::optional<WebPageCreationParameters> WebPageCreationParameters::decode(IPC::Decoder& decoder) 112 112 { 113 WebPageCreationParameters parameters; 113 114 if (!decoder.decode(parameters.viewSize)) 114 return false;115 return std::nullopt; 115 116 if (!decoder.decode(parameters.activityState)) 116 return false;117 return std::nullopt; 117 118 if (!decoder.decode(parameters.store)) 118 return false;119 return std::nullopt; 119 120 if (!decoder.decodeEnum(parameters.drawingAreaType)) 120 return false; 121 if (!decoder.decode(parameters.pageGroupData)) 122 return false; 121 return std::nullopt; 122 std::optional<WebPageGroupData> pageGroupData; 123 decoder >> pageGroupData; 124 if (!pageGroupData) 125 return std::nullopt; 126 parameters.pageGroupData = WTFMove(*pageGroupData); 123 127 if (!decoder.decode(parameters.drawsBackground)) 124 return false;128 return std::nullopt; 125 129 if (!decoder.decode(parameters.isEditable)) 126 return false;130 return std::nullopt; 127 131 if (!decoder.decode(parameters.underlayColor)) 128 return false;132 return std::nullopt; 129 133 if (!decoder.decode(parameters.useFixedLayout)) 130 return false;134 return std::nullopt; 131 135 if (!decoder.decode(parameters.fixedLayoutSize)) 132 return false;136 return std::nullopt; 133 137 if (!decoder.decodeEnum(parameters.paginationMode)) 134 return false;138 return std::nullopt; 135 139 if (!decoder.decode(parameters.paginationBehavesLikeColumns)) 136 return false;140 return std::nullopt; 137 141 if (!decoder.decode(parameters.pageLength)) 138 return false;142 return std::nullopt; 139 143 if (!decoder.decode(parameters.gapBetweenPages)) 140 return false;144 return std::nullopt; 141 145 if (!decoder.decode(parameters.paginationLineGridEnabled)) 142 return false;146 return std::nullopt; 143 147 if (!decoder.decode(parameters.userAgent)) 144 return false;148 return std::nullopt; 145 149 if (!decoder.decode(parameters.itemStates)) 146 return false;150 return std::nullopt; 147 151 if (!decoder.decode(parameters.sessionID)) 148 return false;152 return std::nullopt; 149 153 if (!decoder.decode(parameters.highestUsedBackForwardItemID)) 150 return false;154 return std::nullopt; 151 155 if (!decoder.decode(parameters.userContentControllerID)) 152 return false;156 return std::nullopt; 153 157 if (!decoder.decode(parameters.visitedLinkTableID)) 154 return false;158 return std::nullopt; 155 159 if (!decoder.decode(parameters.websiteDataStoreID)) 156 return false;160 return std::nullopt; 157 161 if (!decoder.decode(parameters.canRunBeforeUnloadConfirmPanel)) 158 return false;162 return std::nullopt; 159 163 if (!decoder.decode(parameters.canRunModal)) 160 return false;164 return std::nullopt; 161 165 if (!decoder.decode(parameters.deviceScaleFactor)) 162 return false;166 return std::nullopt; 163 167 if (!decoder.decode(parameters.viewScaleFactor)) 164 return false;168 return std::nullopt; 165 169 if (!decoder.decode(parameters.topContentInset)) 166 return false;170 return std::nullopt; 167 171 if (!decoder.decode(parameters.mediaVolume)) 168 return false;172 return std::nullopt; 169 173 if (!decoder.decode(parameters.muted)) 170 return false;174 return std::nullopt; 171 175 if (!decoder.decode(parameters.mayStartMediaWhenInWindow)) 172 return false;176 return std::nullopt; 173 177 if (!decoder.decode(parameters.minimumLayoutSize)) 174 return false;178 return std::nullopt; 175 179 if (!decoder.decode(parameters.autoSizingShouldExpandToViewHeight)) 176 return false;180 return std::nullopt; 177 181 if (!decoder.decode(parameters.viewportSizeForCSSViewportUnits)) 178 return false;182 return std::nullopt; 179 183 if (!decoder.decodeEnum(parameters.scrollPinningBehavior)) 180 return false;184 return std::nullopt; 181 185 if (!decoder.decode(parameters.scrollbarOverlayStyle)) 182 return false;186 return std::nullopt; 183 187 if (!decoder.decode(parameters.backgroundExtendsBeyondPage)) 184 return false;188 return std::nullopt; 185 189 if (!decoder.decodeEnum(parameters.layerHostingMode)) 186 return false;190 return std::nullopt; 187 191 if (!decoder.decode(parameters.mimeTypesWithCustomContentProviders)) 188 return false;192 return std::nullopt; 189 193 if (!decoder.decode(parameters.controlledByAutomation)) 190 return false;194 return std::nullopt; 191 195 192 196 #if ENABLE(REMOTE_INSPECTOR) 193 197 if (!decoder.decode(parameters.allowsRemoteInspection)) 194 return false;198 return std::nullopt; 195 199 if (!decoder.decode(parameters.remoteInspectionNameOverride)) 196 return false;200 return std::nullopt; 197 201 #endif 198 202 199 203 #if PLATFORM(MAC) 200 204 if (!decoder.decode(parameters.colorSpace)) 201 return false;205 return std::nullopt; 202 206 #endif 203 207 204 208 #if PLATFORM(IOS) 205 209 if (!decoder.decode(parameters.screenSize)) 206 return false;210 return std::nullopt; 207 211 if (!decoder.decode(parameters.availableScreenSize)) 208 return false;212 return std::nullopt; 209 213 if (!decoder.decode(parameters.textAutosizingWidth)) 210 return false;214 return std::nullopt; 211 215 if (!decoder.decode(parameters.ignoresViewportScaleLimits)) 212 return false;216 return std::nullopt; 213 217 if (!decoder.decode(parameters.allowsBlockSelection)) 214 return false;218 return std::nullopt; 215 219 #endif 216 220 217 221 #if PLATFORM(COCOA) 218 222 if (!decoder.decode(parameters.smartInsertDeleteEnabled)) 219 return false;223 return std::nullopt; 220 224 #endif 221 225 222 226 if (!decoder.decode(parameters.appleMailPaginationQuirkEnabled)) 223 return false;227 return std::nullopt; 224 228 225 229 if (!decoder.decode(parameters.shouldScaleViewToFitDocument)) 226 return false;230 return std::nullopt; 227 231 228 232 if (!decoder.decodeEnum(parameters.userInterfaceLayoutDirection)) 229 return false;233 return std::nullopt; 230 234 if (!decoder.decodeEnum(parameters.observedLayoutMilestones)) 231 return false;235 return std::nullopt; 232 236 233 237 if (!decoder.decode(parameters.overrideContentSecurityPolicy)) 234 return false;238 return std::nullopt; 235 239 236 240 if (!decoder.decode(parameters.cpuLimit)) 237 return false;241 return std::nullopt; 238 242 239 243 if (!decoder.decode(parameters.urlSchemeHandlers)) 240 return false;244 return std::nullopt; 241 245 242 246 if (!decoder.decode(parameters.iceCandidateFilteringEnabled)) 243 return false;247 return std::nullopt; 244 248 245 249 if (!decoder.decode(parameters.enumeratingAllNetworkInterfacesEnabled)) 246 return false;250 return std::nullopt; 247 251 248 252 if (!decoder.decode(parameters.userContentWorlds)) 249 return false;253 return std::nullopt; 250 254 if (!decoder.decode(parameters.userScripts)) 251 return false;255 return std::nullopt; 252 256 if (!decoder.decode(parameters.userStyleSheets)) 253 return false;257 return std::nullopt; 254 258 if (!decoder.decode(parameters.messageHandlers)) 255 return false;259 return std::nullopt; 256 260 #if ENABLE(CONTENT_EXTENSIONS) 257 261 if (!decoder.decode(parameters.contentRuleLists)) 258 return false;259 #endif 260 return true;262 return std::nullopt; 263 #endif 264 return WTFMove(parameters); 261 265 } 262 266 -
trunk/Source/WebKit/Shared/WebPageCreationParameters.h
r220887 r221319 60 60 struct WebPageCreationParameters { 61 61 void encode(IPC::Encoder&) const; 62 static bool decode(IPC::Decoder&, WebPageCreationParameters&); 62 static std::optional<WebPageCreationParameters> decode(IPC::Decoder&); 63 using ModernDecoder = std::true_type; 63 64 64 65 WebCore::IntSize viewSize; -
trunk/Source/WebKit/Shared/WebPageGroupData.cpp
r204668 r221319 40 40 } 41 41 42 bool WebPageGroupData::decode(IPC::Decoder& decoder, WebPageGroupData& data)42 std::optional<WebPageGroupData> WebPageGroupData::decode(IPC::Decoder& decoder) 43 43 { 44 if (!decoder.decode(data.identifier)) 45 return false; 46 if (!decoder.decode(data.pageGroupID)) 47 return false; 48 if (!decoder.decode(data.visibleToInjectedBundle)) 49 return false; 50 if (!decoder.decode(data.visibleToHistoryClient)) 51 return false; 52 if (!decoder.decode(data.userContentControllerIdentifier)) 53 return false; 54 return true; 44 String id; 45 if (!decoder.decode(id)) 46 return std::nullopt; 47 uint64_t pageGroupID; 48 if (!decoder.decode(pageGroupID)) 49 return std::nullopt; 50 bool visibleToInjectedBundle; 51 if (!decoder.decode(visibleToInjectedBundle)) 52 return std::nullopt; 53 bool visibleToHistoryClient; 54 if (!decoder.decode(visibleToHistoryClient)) 55 return std::nullopt; 56 uint64_t userContentControllerIdentifier; 57 if (!decoder.decode(userContentControllerIdentifier)) 58 return std::nullopt; 59 return { { id, pageGroupID, visibleToInjectedBundle, visibleToHistoryClient, userContentControllerIdentifier } }; 55 60 } 56 61 -
trunk/Source/WebKit/Shared/WebPageGroupData.h
r204668 r221319 24 24 */ 25 25 26 #ifndef WebPageGroupData_h 27 #define WebPageGroupData_h 26 #pragma once 28 27 29 28 #include <wtf/text/WTFString.h> … … 38 37 struct WebPageGroupData { 39 38 void encode(IPC::Encoder&) const; 40 static bool decode(IPC::Decoder&, WebPageGroupData&); 39 static std::optional<WebPageGroupData> decode(IPC::Decoder&); 40 using ModernDecoder = std::true_type; 41 41 42 42 String identifier; … … 49 49 50 50 } // namespace WebKit 51 52 53 #endif // WebPageGroupData_h -
trunk/Source/WebKit/Shared/WebsitePolicies.h
r218229 r221319 27 27 28 28 #include <wtf/OptionSet.h> 29 #include <wtf/Optional.h> 29 30 30 31 namespace WebKit { … … 49 50 50 51 template<class Encoder> void encode(Encoder&) const; 51 template<class Decoder> static bool decode(Decoder&, WebsitePolicies&); 52 template<class Decoder> static std::optional<WebsitePolicies> decode(Decoder&); 53 using ModernDecoder = std::true_type; 52 54 }; 53 55 … … 59 61 } 60 62 61 template<class Decoder> bool WebsitePolicies::decode(Decoder& decoder, WebsitePolicies& result)63 template<class Decoder> std::optional<WebsitePolicies> WebsitePolicies::decode(Decoder& decoder) 62 64 { 63 if (!decoder.decode(result.contentBlockersEnabled)) 64 return false; 65 if (!decoder.decodeEnum(result.autoplayPolicy)) 66 return false; 67 if (!decoder.decode(result.allowedAutoplayQuirks)) 68 return false; 69 return true; 65 bool contentBlockersEnabled; 66 if (!decoder.decode(contentBlockersEnabled)) 67 return std::nullopt; 68 69 WebsiteAutoplayPolicy autoplayPolicy; 70 if (!decoder.decodeEnum(autoplayPolicy)) 71 return std::nullopt; 72 73 OptionSet<WebsiteAutoplayQuirk> allowedAutoplayQuirks; 74 if (!decoder.decode(allowedAutoplayQuirks)) 75 return std::nullopt; 76 77 return { { contentBlockersEnabled, allowedAutoplayQuirks, autoplayPolicy } }; 70 78 } 71 79
Note: See TracChangeset
for help on using the changeset viewer.