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

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

Issue 11886073: Use ImageLoader instead of ImageLoadingTracker (Part 12) (Closed) Base URL: https://git.chromium.org/chromium/src.git@Issue_163929
Patch Set: Address code review feedback Created 7 years, 11 months 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 | « chrome/browser/extensions/tab_helper.h ('k') | no next file » | 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/tab_helper.h" 5 #include "chrome/browser/extensions/tab_helper.h"
6 6
7 #include "chrome/browser/extensions/activity_log.h" 7 #include "chrome/browser/extensions/activity_log.h"
8 #include "chrome/browser/extensions/app_notify_channel_ui.h" 8 #include "chrome/browser/extensions/app_notify_channel_ui.h"
9 #include "chrome/browser/extensions/crx_installer.h" 9 #include "chrome/browser/extensions/crx_installer.h"
10 #include "chrome/browser/extensions/extension_action.h" 10 #include "chrome/browser/extensions/extension_action.h"
11 #include "chrome/browser/extensions/extension_action_manager.h" 11 #include "chrome/browser/extensions/extension_action_manager.h"
12 #include "chrome/browser/extensions/extension_service.h" 12 #include "chrome/browser/extensions/extension_service.h"
13 #include "chrome/browser/extensions/extension_tab_util.h" 13 #include "chrome/browser/extensions/extension_tab_util.h"
14 #include "chrome/browser/extensions/image_loader.h"
14 #include "chrome/browser/extensions/page_action_controller.h" 15 #include "chrome/browser/extensions/page_action_controller.h"
15 #include "chrome/browser/extensions/script_badge_controller.h" 16 #include "chrome/browser/extensions/script_badge_controller.h"
16 #include "chrome/browser/extensions/script_bubble_controller.h" 17 #include "chrome/browser/extensions/script_bubble_controller.h"
17 #include "chrome/browser/extensions/script_executor.h" 18 #include "chrome/browser/extensions/script_executor.h"
18 #include "chrome/browser/extensions/webstore_standalone_installer.h" 19 #include "chrome/browser/extensions/webstore_standalone_installer.h"
19 #include "chrome/browser/profiles/profile.h" 20 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/sessions/session_id.h" 21 #include "chrome/browser/sessions/session_id.h"
21 #include "chrome/browser/sessions/session_tab_helper.h" 22 #include "chrome/browser/sessions/session_tab_helper.h"
22 #include "chrome/browser/ui/browser_dialogs.h" 23 #include "chrome/browser/ui/browser_dialogs.h"
23 #include "chrome/browser/ui/web_applications/web_app_ui.h" 24 #include "chrome/browser/ui/web_applications/web_app_ui.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 76
76 TabHelper::TabHelper(content::WebContents* web_contents) 77 TabHelper::TabHelper(content::WebContents* web_contents)
77 : content::WebContentsObserver(web_contents), 78 : content::WebContentsObserver(web_contents),
78 extension_app_(NULL), 79 extension_app_(NULL),
79 ALLOW_THIS_IN_INITIALIZER_LIST( 80 ALLOW_THIS_IN_INITIALIZER_LIST(
80 extension_function_dispatcher_( 81 extension_function_dispatcher_(
81 Profile::FromBrowserContext(web_contents->GetBrowserContext()), 82 Profile::FromBrowserContext(web_contents->GetBrowserContext()),
82 this)), 83 this)),
83 pending_web_app_action_(NONE), 84 pending_web_app_action_(NONE),
84 script_executor_(new ScriptExecutor(web_contents, 85 script_executor_(new ScriptExecutor(web_contents,
85 &script_execution_observers_)) { 86 &script_execution_observers_)),
87 ALLOW_THIS_IN_INITIALIZER_LIST(image_loader_ptr_factory_(this)) {
86 // The ActiveTabPermissionManager requires a session ID; ensure this 88 // The ActiveTabPermissionManager requires a session ID; ensure this
87 // WebContents has one. 89 // WebContents has one.
88 SessionTabHelper::CreateForWebContents(web_contents); 90 SessionTabHelper::CreateForWebContents(web_contents);
89 active_tab_permission_granter_.reset(new ActiveTabPermissionGranter( 91 active_tab_permission_granter_.reset(new ActiveTabPermissionGranter(
90 web_contents, 92 web_contents,
91 SessionID::IdForTab(web_contents), 93 SessionID::IdForTab(web_contents),
92 Profile::FromBrowserContext(web_contents->GetBrowserContext()))); 94 Profile::FromBrowserContext(web_contents->GetBrowserContext())));
93 if (FeatureSwitch::script_badges()->IsEnabled()) { 95 if (FeatureSwitch::script_badges()->IsEnabled()) {
94 location_bar_controller_.reset( 96 location_bar_controller_.reset(
95 new ScriptBadgeController(web_contents, this)); 97 new ScriptBadgeController(web_contents, this));
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 if (!extension_service || !extension_service->is_ready()) 427 if (!extension_service || !extension_service->is_ready())
426 return NULL; 428 return NULL;
427 429
428 const Extension* extension = 430 const Extension* extension =
429 extension_service->GetExtensionById(extension_app_id, false); 431 extension_service->GetExtensionById(extension_app_id, false);
430 return extension; 432 return extension;
431 } 433 }
432 434
433 void TabHelper::UpdateExtensionAppIcon(const Extension* extension) { 435 void TabHelper::UpdateExtensionAppIcon(const Extension* extension) {
434 extension_app_icon_.reset(); 436 extension_app_icon_.reset();
437 // Ensure previously enqueued callbacks are ignored.
438 image_loader_ptr_factory_.InvalidateWeakPtrs();
435 439
440 // Enqueue OnImageLoaded callback.
436 if (extension) { 441 if (extension) {
437 extension_app_image_loader_.reset(new ImageLoadingTracker(this)); 442 Profile* profile =
438 extension_app_image_loader_->LoadImage( 443 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
444 extensions::ImageLoader* loader = extensions::ImageLoader::Get(profile);
445 loader->LoadImageAsync(
439 extension, 446 extension,
440 extension->GetIconResource(extension_misc::EXTENSION_ICON_SMALLISH, 447 extension->GetIconResource(extension_misc::EXTENSION_ICON_SMALLISH,
441 ExtensionIconSet::MATCH_EXACTLY), 448 ExtensionIconSet::MATCH_EXACTLY),
442 gfx::Size(extension_misc::EXTENSION_ICON_SMALLISH, 449 gfx::Size(extension_misc::EXTENSION_ICON_SMALLISH,
443 extension_misc::EXTENSION_ICON_SMALLISH), 450 extension_misc::EXTENSION_ICON_SMALLISH),
444 ImageLoadingTracker::CACHE); 451 base::Bind(&TabHelper::OnImageLoaded,
445 } else { 452 image_loader_ptr_factory_.GetWeakPtr()));
446 extension_app_image_loader_.reset(NULL);
447 } 453 }
448 } 454 }
449 455
450 void TabHelper::SetAppIcon(const SkBitmap& app_icon) { 456 void TabHelper::SetAppIcon(const SkBitmap& app_icon) {
451 extension_app_icon_ = app_icon; 457 extension_app_icon_ = app_icon;
452 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE); 458 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE);
453 } 459 }
454 460
455 void TabHelper::OnImageLoaded(const gfx::Image& image, 461 void TabHelper::OnImageLoaded(const gfx::Image& image) {
456 const std::string& extension_id,
457 int index) {
458 if (!image.IsEmpty()) { 462 if (!image.IsEmpty()) {
459 extension_app_icon_ = *image.ToSkBitmap(); 463 extension_app_icon_ = *image.ToSkBitmap();
460 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); 464 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB);
461 } 465 }
462 } 466 }
463 467
464 WindowController* TabHelper::GetExtensionWindowController() const { 468 WindowController* TabHelper::GetExtensionWindowController() const {
465 return ExtensionTabUtil::GetWindowControllerOfTab(web_contents()); 469 return ExtensionTabUtil::GetWindowControllerOfTab(web_contents());
466 } 470 }
467 471
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 script_bubble_controller_->OnExtensionUnloaded( 518 script_bubble_controller_->OnExtensionUnloaded(
515 content::Details<extensions::UnloadedExtensionInfo>( 519 content::Details<extensions::UnloadedExtensionInfo>(
516 details)->extension->id()); 520 details)->extension->id());
517 break; 521 break;
518 } 522 }
519 } 523 }
520 } 524 }
521 } 525 }
522 526
523 } // namespace extensions 527 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/tab_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698