Enable Enterprise enrollment on desktop builds.
[chromium-blink-merge.git] / chrome / browser / extensions / api / execute_code_function.h
blob213998f1e68cdc0c2e7e051c3011c41baa617b60
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_EXECUTE_CODE_FUNCTION_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_EXECUTE_CODE_FUNCTION_H_
8 #include "chrome/browser/extensions/chrome_extension_function.h"
9 #include "chrome/browser/extensions/script_executor.h"
10 #include "chrome/common/extensions/api/tabs.h"
12 namespace extensions {
14 // Base class for javascript code injection.
15 // This is used by both chrome.webview.executeScript and
16 // chrome.tabs.executeScript.
17 class ExecuteCodeFunction : public ChromeAsyncExtensionFunction {
18 public:
19 ExecuteCodeFunction();
21 protected:
22 virtual ~ExecuteCodeFunction();
24 // ExtensionFunction implementation.
25 virtual bool HasPermission() OVERRIDE;
26 virtual bool RunImpl() OVERRIDE;
28 // Initialize |details_| if it hasn't already been.
29 virtual bool Init() = 0;
30 virtual bool ShouldInsertCSS() const = 0;
31 virtual bool CanExecuteScriptOnPage() = 0;
32 virtual ScriptExecutor* GetScriptExecutor() = 0;
33 virtual bool IsWebView() const = 0;
34 virtual const GURL& GetWebViewSrc() const = 0;
35 virtual void OnExecuteCodeFinished(const std::string& error,
36 int32 on_page_id,
37 const GURL& on_url,
38 const base::ListValue& result);
40 // The injection details.
41 scoped_ptr<api::tabs::InjectDetails> details_;
43 private:
44 // Called when contents from the file whose path is specified in JSON
45 // arguments has been loaded.
46 void DidLoadFile(bool success, const std::string& data);
48 // Runs on FILE thread. Loads message bundles for the extension and
49 // localizes the CSS data. Calls back DidLoadAndLocalizeFile on the UI thread.
50 void GetFileURLAndLocalizeCSS(
51 ScriptExecutor::ScriptType script_type,
52 const std::string& data,
53 const std::string& extension_id,
54 const base::FilePath& extension_path,
55 const std::string& extension_default_locale);
57 // Called when contents from the loaded file have been localized.
58 void DidLoadAndLocalizeFile(bool success, const std::string& data);
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);
64 // Contains extension resource built from path of file which is
65 // specified in JSON arguments.
66 ExtensionResource resource_;
68 // The URL of the file being injected into the page.
69 GURL file_url_;
72 } // namespace extensions
74 #endif // CHROME_BROWSER_EXTENSIONS_API_EXECUTE_CODE_FUNCTION_H_