| 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_API_TABS_EXECUTE_CODE_IN_TAB_FUNCTION_H__ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_TABS_EXECUTE_CODE_IN_TAB_FUNCTION_H__ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "chrome/browser/extensions/extension_function.h" | |
| 11 #include "chrome/common/extensions/extension_resource.h" | |
| 12 #include "chrome/common/extensions/user_script.h" | |
| 13 | |
| 14 namespace extensions { | |
| 15 namespace api { | |
| 16 namespace tabs { | |
| 17 struct InjectDetails; | |
| 18 } // namespace tabs | |
| 19 } // namespace api | |
| 20 } // namespace extensions | |
| 21 | |
| 22 // Implement API call tabs.executeScript and tabs.insertCSS. | |
| 23 class ExecuteCodeInTabFunction : public AsyncExtensionFunction { | |
| 24 public: | |
| 25 ExecuteCodeInTabFunction(); | |
| 26 | |
| 27 protected: | |
| 28 virtual ~ExecuteCodeInTabFunction(); | |
| 29 | |
| 30 // ExtensionFunction: | |
| 31 virtual bool HasPermission() OVERRIDE; | |
| 32 virtual bool RunImpl() OVERRIDE; | |
| 33 | |
| 34 // Message handler. | |
| 35 virtual void OnExecuteCodeFinished(const std::string& error, | |
| 36 int32 on_page_id, | |
| 37 const GURL& on_url, | |
| 38 const ListValue& script_result); | |
| 39 | |
| 40 private: | |
| 41 // Initialize the |execute_tab_id_| and |details_| if they haven't already | |
| 42 // been. Returns whether initialization was successful. | |
| 43 bool Init(); | |
| 44 | |
| 45 // Called when contents from the file whose path is specified in JSON | |
| 46 // arguments has been loaded. | |
| 47 void DidLoadFile(bool success, const std::string& data); | |
| 48 | |
| 49 // Runs on FILE thread. Loads message bundles for the extension and | |
| 50 // localizes the CSS data. Calls back DidLoadAndLocalizeFile on the UI thread. | |
| 51 void LocalizeCSS( | |
| 52 const std::string& data, | |
| 53 const std::string& extension_id, | |
| 54 const FilePath& extension_path, | |
| 55 const std::string& extension_default_locale); | |
| 56 | |
| 57 // Called when contents from the loaded file have been localized. | |
| 58 void DidLoadAndLocalizeFile(bool success, const std::string& data); | |
| 59 | |
| 60 // Run in UI thread. Code string contains the code to be executed. Returns | |
| 61 // true on success. If true is returned, this does an AddRef. | |
| 62 bool Execute(const std::string& code_string); | |
| 63 | |
| 64 // Id of tab which executes code. | |
| 65 int execute_tab_id_; | |
| 66 | |
| 67 // The injection details. | |
| 68 scoped_ptr<extensions::api::tabs::InjectDetails> details_; | |
| 69 | |
| 70 // Contains extension resource built from path of file which is | |
| 71 // specified in JSON arguments. | |
| 72 ExtensionResource resource_; | |
| 73 }; | |
| 74 | |
| 75 class TabsExecuteScriptFunction : public ExecuteCodeInTabFunction { | |
| 76 private: | |
| 77 virtual ~TabsExecuteScriptFunction() {} | |
| 78 | |
| 79 virtual void OnExecuteCodeFinished(const std::string& error, | |
| 80 int32 on_page_id, | |
| 81 const GURL& on_url, | |
| 82 const ListValue& script_result) OVERRIDE; | |
| 83 | |
| 84 DECLARE_EXTENSION_FUNCTION_NAME("tabs.executeScript") | |
| 85 }; | |
| 86 | |
| 87 class TabsInsertCSSFunction : public ExecuteCodeInTabFunction { | |
| 88 private: | |
| 89 virtual ~TabsInsertCSSFunction() {} | |
| 90 | |
| 91 DECLARE_EXTENSION_FUNCTION_NAME("tabs.insertCSS") | |
| 92 }; | |
| 93 | |
| 94 #endif // CHROME_BROWSER_EXTENSIONS_API_TABS_EXECUTE_CODE_IN_TAB_FUNCTION_H__ | |
| OLD | NEW |