Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / webui / ntp / android / promo_handler.h
blob33a7e9fb7a900349d345b65acc3d3588c23b0d08
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_UI_WEBUI_NTP_ANDROID_PROMO_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_NTP_ANDROID_PROMO_HANDLER_H_
8 #include "content/public/browser/notification_observer.h"
9 #include "content/public/browser/notification_registrar.h"
10 #include "content/public/browser/web_ui_message_handler.h"
12 namespace base {
13 class DictionaryValue;
14 class ListValue;
17 namespace user_prefs {
18 class PrefRegistrySyncable;
21 // The handler for JavaScript messages related to the Android NTP promo.
22 class PromoHandler : public content::WebUIMessageHandler,
23 public content::NotificationObserver {
24 public:
25 PromoHandler();
26 virtual ~PromoHandler();
28 // WebUIMessageHandler implementation.
29 virtual void RegisterMessages() OVERRIDE;
31 // Register preferences.
32 static void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry);
34 private:
35 // NotificationObserver override and implementation.
36 virtual void Observe(int type,
37 const content::NotificationSource& source,
38 const content::NotificationDetails& details) OVERRIDE;
40 // Callback for the "promoSendEmail" message.
41 // |args| is a list [ subject, body, app-chooser-message ].
42 void HandlePromoSendEmail(const base::ListValue* args);
44 // Callback for the "promoActionTriggered" message.
45 // No arguments.
46 void HandlePromoActionTriggered(const base::ListValue* args);
48 // Callback for the "promoDisabled" message.
49 // No arguments.
50 void HandlePromoDisabled(const base::ListValue* args);
52 // Callback for the "getPromotions" message.
53 // No arguments.
54 void HandleGetPromotions(const base::ListValue* args);
56 // Callback for the "recordImpression" message.
57 // |args| is a list with a name of a page to record an impression from.
58 void HandleRecordImpression(const base::ListValue* args);
60 // Gathers the promotion information and updates the page.
61 void InjectPromoDecorations();
63 // Records an impression; could trigger a refresh if max_views are exceeded.
64 void RecordPromotionImpression(const std::string& id);
66 // Fetches the active promotion and defines what should be passed to JS.
67 // Returns true if the promotion should be shown and the |result| is ready.
68 bool FetchPromotion(base::DictionaryValue* result);
70 // Returns true if the Chrome Promo is allowed.
71 bool DoesChromePromoMatchCurrentSync(
72 bool promo_requires_sync,
73 bool promo_requires_no_active_desktop_sync_sessions);
75 // Updates the profile preference if any desktop session was discovered.
76 void CheckDesktopSessions();
78 // Registrar to receive notification on promo changes.
79 content::NotificationRegistrar registrar_;
81 DISALLOW_COPY_AND_ASSIGN(PromoHandler);
84 #endif // CHROME_BROWSER_UI_WEBUI_NTP_ANDROID_PROMO_HANDLER_H_