Home | History | Annotate | Download | only in webui
      1 // Copyright (c) 2011 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 CHROME_BROWSER_UI_WEBUI_TEXTFIELDS_UI_H_
      6 #define CHROME_BROWSER_UI_WEBUI_TEXTFIELDS_UI_H_
      7 #pragma once
      8 
      9 #include <string>
     10 
     11 #include "chrome/browser/ui/webui/chrome_url_data_manager.h"
     12 #include "content/browser/webui/web_ui.h"
     13 
     14 class RefCountedMemory;
     15 
     16 /**
     17  * ChromeURLDataManager::DataSource implementation that asynchronously answers
     18  * requests for chrome://textfields URL. On receiving a request, this object
     19  * reads the html from the local resource textfields.html and sends back the
     20  * response.
     21  */
     22 class TextfieldsUIHTMLSource : public ChromeURLDataManager::DataSource {
     23  public:
     24   TextfieldsUIHTMLSource();
     25 
     26   // Called when the network layer has requested a resource underneath
     27   // the path we registered.
     28   virtual void StartDataRequest(const std::string& path,
     29                                 bool is_incognito,
     30                                 int request_id);
     31   virtual std::string GetMimeType(const std::string& path) const;
     32 
     33  private:
     34   virtual ~TextfieldsUIHTMLSource();
     35 
     36   DISALLOW_COPY_AND_ASSIGN(TextfieldsUIHTMLSource);
     37 };
     38 
     39 /**
     40  * Handler for JavaScript calls from the DOM.
     41  */
     42 class TextfieldsDOMHandler : public WebUIMessageHandler {
     43  public:
     44   TextfieldsDOMHandler();
     45 
     46   // Handles the "textfieldValue" call from the JavaScript. This call
     47   // synchonizes the value inside the JavaScript textfield with the copy in the
     48   // DOM object.
     49   virtual void HandleTextfieldValue(const ListValue* args);
     50 
     51  protected:
     52   virtual void RegisterMessages();
     53 
     54  private:
     55   DISALLOW_COPY_AND_ASSIGN(TextfieldsDOMHandler);
     56 };
     57 
     58 class TextfieldsUI : public WebUI {
     59  public:
     60   explicit TextfieldsUI(TabContents* contents);
     61 
     62   const std::wstring& text() const { return text_; }
     63   void set_text(const std::wstring& text) { text_ = text; }
     64 
     65  private:
     66   std::wstring text_;
     67 
     68   DISALLOW_COPY_AND_ASSIGN(TextfieldsUI);
     69 };
     70 
     71 #endif  // CHROME_BROWSER_UI_WEBUI_TEXTFIELDS_UI_H_
     72