| Index: Source/WebCore/bindings/dart/DartController.cpp
|
| diff --git a/Source/WebCore/bindings/dart/DartController.cpp b/Source/WebCore/bindings/dart/DartController.cpp
|
| deleted file mode 100644
|
| index 90e1511ef536407c97502caf801010c302d3787d..0000000000000000000000000000000000000000
|
| --- a/Source/WebCore/bindings/dart/DartController.cpp
|
| +++ /dev/null
|
| @@ -1,418 +0,0 @@
|
| -// Copyright (c) 2009, Google Inc.
|
| -// All rights reserved.
|
| -//
|
| -// Redistribution and use in source and binary forms, with or without
|
| -// modification, are permitted provided that the following conditions are
|
| -// met:
|
| -//
|
| -// * Redistributions of source code must retain the above copyright
|
| -// notice, this list of conditions and the following disclaimer.
|
| -// * Redistributions in binary form must reproduce the above
|
| -// copyright notice, this list of conditions and the following disclaimer
|
| -// in the documentation and/or other materials provided with the
|
| -// distribution.
|
| -// * Neither the name of Google Inc. nor the names of its
|
| -// contributors may be used to endorse or promote products derived from
|
| -// this software without specific prior written permission.
|
| -//
|
| -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| -
|
| -#include "config.h"
|
| -#include "DartController.h"
|
| -
|
| -#include "DOMTimer.h"
|
| -#include "DOMWindow.h"
|
| -#include "DartApplicationLoader.h"
|
| -#include "DartBuiltinLibrarySource.h"
|
| -#include "DartClassInfo.h"
|
| -#include "DartDOMWindow.h"
|
| -#include "DartDOMWrapper.h"
|
| -#include "DartIsolateState.h"
|
| -#include "DartUtilities.h"
|
| -#include "Document.h"
|
| -#include "Frame.h"
|
| -#include "HTMLNames.h"
|
| -#include "HTMLScriptElement.h"
|
| -#include "IDBPendingTransactionMonitor.h"
|
| -#include "NodeList.h"
|
| -#include "Page.h"
|
| -#include "PageGroup.h"
|
| -#include "ScheduledAction.h"
|
| -#include "ScriptExecutionContext.h"
|
| -#include "Settings.h"
|
| -#include "StorageNamespace.h"
|
| -
|
| -#include "npruntime_impl.h"
|
| -#include <bindings/npruntime.h>
|
| -
|
| -namespace WebCore {
|
| -
|
| -static void initDOMIsolate()
|
| -{
|
| - DartApiScope dartApiScope;
|
| -
|
| - // Fix the dom library.
|
| - Dart_Handle dom = Dart_LookupLibrary(Dart_NewString(DartUtilities::domLibraryName));
|
| -
|
| - // Inject builtin library to forward core functionality to dom.
|
| - // FIXME: We need to provide something for non-DOM isolates as well.
|
| - Dart_Handle core = Dart_LookupLibrary(Dart_NewString("dart:core"));
|
| - Dart_LoadSource(core, Dart_NewString("dart:builtin"), Dart_NewString(dartBuiltinLibrarySource));
|
| - Dart_LibraryImportLibrary(core, dom);
|
| -
|
| - Dart_Handle domimpl = Dart_LookupLibrary(Dart_NewString("dart:domimpl"));
|
| - ASSERT(!Dart_IsError(domimpl));
|
| - Dart_SetNativeResolver(domimpl, domResolver);
|
| -}
|
| -
|
| -DartPerScriptState::DartPerScriptState(Document* document, PassRefPtr<DartApplicationLoader> applicationLoader)
|
| - : m_dartApplicationLoader(applicationLoader)
|
| - , m_isolate(DartIsolateState::create(document, m_dartApplicationLoader.get()))
|
| -{
|
| - initDOMIsolate();
|
| - isolateToDartApplicationLoaderMap().set(m_isolate, m_dartApplicationLoader.get());
|
| - // DartIsolateState::create pushes newly create isolate, undo it.
|
| - DartIsolateState::pop();
|
| -}
|
| -
|
| -DartPerScriptState::~DartPerScriptState()
|
| -{
|
| - *DartUtilities::recursionForIsolate(m_isolate) = 0;
|
| - isolateToDartApplicationLoaderMap().remove(m_isolate);
|
| - DartIsolateState::shutdown(m_isolate);
|
| -}
|
| -
|
| -DartController::DartController(Frame* frame)
|
| - : m_frame(frame)
|
| - , m_scriptsLoaded(false)
|
| - , m_states()
|
| - , m_npObjectMap()
|
| -{
|
| - // The DartController's constructor must be called in the Frame's
|
| - // constructor, so it can properly maintain the unit of related
|
| - // browsing contexts.
|
| -
|
| - // The DartController must be created after the frame's loader and
|
| - // tree nodes are initialized.
|
| - ASSERT(frame->loader());
|
| - ASSERT(frame->tree());
|
| -}
|
| -
|
| -void DartController::clearWindowShell()
|
| -{
|
| - m_scriptsLoaded = false;
|
| - m_states.clear();
|
| -}
|
| -
|
| -class PostMessageTask : public ScriptExecutionContext::Task {
|
| -public:
|
| - PostMessageTask(Dart_Isolate destinationIsolate, Dart_Port destinationPort, Dart_Port replyPort, Dart_Message message)
|
| - : m_destinationIsolate(destinationIsolate)
|
| - , m_destinationPort(destinationPort)
|
| - , m_replyPort(replyPort)
|
| - , m_message(message) { }
|
| -
|
| - ~PostMessageTask()
|
| - {
|
| - free(m_message);
|
| - }
|
| -
|
| - virtual void performTask(ScriptExecutionContext* context)
|
| - {
|
| - // FIXME: one shouldn't trust isFullDomIsolate as another
|
| - // isolate with the same address might be allocated. Apparently better
|
| - // way would be to maintain a way to tell all the tasks that they are
|
| - // cancelled from now on. For example, we may maintain a list of all
|
| - // pending tasks and iterate over it.
|
| - // destinationIsolate might have been shut down before.
|
| - if (!DartUtilities::isFullDomIsolate(m_destinationIsolate))
|
| - return;
|
| - DartIsolateState::Scope scope(m_destinationIsolate);
|
| - DartApiScope apiScope;
|
| - Dart_Handle result = Dart_HandleMessage(m_destinationPort, m_replyPort, m_message);
|
| - if (Dart_IsError(result))
|
| - DartUtilities::reportProblem(context, result);
|
| - }
|
| -
|
| -private:
|
| - Dart_Isolate m_destinationIsolate;
|
| - Dart_Port m_destinationPort;
|
| - Dart_Port m_replyPort;
|
| - Dart_Message m_message;
|
| -};
|
| -
|
| -static bool postMessageCallback(Dart_Isolate destinationIsolate, Dart_Port destinationPort, Dart_Port replyPort, Dart_Message message)
|
| -{
|
| - ASSERT(DartUtilities::isFullDomIsolate(destinationIsolate));
|
| - ScriptExecutionContext* destinationContext = DartUtilities::isolateContext(destinationIsolate);
|
| - destinationContext->postTask(adoptPtr(new PostMessageTask(destinationIsolate, destinationPort, replyPort, message)));
|
| - return true;
|
| -}
|
| -
|
| -static void closePortCallback(Dart_Isolate, Dart_Port)
|
| -{
|
| -}
|
| -
|
| -void DartController::setupDOMEnabledIsolate(ScriptExecutionContext* context)
|
| -{
|
| - ASSERT(context);
|
| - Dart_SetMessageCallbacks(&postMessageCallback, &closePortCallback);
|
| - DartUtilities::registerIsolateContext(Dart_CurrentIsolate(), context);
|
| -}
|
| -
|
| -bool DartController::createPureIsolateCallback(void* data, char** errorMsg)
|
| -{
|
| - Dart_Isolate isolate = Dart_CreateIsolate(DartUtilities::fullSnapshot(), data, errorMsg);
|
| - if (!isolate)
|
| - return false;
|
| -
|
| - DartApiScope dartApiScope;
|
| - // It's safe to initialize DOM for pure Dart isolates: unless Dart isolate is
|
| - // registered with DartUtilities::registerIsolatecContext, its DOM functionality
|
| - // will be disabled: we won't be able to resolve top level accessors.
|
| - initDOMIsolate();
|
| -
|
| - DartApplicationLoader* dartApplicationLoader = reinterpret_cast<DartApplicationLoader*>(data);
|
| - // FIXME: when DartVM has shutdown callback, we'll be able to deref it.
|
| - dartApplicationLoader->ref();
|
| - ASSERT(!dartApplicationLoader->isLoadingMainIsolate());
|
| - dartApplicationLoader->reinjectSources();
|
| -
|
| - return true;
|
| -}
|
| -
|
| -void DartController::initVMIfNeeded()
|
| -{
|
| - static bool hasBeenInitialized = false;
|
| - if (hasBeenInitialized)
|
| - return;
|
| -
|
| - // FIXME: make sure Dart_SetVMFlags is called even if there was no
|
| - // --dart-flags command line switch.
|
| - Dart_SetVMFlags(0, 0);
|
| - Dart_Initialize(&createPureIsolateCallback, 0);
|
| - hasBeenInitialized = true;
|
| -}
|
| -
|
| -bool DartController::isDartMimeType(const String& mimeType)
|
| -{
|
| - DEFINE_STATIC_LOCAL(HashSet<String>, types, ());
|
| - if (types.isEmpty()) {
|
| - types.add("application/dart");
|
| - types.add("application/dart-app");
|
| - types.add("application/dart-script");
|
| - }
|
| - return !mimeType.isEmpty() && types.contains(mimeType);
|
| -}
|
| -
|
| -
|
| -class DartScriptRunner : public EventListener {
|
| -public:
|
| - static PassRefPtr<DartScriptRunner> create()
|
| - {
|
| - return adoptRef(new DartScriptRunner());
|
| - }
|
| -
|
| - virtual void handleEvent(ScriptExecutionContext* context, Event*)
|
| - {
|
| - ASSERT(context->isDocument());
|
| - Document* document = static_cast<Document*>(context);
|
| -
|
| - // this gets removed below, so protect it while handler runs.
|
| - RefPtr<DartScriptRunner> protect = this;
|
| - document->domWindow()->removeEventListener(String("DOMContentLoaded"), this, false);
|
| -
|
| - DartController::retrieve(context)->loadScripts();
|
| - }
|
| -
|
| - virtual bool operator==(const EventListener& other)
|
| - {
|
| - return this == &other;
|
| - }
|
| -
|
| -private:
|
| - DartScriptRunner()
|
| - : EventListener(EventListener::NativeEventListenerType)
|
| - {
|
| - }
|
| -};
|
| -
|
| -void DartController::evaluate(const ScriptSourceCode& sourceCode)
|
| -{
|
| - if (!m_scriptsLoaded) {
|
| - m_scriptsLoaded = true;
|
| - // FIXME: We defer loading Dart scripts until document is fully parsed to make
|
| - // sure DartController::loadScripts will find all the script tags in document.
|
| - // To make startup faster, we should start loading Dart scripts immediately.
|
| - Document* document = m_frame->document();
|
| - if (document->readyState() == "loading")
|
| - document->domWindow()->addEventListener(String("DOMContentLoaded"), DartScriptRunner::create(), false);
|
| - else
|
| - loadScripts();
|
| - }
|
| -}
|
| -
|
| -
|
| -void DartController::loadScripts()
|
| -{
|
| - initVMIfNeeded();
|
| -
|
| - Vector<RefPtr<HTMLScriptElement> > dartScripts;
|
| - RefPtr<NodeList> scripts = m_frame->document()->getElementsByTagName("script");
|
| - for (unsigned i = 0; i < scripts->length(); ++i) {
|
| - Node* scriptNode = scripts->item(i);
|
| - HTMLScriptElement* scriptElement = static_cast<HTMLScriptElement*>(scriptNode);
|
| - String typeAttr = scriptElement->getAttribute(HTMLNames::typeAttr).string();
|
| - if (isDartMimeType(typeAttr.stripWhiteSpace().lower()))
|
| - dartScripts.append(scriptElement);
|
| - }
|
| - Document* document = frame()->document();
|
| - for (size_t i = 0; i < dartScripts.size(); ++i) {
|
| - RefPtr<HTMLScriptElement> scriptElement = dartScripts.at(i);
|
| -
|
| - // FIXME: it may make sense to ensure that we'll never call evaluate more than once for the same script tag.
|
| - DartPerScriptState* state = new DartPerScriptState(document, adoptRef(new DartApplicationLoader(document)));
|
| - ASSERT(state->isolate());
|
| - m_states.append(adoptPtr(state));
|
| -
|
| - DartIsolateState::Scope scope(state->isolate());
|
| - if (scriptElement->src().isEmpty())
|
| - state->dartApplicationLoader()->load(m_frame->document()->url(), scriptElement->scriptContent());
|
| - else
|
| - state->dartApplicationLoader()->loadScriptResource(scriptElement->src());
|
| - }
|
| -}
|
| -
|
| -void DartController::bindToWindowObject(Frame* frame, const String& key, NPObject* object)
|
| -{
|
| - // FIXME: proper management of lifetime.
|
| - m_npObjectMap.set(key, object);
|
| -}
|
| -
|
| -NPObject* DartController::npObject(const String& key)
|
| -{
|
| - return m_npObjectMap.get(key);
|
| -}
|
| -
|
| -Dart_Handle DartController::callFunction(Dart_Handle function, int argc, Dart_Handle* argv)
|
| -{
|
| - // FIXME: Introduce Dart variant of V8GCController::checkMemoryUsage();
|
| - const int kMaxRecursionDepth = 22;
|
| -
|
| - int* recursion = DartUtilities::recursionForCurrentIsolate();
|
| -
|
| - if (*recursion >= kMaxRecursionDepth)
|
| - return Dart_Error("Maximum call stack size exceeded");
|
| -
|
| - // FIXME: implement InspectorInstrumentationCookie stuff a la v8.
|
| - (*recursion)++;
|
| - Dart_Handle result = Dart_InvokeClosure(function, argc, argv);
|
| - (*recursion)--;
|
| -
|
| - // Release the storage mutex if applicable.
|
| - didLeaveScriptContext(*recursion);
|
| -
|
| - // Handle fatal error in Dart VM a la v8.
|
| -
|
| - return result;
|
| -}
|
| -
|
| -class StartIsolateAction : public ScheduledAction {
|
| -public:
|
| - StartIsolateAction(Dart_Isolate isolate, const String& mainLibURL, const String& entryPoint)
|
| - : ScheduledAction(v8::Handle<v8::Context>(), String())
|
| - , m_isolate(isolate)
|
| - , m_mainLibURL(mainLibURL)
|
| - , m_entryPoint(entryPoint)
|
| - { }
|
| -
|
| - virtual void execute(ScriptExecutionContext* context)
|
| - {
|
| - DartIsolateState::Scope scope(m_isolate);
|
| - DartApiScope apiScope;
|
| -
|
| - Dart_Port mainPort = Dart_GetMainPortId();
|
| - Dart_Handle port = Dart_GetReceivePort(mainPort);
|
| - if (Dart_IsError(port))
|
| - DartUtilities::reportProblem(context, port);
|
| -
|
| - Dart_Handle mainLib = Dart_LookupLibrary(DartUtilities::stringToDartString(m_mainLibURL));
|
| - if (Dart_IsError(mainLib))
|
| - DartUtilities::reportProblem(context, mainLib);
|
| -
|
| - Dart_Handle result = Dart_InvokeStatic(
|
| - mainLib,
|
| - Dart_NewString(""),
|
| - DartUtilities::stringToDartString(m_entryPoint),
|
| - 1, &port);
|
| - // FIXME: consider communicating exceptions back to parent isolate somehow.
|
| - if (Dart_IsError(result))
|
| - DartUtilities::reportProblem(context, result);
|
| - }
|
| -
|
| -private:
|
| - Dart_Isolate m_isolate;
|
| - const String m_mainLibURL;
|
| - const String m_entryPoint;
|
| -};
|
| -
|
| -Dart_Handle DartController::spawnDomIsolate(DOMWindow* targetWindow, const String& entryPoint)
|
| -{
|
| - Dart_Isolate parentIsolate = Dart_CurrentIsolate();
|
| -
|
| - RefPtr<DartApplicationLoader> applicationLoader = isolateToDartApplicationLoaderMap().get(parentIsolate);
|
| - ASSERT(applicationLoader);
|
| -
|
| - Dart_Isolate childIsolate;
|
| - Dart_Port childIsolatePort;
|
| - {
|
| - DartPerScriptState* state = new DartPerScriptState(targetWindow->document(), applicationLoader);
|
| - m_states.append(adoptPtr(state)); // FIXME: should we add to m_states? Should navigation clear it?
|
| - childIsolate = state->isolate();
|
| -
|
| - DartIsolateState::Scope scope(childIsolate);
|
| - DartApiScope apiScope;
|
| - applicationLoader->reinjectSources();
|
| - childIsolatePort = Dart_GetMainPortId();
|
| - }
|
| -
|
| - Dart_Handle sendPort = Dart_NewSendPort(childIsolatePort);
|
| - if (Dart_IsError(sendPort))
|
| - return sendPort;
|
| -
|
| - OwnPtr<StartIsolateAction> action = adoptPtr(new StartIsolateAction(childIsolate, applicationLoader->mainLibraryURL(), entryPoint));
|
| - DOMTimer::install(m_frame->document(), action.release(), 0, true);
|
| -
|
| - return sendPort;
|
| -}
|
| -
|
| -void DartController::didLeaveScriptContext(int recursion)
|
| -{
|
| - // FIXME: implement this.
|
| -}
|
| -
|
| -DartController* DartController::retrieve(Frame* frame)
|
| -{
|
| - if (!frame)
|
| - return 0;
|
| - return frame->script()->scriptControllerDelegate();
|
| -}
|
| -
|
| -DartController* DartController::retrieve(ScriptExecutionContext* context)
|
| -{
|
| - if (!context || !context->isDocument())
|
| - return 0;
|
| - return retrieve(static_cast<Document*>(context)->frame());
|
| -}
|
| -
|
| -}
|
|
|