blob: 0a53607a5e47cbdd5c20715467c6c84668d9ae9a [file] [log] [blame]
[email protected]ea0f18b2009-07-27 22:16:111// Copyright (c) 2009 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
[email protected]811bfe372009-07-01 08:46:255#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_DOM_UI_H_
6#define CHROME_BROWSER_EXTENSIONS_EXTENSION_DOM_UI_H_
7
[email protected]b27257562009-11-16 23:28:268#include <string>
9
[email protected]811bfe372009-07-01 08:46:2510#include "base/scoped_ptr.h"
11#include "chrome/browser/dom_ui/dom_ui.h"
12#include "chrome/browser/extensions/extension_function_dispatcher.h"
[email protected]b27257562009-11-16 23:28:2613#include "chrome/browser/extensions/extension_popup_host.h"
[email protected]d3cfa482009-10-17 13:54:5714#include "chrome/common/extensions/extension.h"
[email protected]811bfe372009-07-01 08:46:2515
[email protected]86c008e82009-08-28 20:26:0516class ListValue;
17class PrefService;
[email protected]b27257562009-11-16 23:28:2618class RenderViewHost;
[email protected]86c008e82009-08-28 20:26:0519class TabContents;
20
[email protected]811bfe372009-07-01 08:46:2521// This class implements DOMUI for extensions and allows extensions to put UI in
22// the main tab contents area.
[email protected]d3cfa482009-10-17 13:54:5723class ExtensionDOMUI
[email protected]811bfe372009-07-01 08:46:2524 : public DOMUI,
[email protected]b27257562009-11-16 23:28:2625 public ExtensionPopupHost::PopupDelegate,
[email protected]811bfe372009-07-01 08:46:2526 public ExtensionFunctionDispatcher::Delegate {
27 public:
28 explicit ExtensionDOMUI(TabContents* tab_contents);
[email protected]86c008e82009-08-28 20:26:0529
[email protected]811bfe372009-07-01 08:46:2530 ExtensionFunctionDispatcher* extension_function_dispatcher() const {
31 return extension_function_dispatcher_.get();
32 }
33
34 // DOMUI
35 virtual void RenderViewCreated(RenderViewHost* render_view_host);
[email protected]cf430e22009-07-16 18:04:3636 virtual void RenderViewReused(RenderViewHost* render_view_host);
[email protected]811bfe372009-07-01 08:46:2537 virtual void ProcessDOMUIMessage(const std::string& message,
[email protected]e4dad9fb2009-10-06 18:15:5838 const Value* content,
[email protected]811bfe372009-07-01 08:46:2539 int request_id,
40 bool has_callback);
41
42 // ExtensionFunctionDispatcher::Delegate
43 virtual Browser* GetBrowser();
[email protected]b27257562009-11-16 23:28:2644 virtual ExtensionDOMUI* GetExtensionDOMUI() { return this; }
45
46 // ExtensionPopupHost::Delegate
47 virtual RenderViewHost* GetRenderViewHost();
[email protected]811bfe372009-07-01 08:46:2548
[email protected]86c008e82009-08-28 20:26:0549 // BrowserURLHandler
50 static bool HandleChromeURLOverride(GURL* url, Profile* profile);
51
52 // Register and unregister a dictionary of one or more overrides.
53 // Page names are the keys, and chrome-extension: URLs are the values.
54 // (e.g. { "newtab": "chrome-extension://<id>/my_new_tab.html" }
55 static void RegisterChromeURLOverrides(Profile* profile,
[email protected]d3cfa482009-10-17 13:54:5756 const Extension::URLOverrideMap& overrides);
[email protected]86c008e82009-08-28 20:26:0557 static void UnregisterChromeURLOverrides(Profile* profile,
[email protected]d3cfa482009-10-17 13:54:5758 const Extension::URLOverrideMap& overrides);
[email protected]86c008e82009-08-28 20:26:0559 static void UnregisterChromeURLOverride(const std::string& page,
60 Profile* profile,
61 Value* override);
62
63 // Called from BrowserPrefs
64 static void RegisterUserPrefs(PrefService* prefs);
65
[email protected]811bfe372009-07-01 08:46:2566 private:
[email protected]86c008e82009-08-28 20:26:0567 // Unregister the specified override, and if it's the currently active one,
68 // ensure that something takes its place.
69 static void UnregisterAndReplaceOverride(const std::string& page,
70 Profile* profile,
71 ListValue* list,
72 Value* override);
73
74 // When the RenderViewHost changes (RenderViewCreated and RenderViewReused),
75 // we need to reset the ExtensionFunctionDispatcher so it's talking to the
76 // right one, as well as being linked to the correct URL.
77 void ResetExtensionFunctionDispatcher(RenderViewHost* render_view_host);
78
[email protected]811bfe372009-07-01 08:46:2579 scoped_ptr<ExtensionFunctionDispatcher> extension_function_dispatcher_;
80};
81
82#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_DOM_UI_H_