OLD | NEW |
(Empty) | |
| 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_BADGE_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_SCRIPT_BADGE_CONTROLLER_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <map> |
| 10 #include <set> |
| 11 #include <string> |
| 12 |
| 13 #include "base/memory/linked_ptr.h" |
| 14 #include "chrome/browser/extensions/action_box_controller.h" |
| 15 #include "chrome/browser/extensions/script_executor.h" |
| 16 #include "chrome/browser/extensions/script_executor_impl.h" |
| 17 #include "content/public/browser/web_contents_observer.h" |
| 18 |
| 19 class Extension; |
| 20 class ExtensionAction; |
| 21 class ExtensionService; |
| 22 class TabContentsWrapper; |
| 23 |
| 24 namespace extensions { |
| 25 |
| 26 // An ActionBoxController which corresponds to script badges, and implements |
| 27 // ScriptExecutor in order to show those scripts in the action box too. |
| 28 class ScriptBadgeController : public ActionBoxController, |
| 29 public ScriptExecutor, |
| 30 public content::WebContentsObserver { |
| 31 public: |
| 32 explicit ScriptBadgeController(TabContentsWrapper* tab_contents); |
| 33 virtual ~ScriptBadgeController(); |
| 34 |
| 35 // ActionBoxController implementation. |
| 36 virtual scoped_ptr<std::vector<ExtensionAction*> > GetCurrentActions() |
| 37 OVERRIDE; |
| 38 virtual Action OnClicked(const std::string& extension_id, |
| 39 int mouse_button) OVERRIDE; |
| 40 |
| 41 // ScriptExecutor implementation. |
| 42 virtual void ExecuteScript(const std::string& extension_id, |
| 43 ScriptType script_type, |
| 44 const std::string& code, |
| 45 FrameScope frame_scope, |
| 46 UserScript::RunLocation run_at, |
| 47 WorldType world_type, |
| 48 const ExecuteScriptCallback& callback) OVERRIDE; |
| 49 |
| 50 // content::WebContentsObserver implementation. |
| 51 virtual void DidNavigateMainFrame( |
| 52 const content::LoadCommittedDetails& details, |
| 53 const content::FrameNavigateParams& params) OVERRIDE; |
| 54 |
| 55 private: |
| 56 // Gets the script badge for |extension|. |
| 57 ExtensionAction* GetScriptBadge(const Extension* extension); |
| 58 |
| 59 // Gets the ExtensionService for |tab_contents_|. |
| 60 ExtensionService* GetExtensionService(); |
| 61 |
| 62 // Delegate ScriptExecutorImpl for running ExecuteScript. |
| 63 ScriptExecutorImpl script_executor_; |
| 64 |
| 65 // Our parent TabContentsWrapper. |
| 66 TabContentsWrapper* tab_contents_; |
| 67 |
| 68 // The extensions that have called ExecuteScript on the current frame. |
| 69 std::set<std::string> extensions_executing_scripts_; |
| 70 |
| 71 // Script badges that have been generated for extensions. This is both those |
| 72 // with actions already declared that are copied and normalised, and actions |
| 73 // that get generated for extensions that haven't declared anything. |
| 74 typedef std::map<std::string, linked_ptr<ExtensionAction> > ScriptBadgeMap; |
| 75 ScriptBadgeMap script_badges_; |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(ScriptBadgeController); |
| 78 }; |
| 79 |
| 80 } // namespace extensions |
| 81 |
| 82 #endif // CHROME_BROWSER_EXTENSIONS_SCRIPT_BADGE_CONTROLLER_H_ |
OLD | NEW |