[email protected] | b6cd472 | 2014-05-01 22:04:06 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 44c49c9 | 2011-03-28 16:17:23 | [diff] [blame] | 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] | b6cd472 | 2014-05-01 22:04:06 | [diff] [blame] | 5 | #ifndef EXTENSIONS_RENDERER_EXTENSION_HELPER_H_ |
| 6 | #define EXTENSIONS_RENDERER_EXTENSION_HELPER_H_ |
[email protected] | 44c49c9 | 2011-03-28 16:17:23 | [diff] [blame] | 7 | |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 8 | #include <vector> |
[email protected] | 946a003 | 2011-03-31 18:42:28 | [diff] [blame] | 9 | |
[email protected] | 5b1a04b4 | 2012-06-15 00:41:44 | [diff] [blame] | 10 | #include "content/public/common/console_message_level.h" |
[email protected] | 3a034ebb | 2011-10-03 19:19:44 | [diff] [blame] | 11 | #include "content/public/renderer/render_view_observer.h" |
| 12 | #include "content/public/renderer/render_view_observer_tracker.h" |
[email protected] | cb2edf2 | 2013-04-01 20:25:23 | [diff] [blame] | 13 | #include "extensions/common/view_type.h" |
[email protected] | 44c49c9 | 2011-03-28 16:17:23 | [diff] [blame] | 14 | |
| 15 | class GURL; |
[email protected] | a2ef54c | 2011-10-10 16:20:31 | [diff] [blame] | 16 | class SkBitmap; |
[email protected] | 686914f | 2013-04-25 04:54:58 | [diff] [blame] | 17 | struct ExtensionMsg_ExternalConnectionInfo; |
[email protected] | 38b59290 | 2011-04-16 02:08:42 | [diff] [blame] | 18 | |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 19 | namespace base { |
[email protected] | 686914f | 2013-04-25 04:54:58 | [diff] [blame] | 20 | class DictionaryValue; |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 21 | class ListValue; |
| 22 | } |
| 23 | |
[email protected] | 8fe74bf | 2012-08-07 21:08:42 | [diff] [blame] | 24 | namespace extensions { |
| 25 | class Dispatcher; |
[email protected] | 8865fea | 2013-10-23 01:17:26 | [diff] [blame] | 26 | struct Message; |
[email protected] | 8fe74bf | 2012-08-07 21:08:42 | [diff] [blame] | 27 | |
[email protected] | d0cf438c | 2011-08-18 03:08:52 | [diff] [blame] | 28 | // RenderView-level plumbing for extension features. |
[email protected] | 3a034ebb | 2011-10-03 19:19:44 | [diff] [blame] | 29 | class ExtensionHelper |
| 30 | : public content::RenderViewObserver, |
| 31 | public content::RenderViewObserverTracker<ExtensionHelper> { |
[email protected] | 44c49c9 | 2011-03-28 16:17:23 | [diff] [blame] | 32 | public: |
[email protected] | 7042b68 | 2012-04-19 22:57:51 | [diff] [blame] | 33 | // Returns a list of extension RenderViews that match the given filter |
| 34 | // criteria. If |browser_window_id| is not extension_misc::kUnknownWindowId, |
| 35 | // the list is restricted to views in that browser window. |
| 36 | static std::vector<content::RenderView*> GetExtensionViews( |
| 37 | const std::string& extension_id, |
| 38 | int browser_window_id, |
[email protected] | cb2edf2 | 2013-04-01 20:25:23 | [diff] [blame] | 39 | ViewType view_type); |
[email protected] | 7042b68 | 2012-04-19 22:57:51 | [diff] [blame] | 40 | |
| 41 | // Returns the given extension's background page, or NULL if none. |
| 42 | static content::RenderView* GetBackgroundPage( |
| 43 | const std::string& extension_id); |
| 44 | |
[email protected] | 8fe74bf | 2012-08-07 21:08:42 | [diff] [blame] | 45 | ExtensionHelper(content::RenderView* render_view, Dispatcher* dispatcher); |
[email protected] | c2a4159 | 2011-09-08 01:13:18 | [diff] [blame] | 46 | virtual ~ExtensionHelper(); |
[email protected] | 44c49c9 | 2011-03-28 16:17:23 | [diff] [blame] | 47 | |
[email protected] | fc5e65d6b | 2012-06-13 00:22:57 | [diff] [blame] | 48 | int tab_id() const { return tab_id_; } |
[email protected] | 9966325b | 2011-04-18 05:00:10 | [diff] [blame] | 49 | int browser_window_id() const { return browser_window_id_; } |
[email protected] | cb2edf2 | 2013-04-01 20:25:23 | [diff] [blame] | 50 | ViewType view_type() const { return view_type_; } |
[email protected] | d266361 | 2013-03-17 09:25:56 | [diff] [blame] | 51 | Dispatcher* dispatcher() const { return dispatcher_; } |
[email protected] | 4f1633f | 2013-03-09 14:26:24 | [diff] [blame] | 52 | |
[email protected] | 44c49c9 | 2011-03-28 16:17:23 | [diff] [blame] | 53 | private: |
| 54 | // RenderViewObserver implementation. |
[email protected] | 5341642 | 2011-11-21 16:53:54 | [diff] [blame] | 55 | virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
[email protected] | c5041c32 | 2014-04-08 05:06:47 | [diff] [blame] | 56 | virtual void DidCreateDocumentElement(blink::WebLocalFrame* frame) OVERRIDE; |
[email protected] | f5b6dd112 | 2013-10-04 02:42:50 | [diff] [blame] | 57 | virtual void DidMatchCSS( |
[email protected] | c5041c32 | 2014-04-08 05:06:47 | [diff] [blame] | 58 | blink::WebLocalFrame* frame, |
[email protected] | a1221aea | 2013-11-07 01:31:30 | [diff] [blame] | 59 | const blink::WebVector<blink::WebString>& newly_matching_selectors, |
| 60 | const blink::WebVector<blink::WebString>& stopped_matching_selectors) |
[email protected] | f5b6dd112 | 2013-10-04 02:42:50 | [diff] [blame] | 61 | OVERRIDE; |
[email protected] | a1221aea | 2013-11-07 01:31:30 | [diff] [blame] | 62 | virtual void DraggableRegionsChanged(blink::WebFrame* frame) OVERRIDE; |
[email protected] | 44c49c9 | 2011-03-28 16:17:23 | [diff] [blame] | 63 | |
[email protected] | 74e21e7 | 2012-07-09 21:20:53 | [diff] [blame] | 64 | void OnExtensionResponse(int request_id, bool success, |
| 65 | const base::ListValue& response, |
| 66 | const std::string& error); |
[email protected] | 44c49c9 | 2011-03-28 16:17:23 | [diff] [blame] | 67 | void OnExtensionMessageInvoke(const std::string& extension_id, |
[email protected] | 68e63ea1 | 2013-06-05 05:00:54 | [diff] [blame] | 68 | const std::string& module_name, |
[email protected] | 44c49c9 | 2011-03-28 16:17:23 | [diff] [blame] | 69 | const std::string& function_name, |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 70 | const base::ListValue& args, |
[email protected] | b085856f | 2012-03-02 04:37:25 | [diff] [blame] | 71 | bool user_gesture); |
[email protected] | 686914f | 2013-04-25 04:54:58 | [diff] [blame] | 72 | void OnExtensionDispatchOnConnect( |
| 73 | int target_port_id, |
| 74 | const std::string& channel_name, |
| 75 | const base::DictionaryValue& source_tab, |
[email protected] | 8ad95b7 | 2013-10-16 02:54:11 | [diff] [blame] | 76 | const ExtensionMsg_ExternalConnectionInfo& info, |
| 77 | const std::string& tls_channel_id); |
[email protected] | b2e86ec1 | 2011-09-15 01:59:06 | [diff] [blame] | 78 | void OnExtensionDeliverMessage(int target_port_id, |
[email protected] | 8865fea | 2013-10-23 01:17:26 | [diff] [blame] | 79 | const Message& message); |
[email protected] | d6b3961 | 2013-03-08 02:33:13 | [diff] [blame] | 80 | void OnExtensionDispatchOnDisconnect(int port_id, |
| 81 | const std::string& error_message); |
[email protected] | cb2edf2 | 2013-04-01 20:25:23 | [diff] [blame] | 82 | void OnNotifyRendererViewType(ViewType view_type); |
[email protected] | fc5e65d6b | 2012-06-13 00:22:57 | [diff] [blame] | 83 | void OnSetTabId(int tab_id); |
[email protected] | 9966325b | 2011-04-18 05:00:10 | [diff] [blame] | 84 | void OnUpdateBrowserWindowId(int window_id); |
[email protected] | 5b1a04b4 | 2012-06-15 00:41:44 | [diff] [blame] | 85 | void OnAddMessageToConsole(content::ConsoleMessageLevel level, |
| 86 | const std::string& message); |
[email protected] | 02d51e4 | 2012-10-18 02:39:19 | [diff] [blame] | 87 | void OnAppWindowClosed(); |
[email protected] | 9a1314a | 2014-08-18 19:27:39 | [diff] [blame] | 88 | void OnSetFrameName(const std::string& name); |
[email protected] | 38b59290 | 2011-04-16 02:08:42 | [diff] [blame] | 89 | |
[email protected] | 8fe74bf | 2012-08-07 21:08:42 | [diff] [blame] | 90 | Dispatcher* dispatcher_; |
[email protected] | 8d97ade | 2011-04-14 18:17:08 | [diff] [blame] | 91 | |
[email protected] | 9966325b | 2011-04-18 05:00:10 | [diff] [blame] | 92 | // Type of view attached with RenderView. |
[email protected] | cb2edf2 | 2013-04-01 20:25:23 | [diff] [blame] | 93 | ViewType view_type_; |
[email protected] | 9966325b | 2011-04-18 05:00:10 | [diff] [blame] | 94 | |
[email protected] | fc5e65d6b | 2012-06-13 00:22:57 | [diff] [blame] | 95 | // Id of the tab which the RenderView is attached to. |
| 96 | int tab_id_; |
| 97 | |
[email protected] | 9966325b | 2011-04-18 05:00:10 | [diff] [blame] | 98 | // Id number of browser window which RenderView is attached to. |
| 99 | int browser_window_id_; |
| 100 | |
[email protected] | c2a4159 | 2011-09-08 01:13:18 | [diff] [blame] | 101 | DISALLOW_COPY_AND_ASSIGN(ExtensionHelper); |
[email protected] | 44c49c9 | 2011-03-28 16:17:23 | [diff] [blame] | 102 | }; |
| 103 | |
[email protected] | 8fe74bf | 2012-08-07 21:08:42 | [diff] [blame] | 104 | } // namespace extensions |
| 105 | |
[email protected] | b6cd472 | 2014-05-01 22:04:06 | [diff] [blame] | 106 | #endif // EXTENSIONS_RENDERER_EXTENSION_HELPER_H_ |