1 /* 2 * Copyright (C) 2009 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 "WebKit.h" 33 34 #include "Logging.h" 35 #include "Page.h" 36 #include "RuntimeEnabledFeatures.h" 37 #include "Settings.h" 38 #include "TextEncoding.h" 39 #include "WebMediaPlayerClientImpl.h" 40 #include "WebSocket.h" 41 #include "WorkerContextExecutionProxy.h" 42 43 #include <wtf/Assertions.h> 44 #include <wtf/Threading.h> 45 #include <wtf/text/AtomicString.h> 46 47 namespace WebKit { 48 49 // Make sure we are not re-initialized in the same address space. 50 // Doing so may cause hard to reproduce crashes. 51 static bool s_webKitInitialized = false; 52 53 static WebKitClient* s_webKitClient = 0; 54 static bool s_layoutTestMode = false; 55 56 void initialize(WebKitClient* webKitClient) 57 { 58 ASSERT(!s_webKitInitialized); 59 s_webKitInitialized = true; 60 61 ASSERT(webKitClient); 62 ASSERT(!s_webKitClient); 63 s_webKitClient = webKitClient; 64 65 WTF::initializeThreading(); 66 WTF::initializeMainThread(); 67 WTF::AtomicString::init(); 68 69 // There are some code paths (for example, running WebKit in the browser 70 // process and calling into LocalStorage before anything else) where the 71 // UTF8 string encoding tables are used on a background thread before 72 // they're set up. This is a problem because their set up routines assert 73 // they're running on the main WebKitThread. It might be possible to make 74 // the initialization thread-safe, but given that so many code paths use 75 // this, initializing this lazily probably doesn't buy us much. 76 WebCore::UTF8Encoding(); 77 } 78 79 void shutdown() 80 { 81 s_webKitClient = 0; 82 } 83 84 WebKitClient* webKitClient() 85 { 86 return s_webKitClient; 87 } 88 89 void setLayoutTestMode(bool value) 90 { 91 s_layoutTestMode = value; 92 } 93 94 bool layoutTestMode() 95 { 96 return s_layoutTestMode; 97 } 98 99 void enableLogChannel(const char* name) 100 { 101 WTFLogChannel* channel = WebCore::getChannelFromName(name); 102 if (channel) 103 channel->state = WTFLogChannelOn; 104 } 105 106 void resetPluginCache(bool reloadPages) 107 { 108 WebCore::Page::refreshPlugins(reloadPages); 109 } 110 111 } // namespace WebKit 112