1// Copyright 2013 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef EXTENSIONS_COMMON_EXTENSION_URLS_H_
6#define EXTENSIONS_COMMON_EXTENSION_URLS_H_
7
8#include <string>
9
10#include "base/strings/string16.h"
11#include "base/strings/string_piece.h"
12#include "url/gurl.h"
13
14namespace url {
15class Origin;
16}
17
18namespace extensions {
19
20// The name of the event_bindings module.
21extern const char kEventBindings[];
22
23// The name of the schemaUtils module.
24extern const char kSchemaUtils[];
25
26// Determine whether or not a source came from an extension. |source| can link
27// to a page or a script, and can be external (e.g., "http://www.google.com"),
28// extension-related (e.g., "chrome-extension://<extension_id>/background.js"),
29// or internal (e.g., "event_bindings" or "schemaUtils").
30bool IsSourceFromAnExtension(const base::string16& source);
31
32} // namespace extensions
33
34namespace extension_urls {
35
36// Canonical URLs for the Chrome Webstore. You probably want to use one of
37// the calls below rather than using one of these constants directly, since
38// the active extensions embedder may provide its own webstore URLs.
39extern const char kChromeWebstoreBaseURL[];
40extern const char kChromeWebstoreUpdateURL[];
41
42// Returns the URL prefix for the extension/apps gallery. Can be set via the
43// --apps-gallery-url switch. The URL returned will not contain a trailing
44// slash. Do not use this as a prefix/extent for the store.
45GURL GetWebstoreLaunchURL();
46
47// Returns the URL to the extensions category on the Web Store. This is
48// derived from GetWebstoreLaunchURL().
49std::string GetWebstoreExtensionsCategoryURL();
50
51// Returns the URL prefix for an item in the extension/app gallery. This URL
52// will contain a trailing slash and should be concatenated with an item ID
53// to get the item detail URL.
54std::string GetWebstoreItemDetailURLPrefix();
55
56// Returns the URL used to get webstore data (ratings, manifest, icon URL,
57// etc.) about an extension from the webstore as JSON.
58GURL GetWebstoreItemJsonDataURL(const std::string& extension_id);
59
60// Returns the URL used to get webstore search results in JSON format. The URL
61// returns a JSON dictionary that has the search results (under "results").
62// Each entry in the array is a dictionary as the data returned for
63// GetWebstoreItemJsonDataURL above. |query| is the user typed query string.
64// |host_language_code| is the host language code, e.g. en_US. Both arguments
65// will be escaped and added as a query parameter to the returned web store
66// json search URL.
67GURL GetWebstoreJsonSearchUrl(const std::string& query,
68 const std::string& host_language_code);
69
70// Returns the URL of the web store search results page for |query|.
71GURL GetWebstoreSearchPageUrl(const std::string& query);
72
73// Returns the compile-time constant webstore update url specific to
74// Chrome. Usually you should prefer using GetWebstoreUpdateUrl.
75GURL GetDefaultWebstoreUpdateUrl();
76
77// Return the update URL used by gallery/webstore extensions/apps. This may
78// have been overridden by a command line flag for testing purposes.
79GURL GetWebstoreUpdateUrl();
80
81// Returns the url to visit to report abuse for the given |extension_id|
82// and |referrer_id|.
83GURL GetWebstoreReportAbuseUrl(const std::string& extension_id,
84 const std::string& referrer_id);
85
86// Returns whether the URL is the webstore update URL (just considering host
87// and path, not scheme, query, etc.)
88bool IsWebstoreUpdateUrl(const GURL& update_url);
89
90// Returns true if the URL points to an extension blacklist.
91bool IsBlacklistUpdateUrl(const GURL& url);
92
93// Returns true if the origin points to an URL used for safebrowsing.
94// TODO(devlin): Update other methods to also take an url::Origin?
95bool IsSafeBrowsingUrl(const url::Origin& origin, base::StringPiece path);
96
97} // namespace extension_urls
98
99#endif // EXTENSIONS_COMMON_EXTENSION_URLS_H_
100