Logo Search packages:      
Sourcecode: chromium-browser version File versions  Download package


// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.


#include <string>

#include "chrome/browser/content_setting_combo_model.h"
#include "chrome/browser/host_content_settings_map.h"
#include "chrome/common/content_settings.h"
#include "chrome/common/content_settings_types.h"
#include "views/window/dialog_delegate.h"
#include "views/controls/combobox/combobox.h"
#include "views/controls/textfield/textfield.h"

namespace views {
class ImageView;
class Label;

class ContentExceptionsTableModel;

// ExceptionEditorView is responsible for showing a dialog that allows the user
// to create or edit a single content exception. If the user clicks ok the
// delegate is notified and completes the edit.
// To use an ExceptionEditorView create one and invoke Show on it.
// ExceptionEditorView is deleted when the dialog closes.
class ExceptionEditorView : public views::View,
                            public views::Textfield::Controller,
                            public views::DialogDelegate {
  class Delegate {
    // Invoked when the user accepts the edit.
    virtual void AcceptExceptionEdit(
        const HostContentSettingsMap::Pattern& pattern,
        ContentSetting setting,
        int index,
        bool is_new) = 0;

    virtual ~Delegate() {}

  // Creates a new ExceptionEditorView with the supplied args. |index| is the
  // index into the ContentExceptionsTableModel of the exception. This is not
  // used by ExceptionEditorView but instead passed to the delegate.
  ExceptionEditorView(Delegate* delegate,
                      ContentExceptionsTableModel* model,
                      int index,
                      const HostContentSettingsMap::Pattern& pattern,
                      ContentSetting setting);
  virtual ~ExceptionEditorView() {}

  void Show(gfx::NativeWindow parent);

  // views::DialogDelegate overrides.
  virtual bool IsModal() const;
  virtual std::wstring GetWindowTitle() const;
  virtual bool IsDialogButtonEnabled(
      MessageBoxFlags::DialogButton button) const;
  virtual bool Cancel();
  virtual bool Accept();
  virtual views::View* GetContentsView();

  // views::Textfield::Controller overrides. Updates whether the user can
  // accept the dialog as well as updating image views showing whether value is
  // valid.
  virtual void ContentsChanged(views::Textfield* sender,
                               const std::wstring& new_contents);
  virtual bool HandleKeystroke(views::Textfield* sender,
                               const views::Textfield::Keystroke& key);

  void Init();

  views::Label* CreateLabel(int message_id);

  // Returns true if we're adding a new item.
  bool is_new() const { return index_ == -1; }

  bool IsPatternValid(const HostContentSettingsMap::Pattern& pattern) const;

  void UpdateImageView(views::ImageView* image_view, bool is_valid);

  Delegate* delegate_;
  ContentExceptionsTableModel* model_;
  ContentSettingComboModel cb_model_;

  // Index of the item being edited. If -1, indices this is a new entry.
  const int index_;
  const HostContentSettingsMap::Pattern pattern_;
  const ContentSetting setting_;

  views::Textfield* pattern_tf_;
  views::ImageView* pattern_iv_;
  views::Combobox* action_cb_;



Generated by  Doxygen 1.6.0   Back to index