summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorlevin@chromium.org <levin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-23 22:01:25 +0000
committerlevin@chromium.org <levin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-23 22:01:25 +0000
commit52ded45f70f0defc422d0fcf2b1cd873be839a69 (patch)
tree941775d84d7f4cf93b60a11324dc955022323a16 /chrome
parent36e8db95f83d177c765a4401ad86df822b81efc2 (diff)
downloadchromium_src-52ded45f70f0defc422d0fcf2b1cd873be839a69.zip
chromium_src-52ded45f70f0defc422d0fcf2b1cd873be839a69.tar.gz
chromium_src-52ded45f70f0defc422d0fcf2b1cd873be839a69.tar.bz2
Skeleton of sync handler on the I/O thread for GetSearchProviderInstallState.
BUG=38475 TEST=Not fully testable yet (but the test is unit_test --gtest_filter=SearchProviderTest.TestIsSearchProviderInstalled Review URL: http://codereview.chromium.org/3117034 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57114 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.cc6
-rw-r--r--chrome/browser/renderer_host/resource_message_filter.h5
-rw-r--r--chrome/browser/search_engines/search_provider_install_state_dispatcher_host.cc90
-rw-r--r--chrome/browser/search_engines/search_provider_install_state_dispatcher_host.h56
-rw-r--r--chrome/chrome_browser.gypi2
-rw-r--r--chrome/common/render_messages_internal.h5
-rw-r--r--chrome/renderer/external_extension.cc5
-rw-r--r--chrome/renderer/render_view.cc5
-rw-r--r--chrome/renderer/render_view.h4
9 files changed, 173 insertions, 5 deletions
diff --git a/chrome/browser/renderer_host/resource_message_filter.cc b/chrome/browser/renderer_host/resource_message_filter.cc
index 471d3ba..6f00e94 100644
--- a/chrome/browser/renderer_host/resource_message_filter.cc
+++ b/chrome/browser/renderer_host/resource_message_filter.cc
@@ -53,6 +53,7 @@
#include "chrome/browser/renderer_host/database_dispatcher_host.h"
#include "chrome/browser/renderer_host/render_view_host_notification_task.h"
#include "chrome/browser/renderer_host/render_widget_helper.h"
+#include "chrome/browser/search_engines/search_provider_install_state_dispatcher_host.h"
#include "chrome/browser/speech/speech_input_dispatcher_host.h"
#include "chrome/browser/spellchecker_platform_engine.h"
#include "chrome/browser/task_manager.h"
@@ -244,6 +245,9 @@ ResourceMessageFilter::ResourceMessageFilter(
ALLOW_THIS_IN_INITIALIZER_LIST(geolocation_dispatcher_host_(
GeolocationDispatcherHost::New(
this->id(), profile->GetGeolocationPermissionContext()))),
+ ALLOW_THIS_IN_INITIALIZER_LIST(
+ search_provider_install_state_dispatcher_host_(
+ new SearchProviderInstallStateDispatcherHost(this, profile))),
ALLOW_THIS_IN_INITIALIZER_LIST(device_orientation_dispatcher_host_(
new device_orientation::DispatcherHost(this->id()))),
ALLOW_THIS_IN_INITIALIZER_LIST(file_system_dispatcher_host_(
@@ -353,6 +357,8 @@ bool ResourceMessageFilter::OnMessageReceived(const IPC::Message& msg) {
msg, this, next_route_id_callback(), &msg_is_ok) ||
geolocation_dispatcher_host_->OnMessageReceived(msg, &msg_is_ok) ||
speech_input_dispatcher_host_->OnMessageReceived(msg, &msg_is_ok) ||
+ search_provider_install_state_dispatcher_host_->OnMessageReceived(
+ msg, &msg_is_ok) ||
device_orientation_dispatcher_host_->OnMessageReceived(msg, &msg_is_ok) ||
file_system_dispatcher_host_->OnMessageReceived(msg, &msg_is_ok);
diff --git a/chrome/browser/renderer_host/resource_message_filter.h b/chrome/browser/renderer_host/resource_message_filter.h
index 83d4985..51fcd66 100644
--- a/chrome/browser/renderer_host/resource_message_filter.h
+++ b/chrome/browser/renderer_host/resource_message_filter.h
@@ -43,6 +43,7 @@ class IndexedDBDispatcherHost;
class NotificationsPrefsCache;
class Profile;
class RenderWidgetHelper;
+class SearchProviderInstallStateDispatcherHost;
class URLRequestContextGetter;
struct ViewHostMsg_CreateWindow_Params;
struct ViewHostMsg_CreateWorker_Params;
@@ -469,6 +470,10 @@ class ResourceMessageFilter : public IPC::ChannelProxy::MessageFilter,
// Used to handle geolocation-related messages.
scoped_refptr<GeolocationDispatcherHost> geolocation_dispatcher_host_;
+ // Used to handle search provider related messages.
+ scoped_ptr<SearchProviderInstallStateDispatcherHost>
+ search_provider_install_state_dispatcher_host_;
+
// Used to handle device orientation related messages.
scoped_refptr<device_orientation::DispatcherHost>
device_orientation_dispatcher_host_;
diff --git a/chrome/browser/search_engines/search_provider_install_state_dispatcher_host.cc b/chrome/browser/search_engines/search_provider_install_state_dispatcher_host.cc
new file mode 100644
index 0000000..87803ba
--- /dev/null
+++ b/chrome/browser/search_engines/search_provider_install_state_dispatcher_host.cc
@@ -0,0 +1,90 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/search_engines/search_provider_install_state_dispatcher_host.h"
+
+#include "base/logging.h"
+#include "chrome/browser/chrome_thread.h"
+#include "chrome/browser/profile.h"
+#include "chrome/browser/renderer_host/render_view_host.h"
+#include "chrome/browser/renderer_host/resource_message_filter.h"
+#include "chrome/common/render_messages.h"
+#include "ipc/ipc_message.h"
+#include "googleurl/src/gurl.h"
+
+SearchProviderInstallStateDispatcherHost::
+SearchProviderInstallStateDispatcherHost(
+ ResourceMessageFilter* ipc_sender,
+ Profile* profile)
+ : ipc_sender_(ipc_sender),
+ is_off_the_record_(profile->IsOffTheRecord()) {
+ // This is initialized by ResourceMessageFilter. Do not add any non-trivial
+ // initialization here. Instead do it lazily when required.
+ DCHECK(ipc_sender);
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI));
+}
+
+SearchProviderInstallStateDispatcherHost::
+~SearchProviderInstallStateDispatcherHost() {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+}
+
+void SearchProviderInstallStateDispatcherHost::Send(IPC::Message* message) {
+ ipc_sender_->Send(message);
+}
+
+bool SearchProviderInstallStateDispatcherHost::OnMessageReceived(
+ const IPC::Message& message,
+ bool* message_was_ok) {
+ DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO));
+ bool handled = true;
+ IPC_BEGIN_MESSAGE_MAP_EX(SearchProviderInstallStateDispatcherHost, message,
+ *message_was_ok)
+ IPC_MESSAGE_HANDLER_DELAY_REPLY(ViewHostMsg_GetSearchProviderInstallState,
+ OnMsgGetSearchProviderInstallState)
+ IPC_MESSAGE_UNHANDLED(handled = false)
+ IPC_END_MESSAGE_MAP()
+ return handled;
+}
+
+ViewHostMsg_GetSearchProviderInstallState_Params
+SearchProviderInstallStateDispatcherHost::GetSearchProviderInstallState(
+ const GURL& page_location,
+ const GURL& requested_host) {
+ GURL requested_origin = requested_host.GetOrigin();
+
+ // Do the security check before any others to avoid information leaks.
+ if (page_location.GetOrigin() != requested_origin)
+ return ViewHostMsg_GetSearchProviderInstallState_Params::Denied();
+
+ // In incognito mode, no search information is exposed. (This check must be
+ // done after the security check or else a web site can detect that the
+ // user is in incognito mode just by doing a cross origin request.)
+ if (is_off_the_record_)
+ return ViewHostMsg_GetSearchProviderInstallState_Params::NotInstalled();
+
+ // TODO(levin): Real logic goes here.
+ return ViewHostMsg_GetSearchProviderInstallState_Params::NotInstalled();
+}
+
+void
+SearchProviderInstallStateDispatcherHost::OnMsgGetSearchProviderInstallState(
+ const GURL& page_location,
+ const GURL& requested_host,
+ IPC::Message* reply_msg) {
+ ViewHostMsg_GetSearchProviderInstallState_Params install_state =
+ GetSearchProviderInstallState(page_location, requested_host);
+ ReplyWithProviderInstallState(reply_msg, install_state);
+}
+
+void SearchProviderInstallStateDispatcherHost::ReplyWithProviderInstallState(
+ IPC::Message* reply_msg,
+ ViewHostMsg_GetSearchProviderInstallState_Params install_state) {
+ DCHECK(reply_msg);
+
+ ViewHostMsg_GetSearchProviderInstallState::WriteReplyParams(
+ reply_msg,
+ install_state);
+ Send(reply_msg);
+}
diff --git a/chrome/browser/search_engines/search_provider_install_state_dispatcher_host.h b/chrome/browser/search_engines/search_provider_install_state_dispatcher_host.h
new file mode 100644
index 0000000..d7de57f
--- /dev/null
+++ b/chrome/browser/search_engines/search_provider_install_state_dispatcher_host.h
@@ -0,0 +1,56 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_SEARCH_ENGINES_SEARCH_PROVIDER_INSTALL_STATE_DISPATCHER_HOST_H_
+#define CHROME_BROWSER_SEARCH_ENGINES_SEARCH_PROVIDER_INSTALL_STATE_DISPATCHER_HOST_H_
+
+#include "base/basictypes.h"
+
+namespace IPC {
+class Message;
+}
+
+class GURL;
+class Profile;
+class ResourceMessageFilter;
+struct ViewHostMsg_GetSearchProviderInstallState_Params;
+
+// Handles messages regarding search provider install state on the I/O thread.
+class SearchProviderInstallStateDispatcherHost {
+ public:
+ // Unlike the other methods, the constructor is called on the UI thread.
+ SearchProviderInstallStateDispatcherHost(ResourceMessageFilter* ipc_sender,
+ Profile* profile);
+ ~SearchProviderInstallStateDispatcherHost();
+
+ // Send a message to the renderer process.
+ void Send(IPC::Message* message);
+
+ // Called to possibly handle the incoming IPC message. Returns true if
+ // handled.
+ bool OnMessageReceived(const IPC::Message& message, bool* message_was_ok);
+
+ private:
+ // Figures out the install state for the search provider.
+ ViewHostMsg_GetSearchProviderInstallState_Params
+ GetSearchProviderInstallState(const GURL& page_location,
+ const GURL& requested_host);
+
+ // Starts handling the message requesting the search provider install state.
+ void OnMsgGetSearchProviderInstallState(const GURL& page_location,
+ const GURL& requested_host,
+ IPC::Message* reply_msg);
+
+ // Sends the reply message about the search provider install state.
+ void ReplyWithProviderInstallState(
+ IPC::Message* reply_msg,
+ ViewHostMsg_GetSearchProviderInstallState_Params install_state);
+
+ ResourceMessageFilter* ipc_sender_;
+ const bool is_off_the_record_;
+
+ DISALLOW_COPY_AND_ASSIGN(SearchProviderInstallStateDispatcherHost);
+};
+
+#endif // CHROME_BROWSER_SEARCH_ENGINES_SEARCH_PROVIDER_INSTALL_STATE_DISPATCHER_HOST_H_
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index ed39207..22901b4 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -2369,6 +2369,8 @@
'browser/search_engines/edit_search_engine_controller.h',
'browser/search_engines/keyword_editor_controller.cc',
'browser/search_engines/keyword_editor_controller.h',
+ 'browser/search_engines/search_provider_install_state_dispatcher_host.cc',
+ 'browser/search_engines/search_provider_install_state_dispatcher_host.h',
'browser/search_engines/template_url.cc',
'browser/search_engines/template_url.h',
'browser/search_engines/template_url_fetcher.cc',
diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h
index 5bfb341..ec47c92 100644
--- a/chrome/common/render_messages_internal.h
+++ b/chrome/common/render_messages_internal.h
@@ -1612,9 +1612,10 @@ IPC_BEGIN_MESSAGES(ViewHost)
// Find out if the given url's security origin is installed as a search
// provider.
- IPC_SYNC_MESSAGE_ROUTED1_1(
+ IPC_SYNC_MESSAGE_ROUTED2_1(
ViewHostMsg_GetSearchProviderInstallState,
- GURL,
+ GURL /* page url */,
+ GURL /* inquiry url */,
ViewHostMsg_GetSearchProviderInstallState_Params /* install */)
// Required for updating text input state.
diff --git a/chrome/renderer/external_extension.cc b/chrome/renderer/external_extension.cc
index 8a1b6ec..251a12a 100644
--- a/chrome/renderer/external_extension.cc
+++ b/chrome/renderer/external_extension.cc
@@ -124,8 +124,11 @@ v8::Handle<v8::Value> ExternalExtensionWrapper::IsSearchProviderInstalled(
RenderView* render_view = GetRenderView();
if (!render_view) return v8::Undefined();
+ WebFrame* webframe = WebFrame::frameForEnteredContext();
+ if (!webframe) return v8::Undefined();
+
ViewHostMsg_GetSearchProviderInstallState_Params install
- = render_view->GetSearchProviderInstallState(name);
+ = render_view->GetSearchProviderInstallState(webframe, name);
if (install.state ==
ViewHostMsg_GetSearchProviderInstallState_Params::DENIED) {
// FIXME: throw access denied exception.
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index 2e66fc7..8ab971c 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -1609,12 +1609,15 @@ void RenderView::AddSearchProvider(const std::string& url) {
}
ViewHostMsg_GetSearchProviderInstallState_Params
-RenderView::GetSearchProviderInstallState(const std::string& url) {
+RenderView::GetSearchProviderInstallState(WebFrame* frame,
+ const std::string& url) {
GURL inquiry_url = GURL(url);
if (inquiry_url.is_empty())
return ViewHostMsg_GetSearchProviderInstallState_Params::Denied();
+
ViewHostMsg_GetSearchProviderInstallState_Params install;
Send(new ViewHostMsg_GetSearchProviderInstallState(routing_id_,
+ frame->url(),
inquiry_url,
&install));
return install;
diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h
index 7000d2a..46b6bae 100644
--- a/chrome/renderer/render_view.h
+++ b/chrome/renderer/render_view.h
@@ -104,6 +104,7 @@ class WebApplicationCacheHostClient;
class WebDataSource;
class WebDocument;
class WebDragData;
+class WebFrame;
class WebGeolocationServiceInterface;
class WebImage;
class WebInputElement;
@@ -214,7 +215,8 @@ class RenderView : public RenderWidget,
// Returns the install state for the given search provider url.
ViewHostMsg_GetSearchProviderInstallState_Params
- GetSearchProviderInstallState(const std::string& url);
+ GetSearchProviderInstallState(WebKit::WebFrame* frame,
+ const std::string& url);
// Evaluates a string of JavaScript in a particular frame.
void EvaluateScript(const std::wstring& frame_xpath,