OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ui/extensions/extension_action_view_controller.h" | 5 #include "chrome/browser/ui/extensions/extension_action_view_controller.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/extensions/api/commands/command_service.h" | 9 #include "chrome/browser/extensions/api/commands/command_service.h" |
10 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 10 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
11 #include "chrome/browser/extensions/extension_action.h" | 11 #include "chrome/browser/extensions/extension_action.h" |
12 #include "chrome/browser/extensions/extension_view.h" | 12 #include "chrome/browser/extensions/extension_view.h" |
13 #include "chrome/browser/extensions/extension_view_host.h" | 13 #include "chrome/browser/extensions/extension_view_host.h" |
14 #include "chrome/browser/extensions/extension_view_host_factory.h" | 14 #include "chrome/browser/extensions/extension_view_host_factory.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/sessions/session_tab_helper.h" | 16 #include "chrome/browser/sessions/session_tab_helper.h" |
17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
18 #include "chrome/browser/ui/extensions/accelerator_priority.h" | 18 #include "chrome/browser/ui/extensions/accelerator_priority.h" |
19 #include "chrome/browser/ui/extensions/extension_action_platform_delegate.h" | 19 #include "chrome/browser/ui/extensions/extension_action_platform_delegate.h" |
20 #include "chrome/browser/ui/extensions/icon_with_badge_image_source.h" | 20 #include "chrome/browser/ui/extensions/icon_with_badge_image_source.h" |
21 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h" | 21 #include "chrome/browser/ui/toolbar/toolbar_action_view_delegate.h" |
22 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" | 22 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" |
23 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" | 23 #include "chrome/browser/ui/toolbar/toolbar_actions_bar.h" |
24 #include "chrome/common/extensions/api/extension_action/action_info.h" | 24 #include "chrome/common/extensions/api/extension_action/action_info.h" |
25 #include "extensions/browser/extension_host.h" | 25 #include "extensions/browser/extension_host.h" |
26 #include "extensions/browser/extension_registry.h" | 26 #include "extensions/browser/extension_registry.h" |
27 #include "extensions/common/extension.h" | 27 #include "extensions/common/extension.h" |
28 #include "extensions/common/feature_switch.h" | 28 #include "extensions/common/feature_switch.h" |
29 #include "extensions/common/manifest_constants.h" | 29 #include "extensions/common/manifest_constants.h" |
30 #include "ui/base/resource/material_design/material_design_controller.h" | |
31 #include "ui/gfx/image/image_skia.h" | 30 #include "ui/gfx/image/image_skia.h" |
32 #include "ui/gfx/image/image_skia_operations.h" | 31 #include "ui/gfx/image/image_skia_operations.h" |
33 | 32 |
34 using extensions::ActionInfo; | 33 using extensions::ActionInfo; |
35 using extensions::CommandService; | 34 using extensions::CommandService; |
36 | 35 |
37 ExtensionActionViewController::ExtensionActionViewController( | 36 ExtensionActionViewController::ExtensionActionViewController( |
38 const extensions::Extension* extension, | 37 const extensions::Extension* extension, |
39 Browser* browser, | 38 Browser* browser, |
40 ExtensionAction* extension_action, | 39 ExtensionAction* extension_action, |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 } | 358 } |
360 | 359 |
361 scoped_ptr<IconWithBadgeImageSource> | 360 scoped_ptr<IconWithBadgeImageSource> |
362 ExtensionActionViewController::GetIconImageSource( | 361 ExtensionActionViewController::GetIconImageSource( |
363 content::WebContents* web_contents, | 362 content::WebContents* web_contents, |
364 const gfx::Size& size) { | 363 const gfx::Size& size) { |
365 int tab_id = SessionTabHelper::IdForTab(web_contents); | 364 int tab_id = SessionTabHelper::IdForTab(web_contents); |
366 scoped_ptr<IconWithBadgeImageSource> image_source( | 365 scoped_ptr<IconWithBadgeImageSource> image_source( |
367 new IconWithBadgeImageSource(size)); | 366 new IconWithBadgeImageSource(size)); |
368 | 367 |
369 gfx::Image icon(icon_factory_.GetIcon(tab_id)); | 368 image_source->SetIcon(icon_factory_.GetIcon(tab_id)); |
370 if (ui::MaterialDesignController::IsModeMaterial()) { | |
371 // TODO(tdanderson): Use a 16x16 icon if it exists instead of resizing. | |
372 icon = gfx::Image(gfx::ImageSkiaOperations::CreateResizedImage( | |
373 *icon.ToImageSkia(), | |
374 skia::ImageOperations::RESIZE_BEST, | |
375 gfx::Size(extension_misc::EXTENSION_ICON_BITTY, | |
376 extension_misc::EXTENSION_ICON_BITTY))); | |
377 } | |
378 image_source->SetIcon(icon); | |
379 | 369 |
380 scoped_ptr<IconWithBadgeImageSource::Badge> badge; | 370 scoped_ptr<IconWithBadgeImageSource::Badge> badge; |
381 std::string badge_text = extension_action_->GetBadgeText(tab_id); | 371 std::string badge_text = extension_action_->GetBadgeText(tab_id); |
382 if (!badge_text.empty()) { | 372 if (!badge_text.empty()) { |
383 badge.reset(new IconWithBadgeImageSource::Badge( | 373 badge.reset(new IconWithBadgeImageSource::Badge( |
384 badge_text, | 374 badge_text, |
385 extension_action_->GetBadgeTextColor(tab_id), | 375 extension_action_->GetBadgeTextColor(tab_id), |
386 extension_action_->GetBadgeBackgroundColor(tab_id))); | 376 extension_action_->GetBadgeBackgroundColor(tab_id))); |
387 } | 377 } |
388 image_source->SetBadge(badge.Pass()); | 378 image_source->SetBadge(badge.Pass()); |
389 | 379 |
390 // Greyscaling disabled actions and having a special wants-to-run decoration | 380 // Greyscaling disabled actions and having a special wants-to-run decoration |
391 // are gated on the toolbar redesign. | 381 // are gated on the toolbar redesign. |
392 if (extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) { | 382 if (extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) { |
393 // If the extension doesn't want to run on the active web contents, we | 383 // If the extension doesn't want to run on the active web contents, we |
394 // grayscale it to indicate that. | 384 // grayscale it to indicate that. |
395 image_source->set_grayscale(!IsEnabled(web_contents)); | 385 image_source->set_grayscale(!IsEnabled(web_contents)); |
396 // If the action *does* want to run on the active web contents and is also | 386 // If the action *does* want to run on the active web contents and is also |
397 // overflowed, we add a decoration so that the user can see which overflowed | 387 // overflowed, we add a decoration so that the user can see which overflowed |
398 // action wants to run (since they wouldn't be able to see the change from | 388 // action wants to run (since they wouldn't be able to see the change from |
399 // grayscale to color). | 389 // grayscale to color). |
400 bool is_overflow = | 390 bool is_overflow = |
401 toolbar_actions_bar_ && toolbar_actions_bar_->in_overflow_mode(); | 391 toolbar_actions_bar_ && toolbar_actions_bar_->in_overflow_mode(); |
402 image_source->set_paint_decoration(WantsToRun(web_contents) && is_overflow); | 392 image_source->set_paint_decoration(WantsToRun(web_contents) && is_overflow); |
403 } | 393 } |
404 | 394 |
405 return image_source.Pass(); | 395 return image_source.Pass(); |
406 } | 396 } |
OLD | NEW |