void GetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration) { AndroidBridge* bridge = AndroidBridge::Bridge(); if (!bridge) { return; } nsresult rv; nsCOMPtr<nsIScreenManager> screenMgr = do_GetService("@mozilla.org/gfx/screenmanager;1", &rv); if (NS_FAILED(rv)) { NS_ERROR("Can't find nsIScreenManager!"); return; } nsIntRect rect; PRInt32 colorDepth, pixelDepth; 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<ScreenOrientation>(bridge->GetScreenOrientation()); *aScreenConfiguration = hal::ScreenConfiguration(rect, orientation, colorDepth, pixelDepth); }
void GetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration) { AndroidBridge* bridge = AndroidBridge::Bridge(); if (!bridge) { return; } nsresult rv; nsCOMPtr<nsIScreenManager> screenMgr = do_GetService("@mozilla.org/gfx/screenmanager;1", &rv); if (NS_FAILED(rv)) { NS_ERROR("Can't find nsIScreenManager!"); return; } int32_t colorDepth, pixelDepth; int16_t angle; ScreenOrientationInternal orientation; nsCOMPtr<nsIScreen> screen; int32_t rectX, rectY, rectWidth, rectHeight; screenMgr->GetPrimaryScreen(getter_AddRefs(screen)); screen->GetRect(&rectX, &rectY, &rectWidth, &rectHeight); screen->GetColorDepth(&colorDepth); screen->GetPixelDepth(&pixelDepth); orientation = static_cast<ScreenOrientationInternal>(bridge->GetScreenOrientation()); angle = bridge->GetScreenAngle(); *aScreenConfiguration = hal::ScreenConfiguration(nsIntRect(rectX, rectY, rectWidth, rectHeight), orientation, angle, colorDepth, pixelDepth); }
void Vibrate(const nsTArray<uint32> &pattern, const WindowIdentifier &) { // Ignore the WindowIdentifier parameter; it's here only because hal::Vibrate, // hal_sandbox::Vibrate, and hal_impl::Vibrate all must have the same // signature. // Strangely enough, the Android Java API seems to treat vibrate([0]) as a // nop. But we want to treat vibrate([0]) like CancelVibrate! (Note that we // also need to treat vibrate([]) as a call to CancelVibrate.) bool allZero = true; for (uint32 i = 0; i < pattern.Length(); i++) { if (pattern[i] != 0) { allZero = false; break; } } if (allZero) { hal_impl::CancelVibrate(WindowIdentifier()); return; } AndroidBridge* b = AndroidBridge::Bridge(); if (!b) { return; } b->Vibrate(pattern); }
NS_IMETHODIMP nsAndroidHistory::RegisterVisitedCallback(nsIURI *aURI, Link *aContent) { if (!aContent || !aURI) return NS_OK; nsCAutoString uri; nsresult rv = aURI->GetSpec(uri); if (NS_FAILED(rv)) return rv; NS_ConvertUTF8toUTF16 uriString(uri); nsTArray<Link*>* list = mListeners.Get(uriString); if (! list) { list = new nsTArray<Link*>(); mListeners.Put(uriString, list); } list->AppendElement(aContent); AndroidBridge *bridge = AndroidBridge::Bridge(); if (bridge) { bridge->CheckURIVisited(uriString); } return NS_OK; }
NS_IMETHODIMP nsAndroidHistory::VisitURI(nsIURI *aURI, nsIURI *aLastVisitedURI, uint32_t aFlags) { if (!aURI) return NS_OK; if (!(aFlags & VisitFlags::TOP_LEVEL)) return NS_OK; if (aFlags & VisitFlags::REDIRECT_SOURCE) return NS_OK; if (aFlags & VisitFlags::UNRECOVERABLE_ERROR) return NS_OK; AndroidBridge *bridge = AndroidBridge::Bridge(); if (bridge) { nsAutoCString uri; nsresult rv = aURI->GetSpec(uri); if (NS_FAILED(rv)) return rv; NS_ConvertUTF8toUTF16 uriString(uri); bridge->MarkURIVisited(uriString); } return NS_OK; }
void CancelVibrate(const WindowIdentifier &) { // Ignore WindowIdentifier parameter. AndroidBridge* b = AndroidBridge::Bridge(); if (b) b->CancelVibrate(); }
void DisableNetworkNotifications() { AndroidBridge* bridge = AndroidBridge::Bridge(); if (!bridge) { return; } bridge->DisableNetworkNotifications(); }
void EnableScreenConfigurationNotifications() { AndroidBridge* bridge = AndroidBridge::Bridge(); if (!bridge) { return; } bridge->EnableScreenOrientationNotifications(); }
void UnlockScreenOrientation() { AndroidBridge* bridge = AndroidBridge::Bridge(); if (!bridge) { return; } bridge->UnlockScreenOrientation(); }
void EnableBatteryNotifications() { AndroidBridge* bridge = AndroidBridge::Bridge(); if (!bridge) { return; } bridge->EnableBatteryNotifications(); }
void DisableScreenOrientationNotifications() { AndroidBridge* bridge = AndroidBridge::Bridge(); if (!bridge) { return; } bridge->DisableScreenOrientationNotifications(); }
void GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo) { AndroidBridge* bridge = AndroidBridge::Bridge(); if (!bridge) { return; } bridge->GetCurrentNetworkInformation(aNetworkInfo); }
void GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInfo) { AndroidBridge* bridge = AndroidBridge::Bridge(); if (!bridge) { return; } bridge->GetCurrentBatteryInformation(aBatteryInfo); }
bool LockScreenOrientation(const dom::ScreenOrientation& aOrientation) { AndroidBridge* bridge = AndroidBridge::Bridge(); if (!bridge) { return false; } bridge->LockScreenOrientation(dom::ScreenOrientationWrapper(aOrientation)); return true; }
void GetCurrentScreenOrientation(dom::ScreenOrientation* aScreenOrientation) { AndroidBridge* bridge = AndroidBridge::Bridge(); if (!bridge) { return; } dom::ScreenOrientationWrapper orientationWrapper; bridge->GetScreenOrientation(orientationWrapper); *aScreenOrientation = orientationWrapper.orientation; }
NS_IMETHODIMP nsAndroidHistory::SetURITitle(nsIURI *aURI, const nsAString& aTitle) { AndroidBridge *bridge = AndroidBridge::Bridge(); if (bridge) { nsAutoCString uri; nsresult rv = aURI->GetSpec(uri); if (NS_FAILED(rv)) return rv; NS_ConvertUTF8toUTF16 uriString(uri); bridge->SetURITitle(uriString, aTitle); } return NS_OK; }
nsresult nsAppShell::Init() { #ifdef PR_LOGGING if (!gWidgetLog) gWidgetLog = PR_NewLogModule("Widget"); #endif mObserversHash.Init(); nsresult rv = nsBaseAppShell::Init(); AndroidBridge* bridge = AndroidBridge::Bridge(); nsCOMPtr<nsIObserverService> obsServ = mozilla::services::GetObserverService(); if (obsServ) { obsServ->AddObserver(this, "xpcom-shutdown", false); } if (sPowerManagerService) sPowerManagerService->AddWakeLockListener(sWakeLockListener); if (!bridge) return rv; Preferences::AddStrongObservers(this, kObservedPrefs); bool match; rv = Preferences::GetBool(PREFNAME_MATCH_OS, &match); NS_ENSURE_SUCCESS(rv, rv); if (match) { bridge->SetSelectedLocale(EmptyString()); return NS_OK; } nsAutoString locale; rv = Preferences::GetLocalizedString(PREFNAME_UA_LOCALE, &locale); if (NS_FAILED(rv)) { rv = Preferences::GetString(PREFNAME_UA_LOCALE, &locale); } bridge->SetSelectedLocale(locale); mAllowCoalescingTouches = Preferences::GetBool(PREFNAME_COALESCE_TOUCHES, true); return rv; }
NS_IMETHODIMP nsAppShell::Observe(nsISupports* aSubject, const char* aTopic, const PRUnichar* aData) { if (!strcmp(aTopic, "xpcom-shutdown")) { // We need to ensure no observers stick around after XPCOM shuts down // or we'll see crashes, as the app shell outlives XPConnect. mObserversHash.Clear(); return nsBaseAppShell::Observe(aSubject, aTopic, aData); } else if (!strcmp(aTopic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID) && aData && ( nsDependentString(aData).Equals( NS_LITERAL_STRING(PREFNAME_UA_LOCALE)) || nsDependentString(aData).Equals( NS_LITERAL_STRING(PREFNAME_COALESCE_TOUCHES)) || nsDependentString(aData).Equals( NS_LITERAL_STRING(PREFNAME_MATCH_OS)))) { AndroidBridge* bridge = AndroidBridge::Bridge(); if (!bridge) { return NS_OK; } bool match; nsresult rv = Preferences::GetBool(PREFNAME_MATCH_OS, &match); NS_ENSURE_SUCCESS(rv, rv); if (match) { bridge->SetSelectedLocale(EmptyString()); return NS_OK; } nsAutoString locale; if (NS_FAILED(Preferences::GetLocalizedString(PREFNAME_UA_LOCALE, &locale))) { locale = Preferences::GetString(PREFNAME_UA_LOCALE); } bridge->SetSelectedLocale(locale); mAllowCoalescingTouches = Preferences::GetBool(PREFNAME_COALESCE_TOUCHES, true); return NS_OK; } return NS_OK; }
NS_IMETHODIMP nsAndroidHistory::VisitURI(nsIURI *aURI, nsIURI *aLastVisitedURI, PRUint32 aFlags) { if (!aURI) return NS_OK; if (!(aFlags & VisitFlags::TOP_LEVEL)) return NS_OK; AndroidBridge *bridge = AndroidBridge::Bridge(); if (bridge) { nsCAutoString uri; nsresult rv = aURI->GetSpec(uri); if (NS_FAILED(rv)) return rv; NS_ConvertUTF8toUTF16 uriString(uri); bridge->MarkURIVisited(uriString); } return NS_OK; }
bool nsAppShell::ProcessNextNativeEvent(bool mayWait) { EVLOG("nsAppShell::ProcessNextNativeEvent %d", mayWait); nsAutoPtr<AndroidGeckoEvent> curEvent; { MutexAutoLock lock(mCondLock); curEvent = PopNextEvent(); if (!curEvent && mayWait) { // 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: values.AppendElement(curEvent->X()); values.AppendElement(curEvent->Y()); values.AppendElement(curEvent->Z()); break; case hal::SENSOR_PROXIMITY: 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(nsnull, "memory-pressure", minimize.get()); obsServ->NotifyObservers(nsnull, "application-background", nsnull); break; } case AndroidGeckoEvent::ACTIVITY_SHUTDOWN: { nsCOMPtr<nsIObserverService> obsServ = mozilla::services::GetObserverService(); NS_NAMED_LITERAL_STRING(context, "shutdown-persist"); obsServ->NotifyObservers(nsnull, "quit-application-granted", nsnull); obsServ->NotifyObservers(nsnull, "quit-application-forced", nsnull); obsServ->NotifyObservers(nsnull, "profile-change-net-teardown", context.get()); obsServ->NotifyObservers(nsnull, "profile-change-teardown", context.get()); obsServ->NotifyObservers(nsnull, "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(nsnull, "application-background", nsnull); // 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(nsnull); } break; } case AndroidGeckoEvent::ACTIVITY_START: { if (curEvent->Flags() > 0) break; nsCOMPtr<nsIObserverService> obsServ = mozilla::services::GetObserverService(); obsServ->NotifyObservers(nsnull, "application-foreground", nsnull); break; } case AndroidGeckoEvent::SCREENSHOT: { if (!mBrowserApp) break; AndroidBridge* bridge = AndroidBridge::Bridge(); if (!bridge) break; nsCOMPtr<nsIDOMWindow> domWindow; nsCOMPtr<nsIBrowserTab> tab; float scale; mBrowserApp->GetBrowserTab(curEvent->MetaState(), getter_AddRefs(tab)); if (!tab) break; tab->GetWindow(getter_AddRefs(domWindow)); if (!domWindow) break; if (NS_FAILED(tab->GetScale(&scale))) break; nsTArray<nsIntPoint> points = curEvent->Points(); NS_ASSERTION(points.Length() == 2, "Screenshot event does not have enough coordinates"); bridge->TakeScreenshot(domWindow, 0, 0, points[0].x, points[0].y, points[1].x, points[1].y, curEvent->MetaState(), scale); 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(nsnull, 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), nsnull, 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 nsAndroidHistory::NotifyURIVisited(nsString(curEvent->Characters())); #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(nsnull, "application-foreground", nsnull); } break; } case AndroidGeckoEvent::SCREENORIENTATION_CHANGED: { hal::NotifyScreenOrientationChange(static_cast<dom::ScreenOrientation>(curEvent->ScreenOrientation())); break; } default: nsWindow::OnGlobalAndroidEvent(curEvent); } EVLOG("nsAppShell: -- done event %p %d", (void*)curEvent.get(), curEvent->Type()); return true; }
bool nsAppShell::ProcessNextNativeEvent(bool mayWait) { EVLOG("nsAppShell::ProcessNextNativeEvent %d", mayWait); nsAutoPtr<AndroidGeckoEvent> curEvent; AndroidGeckoEvent *nextEvent; { MutexAutoLock lock(mCondLock); curEvent = PopNextEvent(); if (!curEvent && mayWait) { // 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; // Combine subsequent events of the same type nextEvent = PeekNextEvent(); while (nextEvent) { int curType = curEvent->Type(); int nextType = nextEvent->Type(); while (nextType == AndroidGeckoEvent::VIEWPORT && mNumViewports > 1) { // Skip this viewport change, as there's another one later and // processing this one will only cause more unnecessary work PopNextEvent(); delete nextEvent; nextEvent = PeekNextEvent(); nextType = nextEvent->Type(); } while (nextType == AndroidGeckoEvent::DRAW && mLastDrawEvent && mNumDraws > 1) { // skip this draw, since there's a later one already in the queue.. this will let us // deal with sequences that look like: // MOVE DRAW MOVE DRAW MOVE DRAW // and end up with just // MOVE DRAW // when we process all the events. // Combine the next draw event's rect with the last one in the queue const nsIntRect& nextRect = nextEvent->Rect(); const nsIntRect& lastRect = mLastDrawEvent->Rect(); int combinedArea = (lastRect.width * lastRect.height) + (nextRect.width * nextRect.height); nsIntRect combinedRect = lastRect.Union(nextRect); mLastDrawEvent->Init(AndroidGeckoEvent::DRAW, combinedRect); // XXX We may want to consider using regions instead of rectangles. // Print an error if we're upload a lot more than we would // if we handled this as two separate events. int boundsArea = combinedRect.width * combinedRect.height; if (boundsArea > combinedArea * 8) ALOG("nsAppShell::ProcessNextNativeEvent: " "Area of bounds greatly exceeds combined area: %d > %d", boundsArea, combinedArea); // Remove the next draw event PopNextEvent(); delete nextEvent; #if defined(DEBUG_ANDROID_EVENTS) ALOG("# Removing DRAW event (%d outstanding)", mNumDraws); #endif nextEvent = PeekNextEvent(); nextType = nextEvent->Type(); } // If the next type of event isn't the same as the current type, // we don't coalesce. if (nextType != curType) break; // Can only coalesce motion move events, for motion events if (curType != AndroidGeckoEvent::MOTION_EVENT) break; if (!(curEvent->Action() == AndroidMotionEvent::ACTION_MOVE && nextEvent->Action() == AndroidMotionEvent::ACTION_MOVE)) break; #if defined(DEBUG_ANDROID_EVENTS) ALOG("# Removing % 2d event", curType); #endif curEvent = PopNextEvent(); nextEvent = PeekNextEvent(); } EVLOG("nsAppShell: event %p %d [ndraws %d]", (void*)curEvent.get(), curEvent->Type(), mNumDraws); switch (curEvent->Type()) { case AndroidGeckoEvent::NATIVE_POKE: NativeEventCallback(); break; case AndroidGeckoEvent::SENSOR_EVENT: { mPendingSensorEvents = false; InfallibleTArray<float> values; mozilla::hal::SensorType type = (mozilla::hal::SensorType) curEvent->Flags(); switch (type) { case hal::SENSOR_ORIENTATION: values.AppendElement(curEvent->X()); values.AppendElement(-curEvent->Y()); values.AppendElement(-curEvent->Z()); break; case hal::SENSOR_ACCELERATION: case hal::SENSOR_LINEAR_ACCELERATION: case hal::SENSOR_GYROSCOPE: values.AppendElement(-curEvent->X()); values.AppendElement(curEvent->Y()); values.AppendElement(curEvent->Z()); break; case hal::SENSOR_PROXIMITY: 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(nsnull, "memory-pressure", minimize.get()); obsServ->NotifyObservers(nsnull, "application-background", nsnull); break; } case AndroidGeckoEvent::ACTIVITY_SHUTDOWN: { nsCOMPtr<nsIObserverService> obsServ = mozilla::services::GetObserverService(); NS_NAMED_LITERAL_STRING(context, "shutdown-persist"); obsServ->NotifyObservers(nsnull, "quit-application-granted", nsnull); obsServ->NotifyObservers(nsnull, "quit-application-forced", nsnull); obsServ->NotifyObservers(nsnull, "profile-change-net-teardown", context.get()); obsServ->NotifyObservers(nsnull, "profile-change-teardown", context.get()); obsServ->NotifyObservers(nsnull, "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(nsnull, "application-background", nsnull); } // 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(nsnull); } break; } case AndroidGeckoEvent::ACTIVITY_START: { if (curEvent->Flags() > 0) break; nsCOMPtr<nsIObserverService> obsServ = mozilla::services::GetObserverService(); obsServ->NotifyObservers(nsnull, "application-foreground", nsnull); break; } case AndroidGeckoEvent::SCREENSHOT: { if (!mBrowserApp) break; AndroidBridge* bridge = AndroidBridge::Bridge(); if (!bridge) break; nsCOMPtr<nsIDOMWindow> domWindow; nsCOMPtr<nsIBrowserTab> tab; float scale; mBrowserApp->GetBrowserTab(curEvent->MetaState(), getter_AddRefs(tab)); if (!tab) break; tab->GetWindow(getter_AddRefs(domWindow)); if (!domWindow) break; if (NS_FAILED(tab->GetScale(&scale))) break; nsTArray<nsIntPoint> points = curEvent->Points(); NS_ASSERTION(points.Length() == 2, "Screenshot event does not have enough coordinates"); bridge->TakeScreenshot(domWindow, 0, 0, points[0].x, points[0].y, points[1].x, points[1].y, curEvent->MetaState(), scale); 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(nsnull, 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; const char *argv[3] = { "dummyappname", "-remote", uri }; nsresult rv = cmdline->Init(3, const_cast<char **>(argv), nsnull, nsICommandLine::STATE_REMOTE_AUTO); if (NS_SUCCEEDED(rv)) cmdline->Run(); nsMemory::Free(uri); 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 nsAndroidHistory::NotifyURIVisited(nsString(curEvent->Characters())); #endif break; } case AndroidGeckoEvent::NETWORK_CHANGED: { hal::NotifyNetworkChange(hal::NetworkInformation(curEvent->Bandwidth(), curEvent->CanBeMetered())); break; } case AndroidGeckoEvent::ACTIVITY_RESUMING: { if (curEvent->Flags() == 0) { // We didn't return from one of our own activities, so restore // to foreground status nsCOMPtr<nsIObserverService> obsServ = mozilla::services::GetObserverService(); obsServ->NotifyObservers(nsnull, "application-foreground", nsnull); } break; } case AndroidGeckoEvent::SCREENORIENTATION_CHANGED: { hal::NotifyScreenOrientationChange(static_cast<dom::ScreenOrientation>(curEvent->ScreenOrientation())); break; } default: nsWindow::OnGlobalAndroidEvent(curEvent); } EVLOG("nsAppShell: -- done event %p %d", (void*)curEvent.get(), curEvent->Type()); return true; }