/*virtual*/ void PCLDepthToMeters::_Initialize (const Arguments& parameters) { CheckParameters (parameters, _parameters); _parameters = _runtime.CopyArguments (parameters); _input_args.push_back (ShortMatrix (GetRuntime()).SetName ("DepthMatrix").SetDescription ("Depth matrix")); _output_args.push_back (DoubleMatrix (GetRuntime()).SetName ("MetersMatrix").SetDescription ("Real world coordinates matrix in meters")); }
/*virtual*/ void PCLDepthToRealWorld::_Initialize (const Arguments& parameters) { CheckParameters (parameters, _parameters); _parameters = _runtime.CopyArguments (parameters); _input_args.push_back (ShortMatrix (GetRuntime()).SetName ("DepthMatrix").SetDescription ("Depth matrix")); _output_args.push_back (XYZArray (GetRuntime()).SetName ("XYZMeters").SetDescription ("(x,y,z)-array in real world coordinates in meters")); }
void ScriptInterface::DumpHeap() { #if MOZJS_DEBUG_ABI JS_DumpHeap(m->m_cx, stderr, NULL, 0, NULL, (size_t)-1, NULL); #endif fprintf(stderr, "# Bytes allocated: %u\n", JS_GetGCParameter(GetRuntime(), JSGC_BYTES)); JS_GC(m->m_cx); fprintf(stderr, "# Bytes allocated after GC: %u\n", JS_GetGCParameter(GetRuntime(), JSGC_BYTES)); }
void XPCWrappedNativeScope::RemoveWrappedNativeProtos() { XPCAutoLock al(mRuntime->GetMapLock()); mWrappedNativeProtoMap->Enumerate(WNProtoRemover, GetRuntime()->GetDetachedWrappedNativeProtoMap()); mMainThreadWrappedNativeProtoMap->Enumerate(WNProtoRemover, GetRuntime()->GetDetachedWrappedNativeProtoMap()); }
OP_STATUS DOM_FeedList::GetItem(UINT idx, ES_Value *value) { UINT len = 0; UINT* map = g_webfeeds_api->GetAllFeedIds(len, m_subscribed_only); if (idx < len) { if (OpFeed *feed = g_webfeeds_api->GetFeedById(map[idx])) { OP_DELETEA(map); DOM_HOSTOBJECT_SAFE(dom_feed, feed->GetDOMObject(GetEnvironment()), DOM_TYPE_FEED, DOM_Feed); if (!dom_feed) { OP_STATUS oom = DOM_Feed::Make(dom_feed, feed, GetRuntime()); if (OpStatus::IsError(oom)) return oom; } DOMSetObject(value, dom_feed); return OpStatus::OK; } } OP_DELETEA(map); DOMSetNull(value); return OpStatus::OK; }
void XPCWrappedNativeProto::JSProtoObjectFinalized(js::FreeOp *fop, JSObject *obj) { NS_ASSERTION(obj == mJSProtoObject, "huh?"); // Map locking is not necessary since we are running gc. // Only remove this proto from the map if it is the one in the map. ClassInfo2WrappedNativeProtoMap* map = GetScope()->GetWrappedNativeProtoMap(ClassIsMainThreadOnly()); if (map->Find(mClassInfo) == this) map->Remove(mClassInfo); GetRuntime()->GetDetachedWrappedNativeProtoMap()->Remove(this); GetRuntime()->GetDyingWrappedNativeProtoMap()->Add(this); mJSProtoObject.finalize(js::CastToJSFreeOp(fop)->runtime()); }
GlobalTimer::~GlobalTimer() { if (!m_nTimerID) return; if (GetRuntime()) m_pFormFillEnv->GetSysHandler()->KillTimer(m_nTimerID); GetGlobalTimerMap()->erase(m_nTimerID); }
/* virtual */ void DOM_JILRadioInfo::OnRadioSourceChanged(OpTelephonyNetworkInfo::RadioSignalSource radio_source, BOOL is_roaming) { if (m_on_radio_source_changed) { ES_AsyncInterface* async_iface = GetRuntime()->GetEnvironment()->GetAsyncInterface(); ES_Value argv[2]; DOMSetString(&(argv[0]), RadioSignalSourceValueToString(radio_source)); DOMSetBoolean(&(argv[1]), is_roaming); async_iface->CallFunction(m_on_radio_source_changed, GetNativeObject(), sizeof(argv) / sizeof(argv[0]), argv, NULL, NULL); } }
/* virtual */ BOOL DOM_HTMLDocument::SecurityCheck(OpAtom property_name, ES_Value *value, ES_Runtime *origining_runtime) { switch (OriginLoadCheck(GetRuntime(), origining_runtime)) { case YES: return TRUE; case MAYBE: return property_name == OP_ATOM_location || property_name == OP_ATOM_document || property_name == OP_ATOM_readyState; } return FALSE; }
void XPCWrappedNativeProto::JSProtoObjectFinalized(JSContext *cx, JSObject *obj) { NS_ASSERTION(obj == mJSProtoObject, "huh?"); // Map locking is not necessary since we are running gc. if(IsShared()) { // Only remove this proto from the map if it is the one in the map. ClassInfo2WrappedNativeProtoMap* map = GetScope()->GetWrappedNativeProtoMap(ClassIsMainThreadOnly()); if(map->Find(mClassInfo) == this) map->Remove(mClassInfo); } GetRuntime()->GetDetachedWrappedNativeProtoMap()->Remove(this); GetRuntime()->GetDyingWrappedNativeProtoMap()->Add(this); mJSProtoObject = nsnull; }
void DOM_JILMediaPlayer::SetState(PlayerState state) { m_state = state; if (m_on_mediaplayer_state_changed) { ES_AsyncInterface* async_iface = GetRuntime()->GetEnvironment()->GetAsyncInterface(); ES_Value argv[1]; OP_ASSERT(state >= PLAYER_STATE_FIRST); OP_ASSERT(state < PLAYER_STATE_LAST); OP_ASSERT(m_state_strings[m_state]); DOMSetString(&(argv[0]), m_state_strings[m_state]); async_iface->CallFunction(m_on_mediaplayer_state_changed, GetNativeObject(), sizeof(argv) / sizeof(argv[0]), argv, NULL, NULL); } }
OP_STATUS DOM_ApplicationCache::OnEvent(DOM_EventType event_type, BOOL lengthComputable, OpFileLength loaded, OpFileLength total) { // Check that the event type is relevant to the application cache OP_ASSERT(IsValidEventType(event_type)); DOM_Runtime* runtime = GetRuntime(); OP_ASSERT(runtime); DOM_Event *event = NULL; if (event_type == ONPROGRESS) { RETURN_IF_ERROR(DOMSetObjectRuntime(event = OP_NEW(DOM_ApplicationCacheProgressEvent, ()), runtime, runtime->GetPrototype(DOM_Runtime::PROGRESSEVENT_PROTOTYPE), "ProgressEvent")); static_cast<DOM_ProgressEvent*>(event)->InitProgressEvent(lengthComputable, loaded, total); }
RampToGray::RampToGray(Runtime& runtime): Base(runtime) { StringSelection typesel(GetRuntime()); typesel.SetName ("Ramp") .SetDescription ("type of ramp") .SetCount (1); typesel.CreateData(); typesel.SetSymbols (0, "JET"); typesel.SetIndex (0); _parameters.push_back (typesel); _act_params = _parameters; _input_args.push_back (ByteImage(runtime).SetName("Input image").SetDescription("Arbitrary single-page input image").SetChannels(3)); _output_args.push_back (ByteImage(runtime).SetName("Output image").SetDescription("Grayscale output image").SetChannels(1)); InitColourModel(); }
OP_STATUS DOM_JILRadioInfo::CreateRadioSignalSourceTypes() { ES_Object* radio_signal_sources; RETURN_IF_ERROR(GetRuntime()->CreateNativeObjectObject(&radio_signal_sources)); ES_Value value; DOMSetString(&value, UNI_L("cdma")); RETURN_IF_ERROR(GetRuntime()->PutName(radio_signal_sources, UNI_L("CDMA"), value, PROP_READ_ONLY | PROP_DONT_DELETE)); DOMSetString(&value, UNI_L("gsm")); RETURN_IF_ERROR(GetRuntime()->PutName(radio_signal_sources, UNI_L("GSM"), value, PROP_READ_ONLY | PROP_DONT_DELETE)); DOMSetString(&value, UNI_L("lte")); RETURN_IF_ERROR(GetRuntime()->PutName(radio_signal_sources, UNI_L("LTE"), value, PROP_READ_ONLY | PROP_DONT_DELETE)); DOMSetString(&value, UNI_L("tdscdma")); RETURN_IF_ERROR(GetRuntime()->PutName(radio_signal_sources, UNI_L("TDSCDMA"), value, PROP_READ_ONLY | PROP_DONT_DELETE)); DOMSetString(&value, UNI_L("wcdma")); RETURN_IF_ERROR(GetRuntime()->PutName(radio_signal_sources, UNI_L("WCDMA"), value, PROP_READ_ONLY | PROP_DONT_DELETE)); DOMSetObject(&value, radio_signal_sources); RETURN_IF_ERROR(GetRuntime()->PutName(GetNativeObject(), UNI_L("RadioSignalSourceTypes"), value, PROP_READ_ONLY | PROP_DONT_DELETE)); return OpStatus::OK; }
/* virtual */ ES_PutState JS_Location::PutName(OpAtom property_name, ES_Value* value, ES_Runtime* origining_runtime) { if (GetName(property_name, NULL, origining_runtime) != GET_SUCCESS) return PUT_FAILED; FramesDocument *frames_doc = GetFramesDocument(); if (!frames_doc) return PUT_SUCCESS; if (value->type != VALUE_STRING) return PUT_NEEDS_STRING; const uni_char *value_string = value->value.string; while (value_string[0] == ' ') ++value_string; if (property_name == OP_ATOM_href) if (value_string[0] == '#') property_name = OP_ATOM_hash; else if (value_string[0] == '?') property_name = OP_ATOM_search; URL url; DocumentReferrer ref_url(GetStandardRefURL(frames_doc, origining_runtime)); TempBuffer buffer; URL current_url = ref_url.url; #ifdef SELFTEST if (!do_navigation) current_url = this->current_url; #endif // SELFTEST switch (property_name) { case OP_ATOM_href: case OP_ATOM_protocol: case OP_ATOM_host: case OP_ATOM_hostname: case OP_ATOM_port: case OP_ATOM_pathname: BOOL allowed; if (OpStatus::IsError(OpSecurityManager::CheckSecurity(OpSecurityManager::DOM_ALLOWED_TO_NAVIGATE, static_cast<DOM_Runtime *>(origining_runtime), GetRuntime(), allowed)) || !allowed) return PUT_SECURITY_VIOLATION; } switch (property_name) { case OP_ATOM_protocol: { unsigned length = uni_strlen(value_string); while (length > 0 && value_string[length - 1] == ':') length--; if (length > 0) { const uni_char *current_url_string = current_url.GetAttribute(URL::KUniName_Username_Password_NOT_FOR_UI).CStr(); const uni_char *current_scheme_end = uni_strchr(current_url_string, ':'); if (!current_scheme_end) return PUT_SUCCESS; PUT_FAILED_IF_ERROR(buffer.Append(value_string, length)); PUT_FAILED_IF_ERROR(buffer.Append(current_scheme_end)); url = GetEncodedURL(origining_runtime->GetFramesDocument(), buffer.GetStorage()); BOOL allowed; if (url.Type() == URL_JAVASCRIPT) if (OpStatus::IsError(OpSecurityManager::CheckSecurity(OpSecurityManager::DOM_STANDARD, static_cast<DOM_Runtime *>(origining_runtime), GetRuntime(), allowed)) || !allowed) return PUT_SUCCESS; } break; } case OP_ATOM_host: { const uni_char *current_url_string = current_url.GetAttribute(URL::KUniName_Username_Password_NOT_FOR_UI).CStr(); const uni_char *current_scheme_end = uni_strchr(current_url_string, ':'); // URL must be an "authority-based URL" if (current_scheme_end && current_scheme_end[1] == '/' && current_scheme_end[2] == '/') { OpString hostname; PUT_FAILED_IF_ERROR(current_url.GetAttribute(URL::KUniHostName, hostname)); /* Just bail if the URL doesn't have a hostname after all. */ if (!hostname.CStr()) return PUT_SUCCESS; uni_char *hostname_start = uni_strstr(current_url_string, hostname.CStr()); OP_ASSERT(hostname_start); uni_char *hostname_end = hostname_start + hostname.Length(); unsigned short port = current_url.GetAttribute(URL::KServerPort); if (port > 0 && *hostname_end == ':') { hostname_end++; while (uni_isdigit(*hostname_end)) hostname_end++; } PUT_FAILED_IF_ERROR(buffer.Append(current_url_string, hostname_start - current_url_string)); PUT_FAILED_IF_ERROR(buffer.Append(value_string)); PUT_FAILED_IF_ERROR(buffer.Append(hostname_end)); url = GetEncodedURL(origining_runtime->GetFramesDocument(), buffer.GetStorage()); } break; } case OP_ATOM_hostname: { while (*value_string == '/') value_string++; const uni_char *current_url_string = current_url.GetAttribute(URL::KUniName_Username_Password_NOT_FOR_UI).CStr(); const uni_char *current_scheme_end = uni_strchr(current_url_string, ':'); // URL must be an "authority-based URL" if (*value_string && current_scheme_end && current_scheme_end[1] == '/' && current_scheme_end[2] == '/') { OpString hostname; PUT_FAILED_IF_ERROR(current_url.GetAttribute(URL::KUniHostName, hostname)); /* Just bail if the URL doesn't have a hostname after all. */ if (!hostname.CStr()) return PUT_SUCCESS; uni_char *hostname_start = uni_strstr(current_url_string, hostname.CStr()); OP_ASSERT(hostname_start); uni_char *hostname_end = hostname_start + hostname.Length(); PUT_FAILED_IF_ERROR(buffer.Append(current_url_string, hostname_start - current_url_string)); PUT_FAILED_IF_ERROR(buffer.Append(value_string)); PUT_FAILED_IF_ERROR(buffer.Append(hostname_end)); url = GetEncodedURL(origining_runtime->GetFramesDocument(), buffer.GetStorage()); } break; } case OP_ATOM_port: { const uni_char *current_url_string = current_url.GetAttribute(URL::KUniName_Username_Password_NOT_FOR_UI).CStr(); const uni_char *current_scheme_end = uni_strchr(current_url_string, ':'); // URL must be an "authority-based URL" if (current_scheme_end && current_scheme_end[1] == '/' && current_scheme_end[2] == '/') { while (*value_string == '0') value_string++; int port = 0; if (uni_isdigit(*value_string)) port = uni_atoi(value_string); if (port <= 0 || port > 65535) break; OpString hostname; PUT_FAILED_IF_ERROR(current_url.GetAttribute(URL::KUniHostName, hostname)); /* Just bail if the URL doesn't have a hostname after all. */ if (!hostname.CStr()) return PUT_SUCCESS; uni_char *hostname_start = uni_strstr(current_scheme_end, hostname.CStr()); OP_ASSERT(hostname_start); uni_char *hostname_end = hostname_start + hostname.Length(); PUT_FAILED_IF_ERROR(buffer.Append(current_url_string, hostname_end - current_url_string)); PUT_FAILED_IF_ERROR(buffer.Append(":")); if (*hostname_end == ':') { hostname_end++; while (uni_isdigit(*hostname_end)) hostname_end++; } PUT_FAILED_IF_ERROR(buffer.AppendLong(port)); PUT_FAILED_IF_ERROR(buffer.Append(hostname_end)); url = GetEncodedURL(origining_runtime->GetFramesDocument(), buffer.GetStorage()); } break; } case OP_ATOM_href: case OP_ATOM_pathname: { url = GetEncodedURL(origining_runtime->GetFramesDocument(), value_string); BOOL allowed; // Stricter security for javascript urls. It's possible this check should move into DocumentManager in the future. if (url.Type() == URL_JAVASCRIPT) if (OpStatus::IsError(OpSecurityManager::CheckSecurity(OpSecurityManager::DOM_STANDARD, static_cast<DOM_Runtime *>(origining_runtime), GetRuntime(), allowed)) || !allowed) return PUT_SUCCESS; break; } case OP_ATOM_search: { const uni_char *current_url_string = current_url.GetAttribute(URL::KUniName_Username_Password_NOT_FOR_UI).CStr(); int current_len; const uni_char *current_search_start = uni_strchr(current_url_string, '?'); if (current_search_start) current_len = current_search_start - current_url_string; else current_len = uni_strlen(current_url_string); if (value_string[0] == '?') ++value_string; PUT_FAILED_IF_ERROR(buffer.Expand(current_len + uni_strlen(value_string) + 2)); OpStatus::Ignore(buffer.Append(current_url_string, current_len)); // buffer is successfully expanded above OpStatus::Ignore(buffer.Append("?")); OpStatus::Ignore(buffer.Append(value_string)); url = GetEncodedURL(origining_runtime->GetFramesDocument(), buffer.GetStorage()); break; } case OP_ATOM_hash: if (value_string[0] == '#') ++value_string; // Strip trailing whitespace if (unsigned length = uni_strlen(value_string)) { if (value_string[length - 1] == ' ') { PUT_FAILED_IF_ERROR(buffer.Append(value_string)); uni_char *string = buffer.GetStorage(); while (length > 0 && string[length - 1] == ' ') --length; string[length] = 0; value_string = string; } } #ifdef SELFTEST url = URL(!do_navigation ? current_url : frames_doc->GetURL(), value_string); #else url = URL(frames_doc->GetURL(), value_string); #endif // SELFTEST break; } if (url.Type() != URL_NULL_TYPE) { #ifdef GADGET_SUPPORT switch (property_name) { case OP_ATOM_href: case OP_ATOM_protocol: case OP_ATOM_host: case OP_ATOM_hostname: case OP_ATOM_port: case OP_ATOM_pathname: { BOOL allowed; if (frames_doc->GetWindow()->GetGadget()) if (OpStatus::IsError(OpSecurityManager::CheckSecurity(OpSecurityManager::GADGET_ALLOWED_TO_NAVIGATE, OpSecurityContext(frames_doc), url, allowed)) || !allowed) return PUT_SECURITY_VIOLATION; } } #endif // GADGET_SUPPORT return SetTheURL(frames_doc, ref_url, url, GetCurrentThread(origining_runtime), property_name == OP_ATOM_hash); } else return PUT_SUCCESS; }
DOM_MessagePort* DOM_BrowserTab::GetPort() { if (!m_port || !m_port->IsEntangled()) { if (!m_window_id) return NULL; m_port = NULL; // The previous port will be garbage collected. Window* window = GetTabWindow(); if (DOM_ExtensionScope* scope = m_extension_support->GetExtensionGlobalScope(window)) OpStatus::Ignore(DOM_ExtensionSupport::GetPortTarget(scope->GetExtension()->GetPort(), m_port, GetRuntime())); } OP_ASSERT(!m_port || m_port->IsEntangled()); return m_port; }
CJS_Timer::~CJS_Timer() { CJS_Runtime* pRuntime = GetRuntime(); if (pRuntime) pRuntime->RemoveObserver(this); KillJSTimer(); }
/* virtual */ ES_PutState DOM_HTMLDocument::PutName(OpAtom property_name, ES_Value* value, ES_Runtime* origining_runtime) { ES_GetState state; ES_Value value2; switch(property_name) { case OP_ATOM_title: if (value->type != VALUE_STRING) return PUT_NEEDS_STRING; else return SetTitle(value, origining_runtime); case OP_ATOM_body: if (value->type != VALUE_OBJECT || !root) return DOM_PUTNAME_DOMEXCEPTION(HIERARCHY_REQUEST_ERR); else return ((DOM_HTMLElement *) root)->PutChildElement(OP_ATOM_body, value, (DOM_Runtime *) origining_runtime, NULL); case OP_ATOM_bgColor: case OP_ATOM_fgColor: case OP_ATOM_linkColor: case OP_ATOM_alinkColor: case OP_ATOM_vlinkColor: state = GetName(OP_ATOM_body, &value2, origining_runtime); if (state == GET_NO_MEMORY) return PUT_NO_MEMORY; else if (state == GET_SUCCESS && value2.type == VALUE_OBJECT) { DOM_Node *node = DOM_VALUE2OBJECT(value2, DOM_Node); if (property_name == OP_ATOM_fgColor) property_name = OP_ATOM_text; else if (property_name == OP_ATOM_linkColor) property_name = OP_ATOM_link; else if (property_name == OP_ATOM_alinkColor) property_name = OP_ATOM_aLink; else if (property_name == OP_ATOM_vlinkColor) property_name = OP_ATOM_vLink; if (value->type == VALUE_NULL) DOMSetString(value); return node->PutName(property_name, value, origining_runtime); } return PUT_SUCCESS; case OP_ATOM_domain: if (value->type != VALUE_STRING) return PUT_NEEDS_STRING; else { OP_STATUS status = GetRuntime()->SetDomainChecked(value->value.string); if (OpStatus::IsMemoryError(status)) return PUT_NO_MEMORY; else if (OpStatus::IsError(status)) return PUT_SECURITY_VIOLATION; else return PUT_SUCCESS; } case OP_ATOM_head: return PUT_SUCCESS; case OP_ATOM_URL: case OP_ATOM_images: case OP_ATOM_applets: case OP_ATOM_links: case OP_ATOM_embeds: case OP_ATOM_forms: case OP_ATOM_anchors: case OP_ATOM_compatMode: return PUT_READ_ONLY; } return DOM_Document::PutName (property_name, value, origining_runtime); }
ES_GetState DOM_BrowserTab::GetTabInfo(OpAtom property_name, ES_Value* value, ES_Runtime* origining_runtime, ES_Object* restart_object) { if (!value) return GET_SUCCESS; // Private mode can be obtained synchronously if we have window. if (property_name == OP_ATOM_private) { Window* window = GetTabWindow(); if (window) { DOMSetBoolean(value, window->GetPrivacyMode()); return GET_SUCCESS; } } OP_ASSERT(GetTabId()); DOM_TabsApiHelper* call_helper; if (!restart_object) { GET_FAILED_IF_ERROR(DOM_TabsApiHelper::Make(call_helper, static_cast<DOM_Runtime*>(origining_runtime))); call_helper->QueryTab(GetTabId()); } else call_helper = DOM_HOSTOBJECT(restart_object, DOM_TabsApiHelper); if (call_helper->IsFinished()) { if (property_name == OP_ATOM_closed) { DOMSetBoolean(value, OpStatus::IsError(call_helper->GetStatus())); return GET_SUCCESS; } else GET_FAILED_IF_ERROR(call_helper->GetStatus()); switch (property_name) { case OP_ATOM_browserWindow: DOM_BrowserWindow* new_win; GET_FAILED_IF_ERROR(DOM_TabApiCache::GetOrCreateWindow(new_win, m_extension_support, call_helper->GetResult().value.query_tab.browser_window_id, GetRuntime())); DOMSetObject(value, new_win); break; case OP_ATOM_locked: DOMSetBoolean(value, call_helper->GetResult().value.query_tab.is_locked); break; case OP_ATOM_position: DOMSetNumber(value, call_helper->GetResult().value.query_tab.position); break; case OP_ATOM_tabGroup: if (call_helper->GetResult().value.query_tab.tab_group_id == 0) DOMSetNull(value); else { DOM_BrowserTabGroup* tab_group; GET_FAILED_IF_ERROR(DOM_TabApiCache::GetOrCreateTabGroup(tab_group, m_extension_support, call_helper->GetResult().value.query_tab.tab_group_id, GetRuntime())); DOMSetObject(value, tab_group); } break; case OP_ATOM_focused: case OP_ATOM_selected: DOMSetBoolean(value, call_helper->GetResult().value.query_tab.is_selected); break; case OP_ATOM_title: if (!call_helper->GetResult().value.query_tab.is_private || IsPrivateDataAllowed()) { TempBuffer* tmp = GetEmptyTempBuf(); GET_FAILED_IF_ERROR(tmp->Append(call_helper->GetResult().value.query_tab.title)); DOMSetString(value, tmp); } return GET_SUCCESS; case OP_ATOM_private: DOMSetBoolean(value, call_helper->GetResult().value.query_tab.is_private); return GET_SUCCESS; default: OP_ASSERT(!"Unexpected property"); } return GET_SUCCESS; } else return call_helper->BlockGet(value, origining_runtime); }