Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / chrome / renderer / searchbox / search_bouncer.cc
blob35899c046b9705f071456f9ae2da190815f17338
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"
13 namespace {
14 base::LazyInstance<SearchBouncer>::Leaky g_search_bouncer =
15 LAZY_INSTANCE_INITIALIZER;
16 } // namespace
18 SearchBouncer::SearchBouncer() {
21 SearchBouncer::~SearchBouncer() {
24 // static
25 SearchBouncer* SearchBouncer::GetInstance() {
26 return g_search_bouncer.Pointer();
29 bool SearchBouncer::ShouldFork(const GURL& url) const {
30 if (!url.is_valid())
31 return false;
32 for (std::vector<GURL>::const_iterator it = search_urls_.begin();
33 it != search_urls_.end(); ++it) {
34 if (search::MatchesOriginAndPath(url, *it)) {
35 return true;
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) {
46 bool handled = true;
47 IPC_BEGIN_MESSAGE_MAP(SearchBouncer, message)
48 IPC_MESSAGE_HANDLER(ChromeViewMsg_SetSearchURLs, OnSetSearchURLs)
49 IPC_MESSAGE_UNHANDLED(handled = false)
50 IPC_END_MESSAGE_MAP()
52 return handled;
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;