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

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

Issue 923463003: [Extensions] Remove the Infobar API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments Created 5 years, 10 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/extension_infobar_delegate.h"
6
7 #include "chrome/browser/chrome_notification_types.h"
8 #include "chrome/browser/extensions/extension_view_host.h"
9 #include "chrome/browser/extensions/extension_view_host_factory.h"
10 #include "chrome/browser/infobars/infobar_service.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/infobar_container_delegate.h"
14 #include "components/infobars/core/infobar.h"
15 #include "content/public/browser/notification_details.h"
16 #include "content/public/browser/notification_source.h"
17 #include "extensions/browser/extension_registry.h"
18 #include "extensions/common/extension.h"
19
20 ExtensionInfoBarDelegate::~ExtensionInfoBarDelegate() {
21 }
22
23 // static
24 void ExtensionInfoBarDelegate::Create(content::WebContents* web_contents,
25 Browser* browser,
26 const extensions::Extension* extension,
27 const GURL& url,
28 int height) {
29 InfoBarService::FromWebContents(web_contents)->AddInfoBar(
30 ExtensionInfoBarDelegate::CreateInfoBar(
31 scoped_ptr<ExtensionInfoBarDelegate>(new ExtensionInfoBarDelegate(
32 browser, extension, url, web_contents, height))));
33 }
34
35 ExtensionInfoBarDelegate::ExtensionInfoBarDelegate(
36 Browser* browser,
37 const extensions::Extension* extension,
38 const GURL& url,
39 content::WebContents* web_contents,
40 int height)
41 : infobars::InfoBarDelegate(),
42 #if defined(TOOLKIT_VIEWS)
43 browser_(browser),
44 #endif
45 extension_(extension),
46 extension_registry_observer_(this),
47 closing_(false) {
48 extension_view_host_.reset(
49 extensions::ExtensionViewHostFactory::CreateInfobarHost(url, browser));
50 extension_view_host_->SetAssociatedWebContents(web_contents);
51
52 extension_registry_observer_.Add(
53 extensions::ExtensionRegistry::Get(browser->profile()));
54 registrar_.Add(this,
55 extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE,
56 content::Source<Profile>(browser->profile()));
57
58 height_ = std::max(0, height);
59 height_ =
60 std::min(2 * InfoBarContainerDelegate::kDefaultBarTargetHeight, height_);
61 if (height_ == 0)
62 height_ = InfoBarContainerDelegate::kDefaultBarTargetHeight;
63 }
64
65 content::WebContents* ExtensionInfoBarDelegate::GetWebContents() {
66 return InfoBarService::WebContentsFromInfoBar(infobar());
67 }
68
69 // ExtensionInfoBarDelegate::CreateInfoBar() is implemented in platform-specific
70 // files.
71
72 bool ExtensionInfoBarDelegate::EqualsDelegate(
73 infobars::InfoBarDelegate* delegate) const {
74 ExtensionInfoBarDelegate* extension_delegate =
75 delegate->AsExtensionInfoBarDelegate();
76 // When an extension crashes, an InfoBar is shown (for the crashed extension).
77 // That will result in a call to this function (to see if this InfoBarDelegate
78 // is already showing the 'extension crashed InfoBar', which it never is), but
79 // if it is our extension that crashes, the extension delegate is NULL so
80 // we cannot check.
81 if (!extension_delegate)
82 return false;
83
84 // Only allow one InfoBar at a time per extension.
85 return extension_delegate->extension_view_host()->extension() ==
86 extension_view_host_->extension();
87 }
88
89 void ExtensionInfoBarDelegate::InfoBarDismissed() {
90 closing_ = true;
91 }
92
93 infobars::InfoBarDelegate::Type ExtensionInfoBarDelegate::GetInfoBarType()
94 const {
95 return PAGE_ACTION_TYPE;
96 }
97
98 ExtensionInfoBarDelegate*
99 ExtensionInfoBarDelegate::AsExtensionInfoBarDelegate() {
100 return this;
101 }
102
103 void ExtensionInfoBarDelegate::OnExtensionUnloaded(
104 content::BrowserContext* browser_context,
105 const extensions::Extension* extension,
106 extensions::UnloadedExtensionInfo::Reason reason) {
107 if (extension_ == extension)
108 infobar()->RemoveSelf();
109 }
110
111 void ExtensionInfoBarDelegate::Observe(
112 int type,
113 const content::NotificationSource& source,
114 const content::NotificationDetails& details) {
115 DCHECK_EQ(type, extensions::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE);
116 if (extension_view_host_.get() ==
117 content::Details<extensions::ExtensionHost>(details).ptr())
118 infobar()->RemoveSelf();
119 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_infobar_delegate.h ('k') | chrome/browser/extensions/extension_view_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698