London (CNN) -- Rebekah Brooks, a former newspaper editor and News Corp. executive, was grilled Friday about her close relationship with Prime Minister David Cameron and other top politicians at a UK inquiry into media ethics.
Brooks detailed frequent contacts with Cameron in the run-up to the 2010 election and said she had received commiserations from the prime minister when she resigned from News International last summer.
She said the message, along the lines of "keep your head up," was among a number of "indirect messages" of sympathy that top politicians sent to her.
Brooks resigned as chief executive of News International, the British arm of Rupert Murdoch's News Corp., in July amid public outrage over claims of widespread hacking by staff at its News of the World newspaper.
The government-appointed Leveson Inquiry, set up in response to the accusations of phone hacking by the News of the World, is examining the links between Britain's media and politics.
Brooks' testimony about the contacts she had with Britain's current and former prime ministers could prove embarrassing to them if it reveals too close a relationship.
And her evidence surrounding News Corp.'s bid to take over full ownership of British satellite broadcaster BSkyB may prompt further questions.
Brooks, who said she had an "informal role" in lobbying for the bid, told the inquiry she had discussed it with both Cameron and Chancellor of the Exchequer George Osborne.
An e-mail from a News Corp. employee to Brooks also suggested Culture Secretary Jeremy Hunt had asked him to advise privately on how News International was dealing with the phone hacking allegations, the inquiry heard.
The employee is known to have referred to contact with Hunt -- the Cabinet minister who oversees British broadcasting and who was charged with making an impartial decision on the bid -- when he in fact dealt with Hunt's aide.
The aide was forced to resign last month over revelations of apparent back-channel communications between his office and News Corp. over the bid.
The controversial bid was eventually abandoned last summer amid the furor over the phone hacking scandal.
Brooks said her discussion of the takeover with Cameron was not in depth, and that he made it clear it was not his decision to make.
She also argued in favor of the bid to Osborne over dinner, but he was not explicitly supportive of it, Brooks said. It was an appropriate conversation to have, she told inquiry lawyer Robert Jay, as she was entitled to reflect the opposite view to what Osborne had heard from many other news outlets.
In the closing minutes of her five hours of testimony -- during which she appeared largely composed but grew more testy as time wore on -- Brooks defended her position as an editor and chief executive.
She said "much has been made of cozy relationships and informal contacts" between journalists and politicians, but that it came down to individuals to ensure their conduct was professional.
The system is not perfect, she told the judge overseeing the inquiry, Lord Justice Leveson, but the current government has taken steps to improve transparency about meetings between the press and politicians.
Brooks said the phone hacking scandal increasingly occupied her time in her final months at News International.
But she denied being a "go-between" in an increasingly fraught relationship between Rupert Murdoch and his son James, and she dismissed the suggestion the younger Murdoch had sought to shift the blame to subordinates.
Brooks also said she never witnessed any inappropriate dealings with the police.
Brooks has been arrested twice and released on bail in connection with police investigations into the scandal. She denies any knowledge of phone hacking on her watch.
The ongoing investigations mean questioning on the issue of phone hacking is limited, so as not to prejudice them or any future trial.
Questioned over her relationship with Cameron, a family friend of her husband's, Brooks said she had met him "probably three or four times" in the five months leading up to the May 2010 election.
She said they would exchange text messages once or twice a week but denied reports that there were as many as 12 texts a day.
The messages were signed off "DC" in the main, she said. Occasionally he would sign them off " 'LOL,' lots of love, until I told him it meant 'laugh out loud,' when he didn't sign them off like that any more," she said.
Asked if she and Cameron had discussed the phone hacking allegations against News of the World, she said they had done so in very general terms.
In late 2010, they had a more detailed discussion, she said, because civil cases were in court and the issue was in the news.
Brooks was editor of News of the World in 2002 when the newspaper hacked the voice mail of a missing schoolgirl, Milly Dowler, who was later found dead. The hacking scandal led to the paper's closure in 2011. Brooks then edited The Sun, Britain's biggest-selling daily tabloid, from 2003 to 2009.
Cameron has said the relationship between the media and politicians has become "too cozy." He is expected to appear before the inquiry in the coming weeks.
Testifying Friday, Brooks told the inquiry she had received "indirect messages" of sympathy on her resignation in July, from 10 Downing Street, 11 Downing Street, the Home Office and the Foreign Office.
A "very few" Labour politicians sent messages of commiseration, Brooks said.
Former Prime Minister Tony Blair sent her a message, but his successor, Gordon Brown, did not, she said.
Blair's Labour Party benefited from the support of The Sun in three elections, but the paper switched allegiance to the Conservatives before the 2010 election in which Brown lost power.
In 2009, "we were running out of ways to support Mr. Brown's government," Brooks said, explaining what lay behind the paper's shift to Cameron in September that year.
She also said Brown had been "incredibly aggressive and very angry" in a phone call to her after The Sun published stories critical of his handling of a condolence letter to the family of a soldier killed in Afghanistan.
Brooks defended The Sun's handling of an article it published in 2006 about Brown's infant son, Fraser, having cystic fibrosis, which the former prime minister criticized in 2011.
Brooks denied the paper had illegally accessed Fraser's medical records. She did not reveal The Sun's source for the article but said the Browns had given permission for the paper to run it.
She said Brown had not raised concerns in the intervening years, when they continued to meet socially, and that "Mr. Brown's recollections of that time were not the same as my own."
Asked Friday if there was a danger that her newspaper got too close to those in power and their "spin doctors," Brooks said the job of journalists was to question what they were told and serve their readers.
Brooks acknowledged becoming friendly with Blair by the end of his decade in power but said she was less friendly with Brown. She was more friends with Brown's wife, Sarah, Brooks said.
She had known Blair for more than a decade, she said, with many social and political meetings in the time he was prime minister. They also spoke on the phone and had dinners together.
Brooks and her husband, Charlie Brooks, live near Cameron's constituency home and have socialized together. She attended a private birthday party for Cameron in late 2010.
Questioned about her working relationship with Rupert Murdoch, Brooks said she was close to him and believed he trusted her implicitly.
But she rejected the suggestion that politicians thought they had to go through her to get close to Murdoch.
Brooks acknowledged she had made friendships during her years as a journalist, editor and chief executive but said she was always aware that she was a journalist and they were politicians, and assumed they also were.
Asked whether The Sun engendered fear in politicians, Brooks said she did not see them as people who were easily scared.
Jay, the inquiry lawyer, pressed Brooks over her newspaper's role in putting pressure on the Cameron government, particularly Home Secretary Theresa May, to review the case of Madeleine McCann, a child abducted in Portugal.
Brooks said The Sun had tried to persuade the government to open a review but said "threat" was too strong a word to describe its efforts.
Brooks' appearance at the Leveson Inquiry came a day after fellow ex-News of the World editor Andy Coulson, who became director of communications for Cameron after he quit the paper, took to the stand.
Critics have questioned Cameron's judgment in hiring Coulson in 2007 and asked why he was not subjected to more rigorous security vetting.
Coulson resigned as Cameron's spokesman in January 2011 when police opened a new investigation into the scandal. He insisted he was innocent but said he had become a distraction for the government.
Questioned Thursday, Coulson said the jailing of two News of the World employees over phone hacking in 2007 did come up in discussions with senior party members before his job offer.
He told the inquiry he had told them and Cameron what he has said repeatedly -- that he knew nothing about the practice of hacking under his leadership of the paper.
Coulson said he never witnessed a conversation that was "inappropriate" between members of the government and News International.
He dismissed as a conspiracy theory the suggestion that Conservatives had struck some kind of deal on News Corp.'s takeover of BSkyB in return for Murdoch's support.
CNN's Laura Perez Maestro contributed to this report.