From 34f1757f5f256761a8c6c3371a17f7ab9f208fcb Mon Sep 17 00:00:00 2001 From: dli Date: Sun, 3 Jun 2018 21:34:51 +0800 Subject: [PATCH] update plugin module for iOS support addEventListener --- Core/content/lynx_thread.h | 23 ++ Core/content/lynx_thread_impl.cc | 52 +++ Core/plugin/base/ios/plugin_builder.mm | 19 -- Core/plugin/base/ios/plugin_impl.h | 21 +- Core/plugin/base/ios/plugin_impl.mm | 86 +++-- Core/plugin/base/plugin.cc | 12 +- Core/plugin/base/plugin.h | 29 +- Core/plugin/base/plugin_builder.h | 13 - Core/plugin/base/plugin_manager.cc | 70 ---- Core/plugin/base/plugin_manager.h | 33 -- Core/plugin/impl/clipboard/clipboard.js | 12 +- .../impl/clipboard/ios/clipboard_plugin.h | 9 + .../impl/clipboard/ios/clipboard_plugin.mm | 36 ++ Core/plugin/impl/exec.js | 40 +++ Core/plugin/impl/main.js | 3 + .../impl/net_info/ios/net_info_plugin.h | 8 +- .../impl/net_info/ios/net_info_plugin.mm | 60 ++-- Core/plugin/impl/net_info/netinfo.js | 16 +- Core/plugin/impl/plugin.js | 91 +++++ Core/plugin/plugin.js | 26 -- Core/plugin/plugin_client.cc | 96 ++++++ Core/plugin/plugin_client.h | 43 +++ Core/plugin/plugin_server.h | 35 ++ Core/plugin/plugin_server_impl.cc | 248 ++++++++++++++ Core/render/event_target.cc | 4 +- Core/runtime/base/lynx_array.cc | 130 +++---- Core/runtime/base/lynx_array.h | 43 ++- Core/runtime/base/lynx_value.cc | 138 ++++---- Core/runtime/base/lynx_value.h | 319 +++++++++--------- Core/runtime/global.cc | 4 +- Core/runtime/global.h | 6 +- Core/runtime/js/js_vm.h | 24 +- Core/runtime/jsc/js_vm.cc | 11 +- Core/runtime/runtime.cc | 13 +- Core/runtime/runtime.h | 2 + Core/runtime/v8/js_vm.cc | 43 +-- iOS/assets.bundle/homedemo/index.html | 4 +- iOS/assets.bundle/homedemo/plugin_test.js | 7 + iOS/assets.bundle/manifest.json | 2 +- iOS/assets.bundle/plugin.js | 91 +++++ iOS/lynx.xcodeproj/project.pbxproj | 74 ++-- iOS/lynx/app_delegate.mm | 7 + 42 files changed, 1391 insertions(+), 612 deletions(-) create mode 100644 Core/content/lynx_thread.h create mode 100644 Core/content/lynx_thread_impl.cc delete mode 100644 Core/plugin/base/ios/plugin_builder.mm delete mode 100644 Core/plugin/base/plugin_builder.h delete mode 100644 Core/plugin/base/plugin_manager.cc delete mode 100644 Core/plugin/base/plugin_manager.h create mode 100644 Core/plugin/impl/clipboard/ios/clipboard_plugin.h create mode 100644 Core/plugin/impl/clipboard/ios/clipboard_plugin.mm create mode 100644 Core/plugin/impl/exec.js create mode 100644 Core/plugin/impl/main.js create mode 100644 Core/plugin/impl/plugin.js delete mode 100644 Core/plugin/plugin.js create mode 100644 Core/plugin/plugin_client.cc create mode 100644 Core/plugin/plugin_client.h create mode 100644 Core/plugin/plugin_server.h create mode 100644 Core/plugin/plugin_server_impl.cc create mode 100644 iOS/assets.bundle/homedemo/plugin_test.js diff --git a/Core/content/lynx_thread.h b/Core/content/lynx_thread.h new file mode 100644 index 00000000..e916d2dc --- /dev/null +++ b/Core/content/lynx_thread.h @@ -0,0 +1,23 @@ +// Copyright 2017 The Lynx Authors. All rights reserved. + +#ifndef LYNX_CORE_CONTENT_LYNX_THREAD_H_ +#define LYNX_CORE_CONTENT_LYNX_THREAD_H_ + +#include "base/threading/thread.h" + +namespace content { + class LynxThread { + public: + enum ID { + UI, + IO, + JS, + PLUGIN, + ID_COUNT, + }; + static void Initialize(); + static void PostTask(ID identifier, base::Closure* task); + }; +} // namespace content + +#endif // LYNX_CORE_CONTENT_LYNX_THREAD_H_ diff --git a/Core/content/lynx_thread_impl.cc b/Core/content/lynx_thread_impl.cc new file mode 100644 index 00000000..0bf8ca01 --- /dev/null +++ b/Core/content/lynx_thread_impl.cc @@ -0,0 +1,52 @@ +// Copyright 2017 The Lynx Authors. All rights reserved. + +#include "content/lynx_thread.h" +#include "base/lazy_instance.h" + +namespace content { + +namespace { + static const char* g_lynx_thread_names[LynxThread::ID_COUNT] = { + "", + "Lynx_IOThread", + "Lynx_JSThread", + "Lynx_PluginThread", + }; + + static const base::MessageLoop::MESSAGE_LOOP_TYPE g_lynx_thread_loop_type[LynxThread::ID_COUNT] = { + base::MessageLoop::MESSAGE_LOOP_NONE, + base::MessageLoop::MESSAGE_LOOP_NONE, + base::MessageLoop::MESSAGE_LOOP_NONE, + base::MessageLoop::MESSAGE_LOOP_POSIX, + }; + + class ThreadManager { + public: + void Initialize() { + for(int i = 0; i < LynxThread::ID_COUNT; ++i) { + if(g_lynx_thread_loop_type[i] != base::MessageLoop::MESSAGE_LOOP_NONE) { + threads[i] = lynx_new base::Thread(g_lynx_thread_loop_type[i], g_lynx_thread_names[i]); + threads[i]->Start(); + } + } + } + void PostTask(LynxThread::ID identifier, base::Closure* task) { + threads[identifier]->Looper()->PostTask(task); + } + private: + base::Thread* threads[LynxThread::ID_COUNT]; + }; + + base::LazyInstance g_thread_manager; +} + +void LynxThread::Initialize() { + g_thread_manager.Get()->Initialize(); +} + +void LynxThread::PostTask(ID identifier, base::Closure* task) { + g_thread_manager.Get()->PostTask(identifier, task); +} + +} + diff --git a/Core/plugin/base/ios/plugin_builder.mm b/Core/plugin/base/ios/plugin_builder.mm deleted file mode 100644 index 86e8fe68..00000000 --- a/Core/plugin/base/ios/plugin_builder.mm +++ /dev/null @@ -1,19 +0,0 @@ -// -// plugin_register.m -// lynx -// -// Created by dli on 2018/5/20. -// Copyright © 2018年 lynx. All rights reserved. -// - - -#include "plugin/base/plugin_manager.h" -#include "plugin/base/plugin_builder.h" - -#import "plugin/impl/net_info/ios/net_info_plugin.h" - -namespace plugin { - void PluginBuilder::build(PluginManager* manager) { - [NetInfoPlugin createWithManager:manager]; - } -} diff --git a/Core/plugin/base/ios/plugin_impl.h b/Core/plugin/base/ios/plugin_impl.h index 48fc9a70..4c9b5940 100644 --- a/Core/plugin/base/ios/plugin_impl.h +++ b/Core/plugin/base/ios/plugin_impl.h @@ -1,20 +1,19 @@ +// Copyright 2017 The Lynx Authors. All rights reserved. + #ifndef LYNX_PLUGIN_BASE_IOS_PLUGIN_MANAGER_H_ #define LYNX_PLUGIN_BASE_IOS_PLUGIN_MANAGER_H_ -#include "plugin/base/plugin.h" -#include "plugin/base/plugin_manager.h" - -@protocol PluginProtocol +#include -@required --(void) Exec:(NSArray*)args; - -@end +@interface LynxPlugin : NSObject +@property (atomic, readwrite)NSString* pluginName; +-(void) exec:(NSInteger)clientId argments:(NSArray*)args; +-(void) returnBack:(NSInteger)clientId method:(NSNumber*)methodId successed:(Boolean)successed argments:(NSArray*)args; +-(void) addEvent:(NSString*) event; +-(void) removeEvent:(NSString*) event; +-(void) dispatchEvent:(NSString*) event argments:(NSArray*)args; -@interface LynxPlugin : NSObject --(id) initWithName:(NSString*)name pluginManager:(plugin::PluginManager*)manager; --(void) Return:(NSNumber*) methodId resultType:(plugin::Plugin::ResultType)type argments:(NSArray*)args; @end #endif // LYNX_PLUGIN_BASE_IOS_PLUGIN_MANAGER_H_ diff --git a/Core/plugin/base/ios/plugin_impl.mm b/Core/plugin/base/ios/plugin_impl.mm index 07600f99..36ebfc7d 100644 --- a/Core/plugin/base/ios/plugin_impl.mm +++ b/Core/plugin/base/ios/plugin_impl.mm @@ -1,58 +1,88 @@ +// Copyright 2017 The Lynx Authors. All rights reserved. + #include "plugin/base/plugin.h" +#include "plugin/plugin_server.h" + #include "plugin/base/ios/plugin_impl.h" -#include "plugin/base/plugin_manager.h" #include "base/log/logging.h" #include "base/ios/oc_helper.h" #include +#include -namespace plugin { - class PluginImpl : public Plugin { - public: - PluginImpl(const char* name, PluginManager* manager, LynxPlugin* instance) : Plugin(manager), instance_(instance){ - manager->Register(name, this); - } - - virtual void Exec(base::ScopedPtr args) { - NSArray* array = base::ios::OCHelper::ConvertToOCArray(args.Get()); - [instance_ Exec:array]; - } - - private: - LynxPlugin* instance_; - }; -} @implementation LynxPlugin { plugin::Plugin* delegate_; } --(id) initWithName:(NSString*)name pluginManager:(plugin::PluginManager*)manager { - self = [super init]; - if(self != nil) { - delegate_ = new plugin::PluginImpl([name UTF8String], manager, self); - } - return self; +-(void) setDelegate:(plugin::Plugin*) delegate { + delegate_ = delegate; } --(void) Exec:(NSArray*)args { - NSString* methodName = [NSString stringWithFormat:@"%@:arguments:", [args objectAtIndex:1]]; +-(void) exec:(NSInteger)clientId argments:(NSArray*)args { + NSString* methodName = [NSString stringWithFormat:@"%@:method:arguments:", [args objectAtIndex:1]]; SEL normalSelector = NSSelectorFromString(methodName); if ([self respondsToSelector:normalSelector]) { - ((void (*)(id, SEL, id, id))objc_msgSend)(self, normalSelector, [args objectAtIndex:2], [args objectAtIndex:3]); + ((void (*)(id, SEL, NSInteger, id, id))objc_msgSend)(self, normalSelector, clientId, [args objectAtIndex:2], [args objectAtIndex:3]); } else { NSLog(@"ERROR: Method '%@' not defined in Plugin '%@'", methodName, [args objectAtIndex:0]); } } --(void) Return:(NSNumber*) methodId resultType:(plugin::Plugin::ResultType)type argments:(NSArray*)args { +-(void) returnBack:(NSInteger)clientId method:(NSNumber*) method successed:(Boolean)successed argments:(NSArray*)args { base::ScopedPtr array = base::ios::OCHelper::ConvertToLynxArray(args); - delegate_->Return([methodId intValue], type, array); + delegate_->Return(clientId, [method intValue], successed, array); +} + +-(void) addEvent:(NSString*) event { + NSLog(@"ERROR: AddEvent not implement in Plugin '%@'", _pluginName); } +-(void) removeEvent:(NSString*) event { + NSLog(@"ERROR: RemoveEvent not implement in Plugin '%@'", _pluginName); +} +-(void) dispatchEvent:(NSString*) event argments:(NSArray*)args { + base::ScopedPtr array = base::ios::OCHelper::ConvertToLynxArray(args); + std::string plugin_name([_pluginName UTF8String]); + std::string plugin_event([event UTF8String]); + delegate_->DispatchEvent(plugin_name, plugin_event, array); +} @end +namespace plugin { + class PluginImpl : public Plugin { + public: + PluginImpl(){} + virtual ~PluginImpl() {} + PluginImpl(LynxPlugin* instance) : Plugin(), instance_(instance){ + [instance_ setDelegate:this]; + } + + virtual void Exec(long client_id, base::ScopedPtr args) { + NSArray* array = base::ios::OCHelper::ConvertToOCArray(args.Get()); + [instance_ exec:client_id argments:array]; + } + + virtual void AddEvent(const std::string& event) { + [instance_ addEvent:[NSString stringWithUTF8String:event.c_str()]]; + } + + virtual void RemoveEvent(const std::string& event) { + [instance_ removeEvent:[NSString stringWithUTF8String:event.c_str()]]; + } + private: + LynxPlugin* instance_; + }; + + Plugin* Plugin::Create(const std::string &name) { + NSString* plugin_clazz_name = [NSString stringWithFormat:@"%@Plugin", [NSString stringWithUTF8String:name.c_str()]]; + Class clazz = NSClassFromString(plugin_clazz_name); + LynxPlugin* lynx_plugin = [[clazz alloc] init]; + return new PluginImpl(lynx_plugin); + } +} + diff --git a/Core/plugin/base/plugin.cc b/Core/plugin/base/plugin.cc index c9196800..960d495b 100644 --- a/Core/plugin/base/plugin.cc +++ b/Core/plugin/base/plugin.cc @@ -1,9 +1,15 @@ +// Copyright 2017 The Lynx Authors. All rights reserved. + #include "plugin/base/plugin.h" -#include "plugin/base/plugin_manager.h" +#include "plugin/plugin_server.h" namespace plugin { - void Plugin::Return(int method_id, ResultType type, base::ScopedPtr args){ - manager_->Return(method_id, type, args); + void Plugin::Return(long client, int method, bool successed, base::ScopedPtr args) { + PluginServer::Return(client, method, successed, args); + } + + void Plugin::DispatchEvent(const std::string& name, const std::string& event, base::ScopedPtr args) { + PluginServer::DispatchEvent(name, event, args); } } diff --git a/Core/plugin/base/plugin.h b/Core/plugin/base/plugin.h index edd1e157..1e9eec9d 100644 --- a/Core/plugin/base/plugin.h +++ b/Core/plugin/base/plugin.h @@ -1,26 +1,33 @@ +// Copyright 2017 The Lynx Authors. All rights reserved. + #ifndef LYNX_PLUGIN_PLUGIN_H_ #define LYNX_PLUGIN_PLUGIN_H_ #include "runtime/base/lynx_value.h" #include "runtime/base/lynx_array.h" +#include "render/event_target.h" + +#include +#include + namespace plugin { class PluginManager; class Plugin { public: - enum ResultType { - ResultType_Fail, - ResultType_Success, - ResultType_Event - }; - Plugin(PluginManager* manager):manager_(manager){} + Plugin(){} virtual ~Plugin(){} - virtual void Exec(base::ScopedPtr args){} - void AddEventListener(base::ScopedPtr args){} - void Return(int method_id, ResultType type, base::ScopedPtr args); - private: - PluginManager* manager_; + virtual void Exec(long client, base::ScopedPtr args){} + void Return(long client_id, int method_id, bool successed, base::ScopedPtr args); + + virtual void AddEvent(const std::string& event) {} + virtual void RemoveEvent(const std::string& event) {} + void DispatchEvent(const std::string& name, const std::string& event, base::ScopedPtr args); + + static Plugin* Create(const std::string& name); + protected: + std::unordered_set register_events_; }; } diff --git a/Core/plugin/base/plugin_builder.h b/Core/plugin/base/plugin_builder.h deleted file mode 100644 index 31c04bc4..00000000 --- a/Core/plugin/base/plugin_builder.h +++ /dev/null @@ -1,13 +0,0 @@ - -#ifndef LYNX_PLUGIN_PLUGIN_BUILDER_H_ -#define LYNX_PLUGIN_PLUGIN_BUILDER_H_ - -namespace plugin { - class PluginManager; - class PluginBuilder { - public: - static void build(PluginManager* manager); - }; -} - -#endif diff --git a/Core/plugin/base/plugin_manager.cc b/Core/plugin/base/plugin_manager.cc deleted file mode 100644 index 2be2002d..00000000 --- a/Core/plugin/base/plugin_manager.cc +++ /dev/null @@ -1,70 +0,0 @@ -#include "plugin/base/plugin_manager.h" - -#include "plugin/base/plugin.h" -#include "runtime/base/lynx_value.h" -#include "runtime/base/lynx_array.h" -#include "runtime/js/class_template.h" - -#include "base/log/logging.h" - -#include "plugin/base/plugin_builder.h" - -namespace plugin { - - #define FOR_EACH_METHOD_BINDING(V) \ - V(PluginManager, Exec) \ - V(PluginManager, Init) \ - - // Defines methods and fields - FOR_EACH_METHOD_BINDING(DEFINE_METHOD_CALLBACK) - - // Defines default ClassTemplate - DEFINE_CLASS_TEMPLATE_START(PluginManager) - EXPOSE_CONSTRUCTOR(true) - FOR_EACH_METHOD_BINDING(REGISTER_METHOD_CALLBACK) - DEFINE_CLASS_TEMPLATE_END - - PluginManager::PluginManager(jscore::JSContext* context) : LynxObject(context, DEFAULT_CLASS_TEMPLATE(context)), context_(context){ - - } - - PluginManager::~PluginManager() { - - } - - void PluginManager::Register(const char* name, Plugin* plugin) { - plugins_.add(name, plugin); - } - - base::ScopedPtr PluginManager::Init(base::ScopedPtr& array) { - PluginBuilder::build(this); - callback_.Reset(array->Get(0)->data_.lynx_function); - return base::ScopedPtr(NULL); - } - - base::ScopedPtr PluginManager::Exec(base::ScopedPtr& array) { - std::string module_name(array->Get(0)->data_.str); - Plugins::iterator iter = plugins_.find(module_name); - if(iter == plugins_.end()) { - DLOG(ERROR) << ""; - return base::ScopedPtr(NULL); - } - iter->second->Exec(array); - return base::ScopedPtr(NULL); - } - - void PluginManager::Return(int method_id, Plugin::ResultType type, base::ScopedPtr& result){ - if(context_) { - context_->runtime()->thread_manager()->RunOnJSThread(base::Bind(&PluginManager::ReturnOnJSThread, - base::ScopedRefPtr(this), method_id, type, result)); - } - } - - void PluginManager::ReturnOnJSThread(int method_id, Plugin::ResultType type, base::ScopedPtr result) { - base::ScopedPtr args(lynx_new jscore::LynxArray); - args->Push(jscore::LynxValue::MakeInt(method_id).Release()); - args->Push(jscore::LynxValue::MakeInt(type).Release()); - args->Push(result.Release()); - callback_->Run(this, args.Get()); - } -} diff --git a/Core/plugin/base/plugin_manager.h b/Core/plugin/base/plugin_manager.h deleted file mode 100644 index 9cc12e48..00000000 --- a/Core/plugin/base/plugin_manager.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef LYNX_PLUGIN_PLUGIN_MANAGER_H_ -#define LYNX_PLUGIN_PLUGIN_MANAGER_H_ - -#include "runtime/base/lynx_object.h" -#include "runtime/runtime.h" -#include "base/scoped_ptr_map.h" -#include "plugin/base/plugin.h" - -namespace plugin { - - class PluginManager : public jscore::LynxObject { - public: - PluginManager(jscore::JSContext* context); - virtual ~PluginManager(); - - base::ScopedPtr Init(base::ScopedPtr& array); - base::ScopedPtr Exec(base::ScopedPtr& array); - void Return(int method_id, Plugin::ResultType type, base::ScopedPtr& result); - void Register(const char* name, Plugin* plugin); - private: - void ReturnOnJSThread(int method_id, Plugin::ResultType type, base::ScopedPtr result); - - typedef base::ScopedPtrMap Plugins; - Plugins plugins_; - - base::ScopedPtr callback_; - - jscore::JSContext* context_; - private: - DISALLOW_COPY_AND_ASSIGN(PluginManager); - }; -} -#endif diff --git a/Core/plugin/impl/clipboard/clipboard.js b/Core/plugin/impl/clipboard/clipboard.js index 5c01b28d..bf84b76e 100644 --- a/Core/plugin/impl/clipboard/clipboard.js +++ b/Core/plugin/impl/clipboard/clipboard.js @@ -1,9 +1,15 @@ +var exec = require('../exec').exec + var Clipboard = {} -Clipboard.getString = function(callback) { - exec('NetInfo', 'getString', [], callback, null) +Clipboard.getString = function() { + return new Promise((resolve, reject)=>{ + exec('Clipboard', 'getString', [], function(content){ resolve(content) }, null) + }); } Clipboard.setString = function(content) { - exec('NetInfo', 'setString', [content], null, null) + exec('Clipboard', 'setString', [content], null, null) } +module.exports = Clipboard + diff --git a/Core/plugin/impl/clipboard/ios/clipboard_plugin.h b/Core/plugin/impl/clipboard/ios/clipboard_plugin.h new file mode 100644 index 00000000..07f81ef2 --- /dev/null +++ b/Core/plugin/impl/clipboard/ios/clipboard_plugin.h @@ -0,0 +1,9 @@ +// Copyright 2017 The Lynx Authors. All rights reserved. + +#include "plugin/base/ios/plugin_impl.h" + +@interface ClipboardPlugin : LynxPlugin + +-(id) init; + +@end diff --git a/Core/plugin/impl/clipboard/ios/clipboard_plugin.mm b/Core/plugin/impl/clipboard/ios/clipboard_plugin.mm new file mode 100644 index 00000000..0cd4f211 --- /dev/null +++ b/Core/plugin/impl/clipboard/ios/clipboard_plugin.mm @@ -0,0 +1,36 @@ +// Copyright 2017 The Lynx Authors. All rights reserved. + +#import +#import + +#import "plugin/impl/clipboard/ios/clipboard_plugin.h" + +@implementation ClipboardPlugin + + +-(id) init { + self = [super init]; + if(self != nil) { + self.pluginName = @"Clipboard"; + } + return self; +} + + +-(void) getString:(NSInteger)clientId method:(NSNumber*)methodId arguments:(NSArray*) args { + dispatch_sync(dispatch_get_main_queue(), ^{ + UIPasteboard *clipboard = [UIPasteboard generalPasteboard]; + NSMutableArray* result = [[NSMutableArray alloc]init]; + [result addObject:(clipboard.string ? : @"")]; + [self returnBack:clientId method:methodId successed:true argments:result]; + }); +} + +-(void) setString:(NSInteger)clientId method:(NSNumber*)methodId arguments:(NSArray*) args { + dispatch_sync(dispatch_get_main_queue(), ^{ + UIPasteboard *clipboard = [UIPasteboard generalPasteboard]; + clipboard.string = ([args objectAtIndex:0] ? : @""); + }); +} + +@end diff --git a/Core/plugin/impl/exec.js b/Core/plugin/impl/exec.js new file mode 100644 index 00000000..fe25eae5 --- /dev/null +++ b/Core/plugin/impl/exec.js @@ -0,0 +1,40 @@ + +function exec(name, method, args, onSuccess, onFail) { + var callbackId = plugin.callbackId++ + if (onSuccess || onFail) { + plugin.callbacks[callbackId] = {success:onSuccess, fail:onFail}; + } + plugin.exec(name, method, callbackId, args) +} + +function addEventListener(name, method, callback) { + plugin.addEventListener(name, method, callback) +} + +function removeEventListener(name, method, callback) { + plugin.removeEventListener(name, method, callback) +} + +function callbackFromNative(callbackId, successed, args) { + + var callback = plugin.callbacks[callbackId]; + if (callback) { + if (successed) { + callback.success.apply(null, args); + } else { + callback.fail.apply(null, args); + } + delete plugin.callbacks[callbackId]; + } +} + +plugin.callbackId = 0 +plugin.callbacks = {} +plugin.init(callbackFromNative) + +var pluginExec = {} + +pluginExec.addEventListener = addEventListener +pluginExec.removeEventListener = removeEventListener +pluginExec.exec = exec +module.exports = pluginExec diff --git a/Core/plugin/impl/main.js b/Core/plugin/impl/main.js new file mode 100644 index 00000000..d17e255a --- /dev/null +++ b/Core/plugin/impl/main.js @@ -0,0 +1,3 @@ + +global.NetInfo = require('./net_info/netinfo') +global.Clipboard = require('./clipboard/clipboard') diff --git a/Core/plugin/impl/net_info/ios/net_info_plugin.h b/Core/plugin/impl/net_info/ios/net_info_plugin.h index 7e799085..7d03446c 100644 --- a/Core/plugin/impl/net_info/ios/net_info_plugin.h +++ b/Core/plugin/impl/net_info/ios/net_info_plugin.h @@ -1,11 +1,9 @@ -#include "plugin/base/ios/plugin_impl.h" +// Copyright 2017 The Lynx Authors. All rights reserved. -#include "plugin/base/plugin_manager.h" +#include "plugin/base/ios/plugin_impl.h" @interface NetInfoPlugin : LynxPlugin -@property (atomic, readwrite) NSString* networkStatus; - -+(void) createWithManager: (plugin::PluginManager*)manager; +-(id) init; @end diff --git a/Core/plugin/impl/net_info/ios/net_info_plugin.mm b/Core/plugin/impl/net_info/ios/net_info_plugin.mm index a213bf08..2cc41045 100644 --- a/Core/plugin/impl/net_info/ios/net_info_plugin.mm +++ b/Core/plugin/impl/net_info/ios/net_info_plugin.mm @@ -1,30 +1,19 @@ -// -// net_info_plugin.m -// lynx -// -// Created by dli on 2018/5/20. -// Copyright © 2018年 lynx. All rights reserved. -// +// Copyright 2017 The Lynx Authors. All rights reserved. #import #import #import #import "AFNetworkReachabilityManager.h" -#include "plugin/impl/net_info/ios/net_info_plugin.h" +#import "plugin/impl/net_info/ios/net_info_plugin.h" @implementation NetInfoPlugin -+(void) createWithManager: (plugin::PluginManager*)manager { - [[NetInfoPlugin alloc] initWithManager:manager]; -} - --(id) initWithManager: (plugin::PluginManager*)manager { - self = [super initWithName:@"NetInfo" pluginManager:manager]; +-(id) init { + self = [super init]; if(self != nil) { - self.networkStatus = @"unknown"; - [self startNetworkStatusObserver]; + self.pluginName = @"NetInfo"; } return self; } @@ -33,34 +22,55 @@ -(void) dealloc { [self stopNetworkStatusObserver]; } --(void) getConnectInfo: (NSNumber*)methodId arguments:(NSArray*) args { +-(void) getConnectInfo:(NSInteger)clientId method:(NSNumber*)methodId arguments:(NSArray*) args { + __weak typeof(self) weakSelf = self; dispatch_sync(dispatch_get_main_queue(), ^{ + __strong __typeof(weakSelf)strongSelf = weakSelf; NSMutableArray* result = [[NSMutableArray alloc]init]; - [result addObject:[self networkingStatesFromStatebar]]; - [self Return:methodId resultType:plugin::Plugin::ResultType_Success argments:result]; + [result addObject:[strongSelf networkingStatesFromStatebar] ? : @'unknown']; + [strongSelf returnBack:clientId method:methodId successed:true argments:result]; }); } --(void) startNetworkStatusObserver { +-(void) addEvent:(NSString*) event { + if([event isEqualToString:@"connectionChange"]) { + [self startNetworkStatusObserver:event]; + } + +} + +-(void) removeEvent:(NSString*) event { + if([event isEqualToString:@"connectionChange"]) { + [self stopNetworkStatusObserver]; + } +} + +-(void) startNetworkStatusObserver:(NSString*)event { AFNetworkReachabilityManager *mgr = [AFNetworkReachabilityManager sharedManager]; + __weak typeof(self) weakSelf = self; [mgr setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) { + NSString* networkStatus = nil; switch (status) { case AFNetworkReachabilityStatusUnknown://未知网络 - _networkStatus = @"unknown"; + networkStatus = @"unknown"; break; case AFNetworkReachabilityStatusNotReachable://没有网络(断网) - _networkStatus = @"none"; + networkStatus = @"none"; break; case AFNetworkReachabilityStatusReachableViaWWAN://手机自带网络 - _networkStatus = [self getCellularStates]; + networkStatus = [self getCellularStates]; break; case AFNetworkReachabilityStatusReachableViaWiFi:// WIFI - _networkStatus = @"wifi"; + networkStatus = @"wifi"; break; default: - _networkStatus = @"unknown"; + networkStatus = @"unknown"; break; } + __strong __typeof(weakSelf)strongSelf = weakSelf; + NSMutableArray* result = [[NSMutableArray alloc]init]; + [result addObject:networkStatus]; + [strongSelf dispatchEvent:event argments:result]; }]; [mgr startMonitoring]; diff --git a/Core/plugin/impl/net_info/netinfo.js b/Core/plugin/impl/net_info/netinfo.js index 02eda14f..2ef0ad2b 100644 --- a/Core/plugin/impl/net_info/netinfo.js +++ b/Core/plugin/impl/net_info/netinfo.js @@ -1,16 +1,22 @@ +var exec = require('../exec').exec +var addEventListener = require('../exec').addEventListener +var removeEventListener = require('../exec').removeEventListener var NetInfo = {} -NetInfo.getConnectInfo = function(callback) { - exec('NetInfo', 'getConnectInfo', [], callback, null) -} + +NetInfo.getConnectInfo = function() { + return new Promise((resolve, reject)=>{ + exec('NetInfo', 'getConnectInfo', [], function(info){ resolve(info) }, null) + });} NetInfo.isConnected = function(callback) { exec('NetInfo', 'isConnected', [], callback, null) } NetInfo.addEventListener = function(event, callback) { - exec('NetInfo', 'addEventListener', [event, callback], null, null) + addEventListener('NetInfo', event, callback) } NetInfo.removeEventListener = function(event, callback) { - exec('NetInfo', 'removeEventListener', [event, callback], null, null) + removeEventListener('NetInfo', event, callback) } +module.exports = NetInfo diff --git a/Core/plugin/impl/plugin.js b/Core/plugin/impl/plugin.js new file mode 100644 index 00000000..0769e9fc --- /dev/null +++ b/Core/plugin/impl/plugin.js @@ -0,0 +1,91 @@ +(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i{ + exec('Clipboard', 'getString', [], function(content){ resolve(content) }, null) + }); +} + +Clipboard.setString = function(content) { + exec('Clipboard', 'setString', [content], null, null) +} + +module.exports = Clipboard + + +},{"../exec":2}],2:[function(require,module,exports){ + +function exec(module, method, args, onSuccess, onFail) { + var callbackId = plugin.callbackId++ + if (onSuccess || onFail) { + plugin.callbacks[callbackId] = {success:onSuccess, fail:onFail}; + } + plugin.exec(module, method, callbackId, args) +} + +function addEventListener(module, method, callback) { + plugin.addEventListener(module, method, callback) +} + +function removeEventListener(module, method, callback) { + plugin.removeEventListener(module, method, callback) +} + +function callbackFromNative(callbackId, successed, args) { + + var callback = plugin.callbacks[callbackId]; + if (callback) { + if (successed) { + callback.success.apply(null, args); + } else { + callback.fail.apply(null, args); + } + delete plugin.callbacks[callbackId]; + } +} + +plugin.callbackId = 0 +plugin.callbacks = {} +plugin.init(callbackFromNative) + +var pluginExec = {} + +pluginExec.addEventListener = addEventListener +pluginExec.removeEventListener = removeEventListener +pluginExec.exec = exec +module.exports = pluginExec + +},{}],3:[function(require,module,exports){ +(function (global){ + +global.NetInfo = require('./net_info/netinfo') +global.Clipboard = require('./clipboard/clipboard') + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) +},{"./clipboard/clipboard":1,"./net_info/netinfo":4}],4:[function(require,module,exports){ +var exec = require('../exec').exec +var addEventListener = require('../exec').addEventListener +var removeEventListener = require('../exec').removeEventListener +var NetInfo = {} + +NetInfo.getConnectInfo = function() { + return new Promise((resolve, reject)=>{ + exec('NetInfo', 'getConnectInfo', [], function(info){ resolve(info) }, null) + });} + +NetInfo.isConnected = function(callback) { + exec('NetInfo', 'isConnected', [], callback, null) +} + +NetInfo.addEventListener = function(event, callback) { + addEventListener('NetInfo', event, callback) +} + +NetInfo.removeEventListener = function(event, callback) { + removeEventListener('NetInfo', event, callback) +} +module.exports = NetInfo + +},{"../exec":2}]},{},[3]); diff --git a/Core/plugin/plugin.js b/Core/plugin/plugin.js deleted file mode 100644 index 2d82c10c..00000000 --- a/Core/plugin/plugin.js +++ /dev/null @@ -1,26 +0,0 @@ - -function exec(module, method, args, onSuccess, onFail) { - var callbackId = plugin.callbackId++ - if (onSuccess || onFail) { - plugin.callbacks[callbackId] = {success:onSuccess, fail:onFail}; - } - plugin.exec(module, method, callbackId, args) -} - -function callbackFromNative(callbackId, status, args) { - - var callback = plugin.callbacks[callbackId]; - if (callback) { - if (status === 0) { - callback.fail.apply(null, args); - } else if (status === 1) { - callback.success.apply(null, args); - } - delete plugin.callbacks[callbackId]; - } -} - -plugin.callbackId = 0 -plugin.callbacks = {} -plugin.init(callbackFromNative) - diff --git a/Core/plugin/plugin_client.cc b/Core/plugin/plugin_client.cc new file mode 100644 index 00000000..6bd80914 --- /dev/null +++ b/Core/plugin/plugin_client.cc @@ -0,0 +1,96 @@ +// Copyright 2017 The Lynx Authors. All rights reserved. + +#include "plugin/plugin_client.h" +#include "plugin/plugin_server.h" + +#include "plugin/base/plugin.h" +#include "runtime/base/lynx_array.h" +#include "runtime/base/lynx_value.h" +#include "runtime/js/class_template.h" + +#include "base/log/logging.h" + +namespace plugin { + +#define FOR_EACH_METHOD_BINDING(V) \ + V(PluginClient, Exec) \ + V(PluginClient, Init) \ + V(PluginClient, AddEventListener) \ + V(PluginClient, RemoveEventListener) + +// Defines methods and fields +FOR_EACH_METHOD_BINDING(DEFINE_METHOD_CALLBACK) + +// Defines default ClassTemplate +DEFINE_CLASS_TEMPLATE_START(PluginClient) +EXPOSE_CONSTRUCTOR(true) +FOR_EACH_METHOD_BINDING(REGISTER_METHOD_CALLBACK) +DEFINE_CLASS_TEMPLATE_END + +PluginClient::PluginClient(jscore::JSContext* context) + : LynxObject(context, DEFAULT_CLASS_TEMPLATE(context)), + runtime_(context->runtime()) {} + +PluginClient::~PluginClient() {} + +base::ScopedPtr PluginClient::Init( + base::ScopedPtr& array) { + callback_.Reset(array->Get(0)->data_.lynx_function); + return base::ScopedPtr(NULL); +} + +base::ScopedPtr PluginClient::Exec( + base::ScopedPtr& array) { + PluginServer::Exec(this, array); + return base::ScopedPtr(NULL); +} + +base::ScopedPtr PluginClient::AddEventListener( + base::ScopedPtr& array) { + std::string name(array->Get(0)->data_.str); + std::string event = array->Get(1)->data_.str; + jscore::LynxFunction* js_function = array->Get(2)->data_.lynx_function; + lynx::EventTarget::AddEventListener(name + "#" + event, js_function, false); + return base::ScopedPtr(NULL); +} + +base::ScopedPtr PluginClient::RemoveEventListener( + base::ScopedPtr& array) { + std::string name(array->Get(0)->data_.str); + std::string event = array->Get(1)->data_.str; + jscore::LynxFunction* js_function = array->Get(2)->data_.lynx_function; + lynx::EventTarget::RemoveEventListener(name + "#" + event, js_function); + return base::ScopedPtr(NULL); +} + +void PluginClient::RegisterEvent(const std::string& plugin_event, + RegisterEventType type) { + size_t pos = plugin_event.find('#'); + std::string name = plugin_event.substr(0, pos); + std::string event = plugin_event.substr(pos + 1,plugin_event.length() - pos); + switch (type) { + case EVENT_ADD: + PluginServer::AddEvent(this, name, event); + break; + case EVENT_REMOVE: + PluginServer::RemoveEvent(this, name, event); + break; + default: + break; + } +} + +void PluginClient::Return(int method_id, + bool successed, + base::ScopedPtr result) { + base::ScopedPtr args(lynx_new jscore::LynxArray); + args->Push(jscore::LynxValue::MakeInt(method_id).Release()); + args->Push(jscore::LynxValue::MakeBool(successed).Release()); + args->Push(result.Release()); + callback_->Run(this, args.Get()); +} + +void PluginClient::RunOnClientThread(base::Closure* clousre) { + runtime_->thread_manager()->RunOnJSThread(clousre); +} +} // namespace plugin diff --git a/Core/plugin/plugin_client.h b/Core/plugin/plugin_client.h new file mode 100644 index 00000000..776af304 --- /dev/null +++ b/Core/plugin/plugin_client.h @@ -0,0 +1,43 @@ +// Copyright 2017 The Lynx Authors. All rights reserved. + +#ifndef LYNX_PLUGIN_PLUGIN_CLIENT_H_ +#define LYNX_PLUGIN_PLUGIN_CLIENT_H_ + +#include "base/scoped_ptr_map.h" +#include "plugin/base/plugin.h" +#include "runtime/base/lynx_object.h" +#include "runtime/runtime.h" + +namespace plugin { + +class PluginClient : public jscore::LynxObject, public lynx::EventTarget { + public: + PluginClient(jscore::JSContext* context); + virtual ~PluginClient(); + + base::ScopedPtr Init( + base::ScopedPtr& array); + base::ScopedPtr Exec( + base::ScopedPtr& array); + base::ScopedPtr AddEventListener( + base::ScopedPtr& array); + base::ScopedPtr RemoveEventListener( + base::ScopedPtr& array); + void Return(int method_id, + bool successed, + base::ScopedPtr result); + + void RunOnClientThread(base::Closure* clousre); + + private: + virtual void RegisterEvent(const std::string& plugin_event, RegisterEventType type) override; + + base::ScopedPtr callback_; + + jscore::Runtime* runtime_; + + private: + DISALLOW_COPY_AND_ASSIGN(PluginClient); +}; +} // namespace plugin +#endif // LYNX_PLUGIN_PLUGIN_CLIENT_H_ diff --git a/Core/plugin/plugin_server.h b/Core/plugin/plugin_server.h new file mode 100644 index 00000000..76a2910a --- /dev/null +++ b/Core/plugin/plugin_server.h @@ -0,0 +1,35 @@ +// Copyright 2017 The Lynx Authors. All rights reserved. + +#ifndef LYNX_PLUGIN_PLUGIN_SERVER_H_ +#define LYNX_PLUGIN_PLUGIN_SERVER_H_ + +#include "base/scoped_ptr.h" +#include "runtime/base/lynx_array.h" + +namespace plugin { + class Plugin; +class PluginClient; +class PluginServer { + public: + static void Initialize(); + static void Exec(PluginClient* client, + base::ScopedPtr& array); + static void AddEvent(PluginClient* client, + const std::string& name, + const std::string& event); + static void RemoveEvent(PluginClient* client, + const std::string& name, + const std::string& event); + static void Return(long client_id, int method, + bool successed, + base::ScopedPtr& array); + + static void DispatchEvent(const std::string& name, + const std::string& event, + base::ScopedPtr& array); + static void Register(PluginClient* client); + static void UnRegister(PluginClient* client); +}; +} // namespace plugin + +#endif // LYNX_PLUGIN_PLUGIN_SERVER_H_ diff --git a/Core/plugin/plugin_server_impl.cc b/Core/plugin/plugin_server_impl.cc new file mode 100644 index 00000000..9b603bd3 --- /dev/null +++ b/Core/plugin/plugin_server_impl.cc @@ -0,0 +1,248 @@ +// Copyright 2017 The Lynx Authors. All rights reserved. + +#include "base/lazy_instance.h" +#include "base/log/logging.h" +#include "base/ref_counted_ptr.h" +#include "content/lynx_thread.h" +#include "plugin/base/plugin.h" +#include "plugin/plugin_client.h" +#include "plugin/plugin_server.h" + +#include "base/threading/completion_event.h" + +#include +#include +#include +#include + +namespace plugin { +namespace { + +class PluginServerImpl : public base::RefCountPtr { + public: + PluginServerImpl() {} + + void Register(PluginClient* client, base::CompletionEvent* completion) { + clients_.insert(client); + completion->Signal(); + } + + void UnRegister(PluginClient* client, base::CompletionEvent* completion) { + for (EventMap::iterator iter = event_map_.begin(); iter != event_map_.end(); + ++iter) { + if (iter->second.find(client) != iter->second.end()) { + RemoveEvent(client, iter->first.first, iter->first.second); + } + } + Clients::iterator iter = clients_.find(client); + if (iter != clients_.end()) { + clients_.erase(iter); + completion->Signal(); + } + } + + void Exec(PluginClient* client, base::ScopedPtr array) { + std::string module(array->Get(0)->data_.str); + Plugin* plugin = FindPlugin(module); + if (plugin) { + plugin->Exec(reinterpret_cast(client), array); + } + return; + } + + void Return(long client_id, + int method_id, + bool successed, + base::ScopedPtr array) { + PluginClient* plugin_client = reinterpret_cast(client_id); + Clients::iterator iter = clients_.find(plugin_client); + if (iter != clients_.end()) { + plugin_client->RunOnClientThread( + base::Bind(&PluginServerImpl::ReturnOnClientThread, + base::ScopedRefPtr(this), plugin_client, + method_id, successed, array)); + } + return; + } + + void AddEvent(PluginClient* client, + const std::string& name, + const std::string& event) { + std::pair plugin_event(name, event); + EventMap::iterator plugin_event_iter = event_map_.find(plugin_event); + if (plugin_event_iter == event_map_.end()) { + Plugin* plugin = FindPlugin(name); + if (plugin) { + plugin->AddEvent(event); + } + + std::unordered_set client_set; + client_set.insert(client); + event_map_.insert(make_pair(plugin_event, client_set)); + } else { + plugin_event_iter->second.insert(client); + } + } + + void RemoveEvent(PluginClient* client, + const std::string& name, + const std::string& event) { + std::pair plugin_event(name, event); + EventMap::iterator plugin_event_iter = event_map_.find(plugin_event); + if (plugin_event_iter != event_map_.end()) { + plugin_event_iter->second.erase(client); + if (plugin_event_iter->second.empty()) { + Plugins::iterator plugin_iter = plugins_.find(name); + if (plugin_iter != plugins_.end()) { + plugin_iter->second->RemoveEvent(event); + } + } + } + } + + void DispatchEvent(const std::string& name, + const std::string& event, + base::ScopedPtr array) { + std::pair plugin_event(name, event); + EventMap::iterator plugin_event_iter = event_map_.find(plugin_event); + if (plugin_event_iter != event_map_.end()) { + for (std::unordered_set::iterator client_iter = + plugin_event_iter->second.begin(); + client_iter != plugin_event_iter->second.end(); ++client_iter) { + base::ScopedPtr result(array->Clone()); + std::string plugin_event = name + "#" + event; + (*client_iter) + ->RunOnClientThread( + base::Bind(&PluginServerImpl::DispatchEventOnClientThread, + base::ScopedRefPtr(this), + (*client_iter), plugin_event, result)); + } + } + } + + private: + Plugin* FindPlugin(const std::string& name) { + Plugin* plugin = nullptr; + Plugins::iterator iter = plugins_.find(name); + if (iter != plugins_.end()) { + plugin = iter->second; + } else { + plugin = RegisterPlugin(name); + } + if (!plugin) { + DLOG(ERROR) << "Cant't find plugin " << name; + } + return plugin; + } + + Plugin* RegisterPlugin(const std::string& name) { + Plugin* plugin = Plugin::Create(name); + plugins_.add(name, plugin); + return plugin; + } + + void ReturnOnClientThread(PluginClient* client, + int method, + bool successed, + base::ScopedPtr result) { + client->Return(method, successed, result); + } + + void DispatchEventOnClientThread(PluginClient* client, + const std::string& event, + base::ScopedPtr result) { + client->DispatchEvent(event, result); + } + + typedef std::map, + std::unordered_set> + EventMap; + EventMap event_map_; + + typedef std::unordered_set Clients; + Clients clients_; + + typedef base::ScopedPtrMap Plugins; + Plugins plugins_; +}; + +base::LazyInstance g_plugin_server; +} // namespace + +void PluginServer::Register(PluginClient* client) { + base::CompletionEvent* completion = lynx_new base::CompletionEvent; + content::LynxThread::PostTask( + content::LynxThread::PLUGIN, + base::Bind(&PluginServerImpl::Register, + base::ScopedRefPtr(g_plugin_server.Get()), + client, completion)); + completion->Wait(); + lynx_delete(completion); +} + +void PluginServer::UnRegister(PluginClient* client) { + base::CompletionEvent* completion = lynx_new base::CompletionEvent; + content::LynxThread::PostTask( + content::LynxThread::PLUGIN, + base::Bind(&PluginServerImpl::UnRegister, + base::ScopedRefPtr(g_plugin_server.Get()), + client, completion)); + completion->Wait(); + lynx_delete(completion); +} + +void PluginServer::Exec(PluginClient* client, + base::ScopedPtr& array) { + content::LynxThread::PostTask( + content::LynxThread::PLUGIN, + base::Bind(&PluginServerImpl::Exec, + base::ScopedRefPtr(g_plugin_server.Get()), + client, array)); +} + +void PluginServer::Return(long client_id, + int method_id, + bool successed, + base::ScopedPtr& array) { + content::LynxThread::PostTask( + content::LynxThread::PLUGIN, + base::Bind(&PluginServerImpl::Return, + base::ScopedRefPtr(g_plugin_server.Get()), + client_id, method_id, successed, array)); +} + +void PluginServer::AddEvent(PluginClient* client, + const std::string& name, + const std::string& event) { + content::LynxThread::PostTask( + content::LynxThread::PLUGIN, + base::Bind(&PluginServerImpl::AddEvent, + base::ScopedRefPtr(g_plugin_server.Get()), + client, name, event)); +} + +void PluginServer::RemoveEvent(PluginClient* client, + const std::string& name, + const std::string& event) { + content::LynxThread::PostTask( + content::LynxThread::PLUGIN, + base::Bind(&PluginServerImpl::RemoveEvent, + base::ScopedRefPtr(g_plugin_server.Get()), + client, name, event)); +} + +void PluginServer::DispatchEvent(const std::string& name, + const std::string& event, + base::ScopedPtr& array) { + content::LynxThread::PostTask( + content::LynxThread::PLUGIN, + base::Bind(&PluginServerImpl::DispatchEvent, + base::ScopedRefPtr(g_plugin_server.Get()), + name, event, array)); +} + +void PluginServer::Initialize() { + g_plugin_server.Get()->AddRef(); +} + +} // namespace plugin diff --git a/Core/render/event_target.cc b/Core/render/event_target.cc index 1fb1fe5f..270ee447 100644 --- a/Core/render/event_target.cc +++ b/Core/render/event_target.cc @@ -15,9 +15,7 @@ void EventTarget::DispatchEvent(const std::string& event, base::ScopedPtrsecond->size(); for (int i = 0; i < length; i++) { - if (target_data_ != NULL) { - (*iter->second)[i]->function_->Run(target_data_, args.Get()); - } + (*iter->second)[i]->function_->Run(target_data_, args.Get()); } } diff --git a/Core/runtime/base/lynx_array.cc b/Core/runtime/base/lynx_array.cc index 58a5311b..699f87d0 100644 --- a/Core/runtime/base/lynx_array.cc +++ b/Core/runtime/base/lynx_array.cc @@ -1,78 +1,88 @@ // Copyright 2017 The Lynx Authors. All rights reserved. -#include #include "lynx_array.h" +#include namespace jscore { - LynxArray::LynxArray() : LynxValue(LynxValue::Type::VALUE_LYNX_ARRAY) { - data_.lynx_array = this; - } +LynxArray::LynxArray() : LynxValue(LynxValue::Type::VALUE_LYNX_ARRAY) { + data_.lynx_array = this; +} - LynxArray::~LynxArray() { - data_.lynx_array = 0; - } +LynxArray::~LynxArray() { + data_.lynx_array = 0; +} - void LynxArray::Push(LynxValue* value) { - values_.push_back(value); - if(value != NULL) { - AddPtr(value); - } - } +void LynxArray::Push(LynxValue* value) { + values_.push_back(value); + if (value != NULL) { + AddPtr(value); + } +} - LynxValue* LynxArray::Pop() { - if (values_.size() > 0) { - LynxValue* value = values_[values_.size() - 1]; - values_.pop_back(); - RemovePtr(value); - return value; - } - return 0; - } +LynxValue* LynxArray::Pop() { + if (values_.size() > 0) { + LynxValue* value = values_[values_.size() - 1]; + values_.pop_back(); + RemovePtr(value); + return value; + } + return 0; +} - LynxValue* LynxArray::Get(int index) { - return values_[index]; - } +LynxValue* LynxArray::Get(int index) { + return values_[index]; +} - base::ScopedPtr LynxArray::Release(int index) { - LynxValue* temp = values_[index]; - values_[index] = NULL; - RemovePtr(temp); - return base::MakeScopedPtr(temp); - } +base::ScopedPtr LynxArray::Release(int index) { + LynxValue* temp = values_[index]; + values_[index] = NULL; + RemovePtr(temp); + return base::MakeScopedPtr(temp); +} - size_t LynxArray::Size() { - return values_.size(); - } +size_t LynxArray::Size() { + return values_.size(); +} - void LynxArray::RemovePtr(LynxValue* value) { - bool exist = false; - for (auto it = values_.begin(); it != values_.end(); ++it) { - if (*it == value) { - exist = true; - break; - } - } - if (!exist) { - ptrs_.release(value); - } +void LynxArray::RemovePtr(LynxValue* value) { + bool exist = false; + for (auto it = values_.begin(); it != values_.end(); ++it) { + if (*it == value) { + exist = true; + break; } + } + if (!exist) { + ptrs_.release(value); + } +} + +void LynxArray::AddPtr(LynxValue* value) { + ptrs_.add(value); +} - void LynxArray::AddPtr(LynxValue* value) { - ptrs_.add(value); +LynxArray* LynxArray::Clone() { + LynxArray* array = lynx_new LynxArray; + for (int i = 0; i < Size(); ++i) { + if (Get(i) != NULL) { + array->Push(Get(i)->Clone()); } + } + return array; +} - std::string LynxArray::ToString() { - std::stringstream stream; - stream<<"["; - for (int i = 0; i < Size(); ++i) { - if (Get(i) != NULL) { - stream << Get(i)->ToString(); - } - if (i != Size() - 1) { - stream << ", "; - } - } - stream<<"]"; - return stream.str(); +std::string LynxArray::ToString() { + std::stringstream stream; + stream << "["; + for (int i = 0; i < Size(); ++i) { + if (Get(i) != NULL) { + stream << Get(i)->ToString(); + } + if (i != Size() - 1) { + stream << ", "; } + } + stream << "]"; + return stream.str(); } +} // namespace jscore diff --git a/Core/runtime/base/lynx_array.h b/Core/runtime/base/lynx_array.h index d0df3a9a..de7283c5 100644 --- a/Core/runtime/base/lynx_array.h +++ b/Core/runtime/base/lynx_array.h @@ -4,35 +4,34 @@ #define LYNX_RUNTIME_LYNX_ARRAY_H_ #include -#include "runtime/base/lynx_value.h" #include "base/scoped_set.h" +#include "runtime/base/lynx_value.h" namespace jscore { - class LynxArray : public LynxValue { - public: - LynxArray(); - virtual ~LynxArray(); +class LynxArray : public LynxValue { + public: + LynxArray(); + virtual ~LynxArray(); - void Push(LynxValue* value); - LynxValue* Pop(); - LynxValue* Get(int index); - base::ScopedPtr Release(int index); - size_t Size(); + void Push(LynxValue* value); + LynxValue* Pop(); + LynxValue* Get(int index); + base::ScopedPtr Release(int index); + size_t Size(); - void Release() { - ptrs_.release(); - } + void Release() { ptrs_.release(); } - virtual std::string ToString(); + virtual std::string ToString(); - private: - void RemovePtr(LynxValue* value); - void AddPtr(LynxValue* value); - std::vector values_; - base::ScopedSet ptrs_; - }; -} + LynxArray* Clone(); + private: + void RemovePtr(LynxValue* value); + void AddPtr(LynxValue* value); + std::vector values_; + base::ScopedSet ptrs_; +}; +} // namespace jscore -#endif //LYNX_RUNTIME_LYNX_ARRAY_H_ +#endif // LYNX_RUNTIME_LYNX_ARRAY_H_ diff --git a/Core/runtime/base/lynx_value.cc b/Core/runtime/base/lynx_value.cc index 90f1dad7..86f12419 100644 --- a/Core/runtime/base/lynx_value.cc +++ b/Core/runtime/base/lynx_value.cc @@ -1,74 +1,94 @@ // Copyright 2017 The Lynx Authors. All rights reserved. -#include #include "runtime/base/lynx_value.h" +#include +#include "runtime/base/lynx_array.h" #include "runtime/base/lynx_map.h" #include "runtime/base/lynx_object.h" -#include "runtime/base/lynx_array.h" #include "runtime/platform_value.h" namespace jscore { - LynxValue::LynxValue() { +LynxValue::LynxValue() {} - } +LynxValue::LynxValue(Type type) : type_(type) {} - LynxValue::LynxValue(Type type) : type_(type) { +LynxValue::~LynxValue() { + if (type_ == VALUE_LYNX_ARRAY && data_.lynx_array != 0) { + lynx_delete(data_.lynx_array); + } else if (type_ == VALUE_LYNX_MAP && data_.lynx_map != 0) { + lynx_delete(data_.lynx_map); + } else if (type_ == VALUE_PLATFORM && data_.platform_value != 0) { + lynx_delete(data_.platform_value); + } else if (type_ == VALUE_STRING && data_.str != 0) { + lynx_deleteA(data_.str); + } +} - } +std::string LynxValue::ToString() { + std::string result = ""; + switch (type_) { + case LynxValue::Type::VALUE_INT: { + double number = data_.i; + std::stringstream stream; + stream << number; + result = stream.str(); + } break; + case LynxValue::Type::VALUE_DOUBLE: { + double number = data_.d; + std::stringstream stream; + stream << number; + result = stream.str(); + } break; + case LynxValue::Type::VALUE_BOOL: { + if (data_.b) { + result = "true"; + } else { + result = "false"; + } + } break; + case LynxValue::Type::VALUE_STRING: + result = data_.str; + break; + case LynxValue::Type::VALUE_LYNX_OBJECT: + result = "LynxObject"; + break; + case LynxValue::Type::VALUE_NULL: + result = "null"; + break; + case LynxValue::Type::VALUE_UNDEFINED: + result = "undefined"; + break; + default: + break; + } + return result; +} - LynxValue::~LynxValue() { - if (type_ == VALUE_LYNX_ARRAY && data_.lynx_array != 0) { - lynx_delete(data_.lynx_array); - } else if (type_ == VALUE_LYNX_MAP && data_.lynx_map != 0) { - lynx_delete(data_.lynx_map); - } else if (type_ == VALUE_PLATFORM && data_.platform_value != 0) { - lynx_delete(data_.platform_value); - } else if (type_ == VALUE_STRING && data_.str != 0) { - lynx_deleteA(data_.str); - } - } +LynxValue* LynxValue::Clone() { + LynxValue* v = nullptr; + switch (type_) { + case LynxValue::Type::VALUE_INT: + v = MakeInt(data_.i).Release(); + break; + case LynxValue::Type::VALUE_DOUBLE: + v = MakeDouble(data_.d).Release(); + break; + case LynxValue::Type::VALUE_BOOL: + v = MakeBool(data_.b).Release(); + break; + case LynxValue::Type::VALUE_STRING: { + std::string str(data_.str); + v = MakeString(str).Release(); + } break; + case LynxValue::Type::VALUE_LYNX_OBJECT: + case LynxValue::Type::VALUE_NULL: + case LynxValue::Type::VALUE_UNDEFINED: - std::string LynxValue::ToString() { - std::string result = ""; - switch (type_) { - case LynxValue::Type::VALUE_INT: { - double number = data_.i; - std::stringstream stream; - stream << number; - result = stream.str(); - } - break; - case LynxValue::Type::VALUE_DOUBLE: { - double number = data_.d; - std::stringstream stream; - stream << number; - result = stream.str(); - } - break; - case LynxValue::Type::VALUE_BOOL: { - if (data_.b) { - result = "true"; - } else { - result = "false"; - } - } - break; - case LynxValue::Type::VALUE_STRING: - result = data_.str; - break; - case LynxValue::Type::VALUE_LYNX_OBJECT: - result = "LynxObject"; - break; - case LynxValue::Type::VALUE_NULL: - result = "null"; - break; - case LynxValue::Type::VALUE_UNDEFINED: - result = "undefined"; - break; - default: - break; - } - return result; - } + break; + default: + break; + } + return v; } +} // namespace jscore diff --git a/Core/runtime/base/lynx_value.h b/Core/runtime/base/lynx_value.h index fe22dff8..53f6d9c9 100644 --- a/Core/runtime/base/lynx_value.h +++ b/Core/runtime/base/lynx_value.h @@ -8,159 +8,166 @@ namespace jscore { - class LynxArray; - class LynxMap; - class LynxObject; - class ObjectWrap; - class PlatformValue; - class LynxFunction; - class LynxHolder; - - class LynxValue { - public: - enum Type { - VALUE_INT, - VALUE_LONG, - VALUE_BOOL, - VALUE_FLOAT, - VALUE_DOUBLE, - VALUE_STRING, - VALUE_LYNX_MAP, - VALUE_LYNX_ARRAY, - VALUE_LYNX_OBJECT, - VALUE_LYNX_FUNCTION, - VALUE_LYNX_HOLDER, - VALUE_PLATFORM, - VALUE_NULL, - VALUE_UNDEFINED - }; - - Type type_; - union { - int i; - bool b; - long l; - float f; - double d; - const char* str; - LynxArray* lynx_array; - LynxMap* lynx_map; - LynxObject* lynx_object; - LynxFunction* lynx_function; - PlatformValue* platform_value; - LynxHolder* lynx_holder; - } data_; - - inline static base::ScopedPtr MakeBool(bool value) { - base::ScopedPtr lynx_value(lynx_new LynxValue(LynxValue::Type::VALUE_BOOL)); - lynx_value->data_.b = value; - return lynx_value; - } - - inline static base::ScopedPtr MakeLong(long value) { - base::ScopedPtr lynx_value(lynx_new LynxValue(LynxValue::Type::VALUE_LONG)); - lynx_value->data_.l = value; - return lynx_value; - } - - inline static base::ScopedPtr MakeInt(int value) { - base::ScopedPtr lynx_value(lynx_new LynxValue(LynxValue::Type::VALUE_INT)); - lynx_value->data_.i = value; - return lynx_value; - } - - inline static base::ScopedPtr MakeFloat(float value) { - base::ScopedPtr lynx_value( - lynx_new LynxValue(LynxValue::Type::VALUE_FLOAT)); - lynx_value->data_.f = value; - return lynx_value; - } - - inline static base::ScopedPtr MakeDouble(double value) { - base::ScopedPtr lynx_value( - lynx_new LynxValue(LynxValue::Type::VALUE_DOUBLE)); - lynx_value->data_.d = value; - return lynx_value; - } - - static base::ScopedPtr MakeString(std::string& value) { - base::ScopedPtr lynx_value( - lynx_new LynxValue(LynxValue::Type::VALUE_STRING)); - char* str = lynx_new char[value.size() + 1]; - strcpy(str, value.c_str()); - lynx_value->data_.str = str; - return lynx_value; - } - - static base::ScopedPtr MakeString(const std::string& value) { - base::ScopedPtr lynx_value( - lynx_new LynxValue(LynxValue::Type::VALUE_STRING)); - char* str = lynx_new char[value.size() + 1]; - strcpy(str, value.c_str()); - lynx_value->data_.str = str; - return lynx_value; - } - - static base::ScopedPtr MakeString(std::string&& value) { - base::ScopedPtr lynx_value( - lynx_new LynxValue(LynxValue::Type::VALUE_STRING)); - char* str = lynx_new char[value.size() + 1]; - strcpy(str, value.c_str()); - lynx_value->data_.str = str; - return lynx_value; - } - - inline static base::ScopedPtr MakeObject(LynxObject *object) { - base::ScopedPtr lynx_object( - lynx_new LynxValue(LynxValue::Type::VALUE_LYNX_OBJECT)); - lynx_object->data_.lynx_object = object; - return lynx_object; - } - - inline static base::ScopedPtr MakeLynxFunction(LynxFunction* function) { - base::ScopedPtr lynx_value( - lynx_new LynxValue(LynxValue::Type::VALUE_LYNX_FUNCTION)); - lynx_value->data_.lynx_function = function; - return lynx_value; - } - - inline static base::ScopedPtr MakePlatformValue(PlatformValue* platform_value) { - base::ScopedPtr lynx_object( - lynx_new LynxValue(LynxValue::Type::VALUE_PLATFORM)); - lynx_object->data_.platform_value = platform_value; - return lynx_object; - } - - inline static base::ScopedPtr MakeLynxHolder(LynxHolder* lynx_holder) { - base::ScopedPtr lynx_object( - lynx_new LynxValue(LynxValue::Type::VALUE_LYNX_HOLDER)); - lynx_object->data_.lynx_holder = lynx_holder; - return lynx_object; - } - - static base::ScopedPtr MakeNull() { - base::ScopedPtr null(lynx_new LynxValue(LynxValue::Type::VALUE_NULL)); - return null; - } - - static base::ScopedPtr MakeUndefined() { - base::ScopedPtr undefined( - lynx_new LynxValue(LynxValue::Type::VALUE_UNDEFINED)); - return undefined; - } - - virtual ~LynxValue(); - - virtual std::string ToString(); - - protected: - - LynxValue(); - - LynxValue(Type type); - - }; -} - - -#endif //LYNX_RUNTIME_LYNX_VALUE_H_ +class LynxArray; +class LynxMap; +class LynxObject; +class ObjectWrap; +class PlatformValue; +class LynxFunction; +class LynxHolder; + +class LynxValue { + public: + enum Type { + VALUE_INT, + VALUE_LONG, + VALUE_BOOL, + VALUE_FLOAT, + VALUE_DOUBLE, + VALUE_STRING, + VALUE_LYNX_MAP, + VALUE_LYNX_ARRAY, + VALUE_LYNX_OBJECT, + VALUE_LYNX_FUNCTION, + VALUE_LYNX_HOLDER, + VALUE_PLATFORM, + VALUE_NULL, + VALUE_UNDEFINED + }; + + Type type_; + union { + int i; + bool b; + long l; + float f; + double d; + const char* str; + LynxArray* lynx_array; + LynxMap* lynx_map; + LynxObject* lynx_object; + LynxFunction* lynx_function; + PlatformValue* platform_value; + LynxHolder* lynx_holder; + } data_; + + inline static base::ScopedPtr MakeBool(bool value) { + base::ScopedPtr lynx_value( + lynx_new LynxValue(LynxValue::Type::VALUE_BOOL)); + lynx_value->data_.b = value; + return lynx_value; + } + + inline static base::ScopedPtr MakeLong(long value) { + base::ScopedPtr lynx_value( + lynx_new LynxValue(LynxValue::Type::VALUE_LONG)); + lynx_value->data_.l = value; + return lynx_value; + } + + inline static base::ScopedPtr MakeInt(int value) { + base::ScopedPtr lynx_value( + lynx_new LynxValue(LynxValue::Type::VALUE_INT)); + lynx_value->data_.i = value; + return lynx_value; + } + + inline static base::ScopedPtr MakeFloat(float value) { + base::ScopedPtr lynx_value( + lynx_new LynxValue(LynxValue::Type::VALUE_FLOAT)); + lynx_value->data_.f = value; + return lynx_value; + } + + inline static base::ScopedPtr MakeDouble(double value) { + base::ScopedPtr lynx_value( + lynx_new LynxValue(LynxValue::Type::VALUE_DOUBLE)); + lynx_value->data_.d = value; + return lynx_value; + } + + static base::ScopedPtr MakeString(std::string& value) { + base::ScopedPtr lynx_value( + lynx_new LynxValue(LynxValue::Type::VALUE_STRING)); + char* str = lynx_new char[value.size() + 1]; + strcpy(str, value.c_str()); + str[value.size()] = 0; + lynx_value->data_.str = str; + return lynx_value; + } + + static base::ScopedPtr MakeString(const std::string& value) { + base::ScopedPtr lynx_value( + lynx_new LynxValue(LynxValue::Type::VALUE_STRING)); + char* str = lynx_new char[value.size() + 1]; + strcpy(str, value.c_str()); + lynx_value->data_.str = str; + return lynx_value; + } + + static base::ScopedPtr MakeString(std::string&& value) { + base::ScopedPtr lynx_value( + lynx_new LynxValue(LynxValue::Type::VALUE_STRING)); + char* str = lynx_new char[value.size() + 1]; + strcpy(str, value.c_str()); + lynx_value->data_.str = str; + return lynx_value; + } + + inline static base::ScopedPtr MakeObject(LynxObject* object) { + base::ScopedPtr lynx_object( + lynx_new LynxValue(LynxValue::Type::VALUE_LYNX_OBJECT)); + lynx_object->data_.lynx_object = object; + return lynx_object; + } + + inline static base::ScopedPtr MakeLynxFunction( + LynxFunction* function) { + base::ScopedPtr lynx_value( + lynx_new LynxValue(LynxValue::Type::VALUE_LYNX_FUNCTION)); + lynx_value->data_.lynx_function = function; + return lynx_value; + } + + inline static base::ScopedPtr MakePlatformValue( + PlatformValue* platform_value) { + base::ScopedPtr lynx_object( + lynx_new LynxValue(LynxValue::Type::VALUE_PLATFORM)); + lynx_object->data_.platform_value = platform_value; + return lynx_object; + } + + inline static base::ScopedPtr MakeLynxHolder( + LynxHolder* lynx_holder) { + base::ScopedPtr lynx_object( + lynx_new LynxValue(LynxValue::Type::VALUE_LYNX_HOLDER)); + lynx_object->data_.lynx_holder = lynx_holder; + return lynx_object; + } + + static base::ScopedPtr MakeNull() { + base::ScopedPtr null( + lynx_new LynxValue(LynxValue::Type::VALUE_NULL)); + return null; + } + + static base::ScopedPtr MakeUndefined() { + base::ScopedPtr undefined( + lynx_new LynxValue(LynxValue::Type::VALUE_UNDEFINED)); + return undefined; + } + + virtual ~LynxValue(); + + virtual std::string ToString(); + + LynxValue* Clone(); + + protected: + LynxValue(); + + LynxValue(Type type); +}; +} // namespace jscore + +#endif // LYNX_RUNTIME_LYNX_VALUE_H_ diff --git a/Core/runtime/global.cc b/Core/runtime/global.cc index f692393d..8b042249 100644 --- a/Core/runtime/global.cc +++ b/Core/runtime/global.cc @@ -2,7 +2,7 @@ #include "runtime/global.h" -#include "plugin/base/plugin_manager.h" +#include "plugin/plugin_client.h" #include "runtime/base/lynx_array.h" #include "runtime/base/lynx_value.h" #include "runtime/console.h" @@ -69,7 +69,7 @@ void Global::OnJSObjectAttached() { document_ = lynx_new Document(context_); document_->ProtectJSObject(); #if PLUGIN_ENABLE - plugin_ = lynx_new plugin::PluginManager(context_); + plugin_ = lynx_new plugin::PluginClient(context_); plugin_->ProtectJSObject(); #endif } diff --git a/Core/runtime/global.h b/Core/runtime/global.h index a15ed940..88ee8a12 100644 --- a/Core/runtime/global.h +++ b/Core/runtime/global.h @@ -6,7 +6,7 @@ #include "runtime/base/lynx_object.h" namespace plugin { -class PluginManager; +class PluginClient; } namespace jscore { @@ -27,7 +27,7 @@ class Global : public LynxObject { inline Loader* loader() { return loader_.Get(); } inline Document* document() { return document_.Get(); } #if PLUGIN_ENABLE - inline plugin::PluginManager* plugin() { return plugin_.Get(); } + inline plugin::PluginClient* plugin() { return plugin_.Get(); } #endif base::ScopedPtr SetTimeout(base::ScopedPtr& array); @@ -50,7 +50,7 @@ class Global : public LynxObject { base::ScopedRefPtr loader_; base::ScopedRefPtr document_; #if PLUGIN_ENABLE - base::ScopedRefPtr plugin_; + base::ScopedRefPtr plugin_; #endif DISALLOW_COPY_AND_ASSIGN(Global); }; diff --git a/Core/runtime/js/js_vm.h b/Core/runtime/js/js_vm.h index ff378b04..24308f48 100644 --- a/Core/runtime/js/js_vm.h +++ b/Core/runtime/js/js_vm.h @@ -8,17 +8,19 @@ #include "base/ref_counted_ptr.h" namespace jscore { -class JSVM : public base::RefCountPtr{ -public: - JSVM(): vm_(NULL) {} - ~JSVM(); - void Initialize(); - - void* vm() { - return vm_; - } -private: - void* vm_; +class JSVM : public base::RefCountPtr { + public: + JSVM() : vm_(NULL) {} + ~JSVM(); + + static JSVM* Instance(); + + void Initialize(); + + void* vm() { return vm_; } + + private: + void* vm_; }; } // namespace jscore diff --git a/Core/runtime/jsc/js_vm.cc b/Core/runtime/jsc/js_vm.cc index 2c769a2c..775d0b6c 100644 --- a/Core/runtime/jsc/js_vm.cc +++ b/Core/runtime/jsc/js_vm.cc @@ -2,8 +2,17 @@ #include #include "runtime/js/js_vm.h" +#include "base/lazy_instance.h" namespace jscore { + namespace { + base::LazyInstance g_vm; + } + + JSVM* JSVM::Instance() { + return g_vm.Get(); + } + void JSVM::Initialize() { JSContextGroupRef context_group = JSContextGroupCreate(); vm_ = static_cast(const_cast(context_group)); @@ -15,4 +24,4 @@ namespace jscore { JSContextGroupRelease(context_group); } } -} \ No newline at end of file +} diff --git a/Core/runtime/runtime.cc b/Core/runtime/runtime.cc index fb87a599..2de4ccce 100644 --- a/Core/runtime/runtime.cc +++ b/Core/runtime/runtime.cc @@ -2,6 +2,7 @@ #include "runtime/js/js_context.h" #include "runtime/runtime.h" +#include "runtime/global.h" #include "parser/render_parser.h" #include "render/render_tree_host_impl.h" #include "runtime/base/lynx_object_platform.h" @@ -9,6 +10,9 @@ #include "base/trace_event/trace_event_common.h" #include "base/log/logging.h" +#include "plugin/plugin_server.h" +#include "base/threading/completion_event.h" + namespace jscore { Runtime::Runtime(JSContext* context) @@ -124,9 +128,13 @@ namespace jscore { void Runtime::InitRuntimeOnJSThread(const char *arg) { TRACE_EVENT0("js", "Runtime::InitRuntimeOnJSThread"); - vm_ = lynx_new JSVM(); + //vm_ = JSVM::Instance(); + vm_ = lynx_new JSVM; vm_->Initialize(); context_->Initialize(vm_.Get(), this); +#if ENABLE_PLUGIN + plugin::PluginServer::Register(context_->global()->plugin()); +#endif //inspector_->Attach(this); } @@ -154,6 +162,9 @@ namespace jscore { } void Runtime::DestroyOnJSThread() { +#if ENABLE_PLUGIN + plugin::PluginServer::UnRegister(context_->global()->plugin()); +#endif Release(); } diff --git a/Core/runtime/runtime.h b/Core/runtime/runtime.h index f6197bbc..d2b6b96a 100644 --- a/Core/runtime/runtime.h +++ b/Core/runtime/runtime.h @@ -46,6 +46,8 @@ class Runtime : public base::RefCountPtr{ void LoadHTML(const std::string& url, const std::string& html); void Reload(bool force); void Destroy(); + void Pause(); + void Resume(); void AddJavaScriptInterface(const std::string& name, LynxObjectPlatform* object); diff --git a/Core/runtime/v8/js_vm.cc b/Core/runtime/v8/js_vm.cc index a5b572da..b89fd9f1 100644 --- a/Core/runtime/v8/js_vm.cc +++ b/Core/runtime/v8/js_vm.cc @@ -2,36 +2,37 @@ #include "runtime/js/js_vm.h" -#include "v8.h" #include "libplatform/libplatform.h" #include "runtime/v8/simple_allocator.h" +#include "v8.h" namespace { bool g_is_vm_initialized_ = false; - jscore::SimpleAllocator g_allocator; -} +jscore::SimpleAllocator g_allocator; +} // namespace namespace jscore { - JSVM::~JSVM() { - if(vm_) { - v8::Isolate* isolate = static_cast(vm_); - isolate->Dispose(); - } - } +JSVM::~JSVM() { + if (vm_) { + v8::Isolate* isolate = static_cast(vm_); + isolate->Dispose(); + } +} void JSVM::Initialize() { - if (!g_is_vm_initialized_) { - const char* flag = "--noflush_code --noage_code --nocompact_code_space --expose_gc"; - v8::V8::SetFlagsFromString(flag, static_cast(strlen(flag))); + if (!g_is_vm_initialized_) { + const char* flag = + "--noflush_code --noage_code --nocompact_code_space --expose_gc"; + v8::V8::SetFlagsFromString(flag, static_cast(strlen(flag))); - v8::V8::InitializeICU(); - v8::V8::InitializeExternalStartupData(""); - v8::V8::InitializePlatform(v8::platform::CreateDefaultPlatform()); - v8::V8::Initialize(); - g_is_vm_initialized_ = true; - } - v8::Isolate::CreateParams create_params; - create_params.array_buffer_allocator = &g_allocator; - vm_ = static_cast(v8::Isolate::New(create_params)); + v8::V8::InitializeICU(); + v8::V8::InitializeExternalStartupData(""); + v8::V8::InitializePlatform(v8::platform::CreateDefaultPlatform()); + v8::V8::Initialize(); + g_is_vm_initialized_ = true; + } + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = &g_allocator; + vm_ = static_cast(v8::Isolate::New(create_params)); } } // namespace jscore diff --git a/iOS/assets.bundle/homedemo/index.html b/iOS/assets.bundle/homedemo/index.html index a186ec5f..3dc0d2d9 100644 --- a/iOS/assets.bundle/homedemo/index.html +++ b/iOS/assets.bundle/homedemo/index.html @@ -1,4 +1,6 @@
Setting
Send feedback
About Lynx
Demos
Gallery
Gallery Demo
Coordinator
Coordinator Demo
Component
Button
Button Demo
Checkbox
Checkbox Demo
Radio
Radio Demo
Canvas
Canvas Demo
Swiper
Swiper Demo
Demos
Animations
Scroll Animation
Shopping
Test Shopping
Lynx
+ + - \ No newline at end of file + diff --git a/iOS/assets.bundle/homedemo/plugin_test.js b/iOS/assets.bundle/homedemo/plugin_test.js new file mode 100644 index 00000000..f2b6aab0 --- /dev/null +++ b/iOS/assets.bundle/homedemo/plugin_test.js @@ -0,0 +1,7 @@ +//NetInfo.getConnectInfo().then((info)=>{ +// console.log(info) +// }) + +NetInfo.addEventListener("connectionChange", (info)=>{ + console.log(info) + }) diff --git a/iOS/assets.bundle/manifest.json b/iOS/assets.bundle/manifest.json index eedb6936..3f93c55f 100644 --- a/iOS/assets.bundle/manifest.json +++ b/iOS/assets.bundle/manifest.json @@ -1,5 +1,5 @@ { - "debug": false, + "debug": true, "application": { "packageName": "com.demo", "icon": "icon.png", diff --git a/iOS/assets.bundle/plugin.js b/iOS/assets.bundle/plugin.js index e69de29b..81b989f0 100644 --- a/iOS/assets.bundle/plugin.js +++ b/iOS/assets.bundle/plugin.js @@ -0,0 +1,91 @@ + (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i{ + exec('Clipboard', 'getString', [], function(content){ resolve(content) }, null) + }); + } + + Clipboard.setString = function(content) { + exec('Clipboard', 'setString', [content], null, null) + } + + module.exports = Clipboard + + + },{"../exec":2}],2:[function(require,module,exports){ + + function exec(module, method, args, onSuccess, onFail) { + var callbackId = plugin.callbackId++ + if (onSuccess || onFail) { + plugin.callbacks[callbackId] = {success:onSuccess, fail:onFail}; + } + plugin.exec(module, method, callbackId, args) + } + + function addEventListener(module, method, callback) { + plugin.addEventListener(module, method, callback) + } + + function removeEventListener(module, method, callback) { + plugin.removeEventListener(module, method, callback) + } + + function callbackFromNative(callbackId, successed, args) { + + var callback = plugin.callbacks[callbackId]; + if (callback) { + if (successed) { + callback.success.apply(null, args); + } else { + callback.fail.apply(null, args); + } + delete plugin.callbacks[callbackId]; + } + } + + plugin.callbackId = 0 + plugin.callbacks = {} + plugin.init(callbackFromNative) + + var pluginExec = {} + + pluginExec.addEventListener = addEventListener + pluginExec.removeEventListener = removeEventListener + pluginExec.exec = exec + module.exports = pluginExec + + },{}],3:[function(require,module,exports){ + (function (global){ + + global.NetInfo = require('./net_info/netinfo') + global.Clipboard = require('./clipboard/clipboard') + + }).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) + },{"./clipboard/clipboard":1,"./net_info/netinfo":4}],4:[function(require,module,exports){ + var exec = require('../exec').exec + var addEventListener = require('../exec').addEventListener + var removeEventListener = require('../exec').removeEventListener + var NetInfo = {} + + NetInfo.getConnectInfo = function() { + return new Promise((resolve, reject)=>{ + exec('NetInfo', 'getConnectInfo', [], function(info){ resolve(info) }, null) + });} + + NetInfo.isConnected = function(callback) { + exec('NetInfo', 'isConnected', [], callback, null) + } + + NetInfo.addEventListener = function(event, callback) { + addEventListener('NetInfo', event, callback) + } + + NetInfo.removeEventListener = function(event, callback) { + removeEventListener('NetInfo', event, callback) + } + module.exports = NetInfo + + },{"../exec":2}]},{},[3]); diff --git a/iOS/lynx.xcodeproj/project.pbxproj b/iOS/lynx.xcodeproj/project.pbxproj index 283cb03b..a0980460 100644 --- a/iOS/lynx.xcodeproj/project.pbxproj +++ b/iOS/lynx.xcodeproj/project.pbxproj @@ -22,12 +22,15 @@ 4214C31720B17EEC005EC1ED /* CoreTelephony.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4214C31620B17EEC005EC1ED /* CoreTelephony.framework */; }; 4214C32F20B2D4D3005EC1ED /* netinfo.js in Resources */ = {isa = PBXBuildFile; fileRef = 4214C31F20B2D4D3005EC1ED /* netinfo.js */; }; 4214C33020B2D4D3005EC1ED /* clipboard.js in Resources */ = {isa = PBXBuildFile; fileRef = 4214C32120B2D4D3005EC1ED /* clipboard.js */; }; - 4214C33120B2D4D3005EC1ED /* plugin.js in Resources */ = {isa = PBXBuildFile; fileRef = 4214C32220B2D4D3005EC1ED /* plugin.js */; }; - 4214C33220B2D4D3005EC1ED /* plugin_manager.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4214C32520B2D4D3005EC1ED /* plugin_manager.cc */; }; 4214C33320B2D4D3005EC1ED /* plugin.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4214C32720B2D4D3005EC1ED /* plugin.cc */; }; - 4214C33420B2D4D3005EC1ED /* plugin_builder.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4214C32920B2D4D3005EC1ED /* plugin_builder.mm */; }; 4214C33520B2D4D3005EC1ED /* plugin_impl.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4214C32B20B2D4D3005EC1ED /* plugin_impl.mm */; }; 4214C33920B2D5D3005EC1ED /* net_info_plugin.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4214C33720B2D5D3005EC1ED /* net_info_plugin.mm */; }; + 4214C33C20B3EEAE005EC1ED /* exec.js in Resources */ = {isa = PBXBuildFile; fileRef = 4214C33A20B3EEAE005EC1ED /* exec.js */; }; + 4214C33D20B3EEAE005EC1ED /* main.js in Resources */ = {isa = PBXBuildFile; fileRef = 4214C33B20B3EEAE005EC1ED /* main.js */; }; + 4214C34120B3FF9F005EC1ED /* clipboard_plugin.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4214C33F20B3FF9F005EC1ED /* clipboard_plugin.mm */; }; + 4214C34920B98EFD005EC1ED /* lynx_thread_impl.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4214C34720B98EFC005EC1ED /* lynx_thread_impl.cc */; }; + 4214C34E20BFEAC2005EC1ED /* plugin_server_impl.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4214C34A20BFEAC1005EC1ED /* plugin_server_impl.cc */; }; + 4214C34F20BFEAC2005EC1ED /* plugin_client.cc in Sources */ = {isa = PBXBuildFile; fileRef = 4214C34C20BFEAC1005EC1ED /* plugin_client.cc */; }; 42178E7F20994E7B001B8A48 /* builtin.cc in Sources */ = {isa = PBXBuildFile; fileRef = 42177F5B20994E6A001B8A48 /* builtin.cc */; }; 42178E8020994E7B001B8A48 /* table.cc in Sources */ = {isa = PBXBuildFile; fileRef = 42177F5C20994E6A001B8A48 /* table.cc */; }; 42178E8120994E7B001B8A48 /* function.cc in Sources */ = {isa = PBXBuildFile; fileRef = 42177F5F20994E6A001B8A48 /* function.cc */; }; @@ -465,17 +468,23 @@ 4214C31620B17EEC005EC1ED /* CoreTelephony.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreTelephony.framework; path = System/Library/Frameworks/CoreTelephony.framework; sourceTree = SDKROOT; }; 4214C31F20B2D4D3005EC1ED /* netinfo.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = netinfo.js; sourceTree = ""; }; 4214C32120B2D4D3005EC1ED /* clipboard.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = clipboard.js; sourceTree = ""; }; - 4214C32220B2D4D3005EC1ED /* plugin.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = plugin.js; sourceTree = ""; }; - 4214C32420B2D4D3005EC1ED /* plugin_builder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = plugin_builder.h; sourceTree = ""; }; - 4214C32520B2D4D3005EC1ED /* plugin_manager.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = plugin_manager.cc; sourceTree = ""; }; 4214C32620B2D4D3005EC1ED /* plugin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = plugin.h; sourceTree = ""; }; 4214C32720B2D4D3005EC1ED /* plugin.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = plugin.cc; sourceTree = ""; }; - 4214C32920B2D4D3005EC1ED /* plugin_builder.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = plugin_builder.mm; sourceTree = ""; }; 4214C32A20B2D4D3005EC1ED /* plugin_impl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = plugin_impl.h; sourceTree = ""; }; 4214C32B20B2D4D3005EC1ED /* plugin_impl.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = plugin_impl.mm; sourceTree = ""; }; - 4214C32D20B2D4D3005EC1ED /* plugin_manager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = plugin_manager.h; sourceTree = ""; }; 4214C33720B2D5D3005EC1ED /* net_info_plugin.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = net_info_plugin.mm; sourceTree = ""; }; 4214C33820B2D5D3005EC1ED /* net_info_plugin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = net_info_plugin.h; sourceTree = ""; }; + 4214C33A20B3EEAE005EC1ED /* exec.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = exec.js; sourceTree = ""; }; + 4214C33B20B3EEAE005EC1ED /* main.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = main.js; sourceTree = ""; }; + 4214C33F20B3FF9F005EC1ED /* clipboard_plugin.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = clipboard_plugin.mm; sourceTree = ""; }; + 4214C34020B3FF9F005EC1ED /* clipboard_plugin.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = clipboard_plugin.h; sourceTree = ""; }; + 4214C34720B98EFC005EC1ED /* lynx_thread_impl.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = lynx_thread_impl.cc; sourceTree = ""; }; + 4214C34820B98EFC005EC1ED /* lynx_thread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lynx_thread.h; sourceTree = ""; }; + 4214C34A20BFEAC1005EC1ED /* plugin_server_impl.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = plugin_server_impl.cc; sourceTree = ""; }; + 4214C34B20BFEAC1005EC1ED /* plugin_server.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = plugin_server.h; sourceTree = ""; }; + 4214C34C20BFEAC1005EC1ED /* plugin_client.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = plugin_client.cc; sourceTree = ""; }; + 4214C34D20BFEAC1005EC1ED /* plugin_client.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = plugin_client.h; sourceTree = ""; }; + 4214C35020C130F3005EC1ED /* completion_event.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = completion_event.h; sourceTree = ""; }; 42177F5920994E6A001B8A48 /* semantic_analysis.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = semantic_analysis.h; sourceTree = ""; }; 42177F5A20994E6A001B8A48 /* utils.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = utils.h; sourceTree = ""; }; 42177F5B20994E6A001B8A48 /* builtin.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = builtin.cc; sourceTree = ""; }; @@ -1041,9 +1050,12 @@ 4214C31A20B2D4D3005EC1ED /* plugin */ = { isa = PBXGroup; children = ( - 4214C31B20B2D4D3005EC1ED /* impl */, - 4214C32220B2D4D3005EC1ED /* plugin.js */, + 4214C34C20BFEAC1005EC1ED /* plugin_client.cc */, + 4214C34D20BFEAC1005EC1ED /* plugin_client.h */, + 4214C34A20BFEAC1005EC1ED /* plugin_server_impl.cc */, + 4214C34B20BFEAC1005EC1ED /* plugin_server.h */, 4214C32320B2D4D3005EC1ED /* base */, + 4214C31B20B2D4D3005EC1ED /* impl */, ); path = plugin; sourceTree = ""; @@ -1051,6 +1063,8 @@ 4214C31B20B2D4D3005EC1ED /* impl */ = { isa = PBXGroup; children = ( + 4214C33A20B3EEAE005EC1ED /* exec.js */, + 4214C33B20B3EEAE005EC1ED /* main.js */, 4214C32020B2D4D3005EC1ED /* clipboard */, 4214C31C20B2D4D3005EC1ED /* net_info */, ); @@ -1069,6 +1083,7 @@ 4214C32020B2D4D3005EC1ED /* clipboard */ = { isa = PBXGroup; children = ( + 4214C33E20B3FF9F005EC1ED /* ios */, 4214C32120B2D4D3005EC1ED /* clipboard.js */, ); path = clipboard; @@ -1077,12 +1092,9 @@ 4214C32320B2D4D3005EC1ED /* base */ = { isa = PBXGroup; children = ( - 4214C32420B2D4D3005EC1ED /* plugin_builder.h */, - 4214C32520B2D4D3005EC1ED /* plugin_manager.cc */, - 4214C32620B2D4D3005EC1ED /* plugin.h */, - 4214C32720B2D4D3005EC1ED /* plugin.cc */, 4214C32820B2D4D3005EC1ED /* ios */, - 4214C32D20B2D4D3005EC1ED /* plugin_manager.h */, + 4214C32720B2D4D3005EC1ED /* plugin.cc */, + 4214C32620B2D4D3005EC1ED /* plugin.h */, ); path = base; sourceTree = ""; @@ -1090,7 +1102,6 @@ 4214C32820B2D4D3005EC1ED /* ios */ = { isa = PBXGroup; children = ( - 4214C32920B2D4D3005EC1ED /* plugin_builder.mm */, 4214C32A20B2D4D3005EC1ED /* plugin_impl.h */, 4214C32B20B2D4D3005EC1ED /* plugin_impl.mm */, ); @@ -1106,9 +1117,28 @@ path = ios; sourceTree = ""; }; + 4214C33E20B3FF9F005EC1ED /* ios */ = { + isa = PBXGroup; + children = ( + 4214C33F20B3FF9F005EC1ED /* clipboard_plugin.mm */, + 4214C34020B3FF9F005EC1ED /* clipboard_plugin.h */, + ); + path = ios; + sourceTree = ""; + }; + 4214C34620B98EFC005EC1ED /* content */ = { + isa = PBXGroup; + children = ( + 4214C34720B98EFC005EC1ED /* lynx_thread_impl.cc */, + 4214C34820B98EFC005EC1ED /* lynx_thread.h */, + ); + path = content; + sourceTree = ""; + }; 42177F3F20994E6A001B8A48 /* Core */ = { isa = PBXGroup; children = ( + 4214C34620B98EFC005EC1ED /* content */, 4214C31A20B2D4D3005EC1ED /* plugin */, 421795E520994EEA001B8A48 /* third_party */, 42177F5820994E6A001B8A48 /* lepus */, @@ -1677,6 +1707,7 @@ 42178E3020994E7A001B8A48 /* threading */ = { isa = PBXGroup; children = ( + 4214C35020C130F3005EC1ED /* completion_event.h */, 42178E3120994E7A001B8A48 /* message_pump_posix.cc */, 42178E3320994E7A001B8A48 /* message_loop.h */, 42178E3420994E7A001B8A48 /* condition.h */, @@ -2222,14 +2253,15 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( + 4214C33D20B3EEAE005EC1ED /* main.js in Resources */, 425BCA0320A69F3E008AAFC0 /* gtest-param-util-generated.h.pump in Resources */, 4217A90220994F04001B8A48 /* sconscript in Resources */, 4217A90420994F04001B8A48 /* json_valueiterator.inl in Resources */, - 4214C33120B2D4D3005EC1ED /* plugin.js in Resources */, 4217A90520994F04001B8A48 /* init.sh in Resources */, 4214C33020B2D4D3005EC1ED /* clipboard.js in Resources */, 4214C32F20B2D4D3005EC1ED /* netinfo.js in Resources */, 4217A90020994F04001B8A48 /* version.h.in in Resources */, + 4214C33C20B3EEAE005EC1ED /* exec.js in Resources */, BC9D343A1E1DEC92009BD30A /* Assets.xcassets in Resources */, 425BCA0120A69F3E008AAFC0 /* gtest-tuple.h.pump in Resources */, 4217A8D320994F04001B8A48 /* CMakeLists.txt in Resources */, @@ -2504,9 +2536,11 @@ buildActionMask = 2147483647; files = ( BC5DBDB41F5EC7BE005A47E3 /* view_wrapper.mm in Sources */, + 4214C34E20BFEAC2005EC1ED /* plugin_server_impl.cc in Sources */, 4214C33520B2D4D3005EC1ED /* plugin_impl.mm in Sources */, 421438E5207DE59F00ECF750 /* coordinator_pretreatment.mm in Sources */, 42178E8B20994E7B001B8A48 /* url_request_context.cc in Sources */, + 4214C34120B3FF9F005EC1ED /* clipboard_plugin.mm in Sources */, BC31B01D1F6271BE00C0234C /* ui_event_action.mm in Sources */, 421795AB20994E84001B8A48 /* source_cache_manager.cc in Sources */, 421795AE20994E84001B8A48 /* html_loader.cc in Sources */, @@ -2522,6 +2556,7 @@ 42178F2B20994E7B001B8A48 /* render_tree_host.cc in Sources */, 4217A90120994F04001B8A48 /* json_reader.cpp in Sources */, 421795BE20994E84001B8A48 /* time_utils.cc in Sources */, + 4214C34F20BFEAC2005EC1ED /* plugin_client.cc in Sources */, BCDEC7BE209C5168000B0D50 /* prototype_builder.cc in Sources */, 421795CE20994E85001B8A48 /* string_utils.cc in Sources */, 42178F0F20994E7B001B8A48 /* jsc_helper.cc in Sources */, @@ -2578,7 +2613,6 @@ 42178F0520994E7B001B8A48 /* element.cc in Sources */, 42178F2120994E7B001B8A48 /* command_collector.cc in Sources */, BC31B0291F6284D200C0234C /* render_tree_host_impl_bridge.mm in Sources */, - 4214C33220B2D4D3005EC1ED /* plugin_manager.cc in Sources */, 421795BA20994E84001B8A48 /* select_poller.cc in Sources */, BCDEC7D8209C518C000B0D50 /* class_template.cc in Sources */, 42178F4320994E7B001B8A48 /* input_stream.cc in Sources */, @@ -2592,6 +2626,7 @@ 421795DE20994E85001B8A48 /* memory_tracker.cc in Sources */, BC31B01A1F6264E600C0234C /* ui_factory.mm in Sources */, 42178F2620994E7B001B8A48 /* coordinator_executor.cc in Sources */, + 4214C34920B98EFD005EC1ED /* lynx_thread_impl.cc in Sources */, 42178ECB20994E7B001B8A48 /* net_errors.cc in Sources */, 42178F3D20994E7B001B8A48 /* view_stub.cc in Sources */, 42178F2520994E7B001B8A48 /* coordinator_action.cc in Sources */, @@ -2646,7 +2681,6 @@ 421795D020994E85001B8A48 /* string_number_convert.cc in Sources */, 421795B920994E84001B8A48 /* utility.cc in Sources */, 42178EDB20994E7B001B8A48 /* css_color.cc in Sources */, - 4214C33420B2D4D3005EC1ED /* plugin_builder.mm in Sources */, BC31B0161F624F6D00C0234C /* lynx_ui_body.mm in Sources */, 42178F2F20994E7B001B8A48 /* extended_view.cc in Sources */, 421438E8207DE59F00ECF750 /* coordinator_action_executor.mm in Sources */, @@ -2912,6 +2946,7 @@ "DEBUG=1", "IOS=1", "OS_IOS=1", + "PLUGIN_ENABLE=1", ); HEADER_SEARCH_PATHS = ( "$(inherited)", @@ -2957,6 +2992,7 @@ "$(inherited)", "SD_WEBP=1", "OS_IOS=1", + "PLUGIN_ENABLE=1", ); HEADER_SEARCH_PATHS = ( "$(inherited)", diff --git a/iOS/lynx/app_delegate.mm b/iOS/lynx/app_delegate.mm index 63b5338f..0c67ec18 100644 --- a/iOS/lynx/app_delegate.mm +++ b/iOS/lynx/app_delegate.mm @@ -6,6 +6,9 @@ #include "lynx_view_controller.h" #include "debugger/debug_client.h" #include "debugger/ios/debug_host_impl.h" +#include "plugin/plugin_server.h" +#include "content/lynx_thread.h" +#include "runtime/js/js_vm.h" @interface LxAppDelegate () @@ -30,9 +33,13 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( if([appInfo debugable]) { debug::DebugClient::Debugger()->Initialize(lynx_new debug::DebugHostImpl); } + content::LynxThread::Initialize(); + plugin::PluginServer::Initialize(); + //jscore::JSVM::Instance()->Initialize(); UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:[[LynxViewController alloc] initWithName:appInfo.mainPage]]; self.window.rootViewController = navController; + [self.window makeKeyAndVisible];