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