OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/search_engines/search_provider_install_state_message_fi lter.h" | 5 #include "chrome/browser/search_engines/search_provider_install_state_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "chrome/browser/google/google_url_tracker_factory.h" | 9 #include "chrome/browser/google/google_url_tracker_factory.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/search_engines/template_url_service_factory.h" | 11 #include "chrome/browser/search_engines/template_url_service_factory.h" |
12 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" | 12 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" |
13 #include "chrome/common/render_messages.h" | 13 #include "chrome/common/search_provider.mojom.h" |
14 #include "content/public/browser/owned_interface.h" | |
14 #include "content/public/browser/render_process_host.h" | 15 #include "content/public/browser/render_process_host.h" |
16 #include "services/shell/public/cpp/interface_registry.h" | |
15 #include "url/gurl.h" | 17 #include "url/gurl.h" |
16 | 18 |
17 using content::BrowserThread; | 19 using content::BrowserThread; |
18 | 20 |
19 SearchProviderInstallStateMessageFilter:: | 21 SearchProviderInstallStateImpl::SearchProviderInstallStateImpl( |
20 SearchProviderInstallStateMessageFilter( | |
21 int render_process_id, | 22 int render_process_id, |
22 Profile* profile) | 23 Profile* profile) |
23 : BrowserMessageFilter(ChromeMsgStart), | 24 : provider_data_(TemplateURLServiceFactory::GetForProfile(profile), |
24 provider_data_(TemplateURLServiceFactory::GetForProfile(profile), | |
25 UIThreadSearchTermsData(profile).GoogleBaseURLValue(), | 25 UIThreadSearchTermsData(profile).GoogleBaseURLValue(), |
26 GoogleURLTrackerFactory::GetForProfile(profile), | 26 GoogleURLTrackerFactory::GetForProfile(profile), |
27 content::RenderProcessHost::FromID(render_process_id)), | 27 content::RenderProcessHost::FromID(render_process_id)), |
28 is_off_the_record_(profile->IsOffTheRecord()), | 28 is_off_the_record_(profile->IsOffTheRecord()), |
29 weak_factory_(this) { | 29 weak_factory_(this) { |
30 // This is initialized by RenderProcessHostImpl. Do not add any non-trivial | 30 // This is initialized by RenderProcessHostImpl. Do not add any non-trivial |
31 // initialization here. Instead do it lazily when required. | 31 // initialization here. Instead do it lazily when required. |
32 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 32 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
33 } | 33 } |
34 | 34 |
35 bool SearchProviderInstallStateMessageFilter::OnMessageReceived( | 35 SearchProviderInstallStateImpl::~SearchProviderInstallStateImpl() { |
36 const IPC::Message& message) { | |
37 DCHECK_CURRENTLY_ON(BrowserThread::IO); | |
38 bool handled = true; | |
39 IPC_BEGIN_MESSAGE_MAP(SearchProviderInstallStateMessageFilter, message) | |
40 IPC_MESSAGE_HANDLER_DELAY_REPLY( | |
41 ChromeViewHostMsg_GetSearchProviderInstallState, | |
42 OnGetSearchProviderInstallState) | |
43 IPC_MESSAGE_UNHANDLED(handled = false) | |
44 IPC_END_MESSAGE_MAP() | |
45 return handled; | |
46 } | |
47 | |
48 SearchProviderInstallStateMessageFilter:: | |
49 ~SearchProviderInstallStateMessageFilter() { | |
50 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 36 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
51 } | 37 } |
52 | 38 |
53 search_provider::InstallState | 39 // Register the given interface impl. The impl is owned by the host. Messages |
54 SearchProviderInstallStateMessageFilter::GetSearchProviderInstallState( | 40 // will be dispatched on |task_runner| (or on the default task runner if not |
41 // given). The impl will also be deleted on |task_runner|. | |
42 template <typename InterfaceImpl> | |
43 void InstallService2( | |
yzshen1
2016/07/21 15:42:38
It seems this is not used anywhere?
tibell
2016/07/22 00:19:53
Good catch.
Fixed in https://codereview.chromium.
| |
44 content::RenderProcessHost* host, | |
45 std::unique_ptr<InterfaceImpl> impl, | |
46 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner = nullptr) { | |
47 host->AddOwnedInterface(std::move(impl), task_runner); | |
48 } | |
49 | |
50 void SearchProviderInstallStateImpl::Bind( | |
51 chrome::mojom::SearchProviderInstallStateRequest request) { | |
52 binding_set_.AddBinding(this, std::move(request)); | |
53 } | |
54 | |
55 chrome::mojom::InstallState | |
56 SearchProviderInstallStateImpl::GetSearchProviderInstallState( | |
55 const GURL& page_location, | 57 const GURL& page_location, |
56 const GURL& requested_host) { | 58 const GURL& requested_host) { |
57 GURL requested_origin = requested_host.GetOrigin(); | 59 GURL requested_origin = requested_host.GetOrigin(); |
58 | 60 |
59 // Do the security check before any others to avoid information leaks. | 61 // Do the security check before any others to avoid information leaks. |
60 if (page_location.GetOrigin() != requested_origin) | 62 if (page_location.GetOrigin() != requested_origin) |
61 return search_provider::DENIED; | 63 return chrome::mojom::InstallState::DENIED; |
62 | 64 |
63 // In incognito mode, no search information is exposed. (This check must be | 65 // In incognito mode, no search information is exposed. (This check must be |
64 // done after the security check or else a web site can detect that the | 66 // done after the security check or else a web site can detect that the |
65 // user is in incognito mode just by doing a cross origin request.) | 67 // user is in incognito mode just by doing a cross origin request.) |
66 if (is_off_the_record_) | 68 if (is_off_the_record_) |
67 return search_provider::NOT_INSTALLED; | 69 return chrome::mojom::InstallState::NOT_INSTALLED; |
68 | 70 |
69 switch (provider_data_.GetInstallState(requested_origin)) { | 71 switch (provider_data_.GetInstallState(requested_origin)) { |
70 case SearchProviderInstallData::NOT_INSTALLED: | 72 case SearchProviderInstallData::NOT_INSTALLED: |
71 return search_provider::NOT_INSTALLED; | 73 return chrome::mojom::InstallState::NOT_INSTALLED; |
72 | 74 |
73 case SearchProviderInstallData::INSTALLED_BUT_NOT_DEFAULT: | 75 case SearchProviderInstallData::INSTALLED_BUT_NOT_DEFAULT: |
74 return search_provider::INSTALLED_BUT_NOT_DEFAULT; | 76 return chrome::mojom::InstallState::INSTALLED_BUT_NOT_DEFAULT; |
75 | 77 |
76 case SearchProviderInstallData::INSTALLED_AS_DEFAULT: | 78 case SearchProviderInstallData::INSTALLED_AS_DEFAULT: |
77 return search_provider::INSTALLED_AS_DEFAULT; | 79 return chrome::mojom::InstallState::INSTALLED_AS_DEFAULT; |
78 } | 80 } |
79 | 81 |
80 NOTREACHED(); | 82 NOTREACHED(); |
81 return search_provider::NOT_INSTALLED; | 83 return chrome::mojom::InstallState::NOT_INSTALLED; |
82 } | 84 } |
83 | 85 |
84 void | 86 void SearchProviderInstallStateImpl::GetInstallState( |
85 SearchProviderInstallStateMessageFilter::OnGetSearchProviderInstallState( | |
86 const GURL& page_location, | 87 const GURL& page_location, |
87 const GURL& requested_host, | 88 const GURL& requested_host, |
88 IPC::Message* reply_msg) { | 89 const GetInstallStateCallback& callback) { |
89 provider_data_.CallWhenLoaded( | 90 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
90 base::Bind( | 91 provider_data_.CallWhenLoaded(base::Bind( |
91 &SearchProviderInstallStateMessageFilter:: | 92 &SearchProviderInstallStateImpl::ReplyWithProviderInstallState, |
92 ReplyWithProviderInstallState, | 93 weak_factory_.GetWeakPtr(), page_location, requested_host, callback)); |
93 weak_factory_.GetWeakPtr(), | |
94 page_location, | |
95 requested_host, | |
96 reply_msg)); | |
97 } | 94 } |
98 | 95 |
99 void SearchProviderInstallStateMessageFilter::ReplyWithProviderInstallState( | 96 void SearchProviderInstallStateImpl::ReplyWithProviderInstallState( |
100 const GURL& page_location, | 97 const GURL& page_location, |
101 const GURL& requested_host, | 98 const GURL& requested_host, |
102 IPC::Message* reply_msg) { | 99 const GetInstallStateCallback& callback) { |
103 DCHECK(reply_msg); | 100 chrome::mojom::InstallState install_state = |
104 search_provider::InstallState install_state = | |
105 GetSearchProviderInstallState(page_location, requested_host); | 101 GetSearchProviderInstallState(page_location, requested_host); |
106 | 102 |
107 ChromeViewHostMsg_GetSearchProviderInstallState::WriteReplyParams( | 103 callback.Run(install_state); |
108 reply_msg, | |
109 install_state); | |
110 Send(reply_msg); | |
111 } | 104 } |
OLD | NEW |