1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
// Copyright (c) 2011 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.
#ifndef CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_IMAGE_MODEL_H_
#define CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_IMAGE_MODEL_H_
#include "base/macros.h"
#include "base/strings/string16.h"
#include "build/build_config.h"
#include "chrome/browser/ui/content_settings/content_setting_bubble_model.h"
#include "chrome/browser/ui/content_settings/content_setting_bubble_model_delegate.h"
#include "components/content_settings/core/common/content_settings_types.h"
#include "ui/gfx/image/image.h"
namespace content {
class WebContents;
}
namespace gfx {
enum class VectorIconId;
}
// This model provides data (icon ids and tooltip) for the content setting icons
// that are displayed in the location bar.
class ContentSettingImageModel {
public:
virtual ~ContentSettingImageModel() {}
// Generates a vector of all image models to be used within one window.
static std::vector<std::unique_ptr<ContentSettingImageModel>>
GenerateContentSettingImageModels();
// Notifies this model that its setting might have changed and it may need to
// update its visibility, icon and tooltip.
virtual void UpdateFromWebContents(content::WebContents* web_contents) = 0;
// Creates the model for the bubble that will be attached to this image.
// The bubble model is owned by the caller.
virtual ContentSettingBubbleModel* CreateBubbleModel(
ContentSettingBubbleModel::Delegate* delegate,
content::WebContents* web_contents,
Profile* profile) = 0;
// Whether the animation should be run for the given |web_contents|.
virtual bool ShouldRunAnimation(content::WebContents* web_contents) = 0;
// Remembers that the animation has already run for the given |web_contents|,
// so that we do not restart it when the parent view is updated.
virtual void SetAnimationHasRun(content::WebContents* web_contents) = 0;
bool is_visible() const { return is_visible_; }
#if defined(OS_MACOSX)
// Calls UpdateFromWebContents() and returns true if the icon has changed.
bool UpdateFromWebContentsAndCheckIfIconChanged(
content::WebContents* web_contents);
#endif
gfx::Image GetIcon(SkColor nearby_text_color) const;
// Returns the resource ID of a string to show when the icon appears, or 0 if
// we don't wish to show anything.
int explanatory_string_id() const { return explanatory_string_id_; }
const base::string16& get_tooltip() const { return tooltip_; }
protected:
ContentSettingImageModel();
void set_icon_by_vector_id(gfx::VectorIconId id, gfx::VectorIconId badge_id) {
icon_id_ = id;
icon_badge_id_ = badge_id;
}
void set_visible(bool visible) { is_visible_ = visible; }
void set_explanatory_string_id(int text_id) {
explanatory_string_id_ = text_id;
}
void set_tooltip(const base::string16& tooltip) { tooltip_ = tooltip; }
private:
bool is_visible_;
gfx::VectorIconId icon_id_;
gfx::VectorIconId icon_badge_id_;
int explanatory_string_id_;
base::string16 tooltip_;
DISALLOW_COPY_AND_ASSIGN(ContentSettingImageModel);
};
// A subclass for an image model tied to a single content type.
class ContentSettingSimpleImageModel : public ContentSettingImageModel {
public:
explicit ContentSettingSimpleImageModel(ContentSettingsType content_type);
// ContentSettingImageModel implementation.
ContentSettingBubbleModel* CreateBubbleModel(
ContentSettingBubbleModel::Delegate* delegate,
content::WebContents* web_contents,
Profile* profile) override;
bool ShouldRunAnimation(content::WebContents* web_contents) override;
void SetAnimationHasRun(content::WebContents* web_contents) override;
// Factory method. Used only for testing.
static std::unique_ptr<ContentSettingImageModel>
CreateForContentTypeForTesting(ContentSettingsType content_type);
protected:
ContentSettingsType content_type() { return content_type_; }
private:
ContentSettingsType content_type_;
DISALLOW_COPY_AND_ASSIGN(ContentSettingSimpleImageModel);
};
// Image model for subresource filter icons in the location bar.
class ContentSettingSubresourceFilterImageModel
: public ContentSettingImageModel {
public:
ContentSettingSubresourceFilterImageModel();
void UpdateFromWebContents(content::WebContents* web_contents) override;
ContentSettingBubbleModel* CreateBubbleModel(
ContentSettingBubbleModel::Delegate* delegate,
content::WebContents* web_contents,
Profile* profile) override;
bool ShouldRunAnimation(content::WebContents* web_contents) override;
void SetAnimationHasRun(content::WebContents* web_contents) override;
private:
DISALLOW_COPY_AND_ASSIGN(ContentSettingSubresourceFilterImageModel);
};
#endif // CHROME_BROWSER_UI_CONTENT_SETTINGS_CONTENT_SETTING_IMAGE_MODEL_H_
|