| 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/extensions/script_bubble_controller.h" | 5 #include "chrome/browser/extensions/script_bubble_controller.h" |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/component_loader.h" | 7 #include "chrome/browser/extensions/component_loader.h" |
| 8 #include "chrome/browser/extensions/extension_action.h" | 8 #include "chrome/browser/extensions/extension_action.h" |
| 9 #include "chrome/browser/extensions/extension_action_manager.h" | 9 #include "chrome/browser/extensions/extension_action_manager.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/extensions/extension_system.h" | 11 #include "chrome/browser/extensions/extension_system.h" |
| 12 #include "chrome/browser/extensions/extension_tab_util.h" | 12 #include "chrome/browser/extensions/extension_tab_util.h" |
| 13 #include "chrome/browser/extensions/location_bar_controller.h" | 13 #include "chrome/browser/extensions/location_bar_controller.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
| 16 #include "content/public/browser/navigation_details.h" |
| 16 | 17 |
| 17 namespace extensions { | 18 namespace extensions { |
| 18 | 19 |
| 19 ScriptBubbleController::ScriptBubbleController( | 20 ScriptBubbleController::ScriptBubbleController( |
| 20 content::WebContents* web_contents, TabHelper* tab_helper) | 21 content::WebContents* web_contents, TabHelper* tab_helper) |
| 21 : TabHelper::ScriptExecutionObserver(tab_helper), | 22 : TabHelper::ScriptExecutionObserver(tab_helper), |
| 22 content::WebContentsObserver(web_contents) { | 23 content::WebContentsObserver(web_contents) { |
| 23 } | 24 } |
| 24 | 25 |
| 25 ScriptBubbleController::~ScriptBubbleController() { | 26 ScriptBubbleController::~ScriptBubbleController() { |
| 26 } | 27 } |
| 27 | 28 |
| 28 void ScriptBubbleController::OnScriptsExecuted( | 29 void ScriptBubbleController::OnScriptsExecuted( |
| 29 const content::WebContents* web_contents, | 30 const content::WebContents* web_contents, |
| 30 const ExecutingScriptsMap& executing_scripts, | 31 const ExecutingScriptsMap& executing_scripts, |
| 31 int32 page_id, | 32 int32 page_id, |
| 32 const GURL& on_url) { | 33 const GURL& on_url) { |
| 33 DCHECK_EQ(this->web_contents(), web_contents); | 34 DCHECK_EQ(this->web_contents(), web_contents); |
| 34 | 35 |
| 35 bool changed = false; | 36 bool changed = false; |
| 36 ExtensionService* extension_service = GetExtensionService(); | 37 ExtensionService* extension_service = GetExtensionService(); |
| 37 for (ExecutingScriptsMap::const_iterator i = executing_scripts.begin(); | 38 for (ExecutingScriptsMap::const_iterator i = executing_scripts.begin(); |
| 38 i != executing_scripts.end(); ++i) { | 39 i != executing_scripts.end(); ++i) { |
| 39 // Don't display extensions that wouldn't be shown in settings because | 40 // Don't display extensions that wouldn't be shown in settings because |
| 40 // those are effectively not installed from the user's point of view. | 41 // those are effectively not installed from the user's point of view. |
| 41 const Extension* extension = | 42 const Extension* extension = |
| 42 extension_service->extensions()->GetByID(i->first); | 43 extension_service->extensions()->GetByID(i->first); |
| 43 if (extension->ShouldDisplayInExtensionSettings()) | 44 if (extension && extension->ShouldDisplayInExtensionSettings()) |
| 44 changed |= extensions_running_scripts_.insert(i->first).second; | 45 changed |= extensions_running_scripts_.insert(i->first).second; |
| 45 } | 46 } |
| 46 | 47 |
| 47 if (changed) | 48 if (changed) |
| 48 UpdateScriptBubble(); | 49 UpdateScriptBubble(); |
| 49 } | 50 } |
| 50 | 51 |
| 51 void ScriptBubbleController::DidNavigateMainFrame( | 52 void ScriptBubbleController::DidNavigateMainFrame( |
| 52 const content::LoadCommittedDetails& details, | 53 const content::LoadCommittedDetails& details, |
| 53 const content::FrameNavigateParams& params) { | 54 const content::FrameNavigateParams& params) { |
| 55 if (!details.is_navigation_to_different_page()) |
| 56 return; |
| 54 extensions_running_scripts_.clear(); | 57 extensions_running_scripts_.clear(); |
| 55 UpdateScriptBubble(); | 58 UpdateScriptBubble(); |
| 56 } | 59 } |
| 57 | 60 |
| 61 void ScriptBubbleController::OnExtensionUnloaded( |
| 62 const std::string& extension_id) { |
| 63 if (extensions_running_scripts_.erase(extension_id) == 1) |
| 64 UpdateScriptBubble(); |
| 65 } |
| 66 |
| 58 Profile* ScriptBubbleController::profile() const { | 67 Profile* ScriptBubbleController::profile() const { |
| 59 return Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 68 return Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 60 } | 69 } |
| 61 | 70 |
| 62 ExtensionService* ScriptBubbleController::GetExtensionService() const { | 71 ExtensionService* ScriptBubbleController::GetExtensionService() const { |
| 63 return ExtensionSystem::Get(profile())->extension_service(); | 72 return ExtensionSystem::Get(profile())->extension_service(); |
| 64 } | 73 } |
| 65 | 74 |
| 66 void ScriptBubbleController::UpdateScriptBubble() { | 75 void ScriptBubbleController::UpdateScriptBubble() { |
| 67 tab_helper_->location_bar_controller()->NotifyChange(); | 76 tab_helper_->location_bar_controller()->NotifyChange(); |
| 68 } | 77 } |
| 69 | 78 |
| 70 } // namespace extensions | 79 } // namespace extensions |
| OLD | NEW |