Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: chrome/browser/search_engines/search_provider_install_state_dispatcher_host.cc

Issue 5698008: Switch a bunch of remaining filters to derive from BrowserMessageFilters so t... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2010 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.
4
5 #include "chrome/browser/search_engines/search_provider_install_state_dispatcher _host.h"
6
7 #include "base/logging.h"
8 #include "chrome/browser/browser_thread.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/renderer_host/render_process_host.h"
11 #include "chrome/browser/renderer_host/render_view_host.h"
12 #include "chrome/browser/renderer_host/resource_message_filter.h"
13 #include "chrome/common/notification_source.h"
14 #include "chrome/common/notification_type.h"
15 #include "chrome/common/render_messages.h"
16 #include "chrome/common/render_messages_params.h"
17 #include "ipc/ipc_message.h"
18 #include "googleurl/src/gurl.h"
19
20 SearchProviderInstallStateDispatcherHost::
21 SearchProviderInstallStateDispatcherHost(
22 ResourceMessageFilter* ipc_sender,
23 Profile* profile,
24 int render_process_id)
25 : ALLOW_THIS_IN_INITIALIZER_LIST(
26 reply_with_provider_install_state_factory_(this)),
27 provider_data_(profile->GetWebDataService(Profile::EXPLICIT_ACCESS),
28 NotificationType::RENDERER_PROCESS_TERMINATED,
29 Source<RenderProcessHost>(
30 RenderProcessHost::FromID(render_process_id))),
31 ipc_sender_(ipc_sender),
32 is_off_the_record_(profile->IsOffTheRecord()) {
33 // This is initialized by ResourceMessageFilter. Do not add any non-trivial
34 // initialization here. Instead do it lazily when required.
35 DCHECK(ipc_sender);
36 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
37 }
38
39 SearchProviderInstallStateDispatcherHost::
40 ~SearchProviderInstallStateDispatcherHost() {
41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
42 }
43
44 void SearchProviderInstallStateDispatcherHost::Send(IPC::Message* message) {
45 ipc_sender_->Send(message);
46 }
47
48 bool SearchProviderInstallStateDispatcherHost::OnMessageReceived(
49 const IPC::Message& message,
50 bool* message_was_ok) {
51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
52 bool handled = true;
53 IPC_BEGIN_MESSAGE_MAP_EX(SearchProviderInstallStateDispatcherHost, message,
54 *message_was_ok)
55 IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetSearchProviderInstallState,
56 OnMsgGetSearchProviderInstallState)
57 IPC_MESSAGE_UNHANDLED(handled = false)
58 IPC_END_MESSAGE_MAP()
59 return handled;
60 }
61
62 ViewHostMsg_GetSearchProviderInstallState_Params
63 SearchProviderInstallStateDispatcherHost::GetSearchProviderInstallState(
64 const GURL& page_location,
65 const GURL& requested_host) {
66 GURL requested_origin = requested_host.GetOrigin();
67
68 // Do the security check before any others to avoid information leaks.
69 if (page_location.GetOrigin() != requested_origin)
70 return ViewHostMsg_GetSearchProviderInstallState_Params::Denied();
71
72 // In incognito mode, no search information is exposed. (This check must be
73 // done after the security check or else a web site can detect that the
74 // user is in incognito mode just by doing a cross origin request.)
75 if (is_off_the_record_)
76 return ViewHostMsg_GetSearchProviderInstallState_Params::NotInstalled();
77
78 switch (provider_data_.GetInstallState(requested_origin)) {
79 case SearchProviderInstallData::NOT_INSTALLED:
80 return ViewHostMsg_GetSearchProviderInstallState_Params::
81 NotInstalled();
82
83 case SearchProviderInstallData::INSTALLED_BUT_NOT_DEFAULT:
84 return ViewHostMsg_GetSearchProviderInstallState_Params::
85 InstallButNotDefault();
86
87 case SearchProviderInstallData::INSTALLED_AS_DEFAULT:
88 return ViewHostMsg_GetSearchProviderInstallState_Params::
89 InstalledAsDefault();
90 }
91
92 NOTREACHED();
93 return ViewHostMsg_GetSearchProviderInstallState_Params::
94 NotInstalled();
95 }
96
97 void
98 SearchProviderInstallStateDispatcherHost::OnMsgGetSearchProviderInstallState(
99 const GURL& page_location,
100 const GURL& requested_host,
101 IPC::Message* reply_msg) {
102 provider_data_.CallWhenLoaded(
103 reply_with_provider_install_state_factory_.NewRunnableMethod(
104 &SearchProviderInstallStateDispatcherHost::
105 ReplyWithProviderInstallState,
106 page_location,
107 requested_host,
108 reply_msg));
109 }
110
111 void SearchProviderInstallStateDispatcherHost::ReplyWithProviderInstallState(
112 const GURL& page_location,
113 const GURL& requested_host,
114 IPC::Message* reply_msg) {
115 DCHECK(reply_msg);
116 ViewHostMsg_GetSearchProviderInstallState_Params install_state =
117 GetSearchProviderInstallState(page_location, requested_host);
118
119 ViewHostMsg_GetSearchProviderInstallState::WriteReplyParams(
120 reply_msg,
121 install_state);
122 Send(reply_msg);
123 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698