NS_IMETHODIMP nsMIMEInputStream::Available(uint64_t *_retval) { INITSTREAMS; return mStream->Available(_retval); }
NS_IMETHOD IsNonBlocking(bool* aNonBlocking) override { return mStream->IsNonBlocking(aNonBlocking); }
nsresult PendingLookup::SendRemoteQueryInternal() { // If we aren't supposed to do remote lookups, bail. if (!Preferences::GetBool(PREF_SB_DOWNLOADS_REMOTE_ENABLED, false)) { LOG(("Remote lookups are disabled [this = %p]", this)); return NS_ERROR_NOT_AVAILABLE; } // If the remote lookup URL is empty or absent, bail. nsCString serviceUrl; NS_ENSURE_SUCCESS(Preferences::GetCString(PREF_SB_APP_REP_URL, &serviceUrl), NS_ERROR_NOT_AVAILABLE); if (serviceUrl.EqualsLiteral("")) { LOG(("Remote lookup URL is empty [this = %p]", this)); return NS_ERROR_NOT_AVAILABLE; } // If the blocklist or allowlist is empty (so we couldn't do local lookups), // bail nsCString table; NS_ENSURE_SUCCESS(Preferences::GetCString(PREF_DOWNLOAD_BLOCK_TABLE, &table), NS_ERROR_NOT_AVAILABLE); if (table.EqualsLiteral("")) { LOG(("Blocklist is empty [this = %p]", this)); return NS_ERROR_NOT_AVAILABLE; } #ifdef XP_WIN // The allowlist is only needed to do signature verification on Windows NS_ENSURE_SUCCESS(Preferences::GetCString(PREF_DOWNLOAD_ALLOW_TABLE, &table), NS_ERROR_NOT_AVAILABLE); if (table.EqualsLiteral("")) { LOG(("Allowlist is empty [this = %p]", this)); return NS_ERROR_NOT_AVAILABLE; } #endif LOG(("Sending remote query for application reputation [this = %p]", this)); // We did not find a local result, so fire off the query to the // application reputation service. nsCOMPtr<nsIURI> uri; nsresult rv; rv = mQuery->GetSourceURI(getter_AddRefs(uri)); NS_ENSURE_SUCCESS(rv, rv); nsCString spec; rv = GetStrippedSpec(uri, spec); NS_ENSURE_SUCCESS(rv, rv); mRequest.set_url(spec.get()); uint32_t fileSize; rv = mQuery->GetFileSize(&fileSize); NS_ENSURE_SUCCESS(rv, rv); mRequest.set_length(fileSize); // We have no way of knowing whether or not a user initiated the // download. Set it to true to lessen the chance of false positives. mRequest.set_user_initiated(true); nsCString locale; NS_ENSURE_SUCCESS(Preferences::GetCString(PREF_GENERAL_LOCALE, &locale), NS_ERROR_NOT_AVAILABLE); mRequest.set_locale(locale.get()); nsCString sha256Hash; rv = mQuery->GetSha256Hash(sha256Hash); NS_ENSURE_SUCCESS(rv, rv); mRequest.mutable_digests()->set_sha256(sha256Hash.Data()); nsString fileName; rv = mQuery->GetSuggestedFileName(fileName); NS_ENSURE_SUCCESS(rv, rv); mRequest.set_file_basename(NS_ConvertUTF16toUTF8(fileName).get()); mRequest.set_download_type(GetDownloadType(fileName)); if (mRequest.signature().trusted()) { LOG(("Got signed binary for remote application reputation check " "[this = %p]", this)); } else { LOG(("Got unsigned binary for remote application reputation check " "[this = %p]", this)); } // Serialize the protocol buffer to a string. This can only fail if we are // out of memory, or if the protocol buffer req is missing required fields // (only the URL for now). std::string serialized; if (!mRequest.SerializeToString(&serialized)) { return NS_ERROR_UNEXPECTED; } LOG(("Serialized protocol buffer [this = %p]: (length=%d) %s", this, serialized.length(), serialized.c_str())); // Set the input stream to the serialized protocol buffer nsCOMPtr<nsIStringInputStream> sstream = do_CreateInstance("@mozilla.org/io/string-input-stream;1", &rv); NS_ENSURE_SUCCESS(rv, rv); rv = sstream->SetData(serialized.c_str(), serialized.length()); NS_ENSURE_SUCCESS(rv, rv); // Set up the channel to transmit the request to the service. nsCOMPtr<nsIChannel> channel; nsCOMPtr<nsIIOService> ios = do_GetService(NS_IOSERVICE_CONTRACTID, &rv); rv = ios->NewChannel2(serviceUrl, nullptr, nullptr, nullptr, // aLoadingNode nsContentUtils::GetSystemPrincipal(), nullptr, // aTriggeringPrincipal nsILoadInfo::SEC_NORMAL, nsIContentPolicy::TYPE_OTHER, getter_AddRefs(channel)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel, &rv)); NS_ENSURE_SUCCESS(rv, rv); // Upload the protobuf to the application reputation service. nsCOMPtr<nsIUploadChannel2> uploadChannel = do_QueryInterface(channel, &rv); NS_ENSURE_SUCCESS(rv, rv); rv = uploadChannel->ExplicitSetUploadStream(sstream, NS_LITERAL_CSTRING("application/octet-stream"), serialized.size(), NS_LITERAL_CSTRING("POST"), false); NS_ENSURE_SUCCESS(rv, rv); // Set the Safebrowsing cookie jar, so that the regular Google cookie is not // sent with this request. See bug 897516. nsCOMPtr<nsIInterfaceRequestor> loadContext = new mozilla::LoadContext(NECKO_SAFEBROWSING_APP_ID); rv = channel->SetNotificationCallbacks(loadContext); NS_ENSURE_SUCCESS(rv, rv); rv = channel->AsyncOpen(this, nullptr); NS_ENSURE_SUCCESS(rv, rv); return NS_OK; }
NS_IMETHOD Available(uint64_t* aLength) override { return mStream->Available(aLength); }
NS_IMETHOD ReadSegments(nsWriteSegmentFun aWriter, void* aClosure, uint32_t aCount, uint32_t *aResult) override { return mStream->ReadSegments(aWriter, aClosure, aCount, aResult); }
NS_IMETHODIMP nsJARInputThunk::Read(char *buf, uint32_t count, uint32_t *countRead) { return mJarStream->Read(buf, count, countRead); }
// Iterates over the files in the "path" directory, and adds subfolders to // parent for each mailbox file found. nsresult nsMsgBrkMBoxStore::AddSubFolders(nsIMsgFolder *parent, nsCOMPtr<nsIFile> &path, bool deep) { nsresult rv; nsCOMPtr<nsIFile> tmp; // at top level so we can safely assign to path bool isDirectory; path->IsDirectory(&isDirectory); if (!isDirectory) { rv = path->Clone(getter_AddRefs(tmp)); path = tmp; NS_ENSURE_SUCCESS(rv, rv); nsAutoString leafName; path->GetLeafName(leafName); leafName.AppendLiteral(".sbd"); path->SetLeafName(leafName); path->IsDirectory(&isDirectory); } if (!isDirectory) return NS_OK; // first find out all the current subfolders and files, before using them // while creating new subfolders; we don't want to modify and iterate the same // directory at once. nsCOMArray<nsIFile> currentDirEntries; nsCOMPtr<nsISimpleEnumerator> directoryEnumerator; rv = path->GetDirectoryEntries(getter_AddRefs(directoryEnumerator)); NS_ENSURE_SUCCESS(rv, rv); bool hasMore; while (NS_SUCCEEDED(directoryEnumerator->HasMoreElements(&hasMore)) && hasMore) { nsCOMPtr<nsISupports> aSupport; directoryEnumerator->GetNext(getter_AddRefs(aSupport)); nsCOMPtr<nsIFile> currentFile(do_QueryInterface(aSupport, &rv)); if (currentFile) currentDirEntries.AppendObject(currentFile); } // add the folders int32_t count = currentDirEntries.Count(); for (int32_t i = 0; i < count; ++i) { nsCOMPtr<nsIFile> currentFile(currentDirEntries[i]); nsAutoString leafName; currentFile->GetLeafName(leafName); directoryEnumerator->HasMoreElements(&hasMore); // here we should handle the case where the current file is a .sbd directory // w/o a matching folder file, or a directory w/o the name .sbd if (nsShouldIgnoreFile(leafName)) continue; nsCOMPtr<nsIMsgFolder> child; rv = parent->AddSubfolder(leafName, getter_AddRefs(child)); if (child) { nsString folderName; child->GetName(folderName); // try to get it from cache/db if (folderName.IsEmpty()) child->SetPrettyName(leafName); if (deep) { nsCOMPtr<nsIFile> path; rv = child->GetFilePath(getter_AddRefs(path)); AddSubFolders(child, path, true); } } } return rv == NS_MSG_FOLDER_EXISTS ? NS_OK : rv; }
NS_IMETHODIMP SocketTransportShim::GetHost(nsACString & aHost) { return mWrapped->GetHost(aHost); }
NS_IMETHODIMP SocketTransportShim::GetTimeout(uint32_t aType, uint32_t *_retval) { return mWrapped->GetTimeout(aType, _retval); }
nsresult RDFContentSinkImpl::GetResourceAttribute(const char16_t** aAttributes, nsIRDFResource** aResource) { nsCOMPtr<nsIAtom> localName; nsAutoString nodeID; for (; *aAttributes; aAttributes += 2) { const nsDependentSubstring& nameSpaceURI = SplitExpatName(aAttributes[0], getter_AddRefs(localName)); // We'll accept `resource' or `rdf:resource', under the spirit // that we should be liberal towards the input that we // receive. if (!nameSpaceURI.IsEmpty() && !nameSpaceURI.EqualsLiteral(RDF_NAMESPACE_URI)) { continue; } // XXX you can't specify both, but we'll just pick up the // first thing that was specified and ignore the other. if (localName == kResourceAtom) { // XXX Take the URI and make it fully qualified by // sticking it into the document's URL. This may not be // appropriate... nsAutoString relURI(aAttributes[1]); if (rdf_RequiresAbsoluteURI(relURI)) { nsresult rv; nsAutoCString uri; rv = mDocumentURL->Resolve(NS_ConvertUTF16toUTF8(aAttributes[1]), uri); if (NS_FAILED(rv)) return rv; return gRDFService->GetResource(uri, aResource); } return gRDFService->GetResource(NS_ConvertUTF16toUTF8(aAttributes[1]), aResource); } else if (localName == kNodeIdAtom) { nodeID.Assign(aAttributes[1]); } } // If nodeID is present, check if we already know about it. If we've seen // the nodeID before, use the same resource, otherwise generate a new one. if (!nodeID.IsEmpty()) { mNodeIDMap.Get(nodeID,aResource); if (!*aResource) { nsresult rv; rv = gRDFService->GetAnonymousResource(aResource); if (NS_FAILED(rv)) { return rv; } mNodeIDMap.Put(nodeID,*aResource); } return NS_OK; } return NS_ERROR_FAILURE; }
void APZEventState::ProcessAPZStateChange(const nsCOMPtr<nsIDocument>& aDocument, ViewID aViewId, APZStateChange aChange, int aArg) { switch (aChange) { case APZStateChange::TransformBegin: { nsIScrollableFrame* sf = nsLayoutUtils::FindScrollableFrameFor(aViewId); if (sf) { sf->SetTransformingByAPZ(true); } nsIScrollbarMediator* scrollbarMediator = do_QueryFrame(sf); if (scrollbarMediator) { scrollbarMediator->ScrollbarActivityStarted(); } if (aDocument && mActiveAPZTransforms == 0) { nsCOMPtr<nsIDocShell> docshell(aDocument->GetDocShell()); if (docshell && sf) { nsDocShell* nsdocshell = static_cast<nsDocShell*>(docshell.get()); nsdocshell->NotifyAsyncPanZoomStarted(); } } mActiveAPZTransforms++; break; } case APZStateChange::TransformEnd: { mActiveAPZTransforms--; nsIScrollableFrame* sf = nsLayoutUtils::FindScrollableFrameFor(aViewId); if (sf) { sf->SetTransformingByAPZ(false); } nsIScrollbarMediator* scrollbarMediator = do_QueryFrame(sf); if (scrollbarMediator) { scrollbarMediator->ScrollbarActivityStopped(); } if (aDocument && mActiveAPZTransforms == 0) { nsCOMPtr<nsIDocShell> docshell(aDocument->GetDocShell()); if (docshell && sf) { nsDocShell* nsdocshell = static_cast<nsDocShell*>(docshell.get()); nsdocshell->NotifyAsyncPanZoomStopped(); } } break; } case APZStateChange::StartTouch: { mActiveElementManager->HandleTouchStart(aArg); break; } case APZStateChange::StartPanning: { mActiveElementManager->HandlePanStart(); break; } case APZStateChange::EndTouch: { mEndTouchIsClick = aArg; mActiveElementManager->HandleTouchEnd(); break; } default: // APZStateChange has a 'sentinel' value, and the compiler complains // if an enumerator is not handled and there is no 'default' case. break; } }
nsresult RDFContentSinkImpl::GetIdAboutAttribute(const char16_t** aAttributes, nsIRDFResource** aResource, bool* aIsAnonymous) { // This corresponds to the dirty work of production [6.5] nsresult rv = NS_OK; nsAutoString nodeID; nsCOMPtr<nsIAtom> localName; for (; *aAttributes; aAttributes += 2) { const nsDependentSubstring& nameSpaceURI = SplitExpatName(aAttributes[0], getter_AddRefs(localName)); // We'll accept either `ID' or `rdf:ID' (ibid with `about' or // `rdf:about') in the spirit of being liberal towards the // input that we receive. if (!nameSpaceURI.IsEmpty() && !nameSpaceURI.EqualsLiteral(RDF_NAMESPACE_URI)) { continue; } // XXX you can't specify both, but we'll just pick up the // first thing that was specified and ignore the other. if (localName == kAboutAtom) { if (aIsAnonymous) *aIsAnonymous = false; nsAutoString relURI(aAttributes[1]); if (rdf_RequiresAbsoluteURI(relURI)) { nsAutoCString uri; rv = mDocumentURL->Resolve(NS_ConvertUTF16toUTF8(aAttributes[1]), uri); if (NS_FAILED(rv)) return rv; return gRDFService->GetResource(uri, aResource); } return gRDFService->GetResource(NS_ConvertUTF16toUTF8(aAttributes[1]), aResource); } else if (localName == kIdAtom) { if (aIsAnonymous) *aIsAnonymous = false; // In the spirit of leniency, we do not bother trying to // enforce that this be a valid "XML Name" (see // http://www.w3.org/TR/REC-xml#NT-Nmtoken), as per // 6.21. If we wanted to, this would be where to do it. // Construct an in-line resource whose URI is the // document's URI plus the XML name specified in the ID // attribute. nsAutoCString name; nsAutoCString ref('#'); AppendUTF16toUTF8(aAttributes[1], ref); rv = mDocumentURL->Resolve(ref, name); if (NS_FAILED(rv)) return rv; return gRDFService->GetResource(name, aResource); } else if (localName == kNodeIdAtom) { nodeID.Assign(aAttributes[1]); } else if (localName == kAboutEachAtom) { // XXX we don't deal with aboutEach... //MOZ_LOG(gLog, LogLevel::Warning, // ("rdfxml: ignoring aboutEach at line %d", // aNode.GetSourceLineNumber())); } } // Otherwise, we couldn't find anything, so just gensym one... if (aIsAnonymous) *aIsAnonymous = true; // If nodeID is present, check if we already know about it. If we've seen // the nodeID before, use the same resource, otherwise generate a new one. if (!nodeID.IsEmpty()) { mNodeIDMap.Get(nodeID,aResource); if (!*aResource) { rv = gRDFService->GetAnonymousResource(aResource); mNodeIDMap.Put(nodeID,*aResource); } } else { rv = gRDFService->GetAnonymousResource(aResource); } return rv; }
NS_IMETHODIMP nsMIMEInputStream::IsNonBlocking(bool *aNonBlocking) { INITSTREAMS; return mStream->IsNonBlocking(aNonBlocking); }
NS_IMETHODIMP nsMIMEInputStream::Read(char * buf, uint32_t count, uint32_t *_retval) { INITSTREAMS; return mStream->Read(buf, count, _retval); }
static void ShutdownEncodedThread(nsCOMPtr<nsIThread>& aThread) { aThread->Shutdown(); }
NS_IMETHODIMP SocketTransportShim::SetNetworkInterfaceId(const nsACString_internal &aNetworkInterfaceId) { return mWrapped->SetNetworkInterfaceId(aNetworkInterfaceId); }
NS_IMETHODIMP nsJARInputThunk::Available(uint64_t *avail) { return mJarStream->Available(avail); }
NS_IMETHODIMP SocketTransportShim::SetTimeout(uint32_t aType, uint32_t aValue) { return mWrapped->SetTimeout(aType, aValue); }
nsresult nsGopherContentStream::SendRequest() { char type; nsCAutoString request; // used to build request data nsresult rv = ParseTypeAndSelector(type, request); if (NS_FAILED(rv)) return rv; // So, we use the selector as is unless it is a search url if (type == '7') { // Note that we don't use the "standard" nsIURL parsing stuff here // because the only special character is ?, and its possible to search // for a string containing a #, and so on // XXX - should this find the last or first entry? // '?' is valid in both the search string and the url // so no matter what this does, it may be incorrect // This only affects people codeing the query directly into the URL PRInt32 pos = request.RFindChar('?'); if (pos != kNotFound) { // Just replace it with a tab request.SetCharAt('\t', pos); } else { // We require a query string here - if we don't have one, // then we need to ask the user nsCAutoString search; rv = PromptForQueryString(search); if (NS_FAILED(rv)) return rv; request.Append('\t'); request.Append(search); // and update our uri (XXX should probably redirect instead to avoid // confusing consumers of the channel) nsCAutoString spec; rv = mChannel->URI()->GetAsciiSpec(spec); if (NS_FAILED(rv)) return rv; spec.Append('?'); spec.Append(search); rv = mChannel->URI()->SetSpec(spec); if (NS_FAILED(rv)) return rv; } } request.Append(CRLF); PRUint32 n; rv = mSocketOutput->Write(request.get(), request.Length(), &n); if (NS_FAILED(rv)) return rv; NS_ENSURE_STATE(n == request.Length()); // Now, push stream converters appropriately based on our 'type' if (type == '1' || type == '7') { rv = mChannel->PushStreamConverter("text/gopher-dir", APPLICATION_HTTP_INDEX_FORMAT); if (NS_FAILED(rv)) return rv; } else if (type == '0') { nsCOMPtr<nsIStreamListener> converter; rv = mChannel->PushStreamConverter(TEXT_PLAIN, TEXT_HTML, PR_TRUE, getter_AddRefs(converter)); if (NS_FAILED(rv)) return rv; nsCOMPtr<nsITXTToHTMLConv> config = do_QueryInterface(converter); if (config) { nsCAutoString spec; mChannel->URI()->GetSpec(spec); config->SetTitle(NS_ConvertUTF8toUTF16(spec).get()); config->PreFormatHTML(PR_TRUE); } } UpdateContentType(type); return NS_OK; }
NS_IMETHODIMP SocketTransportShim::SetQoSBits(uint8_t aQoSBits) { return mWrapped->SetQoSBits(aQoSBits); }
bool nsAppShell::ProcessNextNativeEvent(bool mayWait) { EVLOG("nsAppShell::ProcessNextNativeEvent %d", mayWait); SAMPLE_LABEL("nsAppShell", "ProcessNextNativeEvent"); nsAutoPtr<AndroidGeckoEvent> curEvent; { MutexAutoLock lock(mCondLock); curEvent = PopNextEvent(); if (!curEvent && mayWait) { SAMPLE_LABEL("nsAppShell::ProcessNextNativeEvent", "Wait"); // hmm, should we really hardcode this 10s? #if defined(DEBUG_ANDROID_EVENTS) PRTime t0, t1; EVLOG("nsAppShell: waiting on mQueueCond"); t0 = PR_Now(); mQueueCond.Wait(PR_MillisecondsToInterval(10000)); t1 = PR_Now(); EVLOG("nsAppShell: wait done, waited %d ms", (int)(t1-t0)/1000); #else mQueueCond.Wait(); #endif curEvent = PopNextEvent(); } } if (!curEvent) return false; EVLOG("nsAppShell: event %p %d", (void*)curEvent.get(), curEvent->Type()); switch (curEvent->Type()) { case AndroidGeckoEvent::NATIVE_POKE: NativeEventCallback(); break; case AndroidGeckoEvent::SENSOR_EVENT: { InfallibleTArray<float> values; mozilla::hal::SensorType type = (mozilla::hal::SensorType) curEvent->Flags(); switch (type) { case hal::SENSOR_ORIENTATION: case hal::SENSOR_LINEAR_ACCELERATION: case hal::SENSOR_ACCELERATION: case hal::SENSOR_GYROSCOPE: case hal::SENSOR_PROXIMITY: values.AppendElement(curEvent->X()); values.AppendElement(curEvent->Y()); values.AppendElement(curEvent->Z()); break; case hal::SENSOR_LIGHT: values.AppendElement(curEvent->X()); break; default: __android_log_print(ANDROID_LOG_ERROR, "Gecko", "### SENSOR_EVENT fired, but type wasn't known %d", type); } const hal::SensorAccuracyType &accuracy = (hal::SensorAccuracyType) curEvent->MetaState(); hal::SensorData sdata(type, PR_Now(), values, accuracy); hal::NotifySensorChange(sdata); } break; case AndroidGeckoEvent::LOCATION_EVENT: { if (!gLocationCallback) break; nsGeoPosition* p = curEvent->GeoPosition(); if (p) gLocationCallback->Update(curEvent->GeoPosition()); else NS_WARNING("Received location event without geoposition!"); break; } case AndroidGeckoEvent::ACTIVITY_STOPPING: { if (curEvent->Flags() > 0) break; nsCOMPtr<nsIObserverService> obsServ = mozilla::services::GetObserverService(); NS_NAMED_LITERAL_STRING(minimize, "heap-minimize"); obsServ->NotifyObservers(nullptr, "memory-pressure", minimize.get()); obsServ->NotifyObservers(nullptr, "application-background", nullptr); break; } case AndroidGeckoEvent::ACTIVITY_SHUTDOWN: { nsCOMPtr<nsIObserverService> obsServ = mozilla::services::GetObserverService(); NS_NAMED_LITERAL_STRING(context, "shutdown-persist"); obsServ->NotifyObservers(nullptr, "quit-application-granted", nullptr); obsServ->NotifyObservers(nullptr, "quit-application-forced", nullptr); obsServ->NotifyObservers(nullptr, "profile-change-net-teardown", context.get()); obsServ->NotifyObservers(nullptr, "profile-change-teardown", context.get()); obsServ->NotifyObservers(nullptr, "profile-before-change", context.get()); nsCOMPtr<nsIAppStartup> appSvc = do_GetService("@mozilla.org/toolkit/app-startup;1"); if (appSvc) appSvc->Quit(nsIAppStartup::eForceQuit); break; } case AndroidGeckoEvent::ACTIVITY_PAUSING: { if (curEvent->Flags() == 0) { // We aren't transferring to one of our own activities, so set // background status nsCOMPtr<nsIObserverService> obsServ = mozilla::services::GetObserverService(); obsServ->NotifyObservers(nullptr, "application-background", nullptr); // If we are OOM killed with the disk cache enabled, the entire // cache will be cleared (bug 105843), so shut down the cache here // and re-init on resume if (nsCacheService::GlobalInstance()) nsCacheService::GlobalInstance()->Shutdown(); } // We really want to send a notification like profile-before-change, // but profile-before-change ends up shutting some things down instead // of flushing data nsIPrefService* prefs = Preferences::GetService(); if (prefs) { // reset the crash loop state nsCOMPtr<nsIPrefBranch> prefBranch; prefs->GetBranch("browser.sessionstore.", getter_AddRefs(prefBranch)); if (prefBranch) prefBranch->SetIntPref("recent_crashes", 0); prefs->SavePrefFile(nullptr); } break; } case AndroidGeckoEvent::ACTIVITY_START: { if (curEvent->Flags() > 0) break; nsCOMPtr<nsIObserverService> obsServ = mozilla::services::GetObserverService(); obsServ->NotifyObservers(nullptr, "application-foreground", nullptr); break; } case AndroidGeckoEvent::PAINT_LISTEN_START_EVENT: { nsCOMPtr<nsIDOMWindow> domWindow; nsCOMPtr<nsIBrowserTab> tab; mBrowserApp->GetBrowserTab(curEvent->MetaState(), getter_AddRefs(tab)); if (!tab) break; tab->GetWindow(getter_AddRefs(domWindow)); if (!domWindow) break; sAfterPaintListener->Register(domWindow); break; } case AndroidGeckoEvent::SCREENSHOT: { if (!mBrowserApp) break; AndroidBridge* bridge = AndroidBridge::Bridge(); if (!bridge) break; int32_t token = curEvent->Flags(); int32_t tabId = curEvent->MetaState(); const nsTArray<nsIntPoint>& points = curEvent->Points(); RefCountedJavaObject* buffer = curEvent->ByteBuffer(); nsCOMPtr<ScreenshotRunnable> sr = new ScreenshotRunnable(mBrowserApp, tabId, points, token, buffer); MessageLoop::current()->PostIdleTask( FROM_HERE, NewRunnableMethod(sr.get(), &ScreenshotRunnable::Run)); break; } case AndroidGeckoEvent::VIEWPORT: case AndroidGeckoEvent::BROADCAST: { if (curEvent->Characters().Length() == 0) break; nsCOMPtr<nsIObserverService> obsServ = mozilla::services::GetObserverService(); const NS_ConvertUTF16toUTF8 topic(curEvent->Characters()); const nsPromiseFlatString& data = PromiseFlatString(curEvent->CharactersExtra()); obsServ->NotifyObservers(nullptr, topic.get(), data.get()); break; } case AndroidGeckoEvent::LOAD_URI: { nsCOMPtr<nsICommandLineRunner> cmdline (do_CreateInstance("@mozilla.org/toolkit/command-line;1")); if (!cmdline) break; if (curEvent->Characters().Length() == 0) break; char *uri = ToNewUTF8String(curEvent->Characters()); if (!uri) break; char *flag = ToNewUTF8String(curEvent->CharactersExtra()); const char *argv[4] = { "dummyappname", "-url", uri, flag ? flag : "" }; nsresult rv = cmdline->Init(4, const_cast<char **>(argv), nullptr, nsICommandLine::STATE_REMOTE_AUTO); if (NS_SUCCEEDED(rv)) cmdline->Run(); nsMemory::Free(uri); if (flag) nsMemory::Free(flag); break; } case AndroidGeckoEvent::SIZE_CHANGED: { // store the last resize event to dispatch it to new windows with a FORCED_RESIZE event if (curEvent != gLastSizeChange) { gLastSizeChange = new AndroidGeckoEvent(curEvent); } nsWindow::OnGlobalAndroidEvent(curEvent); break; } case AndroidGeckoEvent::VISITED: { #ifdef MOZ_ANDROID_HISTORY nsCOMPtr<IHistory> history = services::GetHistoryService(); nsCOMPtr<nsIURI> visitedURI; if (history && NS_SUCCEEDED(NS_NewURI(getter_AddRefs(visitedURI), nsString(curEvent->Characters())))) { history->NotifyVisited(visitedURI); } #endif break; } case AndroidGeckoEvent::NETWORK_CHANGED: { hal::NotifyNetworkChange(hal::NetworkInformation(curEvent->Bandwidth(), curEvent->CanBeMetered())); break; } case AndroidGeckoEvent::ACTIVITY_RESUMING: { if (curEvent->Flags() == 0) { // If we are OOM killed with the disk cache enabled, the entire // cache will be cleared (bug 105843), so shut down cache on pause // and re-init here if (nsCacheService::GlobalInstance()) nsCacheService::GlobalInstance()->Init(); // We didn't return from one of our own activities, so restore // to foreground status nsCOMPtr<nsIObserverService> obsServ = mozilla::services::GetObserverService(); obsServ->NotifyObservers(nullptr, "application-foreground", nullptr); } break; } case AndroidGeckoEvent::SCREENORIENTATION_CHANGED: { nsresult rv; nsCOMPtr<nsIScreenManager> screenMgr = do_GetService("@mozilla.org/gfx/screenmanager;1", &rv); if (NS_FAILED(rv)) { NS_ERROR("Can't find nsIScreenManager!"); break; } nsIntRect rect; int32_t colorDepth, pixelDepth; dom::ScreenOrientation orientation; nsCOMPtr<nsIScreen> screen; screenMgr->GetPrimaryScreen(getter_AddRefs(screen)); screen->GetRect(&rect.x, &rect.y, &rect.width, &rect.height); screen->GetColorDepth(&colorDepth); screen->GetPixelDepth(&pixelDepth); orientation = static_cast<dom::ScreenOrientation>(curEvent->ScreenOrientation()); hal::NotifyScreenConfigurationChange( hal::ScreenConfiguration(rect, orientation, colorDepth, pixelDepth)); break; } default: nsWindow::OnGlobalAndroidEvent(curEvent); } EVLOG("nsAppShell: -- done event %p %d", (void*)curEvent.get(), curEvent->Type()); return true; }
CSSRect CalculateRectToZoomTo(const nsCOMPtr<nsIDocument>& aRootContentDocument, const CSSPoint& aPoint) { // Ensure the layout information we get is up-to-date. aRootContentDocument->FlushPendingNotifications(Flush_Layout); // An empty rect as return value is interpreted as "zoom out". const CSSRect zoomOut; nsCOMPtr<nsIPresShell> shell = aRootContentDocument->GetShell(); if (!shell) { return zoomOut; } nsIScrollableFrame* rootScrollFrame = shell->GetRootScrollFrameAsScrollable(); if (!rootScrollFrame) { return zoomOut; } nsCOMPtr<dom::Element> element = ElementFromPoint(shell, aPoint); if (!element) { return zoomOut; } while (element && !ShouldZoomToElement(element)) { element = element->GetParentElement(); } if (!element) { return zoomOut; } FrameMetrics metrics = nsLayoutUtils::CalculateBasicFrameMetrics(rootScrollFrame); CSSRect compositedArea(metrics.GetScrollOffset(), metrics.CalculateCompositedSizeInCssPixels()); const CSSCoord margin = 15; CSSRect rect = nsLayoutUtils::GetBoundingContentRect(element, rootScrollFrame); // If the element is taller than the visible area of the page scale // the height of the |rect| so that it has the same aspect ratio as // the root frame. The clipped |rect| is centered on the y value of // the touch point. This allows tall narrow elements to be zoomed. if (!rect.IsEmpty() && compositedArea.width > 0.0f) { const float widthRatio = rect.width / compositedArea.width; float targetHeight = compositedArea.height * widthRatio; if (widthRatio < 0.9 && targetHeight < rect.height) { const CSSPoint scrollPoint = CSSPoint::FromAppUnits(rootScrollFrame->GetScrollPosition()); float newY = aPoint.y + scrollPoint.y - (targetHeight * 0.5f); if ((newY + targetHeight) > (rect.y + rect.height)) { rect.y += rect.height - targetHeight; } else if (newY > rect.y) { rect.y = newY; } rect.height = targetHeight; } } rect = CSSRect(std::max(metrics.GetScrollableRect().x, rect.x - margin), rect.y, rect.width + 2 * margin, rect.height); // Constrict the rect to the screen's right edge rect.width = std::min(rect.width, metrics.GetScrollableRect().XMost() - rect.x); // If the rect is already taking up most of the visible area and is // stretching the width of the page, then we want to zoom out instead. if (IsRectZoomedIn(rect, compositedArea)) { return zoomOut; } CSSRect rounded(rect); rounded.Round(); // If the block we're zooming to is really tall, and the user double-tapped // more than a screenful of height from the top of it, then adjust the // y-coordinate so that we center the actual point the user double-tapped // upon. This prevents flying to the top of the page when double-tapping // to zoom in (bug 761721). The 1.2 multiplier is just a little fuzz to // compensate for 'rect' including horizontal margins but not vertical ones. CSSCoord cssTapY = metrics.GetScrollOffset().y + aPoint.y; if ((rect.height > rounded.height) && (cssTapY > rounded.y + (rounded.height * 1.2))) { rounded.y = cssTapY - (rounded.height / 2); } return rounded; }
NS_IMETHOD Read(char* aBuffer, uint32_t aCount, uint32_t* aReadCount) override { return mStream->Read(aBuffer, aCount, aReadCount); }
nsresult RDFContentSinkImpl::OpenObject(const char16_t* aName, const char16_t** aAttributes) { // an "object" non-terminal is either a "description", a "typed // node", or a "container", so this change the content sink's // state appropriately. nsCOMPtr<nsIAtom> localName; const nsDependentSubstring& nameSpaceURI = SplitExpatName(aName, getter_AddRefs(localName)); // Figure out the URI of this object, and create an RDF node for it. nsCOMPtr<nsIRDFResource> source; GetIdAboutAttribute(aAttributes, getter_AddRefs(source)); // If there is no `ID' or `about', then there's not much we can do. if (! source) return NS_ERROR_FAILURE; // Push the element onto the context stack PushContext(source, mState, mParseMode); // Now figure out what kind of state transition we need to // make. We'll either be going into a mode where we parse a // description or a container. bool isaTypedNode = true; if (nameSpaceURI.EqualsLiteral(RDF_NAMESPACE_URI)) { isaTypedNode = false; if (localName == kDescriptionAtom) { // it's a description mState = eRDFContentSinkState_InDescriptionElement; } else if (localName == kBagAtom) { // it's a bag container InitContainer(kRDF_Bag, source); mState = eRDFContentSinkState_InContainerElement; } else if (localName == kSeqAtom) { // it's a seq container InitContainer(kRDF_Seq, source); mState = eRDFContentSinkState_InContainerElement; } else if (localName == kAltAtom) { // it's an alt container InitContainer(kRDF_Alt, source); mState = eRDFContentSinkState_InContainerElement; } else { // heh, that's not *in* the RDF namespace: just treat it // like a typed node isaTypedNode = true; } } if (isaTypedNode) { NS_ConvertUTF16toUTF8 typeStr(nameSpaceURI); typeStr.Append(nsAtomCString(localName)); nsCOMPtr<nsIRDFResource> type; nsresult rv = gRDFService->GetResource(typeStr, getter_AddRefs(type)); if (NS_FAILED(rv)) return rv; rv = mDataSource->Assert(source, kRDF_type, type, true); if (NS_FAILED(rv)) return rv; mState = eRDFContentSinkState_InDescriptionElement; } AddProperties(aAttributes, source); return NS_OK; }
NS_IMETHOD Close() override { return mStream->Close(); }
nsresult RDFContentSinkImpl::OpenProperty(const char16_t* aName, const char16_t** aAttributes) { nsresult rv; // an "object" non-terminal is either a "description", a "typed // node", or a "container", so this change the content sink's // state appropriately. nsCOMPtr<nsIAtom> localName; const nsDependentSubstring& nameSpaceURI = SplitExpatName(aName, getter_AddRefs(localName)); NS_ConvertUTF16toUTF8 propertyStr(nameSpaceURI); propertyStr.Append(nsAtomCString(localName)); nsCOMPtr<nsIRDFResource> property; rv = gRDFService->GetResource(propertyStr, getter_AddRefs(property)); if (NS_FAILED(rv)) return rv; // See if they've specified a 'resource' attribute, in which case // they mean *that* to be the object of this property. nsCOMPtr<nsIRDFResource> target; GetResourceAttribute(aAttributes, getter_AddRefs(target)); bool isAnonymous = false; if (! target) { // See if an 'ID' attribute has been specified, in which case // this corresponds to the fourth form of [6.12]. // XXX strictly speaking, we should reject the RDF/XML as // invalid if they've specified both an 'ID' and a 'resource' // attribute. Bah. // XXX strictly speaking, 'about=' isn't allowed here, but // what the hell. GetIdAboutAttribute(aAttributes, getter_AddRefs(target), &isAnonymous); } if (target) { // They specified an inline resource for the value of this // property. Create an RDF resource for the inline resource // URI, add the properties to it, and attach the inline // resource to its parent. int32_t count; rv = AddProperties(aAttributes, target, &count); NS_ASSERTION(NS_SUCCEEDED(rv), "problem adding properties"); if (NS_FAILED(rv)) return rv; if (count || !isAnonymous) { // If the resource was "anonymous" (i.e., they hadn't // explicitly set an ID or resource attribute), then we'll // only assert this property from the context element *if* // there were properties specified on the anonymous // resource. rv = mDataSource->Assert(GetContextElement(0), property, target, true); if (NS_FAILED(rv)) return rv; } // XXX Technically, we should _not_ fall through here and push // the element onto the stack: this is supposed to be a closed // node. But right now I'm lazy and the code will just Do The // Right Thing so long as the RDF is well-formed. } // Push the element onto the context stack and change state. PushContext(property, mState, mParseMode); mState = eRDFContentSinkState_InPropertyElement; SetParseMode(aAttributes); return NS_OK; }
/* nsISimpleEnumerator GetTargets (in nsIRDFResource aSource, in nsIRDFResource aProperty, in boolean aTruthValue); */ NS_IMETHODIMP nsRDFDataSourceDataSource::GetTargets(nsIRDFResource *aSource, nsIRDFResource *aProperty, bool aTruthValue, nsISimpleEnumerator **_retval) { nsXPIDLCString sourceval; aSource->GetValue(getter_Copies(sourceval)); nsXPIDLCString propval; aProperty->GetValue(getter_Copies(propval)); #ifdef DEBUG_alecf printf("GetTargets(%s, %s,..)\n", (const char*)sourceval, (const char*)propval); #endif nsresult rv; bool isProp; nsCOMPtr<nsISupportsArray> arcs; nsISimpleEnumerator *enumerator; if (NS_SUCCEEDED(aProperty->EqualsNode(kNC_Child, &isProp)) && isProp) { // here we need to determine if we need to extract out the source // or use aSource? if (StringBeginsWith(sourceval, NS_LITERAL_CSTRING("dsresource:"))) { // somehow get the source // XXX ? rv = mDataSource->ArcLabelsOut(realsource, &enumerator); rv = mDataSource->ArcLabelsOut(aSource, &enumerator); } else { rv = mDataSource->ArcLabelsOut(aSource, &enumerator); } // enumerate all the children and create the composite resources bool hasMoreArcs=false; rv = enumerator->HasMoreElements(&hasMoreArcs); while (NS_SUCCEEDED(rv) && hasMoreArcs) { // get the next arc nsCOMPtr<nsISupports> arcSupports; rv = enumerator->GetNext(getter_AddRefs(arcSupports)); nsCOMPtr<nsIRDFResource> arc = do_QueryInterface(arcSupports, &rv); // get all the resources on the ends of the arc arcs nsCOMPtr<nsISimpleEnumerator> targetEnumerator; rv = mDataSource->GetTargets(aSource, arc, true, getter_AddRefs(targetEnumerator)); bool hasMoreTargets; rv = targetEnumerator->HasMoreElements(&hasMoreTargets); while (NS_SUCCEEDED(rv) && hasMoreTargets) { // get the next target nsCOMPtr<nsISupports> targetSupports; rv = enumerator->GetNext(getter_AddRefs(targetSupports)); nsCOMPtr<nsIRDFResource> target=do_QueryInterface(targetSupports, &rv); // now we have an (arc, target) tuple that will be our node // arc will become #Name // target will become #Value #ifdef DEBUG_alecf nsXPIDLString arcValue; nsXPIDLString targetValue; arc->GetValue(getter_Copies(arcValue)); target->GetValue(getter_Copies(targetValue)); printf("#child of %s:\n\t%s = %s\n", (const char*)sourceval #endif } rv = enumerator->HasMoreElements(&hasMoreArcs); } } else if (NS_SUCCEEDED(aProperty->EqualsNode(kNC_Name, &isProp)) &&
NS_IMETHODIMP nsExtProtocolChannel::GetName(nsACString &result) { return mUrl->GetSpec(result); }
lpnsMapiMessage MsgMapiListContext::GetMessage (nsMsgKey key, unsigned long flFlags) { lpnsMapiMessage message = (lpnsMapiMessage) CoTaskMemAlloc (sizeof(nsMapiMessage)); memset(message, 0, sizeof(nsMapiMessage)); if (message) { nsCString subject; nsCString author; nsCOMPtr <nsIMsgDBHdr> msgHdr; nsresult rv = m_db->GetMsgHdrForKey (key, getter_AddRefs(msgHdr)); if (msgHdr) { msgHdr->GetSubject (getter_Copies(subject)); message->lpszSubject = (char *) CoTaskMemAlloc(subject.Length() + 1); strcpy((char *) message->lpszSubject, subject.get()); uint32_t date; (void) msgHdr->GetDateInSeconds(&date); message->lpszDateReceived = ConvertDateToMapiFormat (date); // Pull out the flags info // anything to do with MAPI_SENT? Since we're only reading the Inbox, I guess not uint32_t ourFlags; (void) msgHdr->GetFlags(&ourFlags); if (!(ourFlags & nsMsgMessageFlags::Read)) message->flFlags |= MAPI_UNREAD; if (ourFlags & (nsMsgMessageFlags::MDNReportNeeded | nsMsgMessageFlags::MDNReportSent)) message->flFlags |= MAPI_RECEIPT_REQUESTED; // Pull out the author/originator info message->lpOriginator = (lpnsMapiRecipDesc) CoTaskMemAlloc (sizeof(nsMapiRecipDesc)); memset(message->lpOriginator, 0, sizeof(nsMapiRecipDesc)); if (message->lpOriginator) { msgHdr->GetAuthor (getter_Copies(author)); ConvertRecipientsToMapiFormat(EncodedHeader(author), message->lpOriginator, MAPI_ORIG); } // Pull out the To/CC info nsCString recipients, ccList; msgHdr->GetRecipients(getter_Copies(recipients)); msgHdr->GetCcList(getter_Copies(ccList)); nsCOMArray<msgIAddressObject> parsedToRecips = EncodedHeader(recipients); nsCOMArray<msgIAddressObject> parsedCCRecips = EncodedHeader(ccList); uint32_t numToRecips = parsedToRecips.Length(); uint32_t numCCRecips = parsedCCRecips.Length(); message->lpRecips = (lpnsMapiRecipDesc) CoTaskMemAlloc ((numToRecips + numCCRecips) * sizeof(MapiRecipDesc)); memset(message->lpRecips, 0, (numToRecips + numCCRecips) * sizeof(MapiRecipDesc)); if (message->lpRecips) { ConvertRecipientsToMapiFormat(parsedToRecips, message->lpRecips, MAPI_TO); ConvertRecipientsToMapiFormat(parsedCCRecips, &message->lpRecips[numToRecips], MAPI_CC); } MOZ_LOG(MAPI, mozilla::LogLevel::Debug, ("MsgMapiListContext::GetMessage flags=%x subject %s date %s sender %s\n", flFlags, (char *) message->lpszSubject,(char *) message->lpszDateReceived, author.get()) ); // Convert any body text that we have locally if (!(flFlags & MAPI_ENVELOPE_ONLY)) message->lpszNoteText = (char *) ConvertBodyToMapiFormat (msgHdr); } if (! (flFlags & (MAPI_PEEK | MAPI_ENVELOPE_ONLY))) m_db->MarkRead(key, true, nullptr); } return message; }
// nsIInputStream NS_IMETHODIMP nsMIMEInputStream::Close(void) { INITSTREAMS; return mStream->Close(); }