| 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/browser/tab_contents/tab_contents_observer.h" | 13 #include "content/browser/tab_contents/tab_contents_observer.h" |
| 14 | 14 |
| 15 class MessageLoop; |
| 16 |
| 15 // Implement API call tabs.executeScript and tabs.insertCSS. | 17 // Implement API call tabs.executeScript and tabs.insertCSS. |
| 16 class ExecuteCodeInTabFunction : public AsyncExtensionFunction, | 18 class ExecuteCodeInTabFunction : public AsyncExtensionFunction, |
| 17 public TabContentsObserver { | 19 public TabContentsObserver { |
| 18 public: | 20 public: |
| 19 ExecuteCodeInTabFunction(); | 21 ExecuteCodeInTabFunction(); |
| 20 virtual ~ExecuteCodeInTabFunction(); | 22 virtual ~ExecuteCodeInTabFunction(); |
| 21 | 23 |
| 22 private: | 24 private: |
| 23 virtual bool RunImpl(); | 25 virtual bool RunImpl(); |
| 24 | 26 |
| 25 // TabContentsObserver overrides. | 27 // TabContentsObserver overrides. |
| 26 virtual bool OnMessageReceived(const IPC::Message& message); | 28 virtual bool OnMessageReceived(const IPC::Message& message); |
| 27 | 29 |
| 28 // Message handler. | 30 // Message handler. |
| 29 void OnExecuteCodeFinished(int request_id, bool success, | 31 void OnExecuteCodeFinished(int request_id, bool success, |
| 30 const std::string& error); | 32 const std::string& error); |
| 31 | 33 |
| 32 // Called when contents from the file whose path is specified in JSON | 34 // Called when contents from the file whose path is specified in JSON |
| 33 // arguments has been loaded. | 35 // arguments has been loaded. |
| 34 void DidLoadFile(bool success, const std::string& data); | 36 void DidLoadFile(bool success, const std::string& data); |
| 35 | 37 |
| 38 // Runs on FILE thread. Loads message bundles for the extension and |
| 39 // localizes the CSS data. Calls back DidLoadAndLocalizeFile on the UI thread. |
| 40 void LocalizeCSS( |
| 41 const std::string& data, |
| 42 const std::string& extension_id, |
| 43 const FilePath& extension_path, |
| 44 const std::string& extension_default_locale); |
| 45 |
| 46 // Called when contents from the loaded file have been localized. |
| 47 void DidLoadAndLocalizeFile(bool success, const std::string& data); |
| 48 |
| 36 // Run in UI thread. Code string contains the code to be executed. Returns | 49 // Run in UI thread. Code string contains the code to be executed. Returns |
| 37 // true on success. If true is returned, this does an AddRef. | 50 // true on success. If true is returned, this does an AddRef. |
| 38 bool Execute(const std::string& code_string); | 51 bool Execute(const std::string& code_string); |
| 39 | 52 |
| 40 // Id of tab which executes code. | 53 // Id of tab which executes code. |
| 41 int execute_tab_id_; | 54 int execute_tab_id_; |
| 42 | 55 |
| 43 // Contains extension resource built from path of file which is | 56 // Contains extension resource built from path of file which is |
| 44 // specified in JSON arguments. | 57 // specified in JSON arguments. |
| 45 ExtensionResource resource_; | 58 ExtensionResource resource_; |
| 46 | 59 |
| 47 // If all_frames_ is true, script or CSS text would be injected | 60 // If all_frames_ is true, script or CSS text would be injected |
| 48 // to all frames; Otherwise only injected to top main frame. | 61 // to all frames; Otherwise only injected to top main frame. |
| 49 bool all_frames_; | 62 bool all_frames_; |
| 50 }; | 63 }; |
| 51 | 64 |
| 52 class TabsExecuteScriptFunction : public ExecuteCodeInTabFunction { | 65 class TabsExecuteScriptFunction : public ExecuteCodeInTabFunction { |
| 53 DECLARE_EXTENSION_FUNCTION_NAME("tabs.executeScript") | 66 DECLARE_EXTENSION_FUNCTION_NAME("tabs.executeScript") |
| 54 }; | 67 }; |
| 55 | 68 |
| 56 class TabsInsertCSSFunction : public ExecuteCodeInTabFunction { | 69 class TabsInsertCSSFunction : public ExecuteCodeInTabFunction { |
| 57 DECLARE_EXTENSION_FUNCTION_NAME("tabs.insertCSS") | 70 DECLARE_EXTENSION_FUNCTION_NAME("tabs.insertCSS") |
| 58 }; | 71 }; |
| 59 | 72 |
| 60 #endif // CHROME_BROWSER_EXTENSIONS_EXECUTE_CODE_IN_TAB_FUNCTION_H__ | 73 #endif // CHROME_BROWSER_EXTENSIONS_EXECUTE_CODE_IN_TAB_FUNCTION_H__ |
| OLD | NEW |