summaryrefslogtreecommitdiffstats
path: root/chrome/browser/tab_contents
diff options
context:
space:
mode:
authorlevin@chromium.org <levin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-17 00:30:18 +0000
committerlevin@chromium.org <levin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-17 00:30:18 +0000
commit155f35e6495385739f54e457374cf7d00c741a22 (patch)
tree69f910dc9f247e6961edef40b13f39c190ca686b /chrome/browser/tab_contents
parent273fb9c93ae61f45c6455b17d357ba5aca6b7e22 (diff)
downloadchromium_src-155f35e6495385739f54e457374cf7d00c741a22.zip
chromium_src-155f35e6495385739f54e457374cf7d00c741a22.tar.gz
chromium_src-155f35e6495385739f54e457374cf7d00c741a22.tar.bz2
Implement IsSearchProviderInstalled and a test for it.
It is currently off by default and one must pass in a flag (--enable-search-provider-api-v2) to use it. Api details are in the bug. BUG=38475 TEST=ui_tests --gtest_filter=SearchProviderTest.TestIsSearchProviderInstalled Review URL: http://codereview.chromium.org/2823042 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52778 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents')
-rw-r--r--chrome/browser/tab_contents/tab_contents.cc54
-rw-r--r--chrome/browser/tab_contents/tab_contents.h2
2 files changed, 56 insertions, 0 deletions
diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc
index dd5e558..b5395cc 100644
--- a/chrome/browser/tab_contents/tab_contents.cc
+++ b/chrome/browser/tab_contents/tab_contents.cc
@@ -2713,6 +2713,60 @@ void TabContents::PageHasOSDD(RenderViewHost* render_view_host,
autodetected);
}
+// Indicates if the two inputs have the same security origin.
+// |requested_origin| should only be a security origin (no path, etc.).
+// It is ok if |template_url| is NULL.
+static bool IsSameOrigin(const GURL& requested_origin,
+ const TemplateURL* template_url) {
+ DCHECK(requested_origin == requested_origin.GetOrigin());
+ return template_url && requested_origin ==
+ TemplateURLModel::GenerateSearchURL(template_url).GetOrigin();
+}
+
+ViewHostMsg_GetSearchProviderInstallState_Params
+ TabContents::GetSearchProviderInstallState(const GURL& requested_host) {
+ // Get the last committed entry since that is the page executing the
+ // javascript as opposed to a page being navigated to. We don't want
+ // to trust the page to tell us the url to avoid using potentially
+ // compromised information.
+ NavigationEntry* entry = controller_.GetLastCommittedEntry();
+ GURL page_origin = entry ? entry->virtual_url().GetOrigin() : GURL();
+ GURL requested_origin = requested_host.GetOrigin();
+ // Do the security check before any others to avoid information leaks.
+ if (page_origin != 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 (profile()->IsOffTheRecord())
+ return ViewHostMsg_GetSearchProviderInstallState_Params::NotInstalled();
+
+ TemplateURLModel* url_model = profile()->GetTemplateURLModel();
+ if (!url_model)
+ return ViewHostMsg_GetSearchProviderInstallState_Params::NotInstalled();
+ if (!url_model->loaded())
+ url_model->Load();
+
+ // First check to see if the url is the default search provider.
+ if (IsSameOrigin(requested_origin, url_model->GetDefaultSearchProvider())) {
+ return ViewHostMsg_GetSearchProviderInstallState_Params::
+ InstalledAsDefault();
+ }
+
+ // Is the url any search provider?
+ std::vector<const TemplateURL*> urls = url_model->GetTemplateURLs();
+ for (std::vector<const TemplateURL*>::iterator i = urls.begin();
+ i != urls.end(); ++i) {
+ const TemplateURL* template_url = (*i);
+ if (IsSameOrigin(requested_origin, template_url)) {
+ return ViewHostMsg_GetSearchProviderInstallState_Params::
+ InstallButNotDefault();
+ }
+ }
+ return ViewHostMsg_GetSearchProviderInstallState_Params::NotInstalled();
+}
+
GURL TabContents::GetAlternateErrorPageURL() const {
GURL url;
// Disable alternate error pages when in OffTheRecord/Incognito mode.
diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h
index 59e75e1..3b199b2 100644
--- a/chrome/browser/tab_contents/tab_contents.h
+++ b/chrome/browser/tab_contents/tab_contents.h
@@ -950,6 +950,8 @@ class TabContents : public PageNavigator,
const std::vector<webkit_glue::PasswordForm>& visible_forms);
virtual void PageHasOSDD(RenderViewHost* render_view_host,
int32 page_id, const GURL& url, bool autodetected);
+ virtual ViewHostMsg_GetSearchProviderInstallState_Params
+ GetSearchProviderInstallState(const GURL& url);
virtual GURL GetAlternateErrorPageURL() const;
virtual RendererPreferences GetRendererPrefs(Profile* profile) const;
virtual WebPreferences GetWebkitPrefs();