Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 EXTENSIONS_BROWSER_API_EXECUTE_CODE_FUNCTION_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_EXECUTE_CODE_FUNCTION_H_ |
| 6 #define EXTENSIONS_BROWSER_API_EXECUTE_CODE_FUNCTION_H_ | 6 #define EXTENSIONS_BROWSER_API_EXECUTE_CODE_FUNCTION_H_ |
| 7 | 7 |
| 8 #include "extensions/browser/extension_function.h" | 8 #include "extensions/browser/extension_function.h" |
| 9 #include "extensions/browser/script_executor.h" | 9 #include "extensions/browser/script_executor.h" |
| 10 #include "extensions/common/api/extension_types.h" | 10 #include "extensions/common/api/extension_types.h" |
| 11 #include "extensions/common/host_id.h" | 11 #include "extensions/common/host_id.h" |
| 12 | 12 |
| 13 namespace extensions { | 13 namespace extensions { |
| 14 | 14 |
| 15 // Base class for javascript code injection. | 15 // Base class for javascript code injection. |
| 16 // This is used by both chrome.webview.executeScript and | 16 // This is used by both chrome.webview.executeScript and |
| 17 // chrome.tabs.executeScript. | 17 // chrome.tabs.executeScript. |
| 18 class ExecuteCodeFunction : public AsyncExtensionFunction { | 18 class ExecuteCodeFunction : public AsyncExtensionFunction { |
| 19 public: | 19 public: |
| 20 ExecuteCodeFunction(); | 20 ExecuteCodeFunction(); |
| 21 | 21 |
| 22 // Called when contents from the loaded file have been localized. | |
| 23 void DidLoadAndLocalizeFile(const std::string& file, | |
|
Devlin
2015/03/25 22:12:20
Why is this public now?
Xi Han
2015/03/26 14:00:20
Oops, I bound &ExecuteCodeFunction::DidLoadAndLoca
| |
| 24 bool success, | |
| 25 const std::string& data); | |
| 26 | |
| 22 protected: | 27 protected: |
|
Devlin
2015/03/25 22:12:20
I don't know why I didn't notice this before, but
Xi Han
2015/03/26 14:00:20
I didn't notice that either, removed.
| |
| 23 ~ExecuteCodeFunction() override; | 28 ~ExecuteCodeFunction() override; |
| 24 | 29 |
| 25 // ExtensionFunction implementation. | 30 // ExtensionFunction implementation. |
| 26 bool HasPermission() override; | 31 bool HasPermission() override; |
| 27 bool RunAsync() override; | 32 bool RunAsync() override; |
| 28 | 33 |
| 29 // Initialize |details_| if it hasn't already been. | 34 // Initialize |details_| if it hasn't already been. |
| 30 virtual bool Init() = 0; | 35 virtual bool Init() = 0; |
| 31 virtual bool ShouldInsertCSS() const = 0; | 36 virtual bool ShouldInsertCSS() const = 0; |
| 32 virtual bool CanExecuteScriptOnPage() = 0; | 37 virtual bool CanExecuteScriptOnPage() = 0; |
| 33 virtual ScriptExecutor* GetScriptExecutor() = 0; | 38 virtual ScriptExecutor* GetScriptExecutor() = 0; |
| 34 virtual bool IsWebView() const = 0; | 39 virtual bool IsWebView() const = 0; |
| 35 virtual const GURL& GetWebViewSrc() const = 0; | 40 virtual const GURL& GetWebViewSrc() const = 0; |
| 36 virtual void OnExecuteCodeFinished(const std::string& error, | 41 virtual void OnExecuteCodeFinished(const std::string& error, |
| 37 const GURL& on_url, | 42 const GURL& on_url, |
| 38 const base::ListValue& result); | 43 const base::ListValue& result); |
| 39 | 44 |
| 40 // The injection details. | |
| 41 scoped_ptr<core_api::extension_types::InjectDetails> details_; | |
| 42 | |
| 43 const HostID& host_id() const { return host_id_; } | 45 const HostID& host_id() const { return host_id_; } |
| 44 void set_host_id(HostID host_id) { | 46 void set_host_id(HostID host_id) { |
| 45 host_id_ = host_id; | 47 host_id_ = host_id; |
| 46 } | 48 } |
| 47 | 49 |
| 50 // The injection details. | |
| 51 scoped_ptr<core_api::extension_types::InjectDetails> details_; | |
| 52 | |
| 53 protected: | |
| 54 virtual bool LoadFile(const std::string& file); | |
| 55 | |
| 48 private: | 56 private: |
| 49 // Called when contents from the file whose path is specified in JSON | 57 // Called when contents from the file whose path is specified in JSON |
| 50 // arguments has been loaded. | 58 // arguments has been loaded. |
| 51 void DidLoadFile(bool success, const std::string& data); | 59 void DidLoadFile(bool success, const std::string& data); |
| 52 | 60 |
| 53 // Runs on FILE thread. Loads message bundles for the extension and | 61 // Runs on FILE thread. Loads message bundles for the extension and |
| 54 // localizes the CSS data. Calls back DidLoadAndLocalizeFile on the UI thread. | 62 // localizes the CSS data. Calls back DidLoadAndLocalizeFile on the UI thread. |
| 55 void GetFileURLAndLocalizeCSS(ScriptExecutor::ScriptType script_type, | 63 void GetFileURLAndLocalizeCSS(ScriptExecutor::ScriptType script_type, |
| 56 const std::string& data, | 64 const std::string& data, |
| 57 const std::string& extension_id, | 65 const std::string& extension_id, |
| 58 const base::FilePath& extension_path, | 66 const base::FilePath& extension_path, |
| 59 const std::string& extension_default_locale); | 67 const std::string& extension_default_locale); |
| 60 | 68 |
| 61 // Called when contents from the loaded file have been localized. | |
| 62 void DidLoadAndLocalizeFile(bool success, const std::string& data); | |
| 63 | |
| 64 // Run in UI thread. Code string contains the code to be executed. Returns | 69 // Run in UI thread. Code string contains the code to be executed. Returns |
| 65 // true on success. If true is returned, this does an AddRef. | 70 // true on success. If true is returned, this does an AddRef. |
| 66 bool Execute(const std::string& code_string); | 71 bool Execute(const std::string& code_string); |
| 67 | 72 |
| 68 // Contains extension resource built from path of file which is | 73 // Contains extension resource built from path of file which is |
| 69 // specified in JSON arguments. | 74 // specified in JSON arguments. |
| 70 ExtensionResource resource_; | 75 ExtensionResource resource_; |
| 71 | 76 |
| 72 // The URL of the file being injected into the page. | 77 // The URL of the file being injected into the page. |
| 73 GURL file_url_; | 78 GURL file_url_; |
| 74 | 79 |
| 75 // The ID of the injection host. | 80 // The ID of the injection host. |
| 76 HostID host_id_; | 81 HostID host_id_; |
| 77 }; | 82 }; |
| 78 | 83 |
| 79 } // namespace extensions | 84 } // namespace extensions |
| 80 | 85 |
| 81 #endif // EXTENSIONS_BROWSER_API_EXECUTE_CODE_FUNCTION_H_ | 86 #endif // EXTENSIONS_BROWSER_API_EXECUTE_CODE_FUNCTION_H_ |
| OLD | NEW |