| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/active_script_controller.h" | 5 #include "chrome/browser/extensions/active_script_controller.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 // permissions and granted permissions. | 132 // permissions and granted permissions. |
| 133 // TODO(devlin): Make sure that the permission is removed from | 133 // TODO(devlin): Make sure that the permission is removed from |
| 134 // withheld_permissions if appropriate. | 134 // withheld_permissions if appropriate. |
| 135 PermissionsUpdater(web_contents()->GetBrowserContext()) | 135 PermissionsUpdater(web_contents()->GetBrowserContext()) |
| 136 .AddPermissions(extension, new_permissions.get()); | 136 .AddPermissions(extension, new_permissions.get()); |
| 137 | 137 |
| 138 // Allow current tab to run injection. | 138 // Allow current tab to run injection. |
| 139 OnClicked(extension); | 139 OnClicked(extension); |
| 140 } | 140 } |
| 141 | 141 |
| 142 void ActiveScriptController::OnClicked(const Extension* extension) { |
| 143 DCHECK(ContainsKey(pending_requests_, extension->id())); |
| 144 RunPendingForExtension(extension); |
| 145 } |
| 146 |
| 142 bool ActiveScriptController::HasActiveScriptAction(const Extension* extension) { | 147 bool ActiveScriptController::HasActiveScriptAction(const Extension* extension) { |
| 143 return enabled_ && pending_requests_.count(extension->id()) > 0; | 148 return enabled_ && pending_requests_.count(extension->id()) > 0; |
| 144 } | 149 } |
| 145 | 150 |
| 146 ExtensionAction* ActiveScriptController::GetActionForExtension( | 151 ExtensionAction* ActiveScriptController::GetActionForExtension( |
| 147 const Extension* extension) { | 152 const Extension* extension) { |
| 148 if (!enabled_ || pending_requests_.count(extension->id()) == 0) | 153 if (!enabled_ || pending_requests_.count(extension->id()) == 0) |
| 149 return NULL; // No action for this extension. | 154 return NULL; // No action for this extension. |
| 150 | 155 |
| 151 ActiveScriptMap::iterator existing = | 156 ActiveScriptMap::iterator existing = |
| 152 active_script_actions_.find(extension->id()); | 157 active_script_actions_.find(extension->id()); |
| 153 if (existing != active_script_actions_.end()) | 158 if (existing != active_script_actions_.end()) |
| 154 return existing->second.get(); | 159 return existing->second.get(); |
| 155 | 160 |
| 156 linked_ptr<ExtensionAction> action(ExtensionActionManager::Get( | 161 linked_ptr<ExtensionAction> action(ExtensionActionManager::Get( |
| 157 Profile::FromBrowserContext(web_contents()->GetBrowserContext())) | 162 Profile::FromBrowserContext(web_contents()->GetBrowserContext())) |
| 158 ->GetBestFitAction(*extension, ActionInfo::TYPE_PAGE).release()); | 163 ->GetBestFitAction(*extension, ActionInfo::TYPE_PAGE).release()); |
| 159 action->SetIsVisible(ExtensionAction::kDefaultTabId, true); | 164 action->SetIsVisible(ExtensionAction::kDefaultTabId, true); |
| 160 | 165 |
| 161 active_script_actions_[extension->id()] = action; | 166 active_script_actions_[extension->id()] = action; |
| 162 return action.get(); | 167 return action.get(); |
| 163 } | 168 } |
| 164 | 169 |
| 165 ExtensionAction::ShowAction ActiveScriptController::OnClicked( | |
| 166 const Extension* extension) { | |
| 167 DCHECK(ContainsKey(pending_requests_, extension->id())); | |
| 168 RunPendingForExtension(extension); | |
| 169 return ExtensionAction::ACTION_NONE; | |
| 170 } | |
| 171 | |
| 172 void ActiveScriptController::OnNavigated() { | 170 void ActiveScriptController::OnNavigated() { |
| 173 LogUMA(); | 171 LogUMA(); |
| 174 permitted_extensions_.clear(); | 172 permitted_extensions_.clear(); |
| 175 pending_requests_.clear(); | 173 pending_requests_.clear(); |
| 176 } | 174 } |
| 177 | 175 |
| 178 void ActiveScriptController::OnExtensionUnloaded(const Extension* extension) { | 176 void ActiveScriptController::OnExtensionUnloaded(const Extension* extension) { |
| 179 PendingRequestMap::iterator iter = pending_requests_.find(extension->id()); | 177 PendingRequestMap::iterator iter = pending_requests_.find(extension->id()); |
| 180 if (iter != pending_requests_.end()) | 178 if (iter != pending_requests_.end()) |
| 181 pending_requests_.erase(iter); | 179 pending_requests_.erase(iter); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 UMA_HISTOGRAM_COUNTS_100( | 345 UMA_HISTOGRAM_COUNTS_100( |
| 348 "Extensions.ActiveScriptController.PermittedExtensions", | 346 "Extensions.ActiveScriptController.PermittedExtensions", |
| 349 permitted_extensions_.size()); | 347 permitted_extensions_.size()); |
| 350 UMA_HISTOGRAM_COUNTS_100( | 348 UMA_HISTOGRAM_COUNTS_100( |
| 351 "Extensions.ActiveScriptController.DeniedExtensions", | 349 "Extensions.ActiveScriptController.DeniedExtensions", |
| 352 pending_requests_.size()); | 350 pending_requests_.size()); |
| 353 } | 351 } |
| 354 } | 352 } |
| 355 | 353 |
| 356 } // namespace extensions | 354 } // namespace extensions |
| OLD | NEW |