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/extension_action/extension_actions_api.h
" | 5 #include "chrome/browser/extensions/api/extension_action/extension_actions_api.h
" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 if (color_ints[i] > 255 || color_ints[i] < 0) | 139 if (color_ints[i] > 255 || color_ints[i] < 0) |
140 return false; | 140 return false; |
141 } | 141 } |
142 | 142 |
143 *result = SkColorSetARGB(255, color_ints[0], color_ints[1], color_ints[2]); | 143 *result = SkColorSetARGB(255, color_ints[0], color_ints[1], color_ints[2]); |
144 return true; | 144 return true; |
145 } | 145 } |
146 | 146 |
147 bool ExtensionActionFunction::SetVisible(bool visible) { | 147 bool ExtensionActionFunction::SetVisible(bool visible) { |
148 // If --browser-actions-for-all is enabled there will be a browser_action | 148 // If --browser-actions-for-all is enabled there will be a browser_action |
149 // here instead of a page action. Until we decide to do with that, just | 149 // here instead of a page action. Until we decide what to do with that, just |
150 // ignore. | 150 // ignore. |
151 if (!GetExtension()->page_action()) | 151 if (!GetExtension()->page_action()) |
152 return true; | 152 return true; |
153 extension_action_->SetIsVisible(tab_id_, visible); | 153 extension_action_->SetIsVisible(tab_id_, visible); |
154 NotifyChange(); | 154 NotifyChange(); |
155 return true; | 155 return true; |
156 } | 156 } |
157 | 157 |
158 bool ExtensionActionShowFunction::RunExtensionAction() { | 158 bool ExtensionActionShowFunction::RunExtensionAction() { |
159 return SetVisible(true); | 159 return SetVisible(true); |
160 } | 160 } |
161 | 161 |
162 bool ExtensionActionHideFunction::RunExtensionAction() { | 162 bool ExtensionActionHideFunction::RunExtensionAction() { |
163 return SetVisible(false); | 163 return SetVisible(false); |
164 } | 164 } |
165 | 165 |
166 bool ExtensionActionSetIconFunction::RunExtensionAction() { | 166 bool ExtensionActionSetIconFunction::RunExtensionAction() { |
167 // setIcon can take a variant argument: either a canvas ImageData, or an | 167 // setIcon can take a variant argument: either a canvas ImageData, or an |
168 // icon index. | 168 // icon index. |
169 base::BinaryValue* binary = NULL; | 169 base::BinaryValue* binary = NULL; |
170 int icon_index; | 170 int icon_index; |
171 if (details_->GetBinary("imageData", &binary)) { | 171 if (details_->GetBinary("imageData", &binary)) { |
172 IPC::Message bitmap_pickle(binary->GetBuffer(), binary->GetSize()); | 172 IPC::Message bitmap_pickle(binary->GetBuffer(), binary->GetSize()); |
173 PickleIterator iter(bitmap_pickle); | 173 PickleIterator iter(bitmap_pickle); |
174 SkBitmap bitmap; | 174 SkBitmap bitmap; |
175 EXTENSION_FUNCTION_VALIDATE( | 175 EXTENSION_FUNCTION_VALIDATE( |
176 IPC::ReadParam(&bitmap_pickle, &iter, &bitmap)); | 176 IPC::ReadParam(&bitmap_pickle, &iter, &bitmap)); |
177 extension_action_->SetIcon(tab_id_, bitmap); | 177 extension_action_->SetIcon(tab_id_, bitmap); |
178 } else if (details_->GetInteger("iconIndex", &icon_index)) { | 178 } else if (details_->GetInteger("iconIndex", &icon_index)) { |
179 // If --browser-actions-for-all is enabled there might legimitely be an | 179 // If --browser-actions-for-all is enabled there might legitimately be an |
180 // iconIndex set. Until we decide what to do with that, ignore. | 180 // iconIndex set. Until we decide what to do with that, ignore. |
181 if (!GetExtension()->page_action()) | 181 if (!GetExtension()->page_action()) |
182 return true; | 182 return true; |
183 if (icon_index < 0 || | 183 if (icon_index < 0 || |
184 static_cast<size_t>(icon_index) >= | 184 static_cast<size_t>(icon_index) >= |
185 extension_action_->icon_paths()->size()) { | 185 extension_action_->icon_paths()->size()) { |
186 error_ = kIconIndexOutOfBounds; | 186 error_ = kIconIndexOutOfBounds; |
187 return false; | 187 return false; |
188 } | 188 } |
189 extension_action_->SetIcon(tab_id_, SkBitmap()); | 189 extension_action_->SetIcon(tab_id_, SkBitmap()); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 bool ExtensionActionGetBadgeBackgroundColorFunction::RunExtensionAction() { | 272 bool ExtensionActionGetBadgeBackgroundColorFunction::RunExtensionAction() { |
273 ListValue* list = new ListValue(); | 273 ListValue* list = new ListValue(); |
274 SkColor color = extension_action_->GetBadgeBackgroundColor(tab_id_); | 274 SkColor color = extension_action_->GetBadgeBackgroundColor(tab_id_); |
275 list->Append(Value::CreateIntegerValue(SkColorGetR(color))); | 275 list->Append(Value::CreateIntegerValue(SkColorGetR(color))); |
276 list->Append(Value::CreateIntegerValue(SkColorGetG(color))); | 276 list->Append(Value::CreateIntegerValue(SkColorGetG(color))); |
277 list->Append(Value::CreateIntegerValue(SkColorGetB(color))); | 277 list->Append(Value::CreateIntegerValue(SkColorGetB(color))); |
278 list->Append(Value::CreateIntegerValue(SkColorGetA(color))); | 278 list->Append(Value::CreateIntegerValue(SkColorGetA(color))); |
279 result_.reset(list); | 279 result_.reset(list); |
280 return true; | 280 return true; |
281 } | 281 } |
OLD | NEW |