Changeset 49263 in webkit
- Timestamp:
- Oct 7, 2009, 2:55:58 PM (16 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r49262 r49263 1 2009-10-07 Brian Weinstein <bweinstein@apple.com> 2 3 Reviewed by Timothy Hatcher. 4 5 Fixes <http://webkit.org/b/30104>. 6 Inspector should show cookies of sub-resources on the page. 7 8 This function implements showing cookies for all sub-resources of a page. 9 When the page is loaded, it populates the Storage Panel with a list of all 10 domains that were loaded as part of the full page load (iframes, ads, etc). 11 When the user selects one of the domains, the inspector calls back into the 12 controller, and the controller combines all of the cookies from that domain 13 into a list, and sends that list is sent back to the controller to render. 14 15 A domain now needs to be passed into CookieItemsView, and CookieSidebarTreeElement. 16 17 As a result of a previous patch, we now have detailed cookie information for 18 both Windows on CFNetwork and Mac. Additionally, this patch provides deleteCookie 19 support on Windows. 20 21 * bindings/js/ScriptObject.cpp: 22 (WebCore::ScriptObject::set): 23 * bindings/js/ScriptObject.h: 24 * inspector/InspectorBackend.cpp: 25 (WebCore::InspectorBackend::getCookies): 26 (WebCore::InspectorBackend::deleteCookie): 27 * inspector/InspectorBackend.h: 28 * inspector/InspectorBackend.idl: 29 * inspector/InspectorController.cpp: 30 (WebCore::InspectorController::populateScriptObjects): 31 (WebCore::InspectorController::didFinishLoading): 32 (WebCore::InspectorController::getCookies): 33 (WebCore::InspectorController::buildArrayForCookies): 34 (WebCore::InspectorController::buildObjectForCookie): 35 (WebCore::InspectorController::deleteCookie): 36 * inspector/InspectorController.h: 37 * inspector/InspectorDOMAgent.cpp: 38 * inspector/InspectorDOMAgent.h: 39 * inspector/InspectorFrontend.cpp: 40 (WebCore::InspectorFrontend::addCookieDomainForDocument): 41 * inspector/InspectorFrontend.h: 42 * inspector/front-end/CookieItemsView.js: 43 (WebInspector.CookieItemsView): 44 (WebInspector.CookieItemsView.prototype.update): 45 (WebInspector.CookieItemsView.prototype._deleteButtonClicked): 46 * inspector/front-end/DOMAgent.js: 47 (WebInspector.Cookies.getCookiesAsync): 48 * inspector/front-end/StoragePanel.js: 49 (WebInspector.StoragePanel): 50 (WebInspector.StoragePanel.prototype.reset): 51 (WebInspector.StoragePanel.prototype.addCookieDomain): 52 (WebInspector.StoragePanel.prototype.showCookies): 53 (WebInspector.CookieSidebarTreeElement): 54 (WebInspector.CookieSidebarTreeElement.prototype.onselect): 55 * inspector/front-end/inspector.js: 56 (WebInspector.addCookieDomain): 57 * platform/Cookie.h: 58 (WebCore::CookieHash::hash): 59 (WebCore::CookieHash::equal): 60 (WTF::): 61 * platform/network/win/CookieJarCFNetWin.cpp: 62 (WebCore::deleteCookie): 63 1 64 2009-10-07 Pavel Feldman <pfeldman@chromium.org> 2 65 -
trunk/WebCore/bindings/js/ScriptObject.cpp
r48430 r49263 104 104 } 105 105 106 bool ScriptObject::set(const char* name, unsigned value) 107 { 108 JSLock lock(SilenceAssertionsOnly); 109 PutPropertySlot slot; 110 jsObject()->put(m_scriptState, Identifier(m_scriptState, name), jsNumber(m_scriptState, value), slot); 111 return handleException(m_scriptState); 112 } 113 106 114 bool ScriptObject::set(const char* name, bool value) 107 115 { -
trunk/WebCore/bindings/js/ScriptObject.h
r48430 r49263 53 53 bool set(const char* name, long long); 54 54 bool set(const char* name, int); 55 bool set(const char* name, unsigned); 55 56 bool set(const char* name, bool); 56 57 -
trunk/WebCore/inspector/InspectorBackend.cpp
r49234 r49263 457 457 } 458 458 459 void InspectorBackend::getCookies(long callId) 460 { 461 if (InspectorDOMAgent* domAgent = inspectorDOMAgent()) 462 domAgent->getCookies(callId); 463 } 464 465 void InspectorBackend::deleteCookie(const String& cookieName) 459 void InspectorBackend::getCookies(long callId, const String& domain) 466 460 { 467 461 if (!m_inspectorController) 468 462 return; 469 m_inspectorController->deleteCookie(cookieName); 463 m_inspectorController->getCookies(callId, domain); 464 } 465 466 void InspectorBackend::deleteCookie(const String& cookieName, const String& domain) 467 { 468 if (!m_inspectorController) 469 return; 470 m_inspectorController->deleteCookie(cookieName, domain); 470 471 } 471 472 -
trunk/WebCore/inspector/InspectorBackend.h
r49234 r49263 139 139 void copyNode(long nodeId); 140 140 141 void getCookies(long callId );142 void deleteCookie(const String& cookieName );141 void getCookies(long callId, const String& domain); 142 void deleteCookie(const String& cookieName, const String& domain); 143 143 144 144 // Generic code called from custom implementations. -
trunk/WebCore/inspector/InspectorBackend.idl
r49234 r49263 111 111 void copyNode(in long nodeId); 112 112 113 void getCookies(in long callId );114 void deleteCookie(in DOMString cookieName );113 void getCookies(in long callId, in DOMString domain); 114 void deleteCookie(in DOMString cookieName, in DOMString domain); 115 115 116 116 // Called from InjectedScript. -
trunk/WebCore/inspector/InspectorController.cpp
r49234 r49263 37 37 #include "Console.h" 38 38 #include "ConsoleMessage.h" 39 #include "Cookie.h" 39 40 #include "CookieJar.h" 40 41 #include "Document.h" … … 77 78 #include "TextIterator.h" 78 79 #include <wtf/CurrentTime.h> 80 #include <wtf/ListHashSet.h> 79 81 #include <wtf/RefCounted.h> 80 82 #include <wtf/StdLibExtras.h> … … 653 655 654 656 ResourcesMap::iterator resourcesEnd = m_resources.end(); 655 for (ResourcesMap::iterator it = m_resources.begin(); it != resourcesEnd; ++it) 657 for (ResourcesMap::iterator it = m_resources.begin(); it != resourcesEnd; ++it) { 656 658 it->second->createScriptObject(m_frontend.get()); 657 659 m_frontend->addCookieDomain(it->second->frame()->document()->url().host()); 660 } 661 658 662 unsigned messageCount = m_consoleMessages.size(); 659 663 for (unsigned i = 0; i < messageCount; ++i) … … 973 977 addResource(resource.get()); 974 978 975 if (m_frontend) 979 if (m_frontend) { 976 980 resource->updateScriptObject(m_frontend.get()); 981 m_frontend->addCookieDomain(resource->frame()->document()->url().host()); 982 } 977 983 } 978 984 … … 1147 1153 #endif 1148 1154 1155 void InspectorController::getCookies(long callId, const String& host) 1156 { 1157 if (!m_frontend) 1158 return; 1159 1160 // If we can get raw cookies. 1161 ListHashSet<Cookie> rawCookiesList; 1162 1163 // If we can't get raw cookies - fall back to String representation 1164 String stringCookiesList; 1165 1166 // Return value to getRawCookies should be the same for every call because 1167 // the return value is platform/network backend specific, and the call will 1168 // always return the same true/false value. 1169 bool rawCookiesImplemented = false; 1170 1171 ResourcesMap::iterator resourcesEnd = m_resources.end(); 1172 for (ResourcesMap::iterator it = m_resources.begin(); it != resourcesEnd; ++it) { 1173 Document* document = it->second->frame()->document(); 1174 if (document->url().host() == host) { 1175 Vector<Cookie> docCookiesList; 1176 rawCookiesImplemented = getRawCookies(document, document->cookieURL(), docCookiesList); 1177 1178 if (!rawCookiesImplemented) 1179 // FIXME: We need duplication checking for the String representation of cookies. 1180 stringCookiesList += document->cookie(); 1181 else { 1182 int cookiesSize = docCookiesList.size(); 1183 for (int i = 0; i < cookiesSize; i++) { 1184 if (!rawCookiesList.contains(docCookiesList[i])) 1185 rawCookiesList.add(docCookiesList[i]); 1186 } 1187 } 1188 } 1189 } 1190 1191 if (!rawCookiesImplemented) 1192 m_frontend->didGetCookies(callId, m_frontend->newScriptArray(), stringCookiesList); 1193 else 1194 m_frontend->didGetCookies(callId, buildArrayForCookies(rawCookiesList), String()); 1195 } 1196 1197 ScriptArray InspectorController::buildArrayForCookies(ListHashSet<Cookie>& cookiesList) 1198 { 1199 ScriptArray cookies = m_frontend->newScriptArray(); 1200 1201 ListHashSet<Cookie>::iterator end = cookiesList.end(); 1202 ListHashSet<Cookie>::iterator it = cookiesList.begin(); 1203 for (int i = 0; it != end; ++it, i++) 1204 cookies.set(i, buildObjectForCookie(*it)); 1205 1206 return cookies; 1207 } 1208 1209 ScriptObject InspectorController::buildObjectForCookie(const Cookie& cookie) 1210 { 1211 ScriptObject value = m_frontend->newScriptObject(); 1212 value.set("name", cookie.name); 1213 value.set("value", cookie.value); 1214 value.set("domain", cookie.domain); 1215 value.set("path", cookie.path); 1216 value.set("expires", cookie.expires); 1217 value.set("size", (cookie.name.length() + cookie.value.length())); 1218 value.set("httpOnly", cookie.httpOnly); 1219 value.set("secure", cookie.secure); 1220 value.set("session", cookie.session); 1221 return value; 1222 } 1223 1149 1224 #if ENABLE(DOM_STORAGE) 1150 1225 void InspectorController::didUseDOMStorage(StorageArea* storageArea, bool isLocalStorage, Frame* frame) … … 1730 1805 } 1731 1806 1732 void InspectorController::deleteCookie(const String& cookieName) 1733 { 1734 Document* document = m_inspectedPage->mainFrame()->document(); 1735 WebCore::deleteCookie(document, document->cookieURL(), cookieName); 1807 void InspectorController::deleteCookie(const String& cookieName, const String& domain) 1808 { 1809 ResourcesMap::iterator resourcesEnd = m_resources.end(); 1810 for (ResourcesMap::iterator it = m_resources.begin(); it != resourcesEnd; ++it) { 1811 Document* document = it->second->frame()->document(); 1812 if (document->url().host() == domain) 1813 WebCore::deleteCookie(document, document->cookieURL(), cookieName); 1814 } 1736 1815 } 1737 1816 -
trunk/WebCore/inspector/InspectorController.h
r49234 r49263 31 31 32 32 #include "Console.h" 33 #include "Cookie.h" 33 34 #include "PlatformString.h" 35 #include "ScriptArray.h" 34 36 #include "ScriptObject.h" 35 37 #include "ScriptState.h" … … 40 42 #include <wtf/HashMap.h> 41 43 #include <wtf/HashSet.h> 44 #include <wtf/ListHashSet.h> 42 45 #include <wtf/RefCounted.h> 43 46 #include <wtf/Vector.h> … … 233 236 void mainResourceFiredLoadEvent(DocumentLoader*, const KURL&); 234 237 void mainResourceFiredDOMContentEvent(DocumentLoader*, const KURL&); 238 239 void getCookies(long callId, const String& url); 235 240 236 241 #if ENABLE(DATABASE) … … 308 313 void resetInjectedScript(); 309 314 310 void deleteCookie(const String& cookieName );315 void deleteCookie(const String& cookieName, const String& domain); 311 316 312 317 #if ENABLE(JAVASCRIPT_DEBUGGER) … … 322 327 InspectorDOMStorageResource* getDOMStorageResourceForId(int storageId); 323 328 #endif 329 330 ScriptObject buildObjectForCookie(const Cookie&); 331 ScriptArray buildArrayForCookies(ListHashSet<Cookie>&); 324 332 325 333 void focusNode(); -
trunk/WebCore/inspector/InspectorDOMAgent.cpp
r48887 r49263 439 439 } 440 440 441 void InspectorDOMAgent::getCookies(long callId)442 {443 Document* doc = mainFrameDocument();444 Vector<Cookie> cookiesList;445 bool isImplemented = getRawCookies(doc, doc->cookieURL(), cookiesList);446 447 if (!isImplemented)448 m_frontend->didGetCookies(callId, m_frontend->newScriptArray(), doc->cookie());449 else450 m_frontend->didGetCookies(callId, buildArrayForCookies(cookiesList), String());451 }452 453 441 ScriptObject InspectorDOMAgent::buildObjectForNode(Node* node, int depth, NodeToIdMap* nodesMap) 454 442 { … … 550 538 } 551 539 552 ScriptObject InspectorDOMAgent::buildObjectForCookie(const Cookie& cookie)553 {554 ScriptObject value = m_frontend->newScriptObject();555 value.set("name", cookie.name);556 value.set("value", cookie.value);557 value.set("domain", cookie.domain);558 value.set("path", cookie.path);559 value.set("expires", cookie.expires);560 value.set("size", static_cast<int>(cookie.name.length() + cookie.value.length()));561 value.set("httpOnly", cookie.httpOnly);562 value.set("secure", cookie.secure);563 value.set("session", cookie.session);564 return value;565 }566 567 ScriptArray InspectorDOMAgent::buildArrayForCookies(const Vector<Cookie>& cookiesList)568 {569 ScriptArray cookies = m_frontend->newScriptArray();570 unsigned length = cookiesList.size();571 for (unsigned i = 0; i < length; ++i) {572 const Cookie& cookie = cookiesList[i];573 cookies.set(i, buildObjectForCookie(cookie));574 }575 return cookies;576 }577 578 540 Node* InspectorDOMAgent::innerFirstChild(Node* node) 579 541 { -
trunk/WebCore/inspector/InspectorDOMAgent.h
r48884 r49263 54 54 class Page; 55 55 56 struct Cookie;57 58 56 struct EventListenerInfo { 59 57 EventListenerInfo(Node* node, const AtomicString& eventType, const EventListenerVector& eventListenerVector) … … 89 87 void setTextNodeValue(long callId, long nodeId, const String& value); 90 88 void getEventListenersForNode(long callId, long nodeId); 91 void getCookies(long callId);92 89 93 90 // Methods called from the InspectorController. … … 116 113 117 114 ScriptObject buildObjectForEventListener(const RegisteredEventListener& registeredEventListener, const AtomicString& eventType, Node* node); 118 119 ScriptObject buildObjectForCookie(const Cookie& cookie);120 ScriptArray buildArrayForCookies(const Vector<Cookie>& cookiesList);121 115 122 116 // We represent embedded doms as a part of the same hierarchy. Hence we treat children of frame owners differently. -
trunk/WebCore/inspector/InspectorFrontend.cpp
r49234 r49263 126 126 } 127 127 128 void InspectorFrontend::addCookieDomain(String domain) 129 { 130 OwnPtr<ScriptFunctionCall> function(newFunctionCall("addCookieDomain")); 131 function->appendArgument(domain); 132 function->call(); 133 } 134 128 135 void InspectorFrontend::updateFocusedNode(long long nodeId) 129 136 { -
trunk/WebCore/inspector/InspectorFrontend.h
r49234 r49263 70 70 bool updateResource(long long identifier, const ScriptObject& resourceObj); 71 71 void removeResource(long long identifier); 72 73 void addCookieDomain(String); 72 74 73 75 void updateFocusedNode(long long nodeId); -
trunk/WebCore/inspector/front-end/CookieItemsView.js
r49062 r49263 28 28 */ 29 29 30 WebInspector.CookieItemsView = function( )30 WebInspector.CookieItemsView = function(cookieDomain) 31 31 { 32 32 WebInspector.View.call(this); … … 41 41 this.refreshButton = new WebInspector.StatusBarButton(WebInspector.UIString("Refresh"), "refresh-storage-status-bar-item"); 42 42 this.refreshButton.addEventListener("click", this._refreshButtonClicked.bind(this), false); 43 44 this._cookieDomain = cookieDomain; 43 45 } 44 46 … … 84 86 } 85 87 86 WebInspector.Cookies.getCookiesAsync(callback );88 WebInspector.Cookies.getCookiesAsync(callback, this._cookieDomain); 87 89 }, 88 90 … … 261 263 262 264 var cookie = this._dataGrid.selectedNode.cookie; 263 InspectorController.deleteCookie(cookie.name );265 InspectorController.deleteCookie(cookie.name, this._cookieDomain); 264 266 this.update(); 265 267 }, -
trunk/WebCore/inspector/front-end/DOMAgent.js
r49174 r49263 438 438 WebInspector.Cookies = {} 439 439 440 WebInspector.Cookies.getCookiesAsync = function(callback )440 WebInspector.Cookies.getCookiesAsync = function(callback, cookieDomain) 441 441 { 442 442 function mycallback(cookies, cookiesString) { … … 447 447 } 448 448 var callId = WebInspector.Callback.wrap(mycallback); 449 InspectorController.getCookies(callId );449 InspectorController.getCookies(callId, cookieDomain); 450 450 } 451 451 -
trunk/WebCore/inspector/front-end/StoragePanel.js
r49234 r49263 64 64 this.cookieListTreeElement.expand(); 65 65 66 this.cookieTreeElement = new WebInspector.CookieSidebarTreeElement();67 this.cookieListTreeElement.appendChild(this.cookieTreeElement);68 69 66 this.storageViews = document.createElement("div"); 70 67 this.storageViews.id = "storage-views"; … … 121 118 this._domStorage = []; 122 119 123 delete this._cookieView; 120 this._cookieDomains = {}; 121 this._cookieViews = {}; 124 122 125 123 this.databasesListTreeElement.removeChildren(); 126 124 this.localStorageListTreeElement.removeChildren(); 127 125 this.sessionStorageListTreeElement.removeChildren(); 126 this.cookieListTreeElement.removeChildren(); 127 128 128 this.storageViews.removeChildren(); 129 129 … … 146 146 database._databasesTreeElement = databaseTreeElement; 147 147 this.databasesListTreeElement.appendChild(databaseTreeElement); 148 }, 149 150 addCookieDomain: function(domain) 151 { 152 // Eliminate duplicate domains from the list. 153 if (typeof this._cookieDomains[domain] !== "undefined") 154 return; 155 156 var cookieDomainTreeElement = new WebInspector.CookieSidebarTreeElement(domain); 157 this.cookieListTreeElement.appendChild(cookieDomainTreeElement); 158 this._cookieDomains[domain] = true; 148 159 }, 149 160 … … 241 252 }, 242 253 243 showCookies: function( )254 showCookies: function(cookieDomain) 244 255 { 245 256 if (this.visibleView) 246 257 this.visibleView.hide(); 247 258 248 var view = this._cookieView ;259 var view = this._cookieViews[cookieDomain]; 249 260 if (!view) { 250 view = new WebInspector.CookieItemsView( );251 this._cookieView = view;261 view = new WebInspector.CookieItemsView(cookieDomain); 262 this._cookieViews[cookieDomain] = view; 252 263 } 253 264 … … 569 580 WebInspector.DOMStorageSidebarTreeElement.prototype.__proto__ = WebInspector.SidebarTreeElement.prototype; 570 581 571 WebInspector.CookieSidebarTreeElement = function( )582 WebInspector.CookieSidebarTreeElement = function(cookieDomain) 572 583 { 573 WebInspector.SidebarTreeElement.call(this, "cookie-sidebar-tree-item", null, "", null, false); 584 WebInspector.SidebarTreeElement.call(this, "cookie-sidebar-tree-item", cookieDomain, "", null, false); 585 this._cookieDomain = cookieDomain; 574 586 575 587 this.refreshTitles(); … … 579 591 onselect: function() 580 592 { 581 WebInspector.panels.storage.showCookies(); 582 }, 583 584 get mainTitle() 585 { 586 return WebInspector.UIString("Cookies"); 587 }, 588 589 set mainTitle(x) 590 { 591 // Do nothing. 593 WebInspector.panels.storage.showCookies(this._cookieDomain); 592 594 }, 593 595 -
trunk/WebCore/inspector/front-end/inspector.js
r49234 r49263 1040 1040 payload.version); 1041 1041 this.panels.storage.addDatabase(database); 1042 } 1043 1044 WebInspector.addCookieDomain = function(domain) 1045 { 1046 this.panels.storage.addCookieDomain(domain); 1042 1047 } 1043 1048 -
trunk/WebCore/platform/Cookie.h
r47656 r49263 28 28 29 29 #include "PlatformString.h" 30 #include "StringHash.h" 30 31 31 32 namespace WebCore { … … 59 60 }; 60 61 62 struct CookieHash { 63 static unsigned hash(Cookie key) 64 { 65 return StringHash::hash(key.name) + StringHash::hash(key.domain) + StringHash::hash(key.path) + key.secure; 66 } 67 68 static bool equal(Cookie a, Cookie b) 69 { 70 return a.name == b.name && a.domain == b.domain && a.path == b.path && a.secure == b.secure; 71 } 72 }; 73 } 74 75 namespace WTF { 76 template<typename T> struct DefaultHash; 77 template<> struct DefaultHash<WebCore::Cookie> { 78 typedef WebCore::CookieHash Hash; 79 }; 61 80 } 62 81 -
trunk/WebCore/platform/network/win/CookieJarCFNetWin.cpp
r49210 r49263 149 149 } 150 150 151 void deleteCookie(const Document*, const KURL& , const String&)151 void deleteCookie(const Document*, const KURL& url, const String& name) 152 152 { 153 // FIXME: Not yet implemented 153 CFHTTPCookieStorageRef cookieStorage = currentCookieStorage(); 154 if (!cookieStorage) 155 return; 156 157 RetainPtr<CFURLRef> urlCF(AdoptCF, url.createCFURL()); 158 159 bool sendSecureCookies = url.protocolIs("https"); 160 RetainPtr<CFArrayRef> cookiesCF(AdoptCF, CFHTTPCookieStorageCopyCookiesForURL(cookieStorage, urlCF.get(), sendSecureCookies)); 161 162 CFIndex count = CFArrayGetCount(cookiesCF.get()); 163 for (CFIndex i = 0; i < count; i++) { 164 CFHTTPCookieRef cookie = (CFHTTPCookieRef)CFArrayGetValueAtIndex(cookiesCF.get(), i); 165 String cookieName = CFHTTPCookieGetName(cookie); 166 if (cookieName == name) { 167 CFHTTPCookieStorageDeleteCookie(cookieStorage, cookie); 168 break; 169 } 170 } 154 171 } 155 172
Note:
See TracChangeset
for help on using the changeset viewer.