1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/renderer/searchbox/search_bouncer.h"
7 #include "base/lazy_instance.h"
8 #include "chrome/common/render_messages.h"
9 #include "chrome/common/search_urls.h"
10 #include "content/public/renderer/render_process_observer.h"
11 #include "ipc/ipc_message_macros.h"
14 base::LazyInstance
<SearchBouncer
>::Leaky g_search_bouncer
=
15 LAZY_INSTANCE_INITIALIZER
;
18 SearchBouncer::SearchBouncer() {
21 SearchBouncer::~SearchBouncer() {
25 SearchBouncer
* SearchBouncer::GetInstance() {
26 return g_search_bouncer
.Pointer();
29 bool SearchBouncer::ShouldFork(const GURL
& url
) const {
32 for (std::vector
<GURL
>::const_iterator it
= search_urls_
.begin();
33 it
!= search_urls_
.end(); ++it
) {
34 if (search::MatchesOriginAndPath(url
, *it
)) {
38 return IsNewTabPage(url
);
41 bool SearchBouncer::IsNewTabPage(const GURL
& url
) const {
42 return url
.is_valid() && url
== new_tab_page_url_
;
45 bool SearchBouncer::OnControlMessageReceived(const IPC::Message
& message
) {
47 IPC_BEGIN_MESSAGE_MAP(SearchBouncer
, message
)
48 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetSearchURLs
, OnSetSearchURLs
)
49 IPC_MESSAGE_UNHANDLED(handled
= false)
55 void SearchBouncer::OnSetSearchURLs(
56 std::vector
<GURL
> search_urls
,
57 GURL new_tab_page_url
) {
58 search_urls_
= search_urls
;
59 new_tab_page_url_
= new_tab_page_url
;