Chromium Code Reviews| Index: chrome/browser/webdata/web_intents_table.cc |
| diff --git a/chrome/browser/webdata/web_intents_table.cc b/chrome/browser/webdata/web_intents_table.cc |
| index b717ba4a611425347c7b8aca828631e12e145ba9..a61cb5f1471dadc9af636ccfdf95aff6d005dbc7 100644 |
| --- a/chrome/browser/webdata/web_intents_table.cc |
| +++ b/chrome/browser/webdata/web_intents_table.cc |
| @@ -2,11 +2,16 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include <string> |
|
James Hawkins
2012/02/05 05:21:51
nit: <string> include goes after the web_intents_t
Greg Billock
2012/02/07 00:45:06
Done.
|
| #include "chrome/browser/webdata/web_intents_table.h" |
| +#include "base/i18n/case_conversion.h" |
| #include "base/logging.h" |
| +#include "base/string_util.h" |
| #include "base/utf_string_conversions.h" |
| +#include "chrome/browser/intents/default_intent_service.h" |
| #include "googleurl/src/gurl.h" |
| +#include "net/base/mime_util.h" |
| #include "sql/statement.h" |
| using webkit_glue::WebIntentServiceData; |
| @@ -48,22 +53,41 @@ WebIntentsTable::~WebIntentsTable() { |
| } |
| bool WebIntentsTable::Init() { |
| - if (db_->DoesTableExist("web_intents")) |
| - return true; |
| - |
| - if (!db_->Execute("CREATE TABLE web_intents (" |
| - "service_url LONGVARCHAR," |
| - "action VARCHAR," |
| - "type VARCHAR," |
| - "title VARCHAR," |
| - "disposition VARCHAR," |
| - "UNIQUE (service_url, action, type))")) { |
| - return false; |
| + if (!db_->DoesTableExist("web_intents")) { |
| + if (!db_->Execute("CREATE TABLE web_intents (" |
| + "service_url LONGVARCHAR," |
| + "action VARCHAR," |
| + "type VARCHAR," |
| + "title LONGVARCHAR," |
| + "disposition VARCHAR," |
| + "UNIQUE (service_url, action, type))")) { |
| + return false; |
| + } |
| + } |
| + |
| + if (!db_->DoesTableExist("web_intents_defaults")) { |
| + if (!db_->Execute("CREATE TABLE web_intents_defaults (" |
| + "action VARCHAR," |
| + "type VARCHAR," |
| + "url_prefix LONGVARCHAR," |
| + "user_date INTEGER," |
| + "suppression INTEGER," |
| + "service_url LONGVARCHAR," |
| + "extension_url LONGVARCHAR," |
| + "UNIQUE (action, type, url_prefix))")) { |
| + return false; |
| + } |
| } |
| - if (!db_->Execute("CREATE INDEX web_intents_index ON web_intents (action)")) |
| + if (!db_->Execute("CREATE INDEX IF NOT EXISTS web_intents_index " |
| + "ON web_intents (action)")) |
| return false; |
| + if (!db_->Execute("CREATE INDEX IF NOT EXISTS web_intents_default_index " |
| + "ON web_intents_defaults (action)")) { |
| + return false; |
| + } |
| + |
| return true; |
| } |
| @@ -141,3 +165,68 @@ bool WebIntentsTable::RemoveWebIntentService( |
| return s.Run(); |
| } |
| + |
| +bool TypeMatches(const string16 type_pattern, |
|
James Hawkins
2012/02/05 05:21:51
Document the method.
Greg Billock
2012/02/07 00:45:06
Done.
|
| + const string16 type_match) { |
| + // Strip MIME parameters, lowercase, then check for match. |
| + std::string pattern = UTF16ToUTF8(base::i18n::ToLower(type_pattern)); |
| + pattern = pattern.substr(0, pattern.find(';')); |
| + std::string mime = UTF16ToUTF8(base::i18n::ToLower(type_match)); |
| + mime = mime.substr(0, mime.find(';')); |
| + |
| + // TODO(gbillock): put in MIME parameter matching here. |
|
groby-ooo-7-16
2012/02/06 18:34:53
We currently handle MIME type matching in WebInten
Greg Billock
2012/02/07 00:45:06
That sounds good, especially if we already have st
|
| + |
| + return net::MatchesMimeType(pattern, mime); |
|
groby-ooo-7-16
2012/02/06 18:34:53
Does not work with wild cards on one hand side of
Greg Billock
2012/02/07 00:45:06
Yeah, this assumes that the MIME type in the query
|
| +} |
| + |
| +bool UrlMatches(const std::string& url_prefix, |
|
groby-ooo-7-16
2012/02/06 18:34:53
GURLs use string16 (since URLs can be unicode)
Greg Billock
2012/02/07 00:45:06
GURL::spec() is UTF8, as are all DB entries where
groby-ooo-7-16
2012/02/08 00:48:45
Yes, but StartsWithASCII doesn't compare UTF8 :)
Greg Billock
2012/02/08 19:11:36
:-) True enough. For hostnames, it ought to work f
|
| + const std::string& url) { |
| + return StartsWithASCII(url, url_prefix, true); |
| +} |
| + |
| +bool WebIntentsTable::GetDefaultServices( |
| + const string16& action, |
| + const string16& type, |
| + const std::string& client_url, |
| + std::vector<DefaultIntentService>* default_services) { |
| + sql::Statement s(db_->GetUniqueStatement( |
| + "SELECT action, type, url_prefix, user_date, suppression, " |
| + "service_url, extension_url FROM web_intents_defaults " |
| + "WHERE action=?")); |
| + s.BindString16(0, action); |
| + |
| + while (s.Step()) { |
| + if (TypeMatches(s.ColumnString16(1), type) && |
| + UrlMatches(s.ColumnString(2), client_url)) { |
| + DefaultIntentService entry; |
| + entry.action = s.ColumnString16(0); |
| + entry.type = s.ColumnString16(1); |
| + entry.url_prefix = s.ColumnString(2); |
| + entry.user_date = s.ColumnInt(3); |
| + entry.suppression = s.ColumnInt(4); |
| + entry.service_url = s.ColumnString(5); |
| + entry.extension_url = s.ColumnString(6); |
| + default_services->push_back(entry); |
| + } |
| + } |
| + |
| + return s.Succeeded(); |
| +} |
| + |
| +bool WebIntentsTable::SetDefaultService( |
| + const DefaultIntentService& default_service) { |
| + sql::Statement s(db_->GetUniqueStatement( |
| + "INSERT OR REPLACE INTO web_intents_defaults " |
| + "(action, type, url_prefix, user_date, suppression," |
| + " service_url, extension_url) " |
| + "VALUES (?, ?, ?, ?, ?, ?, ?)")); |
| + s.BindString16(0, default_service.action); |
| + s.BindString16(1, default_service.type); |
| + s.BindString(2, default_service.url_prefix); |
| + s.BindInt(3, default_service.user_date); |
| + s.BindInt(4, default_service.suppression); |
| + s.BindString(5, default_service.service_url); |
| + s.BindString(6, default_service.extension_url); |
| + |
| + return s.Run(); |
| +} |