| 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 #ifndef CHROME_BROWSER_EXTENSIONS_SCRIPT_BADGE_CONTROLLER_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_SCRIPT_BADGE_CONTROLLER_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_SCRIPT_BADGE_CONTROLLER_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_SCRIPT_BADGE_CONTROLLER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| 12 | 12 |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/memory/linked_ptr.h" | 14 #include "base/memory/linked_ptr.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "chrome/browser/extensions/location_bar_controller.h" | 16 #include "chrome/browser/extensions/location_bar_controller.h" |
| 17 #include "chrome/browser/extensions/script_executor.h" | 17 #include "chrome/browser/extensions/script_executor.h" |
| 18 #include "chrome/browser/extensions/script_executor_impl.h" | 18 #include "chrome/browser/extensions/script_executor_impl.h" |
| 19 #include "content/public/browser/notification_observer.h" |
| 20 #include "content/public/browser/notification_registrar.h" |
| 19 #include "content/public/browser/web_contents_observer.h" | 21 #include "content/public/browser/web_contents_observer.h" |
| 20 | 22 |
| 21 class ExtensionAction; | 23 class ExtensionAction; |
| 22 class ExtensionService; | 24 class ExtensionService; |
| 23 class TabContents; | 25 class TabContents; |
| 24 | 26 |
| 25 namespace IPC { | 27 namespace IPC { |
| 26 class Message; | 28 class Message; |
| 27 } | 29 } |
| 28 | 30 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 41 // | 43 // |
| 42 // When extension IDs are recorded a NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED | 44 // When extension IDs are recorded a NOTIFICATION_EXTENSION_LOCATION_BAR_UPDATED |
| 43 // is sent, and those extensions will be returned from GetCurrentActions until | 45 // is sent, and those extensions will be returned from GetCurrentActions until |
| 44 // the next page navigation. | 46 // the next page navigation. |
| 45 // | 47 // |
| 46 // Ref-counted so that it can be safely bound in a base::Bind. | 48 // Ref-counted so that it can be safely bound in a base::Bind. |
| 47 class ScriptBadgeController | 49 class ScriptBadgeController |
| 48 : public base::RefCountedThreadSafe<ScriptBadgeController>, | 50 : public base::RefCountedThreadSafe<ScriptBadgeController>, |
| 49 public LocationBarController, | 51 public LocationBarController, |
| 50 public ScriptExecutor, | 52 public ScriptExecutor, |
| 51 public content::WebContentsObserver { | 53 public content::WebContentsObserver, |
| 54 public content::NotificationObserver { |
| 52 public: | 55 public: |
| 53 explicit ScriptBadgeController(TabContents* tab_contents); | 56 explicit ScriptBadgeController(TabContents* tab_contents); |
| 54 | 57 |
| 55 // LocationBarController implementation. | 58 // LocationBarController implementation. |
| 56 virtual scoped_ptr<std::vector<ExtensionAction*> > GetCurrentActions() | 59 virtual scoped_ptr<std::vector<ExtensionAction*> > GetCurrentActions() |
| 57 OVERRIDE; | 60 OVERRIDE; |
| 58 virtual Action OnClicked(const std::string& extension_id, | 61 virtual Action OnClicked(const std::string& extension_id, |
| 59 int mouse_button) OVERRIDE; | 62 int mouse_button) OVERRIDE; |
| 60 | 63 |
| 61 // ScriptExecutor implementation. | 64 // ScriptExecutor implementation. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 87 | 90 |
| 88 // Sends a LOCATION_BAR_UPDATED notification. | 91 // Sends a LOCATION_BAR_UPDATED notification. |
| 89 void Notify(); | 92 void Notify(); |
| 90 | 93 |
| 91 // content::WebContentsObserver implementation. | 94 // content::WebContentsObserver implementation. |
| 92 virtual void DidNavigateMainFrame( | 95 virtual void DidNavigateMainFrame( |
| 93 const content::LoadCommittedDetails& details, | 96 const content::LoadCommittedDetails& details, |
| 94 const content::FrameNavigateParams& params) OVERRIDE; | 97 const content::FrameNavigateParams& params) OVERRIDE; |
| 95 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 98 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 96 | 99 |
| 100 // content::NotificationObserver implementation. |
| 101 virtual void Observe(int type, |
| 102 const content::NotificationSource& source, |
| 103 const content::NotificationDetails& details) OVERRIDE; |
| 104 |
| 97 // IPC::Message handlers. | 105 // IPC::Message handlers. |
| 98 void OnContentScriptsExecuting(const std::set<std::string>& extension_ids, | 106 void OnContentScriptsExecuting(const std::set<std::string>& extension_ids, |
| 99 int32 page_id); | 107 int32 page_id); |
| 100 | 108 |
| 109 // Tries to insert an extension into the relevant collections, and returns |
| 110 // whether any change was made. |
| 111 bool InsertExtension(const std::string& extension_id); |
| 112 |
| 113 // Tries to erase an extension from the relevant collections, and returns |
| 114 // whether any change was made. |
| 115 bool EraseExtension(const Extension* extension); |
| 116 |
| 101 // Delegate ScriptExecutorImpl for running ExecuteScript. | 117 // Delegate ScriptExecutorImpl for running ExecuteScript. |
| 102 ScriptExecutorImpl script_executor_; | 118 ScriptExecutorImpl script_executor_; |
| 103 | 119 |
| 104 // Our parent TabContents. | 120 // Our parent TabContents. |
| 105 TabContents* tab_contents_; | 121 TabContents* tab_contents_; |
| 106 | 122 |
| 123 // The current extension actions in the order they appeared. |
| 124 std::vector<ExtensionAction*> current_actions_; |
| 125 |
| 107 // The extensions that have called ExecuteScript on the current frame. | 126 // The extensions that have called ExecuteScript on the current frame. |
| 108 std::set<std::string> extensions_executing_scripts_; | 127 std::set<std::string> extensions_executing_scripts_; |
| 109 | 128 |
| 129 // Listen to extension unloaded notifications. |
| 130 content::NotificationRegistrar registrar_; |
| 131 |
| 110 DISALLOW_COPY_AND_ASSIGN(ScriptBadgeController); | 132 DISALLOW_COPY_AND_ASSIGN(ScriptBadgeController); |
| 111 }; | 133 }; |
| 112 | 134 |
| 113 } // namespace extensions | 135 } // namespace extensions |
| 114 | 136 |
| 115 #endif // CHROME_BROWSER_EXTENSIONS_SCRIPT_BADGE_CONTROLLER_H_ | 137 #endif // CHROME_BROWSER_EXTENSIONS_SCRIPT_BADGE_CONTROLLER_H_ |
| OLD | NEW |