Home | History | Annotate | Download | only in views
      1 // Copyright (c) 2010 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_VIEWS_COOKIE_INFO_VIEW_H_
      6 #define CHROME_BROWSER_UI_VIEWS_COOKIE_INFO_VIEW_H_
      7 #pragma once
      8 
      9 #include <string>
     10 #include <vector>
     11 
     12 #include "base/string16.h"
     13 #include "net/base/cookie_monster.h"
     14 #include "ui/base/models/combobox_model.h"
     15 #include "views/controls/combobox/combobox.h"
     16 #include "views/view.h"
     17 
     18 namespace views {
     19 class GridLayout;
     20 class Label;
     21 class NativeButton;
     22 class Textfield;
     23 }
     24 
     25 
     26 ///////////////////////////////////////////////////////////////////////////////
     27 // CookieInfoViewDelegate
     28 //
     29 class CookieInfoViewDelegate {
     30  public:
     31   virtual void ModifyExpireDate(bool session_expire) = 0;
     32 
     33  protected:
     34   virtual ~CookieInfoViewDelegate() {}
     35 };
     36 
     37 ///////////////////////////////////////////////////////////////////////////////
     38 // CookieInfoView
     39 //
     40 //  Responsible for displaying a tabular grid of Cookie information.
     41 class CookieInfoView : public views::View,
     42                        public views::Combobox::Listener,
     43                        public ui::ComboboxModel {
     44  public:
     45   explicit CookieInfoView(bool editable_expiration_date);
     46   virtual ~CookieInfoView();
     47 
     48   // Update the display from the specified CookieNode.
     49   void SetCookie(const std::string& domain,
     50                  const net::CookieMonster::CanonicalCookie& cookie_node);
     51 
     52   // Update the display from the specified cookie string.
     53   void SetCookieString(const GURL& url, const std::string& cookie_line);
     54 
     55   // Clears the cookie display to indicate that no or multiple cookies are
     56   // selected.
     57   void ClearCookieDisplay();
     58 
     59   // Enables or disables the cookie property text fields.
     60   void EnableCookieDisplay(bool enabled);
     61 
     62   void set_delegate(CookieInfoViewDelegate* delegate) { delegate_ = delegate; }
     63 
     64  protected:
     65   // views::View overrides:
     66   virtual void ViewHierarchyChanged(bool is_add,
     67                                     views::View* parent,
     68                                     views::View* child);
     69 
     70   // views::Combobox::Listener override.
     71   virtual void ItemChanged(views::Combobox* combo_box,
     72                            int prev_index,
     73                            int new_index);
     74 
     75   // ui::ComboboxModel overrides for expires_value_combobox_.
     76   virtual int GetItemCount();
     77   virtual string16 GetItemAt(int index);
     78 
     79  private:
     80   // Layout helper routines.
     81   void AddLabelRow(int layout_id, views::GridLayout* layout,
     82                    views::View* label, views::View* value);
     83   void AddControlRow(int layout_id, views::GridLayout* layout,
     84                      views::View* label, views::View* control);
     85 
     86   // Sets up the view layout.
     87   void Init();
     88 
     89   // Individual property labels
     90   views::Label* name_label_;
     91   views::Textfield* name_value_field_;
     92   views::Label* content_label_;
     93   views::Textfield* content_value_field_;
     94   views::Label* domain_label_;
     95   views::Textfield* domain_value_field_;
     96   views::Label* path_label_;
     97   views::Textfield* path_value_field_;
     98   views::Label* send_for_label_;
     99   views::Textfield* send_for_value_field_;
    100   views::Label* created_label_;
    101   views::Textfield* created_value_field_;
    102   views::Label* expires_label_;
    103   views::Textfield* expires_value_field_;
    104   views::Combobox* expires_value_combobox_;
    105   views::View* expire_view_;
    106 
    107   // Option values for expires_value_combobox_.
    108   std::vector<std::wstring> expire_combo_values_;
    109 
    110   // True if expiration date can be edited. In this case we will show
    111   // expires_value_combobox_ instead of expires_value_field_. The cookie's
    112   // expiration date is editable only this class is used in
    113   // CookiesPromptView (alert before cookie is set), in all other cases we
    114   // don't let user directly change cookie setting.
    115   bool editable_expiration_date_;
    116 
    117   CookieInfoViewDelegate* delegate_;
    118 
    119   DISALLOW_COPY_AND_ASSIGN(CookieInfoView);
    120 };
    121 
    122 #endif  // CHROME_BROWSER_UI_VIEWS_COOKIE_INFO_VIEW_H_
    123 
    124