Changeset 66297 in webkit
- Timestamp:
- Aug 27, 2010 9:32:17 PM (14 years ago)
- Location:
- trunk
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/ChangeLog
r66251 r66297 1 2010-08-27 Kimmo Kinnunen <kimmo.t.kinnunen@nokia.com> 2 3 Reviewed by Kenneth Rohde Christiansen. 4 5 [Qt] NPAPI Plugin metadata should be cached, and loading a plugin should not require loading every plugin 6 https://bugs.webkit.org/show_bug.cgi?id=43179 7 8 Add ENABLE_NETSCAPE_PLUGIN_METADATA_CACHE flag to enable persistent 9 NPAPI Plugin Cache. The flag is enabled by default. 10 11 * wtf/Platform.h: Add ENABLE_NETSCAPE_PLUGIN_METADATA_CACHE 12 1 13 2010-07-27 Jer Noble <jer.noble@apple.com> 2 14 -
trunk/JavaScriptCore/wtf/Platform.h
r66251 r66297 858 858 #endif 859 859 860 #if !defined(ENABLE_NETSCAPE_PLUGIN_METADATA_CACHE) 861 #define ENABLE_NETSCAPE_PLUGIN_METADATA_CACHE 0 862 #endif 863 860 864 #if !defined(WTF_USE_PLUGIN_HOST_PROCESS) 861 865 #define WTF_USE_PLUGIN_HOST_PROCESS 0 -
trunk/WebCore/ChangeLog
r66296 r66297 1 2010-08-27 Kimmo Kinnunen <kimmo.t.kinnunen@nokia.com> 2 3 Reviewed by Kenneth Rohde Christiansen. 4 5 [Qt] Cache plugin info to a persistent database 6 7 https://bugs.webkit.org/show_bug.cgi?id=43179 8 9 Implement a cache of NPAPI plugin metadata. Write the metadata to aa 10 file that gets rewritten if any plugin is added / removed. Compilation 11 of the feature is controlled by #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE) 12 13 Currently only enabled for Qt UNIX flavors. 14 15 * WebCore.pro: Enable NETSCAPE_PLUGIN_METADATA_CACHE for UNIX builds 16 * platform/qt/FileSystemQt.cpp: 17 (WebCore::openFile): Added. 18 (WebCore::readFromFile): Added. 19 * plugins/PluginDatabase.cpp: 20 (WebCore::persistentPluginMetadataCachePath): Static accessor for the path 21 (WebCore::PluginDatabase::PluginDatabase): Add instance variable. 22 (WebCore::PluginDatabase::refresh): 23 (WebCore::PluginDatabase::pluginForMIMEType): Ensure returned plugin is loaded. 24 (WebCore::PluginDatabase::MIMETypeForExtension): Ensure returned plugin is loaded. 25 (WebCore::PluginDatabase::clear): 26 (WebCore::fillBufferWithContentsOfFile): Static helper function. 27 (WebCore::readUTF8String): Static helper function. 28 (WebCore::readTime): Static helper function. 29 (WebCore::PluginDatabase::loadPersistentMetadataCache): 30 (WebCore::writeUTF8String): Static helper function. 31 (WebCore::writeTime): Static helper function. 32 (WebCore::PluginDatabase::updatePersistentMetadataCache): Added. 33 (WebCore::PluginDatabase::isPersistentMetadataCacheEnabled): Added. 34 (WebCore::PluginDatabase::setPersistentMetadataCacheEnabled):Added. 35 (WebCore::PluginDatabase::persistentMetadataCachePath): Added. 36 (WebCore::PluginDatabase::setPersistentMetadataCachePath): Added. 37 * plugins/PluginDatabase.h: 38 * plugins/PluginPackage.cpp: 39 (WebCore::PluginPackage::PluginPackage): Add instance variable. 40 (WebCore::PluginPackage::createPackageFromCache): Added. 41 (WebCore::PluginPackage::ensurePluginLoaded): Added. 42 * plugins/PluginPackage.h: 43 (WebCore::PluginPackage::fullMIMEDescription): Added. 44 * plugins/qt/PluginPackageQt.cpp: 45 (WebCore::PluginPackage::fetchInfo): Split mime parsing. 46 (WebCore::PluginPackage::setMIMEDescription): Added. Mime parsing. 47 1 48 2010-08-27 Daniel Bates <dbates@rim.com> 2 49 -
trunk/WebCore/WebCore.pro
r66277 r66297 2395 2395 plugins/qt/PluginContainerQt.h 2396 2396 DEFINES += XP_UNIX 2397 DEFINES += ENABLE_NETSCAPE_PLUGIN_METADATA_CACHE=1 2397 2398 } 2398 2399 } -
trunk/WebCore/platform/qt/FileSystemQt.cpp
r64816 r66297 129 129 } 130 130 131 #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE) 132 PlatformFileHandle openFile(const String& path, FileOpenMode mode) 133 { 134 QIODevice::OpenMode platformMode; 135 136 if (mode == OpenForRead) 137 platformMode = QIODevice::ReadOnly; 138 else if (mode == OpenForWrite) 139 platformMode = (QIODevice::WriteOnly | QIODevice::Truncate); 140 else 141 return invalidPlatformFileHandle; 142 143 QFile* file = new QFile(path); 144 if (file->open(platformMode)) 145 return file; 146 147 return invalidPlatformFileHandle; 148 } 149 150 int readFromFile(PlatformFileHandle handle, char* data, int length) 151 { 152 if (handle && handle->exists() && handle->isReadable()) 153 return handle->read(data, length); 154 return 0; 155 } 156 #endif 157 131 158 void closeFile(PlatformFileHandle& handle) 132 159 { -
trunk/WebCore/plugins/PluginDatabase.cpp
r60187 r66297 31 31 #include "KURL.h" 32 32 #include "PluginPackage.h" 33 #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE) 34 #include "FileSystem.h" 35 #endif 33 36 #include <stdlib.h> 34 37 … … 37 40 typedef HashMap<String, RefPtr<PluginPackage> > PluginPackageByNameMap; 38 41 42 #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE) 43 static const size_t maximumPersistentPluginMetadataCacheSize = 32768; 44 45 static bool gPersistentPluginMetadataCacheIsEnabled; 46 47 String& persistentPluginMetadataCachePath() 48 { 49 DEFINE_STATIC_LOCAL(String, cachePath, ()); 50 return cachePath; 51 } 52 #endif 53 39 54 PluginDatabase::PluginDatabase() 55 #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE) 56 : m_persistentMetadataCacheIsLoaded(false) 57 #endif 40 58 { 41 59 } … … 75 93 bool PluginDatabase::refresh() 76 94 { 95 #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE) 96 if (!m_persistentMetadataCacheIsLoaded) 97 loadPersistentMetadataCache(); 98 #endif 77 99 bool pluginSetChanged = false; 78 100 … … 126 148 if (!pluginSetChanged) 127 149 return false; 150 151 #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE) 152 updatePersistentMetadataCache(); 153 #endif 128 154 129 155 m_registeredMIMETypes.clear(); … … 183 209 continue; 184 210 185 if (plugin->mimeToDescriptions().contains(key)) 211 if (plugin->mimeToDescriptions().contains(key)) { 212 #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE) 213 if (!plugin->ensurePluginLoaded()) 214 continue; 215 #endif 186 216 pluginChoices.append(plugin); 217 } 187 218 } 188 219 … … 223 254 return mimeType; 224 255 256 #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE) 257 if (!plugin->ensurePluginLoaded()) 258 continue; 259 #endif 225 260 pluginChoices.append(plugin); 226 261 mimeTypeForPlugin.add(plugin, mimeType); … … 316 351 m_registeredMIMETypes.clear(); 317 352 m_preferredPlugins.clear(); 353 #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE) 354 m_persistentMetadataCacheIsLoaded = false; 355 #endif 318 356 } 319 357 … … 428 466 #endif // !OS(SYMBIAN) && !OS(WINDOWS) 429 467 430 } 468 #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE) 469 470 static void fillBufferWithContentsOfFile(PlatformFileHandle file, Vector<char>& buffer) 471 { 472 size_t bufferSize = 0; 473 size_t bufferCapacity = 1024; 474 buffer.resize(bufferCapacity); 475 476 do { 477 bufferSize += readFromFile(file, buffer.data() + bufferSize, bufferCapacity - bufferSize); 478 if (bufferSize == bufferCapacity) { 479 if (bufferCapacity < maximumPersistentPluginMetadataCacheSize) { 480 bufferCapacity *= 2; 481 buffer.resize(bufferCapacity); 482 } else { 483 buffer.clear(); 484 return; 485 } 486 } else 487 break; 488 } while (true); 489 490 buffer.shrink(bufferSize); 491 } 492 493 static bool readUTF8String(String& resultString, char*& start, const char* end) 494 { 495 if (start >= end) 496 return false; 497 498 int len = strlen(start); 499 resultString = String::fromUTF8(start, len); 500 start += len + 1; 501 502 return true; 503 } 504 505 static bool readTime(time_t& resultTime, char*& start, const char* end) 506 { 507 if (start + sizeof(time_t) >= end) 508 return false; 509 510 resultTime = *reinterpret_cast<time_t*>(start); 511 start += sizeof(time_t); 512 513 return true; 514 } 515 516 static const char schemaVersion = '1'; 517 static const char persistentPluginMetadataCacheFilename[] = "PluginMetadataCache.bin"; 518 519 void PluginDatabase::loadPersistentMetadataCache() 520 { 521 if (!isPersistentMetadataCacheEnabled() || persistentMetadataCachePath().isEmpty()) 522 return; 523 524 PlatformFileHandle file; 525 String absoluteCachePath = pathByAppendingComponent(persistentMetadataCachePath(), persistentPluginMetadataCacheFilename); 526 file = openFile(absoluteCachePath, OpenForRead); 527 528 if (!isHandleValid(file)) 529 return; 530 531 // Mark cache as loaded regardless of success or failure. If 532 // there's error in the cache, we won't try to load it anymore. 533 m_persistentMetadataCacheIsLoaded = true; 534 535 Vector<char> fileContents; 536 fillBufferWithContentsOfFile(file, fileContents); 537 closeFile(file); 538 539 if (fileContents.size() < 2 || fileContents.first() != schemaVersion || fileContents.last() != '\0') { 540 LOG_ERROR("Unable to read plugin metadata cache: corrupt schema"); 541 deleteFile(absoluteCachePath); 542 return; 543 } 544 545 char* bufferPos = fileContents.data() + 1; 546 char* end = fileContents.data() + fileContents.size(); 547 548 PluginSet cachedPlugins; 549 HashMap<String, time_t> cachedPluginPathsWithTimes; 550 HashMap<String, RefPtr<PluginPackage> > cachedPluginsByPath; 551 552 while (bufferPos < end) { 553 String path; 554 time_t lastModified; 555 String name; 556 String desc; 557 String mimeDesc; 558 if (!(readUTF8String(path, bufferPos, end) 559 && readTime(lastModified, bufferPos, end) 560 && readUTF8String(name, bufferPos, end) 561 && readUTF8String(desc, bufferPos, end) 562 && readUTF8String(mimeDesc, bufferPos, end))) { 563 LOG_ERROR("Unable to read plugin metadata cache: corrupt data"); 564 deleteFile(absoluteCachePath); 565 return; 566 } 567 568 // Skip metadata that points to plugins from directories that 569 // are not part of plugin directory list anymore. 570 String pluginDirectoryName = directoryName(path); 571 if (m_pluginDirectories.find(pluginDirectoryName) == WTF::notFound) 572 continue; 573 574 RefPtr<PluginPackage> package = PluginPackage::createPackageFromCache(path, lastModified, name, desc, mimeDesc); 575 576 if (package && cachedPlugins.add(package).second) { 577 cachedPluginPathsWithTimes.add(package->path(), package->lastModified()); 578 cachedPluginsByPath.add(package->path(), package); 579 } 580 } 581 582 m_plugins.swap(cachedPlugins); 583 m_pluginsByPath.swap(cachedPluginsByPath); 584 m_pluginPathsWithTimes.swap(cachedPluginPathsWithTimes); 585 } 586 587 static bool writeUTF8String(PlatformFileHandle file, const String& string) 588 { 589 CString utf8String = string.utf8(); 590 int length = utf8String.length() + 1; 591 return writeToFile(file, utf8String.data(), length) == length; 592 } 593 594 static bool writeTime(PlatformFileHandle file, const time_t& time) 595 { 596 return writeToFile(file, reinterpret_cast<const char*>(&time), sizeof(time_t)) == sizeof(time_t); 597 } 598 599 void PluginDatabase::updatePersistentMetadataCache() 600 { 601 if (!isPersistentMetadataCacheEnabled() || persistentMetadataCachePath().isEmpty()) 602 return; 603 604 makeAllDirectories(persistentMetadataCachePath()); 605 String absoluteCachePath = pathByAppendingComponent(persistentMetadataCachePath(), persistentPluginMetadataCacheFilename); 606 deleteFile(absoluteCachePath); 607 608 if (m_plugins.isEmpty()) 609 return; 610 611 PlatformFileHandle file; 612 file = openFile(absoluteCachePath, OpenForWrite); 613 614 if (!isHandleValid(file)) { 615 LOG_ERROR("Unable to open plugin metadata cache for saving"); 616 return; 617 } 618 619 char localSchemaVersion = schemaVersion; 620 if (writeToFile(file, &localSchemaVersion, 1) != 1) { 621 LOG_ERROR("Unable to write plugin metadata cache schema"); 622 closeFile(file); 623 deleteFile(absoluteCachePath); 624 return; 625 } 626 627 PluginSet::const_iterator end = m_plugins.end(); 628 for (PluginSet::const_iterator it = m_plugins.begin(); it != end; ++it) { 629 if (!(writeUTF8String(file, (*it)->path()) 630 && writeTime(file, (*it)->lastModified()) 631 && writeUTF8String(file, (*it)->name()) 632 && writeUTF8String(file, (*it)->description()) 633 && writeUTF8String(file, (*it)->fullMIMEDescription()))) { 634 LOG_ERROR("Unable to write plugin metadata to cache"); 635 closeFile(file); 636 deleteFile(absoluteCachePath); 637 return; 638 } 639 } 640 641 closeFile(file); 642 } 643 644 bool PluginDatabase::isPersistentMetadataCacheEnabled() 645 { 646 return gPersistentPluginMetadataCacheIsEnabled; 647 } 648 649 void PluginDatabase::setPersistentMetadataCacheEnabled(bool isEnabled) 650 { 651 gPersistentPluginMetadataCacheIsEnabled = isEnabled; 652 } 653 654 String PluginDatabase::persistentMetadataCachePath() 655 { 656 return WebCore::persistentPluginMetadataCachePath(); 657 } 658 659 void PluginDatabase::setPersistentMetadataCachePath(const String& persistentMetadataCachePath) 660 { 661 WebCore::persistentPluginMetadataCachePath() = persistentMetadataCachePath; 662 } 663 #endif 664 } -
trunk/WebCore/plugins/PluginDatabase.h
r65077 r66297 79 79 80 80 String MIMETypeForExtension(const String& extension) const; 81 #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE) 82 static bool isPersistentMetadataCacheEnabled(); 83 static void setPersistentMetadataCacheEnabled(bool isEnabled); 84 static String persistentMetadataCachePath(); 85 static void setPersistentMetadataCachePath(const String& persistentMetadataCachePath); 86 #endif 81 87 82 88 private: … … 87 93 bool add(PassRefPtr<PluginPackage>); 88 94 void remove(PluginPackage*); 95 #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE) 96 void loadPersistentMetadataCache(); 97 void updatePersistentMetadataCache(); 98 #endif 89 99 90 100 Vector<String> m_pluginDirectories; … … 94 104 HashMap<String, time_t> m_pluginPathsWithTimes; 95 105 HashMap<String, RefPtr<PluginPackage> > m_preferredPlugins; 106 #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE) 107 bool m_persistentMetadataCacheIsLoaded; 108 #endif 96 109 }; 97 110 -
trunk/WebCore/plugins/PluginPackage.cpp
r65524 r66297 109 109 , m_lastModified(lastModified) 110 110 , m_freeLibraryTimer(this, &PluginPackage::freeLibraryTimerFired) 111 #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE) 112 , m_infoIsFromCache(true) 113 #endif 111 114 { 112 115 m_fileName = pathGetFileName(m_path); … … 162 165 return package.release(); 163 166 } 167 168 #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE) 169 PassRefPtr<PluginPackage> PluginPackage::createPackageFromCache(const String& path, const time_t& lastModified, const String& name, const String& description, const String& mimeDescription) 170 { 171 RefPtr<PluginPackage> package = adoptRef(new PluginPackage(path, lastModified)); 172 package->m_name = name; 173 package->m_description = description; 174 package->determineModuleVersionFromDescription(); 175 package->setMIMEDescription(mimeDescription); 176 package->m_infoIsFromCache = true; 177 return package.release(); 178 } 179 #endif 164 180 165 181 #if defined(XP_UNIX) … … 344 360 } 345 361 346 } 362 #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE) 363 bool PluginPackage::ensurePluginLoaded() 364 { 365 if (!m_infoIsFromCache) 366 return m_isLoaded; 367 368 m_quirks = PluginQuirkSet(); 369 m_name = String(); 370 m_description = String(); 371 m_fullMIMEDescription = String(); 372 m_moduleVersion = 0; 373 374 return fetchInfo(); 375 } 376 #endif 377 378 } -
trunk/WebCore/plugins/PluginPackage.h
r65077 r66297 50 50 ~PluginPackage(); 51 51 static PassRefPtr<PluginPackage> createPackage(const String& path, const time_t& lastModified); 52 #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE) 53 static PassRefPtr<PluginPackage> createPackageFromCache(const String& path, const time_t& lastModified, const String& name, const String& description, const String& mimeDescription); 54 #endif 52 55 53 56 const String& name() const { return m_name; } … … 81 84 #endif // OS(SYMBIAN) 82 85 86 #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE) 87 bool ensurePluginLoaded(); 88 void setMIMEDescription(const String& mimeDescription); 89 String fullMIMEDescription() const { return m_fullMIMEDescription;} 90 #endif 83 91 private: 84 92 PluginPackage(const String& path, const time_t& lastModified); … … 122 130 123 131 PluginQuirkSet m_quirks; 132 #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE) 133 String m_fullMIMEDescription; 134 bool m_infoIsFromCache; 135 #endif 124 136 }; 125 137 -
trunk/WebCore/plugins/qt/PluginPackageQt.cpp
r66017 r66297 61 61 determineModuleVersionFromDescription(); 62 62 63 String s = gm(); 63 String mimeDescription = gm(); 64 setMIMEDescription(mimeDescription); 65 m_infoIsFromCache = false; 66 67 return true; 68 } 69 70 void PluginPackage::setMIMEDescription(const String& mimeDescription) 71 { 72 m_fullMIMEDescription = mimeDescription; 73 64 74 Vector<String> types; 65 s.split(UChar(';'), false, types);75 mimeDescription.split(UChar(';'), false, types); 66 76 for (unsigned i = 0; i < types.size(); ++i) { 67 77 Vector<String> mime; … … 77 87 } 78 88 } 79 80 return true;81 89 } 82 90 … … 188 196 return NP_VERSION_MINOR; 189 197 } 198 190 199 } -
trunk/WebKit/qt/Api/qwebplugindatabase.cpp
r50456 r66297 285 285 for (unsigned int i = 0; i < plugins.size(); ++i) { 286 286 PluginPackage* plugin = plugins[i]; 287 qwebplugins.append(QWebPluginInfo(plugin)); 287 if (plugin->ensurePluginLoaded()) 288 qwebplugins.append(QWebPluginInfo(plugin)); 288 289 } 289 290 -
trunk/WebKit/qt/Api/qwebsettings.cpp
r65234 r66297 35 35 #include "PlatformString.h" 36 36 #include "IconDatabase.h" 37 #include "PluginDatabase.h" 37 38 #include "Image.h" 38 39 #include "IntSize.h" … … 1094 1095 QWebSettings::globalSettings()->setAttribute(QWebSettings::OfflineStorageDatabaseEnabled, true); 1095 1096 QWebSettings::globalSettings()->setAttribute(QWebSettings::OfflineWebApplicationCacheEnabled, true); 1097 1098 #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE) 1099 QFileInfo info(storagePath); 1100 if (info.isDir() && info.isWritable()) { 1101 WebCore::PluginDatabase::setPersistentMetadataCacheEnabled(true); 1102 WebCore::PluginDatabase::setPersistentMetadataCachePath(storagePath); 1103 } 1104 #endif 1096 1105 } 1097 1106 -
trunk/WebKit/qt/ChangeLog
r66241 r66297 1 2010-08-27 Kimmo Kinnunen <kimmo.t.kinnunen@nokia.com> 2 3 Reviewed by Kenneth Rohde Christiansen. 4 5 [Qt] Cache plugin info to a persistent database 6 7 https://bugs.webkit.org/show_bug.cgi?id=43179 8 9 Implement a cache of NPAPI plugin metadata. Write the metadata to aa 10 file that gets rewritten if any plugin is added / removed. Compilation 11 of the feature is controlled by #if ENABLE(NETSCAPE_PLUGIN_METADATA_CACHE) 12 13 Currently only enabled for Qt UNIX flavors. 14 15 * Api/qwebplugindatabase.cpp: 16 (QWebPluginDatabase::plugins): Match previous behavior: ensure all returned plugins are loaded. 17 * Api/qwebsettings.cpp: 18 (QWebSettings::enablePersistentStorage): Set plugin cache path. 19 1 20 2010-08-27 Benjamin Poulain <benjamin.poulain@nokia.com> 2 21
Note: See TracChangeset
for help on using the changeset viewer.