| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_EXECUTE_CODE_IN_TAB_FUNCTION_H__ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXECUTE_CODE_IN_TAB_FUNCTION_H__ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXECUTE_CODE_IN_TAB_FUNCTION_H__ | 6 #define CHROME_BROWSER_EXTENSIONS_EXECUTE_CODE_IN_TAB_FUNCTION_H__ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "chrome/browser/extensions/extension_function.h" | 11 #include "chrome/browser/extensions/extension_function.h" |
| 12 #include "chrome/common/extensions/extension_resource.h" | 12 #include "chrome/common/extensions/extension_resource.h" |
| 13 #include "content/common/notification_observer.h" | 13 #include "content/browser/tab_contents/tab_contents_observer.h" |
| 14 #include "content/common/notification_registrar.h" | |
| 15 | 14 |
| 16 // Implement API call tabs.executeScript and tabs.insertCSS. | 15 // Implement API call tabs.executeScript and tabs.insertCSS. |
| 17 class ExecuteCodeInTabFunction : public AsyncExtensionFunction, | 16 class ExecuteCodeInTabFunction : public AsyncExtensionFunction, |
| 18 public NotificationObserver { | 17 public TabContentsObserver { |
| 19 public: | 18 public: |
| 20 ExecuteCodeInTabFunction(); | 19 ExecuteCodeInTabFunction(); |
| 21 virtual ~ExecuteCodeInTabFunction(); | 20 virtual ~ExecuteCodeInTabFunction(); |
| 22 | 21 |
| 23 private: | 22 private: |
| 24 virtual bool RunImpl(); | 23 virtual bool RunImpl(); |
| 25 | 24 |
| 26 virtual void Observe(NotificationType type, | 25 // TabContentsObserver overrides. |
| 27 const NotificationSource& source, | 26 virtual bool OnMessageReceived(const IPC::Message& message); |
| 28 const NotificationDetails& details); | 27 |
| 28 // Message handler. |
| 29 void OnExecuteCodeFinished(int request_id, bool success); |
| 29 | 30 |
| 30 // Called when contents from the file whose path is specified in JSON | 31 // Called when contents from the file whose path is specified in JSON |
| 31 // arguments has been loaded. | 32 // arguments has been loaded. |
| 32 void DidLoadFile(bool success, const std::string& data); | 33 void DidLoadFile(bool success, const std::string& data); |
| 33 | 34 |
| 34 // Run in UI thread. Code string contains the code to be executed. Returns | 35 // Run in UI thread. Code string contains the code to be executed. Returns |
| 35 // true on success. If true is returned, this does an AddRef. | 36 // true on success. If true is returned, this does an AddRef. |
| 36 bool Execute(const std::string& code_string); | 37 bool Execute(const std::string& code_string); |
| 37 | 38 |
| 38 NotificationRegistrar registrar_; | 39 TabContentsObserver::Registrar registrar_; |
| 39 | 40 |
| 40 // Id of tab which executes code. | 41 // Id of tab which executes code. |
| 41 int execute_tab_id_; | 42 int execute_tab_id_; |
| 42 | 43 |
| 43 // Contains extension resource built from path of file which is | 44 // Contains extension resource built from path of file which is |
| 44 // specified in JSON arguments. | 45 // specified in JSON arguments. |
| 45 ExtensionResource resource_; | 46 ExtensionResource resource_; |
| 46 | 47 |
| 47 // If all_frames_ is true, script or CSS text would be injected | 48 // If all_frames_ is true, script or CSS text would be injected |
| 48 // to all frames; Otherwise only injected to top main frame. | 49 // to all frames; Otherwise only injected to top main frame. |
| 49 bool all_frames_; | 50 bool all_frames_; |
| 50 }; | 51 }; |
| 51 | 52 |
| 52 class TabsExecuteScriptFunction : public ExecuteCodeInTabFunction { | 53 class TabsExecuteScriptFunction : public ExecuteCodeInTabFunction { |
| 53 DECLARE_EXTENSION_FUNCTION_NAME("tabs.executeScript") | 54 DECLARE_EXTENSION_FUNCTION_NAME("tabs.executeScript") |
| 54 }; | 55 }; |
| 55 | 56 |
| 56 class TabsInsertCSSFunction : public ExecuteCodeInTabFunction { | 57 class TabsInsertCSSFunction : public ExecuteCodeInTabFunction { |
| 57 DECLARE_EXTENSION_FUNCTION_NAME("tabs.insertCSS") | 58 DECLARE_EXTENSION_FUNCTION_NAME("tabs.insertCSS") |
| 58 }; | 59 }; |
| 59 | 60 |
| 60 #endif // CHROME_BROWSER_EXTENSIONS_EXECUTE_CODE_IN_TAB_FUNCTION_H__ | 61 #endif // CHROME_BROWSER_EXTENSIONS_EXECUTE_CODE_IN_TAB_FUNCTION_H__ |
| OLD | NEW |