Changeset 64396 in webkit
- Timestamp:
- Jul 30, 2010 6:58:28 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 24 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebKit2/ChangeLog
r64390 r64396 1 2010-07-30 Sam Weinig <sam@webkit.org> 2 3 Reviewed by Maciej Stachowiak. 4 5 Patch for https://bugs.webkit.org/show_bug.cgi?id=43290 6 Add structured message passing from the injected bundle to UIProcess 7 8 * Platform/CoreIPC/MessageID.h: 9 * Shared/CoreIPCSupport/WebContextMessageKinds.h: Added. 10 * Shared/CoreIPCSupport/WebProcessProxyMessageKinds.h: 11 (WebProcessProxyMessage::): 12 * UIProcess/API/C/WKContext.h: 13 * UIProcess/WebContext.cpp: 14 (WebKit::): 15 (WebKit::PostMessageEncoder::PostMessageDecoder::PostMessageDecoder): 16 (WebKit::PostMessageEncoder::PostMessageDecoder::decode): 17 (WebKit::WebContext::didReceiveMessageFromInjectedBundle): 18 (WebKit::WebContext::didReceiveMessage): 19 * UIProcess/WebContext.h: 20 * UIProcess/WebContextInjectedBundleClient.cpp: 21 (WebKit::WebContextInjectedBundleClient::didReceiveMessageFromInjectedBundle): 22 * UIProcess/WebContextInjectedBundleClient.h: 23 * UIProcess/WebProcessProxy.cpp: 24 (WebKit::WebProcessProxy::didReceiveMessage): 25 (WebKit::WebProcessProxy::didReceiveSyncMessage): 26 * UIProcess/WebProcessProxy.h: 27 * WebKit2.xcodeproj/project.pbxproj: 28 * WebProcess/InjectedBundle/API/c/WKBundle.cpp: 29 (WKBundlePostMessage): 30 * WebProcess/InjectedBundle/API/c/WKBundle.h: 31 * WebProcess/InjectedBundle/InjectedBundle.cpp: 32 (WebKit::): 33 (WebKit::InjectedBundle::InjectedBundle): 34 (WebKit::InjectedBundle::~InjectedBundle): 35 (WebKit::InjectedBundle::initializeClient): 36 (WebKit::InjectedBundle::postMessage): 37 (WebKit::InjectedBundle::setShouldTrackVisitedLinks): 38 (WebKit::InjectedBundle::removeAllVisitedLinks): 39 (WebKit::InjectedBundle::didCreatePage): 40 (WebKit::InjectedBundle::willDestroyPage): 41 (WebKit::InjectedBundle::didReceiveMessage): 42 * WebProcess/InjectedBundle/InjectedBundle.h: 43 1 44 2010-07-30 Andy Estes <aestes@apple.com> 2 45 -
trunk/WebKit2/Platform/CoreIPC/MessageID.h
r64380 r64396 42 42 43 43 // Messages sent by the web process to the UI process. 44 MessageClassWebContext, 44 45 MessageClassWebProcessProxy, 45 46 MessageClassWebPageProxy, -
trunk/WebKit2/Shared/CoreIPCSupport/WebProcessProxyMessageKinds.h
r64247 r64396 42 42 GetPlugins, 43 43 PopulateVisitedLinks, 44 PostMessage,45 44 }; 46 45 -
trunk/WebKit2/UIProcess/API/C/WKContext.h
r64380 r64396 34 34 35 35 // Injected Bundle Client 36 typedef void (*WKContextDidReceiveMessageFromInjectedBundleCallback)(WKContextRef page, WKStringRef message , const void *clientInfo);36 typedef void (*WKContextDidReceiveMessageFromInjectedBundleCallback)(WKContextRef page, WKStringRef messageName, WKTypeRef messageBody, const void *clientInfo); 37 37 38 38 struct WKContextInjectedBundleClient { -
trunk/WebKit2/UIProcess/WebContext.cpp
r64380 r64396 29 29 #include "InjectedBundleMessageKinds.h" 30 30 #include "RunLoop.h" 31 #include "WebContextMessageKinds.h" 31 32 #include "WebCoreArgumentCoders.h" 32 33 #include "WebPageNamespace.h" … … 35 36 #include "WebProcessMessageKinds.h" 36 37 #include "WebProcessProxy.h" 38 #include <wtf/OwnArrayPtr.h> 37 39 38 40 #include "WKContextPrivate.h" … … 46 48 namespace WebKit { 47 49 48 #ifndef NDEBUG49 static WTF::RefCountedLeakCounter webContextCounter("WebContext");50 #endif51 52 WebContext* WebContext::sharedProcessContext()53 {54 static WebContext* context = adoptRef(new WebContext(ProcessModelSharedSecondaryProcess, String())).leakRef();55 return context;56 }57 58 WebContext* WebContext::sharedThreadContext()59 {60 static WebContext* context = adoptRef(new WebContext(ProcessModelSharedSecondaryThread, String())).leakRef();61 return context;62 }63 64 WebContext::WebContext(ProcessModel processModel, const WebCore::String& injectedBundlePath)65 : m_processModel(processModel)66 , m_injectedBundlePath(injectedBundlePath)67 {68 RunLoop::initializeMainRunLoop();69 70 m_preferences = WebPreferences::shared();71 m_preferences->addContext(this);72 73 #ifndef NDEBUG74 webContextCounter.increment();75 #endif76 }77 78 WebContext::~WebContext()79 {80 ASSERT(m_pageNamespaces.isEmpty());81 m_preferences->removeContext(this);82 83 #ifndef NDEBUG84 webContextCounter.decrement();85 #endif86 }87 88 void WebContext::initializeInjectedBundleClient(const WKContextInjectedBundleClient* client)89 {90 m_injectedBundleClient.initialize(client);91 }92 93 void WebContext::initializeHistoryClient(const WKContextHistoryClient* client)94 {95 m_historyClient.initialize(client);96 97 if (!hasValidProcess())98 return;99 100 m_process->send(WebProcessMessage::SetShouldTrackVisitedLinks, 0, CoreIPC::In(m_historyClient.shouldTrackVisitedLinks()));101 }102 103 void WebContext::ensureWebProcess()104 {105 if (hasValidProcess())106 return;107 108 m_process = WebProcessManager::shared().getWebProcess(this);109 110 m_process->send(WebProcessMessage::SetShouldTrackVisitedLinks, 0, CoreIPC::In(m_historyClient.shouldTrackVisitedLinks()));111 112 for (HashSet<String>::iterator it = m_schemesToRegisterAsEmptyDocument.begin(), end = m_schemesToRegisterAsEmptyDocument.end(); it != end; ++it)113 m_process->send(WebProcessMessage::RegisterURLSchemeAsEmptyDocument, 0, CoreIPC::In(*it));114 }115 116 WebPageProxy* WebContext::createWebPage(WebPageNamespace* pageNamespace)117 {118 ensureWebProcess();119 return m_process->createWebPage(pageNamespace);120 }121 122 void WebContext::reviveIfNecessary()123 {124 ensureWebProcess();125 }126 127 WebPageNamespace* WebContext::createPageNamespace()128 {129 RefPtr<WebPageNamespace> pageNamespace = WebPageNamespace::create(this);130 m_pageNamespaces.add(pageNamespace.get());131 return pageNamespace.release().releaseRef();132 }133 134 void WebContext::pageNamespaceWasDestroyed(WebPageNamespace* pageNamespace)135 {136 ASSERT(m_pageNamespaces.contains(pageNamespace));137 m_pageNamespaces.remove(pageNamespace);138 }139 140 void WebContext::setPreferences(WebPreferences* preferences)141 {142 ASSERT(preferences);143 144 if (preferences == m_preferences)145 return;146 147 m_preferences->removeContext(this);148 m_preferences = preferences;149 m_preferences->addContext(this);150 151 // FIXME: Update all Pages/PageNamespace with the new WebPreferences.152 }153 154 WebPreferences* WebContext::preferences() const155 {156 return m_preferences.get();157 }158 159 void WebContext::preferencesDidChange()160 {161 if (!m_process)162 return;163 164 for (HashSet<WebPageNamespace*>::iterator it = m_pageNamespaces.begin(), end = m_pageNamespaces.end(); it != end; ++it) {165 WebPageNamespace* pageNamespace = *it;166 pageNamespace->preferencesDidChange();167 }168 }169 170 50 namespace { 51 52 // FIXME: We should try to abstract out the shared logic from these and 53 // and the PostMessageEncoder/PostMessageDecoders in InjectedBundle.cpp into 54 // a shared baseclass. 171 55 172 56 // Encodes postMessage messages from the UIProcess -> InjectedBundle … … 188 72 encoder.encode(static_cast<uint32_t>(type)); 189 73 switch (type) { 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 74 case APIObject::TypeArray: { 75 ImmutableArray* array = static_cast<ImmutableArray*>(m_root); 76 encoder.encode(static_cast<uint64_t>(array->size())); 77 for (size_t i = 0; i < array->size(); ++i) 78 encoder.encode(PostMessageEncoder(array->at(i))); 79 break; 80 } 81 case APIObject::TypeString: { 82 WebString* string = static_cast<WebString*>(m_root); 83 encoder.encode(string->string()); 84 break; 85 } 86 case APIObject::TypePage: { 87 WebPageProxy* page = static_cast<WebPageProxy*>(m_root); 88 encoder.encode(page->pageID()); 89 break; 90 } 91 default: 92 ASSERT_NOT_REACHED(); 93 break; 210 94 } 211 95 } … … 215 99 }; 216 100 101 // Decodes postMessage messages going from the InjectedBundle -> UIProcess 102 103 // - Array -> Array 104 // - String -> String 105 // - BundlePage -> Page 106 107 class PostMessageDecoder { 108 public: 109 PostMessageDecoder(APIObject** root, WebContext* context) 110 : m_root(root) 111 , m_context(context) 112 { 113 } 114 115 static bool decode(CoreIPC::ArgumentDecoder& decoder, PostMessageDecoder& coder) 116 { 117 uint32_t type; 118 if (!decoder.decode(type)) 119 return false; 120 121 switch (type) { 122 case APIObject::TypeArray: { 123 uint64_t size; 124 if (!decoder.decode(size)) 125 return false; 126 127 OwnArrayPtr<APIObject*> array; 128 array.set(new APIObject*[size]); 129 130 for (size_t i = 0; i < size; ++i) { 131 APIObject* element; 132 PostMessageDecoder messageCoder(&element, coder.m_context); 133 if (!decoder.decode(messageCoder)) 134 return false; 135 array[i] = element; 136 } 137 138 *(coder.m_root) = ImmutableArray::create(array.release(), size).leakRef(); 139 break; 140 } 141 case APIObject::TypeString: { 142 String string; 143 if (!decoder.decode(string)) 144 return false; 145 *(coder.m_root) = WebString::create(string).leakRef(); 146 break; 147 } 148 case APIObject::TypeBundlePage: { 149 uint64_t pageID; 150 if (!decoder.decode(pageID)) 151 return false; 152 *(coder.m_root) = coder.m_context->process()->webPage(pageID); 153 break; 154 } 155 default: 156 return false; 157 } 158 159 return true; 160 } 161 162 private: 163 APIObject** m_root; 164 WebContext* m_context; 165 }; 166 167 } 168 169 #ifndef NDEBUG 170 static WTF::RefCountedLeakCounter webContextCounter("WebContext"); 171 #endif 172 173 WebContext* WebContext::sharedProcessContext() 174 { 175 static WebContext* context = adoptRef(new WebContext(ProcessModelSharedSecondaryProcess, String())).leakRef(); 176 return context; 177 } 178 179 WebContext* WebContext::sharedThreadContext() 180 { 181 static WebContext* context = adoptRef(new WebContext(ProcessModelSharedSecondaryThread, String())).leakRef(); 182 return context; 183 } 184 185 WebContext::WebContext(ProcessModel processModel, const WebCore::String& injectedBundlePath) 186 : m_processModel(processModel) 187 , m_injectedBundlePath(injectedBundlePath) 188 { 189 RunLoop::initializeMainRunLoop(); 190 191 m_preferences = WebPreferences::shared(); 192 m_preferences->addContext(this); 193 194 #ifndef NDEBUG 195 webContextCounter.increment(); 196 #endif 197 } 198 199 WebContext::~WebContext() 200 { 201 ASSERT(m_pageNamespaces.isEmpty()); 202 m_preferences->removeContext(this); 203 204 #ifndef NDEBUG 205 webContextCounter.decrement(); 206 #endif 207 } 208 209 void WebContext::initializeInjectedBundleClient(const WKContextInjectedBundleClient* client) 210 { 211 m_injectedBundleClient.initialize(client); 212 } 213 214 void WebContext::initializeHistoryClient(const WKContextHistoryClient* client) 215 { 216 m_historyClient.initialize(client); 217 218 if (!hasValidProcess()) 219 return; 220 221 m_process->send(WebProcessMessage::SetShouldTrackVisitedLinks, 0, CoreIPC::In(m_historyClient.shouldTrackVisitedLinks())); 222 } 223 224 void WebContext::ensureWebProcess() 225 { 226 if (hasValidProcess()) 227 return; 228 229 m_process = WebProcessManager::shared().getWebProcess(this); 230 231 m_process->send(WebProcessMessage::SetShouldTrackVisitedLinks, 0, CoreIPC::In(m_historyClient.shouldTrackVisitedLinks())); 232 233 for (HashSet<String>::iterator it = m_schemesToRegisterAsEmptyDocument.begin(), end = m_schemesToRegisterAsEmptyDocument.end(); it != end; ++it) 234 m_process->send(WebProcessMessage::RegisterURLSchemeAsEmptyDocument, 0, CoreIPC::In(*it)); 235 } 236 237 WebPageProxy* WebContext::createWebPage(WebPageNamespace* pageNamespace) 238 { 239 ensureWebProcess(); 240 return m_process->createWebPage(pageNamespace); 241 } 242 243 void WebContext::reviveIfNecessary() 244 { 245 ensureWebProcess(); 246 } 247 248 WebPageNamespace* WebContext::createPageNamespace() 249 { 250 RefPtr<WebPageNamespace> pageNamespace = WebPageNamespace::create(this); 251 m_pageNamespaces.add(pageNamespace.get()); 252 return pageNamespace.release().releaseRef(); 253 } 254 255 void WebContext::pageNamespaceWasDestroyed(WebPageNamespace* pageNamespace) 256 { 257 ASSERT(m_pageNamespaces.contains(pageNamespace)); 258 m_pageNamespaces.remove(pageNamespace); 259 } 260 261 void WebContext::setPreferences(WebPreferences* preferences) 262 { 263 ASSERT(preferences); 264 265 if (preferences == m_preferences) 266 return; 267 268 m_preferences->removeContext(this); 269 m_preferences = preferences; 270 m_preferences->addContext(this); 271 272 // FIXME: Update all Pages/PageNamespace with the new WebPreferences. 273 } 274 275 WebPreferences* WebContext::preferences() const 276 { 277 return m_preferences.get(); 278 } 279 280 void WebContext::preferencesDidChange() 281 { 282 if (!m_process) 283 return; 284 285 for (HashSet<WebPageNamespace*>::iterator it = m_pageNamespaces.begin(), end = m_pageNamespaces.end(); it != end; ++it) { 286 WebPageNamespace* pageNamespace = *it; 287 pageNamespace->preferencesDidChange(); 288 } 217 289 } 218 290 … … 229 301 // InjectedBundle client 230 302 231 void WebContext::didReceiveMessageFromInjectedBundle(const String& message )232 { 233 m_injectedBundleClient.didReceiveMessageFromInjectedBundle(this, message );303 void WebContext::didReceiveMessageFromInjectedBundle(const String& messageName, APIObject* messageBody) 304 { 305 m_injectedBundleClient.didReceiveMessageFromInjectedBundle(this, messageName, messageBody); 234 306 } 235 307 … … 293 365 } 294 366 367 void WebContext::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder& arguments) 368 { 369 switch (messageID.get<WebContextMessage::Kind>()) { 370 case WebContextMessage::PostMessage: { 371 String messageName; 372 // FIXME: This should be a RefPtr<APIObject> 373 APIObject* messageBody = 0; 374 PostMessageDecoder messageCoder(&messageBody, this); 375 if (!arguments.decode(CoreIPC::Out(messageName, messageCoder))) 376 return; 377 378 didReceiveMessageFromInjectedBundle(messageName, messageBody); 379 380 messageBody->deref(); 381 382 return; 383 } 384 } 385 386 ASSERT_NOT_REACHED(); 387 } 388 295 389 } // namespace WebKit -
trunk/WebKit2/UIProcess/WebContext.h
r64386 r64396 84 84 85 85 // InjectedBundle client 86 void didReceiveMessageFromInjectedBundle(const WebCore::String& );86 void didReceiveMessageFromInjectedBundle(const WebCore::String&, APIObject*); 87 87 88 88 // History client … … 100 100 101 101 void registerURLSchemeAsEmptyDocument(const WebCore::String&); 102 103 void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder&); 102 104 103 105 private: -
trunk/WebKit2/UIProcess/WebContextInjectedBundleClient.cpp
r64317 r64396 46 46 } 47 47 48 void WebContextInjectedBundleClient::didReceiveMessageFromInjectedBundle(WebContext* context, const String& message )48 void WebContextInjectedBundleClient::didReceiveMessageFromInjectedBundle(WebContext* context, const String& messageName, APIObject* messageBody) 49 49 { 50 50 if (!m_client.didReceiveMessageFromInjectedBundle) 51 51 return; 52 52 53 m_client.didReceiveMessageFromInjectedBundle(toRef(context), toRef(message .impl()), m_client.clientInfo);53 m_client.didReceiveMessageFromInjectedBundle(toRef(context), toRef(messageName.impl()), toRef(messageBody), m_client.clientInfo); 54 54 } 55 55 -
trunk/WebKit2/UIProcess/WebContextInjectedBundleClient.h
r64317 r64396 35 35 namespace WebKit { 36 36 37 class APIObject; 37 38 class WebContext; 38 39 … … 42 43 void initialize(const WKContextInjectedBundleClient*); 43 44 44 void didReceiveMessageFromInjectedBundle(WebContext*, const WebCore::String& );45 void didReceiveMessageFromInjectedBundle(WebContext*, const WebCore::String&, APIObject*); 45 46 46 47 private: -
trunk/WebKit2/UIProcess/WebProcessProxy.cpp
r64247 r64396 184 184 } 185 185 186 void WebProcessProxy::forwardMessageToWebContext(const String& message)187 {188 m_context->didReceiveMessageFromInjectedBundle(message);189 }190 191 186 void WebProcessProxy::getPlugins(bool refresh, Vector<PluginInfo>& plugins) 192 187 { … … 226 221 if (messageID.is<CoreIPC::MessageClassWebProcessProxy>()) { 227 222 switch (messageID.get<WebProcessProxyMessage::Kind>()) { 228 case WebProcessProxyMessage::PostMessage: {229 String message;230 if (!arguments->decode(CoreIPC::Out(message)))231 return;232 233 forwardMessageToWebContext(message);234 return;235 }236 223 case WebProcessProxyMessage::AddBackForwardItem: { 237 224 uint64_t itemID; … … 317 304 } 318 305 306 if (messageID.is<CoreIPC::MessageClassWebContext>()) { 307 m_context->didReceiveMessage(connection, messageID, *arguments); 308 return; 309 } 310 319 311 uint64_t pageID = arguments->destinationID(); 320 312 if (!pageID) … … 366 358 case WebProcessProxyMessage::DidUpdateHistoryTitle: 367 359 case WebProcessProxyMessage::PopulateVisitedLinks: 368 case WebProcessProxyMessage::PostMessage:369 360 case WebProcessProxyMessage::AddBackForwardItem: 370 361 ASSERT_NOT_REACHED(); … … 372 363 } 373 364 } 374 365 375 366 uint64_t pageID = arguments->destinationID(); 376 367 if (!pageID) -
trunk/WebKit2/UIProcess/WebProcessProxy.h
r63621 r64396 97 97 bool sendMessage(CoreIPC::MessageID, PassOwnPtr<CoreIPC::ArgumentEncoder>); 98 98 99 void forwardMessageToWebContext(const WebCore::String&);100 99 void getPlugins(bool refresh, Vector<WebCore::PluginInfo>&); 101 100 void getPluginHostConnection(const WebCore::String& mimeType, const WebCore::KURL& url, WebCore::String& pluginPath); -
trunk/WebKit2/WebKit2.xcodeproj/project.pbxproj
r64380 r64396 233 233 BCC57162115ADB42001CCAF9 /* NotImplemented.h in Headers */ = {isa = PBXBuildFile; fileRef = BCC57161115ADB42001CCAF9 /* NotImplemented.h */; }; 234 234 BCC938E11180DE440085E5FE /* WKContextPrivate.h in Headers */ = {isa = PBXBuildFile; fileRef = BCC938E01180DE440085E5FE /* WKContextPrivate.h */; settings = {ATTRIBUTES = (Private, ); }; }; 235 BCCB75C61203A1CE00222D1B /* WebContextMessageKinds.h in Headers */ = {isa = PBXBuildFile; fileRef = BCCB75C51203A1CE00222D1B /* WebContextMessageKinds.h */; }; 235 236 BCD0042D110C1E27003B8A67 /* CoreServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BCD0042C110C1E27003B8A67 /* CoreServices.framework */; }; 236 237 BCD0139B110FA420003B8A67 /* WKFrame.h in Headers */ = {isa = PBXBuildFile; fileRef = BCD01397110FA420003B8A67 /* WKFrame.h */; settings = {ATTRIBUTES = (Public, ); }; }; … … 530 531 BCC57161115ADB42001CCAF9 /* NotImplemented.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NotImplemented.h; sourceTree = "<group>"; }; 531 532 BCC938E01180DE440085E5FE /* WKContextPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKContextPrivate.h; sourceTree = "<group>"; }; 533 BCCB75C51203A1CE00222D1B /* WebContextMessageKinds.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebContextMessageKinds.h; sourceTree = "<group>"; }; 532 534 BCD0042C110C1E27003B8A67 /* CoreServices.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreServices.framework; path = /System/Library/Frameworks/CoreServices.framework; sourceTree = "<absolute>"; }; 533 535 BCD01397110FA420003B8A67 /* WKFrame.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKFrame.h; sourceTree = "<group>"; }; … … 1044 1046 BC9E969911457EDE00870E71 /* DrawingAreaProxyMessageKinds.h */, 1045 1047 BCB28CBF120233D9007D99BC /* InjectedBundleMessageKinds.h */, 1048 BCCB75C51203A1CE00222D1B /* WebContextMessageKinds.h */, 1046 1049 BC111B60112F638300337BAB /* WebPageMessageKinds.h */, 1047 1050 BC111B61112F638300337BAB /* WebPageProxyMessageKinds.h */, … … 1322 1325 BCDB86C11200FB97007254BE /* WebURL.h in Headers */, 1323 1326 BCB28CC0120233D9007D99BC /* InjectedBundleMessageKinds.h in Headers */, 1327 BCCB75C61203A1CE00222D1B /* WebContextMessageKinds.h in Headers */, 1324 1328 ); 1325 1329 runOnlyForDeploymentPostprocessing = 0; -
trunk/WebKit2/WebProcess/InjectedBundle/API/c/WKBundle.cpp
r64386 r64396 44 44 } 45 45 46 void WKBundlePostMessage(WKBundleRef bundleRef, WKStringRef message Ref)46 void WKBundlePostMessage(WKBundleRef bundleRef, WKStringRef messageNameRef, WKTypeRef messageBodyRef) 47 47 { 48 toWK(bundleRef)->postMessage(toWK(message Ref)->string());48 toWK(bundleRef)->postMessage(toWK(messageNameRef)->string(), toWK(messageBodyRef)); 49 49 } 50 50 -
trunk/WebKit2/WebProcess/InjectedBundle/API/c/WKBundle.h
r64380 r64396 52 52 WK_EXPORT void WKBundleSetClient(WKBundleRef bundle, WKBundleClient * client); 53 53 54 WK_EXPORT void WKBundlePostMessage(WKBundleRef bundle, WKStringRef message );54 WK_EXPORT void WKBundlePostMessage(WKBundleRef bundle, WKStringRef messageName, WKTypeRef messageBody); 55 55 56 56 #ifdef __cplusplus -
trunk/WebKit2/WebProcess/InjectedBundle/InjectedBundle.cpp
r64380 r64396 28 28 #include "Arguments.h" 29 29 #include "ImmutableArray.h" 30 #include "WebContextMessageKinds.h" 30 31 #include "InjectedBundleMessageKinds.h" 31 32 #include "WKAPICast.h" … … 34 35 #include "WebPage.h" 35 36 #include "WebProcess.h" 36 #include "WebProcessProxyMessageKinds.h"37 37 #include <WebCore/PageGroup.h> 38 38 #include <wtf/OwnArrayPtr.h> … … 42 42 namespace WebKit { 43 43 44 InjectedBundle::InjectedBundle(const WebCore::String& path) 44 namespace { 45 46 // FIXME: We should try to abstract out the shared logic from these and 47 // and the PostMessageEncoder/PostMessageDecoders in WebContext.cpp into 48 // a shared baseclass. 49 50 // Encodes postMessage messages from the InjectedBundle -> UIProcess 51 52 // - Array -> Array 53 // - String -> String 54 // - BundlePage -> Page 55 56 class PostMessageEncoder { 57 public: 58 PostMessageEncoder(APIObject* root) 59 : m_root(root) 60 { 61 } 62 63 void encode(CoreIPC::ArgumentEncoder& encoder) const 64 { 65 APIObject::Type type = m_root->type(); 66 encoder.encode(static_cast<uint32_t>(type)); 67 switch (type) { 68 case APIObject::TypeArray: { 69 ImmutableArray* array = static_cast<ImmutableArray*>(m_root); 70 encoder.encode(static_cast<uint64_t>(array->size())); 71 for (size_t i = 0; i < array->size(); ++i) 72 encoder.encode(PostMessageEncoder(array->at(i))); 73 break; 74 } 75 case APIObject::TypeString: { 76 WebString* string = static_cast<WebString*>(m_root); 77 encoder.encode(string->string()); 78 break; 79 } 80 case APIObject::TypeBundlePage: { 81 WebPage* page = static_cast<WebPage*>(m_root); 82 encoder.encode(page->pageID()); 83 break; 84 } 85 default: 86 ASSERT_NOT_REACHED(); 87 break; 88 } 89 } 90 91 private: 92 APIObject* m_root; 93 }; 94 95 96 // Decodes postMessage messages going from the UIProcess -> InjectedBundle 97 98 // - Array -> Array 99 // - String -> String 100 // - Page -> BundlePage 101 102 class PostMessageDecoder { 103 public: 104 PostMessageDecoder(APIObject** root) 105 : m_root(root) 106 { 107 } 108 109 static bool decode(CoreIPC::ArgumentDecoder& decoder, PostMessageDecoder& coder) 110 { 111 uint32_t type; 112 if (!decoder.decode(type)) 113 return false; 114 115 switch (type) { 116 case APIObject::TypeArray: { 117 uint64_t size; 118 if (!decoder.decode(size)) 119 return false; 120 121 OwnArrayPtr<APIObject*> array; 122 array.set(new APIObject*[size]); 123 124 for (size_t i = 0; i < size; ++i) { 125 APIObject* element; 126 PostMessageDecoder messageCoder(&element); 127 if (!decoder.decode(messageCoder)) 128 return false; 129 array[i] = element; 130 } 131 132 *(coder.m_root) = ImmutableArray::create(array.release(), size).leakRef(); 133 break; 134 } 135 case APIObject::TypeString: { 136 String string; 137 if (!decoder.decode(string)) 138 return false; 139 *(coder.m_root) = WebString::create(string).leakRef(); 140 break; 141 } 142 case APIObject::TypePage: { 143 uint64_t pageID; 144 if (!decoder.decode(pageID)) 145 return false; 146 *(coder.m_root) = WebProcess::shared().webPage(pageID); 147 break; 148 } 149 default: 150 return false; 151 } 152 153 return true; 154 } 155 156 private: 157 APIObject** m_root; 158 }; 159 160 } 161 162 InjectedBundle::InjectedBundle(const String& path) 45 163 : m_path(path) 46 164 , m_platformBundle(0) … … 61 179 } 62 180 63 void InjectedBundle::postMessage(const String& message )64 { 65 WebProcess::shared().connection()->send(Web ProcessProxyMessage::PostMessage, 0, CoreIPC::In(message));181 void InjectedBundle::postMessage(const String& messageName, APIObject* messageBody) 182 { 183 WebProcess::shared().connection()->send(WebContextMessage::PostMessage, 0, CoreIPC::In(messageName, PostMessageEncoder(messageBody))); 66 184 } 67 185 … … 88 206 } 89 207 90 void InjectedBundle::didReceiveMessage(const WebCore::String& messageName, APIObject* messageBody)208 void InjectedBundle::didReceiveMessage(const String& messageName, APIObject* messageBody) 91 209 { 92 210 if (m_client.didReceiveMessage) 93 211 m_client.didReceiveMessage(toRef(this), toRef(messageName.impl()), toRef(messageBody), m_client.clientInfo); 94 }95 96 namespace {97 98 // Decodes postMessage messages going from the UIProcess -> InjectedBundle99 100 // - Array -> Array101 // - String -> String102 // - Page -> BundlePage103 104 class PostMessageDecoder {105 public:106 PostMessageDecoder(APIObject** root)107 : m_root(root)108 {109 }110 111 static bool decode(CoreIPC::ArgumentDecoder& decoder, PostMessageDecoder& coder)112 {113 uint32_t type;114 if (!decoder.decode(type))115 return false;116 117 switch (type) {118 case APIObject::TypeArray: {119 uint64_t size;120 if (!decoder.decode(size))121 return false;122 123 OwnArrayPtr<APIObject*> array;124 array.set(new APIObject*[size]);125 126 for (size_t i = 0; i < size; ++i) {127 APIObject* element;128 PostMessageDecoder messageCoder(&element);129 if (!decoder.decode(messageCoder))130 return false;131 array[i] = element;132 }133 134 *(coder.m_root) = ImmutableArray::create(array.release(), size).leakRef();135 break;136 }137 case APIObject::TypeString: {138 String string;139 if (!decoder.decode(string))140 return false;141 *(coder.m_root) = WebString::create(string).leakRef();142 break;143 }144 case APIObject::TypePage: {145 uint64_t pageID;146 if (!decoder.decode(pageID))147 return false;148 *(coder.m_root) = WebProcess::shared().webPage(pageID);149 break;150 }151 default:152 return false;153 }154 155 return true;156 }157 158 private:159 APIObject** m_root;160 };161 162 212 } 163 213 -
trunk/WebKit2/WebProcess/InjectedBundle/InjectedBundle.h
r64386 r64396 68 68 // API 69 69 void initializeClient(WKBundleClient*); 70 void postMessage(const WebCore::String& );70 void postMessage(const WebCore::String&, APIObject*); 71 71 void setShouldTrackVisitedLinks(bool); 72 72 void removeAllVisitedLinks(); -
trunk/WebKitTools/ChangeLog
r64382 r64396 1 2010-07-30 Sam Weinig <sam@webkit.org> 2 3 Reviewed by Maciej Stachowiak. 4 5 Patch for https://bugs.webkit.org/show_bug.cgi?id=43290 6 Add structured message passing from the injected bundle to UIProcess 7 8 * MiniBrowser/mac/AppDelegate.m: 9 (didRecieveMessageFromInjectedBundle): 10 * MiniBrowser/mac/WebBundle/WebBundleMain.m: 11 (didClearWindowForFrame): 12 (didRecieveMessage): 13 * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp: 14 (WTR::InjectedBundle::done): 15 (WTR::InjectedBundle::didReceiveMessage): 16 * WebKitTestRunner/TestController.cpp: 17 (WTR::TestController::initialize): 18 (WTR::TestController::didReceiveMessageFromInjectedBundle): 19 * WebKitTestRunner/TestController.h: 20 * WebKitTestRunner/TestInvocation.cpp: 21 (WTR::TestInvocation::didReceiveMessageFromInjectedBundle): 22 * WebKitTestRunner/TestInvocation.h: 23 * WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj: 24 1 25 2010-07-30 Sam Weinig <sam@webkit.org> 2 26 -
trunk/WebKitTools/MiniBrowser/mac/AppDelegate.m
r64380 r64396 37 37 @implementation BrowserAppDelegate 38 38 39 void didRecieveMessageFromInjectedBundle(WKContextRef context, WKStringRef message, const void *clientInfo) 40 { 41 CFStringRef cfMessage = WKStringCopyCFString(0, message); 42 LOG(@"ContextInjectedBundleClient - didRecieveMessage - message: %@", cfMessage); 43 CFRelease(cfMessage); 39 void didRecieveMessageFromInjectedBundle(WKContextRef context, WKStringRef messageName, WKTypeRef messageBody, const void *clientInfo) 40 { 41 CFStringRef cfMessageName = WKStringCopyCFString(0, messageName); 42 43 WKTypeID typeID = WKGetTypeID(messageBody); 44 if (typeID == WKStringGetTypeID()) { 45 CFStringRef cfMessageBody = WKStringCopyCFString(0, (WKStringRef)messageBody); 46 LOG(@"ContextInjectedBundleClient - didRecieveMessage - MessageName: %@ MessageBody %@", cfMessageName, cfMessageBody); 47 CFRelease(cfMessageBody); 48 } else { 49 LOG(@"ContextInjectedBundleClient - didRecieveMessage - MessageName: %@ (MessageBody Unhandeled)\n", cfMessageName); 50 } 51 52 CFRelease(cfMessageName); 44 53 45 54 WKStringRef newMessageName = WKStringCreateWithCFString(CFSTR("Response")); 46 55 WKStringRef newMessageBody = WKStringCreateWithCFString(CFSTR("Roger that!")); 47 56 48 LOG(@"my info: %d", (int)WKGetTypeID(newMessageBody));49 50 57 WKContextPostMessageToInjectedBundle(context, newMessageName, newMessageBody); 51 58 52 59 WKStringRelease(newMessageName); 60 WKStringRelease(newMessageBody); 53 61 } 54 62 -
trunk/WebKitTools/MiniBrowser/mac/WebBundle/WebBundleMain.m
r64380 r64396 75 75 CFRelease(cfURL); 76 76 77 WKStringRef message = WKStringCreateWithCFString(CFSTR("Window was cleared")); 78 WKBundlePostMessage(globalBundle, message); 79 WKStringRelease(message); 77 WKStringRef messageName = WKStringCreateWithCFString(CFSTR("Callback")); 78 WKStringRef messageBody = WKStringCreateWithCFString(CFSTR("Window was cleared")); 79 WKBundlePostMessage(globalBundle, messageName, messageBody); 80 WKStringRelease(messageName); 81 WKStringRelease(messageBody); 80 82 } 81 83 … … 114 116 if (typeID == WKStringGetTypeID()) { 115 117 CFStringRef cfMessageBody = WKStringCopyCFString(0, (WKStringRef)messageBody); 116 LOG(@"WKBundleClient - didRecieveMessage %@ (Type=String) %@\n", cfMessageName, cfMessageBody);118 LOG(@"WKBundleClient - didRecieveMessage - MessageName: %@ MessageBody %@", cfMessageName, cfMessageBody); 117 119 CFRelease(cfMessageBody); 118 120 } else { 119 LOG(@"WKBundleClient - didRecieveMessage %@ (Type=Unhandeled)\n", cfMessageName);121 LOG(@"WKBundleClient - didRecieveMessage - MessageName: %@ (MessageBody Unhandeled)\n", cfMessageName); 120 122 } 121 123 122 124 CFRelease(cfMessageName); 123 125 } -
trunk/WebKitTools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp
r64380 r64396 82 82 void InjectedBundle::done() 83 83 { 84 WKRetainPtr<WKStringRef> doneMessageName(AdoptWK, WKStringCreateWithCFString(CFSTR("Done"))); 85 84 86 std::string output = m_outputStream.str(); 85 87 RetainPtr<CFStringRef> outputCFString(AdoptCF, CFStringCreateWithCString(0, output.c_str(), kCFStringEncodingUTF8)); 86 WKRetainPtr<WKStringRef> doneMessage(AdoptWK, WKStringCreateWithCFString(outputCFString.get())); 87 WKBundlePostMessage(m_bundle, doneMessage.get()); 88 WKRetainPtr<WKStringRef> doneMessageBody(AdoptWK, WKStringCreateWithCFString(outputCFString.get())); 89 90 WKBundlePostMessage(m_bundle, doneMessageName.get(), doneMessageBody.get()); 88 91 } 89 92 … … 104 107 CFStringRef cfMessage = WKStringCopyCFString(0, messageName); 105 108 if (CFEqual(cfMessage, CFSTR("BeginTest"))) { 106 WKRetainPtr<WKStringRef> ackMessage(AdoptWK, WKStringCreateWithCFString(CFSTR("BeginTestAck"))); 107 WKBundlePostMessage(m_bundle, ackMessage.get()); 109 WKRetainPtr<WKStringRef> ackMessageName(AdoptWK, WKStringCreateWithCFString(CFSTR("Ack"))); 110 WKRetainPtr<WKStringRef> ackMessageBody(AdoptWK, WKStringCreateWithCFString(CFSTR("BeginTest"))); 111 WKBundlePostMessage(m_bundle, ackMessageName.get(), ackMessageBody.get()); 108 112 109 113 reset(); … … 111 115 } 112 116 113 WKRetainPtr<WKStringRef> errorMessage(AdoptWK, WKStringCreateWithCFString(CFSTR("Error: Unknown."))); 114 WKBundlePostMessage(m_bundle, errorMessage.get()); 117 WKRetainPtr<WKStringRef> errorMessageName(AdoptWK, WKStringCreateWithCFString(CFSTR("Error"))); 118 WKRetainPtr<WKStringRef> errorMessageBody(AdoptWK, WKStringCreateWithCFString(CFSTR("Unknown"))); 119 WKBundlePostMessage(m_bundle, errorMessageName.get(), errorMessageBody.get()); 115 120 } 116 121 -
trunk/WebKitTools/WebKitTestRunner/TestController.cpp
r64287 r64396 83 83 0, 84 84 this, 85 _didReceiveMessageFromInjectedBundle85 didReceiveMessageFromInjectedBundle 86 86 }; 87 87 WKContextSetInjectedBundleClient(m_context.get(), &injectedBundlePathClient); … … 127 127 } 128 128 129 void TestController:: _didReceiveMessageFromInjectedBundle(WKContextRef context, WKStringRef message, const void *clientInfo)129 void TestController::didReceiveMessageFromInjectedBundle(WKContextRef context, WKStringRef messageName, WKTypeRef messageBody, const void *clientInfo) 130 130 { 131 static_cast<TestController*>(const_cast<void*>(clientInfo))->didReceiveMessageFromInjectedBundle(message );131 static_cast<TestController*>(const_cast<void*>(clientInfo))->didReceiveMessageFromInjectedBundle(messageName, messageBody); 132 132 } 133 133 134 void TestController::didReceiveMessageFromInjectedBundle(WKStringRef message )134 void TestController::didReceiveMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody) 135 135 { 136 m_currentInvocation->didReceiveMessageFromInjectedBundle(message );136 m_currentInvocation->didReceiveMessageFromInjectedBundle(messageName, messageBody); 137 137 } 138 138 -
trunk/WebKitTools/WebKitTestRunner/TestController.h
r64286 r64396 68 68 69 69 // WKContextInjectedBundleClient 70 static void _didReceiveMessageFromInjectedBundle(WKContextRef context, WKStringRef message, const void*);71 void didReceiveMessageFromInjectedBundle(WKStringRef message );70 static void didReceiveMessageFromInjectedBundle(WKContextRef context, WKStringRef messageName, WKTypeRef messageBody, const void*); 71 void didReceiveMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody); 72 72 73 73 OwnPtr<TestInvocation> m_currentInvocation; -
trunk/WebKitTools/WebKitTestRunner/TestInvocation.cpp
r64380 r64396 141 141 } 142 142 143 void TestInvocation::didReceiveMessageFromInjectedBundle(WKStringRef message )143 void TestInvocation::didReceiveMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody) 144 144 { 145 RetainPtr<CFStringRef> cfMessage(AdoptCF, WKStringCopyCFString(0, message)); 146 147 if (CFEqual(cfMessage.get(), CFSTR("Error"))) { 145 RetainPtr<CFStringRef> cfMessageName(AdoptCF, WKStringCopyCFString(0, messageName)); 146 if (CFEqual(cfMessageName.get(), CFSTR("Error"))) { 148 147 // Set all states to true to stop spinning the runloop. 149 148 m_gotInitialResponse = true; … … 153 152 } 154 153 155 if (CFEqual(cfMessage.get(), CFSTR("BeginTestAck"))) { 156 m_gotInitialResponse = true; 154 if (CFEqual(cfMessageName.get(), CFSTR("Ack"))) { 155 ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID()); 156 RetainPtr<CFStringRef> cfMessageBody(AdoptCF, WKStringCopyCFString(0, static_cast<WKStringRef>(messageBody))); 157 158 if (CFEqual(cfMessageBody.get(), CFSTR("BeginTest"))) { 159 m_gotInitialResponse = true; 160 return; 161 } 162 163 ASSERT_NOT_REACHED(); 164 } 165 166 if (CFEqual(cfMessageName.get(), CFSTR("Done"))) { 167 ASSERT(WKGetTypeID(messageBody) == WKStringGetTypeID()); 168 OwnPtr<Vector<char> > utf8Message = WKStringToUTF8(static_cast<WKStringRef>(messageBody)); 169 dump(utf8Message->data()); 170 m_gotFinalMessage = true; 157 171 return; 158 172 } 159 173 160 OwnPtr<Vector<char> > utf8Message = WKStringToUTF8(message); 161 162 dump(utf8Message->data()); 163 m_gotFinalMessage = true; 174 ASSERT_NOT_REACHED(); 164 175 } 165 176 -
trunk/WebKitTools/WebKitTestRunner/TestInvocation.h
r64029 r64396 38 38 39 39 void invoke(); 40 void didReceiveMessageFromInjectedBundle(WKStringRef message );40 void didReceiveMessageFromInjectedBundle(WKStringRef messageName, WKTypeRef messageBody); 41 41 42 42 private: -
trunk/WebKitTools/WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj
r64380 r64396 109 109 BC952ED311F3C318003398B4 /* CodeGeneratorTestRunner.pm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.perl; path = CodeGeneratorTestRunner.pm; sourceTree = "<group>"; }; 110 110 BC952F1D11F3C652003398B4 /* JSLayoutTestController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = JSLayoutTestController.cpp; path = DerivedSources/WebKitTestRunner/JSLayoutTestController.cpp; sourceTree = BUILT_PRODUCTS_DIR; }; 111 BC952F1E11F3C652003398B4 /* JSLayoutTestController.h */ = {isa = PBXFileReference; fileEncoding = 4; name = JSLayoutTestController.h; path = DerivedSources/WebKitTestRunner/JSLayoutTestController.h; sourceTree = BUILT_PRODUCTS_DIR; };111 BC952F1E11F3C652003398B4 /* JSLayoutTestController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JSLayoutTestController.h; path = DerivedSources/WebKitTestRunner/JSLayoutTestController.h; sourceTree = BUILT_PRODUCTS_DIR; }; 112 112 BCC997A011D3C8F60017BCA2 /* InjectedBundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InjectedBundle.cpp; sourceTree = "<group>"; }; 113 113 BCC997A111D3C8F60017BCA2 /* InjectedBundle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InjectedBundle.h; sourceTree = "<group>"; };
Note: See TracChangeset
for help on using the changeset viewer.