• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #ifndef CHROME_BROWSER_EXTENSIONS_SCRIPT_BUBBLE_CONTROLLER_H_
6 #define CHROME_BROWSER_EXTENSIONS_SCRIPT_BUBBLE_CONTROLLER_H_
7 
8 #include <set>
9 #include <string>
10 
11 #include "base/basictypes.h"
12 #include "chrome/browser/extensions/tab_helper.h"
13 #include "content/public/browser/web_contents_observer.h"
14 
15 class ExtensionService;
16 
17 namespace extensions {
18 
19 class ExtensionSystem;
20 
21 // Controls the script bubble in the omnibox, which displays information about
22 // extensions which are interacting with the current tab.
23 class ScriptBubbleController
24     : public TabHelper::ScriptExecutionObserver,
25       public content::WebContentsObserver {
26  public:
27   ScriptBubbleController(content::WebContents* web_contents,
28                          TabHelper* tab_helper);
29   virtual ~ScriptBubbleController();
30 
31   // Returns a set of extension ids for extensions running content scripts.
extensions_running_scripts()32   const std::set<std::string>& extensions_running_scripts() {
33     return extensions_running_scripts_;
34   }
35 
36   // TabHelper::ScriptExecutionObserver implementation
37   virtual void OnScriptsExecuted(
38       const content::WebContents* web_contents,
39       const ExecutingScriptsMap& extension_ids,
40       int32 page_id,
41       const GURL& on_url) OVERRIDE;
42 
43   // content::WebContentsObserver implementation.
44   virtual void DidNavigateMainFrame(
45       const content::LoadCommittedDetails& details,
46       const content::FrameNavigateParams& params) OVERRIDE;
47 
48   void OnExtensionUnloaded(const std::string& extension_id);
49 
50  private:
51   // Helper to get the profile of the web contents we're associated with.
52   Profile* profile() const;
53 
54   // Helper to get the extension service for the profile of the web contents
55   // we're associated with.
56   ExtensionService* GetExtensionService() const;
57 
58   // Helper to update the properties of the script bubble to reflect current
59   // internal state.
60   void UpdateScriptBubble();
61 
62   // The accumulated set of extension IDs that are operating on this tab.
63   std::set<std::string> extensions_running_scripts_;
64 
65   DISALLOW_COPY_AND_ASSIGN(ScriptBubbleController);
66 };
67 
68 }  // namespace extensions
69 
70 #endif  // CHROME_BROWSER_EXTENSIONS_SCRIPT_BUBBLE_CONTROLLER_H_
71