The are not "obligated to do so". It's a myth that a business can't pursue anything but short-term gains. Executives have a lot of leeway in how they conduct their affairs and the only thing that can stop them is the board, which is often dominated by the founders, a few large investors or the CxOs anyway.
Remember "corporations are people, my friend?". If that idea can't be stopped, it should be coopted to imply that companies should behave morally above and beyond what the law requires. If we expect people to volunteer and donate, why not expect the same from corporations? That's not my idea, by the way. It's a trend called "corporate social responsibility".
There's also just too much ambiguity between "good business" and "morality" for any hard rules to apply. Is paying workers in poor countries a living wage a waste of money (and thus "illegal") or does it make business sense because it creates employee loyalty & good PR? Is Tim Cook wasting the shareholders' money when Apple spends a few million extra to power their data center with renewable energy or is that good PR, as well as future-proofing your investment?
In the case of Google & FB, their size creates a situation where any additional internet user creates so much value for them that it becomes economically viable to spend a significant amount of money to get that user online. In this case, the idea that "cooperations should only care about the bottom line" actually creates the insane situation that people like you argue that companies shouldn't do something simply because it _also_ happens to help people.