OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/extensions/api/declarative_content/content_action.h" | 5 #include "chrome/browser/extensions/api/declarative_content/content_action.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 bool* bad_message) { | 67 bool* bad_message) { |
68 // We can't show a page action if the extension doesn't have one. | 68 // We can't show a page action if the extension doesn't have one. |
69 if (ActionInfo::GetPageActionInfo(extension) == NULL) { | 69 if (ActionInfo::GetPageActionInfo(extension) == NULL) { |
70 *error = kNoPageAction; | 70 *error = kNoPageAction; |
71 return scoped_refptr<ContentAction>(); | 71 return scoped_refptr<ContentAction>(); |
72 } | 72 } |
73 return scoped_refptr<ContentAction>(new ShowPageAction); | 73 return scoped_refptr<ContentAction>(new ShowPageAction); |
74 } | 74 } |
75 | 75 |
76 // Implementation of ContentAction: | 76 // Implementation of ContentAction: |
77 virtual Type GetType() const OVERRIDE { return ACTION_SHOW_PAGE_ACTION; } | 77 virtual Type GetType() const override { return ACTION_SHOW_PAGE_ACTION; } |
78 virtual void Apply(const std::string& extension_id, | 78 virtual void Apply(const std::string& extension_id, |
79 const base::Time& extension_install_time, | 79 const base::Time& extension_install_time, |
80 ApplyInfo* apply_info) const OVERRIDE { | 80 ApplyInfo* apply_info) const override { |
81 ExtensionAction* action = | 81 ExtensionAction* action = |
82 GetPageAction(apply_info->browser_context, extension_id); | 82 GetPageAction(apply_info->browser_context, extension_id); |
83 action->DeclarativeShow(ExtensionTabUtil::GetTabId(apply_info->tab)); | 83 action->DeclarativeShow(ExtensionTabUtil::GetTabId(apply_info->tab)); |
84 ExtensionActionAPI::Get(apply_info->browser_context)->NotifyChange( | 84 ExtensionActionAPI::Get(apply_info->browser_context)->NotifyChange( |
85 action, apply_info->tab, apply_info->browser_context); | 85 action, apply_info->tab, apply_info->browser_context); |
86 } | 86 } |
87 // The page action is already showing, so nothing needs to be done here. | 87 // The page action is already showing, so nothing needs to be done here. |
88 virtual void Reapply(const std::string& extension_id, | 88 virtual void Reapply(const std::string& extension_id, |
89 const base::Time& extension_install_time, | 89 const base::Time& extension_install_time, |
90 ApplyInfo* apply_info) const OVERRIDE {} | 90 ApplyInfo* apply_info) const override {} |
91 virtual void Revert(const std::string& extension_id, | 91 virtual void Revert(const std::string& extension_id, |
92 const base::Time& extension_install_time, | 92 const base::Time& extension_install_time, |
93 ApplyInfo* apply_info) const OVERRIDE { | 93 ApplyInfo* apply_info) const override { |
94 if (ExtensionAction* action = | 94 if (ExtensionAction* action = |
95 GetPageAction(apply_info->browser_context, extension_id)) { | 95 GetPageAction(apply_info->browser_context, extension_id)) { |
96 action->UndoDeclarativeShow(ExtensionTabUtil::GetTabId(apply_info->tab)); | 96 action->UndoDeclarativeShow(ExtensionTabUtil::GetTabId(apply_info->tab)); |
97 ExtensionActionAPI::Get(apply_info->browser_context)->NotifyChange( | 97 ExtensionActionAPI::Get(apply_info->browser_context)->NotifyChange( |
98 action, apply_info->tab, apply_info->browser_context); | 98 action, apply_info->tab, apply_info->browser_context); |
99 } | 99 } |
100 } | 100 } |
101 | 101 |
102 private: | 102 private: |
103 static ExtensionAction* GetPageAction( | 103 static ExtensionAction* GetPageAction( |
(...skipping 19 matching lines...) Expand all Loading... |
123 : icon_(icon), action_type_(action_type) {} | 123 : icon_(icon), action_type_(action_type) {} |
124 | 124 |
125 static scoped_refptr<ContentAction> Create( | 125 static scoped_refptr<ContentAction> Create( |
126 content::BrowserContext* browser_context, | 126 content::BrowserContext* browser_context, |
127 const Extension* extension, | 127 const Extension* extension, |
128 const base::DictionaryValue* dict, | 128 const base::DictionaryValue* dict, |
129 std::string* error, | 129 std::string* error, |
130 bool* bad_message); | 130 bool* bad_message); |
131 | 131 |
132 // Implementation of ContentAction: | 132 // Implementation of ContentAction: |
133 virtual Type GetType() const OVERRIDE { return ACTION_SET_ICON; } | 133 virtual Type GetType() const override { return ACTION_SET_ICON; } |
134 virtual void Apply(const std::string& extension_id, | 134 virtual void Apply(const std::string& extension_id, |
135 const base::Time& extension_install_time, | 135 const base::Time& extension_install_time, |
136 ApplyInfo* apply_info) const OVERRIDE { | 136 ApplyInfo* apply_info) const override { |
137 Profile* profile = Profile::FromBrowserContext(apply_info->browser_context); | 137 Profile* profile = Profile::FromBrowserContext(apply_info->browser_context); |
138 ExtensionAction* action = GetExtensionAction(profile, extension_id); | 138 ExtensionAction* action = GetExtensionAction(profile, extension_id); |
139 if (action) { | 139 if (action) { |
140 action->DeclarativeSetIcon(ExtensionTabUtil::GetTabId(apply_info->tab), | 140 action->DeclarativeSetIcon(ExtensionTabUtil::GetTabId(apply_info->tab), |
141 apply_info->priority, | 141 apply_info->priority, |
142 icon_); | 142 icon_); |
143 ExtensionActionAPI::Get(profile) | 143 ExtensionActionAPI::Get(profile) |
144 ->NotifyChange(action, apply_info->tab, profile); | 144 ->NotifyChange(action, apply_info->tab, profile); |
145 } | 145 } |
146 } | 146 } |
147 | 147 |
148 virtual void Reapply(const std::string& extension_id, | 148 virtual void Reapply(const std::string& extension_id, |
149 const base::Time& extension_install_time, | 149 const base::Time& extension_install_time, |
150 ApplyInfo* apply_info) const OVERRIDE {} | 150 ApplyInfo* apply_info) const override {} |
151 | 151 |
152 virtual void Revert(const std::string& extension_id, | 152 virtual void Revert(const std::string& extension_id, |
153 const base::Time& extension_install_time, | 153 const base::Time& extension_install_time, |
154 ApplyInfo* apply_info) const OVERRIDE { | 154 ApplyInfo* apply_info) const override { |
155 Profile* profile = Profile::FromBrowserContext(apply_info->browser_context); | 155 Profile* profile = Profile::FromBrowserContext(apply_info->browser_context); |
156 ExtensionAction* action = GetExtensionAction(profile, extension_id); | 156 ExtensionAction* action = GetExtensionAction(profile, extension_id); |
157 if (action) { | 157 if (action) { |
158 action->UndoDeclarativeSetIcon( | 158 action->UndoDeclarativeSetIcon( |
159 ExtensionTabUtil::GetTabId(apply_info->tab), | 159 ExtensionTabUtil::GetTabId(apply_info->tab), |
160 apply_info->priority, | 160 apply_info->priority, |
161 icon_); | 161 icon_); |
162 ExtensionActionAPI::Get(apply_info->browser_context) | 162 ExtensionActionAPI::Get(apply_info->browser_context) |
163 ->NotifyChange(action, apply_info->tab, profile); | 163 ->NotifyChange(action, apply_info->tab, profile); |
164 } | 164 } |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 bool* bad_message, | 495 bool* bad_message, |
496 const base::DictionaryValue** action_dict, | 496 const base::DictionaryValue** action_dict, |
497 std::string* instance_type) { | 497 std::string* instance_type) { |
498 INPUT_FORMAT_VALIDATE(json_action.GetAsDictionary(action_dict)); | 498 INPUT_FORMAT_VALIDATE(json_action.GetAsDictionary(action_dict)); |
499 INPUT_FORMAT_VALIDATE( | 499 INPUT_FORMAT_VALIDATE( |
500 (*action_dict)->GetString(keys::kInstanceType, instance_type)); | 500 (*action_dict)->GetString(keys::kInstanceType, instance_type)); |
501 return true; | 501 return true; |
502 } | 502 } |
503 | 503 |
504 } // namespace extensions | 504 } // namespace extensions |
OLD | NEW |