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