The bubbles you see is are the formation of a crude soap on the bark of a White Pine. During dry periods salts, acids and other particles from the air coat the surface of the bark. When it rains, these mix with the water and form a solution. The foam is from the agitation of the mixture when it encounters a barrier (bark) during its flow toward the ground.
As to why this occurs primarily on pines, botanist Ken Sytsma states, “Pines produce a whole array of natural hydrocarbons for herbivory defense. One set of these is “pine tars” that have been used in the past to make soap. As precipitation works its way down trunks of pines, they accumulate these compounds. What you may be seeing is natural pine soap in the making.” (Thanks to Brenda & Steve Hillier for Mystery Photo idea.)