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

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

Issue 22694006: Infobar system refactor. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 2 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 | Annotate | Revision Log
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_infobar_delegate.h" 5 #include "chrome/browser/extensions/extension_infobar_delegate.h"
6 6
7 #include "chrome/browser/chrome_notification_types.h" 7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/extensions/extension_host.h" 8 #include "chrome/browser/extensions/extension_host.h"
9 #include "chrome/browser/extensions/extension_process_manager.h" 9 #include "chrome/browser/extensions/extension_process_manager.h"
10 #include "chrome/browser/extensions/extension_system.h" 10 #include "chrome/browser/extensions/extension_system.h"
11 #include "chrome/browser/infobars/infobar.h" 11 #include "chrome/browser/infobars/infobar.h"
12 #include "chrome/browser/infobars/infobar_service.h" 12 #include "chrome/browser/infobars/infobar_service.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/common/extensions/extension.h" 15 #include "chrome/common/extensions/extension.h"
16 #include "content/public/browser/notification_details.h" 16 #include "content/public/browser/notification_details.h"
17 #include "content/public/browser/notification_source.h" 17 #include "content/public/browser/notification_source.h"
18 18
19 19
20 ExtensionInfoBarDelegate::~ExtensionInfoBarDelegate() { 20 ExtensionInfoBarDelegate::~ExtensionInfoBarDelegate() {
21 if (observer_)
22 observer_->OnDelegateDeleted();
23 } 21 }
24 22
25 // static 23 // static
26 void ExtensionInfoBarDelegate::Create(InfoBarService* infobar_service, 24 void ExtensionInfoBarDelegate::Create(InfoBarService* infobar_service,
27 Browser* browser, 25 Browser* browser,
28 const extensions::Extension* extension, 26 const extensions::Extension* extension,
29 const GURL& url, 27 const GURL& url,
30 int height) { 28 int height) {
31 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( 29 infobar_service->AddInfoBar(ExtensionInfoBarDelegate::CreateInfoBar(
32 new ExtensionInfoBarDelegate(browser, infobar_service, extension, url, 30 scoped_ptr<ExtensionInfoBarDelegate>(new ExtensionInfoBarDelegate(
33 infobar_service->web_contents(), height))); 31 browser, extension, url, infobar_service->web_contents(), height))));
34 } 32 }
35 33
36 ExtensionInfoBarDelegate::ExtensionInfoBarDelegate( 34 ExtensionInfoBarDelegate::ExtensionInfoBarDelegate(
37 Browser* browser, 35 Browser* browser,
38 InfoBarService* infobar_service,
39 const extensions::Extension* extension, 36 const extensions::Extension* extension,
40 const GURL& url, 37 const GURL& url,
41 content::WebContents* web_contents, 38 content::WebContents* web_contents,
42 int height) 39 int height)
43 : InfoBarDelegate(infobar_service), 40 : InfoBarDelegate(),
44 #if defined(TOOLKIT_VIEWS) 41 #if defined(TOOLKIT_VIEWS)
45 browser_(browser), 42 browser_(browser),
46 #endif 43 #endif
47 observer_(NULL),
48 extension_(extension), 44 extension_(extension),
49 closing_(false) { 45 closing_(false) {
50 ExtensionProcessManager* manager = 46 ExtensionProcessManager* manager =
51 extensions::ExtensionSystem::Get(browser->profile())->process_manager(); 47 extensions::ExtensionSystem::Get(browser->profile())->process_manager();
52 extension_host_.reset(manager->CreateInfobarHost(url, browser)); 48 extension_host_.reset(manager->CreateInfobarHost(url, browser));
53 extension_host_->SetAssociatedWebContents(web_contents); 49 extension_host_->SetAssociatedWebContents(web_contents);
54 50
55 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE, 51 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE,
56 content::Source<Profile>(browser->profile())); 52 content::Source<Profile>(browser->profile()));
57 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED, 53 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
58 content::Source<Profile>(browser->profile())); 54 content::Source<Profile>(browser->profile()));
59 55
60 #if defined(TOOLKIT_VIEWS) || defined(TOOLKIT_GTK) || defined(OS_ANDROID)
61 // TODO(dtrainor): On Android, this is not used. Might need to pull this from
62 // Android UI level in the future. Tracked via issue 115303.
63 int default_height = InfoBar::kDefaultBarTargetHeight;
64 #elif defined(OS_MACOSX)
65 // TODO(pkasting): Once Infobars have been ported to Mac, we can remove the
66 // ifdefs and just use the Infobar constant below.
67 int default_height = 36;
68 #endif
69 height_ = std::max(0, height); 56 height_ = std::max(0, height);
70 height_ = std::min(2 * default_height, height_); 57 height_ = std::min(2 * InfoBar::kDefaultBarTargetHeight, height_);
71 if (height_ == 0) 58 if (height_ == 0)
72 height_ = default_height; 59 height_ = InfoBar::kDefaultBarTargetHeight;
73 } 60 }
74 61
62 // ExtensionInfoBarDelegate::CreateInfoBar() is implemented in platform-specific
63 // files.
64
75 bool ExtensionInfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const { 65 bool ExtensionInfoBarDelegate::EqualsDelegate(InfoBarDelegate* delegate) const {
76 ExtensionInfoBarDelegate* extension_delegate = 66 ExtensionInfoBarDelegate* extension_delegate =
77 delegate->AsExtensionInfoBarDelegate(); 67 delegate->AsExtensionInfoBarDelegate();
78 // When an extension crashes, an InfoBar is shown (for the crashed extension). 68 // When an extension crashes, an InfoBar is shown (for the crashed extension).
79 // That will result in a call to this function (to see if this InfoBarDelegate 69 // That will result in a call to this function (to see if this InfoBarDelegate
80 // is already showing the 'extension crashed InfoBar', which it never is), but 70 // is already showing the 'extension crashed InfoBar', which it never is), but
81 // if it is our extension that crashes, the extension delegate is NULL so 71 // if it is our extension that crashes, the extension delegate is NULL so
82 // we cannot check. 72 // we cannot check.
83 if (!extension_delegate) 73 if (!extension_delegate)
84 return false; 74 return false;
(...skipping 16 matching lines...) Expand all
101 return this; 91 return this;
102 } 92 }
103 93
104 void ExtensionInfoBarDelegate::Observe( 94 void ExtensionInfoBarDelegate::Observe(
105 int type, 95 int type,
106 const content::NotificationSource& source, 96 const content::NotificationSource& source,
107 const content::NotificationDetails& details) { 97 const content::NotificationDetails& details) {
108 if (type == chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE) { 98 if (type == chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE) {
109 if (extension_host_.get() == 99 if (extension_host_.get() ==
110 content::Details<extensions::ExtensionHost>(details).ptr()) 100 content::Details<extensions::ExtensionHost>(details).ptr())
111 RemoveSelf(); 101 infobar()->RemoveSelf();
112 } else { 102 } else {
113 DCHECK(type == chrome::NOTIFICATION_EXTENSION_UNLOADED); 103 DCHECK(type == chrome::NOTIFICATION_EXTENSION_UNLOADED);
114 if (extension_ == content::Details<extensions::UnloadedExtensionInfo>( 104 if (extension_ == content::Details<extensions::UnloadedExtensionInfo>(
115 details)->extension) 105 details)->extension)
116 RemoveSelf(); 106 infobar()->RemoveSelf();
117 } 107 }
118 } 108 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698