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

Side by Side Diff: chrome/browser/ui/extensions/extension_enable_flow.cc

Issue 251603004: Remove NOTIFICATION_EXTENSION_LOADED_DEPRECATED from c/b/ui/extensions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address review Created 6 years, 7 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
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/ui/extensions/extension_enable_flow.h" 5 #include "chrome/browser/ui/extensions/extension_enable_flow.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_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h" 11 #include "chrome/browser/ui/extensions/extension_enable_flow_delegate.h"
12 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" 12 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
13 #include "content/public/browser/notification_details.h" 13 #include "content/public/browser/notification_details.h"
14 #include "content/public/browser/notification_source.h" 14 #include "content/public/browser/notification_source.h"
15 #include "extensions/browser/extension_registry.h" 15 #include "extensions/browser/extension_registry.h"
16 #include "extensions/browser/extension_system.h" 16 #include "extensions/browser/extension_system.h"
17 17
18 using extensions::Extension; 18 using extensions::Extension;
19 19
20 ExtensionEnableFlow::ExtensionEnableFlow(Profile* profile, 20 ExtensionEnableFlow::ExtensionEnableFlow(Profile* profile,
21 const std::string& extension_id, 21 const std::string& extension_id,
22 ExtensionEnableFlowDelegate* delegate) 22 ExtensionEnableFlowDelegate* delegate)
23 : profile_(profile), 23 : profile_(profile),
24 extension_id_(extension_id), 24 extension_id_(extension_id),
25 delegate_(delegate), 25 delegate_(delegate),
26 parent_contents_(NULL), 26 parent_contents_(NULL),
27 parent_window_(NULL) { 27 parent_window_(NULL),
28 extension_registry_observer_(this) {
28 } 29 }
29 30
30 ExtensionEnableFlow::~ExtensionEnableFlow() { 31 ExtensionEnableFlow::~ExtensionEnableFlow() {
31 } 32 }
32 33
33 void ExtensionEnableFlow::StartForWebContents( 34 void ExtensionEnableFlow::StartForWebContents(
34 content::WebContents* parent_contents) { 35 content::WebContents* parent_contents) {
35 parent_contents_ = parent_contents; 36 parent_contents_ = parent_contents;
36 parent_window_ = NULL; 37 parent_window_ = NULL;
37 Run(); 38 Run();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 104
104 void ExtensionEnableFlow::CreatePrompt() { 105 void ExtensionEnableFlow::CreatePrompt() {
105 if (!window_getter_.is_null()) 106 if (!window_getter_.is_null())
106 parent_window_ = window_getter_.Run(); 107 parent_window_ = window_getter_.Run();
107 prompt_.reset(parent_contents_ ? 108 prompt_.reset(parent_contents_ ?
108 new ExtensionInstallPrompt(parent_contents_) : 109 new ExtensionInstallPrompt(parent_contents_) :
109 new ExtensionInstallPrompt(profile_, parent_window_, this)); 110 new ExtensionInstallPrompt(profile_, parent_window_, this));
110 } 111 }
111 112
112 void ExtensionEnableFlow::StartObserving() { 113 void ExtensionEnableFlow::StartObserving() {
113 registrar_.Add(this, 114 extension_registry_observer_.Add(
114 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, 115 extensions::ExtensionRegistry::Get(profile_));
115 content::Source<Profile>(profile_));
116 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOAD_ERROR, 116 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOAD_ERROR,
117 content::Source<Profile>(profile_)); 117 content::Source<Profile>(profile_));
118 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED, 118 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNINSTALLED,
119 content::Source<Profile>(profile_)); 119 content::Source<Profile>(profile_));
120 } 120 }
121 121
122 void ExtensionEnableFlow::StopObserving() { 122 void ExtensionEnableFlow::StopObserving() {
123 registrar_.RemoveAll(); 123 registrar_.RemoveAll();
124 } 124 }
125 125
126 void ExtensionEnableFlow::Observe(int type, 126 void ExtensionEnableFlow::Observe(int type,
127 const content::NotificationSource& source, 127 const content::NotificationSource& source,
128 const content::NotificationDetails& details) { 128 const content::NotificationDetails& details) {
129 switch (type) { 129 switch (type) {
130 case chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED: {
131 const Extension* extension =
132 content::Details<const Extension>(details).ptr();
133 if (extension->id() == extension_id_) {
134 StopObserving();
135 CheckPermissionAndMaybePromptUser();
136 }
137
138 break;
139 }
140 case chrome::NOTIFICATION_EXTENSION_LOAD_ERROR: { 130 case chrome::NOTIFICATION_EXTENSION_LOAD_ERROR: {
141 StopObserving(); 131 StopObserving();
142 delegate_->ExtensionEnableFlowAborted(false); 132 delegate_->ExtensionEnableFlowAborted(false);
143 break; 133 break;
144 } 134 }
145 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: { 135 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED: {
146 const Extension* extension = 136 const Extension* extension =
147 content::Details<const Extension>(details).ptr(); 137 content::Details<const Extension>(details).ptr();
148 if (extension->id() == extension_id_) { 138 if (extension->id() == extension_id_) {
149 StopObserving(); 139 StopObserving();
150 delegate_->ExtensionEnableFlowAborted(false); 140 delegate_->ExtensionEnableFlowAborted(false);
151 } 141 }
152
153 break; 142 break;
154 } 143 }
155 default: 144 default:
156 NOTREACHED(); 145 NOTREACHED();
157 } 146 }
158 } 147 }
159 148
149 void ExtensionEnableFlow::OnExtensionLoaded(
150 content::BrowserContext* browser_context,
151 const Extension* extension) {
152 if (extension->id() == extension_id_) {
153 StopObserving();
154 CheckPermissionAndMaybePromptUser();
155 }
156 }
157
160 void ExtensionEnableFlow::InstallUIProceed() { 158 void ExtensionEnableFlow::InstallUIProceed() {
161 ExtensionService* service = 159 ExtensionService* service =
162 extensions::ExtensionSystem::Get(profile_)->extension_service(); 160 extensions::ExtensionSystem::Get(profile_)->extension_service();
163 161
164 // The extension can be uninstalled in another window while the UI was 162 // The extension can be uninstalled in another window while the UI was
165 // showing. Treat it as a cancellation and notify |delegate_|. 163 // showing. Treat it as a cancellation and notify |delegate_|.
166 const Extension* extension = service->GetExtensionById(extension_id_, true); 164 const Extension* extension = service->GetExtensionById(extension_id_, true);
167 if (!extension) { 165 if (!extension) {
168 delegate_->ExtensionEnableFlowAborted(true); 166 delegate_->ExtensionEnableFlowAborted(true);
169 return; 167 return;
170 } 168 }
171 169
172 service->GrantPermissionsAndEnableExtension(extension); 170 service->GrantPermissionsAndEnableExtension(extension);
173 delegate_->ExtensionEnableFlowFinished(); // |delegate_| may delete us. 171 delegate_->ExtensionEnableFlowFinished(); // |delegate_| may delete us.
174 } 172 }
175 173
176 void ExtensionEnableFlow::InstallUIAbort(bool user_initiated) { 174 void ExtensionEnableFlow::InstallUIAbort(bool user_initiated) {
177 delegate_->ExtensionEnableFlowAborted(user_initiated); 175 delegate_->ExtensionEnableFlowAborted(user_initiated);
178 // |delegate_| may delete us. 176 // |delegate_| may delete us.
179 } 177 }
180 178
181 content::WebContents* ExtensionEnableFlow::OpenURL( 179 content::WebContents* ExtensionEnableFlow::OpenURL(
182 const content::OpenURLParams& params) { 180 const content::OpenURLParams& params) {
183 chrome::ScopedTabbedBrowserDisplayer displayer( 181 chrome::ScopedTabbedBrowserDisplayer displayer(
184 profile_, chrome::GetActiveDesktop()); 182 profile_, chrome::GetActiveDesktop());
185 return displayer.browser()->OpenURL(params); 183 return displayer.browser()->OpenURL(params);
186 } 184 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/extensions/extension_enable_flow.h ('k') | chrome/browser/ui/extensions/extension_installed_bubble.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698