diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-11 17:00:57 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-11 17:00:57 +0000 |
commit | 8427a062d29aa762bf11a3384bb6c02fa2395b16 (patch) | |
tree | 64fa1d2e4f39330eb0960cfe87c374e6be34b296 /chrome/browser/intents | |
parent | 574268ef75cf34e46b268ea035ace78b7c4b2dad (diff) | |
download | chromium_src-8427a062d29aa762bf11a3384bb6c02fa2395b16.zip chromium_src-8427a062d29aa762bf11a3384bb6c02fa2395b16.tar.gz chromium_src-8427a062d29aa762bf11a3384bb6c02fa2395b16.tar.bz2 |
Delete most web intents code.
It's already disabled, so this should have no observable effect.
The database code stays around until I've written a migration to delete the
webintents table.
The apps schema code stays around so that 'intent' blocks in apps are
silently ignored instead of causing an error.
BUG=173194
TBR=piman
Review URL: https://codereview.chromium.org/12225076
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@181702 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/intents')
29 files changed, 0 insertions, 3872 deletions
diff --git a/chrome/browser/intents/OWNERS b/chrome/browser/intents/OWNERS deleted file mode 100644 index 39a4139..0000000 --- a/chrome/browser/intents/OWNERS +++ /dev/null @@ -1,4 +0,0 @@ -gbillock@chromium.org -groby@chromium.org -jhawkins@chromium.org -smckay@chromium.org
\ No newline at end of file diff --git a/chrome/browser/intents/cws_intents_registry.cc b/chrome/browser/intents/cws_intents_registry.cc deleted file mode 100644 index 4211499..0000000 --- a/chrome/browser/intents/cws_intents_registry.cc +++ /dev/null @@ -1,235 +0,0 @@ -// Copyright (c) 2012 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/intents/cws_intents_registry.h" - -#include "base/callback.h" -#include "base/json/json_string_value_serializer.h" -#include "base/memory/scoped_ptr.h" -#include "base/stl_util.h" -#include "base/string16.h" -#include "base/utf_string_conversions.h" -#include "chrome/common/extensions/extension_l10n_util.h" -#include "chrome/common/extensions/message_bundle.h" -#include "chrome/browser/net/chrome_url_request_context.h" -#include "chrome/browser/webdata/web_data_service.h" -#include "google_apis/google_api_keys.h" -#include "net/base/load_flags.h" -#include "net/base/mime_util.h" -#include "net/base/url_util.h" -#include "net/url_request/url_fetcher.h" - -namespace { - -// Limit for the number of suggestions we fix from CWS. Ideally, the registry -// simply get all of them, but there is a) chunking on the CWS side, and b) -// there is a cost with suggestions fetched. (Network overhead for favicons, -// roundtrips to registry to check if installed). -// -// Since the picker limits the number of suggestions displayed to 5, 15 means -// the suggestion list only has the potential to be shorter than that once the -// user has at least 10 installed handlers for the particular action/type. -// -// TODO(groby): Adopt number of suggestions dynamically so the picker can -// always display 5 suggestions unless there are less than 5 viable extensions -// in the CWS. -const char kMaxSuggestions[] = "15"; - -// URL for CWS intents API. -const char kCWSIntentServiceURL[] = - "https://www.googleapis.com/chromewebstore/v1.1b/items/intent"; - -// Determines if a string is a candidate for localization. -bool ShouldLocalize(const std::string& value) { - std::string::size_type index = 0; - index = value.find(extensions::MessageBundle::kMessageBegin); - if (index == std::string::npos) - return false; - - index = value.find(extensions::MessageBundle::kMessageEnd, index); - return (index != std::string::npos); -} - -// Parses a JSON |response| from the CWS into a list of suggested extensions, -// stored in |intents|. |intents| must not be NULL. -void ParseResponse(const std::string& response, - CWSIntentsRegistry::IntentExtensionList* intents) { - std::string error; - scoped_ptr<Value> parsed_response; - JSONStringValueSerializer serializer(response); - parsed_response.reset(serializer.Deserialize(NULL, &error)); - if (parsed_response.get() == NULL) - return; - - DictionaryValue* response_dict = NULL; - if (!parsed_response->GetAsDictionary(&response_dict) || !response_dict) - return; - - ListValue* items; - if (!response_dict->GetList("items", &items)) - return; - - for (ListValue::const_iterator iter(items->begin()); - iter != items->end(); ++iter) { - DictionaryValue* item = static_cast<DictionaryValue*>(*iter); - - // All fields are mandatory - skip this result if any field isn't found. - CWSIntentsRegistry::IntentExtensionInfo info; - if (!item->GetString("id", &info.id)) - continue; - - if (!item->GetInteger("num_ratings", &info.num_ratings)) - continue; - - if (!item->GetDouble("average_rating", &info.average_rating)) - continue; - - if (!item->GetString("manifest", &info.manifest)) - continue; - - std::string manifest_utf8 = UTF16ToUTF8(info.manifest); - JSONStringValueSerializer manifest_serializer(manifest_utf8); - scoped_ptr<Value> manifest_value; - manifest_value.reset(manifest_serializer.Deserialize(NULL, &error)); - if (manifest_value.get() == NULL) - continue; - - DictionaryValue* manifest_dict; - if (!manifest_value->GetAsDictionary(&manifest_dict) || - !manifest_dict->GetString("name", &info.name)) - continue; - - string16 url_string; - if (!item->GetString("icon_url", &url_string)) - continue; - info.icon_url = GURL(url_string); - - // Need to parse CWS reply, since it is not pre-l10n'd. - ListValue* all_locales = NULL; - if (ShouldLocalize(UTF16ToUTF8(info.name)) && - item->GetList("locale_data", &all_locales)) { - std::map<std::string, std::string> localized_title; - - for (ListValue::const_iterator locale_iter(all_locales->begin()); - locale_iter != all_locales->end(); ++locale_iter) { - DictionaryValue* locale = static_cast<DictionaryValue*>(*locale_iter); - - std::string locale_id, title; - if (!locale->GetString("locale_string", &locale_id) || - !locale->GetString("title", &title)) - continue; - - localized_title[locale_id] = title; - } - - std::vector<std::string> valid_locales; - extension_l10n_util::GetAllFallbackLocales( - extension_l10n_util::CurrentLocaleOrDefault(), - "all", - &valid_locales); - for (std::vector<std::string>::iterator iter = valid_locales.begin(); - iter != valid_locales.end(); ++iter) { - if (localized_title.count(*iter)) { - info.name = UTF8ToUTF16(localized_title[*iter]); - break; - } - } - } - - intents->push_back(info); - } -} - -} // namespace - -// Internal object representing all data associated with a single query. -struct CWSIntentsRegistry::IntentsQuery { - IntentsQuery(); - ~IntentsQuery(); - - // Underlying URL request query. - scoped_ptr<net::URLFetcher> url_fetcher; - - // The callback - invoked on completed retrieval. - ResultsCallback callback; -}; - -CWSIntentsRegistry::IntentsQuery::IntentsQuery() { -} - -CWSIntentsRegistry::IntentsQuery::~IntentsQuery() { -} - -CWSIntentsRegistry::IntentExtensionInfo::IntentExtensionInfo() - : num_ratings(0), - average_rating(0) { -} - -CWSIntentsRegistry::IntentExtensionInfo::~IntentExtensionInfo() { -} - -CWSIntentsRegistry::CWSIntentsRegistry(net::URLRequestContextGetter* context) - : request_context_(context) { -} - -CWSIntentsRegistry::~CWSIntentsRegistry() { - // Cancel all pending queries, since we can't handle them any more. - STLDeleteValues(&queries_); -} - -void CWSIntentsRegistry::OnURLFetchComplete(const net::URLFetcher* source) { - DCHECK(source); - - URLFetcherHandle handle = reinterpret_cast<URLFetcherHandle>(source); - QueryMap::iterator it = queries_.find(handle); - DCHECK(it != queries_.end()); - scoped_ptr<IntentsQuery> query(it->second); - DCHECK(query.get() != NULL); - queries_.erase(it); - - std::string response; - source->GetResponseAsString(&response); - - // TODO(groby): Do we really only accept 200, or any 2xx codes? - IntentExtensionList intents; - if (source->GetResponseCode() == 200) - ParseResponse(response, &intents); - - if (!query->callback.is_null()) - query->callback.Run(intents); -} - -void CWSIntentsRegistry::GetIntentServices(const string16& action, - const string16& mimetype, - const ResultsCallback& cb) { - scoped_ptr<IntentsQuery> query(new IntentsQuery); - query->callback = cb; - query->url_fetcher.reset(net::URLFetcher::Create( - 0, BuildQueryURL(action,mimetype), net::URLFetcher::GET, this)); - - if (query->url_fetcher.get() == NULL) - return; - - query->url_fetcher->SetRequestContext(request_context_); - query->url_fetcher->SetLoadFlags( - net::LOAD_DO_NOT_SEND_COOKIES | net::LOAD_DO_NOT_SAVE_COOKIES); - - URLFetcherHandle handle = reinterpret_cast<URLFetcherHandle>( - query->url_fetcher.get()); - queries_[handle] = query.release(); - queries_[handle]->url_fetcher->Start(); -} - -// static -GURL CWSIntentsRegistry::BuildQueryURL(const string16& action, - const string16& type) { - GURL request(kCWSIntentServiceURL); - request = net::AppendQueryParameter(request, "intent", UTF16ToUTF8(action)); - request = net::AppendQueryParameter(request, "mime_types", UTF16ToUTF8(type)); - request = net::AppendQueryParameter(request, "start_index", "0"); - request = net::AppendQueryParameter(request, "num_results", kMaxSuggestions); - request = net::AppendQueryParameter(request, "key", google_apis::GetAPIKey()); - - return request; -} diff --git a/chrome/browser/intents/cws_intents_registry.h b/chrome/browser/intents/cws_intents_registry.h deleted file mode 100644 index 004de37..0000000 --- a/chrome/browser/intents/cws_intents_registry.h +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (c) 2012 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_INTENTS_CWS_INTENTS_REGISTRY_H_ -#define CHROME_BROWSER_INTENTS_CWS_INTENTS_REGISTRY_H_ - -#include <vector> - -#include "base/callback_forward.h" -#include "base/gtest_prod_util.h" -#include "base/hash_tables.h" -#include "base/memory/ref_counted.h" -#include "chrome/browser/profiles/profile_keyed_service.h" -#include "googleurl/src/gurl.h" -#include "net/url_request/url_fetcher_delegate.h" - -namespace net { -class URLRequestContextGetter; -} - -class CWSIntentsRegistryForTest; - -// Handles storing and retrieving of web intents in the web database. -// The registry provides filtering logic to retrieve specific types of intents. -class CWSIntentsRegistry : public ProfileKeyedService, - public net::URLFetcherDelegate { - public: - // Data returned from CWS for a single service. - struct IntentExtensionInfo { - IntentExtensionInfo(); - ~IntentExtensionInfo(); - - std::string id; // The id of the extension. - string16 name; // The name of the extension. - int num_ratings; // Number of ratings in CWS store. - double average_rating; // The average CWS rating. - string16 manifest; // The containing extension's manifest info. - GURL icon_url; // Where to retrieve an icon for this service. - }; - - // List of Intent extensions, as returned by GetIntentServices's |callback| - typedef std::vector<IntentExtensionInfo> IntentExtensionList; - // Callback to return results from GetIntentServices upon completion. - typedef base::Callback<void(const IntentExtensionList&)> ResultsCallback; - - // Requests all intent services matching |action| and |mimetype|. - // |mimetype| must conform to definition as outlined for - // WebIntentsRegistry::GetIntentServices. - // |callback| will be invoked upon retrieving results from CWS, returning - // a list of matching Intent extensions. - void GetIntentServices(const string16& action, - const string16& mimetype, - const ResultsCallback& callback); - - // Build a REST query URL to retrieve intent info from CWS. - static GURL BuildQueryURL(const string16& action, const string16& type); - - private: - // Make sure that only CWSIntentsRegistryFactory can create an instance of - // CWSIntentsRegistry. - friend class CWSIntentsRegistryFactory; - friend class ::CWSIntentsRegistryForTest; - - struct IntentsQuery; - - // This is an opaque version of URLFetcher*, so we can use it as a hash key. - typedef intptr_t URLFetcherHandle; - - // Maps URL fetchers to queries. IntentsQuery objects are owned by the map. - typedef base::hash_map<URLFetcherHandle, IntentsQuery*> QueryMap; - - // |context| is a profile-dependent URL request context. Must not be NULL. - explicit CWSIntentsRegistry(net::URLRequestContextGetter* context); - virtual ~CWSIntentsRegistry(); - - // net::URLFetcherDelegate implementation. - virtual void OnURLFetchComplete(const net::URLFetcher* source) OVERRIDE; - - // Map for all in-flight web data requests/intent queries. - QueryMap queries_; - - // Request context for any CWS requests. - scoped_refptr<net::URLRequestContextGetter> request_context_; - - DISALLOW_COPY_AND_ASSIGN(CWSIntentsRegistry); -}; - -#endif // CHROME_BROWSER_INTENTS_CWS_INTENTS_REGISTRY_H_ diff --git a/chrome/browser/intents/cws_intents_registry_factory.cc b/chrome/browser/intents/cws_intents_registry_factory.cc deleted file mode 100644 index 1e9a907..0000000 --- a/chrome/browser/intents/cws_intents_registry_factory.cc +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2012 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/intents/cws_intents_registry.h" -#include "chrome/browser/intents/cws_intents_registry_factory.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/profiles/profile_dependency_manager.h" - -// static -CWSIntentsRegistry* CWSIntentsRegistryFactory::GetForProfile(Profile* profile) { - return static_cast<CWSIntentsRegistry*>( - GetInstance()->GetServiceForProfile(profile, true)); -} - -CWSIntentsRegistryFactory::CWSIntentsRegistryFactory() - : ProfileKeyedServiceFactory("CWSIntentsRegistry", - ProfileDependencyManager::GetInstance()) { -} - -CWSIntentsRegistryFactory::~CWSIntentsRegistryFactory() { -} - -// static -CWSIntentsRegistryFactory* CWSIntentsRegistryFactory::GetInstance() { - return Singleton<CWSIntentsRegistryFactory>::get(); -} - -ProfileKeyedService* CWSIntentsRegistryFactory::BuildServiceInstanceFor( - Profile* profile) const { - CWSIntentsRegistry* registry = new CWSIntentsRegistry( - profile->GetRequestContext()); - return registry; -} - -bool CWSIntentsRegistryFactory::ServiceRedirectedInIncognito() const { - // TODO(groby): Do we have CWS access in incognito? - return false; -} diff --git a/chrome/browser/intents/cws_intents_registry_factory.h b/chrome/browser/intents/cws_intents_registry_factory.h deleted file mode 100644 index 5007c0f..0000000 --- a/chrome/browser/intents/cws_intents_registry_factory.h +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) 2012 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_INTENTS_CWS_INTENTS_REGISTRY_FACTORY_H_ -#define CHROME_BROWSER_INTENTS_CWS_INTENTS_REGISTRY_FACTORY_H_ - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/memory/singleton.h" -#include "chrome/browser/profiles/profile_keyed_service_factory.h" - -class CWSIntentsRegistry; -class Profile; - -// Singleton that owns all CWSIntentsRegistry objects and associates each with -// their respective profile. Listens for the profile's destruction notification -// and cleans up the associated CWSIntentsRegistry. -class CWSIntentsRegistryFactory : public ProfileKeyedServiceFactory { - public: - // Returns a weak pointer to the WebIntentsRegistry that provides intent - // registration for |profile|. - static CWSIntentsRegistry* GetForProfile(Profile* profile); - - // Returns the singleton instance of the WebIntentsRegistryFactory. - static CWSIntentsRegistryFactory* GetInstance(); - - private: - friend struct DefaultSingletonTraits<CWSIntentsRegistryFactory>; - - CWSIntentsRegistryFactory(); - virtual ~CWSIntentsRegistryFactory(); - - // ProfileKeyedServiceFactory implementation. - virtual ProfileKeyedService* BuildServiceInstanceFor( - Profile* profile) const OVERRIDE; - virtual bool ServiceRedirectedInIncognito() const OVERRIDE; - - DISALLOW_COPY_AND_ASSIGN(CWSIntentsRegistryFactory); -}; - -#endif // CHROME_BROWSER_INTENTS_CWS_INTENTS_REGISTRY_FACTORY_H_ diff --git a/chrome/browser/intents/cws_intents_registry_unittest.cc b/chrome/browser/intents/cws_intents_registry_unittest.cc deleted file mode 100644 index bc09576..0000000 --- a/chrome/browser/intents/cws_intents_registry_unittest.cc +++ /dev/null @@ -1,275 +0,0 @@ -// Copyright (c) 2012 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/intents/cws_intents_registry.h" - -#include "base/bind.h" -#include "base/bind_helpers.h" -#include "base/message_loop.h" -#include "base/utf_string_conversions.h" -#include "chrome/common/extensions/extension_l10n_util.h" -#include "net/url_request/test_url_fetcher_factory.h" -#include "net/url_request/url_request_test_util.h" -#include "testing/gtest/include/gtest/gtest.h" - -// Create a CWSIntentsRegistry proxy for testing purposes. -// Needs to be non-anonymous so it can be friended. -class CWSIntentsRegistryForTest { -public: - CWSIntentsRegistryForTest() : registry_(NULL) {} - ~CWSIntentsRegistryForTest() { delete registry_; } - - void reset(net::URLRequestContextGetter* context) { - delete registry_; - registry_ = new CWSIntentsRegistry(context); - } - - CWSIntentsRegistry* operator->() { return registry_; } - -private: - CWSIntentsRegistry* registry_; -}; - -namespace { - -const char kCWSResponseInvalid[] = - "{\"error\":{" - "\"errors\":[{" - "\"domain\":\"global\"," - "\"reason\":\"invalid\"," - "\"message\":\"Invalid mimetype:foo\"}]," - "\"code\":400," - "\"message\":\"Invalid mimetype:foo\"}}\""; - -const char kCWSResponseValid[] = - "{\"kind\":\"chromewebstore#itemList\"," - " \"total_items\":1," - " \"start_index\":0," - " \"items\":[ " - " {\"kind\":\"chromewebstore#item\"," - " \"id\":\"nhkckhebbbncbkefhcpcgepcgfaclehe\"," - " \"type\":\"APPLICATION\"," - " \"num_ratings\":0," - " \"average_rating\":0.0," - " \"manifest\":\"{\\n\\\"update_url\\\":\\" - "\"http://0.tbhome_staging.dserver.download-qa.td.borg.google.com/" - "service/update2/crx\\\",\\n \\\"name\\\": \\\"Sidd's Intent App\\\"" - ",\\n \\\"description\\\": \\\"Do stuff\\\",\\n \\\"version\\\": " - "\\\"1.2.19\\\",\\n \\\"app\\\": {\\n \\\"urls\\\": [ \\n ]," - "\\n \\\"launch\\\": {\\n \\\"web_url\\\": \\" - "\"http://siddharthasaha.net/\\\"\\n }\\n },\\n \\\"icons\\\": " - "{\\n \\\"128\\\": \\\"icon128.png\\\"\\n },\\n \\\"permissions\\\":" - " [\\n \\\"unlimitedStorage\\\",\\n \\\"notifications\\\"\\n ],\\n" - " \\\"intents\\\": {\\n \\\"http://webintents.org/edit\\\" : {\\n " - "\\\"type\\\" : [\\\"image/png\\\", \\\"image/jpg\\\"],\\n \\\"path\\" - "\" : \\\"//services/edit\\\",\\n \\\"title\\\" : " - "\\\"Sample Editing Intent\\\",\\n \\\"disposition\\\" : \\\"inline\\" - "\"\\n },\\n \\\"http://webintents.org/share\\\" : " - "{\\n \\\"type\\\" : [\\\"text/plain\\\", \\\"image/jpg\\\"]," - "\\n \\\"path\\\" : \\\"//services/share\\\",\\n \\\"title\\\" : " - "\\\"Sample sharing Intent\\\",\\n \\\"disposition\\\" : " - "\\\"inline\\\"\\n }\\n }\\n}\\n\"," - " \"family_safe\":true," - " \"icon_url\":\"http://qa-lighthouse.sandbox.google.com/image/" - "QzPnRCYCBbBGI99ZkGxkp-NNJ488IkkiTyCgynFEeDTJHcw4tHl3csmjTQ\"}]}"; - -const char kCWSResponseValidL10n[] = - "{\"kind\":\"chromewebstore#itemList\"," - " \"total_items\":1," - " \"start_index\":0," - " \"items\":[ " - " {\"kind\":\"chromewebstore#item\"," - " \"id\":\"nhkckhebbbncbkefhcpcgepcgfaclehe\"," - " \"type\":\"APPLICATION\"," - " \"num_ratings\":0," - " \"average_rating\":0.0," - " \"manifest\":\"{\\n\\\"update_url\\\":\\" - "\"http://0.tbhome_staging.dserver.download-qa.td.borg.google.com/" - "service/update2/crx\\\",\\n \\\"name\\\": \\\"__MSG_name__\\\"" - ",\\n \\\"description\\\": \\\"Do stuff\\\",\\n \\\"version\\\": " - "\\\"1.2.19\\\",\\n \\\"app\\\": {\\n \\\"urls\\\": [ \\n ]," - "\\n \\\"launch\\\": {\\n \\\"web_url\\\": \\" - "\"http://siddharthasaha.net/\\\"\\n }\\n },\\n \\\"icons\\\": " - "{\\n \\\"128\\\": \\\"icon128.png\\\"\\n },\\n \\\"permissions\\\":" - " [\\n \\\"unlimitedStorage\\\",\\n \\\"notifications\\\"\\n ],\\n" - " \\\"intents\\\": {\\n \\\"http://webintents.org/edit\\\" : {\\n " - "\\\"type\\\" : [\\\"image/png\\\", \\\"image/jpg\\\"],\\n \\\"path\\" - "\" : \\\"//services/edit\\\",\\n \\\"title\\\" : " - "\\\"Sample Editing Intent\\\",\\n \\\"disposition\\\" : \\\"inline\\" - "\"\\n },\\n \\\"http://webintents.org/share\\\" : " - "{\\n \\\"type\\\" : [\\\"text/plain\\\", \\\"image/jpg\\\"]," - "\\n \\\"path\\\" : \\\"//services/share\\\",\\n \\\"title\\\" : " - "\\\"Sample sharing Intent\\\",\\n \\\"disposition\\\" : " - "\\\"inline\\\"\\n }\\n }\\n}\\n\"," - " \"family_safe\":true," - " \"icon_url\":\"http://qa-lighthouse.sandbox.google.com/image/" - "QzPnRCYCBbBGI99ZkGxkp-NNJ488IkkiTyCgynFEeDTJHcw4tHl3csmjTQ\"," - "\"locale_data\": ["; - -const char kCWSResponseValidL10nPostfix[] = -"]}]}"; - -const char kLocaleDataEn[] = - "{" - " \"locale_string\": \"en\"," - " \"title\": \"Localized EN\"" - "}"; - -const char kLocaleDataDe[] = - "{" - " \"locale_string\": \"de\"," - " \"title\": \"Localized DE\"" - "}"; - -const char kLocaleDataAll[] = - "{" - " \"locale_string\": \"all\"," - " \"title\": \"Localized ALL\"" - "}"; - -const char kValidIconURL[] = - "http://qa-lighthouse.sandbox.google.com/image/" - "QzPnRCYCBbBGI99ZkGxkp-NNJ488IkkiTyCgynFEeDTJHcw4tHl3csmjTQ"; - -const char kValidManifest[] = - "{\n\"update_url\":\"http://0.tbhome_staging.dserver.download-qa.td.borg." - "google.com/service/update2/crx\",\n \"name\": \"Sidd's Intent App\",\n" - " \"description\": \"Do stuff\",\n \"version\": \"1.2.19\",\n \"app\":" - " {\n \"urls\": [ \n ],\n \"launch\": {\n \"web_url\":" - " \"http://siddharthasaha.net/\"\n }\n },\n \"icons\": {\n " - "\"128\": \"icon128.png\"\n },\n \"permissions\": [\n " - "\"unlimitedStorage\",\n \"notifications\"\n ],\n \"intents\": " - "{\n \"http://webintents.org/edit\" : {\n \"type\" : [" - "\"image/png\", \"image/jpg\"],\n \"path\" : \"//services/edit\",\n" - " \"title\" : \"Sample Editing Intent\",\n \"disposition\" : " - "\"inline\"\n },\n \"http://webintents.org/share\" : {\n " - "\"type\" : [\"text/plain\", \"image/jpg\"],\n \"path\" : " - "\"//services/share\",\n \"title\" : \"Sample sharing Intent\",\n" - " \"disposition\" : \"inline\"\n }\n }\n}\n"; - -const char kEditAction[] = "http://webintents.org/edit"; -const char kImagePngType[] = "image/png"; - -class CWSIntentsRegistryTest : public testing::Test { - public: - virtual void SetUp() { - scoped_refptr<net::TestURLRequestContextGetter> context_getter( - new net::TestURLRequestContextGetter(ui_loop_.message_loop_proxy())); - registry_.reset(context_getter); - } - - virtual void TearDown() { - // Pump messages posted by the main thread. - ui_loop_.RunUntilIdle(); - } - - CWSIntentsRegistry::IntentExtensionList WaitForResults() { - ui_loop_.RunUntilIdle(); - return extensions_; - } - - void Callback(const CWSIntentsRegistry::IntentExtensionList& extensions) { - extensions_ = extensions; - } - - void RunRequest(const std::string& action, const std::string& mime, - const std::string& response) { - extensions_.clear(); - - net::FakeURLFetcherFactory test_factory; - test_factory.SetFakeResponse( - CWSIntentsRegistry::BuildQueryURL( - ASCIIToUTF16(action),ASCIIToUTF16(mime)).spec(), - response, true); - - registry_->GetIntentServices(ASCIIToUTF16(action), - ASCIIToUTF16(mime), - base::Bind(&CWSIntentsRegistryTest::Callback, - base::Unretained(this))); - WaitForResults(); - } - - - protected: - // UI loop MUST be declared first, (and thus destroyed last) to allow posted - // DeleteSoon() for e.g.TestURLRequestContextGetter. - MessageLoop ui_loop_; - CWSIntentsRegistryForTest registry_; - CWSIntentsRegistry::IntentExtensionList extensions_; -}; - -} // namespace - -TEST_F(CWSIntentsRegistryTest, ValidQuery) { - RunRequest(kEditAction, kImagePngType,kCWSResponseValid); - ASSERT_EQ(1UL, extensions_.size()); - - EXPECT_EQ(0, extensions_[0].num_ratings); - EXPECT_EQ(0.0, extensions_[0].average_rating); - EXPECT_EQ(std::string(kValidManifest), UTF16ToUTF8(extensions_[0].manifest)); - EXPECT_EQ(std::string("nhkckhebbbncbkefhcpcgepcgfaclehe"), extensions_[0].id); - EXPECT_EQ(std::string("Sidd's Intent App"), - UTF16ToUTF8(extensions_[0].name)); - EXPECT_EQ(std::string(kValidIconURL), extensions_[0].icon_url.spec()); -} - -TEST_F(CWSIntentsRegistryTest, InvalidQuery) { - RunRequest("foo", "foo",kCWSResponseInvalid); - EXPECT_EQ(0UL, extensions_.size()); -} - -TEST_F(CWSIntentsRegistryTest, BuildQueryURL) { - const std::string kExpectedURL = "https://www.googleapis.com" - "/chromewebstore/v1.1b/items/intent" - "?intent=action&mime_types=mime%2Ftype&start_index=0&num_results=15"; - GURL url = CWSIntentsRegistry::BuildQueryURL(ASCIIToUTF16("action"), - ASCIIToUTF16("mime/type")); - - EXPECT_EQ(kExpectedURL, url.spec().substr(0, kExpectedURL.size())); -} - -// Test for match to the application locale - i.e. if running in "en", -// registry will use locale_data for "en" key, with or without "all" -// locale_data present. -TEST_F(CWSIntentsRegistryTest, LocalizeMatchingLocale) { - extension_l10n_util::ScopedLocaleForTest restoreLocaleOnExit; - - std::string response = kCWSResponseValidL10n; - response += kLocaleDataEn + std::string(","); - response += kLocaleDataAll + std::string(","); - response += kLocaleDataDe; - response += kCWSResponseValidL10nPostfix; - - // Picks the proper locale_data based on application locale. - extension_l10n_util::SetProcessLocale("en"); - RunRequest(kEditAction, kImagePngType, response); - ASSERT_EQ(1UL, extensions_.size()); - EXPECT_EQ(std::string("Localized EN"), - UTF16ToUTF8(extensions_[0].name)); - - extension_l10n_util::SetProcessLocale("de"); - RunRequest(kEditAction, kImagePngType, response); - ASSERT_EQ(1UL, extensions_.size()); - EXPECT_EQ(std::string("Localized DE"), - UTF16ToUTF8(extensions_[0].name)); - - // Falls back to locale_data for "All" if unknown application locale. - extension_l10n_util::SetProcessLocale("fr"); - RunRequest(kEditAction, kImagePngType, std::string(kCWSResponseValidL10n) + - kLocaleDataAll + kCWSResponseValidL10nPostfix); - ASSERT_EQ(1UL, extensions_.size()); - EXPECT_EQ(std::string("Localized ALL"), - UTF16ToUTF8(extensions_[0].name)); - - // Keeps original content if unknown application locale and no "all" - // localization data exists. - response = kCWSResponseValidL10n; - response += kLocaleDataEn; - response += kCWSResponseValidL10nPostfix; - extension_l10n_util::SetProcessLocale("de"); - RunRequest(kEditAction, kImagePngType, response); - ASSERT_EQ(1UL, extensions_.size()); - EXPECT_EQ(std::string("__MSG_name__"), - UTF16ToUTF8(extensions_[0].name)); -} diff --git a/chrome/browser/intents/default_web_intent_service.cc b/chrome/browser/intents/default_web_intent_service.cc deleted file mode 100644 index 9f369edd..0000000 --- a/chrome/browser/intents/default_web_intent_service.cc +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) 2012 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/intents/default_web_intent_service.h" -#include "base/string_util.h" - -DefaultWebIntentService::DefaultWebIntentService() - : url_pattern(URLPattern::SCHEME_ALL, URLPattern::kAllUrlsPattern), - user_date(-1), - suppression(0) {} - -DefaultWebIntentService::DefaultWebIntentService( - const string16& srv_action, - const string16& srv_type, - const std::string& srv_service_url) - : action(srv_action), type(srv_type), - url_pattern(URLPattern::SCHEME_ALL, URLPattern::kAllUrlsPattern), - user_date(-1), suppression(0), service_url(srv_service_url) {} - -DefaultWebIntentService::DefaultWebIntentService( - const string16& srv_scheme, - const std::string& srv_service_url) - : scheme(srv_scheme), - url_pattern(URLPattern::SCHEME_ALL, URLPattern::kAllUrlsPattern), - user_date(-1), suppression(0), service_url(srv_service_url) {} - -DefaultWebIntentService::~DefaultWebIntentService() {} - -std::string DefaultWebIntentService::ToString() const { - return "{action=" + UTF16ToASCII(action) - + ", type=" + UTF16ToASCII(type) - + ", service_url=" + service_url - + ", url_pattern=" + url_pattern.GetAsString() - + "}"; -} - -bool DefaultWebIntentService::operator==( - const DefaultWebIntentService& other) const { - return action == other.action && - type == other.type && - scheme == other.scheme && - url_pattern == other.url_pattern && - user_date == other.user_date && - suppression == other.suppression && - service_url == other.service_url; -} diff --git a/chrome/browser/intents/default_web_intent_service.h b/chrome/browser/intents/default_web_intent_service.h deleted file mode 100644 index 191d5c2..0000000 --- a/chrome/browser/intents/default_web_intent_service.h +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) 2012 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_INTENTS_DEFAULT_WEB_INTENT_SERVICE_H_ -#define CHROME_BROWSER_INTENTS_DEFAULT_WEB_INTENT_SERVICE_H_ - -#include <string> - -#include "base/string16.h" -#include "extensions/common/url_pattern.h" - -// Holds data related to a default settings for web intents service -// selection. Holds data in a row in the web_intents_defaults table. -// The key for the table is the |action|, |type|, and |url_pattern|. -// These describe the action and type of the web intent for which the -// default is set, and the url prefix (if any) of source pages for -// which the default applies. The main actionable value is the URL -// of the service or extension page handling the intent. The |user_date| -// and |suppression| fields are provided for more intricate post-fetch -// decisions about whether to use a particular default service. -struct DefaultWebIntentService { - - // Intents are matched to services using two defferent matching - // strategies. - // 1) |action| + |type|. Examples: - // action = "webintents.org/share", type = "mydomain.com/mytype" - // action = "intents.w3c.org/action/view", type = "image/png" - // 2) |scheme| e.g., "mailto", or "web+poodle". - // Type for intent service matching. This can be any arbitray type, - // including commonly recognized types such as mime-types. - string16 action; - string16 type; - string16 scheme; - - URLPattern url_pattern; - - // |user_date| holds the offset time when a user set the default. - // If the user did not set the default explicitly, is <= 0. - int user_date; - - // Currently unused. - int64 suppression; - - std::string service_url; - - DefaultWebIntentService(); - DefaultWebIntentService( - const string16& action, - const string16& type, - const std::string& service_url); - DefaultWebIntentService( - const string16& scheme, - const std::string& service_url); - ~DefaultWebIntentService(); - - std::string ToString() const; - bool operator==(const DefaultWebIntentService& other) const; -}; - -#endif // CHROME_BROWSER_INTENTS_DEFAULT_WEB_INTENT_SERVICE_H_ diff --git a/chrome/browser/intents/default_web_intent_service_unittest.cc b/chrome/browser/intents/default_web_intent_service_unittest.cc deleted file mode 100644 index 9478e96..0000000 --- a/chrome/browser/intents/default_web_intent_service_unittest.cc +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) 2012 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 <string> - -#include "base/utf_string_conversions.h" -#include "chrome/browser/intents/default_web_intent_service.h" -#include "extensions/common/url_pattern.h" -#include "googleurl/src/gurl.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace { - -const char kEmptyString[] = ""; -const char kShareAction[] = "http://webintents.org/share"; -const char kPngType[] = "image/png"; -const char kMailToScheme[] = "mailto"; -const char kQuackService[] = "http://ducknet.com/quack"; -const URLPattern all_pattern( - URLPattern::SCHEME_ALL, URLPattern::kAllUrlsPattern); - -TEST(DefaultWebIntentServiceTest, Defaults) { - DefaultWebIntentService service; - - EXPECT_EQ(string16(), service.action); - EXPECT_EQ(string16(), service.type); - EXPECT_EQ(string16(), service.scheme); - EXPECT_EQ(all_pattern, service.url_pattern); - EXPECT_EQ(-1, service.user_date); - EXPECT_EQ(0, service.suppression); - EXPECT_EQ("", service.service_url); -} - -TEST(DefaultWebIntentServiceTest, ActionServicesEqual) { - DefaultWebIntentService actual( - ASCIIToUTF16(kShareAction), - ASCIIToUTF16(kPngType), - kQuackService); - - DefaultWebIntentService expected; - expected.action = ASCIIToUTF16(kShareAction); - expected.type = ASCIIToUTF16(kPngType); - expected.service_url = kQuackService; - - EXPECT_EQ(expected, actual); -} - -TEST(DefaultWebIntentServiceTest, SchemeServicesEqual) { - DefaultWebIntentService actual( - ASCIIToUTF16(kMailToScheme), - kQuackService); - - DefaultWebIntentService expected; - expected.scheme = ASCIIToUTF16(kMailToScheme); - expected.service_url = kQuackService; - - EXPECT_EQ(expected, actual); -} - -} // namespace diff --git a/chrome/browser/intents/intent_service_host.h b/chrome/browser/intents/intent_service_host.h deleted file mode 100644 index 63d3570..0000000 --- a/chrome/browser/intents/intent_service_host.h +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) 2012 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_INTENTS_INTENT_SERVICE_HOST_H_ -#define CHROME_BROWSER_INTENTS_INTENT_SERVICE_HOST_H_ - -namespace content { -class WebIntentsDispatcher; -} - -namespace web_intents { - -// Interface for web intent "services" that act as handlers for -// web intents invoked by client code or other means. "services" can -// be implemented in a variety of means across different "host" environments -// Examples: -// * In another tab, where the tab hosts a web page that services the -// intent. -// * In the Chrome browser where a file picker can be used to select -// a file from disk in response to a "pick" action. -// * In the underlying OS where a native application could be used -// to handle an intent. -// -// A "service" is selected by policy, based on a heuristic including: -// user selection, system defaults, declaration as an "explicit" intent -// by client code, and other means. This selection process is managed -// by WebInentPickerController. -// -// A service, once selected, is responsible for responding to an intent. -// The "intent" is presented to the service as an instance of -// WebIntentsDispatcher. The dispatcher provides access to the intent data -// in the form of a webkit_glue::WebIntentData. The dispatcher also provides -// the service a means of responding to the intent. -// -// A service instance is owned by WebIntentPickerController. Its lifetime is a -// subset of the life of an intent. It will be created immediately prior -// to calling HandleIntent, and destroyed immediately after SendReply -// is called. -// -// For details see content::WebIntentsDispatcher and webkit_glue::WebIntentData -class IntentServiceHost { - public: - virtual ~IntentServiceHost() {} - - // A service is responsible for replying to the dispatcher in all - // circumstances, including when the user has canceled the operation, - // or the action was terminated without user intervention. In each of - // these cases the correct webkit_glue::WebIntentReplyType should - // be chosen and a response should be delivered to the dispatcher - // via SendReply(webkit_glue::WebIntentReply). - virtual void HandleIntent(content::WebIntentsDispatcher* dispatcher) = 0; -}; - -} // namespace web_intents - -#endif // CHROME_BROWSER_INTENTS_INTENT_SERVICE_HOST_H_ diff --git a/chrome/browser/intents/native_services.cc b/chrome/browser/intents/native_services.cc deleted file mode 100644 index 70ed674..0000000 --- a/chrome/browser/intents/native_services.cc +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) 2012 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. - -// Native services are implemented with UI code necessitating portions -// of native_services.h to be defined in -// chrome/browser/ui/intents/native_file_picker_service.cc - -#include "base/command_line.h" -#include "base/logging.h" -#include "base/string16.h" -#include "base/string_util.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/intents/native_services.h" -#include "chrome/browser/intents/web_intents_util.h" -#include "chrome/common/chrome_switches.h" -#include "googleurl/src/gurl.h" -#include "webkit/glue/web_intent_service_data.h" - -namespace web_intents { - -const char kNativeFilePickerUrl[] = "chrome-intents-native://file-picker"; - -NativeServiceRegistry::NativeServiceRegistry() {} -NativeServiceRegistry::~NativeServiceRegistry() {} - -void NativeServiceRegistry::GetSupportedServices( - const string16& action, - IntentServiceList* services) { - if (!CommandLine::ForCurrentProcess()->HasSwitch( - switches::kWebIntentsNativeServicesEnabled)) - return; - -#if !defined(ANDROID) - if (EqualsASCII(action, kActionPick)) { - // File picker registrations. - webkit_glue::WebIntentServiceData service( - ASCIIToUTF16(kActionPick), - ASCIIToUTF16("*/*"), // Handle any MIME-type. - // This is an action/type based service, so we supply an empty scheme. - string16(), - GURL(kNativeFilePickerUrl), - FilePickerFactory::GetServiceTitle()); - service.disposition = webkit_glue::WebIntentServiceData::DISPOSITION_NATIVE; - - services->push_back(service); - } -#endif -} - -NativeServiceFactory::NativeServiceFactory() {} -NativeServiceFactory::~NativeServiceFactory() {} - -IntentServiceHost* NativeServiceFactory::CreateServiceInstance( - const GURL& service_url, - const webkit_glue::WebIntentData& intent, - content::WebContents* web_contents) { - -#if !defined(ANDROID) - if (service_url.spec() == kNativeFilePickerUrl) { - return FilePickerFactory::CreateServiceInstance(intent, web_contents); - } -#endif - - return NULL; // Couldn't create an instance. -} - -} // namespace web_intents diff --git a/chrome/browser/intents/native_services.h b/chrome/browser/intents/native_services.h deleted file mode 100644 index 1691a19..0000000 --- a/chrome/browser/intents/native_services.h +++ /dev/null @@ -1,104 +0,0 @@ -// Copyright (c) 2012 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_INTENTS_NATIVE_SERVICES_H_ -#define CHROME_BROWSER_INTENTS_NATIVE_SERVICES_H_ - -#include <string> -#include <vector> -#include "base/basictypes.h" -#include "base/string16.h" - -class GURL; - -namespace content { -class WebContents; -class WebIntentsDispatcher; -} - -namespace webkit_glue { -struct WebIntentData; -struct WebIntentServiceData; -} - -namespace web_intents { - -class IntentServiceHost; - -// Service URL for the file picker hosted by the Chrome browser. -extern const char kNativeFilePickerUrl[]; - -#if !defined(ANDROID) -// Factory capable of producing a native file picker IntentServiceHost, -// as well as producing registration information about the service. Instances -// of this class can be obtained via NativeServiceFactory and should not -// otherwise be instantiated directly. -class FilePickerFactory { - public: - // Returns a localized title for the file picker. - static string16 GetServiceTitle(); - - // Returns a new IntentServiceHost for processing the given intent data in the - // context of the given web contents. The intent must be of action type - // "pick". - static IntentServiceHost* CreateServiceInstance( - const webkit_glue::WebIntentData& intent, - content::WebContents* web_contents); - - private: - DISALLOW_IMPLICIT_CONSTRUCTORS(FilePickerFactory); -}; -#endif - -// Supplier of information about services hosted by Chrome itself -// (as opposed to web services). Each service registration produced -// by this class will have a WebIntentServiceData::DISPOSITION_NATIVE -// disposition. This value can be used at runtime to determine when a service -// can be instantiated by our sibling class NativeServiceFactory. -// Instances of this class are currently stateless and fairly light weight. -// Any two instances can be assumed to have the same information. -class NativeServiceRegistry { - public: - typedef std::vector<webkit_glue::WebIntentServiceData> IntentServiceList; - NativeServiceRegistry(); - ~NativeServiceRegistry(); - - // Populates |services| with all supported IntentServiceHosts - // capable of handling |action|. - void GetSupportedServices( - const string16& action, - IntentServiceList* services); - - private: - DISALLOW_COPY_AND_ASSIGN(NativeServiceRegistry); -}; - -// Factory for services hosted by Chrome itself (as opposed to web services). -// When implementing a new native service this is where you add support -// for creating an instance. -// Only services reported by NativeServiceRegistry.GetSupportedServices, -// specifically those having a WebIntentServiceData::DISPOSITION_NATIVE -// disposition, are instantiatable via this class. -// Instances of this class are currently stateless and fairly light weight. -// Any two instances can be assumed to have the same capabilities. -class NativeServiceFactory { - public: - NativeServiceFactory(); - ~NativeServiceFactory(); - - // Returns a new IntentServiceHost for processing the given intent data in the - // context of the given web contents. Callers assume ownership of the - // instance. - IntentServiceHost* CreateServiceInstance( - const GURL& url, - const webkit_glue::WebIntentData& intent, - content::WebContents* web_contents); - - private: - DISALLOW_COPY_AND_ASSIGN(NativeServiceFactory); -}; - -} // namespace web_intents - -#endif // CHROME_BROWSER_INTENTS_NATIVE_SERVICES_H_ diff --git a/chrome/browser/intents/native_services_browsertest.cc b/chrome/browser/intents/native_services_browsertest.cc deleted file mode 100644 index e8442c64..0000000 --- a/chrome/browser/intents/native_services_browsertest.cc +++ /dev/null @@ -1,182 +0,0 @@ -// Copyright (c) 2012 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 <algorithm> -#include <iterator> -#include <string> - -#include "base/command_line.h" -#include "base/file_path.h" -#include "base/path_service.h" -#include "base/string_util.h" -#include "base/utf_string_conversions.h" -#include "base/memory/scoped_ptr.h" -#include "content/public/browser/browser_thread.h" -#include "chrome/browser/intents/intent_service_host.h" -#include "chrome/browser/intents/native_services.h" -#include "chrome/browser/intents/web_intents_util.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/browser/ui/tabs/tab_strip_model.h" -#include "chrome/common/chrome_paths.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/test/base/in_process_browser_test.h" -#include "chrome/test/base/ui_test_utils.h" -#include "content/public/browser/web_contents.h" -#include "content/public/browser/web_intents_dispatcher.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "ui/shell_dialogs/select_file_dialog_factory.h" -#include "webkit/glue/web_intent_data.h" -#include "webkit/glue/web_intent_reply_data.h" -#include "webkit/glue/web_intent_service_data.h" - -using content::BrowserThread; - -namespace { - -const std::string kPoodlePath = "/home/poodles/skippy.png"; -const int64 kTestFileSize = 193; - -base::FilePath CreateTestFile() { - base::FilePath file; - PathService::Get(chrome::DIR_TEST_DATA, &file); - file = file.AppendASCII("web_intents").AppendASCII("test.png"); - return file; -} - -class TestIntentsDispatcher : public content::WebIntentsDispatcher { - public: - TestIntentsDispatcher() { - intent_.action = ASCIIToUTF16(web_intents::kActionPick); - intent_.type = ASCIIToUTF16("image/*"); - } - - virtual const webkit_glue::WebIntentData& GetIntent() OVERRIDE { - return intent_; - } - - virtual void DispatchIntent(content::WebContents* web_contents) OVERRIDE {} - virtual void ResetDispatch() OVERRIDE {} - - virtual void SendReply(const webkit_glue::WebIntentReply& reply) OVERRIDE { - reply_.reset(new webkit_glue::WebIntentReply(reply)); - } - - virtual void RegisterReplyNotification( - const base::Callback<void(webkit_glue::WebIntentReplyType)>&) OVERRIDE { - } - - webkit_glue::WebIntentData intent_; - scoped_ptr<webkit_glue::WebIntentReply> reply_; -}; - -class FakeSelectFileDialog : public ui::SelectFileDialog { - public: - FakeSelectFileDialog( - Listener* listener, ui::SelectFilePolicy* policy, bool should_succeed) - : SelectFileDialog(listener, policy), should_succeed_(should_succeed), - test_file_(CreateTestFile()) { - } - virtual bool IsRunning(gfx::NativeWindow parent_window) const OVERRIDE { - return false; - } - virtual void ListenerDestroyed() OVERRIDE {} - virtual bool HasMultipleFileTypeChoicesImpl() OVERRIDE { - return false; - } - - protected: - virtual void SelectFileImpl( - Type type, - const string16& title, - const base::FilePath& default_path, - const FileTypeInfo* file_types, - int file_type_index, - const base::FilePath::StringType& default_extension, - gfx::NativeWindow owning_window, - void* params) OVERRIDE { - if (should_succeed_) - listener_->FileSelected(test_file_, kTestFileSize, params); - else - listener_->FileSelectionCanceled(params); - } - - private: - bool should_succeed_; - base::FilePath test_file_; - DISALLOW_COPY_AND_ASSIGN(FakeSelectFileDialog); -}; - -class TestSelectFileDialogFactory : public ui::SelectFileDialogFactory { - public: - virtual ui::SelectFileDialog* Create( - ui::SelectFileDialog::Listener* listener, - ui::SelectFilePolicy* policy) OVERRIDE { - return new FakeSelectFileDialog(listener, policy, should_succeed_); - } - bool should_succeed_; -}; - -class NativeServicesBrowserTest : public InProcessBrowserTest { - protected: - virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { - // We start the test server now instead of in - // SetUpInProcessBrowserTestFixture so that we can get its port number. - ASSERT_TRUE(test_server()->Start()); - - command_line->AppendSwitch(switches::kWebIntentsNativeServicesEnabled); - test_file_ = CreateTestFile(); - } - - virtual void SetUpOnMainThread() OVERRIDE { - dispatcher_.reset(new TestIntentsDispatcher()); - factory_.reset(new TestSelectFileDialogFactory()); - ui::SelectFileDialog::SetFactory(factory_.get()); - } - - void DispatchIntent(bool should_succeed) { - factory_->should_succeed_ = should_succeed; - - content::WebContents* tab = - browser()->tab_strip_model()->GetActiveWebContents(); - - web_intents::NativeServiceFactory factory; - GURL url(web_intents::kNativeFilePickerUrl); - scoped_ptr<web_intents::IntentServiceHost> service( - factory.CreateServiceInstance(url, dispatcher_->intent_, tab)); - service->HandleIntent(dispatcher_.get()); - - // Reads of file size are done on the FILE thread, then posted - // back to the UI thread. So these are necessary for the - // should_succeed case and noop for the !should_succeed - content::RunAllPendingInMessageLoop(BrowserThread::FILE); - content::RunAllPendingInMessageLoop(BrowserThread::UI); - } - - scoped_ptr<TestIntentsDispatcher> dispatcher_; - scoped_ptr<TestSelectFileDialogFactory> factory_; - base::FilePath test_file_; -}; - -IN_PROC_BROWSER_TEST_F(NativeServicesBrowserTest, PickFileSelected) { - DispatchIntent(true); - ASSERT_TRUE(dispatcher_->reply_); - EXPECT_EQ( - webkit_glue::WebIntentReply( - webkit_glue::WEB_INTENT_REPLY_SUCCESS, - test_file_, - kTestFileSize), - *dispatcher_->reply_.get()); -} - -IN_PROC_BROWSER_TEST_F(NativeServicesBrowserTest, PickFileCancelled) { - DispatchIntent(false); - ASSERT_TRUE(dispatcher_->reply_); - EXPECT_EQ( - webkit_glue::WebIntentReply( - webkit_glue::WEB_INTENT_REPLY_FAILURE, - string16()), - *dispatcher_->reply_.get()); -} - -} // namespace diff --git a/chrome/browser/intents/native_services_unittest.cc b/chrome/browser/intents/native_services_unittest.cc deleted file mode 100644 index 7cc57d0..0000000 --- a/chrome/browser/intents/native_services_unittest.cc +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) 2012 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 <string> -#include <vector> - -#include "base/command_line.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/intents/native_services.h" -#include "chrome/browser/intents/web_intents_util.h" -#include "chrome/common/chrome_switches.h" -#include "extensions/common/url_pattern.h" -#include "googleurl/src/gurl.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "webkit/glue/web_intent_service_data.h" - -namespace { - -using web_intents::NativeServiceRegistry; - -TEST(NativeServiceRegistryTest, GetSupportedServices) { -#if !defined(ANDROID) - CommandLine::ForCurrentProcess()->AppendSwitch( - switches::kWebIntentsNativeServicesEnabled); - - NativeServiceRegistry::IntentServiceList services; - NativeServiceRegistry registry; - typedef NativeServiceRegistry::IntentServiceList::const_iterator Iter; - - registry.GetSupportedServices(ASCIIToUTF16("dothedew"), &services); - - ASSERT_EQ(0U, services.size()); - for (Iter it = services.begin(); it != services.end(); ++it) { - ADD_FAILURE() << "Unexpected handler for Dew: " << *it; - } - - registry.GetSupportedServices( - ASCIIToUTF16(web_intents::kActionPick), &services); - - EXPECT_EQ(1U, services.size()); - if (services.size() == 1) { - // Verify the service returned is for "pick". - EXPECT_EQ(ASCIIToUTF16(web_intents::kActionPick), services[0].action); - EXPECT_EQ(GURL(web_intents::kNativeFilePickerUrl), services[0].service_url); - } else { - for (Iter it = services.begin(); it != services.end(); ++it) { - ADD_FAILURE() << "Too many services for pick action: " << *it; - } - } -#endif -} - -TEST(NativeServiceRegistryTest, GetSupportedServicesDisabled) { -#if !defined(ANDROID) - NativeServiceRegistry::IntentServiceList services; - NativeServiceRegistry registry; - - registry.GetSupportedServices( - ASCIIToUTF16(web_intents::kActionPick), &services); - - ASSERT_EQ(0U, services.size()); -#endif -} - -} // namespace diff --git a/chrome/browser/intents/register_intent_handler_infobar_delegate.cc b/chrome/browser/intents/register_intent_handler_infobar_delegate.cc deleted file mode 100644 index 5892d7f..0000000 --- a/chrome/browser/intents/register_intent_handler_infobar_delegate.cc +++ /dev/null @@ -1,121 +0,0 @@ -// Copyright (c) 2012 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/intents/register_intent_handler_infobar_delegate.h" - -#include "base/bind.h" -#include "base/bind_helpers.h" -#include "base/logging.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/api/infobars/infobar_service.h" -#include "chrome/browser/favicon/favicon_service.h" -#include "chrome/browser/favicon/favicon_service_factory.h" -#include "chrome/browser/intents/web_intents_registry.h" -#include "chrome/browser/intents/web_intents_registry_factory.h" -#include "chrome/browser/intents/web_intents_util.h" -#include "chrome/browser/profiles/profile.h" -#include "content/public/browser/web_contents.h" -#include "grit/generated_resources.h" -#include "ui/base/l10n/l10n_util.h" - - -// static -void RegisterIntentHandlerInfoBarDelegate::Create( - content::WebContents* web_contents, - const webkit_glue::WebIntentServiceData& data) { - Profile* profile = - Profile::FromBrowserContext(web_contents->GetBrowserContext()); - if (profile->IsOffTheRecord()) - return; - - if (!web_intents::IsWebIntentsEnabledForProfile(profile)) - return; - - FaviconService* favicon_service = FaviconServiceFactory::GetForProfile( - profile, Profile::EXPLICIT_ACCESS); - - WebIntentsRegistry* registry = - WebIntentsRegistryFactory::GetForProfile(profile); - registry->IntentServiceExists( - data, base::Bind( - &CreateContinuation, - base::Unretained(InfoBarService::FromWebContents(web_contents)), - registry, - data, - favicon_service, - web_contents->GetURL())); -} - -InfoBarDelegate::Type - RegisterIntentHandlerInfoBarDelegate::GetInfoBarType() const { - return PAGE_ACTION_TYPE; -} - -string16 RegisterIntentHandlerInfoBarDelegate::GetMessageText() const { - return l10n_util::GetStringFUTF16( - IDS_REGISTER_INTENT_HANDLER_CONFIRM, - service_.title, - UTF8ToUTF16(service_.service_url.host())); -} - -string16 RegisterIntentHandlerInfoBarDelegate::GetButtonLabel( - InfoBarButton button) const { - if (button == BUTTON_OK) { - return l10n_util::GetStringFUTF16(IDS_REGISTER_INTENT_HANDLER_ACCEPT, - UTF8ToUTF16(service_.service_url.host())); - } - - DCHECK(button == BUTTON_CANCEL); - return l10n_util::GetStringUTF16(IDS_REGISTER_INTENT_HANDLER_DENY); -} - -bool RegisterIntentHandlerInfoBarDelegate::Accept() { - registry_->RegisterIntentService(service_); - - // Register a temporary FavIcon in case we never visited the provider page. - if (favicon_service_ && origin_url_ != service_.service_url) - favicon_service_->CloneFavicon(origin_url_, service_.service_url); - - return true; -} - -string16 RegisterIntentHandlerInfoBarDelegate::GetLinkText() const { - return l10n_util::GetStringUTF16(IDS_LEARN_MORE); -} - -bool RegisterIntentHandlerInfoBarDelegate::LinkClicked( - WindowOpenDisposition disposition) { - // TODO(jhawkins): Open the Web Intents Help Center article once it is - // written. - // TODO(jhawkins): Add associated bug for the article here. - return false; -} - -RegisterIntentHandlerInfoBarDelegate::RegisterIntentHandlerInfoBarDelegate( - InfoBarService* infobar_service, - WebIntentsRegistry* registry, - const webkit_glue::WebIntentServiceData& service, - FaviconService* favicon_service, - const GURL& origin_url) - : ConfirmInfoBarDelegate(infobar_service), - registry_(registry), - service_(service), - favicon_service_(favicon_service), - origin_url_(origin_url) { -} - -// static -void RegisterIntentHandlerInfoBarDelegate::CreateContinuation( - InfoBarService* infobar_service, - WebIntentsRegistry* registry, - const webkit_glue::WebIntentServiceData& service, - FaviconService* favicon_service, - const GURL& origin_url, - bool provider_exists) { - if (!provider_exists) { - infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( - new RegisterIntentHandlerInfoBarDelegate( - infobar_service, registry, service, favicon_service, origin_url))); - } -} diff --git a/chrome/browser/intents/register_intent_handler_infobar_delegate.h b/chrome/browser/intents/register_intent_handler_infobar_delegate.h deleted file mode 100644 index 9fcb197..0000000 --- a/chrome/browser/intents/register_intent_handler_infobar_delegate.h +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright (c) 2011 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_INTENTS_REGISTER_INTENT_HANDLER_INFOBAR_DELEGATE_H_ -#define CHROME_BROWSER_INTENTS_REGISTER_INTENT_HANDLER_INFOBAR_DELEGATE_H_ - -#include "base/basictypes.h" -#include "base/string16.h" -#include "chrome/browser/api/infobars/confirm_infobar_delegate.h" -#include "webkit/glue/web_intent_service_data.h" - -#if defined(UNIT_TEST) -#include "base/memory/scoped_ptr.h" -#endif - -class WebIntentsRegistry; -class FaviconService; -class GURL; -namespace content { -class WebContents; -} - -// The InfoBar used to request permission for a site to be registered as an -// Intent handler. -class RegisterIntentHandlerInfoBarDelegate : public ConfirmInfoBarDelegate { - public: - // Checks whether the intent service specified by |data| exists. If not, and - // |web_contents| is in a non-incognito, web-intents-enabled profile, creates - // a register intent handler delegate and adds it to the InfoBarService for - // |web_contents|. - static void Create(content::WebContents* web_contents, - const webkit_glue::WebIntentServiceData& data); - -#if defined(UNIT_TEST) - static scoped_ptr<RegisterIntentHandlerInfoBarDelegate> Create( - WebIntentsRegistry* registry, - const webkit_glue::WebIntentServiceData& data) { - return scoped_ptr<RegisterIntentHandlerInfoBarDelegate>( - new RegisterIntentHandlerInfoBarDelegate(NULL, registry, data, NULL, - GURL())); - } -#endif - - // ConfirmInfoBarDelegate implementation. - virtual Type GetInfoBarType() const OVERRIDE; - virtual string16 GetMessageText() const OVERRIDE; - virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; - virtual bool Accept() OVERRIDE; - virtual string16 GetLinkText() const OVERRIDE; - virtual bool LinkClicked(WindowOpenDisposition disposition) OVERRIDE; - - private: - RegisterIntentHandlerInfoBarDelegate( - InfoBarService* infobar_service, - WebIntentsRegistry* registry, - const webkit_glue::WebIntentServiceData& service, - FaviconService* favicon_service, - const GURL& origin_url); - - // Finishes the work of Create(). This is called back from the - // WebIntentsRegistry once it determines whether the requested intent service - // exists. - static void CreateContinuation( - InfoBarService* infobar_service, - WebIntentsRegistry* registry, - const webkit_glue::WebIntentServiceData& service, - FaviconService* favicon_service, - const GURL& origin_url, - bool provider_exists); - - // The web intents registry to use. Weak pointer. - WebIntentsRegistry* registry_; - - // The cached intent service data bundle passed up from the renderer. - webkit_glue::WebIntentServiceData service_; - - // The favicon service to use. Weak pointer. - FaviconService* favicon_service_; - - // The URL of the page the service was originally registered from. - GURL origin_url_; - - DISALLOW_COPY_AND_ASSIGN(RegisterIntentHandlerInfoBarDelegate); -}; - -#endif // CHROME_BROWSER_INTENTS_REGISTER_INTENT_HANDLER_INFOBAR_DELEGATE_H_ diff --git a/chrome/browser/intents/register_intent_handler_infobar_delegate_unittest.cc b/chrome/browser/intents/register_intent_handler_infobar_delegate_unittest.cc deleted file mode 100644 index 3b3d5f3..0000000 --- a/chrome/browser/intents/register_intent_handler_infobar_delegate_unittest.cc +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright (c) 2012 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 "base/synchronization/waitable_event.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/intents/register_intent_handler_infobar_delegate.h" -#include "chrome/browser/intents/web_intents_registry.h" -#include "chrome/browser/intents/web_intents_registry_factory.h" -#include "chrome/test/base/chrome_render_view_host_test_harness.h" -#include "chrome/test/base/testing_profile.h" -#include "content/public/test/test_browser_thread.h" -#include "testing/gmock/include/gmock/gmock.h" -#include "testing/gtest/include/gtest/gtest.h" -#include "webkit/glue/web_intent_service_data.h" - -using content::BrowserThread; - -namespace { - -class MockWebIntentsRegistry : public WebIntentsRegistry { - public: - MOCK_METHOD1(RegisterIntentService, - void(const webkit_glue::WebIntentServiceData&)); -}; - -ProfileKeyedService* BuildMockWebIntentsRegistry(Profile* profile) { - return new MockWebIntentsRegistry; -} - -MockWebIntentsRegistry* BuildForProfile(Profile* profile) { - return static_cast<MockWebIntentsRegistry*>( - WebIntentsRegistryFactory::GetInstance()->SetTestingFactoryAndUse( - profile, BuildMockWebIntentsRegistry)); -} - -class RegisterIntentHandlerInfoBarDelegateTest - : public ChromeRenderViewHostTestHarness { - protected: - RegisterIntentHandlerInfoBarDelegateTest() - : ui_thread_(BrowserThread::UI, MessageLoopForUI::current()), - db_thread_(BrowserThread::DB, MessageLoopForUI::current()) {} - - virtual void SetUp() { - ChromeRenderViewHostTestHarness::SetUp(); - - profile()->CreateWebDataService(); - web_intents_registry_ = BuildForProfile(profile()); - } - - virtual void TearDown() { - web_intents_registry_ = NULL; - - ChromeRenderViewHostTestHarness::TearDown(); - } - - MockWebIntentsRegistry* web_intents_registry_; - - private: - content::TestBrowserThread ui_thread_; - content::TestBrowserThread db_thread_; - - DISALLOW_COPY_AND_ASSIGN(RegisterIntentHandlerInfoBarDelegateTest); -}; - -TEST_F(RegisterIntentHandlerInfoBarDelegateTest, Accept) { - webkit_glue::WebIntentServiceData service; - service.service_url = GURL("google.com"); - service.action = ASCIIToUTF16("http://webintents.org/share"); - service.type = ASCIIToUTF16("text/url"); - scoped_ptr<RegisterIntentHandlerInfoBarDelegate> infobar_delegate( - RegisterIntentHandlerInfoBarDelegate::Create(web_intents_registry_, - service)); - - EXPECT_CALL(*web_intents_registry_, RegisterIntentService(service)); - infobar_delegate->Accept(); -} - -} // namespace diff --git a/chrome/browser/intents/web_intents_registry.cc b/chrome/browser/intents/web_intents_registry.cc deleted file mode 100644 index f2663b5..0000000 --- a/chrome/browser/intents/web_intents_registry.cc +++ /dev/null @@ -1,528 +0,0 @@ -// Copyright (c) 2012 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/intents/web_intents_registry.h" - -#include <algorithm> - -#include "base/bind.h" -#include "base/bind_helpers.h" -#include "base/callback.h" -#include "base/string_util.h" -#include "base/string16.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/intents/default_web_intent_service.h" -#include "chrome/browser/intents/native_services.h" -#include "chrome/browser/intents/web_intents_util.h" -#include "chrome/browser/webdata/web_data_service.h" -#include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_set.h" -#include "chrome/common/extensions/web_intents_handler.h" -#include "googleurl/src/gurl.h" -#include "net/base/mime_util.h" - -using extensions::Extension; -using net::IsMimeType; - -namespace { - -// TODO(hshi): Temporary workaround for http://crbug.com/134197. -// If no user-set default service is found, use built-in QuickOffice Viewer as -// default for MS office files. Remove this once full defaults is in place. -const char* kQuickOfficeViewerMimeType[] = { - "application/msword", - "application/vnd.ms-powerpoint", - "application/vnd.ms-excel", - "application/vnd.openxmlformats-officedocument.wordprocessingml.document", - "application/vnd.openxmlformats-officedocument.presentationml.presentation", - "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" -}; - -typedef base::Callback<void(const WDTypedResult* result)> ResultsHandler; -typedef WebIntentsRegistry::IntentServiceList IntentServiceList; - -// Compares two web intents type specifiers to see if there is a match. -// First checks if both are MIME types. If so, uses MatchesMimeType. -// If not, uses exact string equality. -bool WebIntentsTypesMatch(const string16& type1, const string16& type2) { - return (IsMimeType(UTF16ToUTF8(type1)) && IsMimeType(UTF16ToUTF8(type2))) - ? web_intents::MimeTypesMatch(type1, type2) - : type1 == type2; -} - -// Adds any intent services of |extension| that match |action| to -// |matching_services|. -void AddMatchingServicesForExtension(const Extension& extension, - const string16& action, - IntentServiceList* matching_services) { - const IntentServiceList& services = - extensions::WebIntentsInfo::GetIntentsServices(&extension); - for (IntentServiceList::const_iterator i = services.begin(); - i != services.end(); ++i) { - if (action.empty() || action == i->action) - matching_services->push_back(*i); - } -} - -// Removes all services from |matching_services| that do not match |type|. -// Wildcards are supported, of the form '<type>/*' or '*'. -void FilterServicesByType(const string16& type, - IntentServiceList* matching_services) { - // Filter out all services not matching the query type. - IntentServiceList::iterator iter(matching_services->begin()); - while (iter != matching_services->end()) { - if (WebIntentsTypesMatch(iter->type, type)) - ++iter; - else - iter = matching_services->erase(iter); - } -} - -// Callback for existence checks. Converts a callback for a list of services -// into a callback that returns true if the list contains a specific service. -void ExistenceCallback(const webkit_glue::WebIntentServiceData& service, - const base::Callback<void(bool)>& callback, - const WDTypedResult* result) { - - WebIntentsRegistry::IntentServiceList list = static_cast< - const WDResult<IntentServiceList>*>(result)->GetValue(); - - for (WebIntentsRegistry::IntentServiceList::const_iterator i = list.begin(); - i != list.end(); ++i) { - if (*i == service) { - callback.Run(true); - return; - } - } - - callback.Run(false); -} - -// Functor object for intent ordering. -struct IntentOrdering { - // Implements StrictWeakOrdering for intents, based on intent-equivalence. - // Order by |service_url|, |action|, |title|, and |disposition| in order. - bool operator()(const webkit_glue::WebIntentServiceData& lhs, - const webkit_glue::WebIntentServiceData& rhs) { - if (lhs.service_url != rhs.service_url) - return lhs.service_url < rhs.service_url; - - if (lhs.action != rhs.action) - return lhs.action < rhs.action; - - if (lhs.title != rhs.title) - return lhs.title < rhs.title; - - if (lhs.disposition != rhs.disposition) - return lhs.disposition < rhs.disposition; - - // At this point, we consider intents to be equal, even if |type| differs. - return false; - } -}; - -// Two intents are equivalent iff all fields except |type| are equal. -bool IntentsAreEquivalent(const webkit_glue::WebIntentServiceData& lhs, - const webkit_glue::WebIntentServiceData& rhs) { - return !((lhs.service_url != rhs.service_url) || - (lhs.action != rhs.action) || - (lhs.title != rhs.title) || - (lhs.disposition != rhs.disposition)); -} - -} // namespace - -using webkit_glue::WebIntentServiceData; - -// Internal object containing arguments to be used in post processing -// WDS results. -struct WebIntentsRegistry::QueryParams { - - // The particular action to filter for while searching through extensions. - // If |action_| is empty, return all extension-provided services. - string16 action_; - - // The MIME type that was requested for this service query. - // Suppports wild cards. - string16 type_; - - // The url of the invoking page. - GURL url_; - - // Create a new QueryParams for all intent services or for existence checks. - QueryParams() : type_(ASCIIToUTF16("*")) {} - - QueryParams(const string16& action, const string16& type) - : action_(action), type_(type) {} - - // Create a new QueryParams for default services. - QueryParams(const string16& action, const string16& type, const GURL& url) - : action_(action), type_(type), url_(url) {} -}; - -// Internal object adapting the WDS consumer interface to base::Bind -// callback way of doing business. -class WebIntentsRegistry::QueryAdapter : public WebDataServiceConsumer { - - public: - // Underlying data query. - WebDataService::Handle query_handle_; - - // Create a new QueryAdapter that delegates results to |handler|. - QueryAdapter(WebIntentsRegistry* registry, const ResultsHandler& handler) - : registry_(registry), handler_(handler) { - registry_->TrackQuery(this); - } - - virtual void OnWebDataServiceRequestDone( - WebDataService::Handle h, - const WDTypedResult* result) OVERRIDE { - - handler_.Run(result); - registry_->ReleaseQuery(this); - } - - private: - // Handle so we can call back into the WebIntentsRegistry when - // processing query results. The registry is guaranteed to be - // valid for the life of this object. We do not own this object. - WebIntentsRegistry* registry_; - - // The callback for this particular query. - ResultsHandler handler_; -}; - -WebIntentsRegistry::WebIntentsRegistry() { - native_services_.reset(new web_intents::NativeServiceRegistry()); -} - -WebIntentsRegistry::~WebIntentsRegistry() { - - // Cancel all pending queries, since we can't handle them any more. - for (QueryVector::iterator it = pending_queries_.begin(); - it != pending_queries_.end(); ++it) { - QueryAdapter* query = *it; - wds_->CancelRequest(query->query_handle_); - delete query; - } -} - -void WebIntentsRegistry::Initialize( - scoped_refptr<WebDataService> wds, - ExtensionServiceInterface* extension_service) { - wds_ = wds; - extension_service_ = extension_service; -} - -void WebIntentsRegistry::OnWebIntentsResultReceived( - const QueryParams& params, - const QueryCallback& callback, - const WDTypedResult* result) { - DCHECK(result); - DCHECK(result->GetType() == WEB_INTENTS_RESULT); - - IntentServiceList matching_services = static_cast< - const WDResult<IntentServiceList>*>(result)->GetValue(); - - // Loop over all services in all extensions, collect ones - // matching the query. - if (extension_service_) { - const ExtensionSet* extensions = extension_service_->extensions(); - if (extensions) { - for (ExtensionSet::const_iterator i(extensions->begin()); - i != extensions->end(); ++i) { - AddMatchingServicesForExtension(**i, params.action_, - &matching_services); - } - } - } - - // add native services. - native_services_->GetSupportedServices(params.action_, &matching_services); - - // Filter out all services not matching the query type. - FilterServicesByType(params.type_, &matching_services); - - // Collapse intents that are equivalent for all but |type|. - CollapseIntents(&matching_services); - - callback.Run(matching_services); -} - -void WebIntentsRegistry::OnAllDefaultIntentServicesReceived( - const DefaultIntentServicesCallback& callback, - const WDTypedResult* result) { - DCHECK(result); - DCHECK(result->GetType() == WEB_INTENTS_DEFAULTS_RESULT); - - const std::vector<DefaultWebIntentService> services = static_cast< - const WDResult<std::vector<DefaultWebIntentService> >*>(result)-> - GetValue(); - - callback.Run(services); -} - -void WebIntentsRegistry::OnWebIntentsDefaultsResultReceived( - const QueryParams& params, - const DefaultQueryCallback& callback, - const WDTypedResult* result) { - DCHECK(result); - DCHECK(result->GetType() == WEB_INTENTS_DEFAULTS_RESULT); - - std::vector<DefaultWebIntentService> services = static_cast< - const WDResult<std::vector<DefaultWebIntentService> >*>(result)-> - GetValue(); - - DefaultWebIntentService default_service; - std::vector<DefaultWebIntentService>::iterator iter(services.begin()); - for (; iter != services.end(); ++iter) { - if (!WebIntentsTypesMatch(iter->type, params.type_)) { - continue; - } - if (!iter->url_pattern.MatchesURL(params.url_)) { - continue; - } - const Extension* extension = ExtensionForURL(iter->service_url); - if (extension != NULL && - !extension_service_->IsExtensionEnabled(extension->id())) { - continue; - } - - // Found a match. If it is better than default_service, use it. - // Currently the metric is that if the new value is user-set, - // prefer it. If the new value has a more specific pattern, prefer it. - // If the new value has a more recent date, prefer it. - if (default_service.user_date <= 0 && iter->user_date >= 0) { - default_service = *iter; - } else if (default_service.url_pattern.match_all_urls() && - !iter->url_pattern.match_all_urls()) { - default_service = *iter; - } else if (iter->url_pattern < default_service.url_pattern) { - default_service = *iter; - } else if (default_service.user_date < iter->user_date) { - default_service = *iter; - } - } - - // If QuickOffice is the default for this, recompute defaults. - if (default_service.service_url - == web_intents::kQuickOfficeViewerServiceURL || - default_service.service_url - == web_intents::kQuickOfficeViewerDevServiceURL) { - default_service.user_date = -1; - } - - // TODO(hshi): Temporary workaround for http://crbug.com/134197. - // If no user-set default service is found, use built-in QuickOffice Viewer as - // default for MS office files. Remove this once full defaults is in place. - - if (default_service.user_date <= 0) { - const char kQuickOfficeDevExtensionId[] = - "ionpfmkccalenbmnddpbmocokhaknphg"; - std::string service_url = web_intents::kQuickOfficeViewerServiceURL; - if (extension_service_->GetInstalledExtension(kQuickOfficeDevExtensionId) && - extension_service_->IsExtensionEnabled(kQuickOfficeDevExtensionId)) { - service_url = web_intents::kQuickOfficeViewerDevServiceURL; - } - - for (size_t i = 0; i < sizeof(kQuickOfficeViewerMimeType) / sizeof(char*); - ++i) { - DefaultWebIntentService qoviewer_service; - qoviewer_service.action = ASCIIToUTF16(web_intents::kActionView); - qoviewer_service.type = ASCIIToUTF16(kQuickOfficeViewerMimeType[i]); - qoviewer_service.service_url = service_url; - if (WebIntentsTypesMatch(qoviewer_service.type, params.type_)) { - default_service = qoviewer_service; - break; - } - } - } - - callback.Run(default_service); -} - -void WebIntentsRegistry::GetIntentServices( - const string16& action, const string16& type, - const QueryCallback& callback) { - DCHECK(wds_.get()); - DCHECK(!callback.is_null()); - - const QueryParams params(action, type); - const ResultsHandler handler = base::Bind( - &WebIntentsRegistry::OnWebIntentsResultReceived, - base::Unretained(this), - params, - callback); - - QueryAdapter* query = new QueryAdapter(this, handler); - query->query_handle_ = wds_->GetWebIntentServicesForAction(action, query); -} - -void WebIntentsRegistry::GetAllIntentServices( - const QueryCallback& callback) { - DCHECK(wds_.get()); - DCHECK(!callback.is_null()); - - const QueryParams params; - const ResultsHandler handler = base::Bind( - &WebIntentsRegistry::OnWebIntentsResultReceived, - base::Unretained(this), - params, - callback); - - QueryAdapter* query = new QueryAdapter(this, handler); - query->query_handle_ = wds_->GetAllWebIntentServices(query); -} - -void WebIntentsRegistry::GetAllDefaultIntentServices( - const DefaultIntentServicesCallback& callback) { - DCHECK(!callback.is_null()); - - ResultsHandler handler = base::Bind( - &WebIntentsRegistry::OnAllDefaultIntentServicesReceived, - base::Unretained(this), - callback); - - QueryAdapter* query = new QueryAdapter(this, handler); - query->query_handle_ = - wds_->GetAllDefaultWebIntentServices(query); -} - -void WebIntentsRegistry::IntentServiceExists( - const WebIntentServiceData& service, - const base::Callback<void(bool)>& callback) { - DCHECK(!callback.is_null()); - - ResultsHandler handler = base::Bind( - &ExistenceCallback, - service, - callback); - - QueryAdapter* query = new QueryAdapter(this, handler); - query->query_handle_ = wds_->GetWebIntentServicesForURL( - UTF8ToUTF16(service.service_url.spec()), query); -} - -void WebIntentsRegistry::GetIntentServicesForExtensionFilter( - const string16& action, - const string16& type, - const std::string& extension_id, - IntentServiceList* services) { - if (extension_service_) { - const Extension* extension = - extension_service_->GetExtensionById(extension_id, false); - AddMatchingServicesForExtension(*extension, - action, - services); - FilterServicesByType(type, services); - } -} - -void WebIntentsRegistry::RegisterDefaultIntentService( - const DefaultWebIntentService& default_service) { - DCHECK(wds_.get()); - wds_->AddDefaultWebIntentService(default_service); -} - -void WebIntentsRegistry::UnregisterDefaultIntentService( - const DefaultWebIntentService& default_service) { - DCHECK(wds_.get()); - wds_->RemoveDefaultWebIntentService(default_service); -} - -void WebIntentsRegistry::UnregisterServiceDefaults(const GURL& service_url) { - DCHECK(wds_.get()); - wds_->RemoveWebIntentServiceDefaults(service_url); -} - -void WebIntentsRegistry::GetDefaultIntentService( - const string16& action, - const string16& type, - const GURL& invoking_url, - const DefaultQueryCallback& callback) { - DCHECK(!callback.is_null()); - - const QueryParams params(action, type); - - ResultsHandler handler = base::Bind( - &WebIntentsRegistry::OnWebIntentsDefaultsResultReceived, - base::Unretained(this), - params, - callback); - - QueryAdapter* query = new QueryAdapter(this, handler); - query->query_handle_ = - wds_->GetDefaultWebIntentServicesForAction(action, query); -} - -void WebIntentsRegistry::RegisterIntentService( - const WebIntentServiceData& service) { - DCHECK(wds_.get()); - wds_->AddWebIntentService(service); -} - -void WebIntentsRegistry::UnregisterIntentService( - const WebIntentServiceData& service) { - DCHECK(wds_.get()); - wds_->RemoveWebIntentService(service); -} - -void WebIntentsRegistry::CollapseIntents(IntentServiceList* services) { - DCHECK(services); - - // No need to do anything for no services/single service. - if (services->size() < 2) - return; - - // Sort so that intents that can be collapsed must be adjacent. - std::sort(services->begin(), services->end(), IntentOrdering()); - - // Combine adjacent services if they are equivalent. - IntentServiceList::iterator write_iter = services->begin(); - IntentServiceList::iterator read_iter = write_iter + 1; - while (read_iter != services->end()) { - if (IntentsAreEquivalent(*write_iter, *read_iter)) { - // If the two intents are equivalent, join types and collapse. - write_iter->type += ASCIIToUTF16(",") + read_iter->type; - } else { - // Otherwise, keep both intents. - ++write_iter; - if (write_iter != read_iter) - *write_iter = *read_iter; - } - ++read_iter; - } - - // Cut off everything after the last intent copied to the list. - if (++write_iter != services->end()) - services->erase(write_iter, services->end()); -} - -const Extension* WebIntentsRegistry::ExtensionForURL(const std::string& url) { - const ExtensionSet* extensions = extension_service_->extensions(); - if (!extensions) - return NULL; - - // Use the unsafe ExtensionURLInfo constructor: we don't care if the extension - // is running or not. - GURL gurl(url); - ExtensionURLInfo info(gurl); - return extensions->GetExtensionOrAppByURL(info); -} - -void WebIntentsRegistry::TrackQuery(QueryAdapter* query) { - DCHECK(query); - pending_queries_.push_back(query); -} - -void WebIntentsRegistry::ReleaseQuery(QueryAdapter* query) { - QueryVector::iterator it = std::find( - pending_queries_.begin(), pending_queries_.end(), query); - if (it != pending_queries_.end()) { - pending_queries_.erase(it); - delete query; - } else { - NOTREACHED(); - } -} diff --git a/chrome/browser/intents/web_intents_registry.h b/chrome/browser/intents/web_intents_registry.h deleted file mode 100644 index b5a20e2..0000000 --- a/chrome/browser/intents/web_intents_registry.h +++ /dev/null @@ -1,180 +0,0 @@ -// Copyright (c) 2012 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_INTENTS_WEB_INTENTS_REGISTRY_H_ -#define CHROME_BROWSER_INTENTS_WEB_INTENTS_REGISTRY_H_ - -#include "base/callback_forward.h" -#include "base/hash_tables.h" -#include "base/memory/ref_counted.h" -#include "chrome/browser/extensions/extension_service.h" -#include "chrome/browser/profiles/profile_keyed_service.h" -#include "chrome/browser/webdata/web_data_service.h" -#include "webkit/glue/web_intent_service_data.h" - -struct DefaultWebIntentService; - -namespace extensions { -class Extension; -} - -namespace web_intents { -class NativeServiceRegistry; -} - -// Handles storing and retrieving of web intents services in the web database. -// The registry provides filtering logic to retrieve specific types of services. -class WebIntentsRegistry : public ProfileKeyedService { - public: - typedef std::vector<webkit_glue::WebIntentServiceData> IntentServiceList; - typedef std::vector<DefaultWebIntentService> DefaultIntentServiceList; - - // Callback used by callers to accept results of a query for - // a list of |WebIntentServiceData|. - typedef base::Callback<void(const IntentServiceList&)> - QueryCallback; - - // Callback used by callers to accept results of a query for - // a list of |DefaultWebIntentService|. - typedef base::Callback<void(const DefaultIntentServiceList&)> - DefaultIntentServicesCallback; - - // Callback used by callers to accept results of a query for - // a |DefaultWebIntentService|. - typedef base::Callback<void(const DefaultWebIntentService&)> - DefaultQueryCallback; - - // Initializes, binds to a valid WebDataService. - void Initialize(scoped_refptr<WebDataService> wds, - ExtensionServiceInterface* extension_service); - - // Registers a service. - virtual void RegisterIntentService( - const webkit_glue::WebIntentServiceData& service); - - // Removes a service from the registry. - void UnregisterIntentService( - const webkit_glue::WebIntentServiceData& service); - - // Requests all services matching |action| and |type|. - // |type| can contain wildcards, i.e. "image/*" or "*". - // |callback| must not be null. - void GetIntentServices(const string16& action, - const string16& type, - const QueryCallback& callback); - - // Requests all services. - // |callback| must not be null. - void GetAllIntentServices(const QueryCallback& callback); - - // Requests all default services. - // |callback| must not be null. - void GetAllDefaultIntentServices( - const DefaultIntentServicesCallback& callback); - - // Tests for the existence of the given |service|. Calls the - // provided |callback| with true if it exists, false if it does not. - // Checks for |service| equality with ==. - // |callback| must not be null. - void IntentServiceExists( - const webkit_glue::WebIntentServiceData& service, - const base::Callback<void(bool)>& callback); - - // Requests all extension services matching |action|, |type| and - // |extension_id|. - // |type| must conform to definition as outlined for GetIntentServices. - // |callback| must not be null. - void GetIntentServicesForExtensionFilter(const string16& action, - const string16& type, - const std::string& extension_id, - IntentServiceList* services); - - // Record the given default service entry. - virtual void RegisterDefaultIntentService( - const DefaultWebIntentService& default_service); - - // Delete the given default service entry. Deletes entries matching - // the |action|, |type|, and |url_pattern| of |default_service|. - virtual void UnregisterDefaultIntentService( - const DefaultWebIntentService& default_service); - - // Delete all default service entries associated with |service_url|. - virtual void UnregisterServiceDefaults(const GURL& service_url); - - // Requests the best default intent service for the given invocation - // parameters. - // |callback| must not be null. - void GetDefaultIntentService(const string16& action, - const string16& type, - const GURL& invoking_url, - const DefaultQueryCallback& callback); - - protected: - // Make sure that only WebIntentsRegistryFactory can create an instance of - // WebIntentsRegistry. - friend class WebIntentsRegistryFactory; - friend class WebIntentsRegistryTest; - FRIEND_TEST_ALL_PREFIXES(WebIntentsRegistryTest, CollapseIntents); - - WebIntentsRegistry(); - virtual ~WebIntentsRegistry(); - - // Collapses a list of IntentServices by joining intents that have identical - // service URLs, actions, and mime types. - // |services| is the list of intent services to be collapsed when passed in - // and will be modified with the new list in-place. - void CollapseIntents(IntentServiceList* services); - - private: - struct QueryParams; - class QueryAdapter; - typedef std::vector<QueryAdapter*> QueryVector; - - // Handles services loaded - void OnWebIntentsResultReceived( - const QueryParams& params, - const QueryCallback& callback, - const WDTypedResult* result); - - // Handles default services loaded, supplying an unfiltered list - // to the callback. - void OnAllDefaultIntentServicesReceived( - const DefaultIntentServicesCallback& callback, - const WDTypedResult* result); - - // Handles default services loaded - void OnWebIntentsDefaultsResultReceived( - const QueryParams& params, - const DefaultQueryCallback& callback, - const WDTypedResult* result); - - const extensions::Extension* ExtensionForURL(const std::string& url); - - // Adds a query to the list of pending queries. - void TrackQuery(QueryAdapter* query); - - // Takes ownership of a query. This removes a query from the list - // of pending queries. - void ReleaseQuery(QueryAdapter* query); - - // Map for all in-flight web data requests/intent queries. - QueryVector pending_queries_; - - // Local reference to Web Data Service. - scoped_refptr<WebDataService> wds_; - - // Local reference to the ExtensionService. - // Shutdown/cleanup is handled by ProfileImpl. We are guaranteed that any - // ProfileKeyedService will be shut down before data on ProfileImpl is - // destroyed (i.e. |extension_service_|), so |extension_service_| is valid - // for the lifetime of the WebIntentsRegistry object. - ExtensionServiceInterface* extension_service_; - - // Registry used to obtain list of supported native services. - scoped_ptr<web_intents::NativeServiceRegistry> native_services_; - - DISALLOW_COPY_AND_ASSIGN(WebIntentsRegistry); -}; - -#endif // CHROME_BROWSER_INTENTS_WEB_INTENTS_REGISTRY_H_ diff --git a/chrome/browser/intents/web_intents_registry_factory.cc b/chrome/browser/intents/web_intents_registry_factory.cc deleted file mode 100644 index 376f3d6..0000000 --- a/chrome/browser/intents/web_intents_registry_factory.cc +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright (c) 2012 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/intents/web_intents_registry_factory.h" - -#include "base/memory/singleton.h" -#include "chrome/browser/extensions/extension_system_factory.h" -#include "chrome/browser/intents/web_intents_registry.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/profiles/profile_dependency_manager.h" -#include "chrome/browser/webdata/web_data_service_factory.h" - -// static -WebIntentsRegistry* WebIntentsRegistryFactory::GetForProfile(Profile* profile) { - return static_cast<WebIntentsRegistry*>( - GetInstance()->GetServiceForProfile(profile, true)); -} - -WebIntentsRegistryFactory::WebIntentsRegistryFactory() - : ProfileKeyedServiceFactory("WebIntentsRegistry", - ProfileDependencyManager::GetInstance()) { - DependsOn(WebDataServiceFactory::GetInstance()); - DependsOn(extensions::ExtensionSystemFactory::GetInstance()); -} - -WebIntentsRegistryFactory::~WebIntentsRegistryFactory() { -} - -// static -WebIntentsRegistryFactory* WebIntentsRegistryFactory::GetInstance() { - return Singleton<WebIntentsRegistryFactory>::get(); -} - -ProfileKeyedService* WebIntentsRegistryFactory::BuildServiceInstanceFor( - Profile* profile) const { - WebIntentsRegistry* registry = new WebIntentsRegistry; - registry->Initialize(WebDataServiceFactory::GetForProfile( - profile, Profile::EXPLICIT_ACCESS), - profile->GetExtensionService()); - return registry; -} - -bool WebIntentsRegistryFactory::ServiceRedirectedInIncognito() const { - return false; -} diff --git a/chrome/browser/intents/web_intents_registry_factory.h b/chrome/browser/intents/web_intents_registry_factory.h deleted file mode 100644 index d130d31..0000000 --- a/chrome/browser/intents/web_intents_registry_factory.h +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) 2012 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_INTENTS_WEB_INTENTS_REGISTRY_FACTORY_H_ -#define CHROME_BROWSER_INTENTS_WEB_INTENTS_REGISTRY_FACTORY_H_ - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "chrome/browser/profiles/profile_keyed_service_factory.h" - -class Profile; -class WebIntentsRegistry; -template <typename T> struct DefaultSingletonTraits; - -// Singleton that owns all WebIntentsRegistrys and associates them with -// Profiles. Listens for the Profile's destruction notification and cleans up -// the associated WebIntentsRegistry. -class WebIntentsRegistryFactory : public ProfileKeyedServiceFactory { - public: - // Returns the WebIntentsRegistry that provides intent registration for - // |profile|. Ownership stays with this factory object. - static WebIntentsRegistry* GetForProfile(Profile* profile); - - // Returns the singleton instance of the WebIntentsRegistryFactory. - static WebIntentsRegistryFactory* GetInstance(); - - private: - friend struct DefaultSingletonTraits<WebIntentsRegistryFactory>; - - WebIntentsRegistryFactory(); - virtual ~WebIntentsRegistryFactory(); - - // ProfileKeyedServiceFactory implementation. - virtual ProfileKeyedService* BuildServiceInstanceFor( - Profile* profile) const OVERRIDE; - virtual bool ServiceRedirectedInIncognito() const OVERRIDE; - - DISALLOW_COPY_AND_ASSIGN(WebIntentsRegistryFactory); -}; - -#endif // CHROME_BROWSER_INTENTS_WEB_INTENTS_REGISTRY_FACTORY_H_ diff --git a/chrome/browser/intents/web_intents_registry_unittest.cc b/chrome/browser/intents/web_intents_registry_unittest.cc deleted file mode 100644 index 921108a..0000000 --- a/chrome/browser/intents/web_intents_registry_unittest.cc +++ /dev/null @@ -1,807 +0,0 @@ -// Copyright (c) 2012 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 "base/bind.h" -#include "base/file_util.h" -#include "base/files/scoped_temp_dir.h" -#include "base/json/json_file_value_serializer.h" -#include "base/message_loop.h" -#include "base/path_service.h" -#include "base/synchronization/waitable_event.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/extensions/test_extension_service.h" -#include "chrome/browser/intents/default_web_intent_service.h" -#include "chrome/browser/intents/web_intents_registry.h" -#include "chrome/browser/webdata/web_data_service.h" -#include "chrome/common/chrome_paths.h" -#include "chrome/common/extensions/extension.h" -#include "chrome/common/extensions/extension_manifest_constants.h" -#include "chrome/common/extensions/extension_set.h" -#include "chrome/common/extensions/manifest.h" -#include "chrome/common/extensions/manifest_handler.h" -#include "chrome/common/extensions/web_intents_handler.h" -#include "content/public/test/test_browser_thread.h" -#include "testing/gmock/include/gmock/gmock.h" -#include "testing/gtest/include/gtest/gtest.h" - -using content::BrowserThread; -using extensions::Extension; -using extensions::Manifest; -using webkit_glue::WebIntentServiceData; - -class MockExtensionService: public TestExtensionService { - public: - virtual ~MockExtensionService() {} - MOCK_CONST_METHOD0(extensions, const ExtensionSet*()); - MOCK_CONST_METHOD2(GetExtensionById, - const Extension*(const std::string&, bool)); - MOCK_CONST_METHOD1(GetInstalledExtension, - const Extension*(const std::string& id)); -}; - -namespace { - -// TODO(groby): Unify loading functions with extension_manifest_unittest code. -DictionaryValue* LoadManifestFile(const base::FilePath& path, - std::string* error) { - EXPECT_TRUE(file_util::PathExists(path)); - JSONFileValueSerializer serializer(path); - return static_cast<DictionaryValue*>(serializer.Deserialize(NULL, error)); -} - -scoped_refptr<Extension> LoadExtensionWithLocation( - const std::string& name, - Manifest::Location location, - std::string* error) { - base::FilePath path; - PathService::Get(chrome::DIR_TEST_DATA, &path); - path = path.AppendASCII("extensions") - .AppendASCII("manifest_tests") - .AppendASCII(name.c_str()); - scoped_ptr<DictionaryValue> value(LoadManifestFile(path, error)); - if (!value.get()) - return NULL; - return Extension::Create(path.DirName(), - location, - *value, - Extension::NO_FLAGS, - Extension::GenerateIdForPath(path), - error); -} - -scoped_refptr<Extension> LoadExtension(const std::string& name, - std::string* error) { - return LoadExtensionWithLocation(name, Manifest::INTERNAL, error); -} - -scoped_refptr<Extension> LoadAndExpectSuccess(const std::string& name) { - std::string error; - scoped_refptr<Extension> extension = LoadExtension(name, &error); - EXPECT_TRUE(extension) << name; - EXPECT_EQ("", error) << name; - return extension; -} - -} // namespace - -class WebIntentsRegistryTest : public testing::Test { - public: - WebIntentsRegistryTest() - : ui_thread_(BrowserThread::UI, &message_loop_), - db_thread_(BrowserThread::DB) {} - - protected: - virtual void SetUp() { - db_thread_.Start(); - wds_ = new WebDataService(); - ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); - wds_->Init(temp_dir_.path()); - registry_.Initialize(wds_, &extension_service_); - EXPECT_CALL(extension_service_, extensions()). - WillRepeatedly(testing::Return(&extensions_)); - EXPECT_CALL(extension_service_, GetExtensionById(testing::_, testing::_)). - WillRepeatedly( - testing::Invoke(this, &WebIntentsRegistryTest::GetExtensionById)); - extensions::ManifestHandler::Register( - extension_manifest_keys::kIntents, - make_linked_ptr(new extensions::WebIntentsHandler)); - } - - virtual void TearDown() { - // Clear all references to wds to force it destruction. - wds_->ShutdownOnUIThread(); - wds_ = NULL; - - // Schedule another task on the DB thread to notify us that it's safe to - // carry on with the test. - base::WaitableEvent done(false, false); - BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, - base::Bind(&base::WaitableEvent::Signal, - base::Unretained(&done))); - done.Wait(); - db_thread_.Stop(); - MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); - MessageLoop::current()->Run(); - } - - const Extension* GetExtensionById(const std::string& extension_id, - testing::Unused) { - for (ExtensionSet::const_iterator iter = extensions_.begin(); - iter != extensions_.end(); ++iter) { - if ((*iter)->id() == extension_id) - return &**iter; - } - - return NULL; - } - - MessageLoopForUI message_loop_; - content::TestBrowserThread ui_thread_; - content::TestBrowserThread db_thread_; - scoped_refptr<WebDataService> wds_; - MockExtensionService extension_service_; - ExtensionSet extensions_; - WebIntentsRegistry registry_; - base::ScopedTempDir temp_dir_; -}; - -// Base consumer for WebIntentsRegistry results. -class TestConsumer { - public: - // Wait for the UI message loop to terminate - happens when OnIntesQueryDone - // is invoked. - void WaitForData() { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - MessageLoop::current()->Run(); - } -}; - -// Consumer of service lists. Stores result data and -// terminates UI thread when callback is invoked. -class ServiceListConsumer : public TestConsumer { - public: - void Accept( - const std::vector<webkit_glue::WebIntentServiceData>& services) { - services_ = services; - - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - MessageLoop::current()->Quit(); - } - - bool ResultsContain(const webkit_glue::WebIntentServiceData& service) { - for (size_t i = 0; i < services_.size(); ++i) { - if (services_[i] == service) - return true; - } - return false; - } - - // Result data from callback. - std::vector<webkit_glue::WebIntentServiceData> services_; -}; - -// Consume or defaultservice lists. Stores result data and -// terminates UI thread when callback is invoked. -class DefaultServiceListConsumer : public TestConsumer { - public: - void Accept(const std::vector<DefaultWebIntentService>& services) { - services_ = services; - - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - MessageLoop::current()->Quit(); - } - - bool ResultsContain(const DefaultWebIntentService& service) { - for (size_t i = 0; i < services_.size(); ++i) { - if (services_[i] == service) - return true; - } - return false; - } - - // Result data from callback. - std::vector<DefaultWebIntentService> services_; -}; - -// Consumer of a default service. Stores result data and -// terminates UI thread when callback is invoked. -class DefaultServiceConsumer : public TestConsumer { - public: - void Accept( - const DefaultWebIntentService& default_service) { - service_ = default_service; - - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); - MessageLoop::current()->Quit(); - } - - // Result default data from callback. - DefaultWebIntentService service_; -}; - -TEST_F(WebIntentsRegistryTest, BasicTests) { - webkit_glue::WebIntentServiceData service; - service.service_url = GURL("http://google.com"); - service.action = ASCIIToUTF16("share"); - service.type = ASCIIToUTF16("image/*"); - service.title = ASCIIToUTF16("Google's Sharing Service"); - - registry_.RegisterIntentService(service); - - service.type = ASCIIToUTF16("video/*"); - service.title = ASCIIToUTF16("Second Service"); - registry_.RegisterIntentService(service); - - service.action = ASCIIToUTF16("search"); - registry_.RegisterIntentService(service); - - ServiceListConsumer consumer; - registry_.GetIntentServices(ASCIIToUTF16("share"), ASCIIToUTF16("*"), - base::Bind(&ServiceListConsumer::Accept, - base::Unretained(&consumer))); - consumer.WaitForData(); - EXPECT_EQ(2U, consumer.services_.size()); - - registry_.GetIntentServices(ASCIIToUTF16("search"), ASCIIToUTF16("*"), - base::Bind(&ServiceListConsumer::Accept, - base::Unretained(&consumer))); - consumer.WaitForData(); - EXPECT_EQ(1U, consumer.services_.size()); - - service.action = ASCIIToUTF16("share"); - service.type = ASCIIToUTF16("image/*"); - registry_.UnregisterIntentService(service); - - registry_.GetIntentServices(ASCIIToUTF16("share"), ASCIIToUTF16("*"), - base::Bind(&ServiceListConsumer::Accept, - base::Unretained(&consumer))); - consumer.WaitForData(); - EXPECT_EQ(1U, consumer.services_.size()); -} - -TEST_F(WebIntentsRegistryTest, GetIntentServicesForExtensionFilter) { - scoped_refptr<Extension> share_extension( - LoadAndExpectSuccess("intent_valid.json")); - scoped_refptr<Extension> edit_extension( - LoadAndExpectSuccess("intent_valid_2.json")); - extensions_.Insert(share_extension); - extensions_.Insert(edit_extension); - ASSERT_EQ(2U, extensions_.size()); - - WebIntentsRegistry::IntentServiceList services; - registry_.GetIntentServicesForExtensionFilter( - ASCIIToUTF16("http://webintents.org/edit"), - ASCIIToUTF16("image/*"), - edit_extension->id(), - &services); - ASSERT_EQ(1U, services.size()); - - EXPECT_EQ(edit_extension->url().spec() + "services/edit", - services[0].service_url.spec()); -} - -TEST_F(WebIntentsRegistryTest, GetAllIntents) { - webkit_glue::WebIntentServiceData service; - service.service_url = GURL("http://google.com"); - service.action = ASCIIToUTF16("share"); - service.type = ASCIIToUTF16("image/*"); - service.title = ASCIIToUTF16("Google's Sharing Service"); - registry_.RegisterIntentService(service); - - service.action = ASCIIToUTF16("search"); - registry_.RegisterIntentService(service); - - ServiceListConsumer consumer; - registry_.GetAllIntentServices(base::Bind(&ServiceListConsumer::Accept, - base::Unretained(&consumer))); - consumer.WaitForData(); - ASSERT_EQ(2U, consumer.services_.size()); - - if (consumer.services_[0].action != ASCIIToUTF16("share")) - std::swap(consumer.services_[0], consumer.services_[1]); - - service.action = ASCIIToUTF16("share"); - EXPECT_EQ(service, consumer.services_[0]); - - service.action = ASCIIToUTF16("search"); - EXPECT_EQ(service, consumer.services_[1]); -} - -TEST_F(WebIntentsRegistryTest, GetExtensionIntents) { - extensions_.Insert(LoadAndExpectSuccess("intent_valid.json")); - extensions_.Insert(LoadAndExpectSuccess("intent_valid_2.json")); - ASSERT_EQ(2U, extensions_.size()); - - ServiceListConsumer consumer; - registry_.GetAllIntentServices(base::Bind(&ServiceListConsumer::Accept, - base::Unretained(&consumer))); - consumer.WaitForData(); - ASSERT_EQ(2U, consumer.services_.size()); -} - -TEST_F(WebIntentsRegistryTest, GetSomeExtensionIntents) { - extensions_.Insert(LoadAndExpectSuccess("intent_valid.json")); - extensions_.Insert(LoadAndExpectSuccess("intent_valid_2.json")); - ASSERT_EQ(2U, extensions_.size()); - - ServiceListConsumer consumer; - registry_.GetIntentServices(ASCIIToUTF16("http://webintents.org/edit"), - ASCIIToUTF16("*"), - base::Bind(&ServiceListConsumer::Accept, - base::Unretained(&consumer))); - consumer.WaitForData(); - ASSERT_EQ(1U, consumer.services_.size()); -} - -TEST_F(WebIntentsRegistryTest, GetIntentsFromMixedSources) { - extensions_.Insert(LoadAndExpectSuccess("intent_valid.json")); - extensions_.Insert(LoadAndExpectSuccess("intent_valid_2.json")); - ASSERT_EQ(2U, extensions_.size()); - - webkit_glue::WebIntentServiceData service; - service.service_url = GURL("http://somewhere.com/intent/edit.html"); - service.action = ASCIIToUTF16("http://webintents.org/edit"); - service.type = ASCIIToUTF16("image/*"); - service.title = ASCIIToUTF16("Image Editing Service"); - registry_.RegisterIntentService(service); - - ServiceListConsumer consumer; - registry_.GetIntentServices( - ASCIIToUTF16("http://webintents.org/edit"), ASCIIToUTF16("*"), - base::Bind(&ServiceListConsumer::Accept, - base::Unretained(&consumer))); - consumer.WaitForData(); - ASSERT_EQ(2U, consumer.services_.size()); - - registry_.GetIntentServices(ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("*"), - base::Bind(&ServiceListConsumer::Accept, - base::Unretained(&consumer))); - consumer.WaitForData(); - ASSERT_EQ(1U, consumer.services_.size()); -} - -TEST_F(WebIntentsRegistryTest, GetIntentsWithMimeAndLiteralMatching) { - WebIntentServiceData services[] = { - WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("image/*"), - string16(), - GURL("http://elsewhere.com/intent/share.html"), - ASCIIToUTF16("Image Sharing Service")), - WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("image/jpeg"), - string16(), - GURL("http://somewhere.com/intent/share.html"), - ASCIIToUTF16("Specific Image Editing Service")), - WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("text/uri-list"), - string16(), - GURL("http://somewhere.com/intent/share.html"), - ASCIIToUTF16("Text Link Sharing Service")), - WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("text/plain"), - string16(), - GURL("http://somewhere2.com/intent/share.html"), - ASCIIToUTF16("Text Sharing Service")), - WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("elsewhere"), - string16(), - GURL("http://elsewhere.com/intent/share.html"), - ASCIIToUTF16("Text Sharing Service")), - WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("somewhere"), - string16(), - GURL("http://somewhere.com/intent/share.html"), - ASCIIToUTF16("Text Sharing Service")), - WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("nota/*"), - string16(), - GURL("http://somewhere.com/intent/share.html"), - ASCIIToUTF16("Text Sharing Service")), - WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("*nomime"), - string16(), - GURL("http://somewhere.com/intent/share.html"), - ASCIIToUTF16("Text Sharing Service")), - WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("*/nomime"), - string16(), - GURL("http://somewhere.com/intent/share.html"), - ASCIIToUTF16("Text Sharing Service")), - WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("*/*nomime"), - string16(), - GURL("http://somewhere.com/intent/share.html"), - ASCIIToUTF16("Text Sharing Service")), - WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("*/*/nomime"), - string16(), - GURL("http://somewhere.com/intent/share.html"), - ASCIIToUTF16("Text Sharing Service")), - WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("nomime/*"), - string16(), - GURL("http://somewhere.com/intent/share.html"), - ASCIIToUTF16("Text Sharing Service")), - WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("x-type/*"), - string16(), - GURL("http://somewhere.com/intent/share.html"), - ASCIIToUTF16("Text Sharing Service")), - WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("x-/*"), // actually a string literal - string16(), - GURL("http://somewhere.com/intent/share.html"), - ASCIIToUTF16("Text Sharing Service")) - }; - registry_.RegisterIntentService(services[0]); - registry_.RegisterIntentService(services[1]); - registry_.RegisterIntentService(services[2]); - registry_.RegisterIntentService(services[3]); - registry_.RegisterIntentService(services[4]); - registry_.RegisterIntentService(services[5]); - registry_.RegisterIntentService(services[6]); - registry_.RegisterIntentService(services[7]); - registry_.RegisterIntentService(services[8]); - registry_.RegisterIntentService(services[9]); - registry_.RegisterIntentService(services[10]); - registry_.RegisterIntentService(services[11]); - registry_.RegisterIntentService(services[12]); - registry_.RegisterIntentService(services[13]); - - ServiceListConsumer consumer; - - // Test specific match on both sides. - registry_.GetIntentServices(ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("text/uri-list"), - base::Bind(&ServiceListConsumer::Accept, - base::Unretained(&consumer))); - consumer.WaitForData(); - ASSERT_EQ(1U, consumer.services_.size()); - EXPECT_EQ(services[2], consumer.services_[0]); - - // Test specific query, wildcard registration. - registry_.GetIntentServices(ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("image/png"), - base::Bind(&ServiceListConsumer::Accept, - base::Unretained(&consumer))); - consumer.WaitForData(); - ASSERT_EQ(1U, consumer.services_.size()); - EXPECT_EQ(services[0], consumer.services_[0]); - - // Test wildcard query, specific registration. - registry_.GetIntentServices(ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("text/*"), - base::Bind(&ServiceListConsumer::Accept, - base::Unretained(&consumer))); - consumer.WaitForData(); - ASSERT_EQ(2U, consumer.services_.size()); - EXPECT_EQ(services[2], consumer.services_[0]); - EXPECT_EQ(services[3], consumer.services_[1]); - - // Test wildcard query, wildcard registration. - registry_.GetIntentServices(ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("image/*"), - base::Bind(&ServiceListConsumer::Accept, - base::Unretained(&consumer))); - consumer.WaitForData(); - ASSERT_EQ(2U, consumer.services_.size()); - EXPECT_EQ(services[0], consumer.services_[0]); - EXPECT_EQ(services[1], consumer.services_[1]); - - // Test "catch-all" query. - registry_.GetIntentServices(ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("*"), - base::Bind(&ServiceListConsumer::Accept, - base::Unretained(&consumer))); - consumer.WaitForData(); - ASSERT_EQ(5U, consumer.services_.size()); - EXPECT_TRUE(consumer.ResultsContain(services[0])); - EXPECT_TRUE(consumer.ResultsContain(services[1])); - EXPECT_TRUE(consumer.ResultsContain(services[2])); - EXPECT_TRUE(consumer.ResultsContain(services[3])); - EXPECT_TRUE(consumer.ResultsContain(services[12])); - - // Test retrieve string literal match. - registry_.GetIntentServices( - ASCIIToUTF16("http://webintents.org/share"), ASCIIToUTF16("elsewhere"), - base::Bind(&ServiceListConsumer::Accept, - base::Unretained(&consumer))); - consumer.WaitForData(); - ASSERT_EQ(1U, consumer.services_.size()); - EXPECT_EQ(services[4], consumer.services_[0]); - - // Test retrieve MIME-looking type but actually isn't - // doesn't wildcard match. - registry_.GetIntentServices( - ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("nota/mimetype"), - base::Bind(&ServiceListConsumer::Accept, - base::Unretained(&consumer))); - consumer.WaitForData(); - ASSERT_EQ(0U, consumer.services_.size()); - - // Also a MIME-ish type that actually isn't. - registry_.GetIntentServices( - ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("x-/mimetype"), - base::Bind(&ServiceListConsumer::Accept, - base::Unretained(&consumer))); - consumer.WaitForData(); - ASSERT_EQ(0U, consumer.services_.size()); - - // Extension MIME type will match wildcard. - registry_.GetIntentServices( - ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("x-type/mimetype"), - base::Bind(&ServiceListConsumer::Accept, - base::Unretained(&consumer))); - consumer.WaitForData(); - ASSERT_EQ(1U, consumer.services_.size()); -} - -TEST_F(WebIntentsRegistryTest, TestGetAllDefaultIntentServices) { - DefaultWebIntentService s0; - s0.action = ASCIIToUTF16("share"); - s0.type = ASCIIToUTF16("text/*"); - // Values here are just dummies to test for preservation. - s0.user_date = 1; - s0.suppression = 4; - s0.service_url = "service_url"; - registry_.RegisterDefaultIntentService(s0); - - DefaultWebIntentService s1; - s1.action = ASCIIToUTF16("pick"); - s1.type = ASCIIToUTF16("image/*"); - // Values here are just dummies to test for preservation. - s1.user_date = 1; - s1.suppression = 4; - s1.service_url = "service_url"; - registry_.RegisterDefaultIntentService(s1); - - DefaultWebIntentService s2; - s2.action = ASCIIToUTF16("save"); - s2.type = ASCIIToUTF16("application/*"); - // Values here are just dummies to test for preservation. - s2.user_date = 1; - s2.suppression = 4; - s2.service_url = "service_url"; - registry_.RegisterDefaultIntentService(s2); - - DefaultServiceListConsumer consumer; - - registry_.GetAllDefaultIntentServices( - base::Bind(&DefaultServiceListConsumer::Accept, - base::Unretained(&consumer))); - - consumer.WaitForData(); - - EXPECT_TRUE(consumer.ResultsContain(s0)); - EXPECT_TRUE(consumer.ResultsContain(s1)); - EXPECT_TRUE(consumer.ResultsContain(s2)); -} - -TEST_F(WebIntentsRegistryTest, TestGetDefaults) { - // Ignore QO-default related calls. - EXPECT_CALL(extension_service_, GetInstalledExtension(testing::_)). - WillRepeatedly(testing::ReturnNull()); - - DefaultWebIntentService default_service; - default_service.action = ASCIIToUTF16("share"); - default_service.type = ASCIIToUTF16("text/*"); - // Values here are just dummies to test for preservation. - default_service.user_date = 1; - default_service.suppression = 4; - default_service.service_url = "service_url"; - registry_.RegisterDefaultIntentService(default_service); - - DefaultServiceConsumer consumer; - - // Test we can retrieve default entries by action. - registry_.GetDefaultIntentService( - ASCIIToUTF16("share"), ASCIIToUTF16("text/plain"), - GURL("http://www.google.com/"), - base::Bind(&DefaultServiceConsumer::Accept, - base::Unretained(&consumer))); - - consumer.WaitForData(); - - EXPECT_EQ("service_url", consumer.service_.service_url); - EXPECT_EQ(1, consumer.service_.user_date); - EXPECT_EQ(4, consumer.service_.suppression); - - // Can get for wildcard. - consumer.service_ = DefaultWebIntentService(); - registry_.GetDefaultIntentService( - ASCIIToUTF16("share"), - ASCIIToUTF16("text/*"), - GURL("http://www.google.com/"), - base::Bind(&DefaultServiceConsumer::Accept, - base::Unretained(&consumer))); - consumer.WaitForData(); - EXPECT_EQ("service_url", consumer.service_.service_url); - EXPECT_EQ(1, consumer.service_.user_date); - EXPECT_EQ(4, consumer.service_.suppression); - - // Test that no action match means we don't retrieve any - // default entries. - consumer.service_ = DefaultWebIntentService(); - ASSERT_EQ("", consumer.service_.service_url); - registry_.GetDefaultIntentService( - ASCIIToUTF16("no-share"), ASCIIToUTF16("text/plain"), - GURL("http://www.google.com/"), - base::Bind(&DefaultServiceConsumer::Accept, - base::Unretained(&consumer))); - - consumer.WaitForData(); - - EXPECT_EQ("", consumer.service_.service_url); - - // Test that no type match means we don't retrieve any - // default entries (they get filtered out). - consumer.service_ = DefaultWebIntentService(); - ASSERT_EQ("", consumer.service_.service_url); - registry_.GetDefaultIntentService( - ASCIIToUTF16("share"), ASCIIToUTF16("image/plain"), - GURL("http://www.google.com/"), - base::Bind(&DefaultServiceConsumer::Accept, - base::Unretained(&consumer))); - - consumer.WaitForData(); - - EXPECT_EQ("", consumer.service_.service_url); - - // Check that a string-literal type won't match. - consumer.service_ = DefaultWebIntentService(); - ASSERT_EQ("", consumer.service_.service_url); - registry_.GetDefaultIntentService( - ASCIIToUTF16("share"), - ASCIIToUTF16("literal"), - GURL("http://www.google.com/"), - base::Bind(&DefaultServiceConsumer::Accept, - base::Unretained(&consumer))); - - consumer.WaitForData(); - - EXPECT_EQ("", consumer.service_.service_url); -} - -// Verify that collapsing equivalent intents works properly. -TEST_F(WebIntentsRegistryTest, CollapseIntents) { - WebIntentsRegistry::IntentServiceList services; - - // Add two intents with identical |service_url|, |title|, and |action|. - services.push_back( - WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("image/png"), - string16(), - GURL("http://somewhere.com/intent/share.html"), - ASCIIToUTF16("Image Sharing Service"))); - services.push_back( - WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("image/jpg"), - string16(), - GURL("http://somewhere.com/intent/share.html"), - ASCIIToUTF16("Image Sharing Service"))); - // Service that differs in disposition. - services.push_back( - WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("image/png"), - string16(), - GURL("http://somewhere.com/intent/share.html"), - ASCIIToUTF16("Image Sharing Service"))); - ASSERT_EQ(WebIntentServiceData::DISPOSITION_WINDOW, - services.back().disposition); - services.back().disposition = WebIntentServiceData::DISPOSITION_INLINE; - // Service that differs in title. - services.push_back( - WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("image/png"), - string16(), - GURL("http://somewhere.com/intent/share.html"), - ASCIIToUTF16("Sharing Service"))); - // Service that differs in |action|. - services.push_back( - WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share-old"), - ASCIIToUTF16("image/png"), - string16(), - GURL("http://somewhere.com/intent/share.html"), - ASCIIToUTF16("Image Sharing Service"))); - // Service that differs in |service_url|. - services.push_back( - WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("image/png"), - string16(), - GURL("http://zoo.com/share.html"), - ASCIIToUTF16("Image Sharing Service"))); - - // Only the first two services should be collapsed. - registry_.CollapseIntents(&services); - ASSERT_EQ(5UL, services.size()); - - // Joined services have their mime types combined - EXPECT_EQ(ASCIIToUTF16("image/png,image/jpg"), services[0].type); - - // Verify the remaining services via distinguishing characteristics. - EXPECT_EQ(WebIntentServiceData::DISPOSITION_INLINE, services[1].disposition); - EXPECT_EQ(ASCIIToUTF16("Sharing Service"), services[2].title); - EXPECT_EQ(ASCIIToUTF16("http://webintents.org/share-old"), - services[3].action); - EXPECT_EQ(GURL("http://zoo.com/share.html").spec(), - services[4].service_url.spec()); -} - -// Verify that GetIntentServices collapses equivalent intents. -TEST_F(WebIntentsRegistryTest, GetIntentsCollapsesEquivalentIntents) { - WebIntentServiceData services[] = { - WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("image/png"), - string16(), - GURL("http://somewhere.com/intent/share.html"), - ASCIIToUTF16("Image Sharing Service")), - WebIntentServiceData(ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("image/jpg"), - string16(), - GURL("http://somewhere.com/intent/share.html"), - ASCIIToUTF16("Image Sharing Service")) - }; - registry_.RegisterIntentService(services[0]); - registry_.RegisterIntentService(services[1]); - - ServiceListConsumer consumer; - registry_.GetIntentServices(ASCIIToUTF16("http://webintents.org/share"), - ASCIIToUTF16("image/*"), - base::Bind(&ServiceListConsumer::Accept, - base::Unretained(&consumer))); - - consumer.WaitForData(); - ASSERT_EQ(1U, consumer.services_.size()); - EXPECT_EQ(ASCIIToUTF16("image/png,image/jpg"), consumer.services_[0].type); -} - -TEST_F(WebIntentsRegistryTest, UnregisterDefaultIntentServicesForServiceURL) { - - const GURL service_url_0("http://jibfest.com/dozer"); - const GURL service_url_1("http://kittyfizzer.com/fizz"); - - DefaultWebIntentService s0; - s0.action = ASCIIToUTF16("share"); - s0.type = ASCIIToUTF16("text/*"); - // Values here are just dummies to test for preservation. - s0.user_date = 1; - s0.suppression = 4; - s0.service_url = service_url_0.spec(); - registry_.RegisterDefaultIntentService(s0); - - DefaultWebIntentService s1; - s1.action = ASCIIToUTF16("whack"); - s1.type = ASCIIToUTF16("text/*"); - // Values here are just dummies to test for preservation. - s1.user_date = 1; - s1.suppression = 4; - s1.service_url = service_url_1.spec(); - registry_.RegisterDefaultIntentService(s1); - - DefaultServiceListConsumer consumer; - - registry_.GetAllDefaultIntentServices( - base::Bind(&DefaultServiceListConsumer::Accept, - base::Unretained(&consumer))); - - consumer.WaitForData(); - - ASSERT_EQ(2U, consumer.services_.size()); - - registry_.UnregisterServiceDefaults(service_url_0); - MessageLoop::current()->RunUntilIdle(); - - registry_.GetAllDefaultIntentServices( - base::Bind(&DefaultServiceListConsumer::Accept, - base::Unretained(&consumer))); - - consumer.WaitForData(); - - ASSERT_EQ(1U, consumer.services_.size()); - EXPECT_EQ(service_url_1.spec(), consumer.services_[0].service_url); -} diff --git a/chrome/browser/intents/web_intents_reporting.cc b/chrome/browser/intents/web_intents_reporting.cc deleted file mode 100644 index c780724..0000000 --- a/chrome/browser/intents/web_intents_reporting.cc +++ /dev/null @@ -1,167 +0,0 @@ -// Copyright (c) 2012 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 "web_intents_reporting.h" - -#include "base/metrics/histogram.h" -#include "base/string_util.h" -#include "chrome/browser/intents/web_intents_util.h" -#include "net/base/mime_util.h" -#include "webkit/glue/web_intent_data.h" - -namespace web_intents { -namespace { - -struct TypeMapping { - const char* name; - const TypeId id; -}; - -const TypeMapping kTypeMap[] = { - { "application", TYPE_ID_APPLICATION }, - { "audio", TYPE_ID_AUDIO }, - { "example", TYPE_ID_EXAMPLE }, - { "image", TYPE_ID_IMAGE }, - { "message", TYPE_ID_MESSAGE }, - { "model", TYPE_ID_MODEL }, - { "multipart", TYPE_ID_MULTIPART }, - { "text", TYPE_ID_TEXT }, - { "video", TYPE_ID_VIDEO }, -}; - -// The number of buckets for the histogram of the duration of time spent in a -// service. -const int kServiceActiveTimeNumBuckets = 10; - -// The lower bound on the tracked duration of time spent in a service. -// This bound is in seconds. -const int kServiceActiveDurationMinSeconds = 1; - -// The upper bound on the tracked duration of time spent in a service. -// This bound is in seconds. -const int kServiceActiveDurationMaxSeconds = 3600; - -// UMA bucket range for custom histograms. -// -// TODO(rouslan): Remove this once we've migrated to sparse histograms. See -// http://crbug.com/153891 before changing anything. -std::vector<int> GetUmaBucketsCustomRange() { - // Please update these numbers if you add more actions or types. - const int kNumActions = 7; - const int kNumTypes = 10; - std::vector<int> range; - for (int i = 1; i <= kNumActions; i++) { - for (int j = 1; j <= kNumTypes; j++) { - range.push_back(i << 8 | j); - } - } - return range; -} - -// Returns the ActionMapping for |action| if one exists, or NULL. -TypeId ToTypeId(const string16& type) { - const std::string iana_type = net::GetIANAMediaType(UTF16ToASCII(type)); - for (size_t i = 0; i < arraysize(kTypeMap); ++i) { - if (iana_type == kTypeMap[i].name) { - return kTypeMap[i].id; - } - } - return TYPE_ID_CUSTOM; -} - -// Records the number of services installed at the time the picker -// is shown to the user. Drops the size into one of several buckets. -void RecordInstalledServiceCount(const UMABucket bucket, size_t installed) { - if (installed == 0) { - UMA_HISTOGRAM_CUSTOM_ENUMERATION("WebIntents.Service.NumInstalled.0.v0", - bucket, GetUmaBucketsCustomRange()); - } else if (installed >= 1 && installed <= 4) { - UMA_HISTOGRAM_CUSTOM_ENUMERATION("WebIntents.Service.NumInstalled.1-4.v0", - bucket, GetUmaBucketsCustomRange()); - } else if (installed >= 5 && installed <= 8) { - UMA_HISTOGRAM_CUSTOM_ENUMERATION("WebIntents.Service.NumInstalled.5-8.v0", - bucket, GetUmaBucketsCustomRange()); - } else { - UMA_HISTOGRAM_CUSTOM_ENUMERATION("WebIntents.Service.NumInstalled.9+.v0", - bucket, GetUmaBucketsCustomRange()); - } -} - -} // namespace - -UMABucket ToUMABucket(const string16& action, const string16& type) { - ActionId action_id = ToActionId(action); - TypeId type_id = ToTypeId(type); - short bucket_id = (action_id << 8) | type_id; - DCHECK(bucket_id > 256); - return static_cast<UMABucket>(bucket_id); -} - -void RecordIntentsDispatchDisabled() { - UMA_HISTOGRAM_COUNTS("WebIntents.DispatchDisabled", 1); -} - -void RecordIntentDispatchRequested() { - UMA_HISTOGRAM_COUNTS("WebIntents.Dispatch", 1); -} - -void RecordIntentDispatched(const UMABucket bucket) { - UMA_HISTOGRAM_CUSTOM_ENUMERATION("WebIntents.IntentDispatched.v0", - bucket, GetUmaBucketsCustomRange()); -} - -void RecordPickerShow(const UMABucket bucket, size_t installed) { - UMA_HISTOGRAM_CUSTOM_ENUMERATION("WebIntents.Picker.Show.v0", - bucket, GetUmaBucketsCustomRange()); - RecordInstalledServiceCount(bucket, installed); -} - -void RecordPickerCancel(const UMABucket bucket) { - UMA_HISTOGRAM_CUSTOM_ENUMERATION("WebIntents.Picker.Cancel.v0", - bucket, GetUmaBucketsCustomRange()); -} - -void RecordServiceInvoke(const UMABucket bucket) { - UMA_HISTOGRAM_CUSTOM_ENUMERATION("WebIntents.Service.Invoked.v0", - bucket, GetUmaBucketsCustomRange()); -} - -void RecordChooseAnotherService(const UMABucket bucket) { - UMA_HISTOGRAM_CUSTOM_ENUMERATION("WebIntents.Service.ChooseAnother.v0", - bucket, GetUmaBucketsCustomRange()); -} - -void RecordCWSExtensionInstalled(const UMABucket bucket) { - UMA_HISTOGRAM_CUSTOM_ENUMERATION("WebIntents.Service.CWSInstall.v0", - bucket, GetUmaBucketsCustomRange()); -} - -void RecordServiceActiveDuration( - webkit_glue::WebIntentReplyType reply_type, - const base::TimeDelta& duration) { - switch (reply_type) { - case webkit_glue::WEB_INTENT_REPLY_SUCCESS: - UMA_HISTOGRAM_CUSTOM_TIMES("WebIntents.Service.ActiveDuration.Success", - duration, - base::TimeDelta::FromSeconds(kServiceActiveDurationMinSeconds), - base::TimeDelta::FromSeconds(kServiceActiveDurationMaxSeconds), - kServiceActiveTimeNumBuckets); - break; - case webkit_glue::WEB_INTENT_REPLY_INVALID: - case webkit_glue::WEB_INTENT_REPLY_FAILURE: - case webkit_glue::WEB_INTENT_PICKER_CANCELLED: - case webkit_glue::WEB_INTENT_SERVICE_CONTENTS_CLOSED: - UMA_HISTOGRAM_CUSTOM_TIMES("WebIntents.Service.ActiveDuration.Failure", - duration, - base::TimeDelta::FromSeconds(kServiceActiveDurationMinSeconds), - base::TimeDelta::FromSeconds(kServiceActiveDurationMaxSeconds), - kServiceActiveTimeNumBuckets); - break; - default: - NOTREACHED(); - break; - } -} - -} // namespace web_intents diff --git a/chrome/browser/intents/web_intents_reporting.h b/chrome/browser/intents/web_intents_reporting.h deleted file mode 100644 index afcd391..0000000 --- a/chrome/browser/intents/web_intents_reporting.h +++ /dev/null @@ -1,135 +0,0 @@ -// Copyright (c) 2012 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_INTENTS_WEB_INTENTS_REPORTING_H_ -#define CHROME_BROWSER_INTENTS_WEB_INTENTS_REPORTING_H_ - -#include "base/string16.h" -#include "chrome/browser/intents/web_intents_util.h" -#include "webkit/glue/web_intent_reply_data.h" - -namespace base { -class TimeDelta; -} - -namespace webkit_glue { -struct WebIntentData; -} - -namespace web_intents { - -// primarily an implementation detail, but declared in this scope -// so they can be used in generating bucket ids -enum TypeId { - TYPE_ID_CUSTOM = 1, - TYPE_ID_APPLICATION, - TYPE_ID_AUDIO, - TYPE_ID_EXAMPLE, - TYPE_ID_IMAGE, - TYPE_ID_MESSAGE, - TYPE_ID_MODEL, - TYPE_ID_MULTIPART, - TYPE_ID_TEXT, - TYPE_ID_VIDEO, -}; - -#define INTENT_UMA_BUCKET(ACTION, TYPE) \ - (ACTION_ID_##ACTION << 8) | TYPE_ID_##TYPE - -// UMA buckets for reporting the Web Intent action and type. -enum UMABucket { - BUCKET_CUSTOM_CUSTOM = INTENT_UMA_BUCKET(CUSTOM, CUSTOM), - BUCKET_CUSTOM_APPLICATION = INTENT_UMA_BUCKET(CUSTOM, APPLICATION), - BUCKET_CUSTOM_AUDIO = INTENT_UMA_BUCKET(CUSTOM, AUDIO), - BUCKET_CUSTOM_EXAMPLE = INTENT_UMA_BUCKET(CUSTOM, EXAMPLE), - BUCKET_CUSTOM_IMAGE = INTENT_UMA_BUCKET(CUSTOM, IMAGE), - BUCKET_CUSTOM_MESSAGE = INTENT_UMA_BUCKET(CUSTOM, MESSAGE), - BUCKET_CUSTOM_MODEL = INTENT_UMA_BUCKET(CUSTOM, MODEL), - BUCKET_CUSTOM_MULTIPART = INTENT_UMA_BUCKET(CUSTOM, MULTIPART), - BUCKET_CUSTOM_TEXT = INTENT_UMA_BUCKET(CUSTOM, TEXT), - BUCKET_CUSTOM_VIDEO = INTENT_UMA_BUCKET(CUSTOM, VIDEO), - BUCKET_EDIT_CUSTOM = INTENT_UMA_BUCKET(EDIT, CUSTOM), - BUCKET_EDIT_APPLICATION = INTENT_UMA_BUCKET(EDIT, APPLICATION), - BUCKET_EDIT_AUDIO = INTENT_UMA_BUCKET(EDIT, AUDIO), - BUCKET_EDIT_EXAMPLE = INTENT_UMA_BUCKET(EDIT, EXAMPLE), - BUCKET_EDIT_IMAGE = INTENT_UMA_BUCKET(EDIT, IMAGE), - BUCKET_EDIT_MESSAGE = INTENT_UMA_BUCKET(EDIT, MESSAGE), - BUCKET_EDIT_MODEL = INTENT_UMA_BUCKET(EDIT, MODEL), - BUCKET_EDIT_MULTIPART = INTENT_UMA_BUCKET(EDIT, MULTIPART), - BUCKET_EDIT_TEXT = INTENT_UMA_BUCKET(EDIT, TEXT), - BUCKET_EDIT_VIDEO = INTENT_UMA_BUCKET(EDIT, VIDEO), - BUCKET_PICK_CUSTOM = INTENT_UMA_BUCKET(PICK, CUSTOM), - BUCKET_PICK_APPLICATION = INTENT_UMA_BUCKET(PICK, APPLICATION), - BUCKET_PICK_AUDIO = INTENT_UMA_BUCKET(PICK, AUDIO), - BUCKET_PICK_EXAMPLE = INTENT_UMA_BUCKET(PICK, EXAMPLE), - BUCKET_PICK_IMAGE = INTENT_UMA_BUCKET(PICK, IMAGE), - BUCKET_PICK_MESSAGE = INTENT_UMA_BUCKET(PICK, MESSAGE), - BUCKET_PICK_MODEL = INTENT_UMA_BUCKET(PICK, MODEL), - BUCKET_PICK_MULTIPART = INTENT_UMA_BUCKET(PICK, MULTIPART), - BUCKET_PICK_TEXT = INTENT_UMA_BUCKET(PICK, TEXT), - BUCKET_PICK_VIDEO = INTENT_UMA_BUCKET(PICK, VIDEO), - BUCKET_SAVE_CUSTOM = INTENT_UMA_BUCKET(SAVE, CUSTOM), - BUCKET_SAVE_APPLICATION = INTENT_UMA_BUCKET(SAVE, APPLICATION), - BUCKET_SAVE_AUDIO = INTENT_UMA_BUCKET(SAVE, AUDIO), - BUCKET_SAVE_EXAMPLE = INTENT_UMA_BUCKET(SAVE, EXAMPLE), - BUCKET_SAVE_IMAGE = INTENT_UMA_BUCKET(SAVE, IMAGE), - BUCKET_SAVE_MESSAGE = INTENT_UMA_BUCKET(SAVE, MESSAGE), - BUCKET_SAVE_MODEL = INTENT_UMA_BUCKET(SAVE, MODEL), - BUCKET_SAVE_MULTIPART = INTENT_UMA_BUCKET(SAVE, MULTIPART), - BUCKET_SAVE_TEXT = INTENT_UMA_BUCKET(SAVE, TEXT), - BUCKET_SAVE_VIDEO = INTENT_UMA_BUCKET(SAVE, VIDEO), - BUCKET_SHARE_CUSTOM = INTENT_UMA_BUCKET(SHARE, CUSTOM), - BUCKET_SHARE_APPLICATION = INTENT_UMA_BUCKET(SHARE, APPLICATION), - BUCKET_SHARE_AUDIO = INTENT_UMA_BUCKET(SHARE, AUDIO), - BUCKET_SHARE_EXAMPLE = INTENT_UMA_BUCKET(SHARE, EXAMPLE), - BUCKET_SHARE_IMAGE = INTENT_UMA_BUCKET(SHARE, IMAGE), - BUCKET_SHARE_MESSAGE = INTENT_UMA_BUCKET(SHARE, MESSAGE), - BUCKET_SHARE_MODEL = INTENT_UMA_BUCKET(SHARE, MODEL), - BUCKET_SHARE_MULTIPART = INTENT_UMA_BUCKET(SHARE, MULTIPART), - BUCKET_SHARE_TEXT = INTENT_UMA_BUCKET(SHARE, TEXT), - BUCKET_SHARE_VIDEO = INTENT_UMA_BUCKET(SHARE, VIDEO), - BUCKET_SUBSCRIBE_CUSTOM = INTENT_UMA_BUCKET(SUBSCRIBE, CUSTOM), - BUCKET_SUBSCRIBE_APPLICATION = INTENT_UMA_BUCKET(SUBSCRIBE, APPLICATION), - BUCKET_SUBSCRIBE_AUDIO = INTENT_UMA_BUCKET(SUBSCRIBE, AUDIO), - BUCKET_SUBSCRIBE_EXAMPLE = INTENT_UMA_BUCKET(SUBSCRIBE, EXAMPLE), - BUCKET_SUBSCRIBE_IMAGE = INTENT_UMA_BUCKET(SUBSCRIBE, IMAGE), - BUCKET_SUBSCRIBE_MESSAGE = INTENT_UMA_BUCKET(SUBSCRIBE, MESSAGE), - BUCKET_SUBSCRIBE_MODEL = INTENT_UMA_BUCKET(SUBSCRIBE, MODEL), - BUCKET_SUBSCRIBE_MULTIPART = INTENT_UMA_BUCKET(SUBSCRIBE, MULTIPART), - BUCKET_SUBSCRIBE_TEXT = INTENT_UMA_BUCKET(SUBSCRIBE, TEXT), - BUCKET_SUBSCRIBE_VIDEO = INTENT_UMA_BUCKET(SUBSCRIBE, VIDEO), - BUCKET_VIEW_CUSTOM = INTENT_UMA_BUCKET(VIEW, CUSTOM), - BUCKET_VIEW_APPLICATION = INTENT_UMA_BUCKET(VIEW, APPLICATION), - BUCKET_VIEW_AUDIO = INTENT_UMA_BUCKET(VIEW, AUDIO), - BUCKET_VIEW_EXAMPLE = INTENT_UMA_BUCKET(VIEW, EXAMPLE), - BUCKET_VIEW_IMAGE = INTENT_UMA_BUCKET(VIEW, IMAGE), - BUCKET_VIEW_MESSAGE = INTENT_UMA_BUCKET(VIEW, MESSAGE), - BUCKET_VIEW_MODEL = INTENT_UMA_BUCKET(VIEW, MODEL), - BUCKET_VIEW_MULTIPART = INTENT_UMA_BUCKET(VIEW, MULTIPART), - BUCKET_VIEW_TEXT = INTENT_UMA_BUCKET(VIEW, TEXT), - BUCKET_VIEW_VIDEO = INTENT_UMA_BUCKET(VIEW, VIDEO), -}; - -#undef INTENT_UMA_BUCKET - -UMABucket ToUMABucket(const string16& action, const string16& type); -void RecordIntentsDispatchDisabled(); -void RecordIntentDispatchRequested(); -void RecordIntentDispatched(const UMABucket bucket); - -// Records the fact that the picker was shown and records the -// number of services installed at the time the picker was shown -void RecordPickerShow(const UMABucket bucket, size_t installed); -void RecordPickerCancel(const UMABucket bucket); -void RecordServiceInvoke(const UMABucket bucket); -// Records the |duration| of time spent in the service. Uses |reply_type| to -// distinguish between failed and successful service usage. -void RecordServiceActiveDuration( - webkit_glue::WebIntentReplyType reply_type, - const base::TimeDelta& duration); -void RecordChooseAnotherService(const UMABucket bucket); -void RecordCWSExtensionInstalled(const UMABucket bucket); -} // namespace web_intents - -#endif // CHROME_BROWSER_INTENTS_WEB_INTENTS_REPORTING_H_ diff --git a/chrome/browser/intents/web_intents_reporting_unittest.cc b/chrome/browser/intents/web_intents_reporting_unittest.cc deleted file mode 100644 index 0bcb136..0000000 --- a/chrome/browser/intents/web_intents_reporting_unittest.cc +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) 2012 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/intents/web_intents_reporting.h" - -#include <vector> - -#include "base/metrics/histogram.h" -#include "base/metrics/statistics_recorder.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/intents/web_intents_util.h" -#include "chrome/browser/search_engines/search_engine_type.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace web_intents { -namespace reporting { -namespace { - -const char kCustomAction[] = "jiggle"; -const char kImageType[] = "image/png"; -const char kCustomType[] = "http://a.b/mine"; - -UMABucket ToBucket(const std::string& action, const std::string& type) { - return web_intents::ToUMABucket( - ASCIIToUTF16(action), ASCIIToUTF16(type)); -} - -} // namespace - -TEST(WebIntentsReportingTest, RecognizedActionAndType) { - EXPECT_EQ(BUCKET_SHARE_IMAGE, ToBucket(kActionShare, kImageType)); -} - -TEST(WebIntentsReportingTest, CustomAction) { - EXPECT_EQ(BUCKET_CUSTOM_IMAGE, ToBucket(kCustomAction, kImageType)); -} - -TEST(WebIntentsReportingTest, CustomType) { - EXPECT_EQ(BUCKET_EDIT_CUSTOM, ToBucket(kActionEdit, kCustomType)); -} - -TEST(WebIntentsReportingTest, CustomActionAndType) { - EXPECT_EQ(BUCKET_CUSTOM_CUSTOM, ToBucket(kCustomAction, kCustomType)); -} - -} // namespace reporting -} // namespace web_intents diff --git a/chrome/browser/intents/web_intents_util.cc b/chrome/browser/intents/web_intents_util.cc deleted file mode 100644 index 0624a10..0000000 --- a/chrome/browser/intents/web_intents_util.cc +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright (c) 2012 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/intents/web_intents_util.h" - -#include "base/command_line.h" -#include "base/string_util.h" -#include "base/utf_string_conversions.h" -#include "chrome/browser/prefs/pref_registry_syncable.h" -#include "chrome/browser/prefs/pref_service.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/browser/ui/browser_finder.h" -#include "chrome/browser/ui/host_desktop.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/common/pref_names.h" -#include "chrome/common/url_constants.h" -#include "content/public/common/content_switches.h" -#include "net/base/mime_util.h" - -namespace web_intents { -namespace { - -struct ActionMapping { - const char* name; - const ActionId id; -}; - -const ActionMapping kActionMap[] = { - { kActionEdit, ACTION_ID_EDIT }, - { kActionPick, ACTION_ID_PICK }, - { kActionSave, ACTION_ID_SAVE }, - { kActionShare, ACTION_ID_SHARE}, - { kActionSubscribe, ACTION_ID_SUBSCRIBE }, - { kActionView, ACTION_ID_VIEW }, -}; - -// Returns the ActionMapping for |action| if one exists, or NULL. -const ActionMapping* FindActionMapping(const string16& action) { - for (size_t i = 0; i < arraysize(kActionMap); ++i) { - if (EqualsASCII(action, kActionMap[i].name)) { - return &kActionMap[i]; - } - } - return NULL; -} - -} // namespace - -const char kActionEdit[] = "http://webintents.org/edit"; -const char kActionPick[] = "http://webintents.org/pick"; -const char kActionSave[] = "http://webintents.org/save"; -const char kActionShare[] = "http://webintents.org/share"; -const char kActionSubscribe[] = "http://webintents.org/subscribe"; -const char kActionView[] = "http://webintents.org/view"; -const char kActionCrosEcho[] = "https://crosecho.com/startEcho"; -const char kQuickOfficeViewerServiceURL[] = - "chrome-extension://gbkeegbaiigmenfmjfclcdgdpimamgkj/views/appViewer.html"; -const char kQuickOfficeViewerDevServiceURL[] = - "chrome-extension://ionpfmkccalenbmnddpbmocokhaknphg/views/appEditor.html"; - -void RegisterUserPrefs(PrefRegistrySyncable* registry) { - registry->RegisterBooleanPref(prefs::kWebIntentsEnabled, true, - PrefRegistrySyncable::SYNCABLE_PREF); -} - -bool IsWebIntentsEnabled(PrefService* prefs) { - return CommandLine::ForCurrentProcess()->HasSwitch( - switches::kWebIntentsInvocationEnabled); -} - -bool IsWebIntentsEnabledForProfile(Profile* profile) { - return IsWebIntentsEnabled(profile->GetPrefs()); -} - -Browser* GetBrowserForBackgroundWebIntentDelivery(Profile* profile) { - Browser* browser = chrome::FindLastActiveWithHostDesktopType( - chrome::GetActiveDesktop()); - if (browser && profile && browser->profile() != profile) - return NULL; - return browser; -} - -bool IsRecognizedAction(const string16& action) { - const ActionMapping* mapping = FindActionMapping(action); - return mapping != NULL; -} - -ActionId ToActionId(const string16& action) { - const ActionMapping* mapping = FindActionMapping(action); - return mapping != NULL ? mapping->id : ACTION_ID_CUSTOM; -} - -bool MimeTypesMatch(const string16& type1, const string16& type2) { - // We don't have a MIME matcher that allows patterns on both sides - // Instead, we do two comparisons, treating each type in turn as a - // pattern. If either one matches, we consider this a MIME match. - std::string t1 = UTF16ToUTF8(type1); - std::string t2 = UTF16ToUTF8(type2); - - // If either side is _all_ wildcard, it's a match! - if (t1 == "*" || t1 == "*/*" || t2 == "*" || t2 == "*/*") - return true; - - StringToLowerASCII(&t1); - StringToLowerASCII(&t2); - return (net::MatchesMimeType(t1, t2)) || net::MatchesMimeType(t2, t1); -} - -} // namespace web_intents diff --git a/chrome/browser/intents/web_intents_util.h b/chrome/browser/intents/web_intents_util.h deleted file mode 100644 index 2dfa99f..0000000 --- a/chrome/browser/intents/web_intents_util.h +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (c) 2012 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_INTENTS_WEB_INTENTS_UTIL_H_ -#define CHROME_BROWSER_INTENTS_WEB_INTENTS_UTIL_H_ - -#include "base/string16.h" - -class Browser; -class Profile; -class PrefService; -class PrefRegistrySyncable; - -namespace web_intents { - -enum ActionId { - ACTION_ID_CUSTOM = 1, // for all unrecognized types - ACTION_ID_EDIT, - ACTION_ID_PICK, - ACTION_ID_SAVE, - ACTION_ID_SHARE, - ACTION_ID_SUBSCRIBE, - ACTION_ID_VIEW, -}; - -// "Recognized" action strings. These are basically the -// actions we're reporting via UMA. -extern const char kActionEdit[]; -extern const char kActionPick[]; -extern const char kActionSave[]; -extern const char kActionShare[]; -extern const char kActionSubscribe[]; -extern const char kActionView[]; -extern const char kActionCrosEcho[]; - -extern const char kQuickOfficeViewerServiceURL[]; -extern const char kQuickOfficeViewerDevServiceURL[]; - -// Registers the preferences related to Web Intents. -void RegisterUserPrefs(PrefRegistrySyncable* registry); - -// Returns true if WebIntents are enabled in preferences. -bool IsWebIntentsEnabled(PrefService* prefs); - -// Returns true if WebIntents are enabled due to various factors. |profile| is -// the Profile to check that WebIntents are enabled for. -bool IsWebIntentsEnabledForProfile(Profile* profile); - -// In a context where we are generating a web intent based on internal events, -// or from an extension background page, get the browser in which to show the -// intent picker to the user. -Browser* GetBrowserForBackgroundWebIntentDelivery(Profile* profile); - -// Returns the recognized action (the one described at -// webintents.org) or an empty string if the action is not recognized. -bool IsRecognizedAction(const string16& action); - -// Returns the action::Id corresponding to |action| or ACTION_ID_CUSTOM -// if |action| is not recognized. -ActionId ToActionId(const string16& action); - -// Returns true if |type1| and |type2| "match". Supports wild cards in both -// |type1| and |type2|. Wild cards are of the form '<type>/*', '*/*', and '*'. -bool MimeTypesMatch(const string16& type1, const string16& type2); - -} // namespace web_intents - -#endif // CHROME_BROWSER_INTENTS_WEB_INTENTS_UTIL_H_ diff --git a/chrome/browser/intents/web_intents_util_stub.cc b/chrome/browser/intents/web_intents_util_stub.cc deleted file mode 100644 index f51fb3a..0000000 --- a/chrome/browser/intents/web_intents_util_stub.cc +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2012 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. - -// Stub implementation of web_intents_util.h to be included in builds -// where ENABLE_WEB_INTENTS is not defined. - -#include "chrome/browser/intents/web_intents_util.h" - -namespace web_intents { - -const char kActionView[] = "http://webintents.org/view"; - -bool IsWebIntentsEnabled(PrefService* prefs) { - return false; -} - -bool IsWebIntentsEnabledForProfile(Profile* profile) { - return false; -} - -Browser* GetBrowserForBackgroundWebIntentDelivery(Profile* profile) { - return NULL; -} - -} // namespace web_intents diff --git a/chrome/browser/intents/web_intents_util_unittest.cc b/chrome/browser/intents/web_intents_util_unittest.cc deleted file mode 100644 index 931204b..0000000 --- a/chrome/browser/intents/web_intents_util_unittest.cc +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright (c) 2012 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/intents/web_intents_util.h" - -#include <string> - -#include "base/utf_string_conversions.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace web_intents { -namespace { - -bool IsRecognized(const std::string& value) { - return web_intents::IsRecognizedAction(ASCIIToUTF16(value)); -} - -ActionId ToAction(const std::string& value) { - return web_intents::ToActionId(ASCIIToUTF16(value)); -} - -bool TypesMatch(const std::string& a, const std::string& b) { - return MimeTypesMatch(ASCIIToUTF16(a), ASCIIToUTF16(b)); -} - -} // namespace - -TEST(WebIntentsUtilTest, IsRecognizedAction) { - EXPECT_TRUE(IsRecognized(kActionEdit)); - EXPECT_FALSE(IsRecognized("http://webintents.org/eDit")); // case matters - EXPECT_TRUE(IsRecognized(kActionPick)); - EXPECT_TRUE(IsRecognized(kActionSave)); - EXPECT_TRUE(IsRecognized(kActionShare)); - EXPECT_TRUE(IsRecognized(kActionSubscribe)); - EXPECT_TRUE(IsRecognized(kActionView)); -} - -TEST(WebIntentsUtilTest, IsRecognizedActionFailure) { - EXPECT_FALSE(IsRecognized(std::string(kActionPick) + "lezooka")); - EXPECT_FALSE(IsRecognized("Chrome LAX")); - EXPECT_FALSE(IsRecognized("_zoom ")); - EXPECT_FALSE(IsRecognized(" ")); - EXPECT_FALSE(IsRecognized("")); -} - -TEST(WebIntentsUtilTest, ToActionId) { - EXPECT_EQ(ACTION_ID_EDIT, ToAction(kActionEdit)); - EXPECT_EQ(ACTION_ID_PICK, ToAction(kActionPick)); - EXPECT_EQ(ACTION_ID_SAVE, ToAction(kActionSave)); - EXPECT_EQ(ACTION_ID_SHARE, ToAction(kActionShare)); - EXPECT_EQ(ACTION_ID_SUBSCRIBE, ToAction(kActionSubscribe)); - EXPECT_EQ(ACTION_ID_VIEW, ToAction(kActionView)); -} - -TEST(WebIntentsUtilTest, MimeTypesMatchLiteral) { - EXPECT_TRUE(TypesMatch("image/png", "image/png")); - - EXPECT_FALSE(TypesMatch(" image/png", "image/png")); - EXPECT_FALSE(TypesMatch("image/png", " image/png")); - EXPECT_FALSE(TypesMatch("image/png ", "image/png")); - EXPECT_FALSE(TypesMatch("image/png", "image/png ")); - EXPECT_FALSE(TypesMatch("image/jpg", "image/png")); - EXPECT_FALSE(TypesMatch("image/png", "image/jpg")); -} - -TEST(WebIntentsUtilTest, MimeTypesMatchWildCards) { - EXPECT_TRUE(TypesMatch("*", "*")); - EXPECT_TRUE(TypesMatch("*", "*/*")); - EXPECT_TRUE(TypesMatch("*/*", "*")); - EXPECT_TRUE(TypesMatch("*/*", "*/*")); - EXPECT_TRUE(TypesMatch("*", "image/png")); - EXPECT_TRUE(TypesMatch("image/png", "*")); - EXPECT_TRUE(TypesMatch("*/*", "image/png")); - EXPECT_TRUE(TypesMatch("image/png", "*/*")); - - EXPECT_FALSE(TypesMatch(" */*", "image/png")); - EXPECT_FALSE(TypesMatch("*/* ", "image/png")); - EXPECT_FALSE(TypesMatch("**", "image/png")); -} - -TEST(WebIntentsUtilTest, MimeTypesMatchParameters) { - EXPECT_TRUE(TypesMatch("*", "video/*;single=true")); - EXPECT_TRUE(TypesMatch("*/*", "video/mpg;single=true")); - EXPECT_TRUE(TypesMatch("video/*", "video/mpg;single=true")); - EXPECT_TRUE(TypesMatch("video/mpg", "video/mpg;single=true")); - EXPECT_TRUE(TypesMatch("video/mpg;single=true", "video/mpg;single=true")); - EXPECT_TRUE(TypesMatch("video/mpg;a=b;single=true", - "video/mpg;single=true;a=b")); - EXPECT_FALSE(TypesMatch("video/mpg;a=b;single=true", - "video/mpg;single=false;a=b")); - EXPECT_FALSE(TypesMatch("video/mpg;single=true", "video/mpg;single=false")); -} - -} // namepsace web_intents |