OLD | NEW |
(Empty) | |
| 1 // Copyright 2011, Google Inc. |
| 2 // 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 #ifndef DartController_h |
| 31 #define DartController_h |
| 32 |
| 33 #include "bindings/core/v8/ScriptSourceCode.h" |
| 34 #include "wtf/Deque.h" |
| 35 #include "wtf/HashMap.h" |
| 36 #include "wtf/Vector.h" |
| 37 #include "wtf/text/WTFString.h" |
| 38 |
| 39 #include <dart_api.h> |
| 40 #include <v8.h> |
| 41 |
| 42 struct NPObject; |
| 43 |
| 44 namespace blink { |
| 45 |
| 46 class DartApplicationLoader; |
| 47 class DartDOMData; |
| 48 class DartScriptInfo; |
| 49 class DartScriptState; |
| 50 class Document; |
| 51 class ExecutionContext; |
| 52 class LocalDOMWindow; |
| 53 class LocalFrame; |
| 54 class ScriptLoader; |
| 55 class ScriptState; |
| 56 class V8ScriptState; |
| 57 |
| 58 typedef HashMap<intptr_t, RefPtr<DartScriptState> > LibraryIdMap; |
| 59 typedef HashMap<Dart_Isolate, LibraryIdMap*> ScriptStatesMap; |
| 60 |
| 61 // This class provides the linkage between a LocalFrame and its attached |
| 62 // Dart isolates. It is similar to ScriptController for JavaScript. |
| 63 // The DartController is owned by its LocalFrame. |
| 64 class DartController { |
| 65 public: |
| 66 DartController(LocalFrame*); |
| 67 virtual ~DartController(); |
| 68 |
| 69 void evaluate(const ScriptSourceCode&, ScriptLoader* = 0); |
| 70 |
| 71 // Exposes NPObject instance to Dart environment. |
| 72 void bindToWindowObject(LocalFrame*, const String& key, NPObject*); |
| 73 NPObject* npObject(const String& key); |
| 74 |
| 75 void clearWindowShell(); |
| 76 void clearScriptObjects(); |
| 77 |
| 78 Dart_Handle callFunction(Dart_Handle function, int argc, Dart_Handle* argv); |
| 79 |
| 80 LocalFrame* frame() const { return m_frame; } |
| 81 void collectScriptStates(V8ScriptState*, Vector<DartScriptState*>& result); |
| 82 void collectScriptStatesForIsolate(Dart_Isolate, v8::Handle<v8::Context> v8C
ontext, Vector<DartScriptState*>& result); |
| 83 DartScriptState* lookupScriptState(Dart_Isolate, v8::Handle<v8::Context> v8C
ontext, intptr_t libraryId); |
| 84 |
| 85 static DartController* retrieve(LocalFrame*); |
| 86 static DartController* retrieve(ExecutionContext*); |
| 87 |
| 88 bool isActive() { return !m_isolates.isEmpty(); } |
| 89 |
| 90 void spawnDomUri(const String& uri); |
| 91 void spawnHelperDomIsolate(const String& libraryUrl, const String& entryPoin
t, DartDOMData* parentDOMData, Dart_Port replyTo); |
| 92 |
| 93 private: |
| 94 const char* ExpirationMessage = "This version of Dartium has expired.\n\n" |
| 95 "Please download the latest version at https://www.dartlang.org/tools/da
rtium"; |
| 96 |
| 97 static void initVMIfNeeded(); |
| 98 |
| 99 static Dart_Isolate createIsolate(const char* scriptURL, const char* entryPo
int, const char* packageRoot, Dart_IsolateFlags*, |
| 100 Document*, bool isDOMEnabled, bool isDebuggerEnabled, char** errorMessag
e); |
| 101 void shutdownIsolate(Dart_Isolate); |
| 102 |
| 103 Dart_Isolate createDOMEnabledIsolate(const String& scriptURL, const String&
entryPoint, const char* packageRoot, Document*); |
| 104 void scheduleScriptExecution(const String&, Dart_Isolate, PassRefPtr<DartScr
iptInfo>); |
| 105 void loadAndRunScript(const String&, Dart_Isolate, PassRefPtr<DartScriptInfo
>); |
| 106 static void shutdownIsolateCallback(void* data); |
| 107 static Dart_Isolate createPureIsolateCallback(const char* prefix, const char
* main, const char* packageRoot, Dart_IsolateFlags*, void* callbackData, char**
errorMsg); |
| 108 |
| 109 static void weakCallback(void* isolateCallbackData, Dart_WeakPersistentHandl
e, void* peer); |
| 110 |
| 111 LibraryIdMap* libraryIdMapForIsolate(Dart_Isolate); |
| 112 DartScriptState* lookupScriptStateFromLibraryIdMap(Dart_Isolate, v8::Handle<
v8::Context>, LibraryIdMap*, intptr_t libraryId); |
| 113 |
| 114 String isolateName(Dart_Isolate); |
| 115 // The frame that owns this controller. |
| 116 LocalFrame* m_frame; |
| 117 |
| 118 // Isolate associated with scripts in this document. |
| 119 Vector<Dart_Isolate> m_isolates; |
| 120 typedef HashMap<Dart_Isolate, RefPtr<DartApplicationLoader> > DartApplicatio
nLoaderMap; |
| 121 |
| 122 DartApplicationLoaderMap m_loaders; |
| 123 RefPtr<DartApplicationLoader> m_mainLoader; |
| 124 HashMap<Dart_Isolate, String> m_isolateNames; |
| 125 HashSet<String> m_usedNames; |
| 126 |
| 127 ScriptStatesMap m_scriptStates; |
| 128 |
| 129 typedef HashMap<String, NPObject*> NPObjectMap; |
| 130 NPObjectMap m_npObjectMap; |
| 131 |
| 132 friend class DartDomLoadCallback; |
| 133 friend class DartScriptRunner; |
| 134 friend class DartService; |
| 135 }; |
| 136 |
| 137 } |
| 138 |
| 139 #endif // DartController_h |
OLD | NEW |