1 // Copyright (c) 2012 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.
5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_EXTENSION_APP_PROVIDER_H_
6 #define CHROME_BROWSER_AUTOCOMPLETE_EXTENSION_APP_PROVIDER_H_
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "base/gtest_prod_util.h"
13 #include "chrome/browser/autocomplete/autocomplete_input.h"
14 #include "chrome/browser/autocomplete/autocomplete_match.h"
15 #include "chrome/browser/autocomplete/autocomplete_provider.h"
16 #include "components/metrics/proto/omnibox_input_type.pb.h"
17 #include "content/public/browser/notification_observer.h"
18 #include "content/public/browser/notification_registrar.h"
19 #include "ui/base/window_open_disposition.h"
21 // This provider is responsible for keeping track of which Extension Apps are
22 // installed and their URLs. An instance of it gets created and managed by
23 // AutocompleteController.
24 class ExtensionAppProvider : public AutocompleteProvider,
25 public content::NotificationObserver {
27 ExtensionAppProvider(AutocompleteProviderListener* listener,
30 // AutocompleteProvider:
31 virtual void Start(const AutocompleteInput& input,
32 bool minimal_changes) OVERRIDE;
34 // Launch an Extension App from |match| details provided by the Omnibox. If
35 // the application wants to launch as a window or panel, |disposition| is
36 // ignored; otherwise it's used to determine in which tab we'll launch the
38 static void LaunchAppFromOmnibox(const AutocompleteMatch& match,
40 WindowOpenDisposition disposition);
43 friend class ExtensionAppProviderTest;
44 FRIEND_TEST_ALL_PREFIXES(ExtensionAppProviderTest, CreateMatchSanitize);
46 // ExtensionApp stores the minimal metadata that we need to match against
51 // App's launch URL (for platform apps, which don't have a launch URL, this
52 // just points to the app's origin).
53 base::string16 launch_url;
54 // If false, then the launch_url will not be considered for matching,
55 // not shown next to the match, and not displayed as the editable text if
56 // the user selects the match with the arrow keys.
57 bool should_match_against_launch_url;
59 typedef std::vector<ExtensionApp> ExtensionApps;
61 virtual ~ExtensionAppProvider();
63 void AddExtensionAppForTesting(const ExtensionApp& extension_app);
65 // Construct a match for the specified parameters.
66 AutocompleteMatch CreateAutocompleteMatch(const AutocompleteInput& input,
67 const ExtensionApp& app,
68 size_t name_match_index,
69 size_t url_match_index);
71 // Fetch the current app list and cache it locally.
72 void RefreshAppList();
74 // Calculate the relevance of the match.
75 int CalculateRelevance(metrics::OmniboxInputType::Type type,
80 // content::NotificationObserver implementation:
81 virtual void Observe(int type,
82 const content::NotificationSource& source,
83 const content::NotificationDetails& details) OVERRIDE;
85 content::NotificationRegistrar registrar_;
87 // Our cache of ExtensionApp objects (name + url) representing the extension
88 // apps we know/care about.
89 ExtensionApps extension_apps_;
91 DISALLOW_COPY_AND_ASSIGN(ExtensionAppProvider);
94 #endif // CHROME_BROWSER_AUTOCOMPLETE_EXTENSION_APP_PROVIDER_H_