1/* 2 * Copyright (C) 2013 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above 11 * copyright notice, this list of conditions and the following disclaimer 12 * in the documentation and/or other materials provided with the 13 * distribution. 14 * * Neither the name of Google Inc. nor the names of its 15 * contributors may be used to endorse or promote products derived from 16 * this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 */ 30 31#include "config.h" 32#include "Init.h" 33 34#include "bindings/core/v8/ScriptStreamerThread.h" 35#include "core/EventNames.h" 36#include "core/EventTargetNames.h" 37#include "core/EventTypeNames.h" 38#include "core/FetchInitiatorTypeNames.h" 39#include "core/HTMLNames.h" 40#include "core/HTMLTokenizerNames.h" 41#include "core/InputTypeNames.h" 42#include "core/MathMLNames.h" 43#include "core/MediaFeatureNames.h" 44#include "core/MediaTypeNames.h" 45#include "core/SVGNames.h" 46#include "core/XLinkNames.h" 47#include "core/XMLNSNames.h" 48#include "core/XMLNames.h" 49#include "core/dom/Document.h" 50#include "core/events/EventFactory.h" 51#include "core/html/parser/HTMLParserThread.h" 52#include "core/workers/WorkerThread.h" 53#include "platform/EventTracer.h" 54#include "platform/FontFamilyNames.h" 55#include "platform/Partitions.h" 56#include "platform/PlatformThreadData.h" 57#include "platform/heap/Heap.h" 58#include "wtf/text/StringStatics.h" 59 60namespace blink { 61 62void CoreInitializer::registerEventFactory() 63{ 64 static bool isRegistered = false; 65 if (isRegistered) 66 return; 67 isRegistered = true; 68 69 Document::registerEventFactory(EventFactory::create()); 70} 71 72void CoreInitializer::init() 73{ 74 ASSERT(!m_isInited); 75 m_isInited = true; 76 77 HTMLNames::init(); 78 SVGNames::init(); 79 XLinkNames::init(); 80 MathMLNames::init(); 81 XMLNSNames::init(); 82 XMLNames::init(); 83 84 EventNames::init(); 85 EventTargetNames::init(); 86 EventTypeNames::init(); 87 FetchInitiatorTypeNames::init(); 88 FontFamilyNames::init(); 89 HTMLTokenizerNames::init(); 90 InputTypeNames::init(); 91 MediaFeatureNames::init(); 92 MediaTypeNames::init(); 93 94 // It would make logical sense to do this in WTF::initialize() but there are 95 // ordering dependencies, e.g. about "xmlns". 96 WTF::StringStatics::init(); 97 98 QualifiedName::init(); 99 Partitions::init(); 100 EventTracer::initialize(); 101 102 registerEventFactory(); 103 104 // Ensure that the main thread's thread-local data is initialized before 105 // starting any worker threads. 106 PlatformThreadData::current(); 107 108 StringImpl::freezeStaticStrings(); 109 110 // Creates HTMLParserThread::shared and ScriptStreamerThread::shared, but 111 // does not start the threads. 112 HTMLParserThread::init(); 113 ScriptStreamerThread::init(); 114} 115 116void CoreInitializer::shutdown() 117{ 118 // Make sure we stop the HTMLParserThread and ScriptStreamerThread before 119 // Platform::current() is cleared. 120 ScriptStreamerThread::shutdown(); 121 HTMLParserThread::shutdown(); 122 123 // Make sure we stop WorkerThreads before Partition::shutdown() which frees ExecutionContext. 124 WorkerThread::terminateAndWaitForAllWorkers(); 125 126 Partitions::shutdown(); 127} 128 129} // namespace blink 130