OLD | NEW |
(Empty) | |
| 1 // Copyright 2013, 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 DartScriptState_h |
| 31 #define DartScriptState_h |
| 32 |
| 33 #include "bindings/core/v8/V8ScriptState.h" |
| 34 |
| 35 #include <dart_api.h> |
| 36 #include <v8.h> |
| 37 |
| 38 namespace blink { |
| 39 |
| 40 class DartScriptState : public ScriptState { |
| 41 WTF_MAKE_NONCOPYABLE(DartScriptState); |
| 42 public: |
| 43 static PassRefPtr<DartScriptState> create(Dart_Isolate isolate, intptr_t lib
raryId, V8ScriptState* v8ScriptState, const String& isolateName) |
| 44 { |
| 45 return adoptRef(new DartScriptState(isolate, libraryId, v8ScriptState, i
solateName)); |
| 46 } |
| 47 |
| 48 // Long term we want to be creating DartScriptStates without V8ScriptStates. |
| 49 static PassRefPtr<DartScriptState> create(Dart_Isolate isolate, intptr_t lib
raryId, const String& isolateName) |
| 50 { |
| 51 return adoptRef(new DartScriptState(isolate, libraryId, 0, isolateName))
; |
| 52 } |
| 53 |
| 54 bool isDartScriptState() const { return true; } |
| 55 V8ScriptState* v8ScriptState() |
| 56 { |
| 57 ASSERT(m_v8ScriptState); |
| 58 return m_v8ScriptState.get(); |
| 59 } |
| 60 |
| 61 LocalDOMWindow* domWindow() const { return m_v8ScriptState->domWindow(); } |
| 62 LocalDOMWindow* callingDOMWindow() const |
| 63 { |
| 64 // In Dart, the calling Window is always the same as the window of the |
| 65 // script as Dart does not expose bindings for cross frame DOM manipulat
ion. |
| 66 // FIXMEDART: If/when cross-frame bindings are made available this needs
to |
| 67 // be changed. Note that we cannot rely on asking the V8 script state fo
r |
| 68 // the calling window (it can differ or be invalid during a navigation). |
| 69 return domWindow(); |
| 70 } |
| 71 |
| 72 ExecutionContext* executionContext() const { return m_v8ScriptState->executi
onContext(); } |
| 73 bool evalEnabled() const { return m_v8ScriptState->evalEnabled(); } |
| 74 void setEvalEnabled(bool flag) { m_v8ScriptState->setEvalEnabled(flag); } |
| 75 bool contextIsValid() const; |
| 76 PassRefPtr<AbstractScriptValue> createNull(); |
| 77 PassRefPtr<AbstractScriptValue> createUndefined(); |
| 78 PassRefPtr<AbstractScriptValue> createBoolean(bool); |
| 79 PassRefPtr<AbstractScriptPromise> createEmptyPromise(); |
| 80 PassRefPtr<AbstractScriptPromise> createRejectedPromise(PassRefPtrWillBeRawP
tr<DOMException>); |
| 81 PassRefPtr<AbstractScriptPromise> createPromiseRejectedWithTypeError(const S
tring& message); |
| 82 virtual PassOwnPtr<AbstractScriptPromiseResolver> createPromiseResolver(Scri
ptPromiseResolver*); |
| 83 AbstractScriptStateProtectingContext* createProtectingContext(); |
| 84 PassRefPtr<AbstractScriptValue> idbAnyToScriptValue(IDBAny*); |
| 85 PassRefPtr<AbstractScriptValue> idbKeyToScriptValue(IDBKey*); |
| 86 |
| 87 Dart_Isolate isolate() { return m_isolate; } |
| 88 virtual intptr_t libraryId() { return m_libraryId; } |
| 89 |
| 90 virtual const String* name() { return &m_name; } |
| 91 virtual bool isJavaScript() { return false; } |
| 92 |
| 93 #ifndef NDEBUG |
| 94 void assertPrimaryKeyValidOrInjectable(PassRefPtr<SharedBuffer>, const Vecto
r<blink::WebBlobInfo>*, IDBKey*, const IDBKeyPath&); |
| 95 #endif |
| 96 |
| 97 private: |
| 98 explicit DartScriptState(Dart_Isolate, intptr_t libraryId, V8ScriptState*, c
onst String& isolateName); |
| 99 ~DartScriptState() { } |
| 100 |
| 101 Dart_Isolate m_isolate; |
| 102 intptr_t m_libraryId; |
| 103 String m_name; |
| 104 RefPtr<V8ScriptState> m_v8ScriptState; |
| 105 }; |
| 106 |
| 107 } |
| 108 |
| 109 #endif // DartScriptState_h |
OLD | NEW |