Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1273)

Side by Side Diff: chrome/browser/extensions/extension_action.cc

Issue 2447553003: More pre-MD odds and ends. (Closed)
Patch Set: fix typo Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_service_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/extension_action.h" 5 #include "chrome/browser/extensions/extension_action.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/base64.h" 10 #include "base/base64.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "chrome/grit/theme_resources.h" 13 #include "chrome/grit/theme_resources.h"
14 #include "extensions/browser/extension_icon_image.h" 14 #include "extensions/browser/extension_icon_image.h"
15 #include "extensions/browser/extension_icon_placeholder.h" 15 #include "extensions/browser/extension_icon_placeholder.h"
16 #include "extensions/common/constants.h" 16 #include "extensions/common/constants.h"
17 #include "extensions/common/extension_icon_set.h" 17 #include "extensions/common/extension_icon_set.h"
18 #include "extensions/common/feature_switch.h" 18 #include "extensions/common/feature_switch.h"
19 #include "extensions/common/manifest_handlers/icons_handler.h" 19 #include "extensions/common/manifest_handlers/icons_handler.h"
20 #include "ipc/ipc_message.h" 20 #include "ipc/ipc_message.h"
21 #include "ipc/ipc_message_utils.h" 21 #include "ipc/ipc_message_utils.h"
22 #include "third_party/skia/include/core/SkBitmap.h" 22 #include "third_party/skia/include/core/SkBitmap.h"
23 #include "third_party/skia/include/core/SkCanvas.h" 23 #include "third_party/skia/include/core/SkCanvas.h"
24 #include "third_party/skia/include/core/SkPaint.h" 24 #include "third_party/skia/include/core/SkPaint.h"
25 #include "third_party/skia/include/effects/SkGradientShader.h" 25 #include "third_party/skia/include/effects/SkGradientShader.h"
26 #include "ui/base/material_design/material_design_controller.h"
27 #include "ui/base/resource/resource_bundle.h" 26 #include "ui/base/resource/resource_bundle.h"
28 #include "ui/gfx/animation/animation_delegate.h" 27 #include "ui/gfx/animation/animation_delegate.h"
29 #include "ui/gfx/canvas.h" 28 #include "ui/gfx/canvas.h"
30 #include "ui/gfx/color_utils.h" 29 #include "ui/gfx/color_utils.h"
31 #include "ui/gfx/geometry/rect.h" 30 #include "ui/gfx/geometry/rect.h"
32 #include "ui/gfx/geometry/size.h" 31 #include "ui/gfx/geometry/size.h"
33 #include "ui/gfx/image/image.h" 32 #include "ui/gfx/image/image.h"
34 #include "ui/gfx/image/image_skia.h" 33 #include "ui/gfx/image/image_skia.h"
35 #include "ui/gfx/image/image_skia_source.h" 34 #include "ui/gfx/image/image_skia_source.h"
36 #include "ui/gfx/ipc/skia/gfx_skia_param_traits.h" 35 #include "ui/gfx/ipc/skia/gfx_skia_param_traits.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 }; 71 };
73 72
74 template <class T> 73 template <class T>
75 bool HasValue(const std::map<int, T>& map, int tab_id) { 74 bool HasValue(const std::map<int, T>& map, int tab_id) {
76 return map.find(tab_id) != map.end(); 75 return map.find(tab_id) != map.end();
77 } 76 }
78 77
79 } // namespace 78 } // namespace
80 79
81 extension_misc::ExtensionIcons ExtensionAction::ActionIconSize() { 80 extension_misc::ExtensionIcons ExtensionAction::ActionIconSize() {
82 return ui::MaterialDesignController::IsModeMaterial() 81 return extension_misc::EXTENSION_ICON_BITTY;
83 ? extension_misc::EXTENSION_ICON_BITTY
84 : extension_misc::EXTENSION_ICON_ACTION;
85 } 82 }
86 83
87 const int ExtensionAction::kDefaultTabId = -1; 84 const int ExtensionAction::kDefaultTabId = -1;
88 85
89 ExtensionAction::ExtensionAction(const extensions::Extension& extension, 86 ExtensionAction::ExtensionAction(const extensions::Extension& extension,
90 extensions::ActionInfo::Type action_type, 87 extensions::ActionInfo::Type action_type,
91 const extensions::ActionInfo& manifest_data) 88 const extensions::ActionInfo& manifest_data)
92 : extension_id_(extension.id()), 89 : extension_id_(extension.id()),
93 extension_name_(extension.name()), 90 extension_name_(extension.name()),
94 action_type_(action_type) { 91 action_type_(action_type) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } else { 138 } else {
142 continue; 139 continue;
143 } 140 }
144 base::PickleIterator pickle_iter(pickle); 141 base::PickleIterator pickle_iter(pickle);
145 SkBitmap bitmap; 142 SkBitmap bitmap;
146 if (!IPC::ReadParam(&pickle, &pickle_iter, &bitmap)) 143 if (!IPC::ReadParam(&pickle, &pickle_iter, &bitmap))
147 return false; 144 return false;
148 CHECK(!bitmap.isNull()); 145 CHECK(!bitmap.isNull());
149 146
150 // Chrome helpfully scales the provided icon(s), but let's not go overboard. 147 // Chrome helpfully scales the provided icon(s), but let's not go overboard.
151 const int kActionIconMaxSize = 10 * extension_misc::EXTENSION_ICON_ACTION; 148 const int kActionIconMaxSize = 10 * ActionIconSize();
152 if (bitmap.drawsNothing() || bitmap.width() > kActionIconMaxSize) 149 if (bitmap.drawsNothing() || bitmap.width() > kActionIconMaxSize)
153 continue; 150 continue;
154 151
155 float scale = 152 float scale = static_cast<float>(bitmap.width()) / ActionIconSize();
156 static_cast<float>(bitmap.width()) / ExtensionAction::ActionIconSize();
157 icon->AddRepresentation(gfx::ImageSkiaRep(bitmap, scale)); 153 icon->AddRepresentation(gfx::ImageSkiaRep(bitmap, scale));
158 } 154 }
159 return true; 155 return true;
160 } 156 }
161 157
162 gfx::Image ExtensionAction::GetExplicitlySetIcon(int tab_id) const { 158 gfx::Image ExtensionAction::GetExplicitlySetIcon(int tab_id) const {
163 return GetValue(&icon_, tab_id); 159 return GetValue(&icon_, tab_id);
164 } 160 }
165 161
166 bool ExtensionAction::SetIsVisible(int tab_id, bool new_visibility) { 162 bool ExtensionAction::SetIsVisible(int tab_id, bool new_visibility) {
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 // If there is a default icon, the icon width will be set depending on our 321 // If there is a default icon, the icon width will be set depending on our
326 // action type. 322 // action type.
327 if (default_icon_) 323 if (default_icon_)
328 return ActionIconSize(); 324 return ActionIconSize();
329 325
330 // If no icon has been set and there is no default icon, we need favicon 326 // If no icon has been set and there is no default icon, we need favicon
331 // width. 327 // width.
332 return ui::ResourceBundle::GetSharedInstance().GetImageNamed( 328 return ui::ResourceBundle::GetSharedInstance().GetImageNamed(
333 IDR_EXTENSIONS_FAVICON).Width(); 329 IDR_EXTENSIONS_FAVICON).Width();
334 } 330 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/extensions/extension_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698