OLD | NEW |
---|---|
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" |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 prompt_.reset(parent_contents_ ? | 109 prompt_.reset(parent_contents_ ? |
110 new ExtensionInstallPrompt(parent_contents_) : | 110 new ExtensionInstallPrompt(parent_contents_) : |
111 new ExtensionInstallPrompt(profile_, parent_window_, this)); | 111 new ExtensionInstallPrompt(profile_, parent_window_, this)); |
112 } | 112 } |
113 | 113 |
114 void ExtensionEnableFlow::StartObserving() { | 114 void ExtensionEnableFlow::StartObserving() { |
115 extension_registry_observer_.Add( | 115 extension_registry_observer_.Add( |
116 extensions::ExtensionRegistry::Get(profile_)); | 116 extensions::ExtensionRegistry::Get(profile_)); |
117 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOAD_ERROR, | 117 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_LOAD_ERROR, |
118 content::Source<Profile>(profile_)); | 118 content::Source<Profile>(profile_)); |
119 registrar_.Add(this, | |
120 chrome::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED, | |
121 content::Source<Profile>(profile_)); | |
122 } | 119 } |
123 | 120 |
124 void ExtensionEnableFlow::StopObserving() { | 121 void ExtensionEnableFlow::StopObserving() { |
125 registrar_.RemoveAll(); | 122 registrar_.RemoveAll(); |
123 extension_registry_observer_.RemoveAll(); | |
limasdf
2014/06/03 19:27:43
I think this is necessary. and it should be addres
| |
126 } | 124 } |
127 | 125 |
128 void ExtensionEnableFlow::Observe(int type, | 126 void ExtensionEnableFlow::Observe(int type, |
129 const content::NotificationSource& source, | 127 const content::NotificationSource& source, |
130 const content::NotificationDetails& details) { | 128 const content::NotificationDetails& details) { |
131 switch (type) { | 129 DCHECK_EQ(chrome::NOTIFICATION_EXTENSION_LOAD_ERROR, type); |
132 case chrome::NOTIFICATION_EXTENSION_LOAD_ERROR: { | 130 StopObserving(); |
133 StopObserving(); | 131 delegate_->ExtensionEnableFlowAborted(false); |
134 delegate_->ExtensionEnableFlowAborted(false); | |
135 break; | |
136 } | |
137 case chrome::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED: { | |
138 const Extension* extension = | |
139 content::Details<const Extension>(details).ptr(); | |
140 if (extension->id() == extension_id_) { | |
141 StopObserving(); | |
142 delegate_->ExtensionEnableFlowAborted(false); | |
143 } | |
144 break; | |
145 } | |
146 default: | |
147 NOTREACHED(); | |
148 } | |
149 } | 132 } |
150 | 133 |
151 void ExtensionEnableFlow::OnExtensionLoaded( | 134 void ExtensionEnableFlow::OnExtensionLoaded( |
152 content::BrowserContext* browser_context, | 135 content::BrowserContext* browser_context, |
153 const Extension* extension) { | 136 const Extension* extension) { |
154 if (extension->id() == extension_id_) { | 137 if (extension->id() == extension_id_) { |
155 StopObserving(); | 138 StopObserving(); |
156 CheckPermissionAndMaybePromptUser(); | 139 CheckPermissionAndMaybePromptUser(); |
157 } | 140 } |
158 } | 141 } |
159 | 142 |
143 void ExtensionEnableFlow::OnExtensionUninstalled( | |
144 content::BrowserContext* browser_context, | |
145 const Extension* extension) { | |
146 if (extension->id() == extension_id_) { | |
147 StopObserving(); | |
148 delegate_->ExtensionEnableFlowAborted(false); | |
149 } | |
150 } | |
151 | |
160 void ExtensionEnableFlow::InstallUIProceed() { | 152 void ExtensionEnableFlow::InstallUIProceed() { |
161 ExtensionService* service = | 153 ExtensionService* service = |
162 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 154 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
163 | 155 |
164 // The extension can be uninstalled in another window while the UI was | 156 // The extension can be uninstalled in another window while the UI was |
165 // showing. Treat it as a cancellation and notify |delegate_|. | 157 // showing. Treat it as a cancellation and notify |delegate_|. |
166 const Extension* extension = service->GetExtensionById(extension_id_, true); | 158 const Extension* extension = service->GetExtensionById(extension_id_, true); |
167 if (!extension) { | 159 if (!extension) { |
168 delegate_->ExtensionEnableFlowAborted(true); | 160 delegate_->ExtensionEnableFlowAborted(true); |
169 return; | 161 return; |
170 } | 162 } |
171 | 163 |
172 service->GrantPermissionsAndEnableExtension(extension); | 164 service->GrantPermissionsAndEnableExtension(extension); |
173 delegate_->ExtensionEnableFlowFinished(); // |delegate_| may delete us. | 165 delegate_->ExtensionEnableFlowFinished(); // |delegate_| may delete us. |
174 } | 166 } |
175 | 167 |
176 void ExtensionEnableFlow::InstallUIAbort(bool user_initiated) { | 168 void ExtensionEnableFlow::InstallUIAbort(bool user_initiated) { |
177 delegate_->ExtensionEnableFlowAborted(user_initiated); | 169 delegate_->ExtensionEnableFlowAborted(user_initiated); |
178 // |delegate_| may delete us. | 170 // |delegate_| may delete us. |
179 } | 171 } |
180 | 172 |
181 content::WebContents* ExtensionEnableFlow::OpenURL( | 173 content::WebContents* ExtensionEnableFlow::OpenURL( |
182 const content::OpenURLParams& params) { | 174 const content::OpenURLParams& params) { |
183 chrome::ScopedTabbedBrowserDisplayer displayer( | 175 chrome::ScopedTabbedBrowserDisplayer displayer( |
184 profile_, chrome::GetActiveDesktop()); | 176 profile_, chrome::GetActiveDesktop()); |
185 return displayer.browser()->OpenURL(params); | 177 return displayer.browser()->OpenURL(params); |
186 } | 178 } |
OLD | NEW |