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.
5 #ifndef COMPONENTS_DOM_DISTILLER_WEBUI_DOM_DISTILLER_HANDLER_H_
6 #define COMPONENTS_DOM_DISTILLER_WEBUI_DOM_DISTILLER_HANDLER_H_
10 #include "base/memory/weak_ptr.h"
11 #include "base/values.h"
12 #include "content/public/browser/web_ui_message_handler.h"
14 namespace dom_distiller
{
16 class DomDistillerService
;
18 // Handler class for DOM Distiller list operations.
19 class DomDistillerHandler
: public content::WebUIMessageHandler
{
21 // The lifetime of |service| has to outlive this handler.
22 DomDistillerHandler(DomDistillerService
* service
, const std::string
& scheme
);
23 ~DomDistillerHandler() override
;
25 // content::WebUIMessageHandler implementation.
26 void RegisterMessages() override
;
28 // Callback from JavaScript for the "requestEntries" message. This
29 // requests the list of entries and returns it to the front end by calling
30 // "onReceivedEntries". There are no JavaScript arguments to this method.
31 void HandleRequestEntries(const base::ListValue
* args
);
33 // Callback from JavaScript for when an article should be added. The first
34 // element in |args| should be a string representing the URL to be added.
35 void HandleAddArticle(const base::ListValue
* args
);
37 // Callback from JavaScript for when an article is selected. The first element
38 // in |args| should be a string representing the ID of the entry to be
40 void HandleSelectArticle(const base::ListValue
* args
);
42 // Callback from JavaScript for when viewing a URL is requested. The first
43 // element in |args| should be a string representing the URL to be viewed.
44 void HandleViewUrl(const base::ListValue
* args
);
47 // Callback from DomDistillerService when an article is available.
48 void OnArticleAdded(bool article_available
);
50 // The DomDistillerService.
51 DomDistillerService
* service_
;
53 // The scheme for DOM distiller articles.
54 std::string article_scheme_
;
56 // Factory for the creating refs in callbacks.
57 base::WeakPtrFactory
<DomDistillerHandler
> weak_ptr_factory_
;
59 DISALLOW_COPY_AND_ASSIGN(DomDistillerHandler
);
62 } // namespace dom_distiller
64 #endif // COMPONENTS_DOM_DISTILLER_WEBUI_DOM_DISTILLER_HANDLER_H_