The US Navy has agreed to limit its use of sonar that may inadvertently harm whales and dolphins in waters near Hawaii and California.